Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: FavIconTests/FavIconsTests.swift

Issue 29664569: Favicon: Issue 6245 - SwiftLinted project files (Closed)
Patch Set: Removed the sorted_imports rule and reversed the import calls to be sorted alphabetically Created Feb. 19, 2018, 10:38 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « FavIcon/Utils.swift ('k') | FavIconTests/HTMLDocumentTests.swift » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 @testable import FavIcon
18 import XCTest 19 import XCTest
19 @testable import FavIcon
20 20
21 #if os(iOS) 21 #if os(iOS)
22 import UIKit 22 import UIKit
23 #elseif os(OSX) 23 #elseif os(OSX)
24 import Cocoa 24 import Cocoa
25 #endif 25 #endif
26 26
27 // swiftlint:disable function_body_length 27 // swiftlint:disable function_body_length
28 // swiftlint:disable line_length
29 28
30 class FavIconTests: XCTestCase { 29 class FavIconTests: XCTestCase {
31 func testScan() { 30 func testScan() {
32 var actualIcons: [DetectedIcon] = [] 31 var actualIcons: [DetectedIcon] = []
33 32
34 performWebRequest(name: "scan") { requestCompleted in 33 performWebRequest(name: "scan") { requestCompleted in
35 do { 34 do {
36 try FavIcon.scan("https://apple.com") { icons, meta in 35 try FavIcon.scan("https://apple.com") { icons, _ in
37 actualIcons = icons 36 actualIcons = icons
38 requestCompleted() 37 requestCompleted()
39 } 38 }
40 } catch let error { 39 } catch let error {
41 XCTFail("failed to detect icons: \(error)") 40 XCTFail("failed to detect icons: \(error)")
42 } 41 }
43 } 42 }
44 43
45 XCTAssertEqual(1, actualIcons.count) 44 XCTAssertEqual(1, actualIcons.count)
46 XCTAssertEqual(URL(string: "https://www.apple.com/favicon.ico")!, actual Icons[0].url) 45 XCTAssertEqual(URL(string: "https://www.apple.com/favicon.ico")!, actual Icons[0].url)
(...skipping 12 matching lines...) Expand all
59 XCTFail("failed to download icons: \(error)") 58 XCTFail("failed to download icons: \(error)")
60 } 59 }
61 } 60 }
62 61
63 XCTAssertEqual(1, actualResults.count) 62 XCTAssertEqual(1, actualResults.count)
64 63
65 switch actualResults[0] { 64 switch actualResults[0] {
66 case .success(let image): 65 case .success(let image):
67 XCTAssertEqual(32, image.size.width) 66 XCTAssertEqual(32, image.size.width)
68 XCTAssertEqual(32, image.size.height) 67 XCTAssertEqual(32, image.size.height)
69 break
70 case .failure(let error): 68 case .failure(let error):
71 XCTFail("unexpected error returned for download: \(error)") 69 XCTFail("unexpected error returned for download: \(error)")
72 break
73 } 70 }
74 } 71 }
75 72
76 func testChooseIcon() { 73 func testChooseIcon() {
77 let mixedIcons = [ 74 let mixedIcons = [
78 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),
79 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),
80 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),
81 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),
82 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
307 private extension XCTestCase { 304 private extension XCTestCase {
308 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) {
309 FavIcon.urlSessionProvider = { URLSession.shared } 306 FavIcon.urlSessionProvider = { URLSession.shared }
310 let expectation = self.expectation(description: "web request - \(name)") 307 let expectation = self.expectation(description: "web request - \(name)")
311 callback(expectation.fulfill) 308 callback(expectation.fulfill)
312 waitForExpectations(timeout: timeout, handler: nil) 309 waitForExpectations(timeout: timeout, handler: nil)
313 } 310 }
314 } 311 }
315 312
316 // swiftlint:enable function_body_length 313 // swiftlint:enable function_body_length
317 // swiftlint:enable line_length
OLDNEW
« no previous file with comments | « FavIcon/Utils.swift ('k') | FavIconTests/HTMLDocumentTests.swift » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld