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
|
"use strict";
const { SyncHistory } = ChromeUtils.import(
"resource://services-settings/SyncHistory.jsm"
);
async function clear_state() {
await new SyncHistory("").clear();
}
add_task(clear_state);
add_task(async function test_entries_are_stored_by_source() {
const history = new SyncHistory();
await history.store("42", "success", { pi: "3.14" });
// Check that history is isolated by source.
await new SyncHistory("main/cfr").store("88", "error");
const l = await history.list();
Assert.deepEqual(l, [
{
timestamp: 42,
status: "success",
infos: { pi: "3.14" },
datetime: new Date(42),
},
]);
});
add_task(clear_state);
add_task(
async function test_old_entries_are_removed_keep_fixed_size_per_source() {
const history = new SyncHistory("settings-sync", { size: 3 });
const anotherHistory = await new SyncHistory("main/cfr");
await history.store("42", "success");
await history.store("41", "sync_error");
await history.store("43", "up_to_date");
let l = await history.list();
Assert.equal(l.length, 3);
await history.store("44", "success");
await anotherHistory.store("44", "success");
l = await history.list();
Assert.equal(l.length, 3);
Assert.ok(!l.map(e => e.timestamp).includes(41));
l = await anotherHistory.list();
Assert.equal(l.length, 1);
}
);
add_task(clear_state);
add_task(async function test_entries_are_sorted_by_timestamp_desc() {
const history = new SyncHistory("settings-sync");
await history.store("42", "success");
await history.store("41", "sync_error");
await history.store("44", "up_to_date");
const l = await history.list();
Assert.deepEqual(
l.map(e => e.timestamp),
[44, 42, 41]
);
});
add_task(clear_state);
|