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