forked from mozilla-mobile/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomSearchEnginesTest.swift
60 lines (50 loc) · 2.43 KB
/
CustomSearchEnginesTest.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
58
59
60
/* 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/. */
@testable import Client
import Shared
import Storage
import Sync
import UIKit
import XCTest
class CustomSearchEnginesTest: XCTestCase {
func testgetSearchTemplate() {
let profile = MockBrowserProfile(localName: "customSearchTests")
let customSearchEngineForm = CustomSearchViewController()
customSearchEngineForm.profile = profile
let template = customSearchEngineForm.getSearchTemplate(withString: "https://github.com/search=%s")
XCTAssertEqual(template, "https://github.com/search={searchTerms}")
let badTemplate = customSearchEngineForm.getSearchTemplate(withString: "https://github.com/search=blah")
XCTAssertNil(badTemplate)
}
func testaddSearchEngine() {
let profile = MockBrowserProfile(localName: "customSearchTests")
let customSearchEngineForm = CustomSearchViewController()
customSearchEngineForm.profile = profile
let q = "http://www.google.ca/?#q=%s"
let title = "YASE"
let expectation = self.expectation(description: "Waiting on favicon fetching")
customSearchEngineForm.createEngine(forQuery: q, andName: title).uponQueue(.main) { result in
XCTAssertNotNil(result.successValue, "Make sure the new engine is not nil")
let engine = result.successValue!
XCTAssertEqual(engine.shortName, title)
XCTAssertNotNil(engine.image)
XCTAssertEqual(engine.searchTemplate, "http://www.google.ca/?#q={searchTerms}")
expectation.fulfill()
}
waitForExpectations(timeout: 5, handler: nil)
}
func testaddSearchEngineFailure() {
let profile = MockBrowserProfile(localName: "customSearchTests")
let customSearchEngineForm = CustomSearchViewController()
customSearchEngineForm.profile = profile
let q = "isthisvalid.com/hhh%s"
let title = "YASE"
let expectation = self.expectation(description: "Waiting on favicon fetching")
customSearchEngineForm.createEngine(forQuery: q, andName: title).uponQueue(.main) { result in
XCTAssertNil(result.successValue, "Make sure the new engine is nil")
expectation.fulfill()
}
waitForExpectations(timeout: 5, handler: nil)
}
}