forked from mozilla-mobile/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MockProfile.swift
172 lines (135 loc) · 4.49 KB
/
MockProfile.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* 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/. */
import Foundation
import Account
import ReadingList
import Shared
import Storage
import Sync
import XCTest
public class MockSyncManager: SyncManager {
public var isSyncing = false
public func syncClients() -> SyncResult { return deferMaybe(.Completed) }
public func syncClientsThenTabs() -> SyncResult { return deferMaybe(.Completed) }
public func syncHistory() -> SyncResult { return deferMaybe(.Completed) }
public func syncLogins() -> SyncResult { return deferMaybe(.Completed) }
public func syncEverything() -> Success {
return succeed()
}
public func beginTimedSyncs() {}
public func endTimedSyncs() {}
public func onAddedAccount() -> Success {
return succeed()
}
public func onRemovedAccount(account: FirefoxAccount?) -> Success {
return succeed()
}
}
public class MockTabQueue: TabQueue {
public func addToQueue(tab: ShareItem) -> Success {
return succeed()
}
public func getQueuedTabs() -> Deferred<Maybe<Cursor<ShareItem>>> {
return deferMaybe(ArrayCursor<ShareItem>(data: []))
}
public func clearQueuedTabs() -> Success {
return succeed()
}
}
public class MockProfile: Profile {
private let name: String = "mockaccount"
func localName() -> String {
return name
}
func shutdown() {
if dbCreated {
db.close()
}
}
private var dbCreated = false
lazy var db: BrowserDB = {
self.dbCreated = true
return BrowserDB(filename: "mock.db", files: self.files)
}()
/**
* Favicons, history, and bookmarks are all stored in one intermeshed
* collection of tables.
*/
private lazy var places: protocol<BrowserHistory, Favicons, SyncableHistory> = {
return SQLiteHistory(db: self.db)!
}()
var favicons: Favicons {
return self.places
}
lazy var queue: TabQueue = {
return MockTabQueue()
}()
var history: protocol<BrowserHistory, SyncableHistory> {
return self.places
}
lazy var syncManager: SyncManager = {
return MockSyncManager()
}()
lazy var bookmarks: protocol<BookmarksModelFactory, ShareToDestination> = {
// Make sure the rest of our tables are initialized before we try to read them!
// This expression is for side-effects only.
let p = self.places
return SQLiteBookmarks(db: self.db)
}()
lazy var searchEngines: SearchEngines = {
return SearchEngines(prefs: self.prefs)
}()
lazy var prefs: Prefs = {
return MockProfilePrefs()
}()
lazy var files: FileAccessor = {
return ProfileFileAccessor(profile: self)
}()
lazy var readingList: ReadingListService? = {
return ReadingListService(profileStoragePath: self.files.rootPath as String)
}()
private lazy var remoteClientsAndTabs: RemoteClientsAndTabs = {
return SQLiteRemoteClientsAndTabs(db: self.db)
}()
private lazy var syncCommands: SyncCommands = {
return SQLiteRemoteClientsAndTabs(db: self.db)
}()
lazy var logins: protocol<BrowserLogins, SyncableLogins> = {
return MockLogins(files: self.files)
}()
let accountConfiguration: FirefoxAccountConfiguration = ProductionFirefoxAccountConfiguration()
var account: FirefoxAccount? = nil
func hasAccount() -> Bool {
return account != nil
}
func hasSyncableAccount() -> Bool {
return account?.actionNeeded == FxAActionNeeded.None
}
func getAccount() -> FirefoxAccount? {
return account
}
func setAccount(account: FirefoxAccount) {
self.account = account
self.syncManager.onAddedAccount()
}
func removeAccount() {
let old = self.account
self.account = nil
self.syncManager.onRemovedAccount(old)
}
func getClients() -> Deferred<Maybe<[RemoteClient]>> {
return deferMaybe([])
}
func getClientsAndTabs() -> Deferred<Maybe<[ClientAndTabs]>> {
return deferMaybe([])
}
func getCachedClientsAndTabs() -> Deferred<Maybe<[ClientAndTabs]>> {
return deferMaybe([])
}
func storeTabs(tabs: [RemoteTab]) -> Deferred<Maybe<Int>> {
return deferMaybe(0)
}
func sendItems(items: [ShareItem], toClients clients: [RemoteClient]) {
}
}