Revision control

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
@testable import Client
6
import Shared
7
import Storage
8
import Sync
9
import UIKit
10
11
import XCTest
12
13
class CustomSearchEnginesTest: XCTestCase {
14
15
func testgetSearchTemplate() {
16
let profile = MockBrowserProfile(localName: "customSearchTests")
17
let customSearchEngineForm = CustomSearchViewController()
18
customSearchEngineForm.profile = profile
19
20
let template = customSearchEngineForm.getSearchTemplate(withString: "https://github.com/search=%s")
21
XCTAssertEqual(template, "https://github.com/search={searchTerms}")
22
23
let badTemplate = customSearchEngineForm.getSearchTemplate(withString: "https://github.com/search=blah")
24
XCTAssertNil(badTemplate)
25
}
26
27
func testaddSearchEngine() {
28
let profile = MockBrowserProfile(localName: "customSearchTests")
29
let customSearchEngineForm = CustomSearchViewController()
30
customSearchEngineForm.profile = profile
32
let title = "YASE"
33
34
let expectation = self.expectation(description: "Waiting on favicon fetching")
35
customSearchEngineForm.createEngine(forQuery: q, andName: title).uponQueue(.main) { result in
36
XCTAssertNotNil(result.successValue, "Make sure the new engine is not nil")
37
let engine = result.successValue!
38
XCTAssertEqual(engine.shortName, title)
39
XCTAssertNotNil(engine.image)
40
XCTAssertEqual(engine.searchTemplate, "http://www.google.ca/?#q={searchTerms}")
41
expectation.fulfill()
42
}
43
waitForExpectations(timeout: 5, handler: nil)
44
}
45
46
func testaddSearchEngineFailure() {
47
let profile = MockBrowserProfile(localName: "customSearchTests")
48
let customSearchEngineForm = CustomSearchViewController()
49
customSearchEngineForm.profile = profile
50
let q = "isthisvalid.com/hhh%s"
51
let title = "YASE"
52
53
let expectation = self.expectation(description: "Waiting on favicon fetching")
54
customSearchEngineForm.createEngine(forQuery: q, andName: title).uponQueue(.main) { result in
55
XCTAssertNil(result.successValue, "Make sure the new engine is nil")
56
expectation.fulfill()
57
}
58
waitForExpectations(timeout: 5, handler: nil)
59
}
60
}