-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_bookmark_validation.js
112 lines (106 loc) · 3.34 KB
/
test_bookmark_validation.js
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
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
add_task(async function test_inconsistencies() {
let buf = await openMirror("inconsistencies");
info("Set up local tree");
await PlacesUtils.bookmarks.insertTree({
guid: PlacesUtils.bookmarks.menuGuid,
source: PlacesUtils.bookmarks.SOURCE_SYNC,
children: [{
// NORMAL bookmark that exists in the mirror; not an inconsistency.
guid: "bookmarkAAAA",
title: "A",
url: "http://example.com/a",
}, {
// NORMAL bookmark that doesn't exist in the mirror at all.
guid: "bookmarkBBBB",
title: "B",
url: "http://example.com/b",
}, {
// NORMAL bookmark with a tombstone that doesn't exist in the mirror.
guid: "bookmarkCCCC",
title: "C",
url: "http://example.com/c",
}, {
// NORMAL bookmark with a tombstone that exists in the mirror; not an
// inconsistency.
guid: "bookmarkDDDD",
title: "D",
url: "http://example.com/d",
}],
});
await PlacesUtils.bookmarks.insertTree({
guid: PlacesUtils.bookmarks.toolbarGuid,
children: [{
// NEW bookmark that doesn't exist in the mirror; not an inconsistency.
guid: "bookmarkEEEE",
title: "E",
url: "http://example.com/e",
}, {
// NEW bookmark that exists in the mirror.
guid: "bookmarkFFFF",
title: "F",
url: "http://example.com/f",
}],
});
await PlacesUtils.bookmarks.remove("bookmarkCCCC");
await PlacesUtils.bookmarks.remove("bookmarkDDDD");
deepEqual(await buf.fetchSyncStatusMismatches(), {
missingLocal: [],
missingRemote: [],
wrongSyncStatus: [],
}, "Should not report inconsistencies with empty mirror");
info("Set up mirror");
await storeRecords(buf, [{
id: "menu",
type: "folder",
children: ["bookmarkAAAA", "bookmarkDDDD"],
}, {
id: "toolbar",
type: "folder",
children: ["bookmarkFFFF"],
}, {
id: "bookmarkAAAA",
type: "bookmark",
title: "A",
bmkUri: "http://example.com/a",
}, {
id: "bookmarkDDDD",
type: "bookmark",
title: "D",
bmkUri: "http://example.com/d",
}, {
id: "bookmarkFFFF",
type: "bookmark",
title: "F",
bmkUri: "http://example.com/f",
}, {
// Merged bookmark that doesn't exist locally.
id: "bookmarkGGGG",
type: "bookmark",
title: "G",
bmkUri: "http://example.com/g",
}], { needsMerge: false });
await storeRecords(buf, [{
id: "bookmarkHHHH",
type: "bookmark",
title: "H",
bmkUri: "http://example.com/h",
}, {
id: "bookmarkIIII",
deleted: true,
}]);
let { missingLocal, missingRemote, wrongSyncStatus } =
await buf.fetchSyncStatusMismatches();
deepEqual(missingLocal, ["bookmarkGGGG"],
"Should report merged remote items that don't exist locally");
deepEqual(missingRemote.sort(), ["bookmarkBBBB", "bookmarkCCCC"],
"Should report NORMAL local items that don't exist remotely");
deepEqual(wrongSyncStatus.sort(), [PlacesUtils.bookmarks.menuGuid,
PlacesUtils.bookmarks.toolbarGuid, PlacesUtils.bookmarks.unfiledGuid,
PlacesUtils.bookmarks.mobileGuid, "bookmarkFFFF"].sort(),
"Should report remote items with wrong local sync status");
await buf.finalize();
await PlacesUtils.bookmarks.eraseEverything();
await PlacesSyncUtils.bookmarks.reset();
});