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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const { Service } = ChromeUtils.import("resource://services-sync/service.js");
let syncedEngines = [];
function SteamEngine() {
SyncEngine.call(this, "Steam", Service);
}
SteamEngine.prototype = {
__proto__: SyncEngine.prototype,
async _sync() {
syncedEngines.push(this.name);
},
};
function StirlingEngine() {
SyncEngine.call(this, "Stirling", Service);
}
StirlingEngine.prototype = {
__proto__: SteamEngine.prototype,
async _sync() {
syncedEngines.push(this.name);
},
};
// Tracking info/collections.
var collectionsHelper = track_collections_helper();
var upd = collectionsHelper.with_updated_collection;
function sync_httpd_setup(handlers) {
handlers["/1.1/johndoe/info/collections"] = collectionsHelper.handler;
delete collectionsHelper.collections.crypto;
delete collectionsHelper.collections.meta;
let cr = new ServerWBO("keys");
handlers["/1.1/johndoe/storage/crypto/keys"] = upd("crypto", cr.handler());
let cl = new ServerCollection();
handlers["/1.1/johndoe/storage/clients"] = upd("clients", cl.handler());
return httpd_setup(handlers);
}
async function setUp() {
syncedEngines = [];
let engine = Service.engineManager.get("steam");
engine.enabled = true;
engine.syncPriority = 1;
engine = Service.engineManager.get("stirling");
engine.enabled = true;
engine.syncPriority = 2;
let server = sync_httpd_setup({
"/1.1/johndoe/storage/meta/global": new ServerWBO("global", {}).handler(),
});
await SyncTestingInfrastructure(server, "johndoe", "ilovejane");
return server;
}
add_task(async function setup() {
await Service.engineManager.clear();
validate_all_future_pings();
await Service.engineManager.register(SteamEngine);
await Service.engineManager.register(StirlingEngine);
});
add_task(async function test_noEngines() {
enableValidationPrefs();
_("Test: An empty array of engines to sync does nothing.");
let server = await setUp();
try {
_("Sync with no engines specified.");
await Service.sync({ engines: [] });
deepEqual(syncedEngines, [], "no engines were synced");
} finally {
await Service.startOver();
await promiseStopServer(server);
}
});
add_task(async function test_oneEngine() {
enableValidationPrefs();
_("Test: Only one engine is synced.");
let server = await setUp();
try {
_("Sync with 1 engine specified.");
await Service.sync({ engines: ["steam"] });
deepEqual(syncedEngines, ["steam"]);
} finally {
await Service.startOver();
await promiseStopServer(server);
}
});
add_task(async function test_bothEnginesSpecified() {
enableValidationPrefs();
_("Test: All engines are synced when specified in the correct order (1).");
let server = await setUp();
try {
_("Sync with both engines specified.");
await Service.sync({ engines: ["steam", "stirling"] });
deepEqual(syncedEngines, ["steam", "stirling"]);
} finally {
await Service.startOver();
await promiseStopServer(server);
}
});
add_task(async function test_bothEnginesSpecified() {
enableValidationPrefs();
_("Test: All engines are synced when specified in the correct order (2).");
let server = await setUp();
try {
_("Sync with both engines specified.");
await Service.sync({ engines: ["stirling", "steam"] });
deepEqual(syncedEngines, ["stirling", "steam"]);
} finally {
await Service.startOver();
await promiseStopServer(server);
}
});
add_task(async function test_bothEnginesDefault() {
enableValidationPrefs();
_("Test: All engines are synced when nothing is specified.");
let server = await setUp();
try {
await Service.sync();
deepEqual(syncedEngines, ["steam", "stirling"]);
} finally {
await Service.startOver();
await promiseStopServer(server);
}
});
|