LEFT | RIGHT |
1 // | 1 // |
2 // FavIcon | 2 // FavIcon |
3 // Copyright © 2016 Leon Breedt | 3 // Copyright © 2016 Leon Breedt |
4 // | 4 // |
5 // Licensed under the Apache License, Version 2.0 (the "License"); | 5 // Licensed under the Apache License, Version 2.0 (the "License"); |
6 // you may not use this file except in compliance with the License. | 6 // you may not use this file except in compliance with the License. |
7 // You may obtain a copy of the License at | 7 // You may obtain a copy of the License at |
8 // | 8 // |
9 // http://www.apache.org/licenses/LICENSE-2.0 | 9 // http://www.apache.org/licenses/LICENSE-2.0 |
10 // | 10 // |
11 // Unless required by applicable law or agreed to in writing, software | 11 // Unless required by applicable law or agreed to in writing, software |
12 // distributed under the License is distributed on an "AS IS" BASIS, | 12 // distributed under the License is distributed on an "AS IS" BASIS, |
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 // See the License for the specific language governing permissions and | 14 // See the License for the specific language governing permissions and |
15 // limitations under the License. | 15 // limitations under the License. |
16 // | 16 // |
17 | 17 |
18 // swiftlint:disable sorted_imports | 18 @testable import FavIcon |
19 | |
20 import XCTest | 19 import XCTest |
21 @testable import FavIcon | |
22 | 20 |
23 #if os(iOS) | 21 #if os(iOS) |
24 import UIKit | 22 import UIKit |
25 #elseif os(OSX) | 23 #elseif os(OSX) |
26 import Cocoa | 24 import Cocoa |
27 #endif | 25 #endif |
28 | 26 |
29 // swiftlint:disable function_body_length | 27 // swiftlint:disable function_body_length |
30 | 28 |
31 class FavIconTests: XCTestCase { | 29 class FavIconTests: XCTestCase { |
(...skipping 28 matching lines...) Expand all Loading... |
60 XCTFail("failed to download icons: \(error)") | 58 XCTFail("failed to download icons: \(error)") |
61 } | 59 } |
62 } | 60 } |
63 | 61 |
64 XCTAssertEqual(1, actualResults.count) | 62 XCTAssertEqual(1, actualResults.count) |
65 | 63 |
66 switch actualResults[0] { | 64 switch actualResults[0] { |
67 case .success(let image): | 65 case .success(let image): |
68 XCTAssertEqual(32, image.size.width) | 66 XCTAssertEqual(32, image.size.width) |
69 XCTAssertEqual(32, image.size.height) | 67 XCTAssertEqual(32, image.size.height) |
70 break | |
71 case .failure(let error): | 68 case .failure(let error): |
72 XCTFail("unexpected error returned for download: \(error)") | 69 XCTFail("unexpected error returned for download: \(error)") |
73 break | |
74 } | 70 } |
75 } | 71 } |
76 | 72 |
77 func testChooseIcon() { | 73 func testChooseIcon() { |
78 let mixedIcons = [ | 74 let mixedIcons = [ |
79 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty
pe: .shortcut, width: 32, height: 32), | 75 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty
pe: .shortcut, width: 32, height: 32), |
80 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty
pe: .classic, width: 64, height: 64), | 76 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty
pe: .classic, width: 64, height: 64), |
81 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty
pe: .appleIOSWebClip, width: 64, height: 64), | 77 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty
pe: .appleIOSWebClip, width: 64, height: 64), |
82 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty
pe: .appleOSXSafariTab, width: 144, height: 144), | 78 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty
pe: .appleOSXSafariTab, width: 144, height: 144), |
83 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty
pe: .classic) | 79 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty
pe: .classic) |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 private extension XCTestCase { | 304 private extension XCTestCase { |
309 func performWebRequest(name: String, timeout: TimeInterval = 50000.0, callba
ck: (@escaping () -> Void) -> Void) { | 305 func performWebRequest(name: String, timeout: TimeInterval = 50000.0, callba
ck: (@escaping () -> Void) -> Void) { |
310 FavIcon.urlSessionProvider = { URLSession.shared } | 306 FavIcon.urlSessionProvider = { URLSession.shared } |
311 let expectation = self.expectation(description: "web request - \(name)") | 307 let expectation = self.expectation(description: "web request - \(name)") |
312 callback(expectation.fulfill) | 308 callback(expectation.fulfill) |
313 waitForExpectations(timeout: timeout, handler: nil) | 309 waitForExpectations(timeout: timeout, handler: nil) |
314 } | 310 } |
315 } | 311 } |
316 | 312 |
317 // swiftlint:enable function_body_length | 313 // swiftlint:enable function_body_length |
LEFT | RIGHT |