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
import UIKit
6
import XCTest
7
@testable import Client
8
import Shared
9
import Storage
10
import SyncTelemetry
11
12
class FirefoxHomeTests: XCTestCase {
13
var profile: MockProfile!
14
var vc: FirefoxHomeViewController!
15
16
override func setUp() {
17
super.setUp()
18
self.profile = MockProfile()
19
self.vc = FirefoxHomeViewController(profile: self.profile)
20
}
21
22
override func tearDown() {
23
self.profile._shutdown()
24
super.tearDown()
25
}
26
27
func testDeletionOfSingleSuggestedSite() {
28
let siteToDelete = vc.defaultTopSites()[0]
29
30
vc.hideURLFromTopSites(siteToDelete)
31
let newSites = vc.defaultTopSites()
32
33
XCTAssertFalse(newSites.contains(siteToDelete, f: { (a, b) -> Bool in
34
return a.url == b.url
35
}))
36
}
37
38
func testDeletionOfAllDefaultSites() {
39
let defaultSites = vc.defaultTopSites()
40
defaultSites.forEach({
41
vc.hideURLFromTopSites($0)
42
})
43
44
let newSites = vc.defaultTopSites()
45
XCTAssertTrue(newSites.isEmpty)
46
}
47
}
48
49
fileprivate class MockTopSitesHistory: MockableHistory {
50
let mockTopSites: [Site]
51
52
init(sites: [Site]) {
53
mockTopSites = sites
54
}
55
56
override func getTopSitesWithLimit(_ limit: Int) -> Deferred<Maybe<Cursor<Site>>> {
57
return deferMaybe(ArrayCursor(data: mockTopSites))
58
}
59
60
override func getPinnedTopSites() -> Deferred<Maybe<Cursor<Site>>> {
61
return deferMaybe(ArrayCursor(data: []))
62
}
63
64
override func updateTopSitesCacheIfInvalidated() -> Deferred<Maybe<Bool>> {
65
return deferMaybe(true)
66
}
67
}