Revision control

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
import Foundation
6
import XCTest
7
import Storage
8
import SDWebImage
9
@testable import Client
10
import Shared
11
12
class TestFavicons: ProfileTest {
13
14
fileprivate func addSite(_ favicons: Favicons, url: String, s: Bool = true) {
15
let expectation = self.expectation(description: "Wait for history")
16
let site = Site(url: url, title: "")
17
let icon = Favicon(url: url + "/icon.png")
18
favicons.addFavicon(icon, forSite: site).upon {
19
XCTAssertEqual($0.isSuccess, s, "Icon added \(url)")
20
expectation.fulfill()
21
}
22
self.waitForExpectations(timeout: 100, handler: nil)
23
}
24
25
// XXX: Temporarily disabling this due to intermittent failures on BuddyBuild.
26
func testFaviconFetcherParse() {
27
let expectation = self.expectation(description: "Wait for Favicons to be fetched")
28
29
let profile = MockProfile()
30
// I want a site that also has an iOS app so I can get "apple-touch-icon-precomposed" icons as well
31
let url = URL(string: "https://instagram.com")
32
FaviconFetcher.getForURL(url!, profile: profile).uponQueue(.main) { result in
33
guard let favicons = result.successValue, favicons.count > 0, let url = favicons.first?.url.asURL else {
34
XCTFail("Favicons were not found.")
35
return expectation.fulfill()
36
}
37
XCTAssertEqual(favicons.count, 1, "Instagram should have a Favicon.")
38
SDWebImageManager.shared.loadImage(with: url, options: .retryFailed, progress: nil, completed: { (img, _, _, _, _, _) in
39
guard let image = img else {
40
XCTFail("Not a valid URL provided for a favicon.")
41
return expectation.fulfill()
42
}
43
XCTAssertNotEqual(image.size, .zero)
44
expectation.fulfill()
45
})
46
47
}
48
self.waitForExpectations(timeout: 3000, handler: nil)
49
}
50
51
func testDefaultFavicons() {
52
// The amazon case tests a special case for multi-reguin domain lookups
54
let url = URL(string: $0)!
55
let icon = FaviconFetcher.getDefaultIconForURL(url: url)
56
XCTAssertNotNil(icon)
57
}
58
}
59
}