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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
add_task(async function test_eraseEverything() {
await PlacesTestUtils.addVisits({
uri: NetUtil.newURI("http://example.com/"),
});
await PlacesTestUtils.addVisits({
uri: NetUtil.newURI("http://mozilla.org/"),
});
let frecencyForExample = frecencyForUrl("http://example.com/");
let frecencyForMozilla = frecencyForUrl("http://example.com/");
Assert.ok(frecencyForExample > 0);
Assert.ok(frecencyForMozilla > 0);
let unfiledFolder = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
type: PlacesUtils.bookmarks.TYPE_FOLDER,
});
checkBookmarkObject(unfiledFolder);
let unfiledBookmark = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: "http://example.com/",
});
checkBookmarkObject(unfiledBookmark);
let unfiledBookmarkInFolder = await PlacesUtils.bookmarks.insert({
parentGuid: unfiledFolder.guid,
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: "http://mozilla.org/",
});
checkBookmarkObject(unfiledBookmarkInFolder);
let menuFolder = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.menuGuid,
type: PlacesUtils.bookmarks.TYPE_FOLDER,
});
checkBookmarkObject(menuFolder);
let menuBookmark = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.menuGuid,
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: "http://example.com/",
});
checkBookmarkObject(menuBookmark);
let menuBookmarkInFolder = await PlacesUtils.bookmarks.insert({
parentGuid: menuFolder.guid,
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: "http://mozilla.org/",
});
checkBookmarkObject(menuBookmarkInFolder);
let toolbarFolder = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
type: PlacesUtils.bookmarks.TYPE_FOLDER,
});
checkBookmarkObject(toolbarFolder);
let toolbarBookmark = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: "http://example.com/",
});
checkBookmarkObject(toolbarBookmark);
let toolbarBookmarkInFolder = await PlacesUtils.bookmarks.insert({
parentGuid: toolbarFolder.guid,
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: "http://mozilla.org/",
});
checkBookmarkObject(toolbarBookmarkInFolder);
await PlacesTestUtils.promiseAsyncUpdates();
Assert.ok(frecencyForUrl("http://example.com/") > frecencyForExample);
Assert.ok(frecencyForUrl("http://example.com/") > frecencyForMozilla);
const promise = PlacesTestUtils.waitForNotification(
"pages-rank-changed",
() => true,
"places"
);
await PlacesUtils.bookmarks.eraseEverything();
// Ensure we get an pages-rank-changed event.
await promise;
Assert.equal(frecencyForUrl("http://example.com/"), frecencyForExample);
Assert.equal(frecencyForUrl("http://example.com/"), frecencyForMozilla);
});
add_task(async function test_eraseEverything_roots() {
await PlacesUtils.bookmarks.eraseEverything();
// Ensure the roots have not been removed.
Assert.ok(
await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.unfiledGuid)
);
Assert.ok(
await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.toolbarGuid)
);
Assert.ok(await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.menuGuid));
Assert.ok(await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.tagsGuid));
Assert.ok(await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.rootGuid));
});
add_task(async function test_eraseEverything_reparented() {
// Create a folder with 1 bookmark in it...
let folder1 = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
type: PlacesUtils.bookmarks.TYPE_FOLDER,
});
let bookmark1 = await PlacesUtils.bookmarks.insert({
parentGuid: folder1.guid,
url: "http://example.com/",
});
// ...and a second folder.
let folder2 = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
type: PlacesUtils.bookmarks.TYPE_FOLDER,
});
// Reparent the bookmark to the 2nd folder.
bookmark1.parentGuid = folder2.guid;
await PlacesUtils.bookmarks.update(bookmark1);
// Erase everything.
await PlacesUtils.bookmarks.eraseEverything();
// All the above items should no longer be in the GUIDHelper cache.
for (let guid of [folder1.guid, bookmark1.guid, folder2.guid]) {
await Assert.rejects(
PlacesUtils.promiseItemId(guid),
/no item found for the given GUID/
);
}
});
add_task(async function test_notifications() {
let bms = await PlacesUtils.bookmarks.insertTree({
guid: PlacesUtils.bookmarks.unfiledGuid,
children: [
{
title: "test",
url: "http://example.com",
},
{
title: "folder",
type: PlacesUtils.bookmarks.TYPE_FOLDER,
children: [
{
title: "test2",
url: "http://example.com/2",
},
],
},
],
});
let skipDescendantsObserver = expectPlacesObserverNotifications(
["bookmark-removed"],
false,
true
);
let receiveAllObserver = expectPlacesObserverNotifications(
["bookmark-removed"],
false
);
await PlacesUtils.bookmarks.eraseEverything();
let expectedNotifications = [
{
type: "bookmark-removed",
guid: bms[1].guid,
},
{
type: "bookmark-removed",
guid: bms[0].guid,
},
];
// If we're skipping descendents, we'll only be notified of the folder.
skipDescendantsObserver.check(expectedNotifications);
// Note: Items of folders get notified first.
expectedNotifications.unshift({
type: "bookmark-removed",
guid: bms[2].guid,
});
receiveAllObserver.check(expectedNotifications);
});
|