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: Favicon: Issue 6245 - SwiftLinted project files Created Jan. 12, 2018, 4:50 p.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 // swiftlint:disable sorted_imports
19
18 import XCTest 20 import XCTest
19 @testable import FavIcon 21 @testable import FavIcon
20 22
21 #if os(iOS) 23 #if os(iOS)
22 import UIKit 24 import UIKit
23 #elseif os(OSX) 25 #elseif os(OSX)
24 import Cocoa 26 import Cocoa
25 #endif 27 #endif
26 28
27 // swiftlint:disable function_body_length 29 // swiftlint:disable function_body_length
28 // swiftlint:disable line_length
29 30
30 class FavIconTests: XCTestCase { 31 class FavIconTests: XCTestCase {
31 func testScan() { 32 func testScan() {
32 var actualIcons: [DetectedIcon] = [] 33 var actualIcons: [DetectedIcon] = []
33 34
34 performWebRequest(name: "scan") { requestCompleted in 35 performWebRequest(name: "scan") { requestCompleted in
35 do { 36 do {
36 try FavIcon.scan("https://apple.com") { icons, meta in 37 try FavIcon.scan("https://apple.com") { icons, _ in
37 actualIcons = icons 38 actualIcons = icons
38 requestCompleted() 39 requestCompleted()
39 } 40 }
40 } catch let error { 41 } catch let error {
41 XCTFail("failed to detect icons: \(error)") 42 XCTFail("failed to detect icons: \(error)")
42 } 43 }
43 } 44 }
44 45
45 XCTAssertEqual(1, actualIcons.count) 46 XCTAssertEqual(1, actualIcons.count)
46 XCTAssertEqual(URL(string: "https://www.apple.com/favicon.ico")!, actual Icons[0].url) 47 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)") 60 XCTFail("failed to download icons: \(error)")
60 } 61 }
61 } 62 }
62 63
63 XCTAssertEqual(1, actualResults.count) 64 XCTAssertEqual(1, actualResults.count)
64 65
65 switch actualResults[0] { 66 switch actualResults[0] {
66 case .success(let image): 67 case .success(let image):
67 XCTAssertEqual(32, image.size.width) 68 XCTAssertEqual(32, image.size.width)
68 XCTAssertEqual(32, image.size.height) 69 XCTAssertEqual(32, image.size.height)
69 break
70 case .failure(let error): 70 case .failure(let error):
71 XCTFail("unexpected error returned for download: \(error)") 71 XCTFail("unexpected error returned for download: \(error)")
72 break
73 } 72 }
74 } 73 }
75 74
76 func testChooseIcon() { 75 func testChooseIcon() {
77 let mixedIcons = [ 76 let mixedIcons = [
78 DetectedIcon(url: URL(string: "https://google.com/favicon.ico")!, ty pe: .shortcut, width: 32, height: 32), 77 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), 78 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), 79 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), 80 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) 81 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 { 306 private extension XCTestCase {
308 func performWebRequest(name: String, timeout: TimeInterval = 50000.0, callba ck: (@escaping () -> Void) -> Void) { 307 func performWebRequest(name: String, timeout: TimeInterval = 50000.0, callba ck: (@escaping () -> Void) -> Void) {
309 FavIcon.urlSessionProvider = { URLSession.shared } 308 FavIcon.urlSessionProvider = { URLSession.shared }
310 let expectation = self.expectation(description: "web request - \(name)") 309 let expectation = self.expectation(description: "web request - \(name)")
311 callback(expectation.fulfill) 310 callback(expectation.fulfill)
312 waitForExpectations(timeout: timeout, handler: nil) 311 waitForExpectations(timeout: timeout, handler: nil)
313 } 312 }
314 } 313 }
315 314
316 // swiftlint:enable function_body_length 315 // 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