forked from mozilla-mobile/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResetTests.swift
78 lines (61 loc) · 2.48 KB
/
ResetTests.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* 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
@testable import Storage
import Sync
import UIKit
import XCTest
class MockBrowserProfile: BrowserProfile {
var peekSyncManager: BrowserSyncManager {
return self.syncManager as! BrowserSyncManager
}
var peekTabs: SQLiteRemoteClientsAndTabs {
return self.remoteClientsAndTabs as! SQLiteRemoteClientsAndTabs
}
}
class MockEngineStateChanges: EngineStateChanges {
var collections: [String] = []
var enabled: [String] = []
var disabled: [String] = []
var clearWasCalled: Bool = false
func collectionsThatNeedLocalReset() -> [String] {
return self.collections
}
func enginesEnabled() -> [String] {
return self.enabled
}
func enginesDisabled() -> [String] {
return self.disabled
}
func clearLocalCommands() {
clearWasCalled = true
}
}
func assertClientsHaveGUIDsFromStorage(_ storage: RemoteClientsAndTabs, expected: [GUID]) {
let recs = storage.getClients().value.successValue
XCTAssertNotNil(recs)
XCTAssertEqual(expected, recs!.map { $0.guid! })
}
class ResetTests: XCTestCase {
func testResetting() {
let profile = MockBrowserProfile(localName: "testResetTests")
// Add a client.
let tabs = profile.peekTabs
XCTAssertTrue(tabs.insertOrUpdateClient(RemoteClient(guid: "abcdefghijkl", name: "Remote", modified: Date.now(), type: "mobile", formfactor: "tablet", os: "Windows", version: "55.0.1a", fxaDeviceId: "fxa1")).value.isSuccess)
_ = tabs.replaceRemoteDevices([RemoteDevice(id: "fxa1", name: "Device 1", type: "desktop", isCurrentDevice: false, lastAccessTime: 123, availableCommands: [:])]).succeeded()
// Verify that it's there.
assertClientsHaveGUIDsFromStorage(tabs, expected: ["abcdefghijkl"])
// Tell the sync manager that "clients" has changed syncID.
let e = MockEngineStateChanges()
e.collections.append("clients")
XCTAssertTrue(profile.peekSyncManager.takeActionsOnEngineStateChanges(e).value.isSuccess)
// We threw away the command.
XCTAssertTrue(e.clearWasCalled)
// And now we have no local clients.
let empty = tabs.getClients().value.successValue
XCTAssertNotNil(empty)
XCTAssertEqual(empty!, [])
}
}