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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// This test ensures that observeHistoryDetails works as expected.
function accumulateNotifications(result, observeHistoryDetails = true) {
let notifications = [];
let resultObserver = new Proxy(NavHistoryResultObserver, {
get(target, name) {
if (name == "check") {
result.removeObserver(resultObserver, false);
return expectedNotifications =>
Assert.deepEqual(notifications, expectedNotifications);
}
if (name == "observeHistoryDetails") {
return observeHistoryDetails;
}
// ignore a few uninteresting notifications.
if (["QueryInterface", "containerStateChanged"].includes(name)) {
return () => {};
}
return () => {
notifications.push(name);
};
},
});
result.addObserver(resultObserver, false);
return resultObserver;
}
add_task(async function test_history_query_observe() {
let query = PlacesUtils.history.getNewQuery();
let options = PlacesUtils.history.getNewQueryOptions();
let result = PlacesUtils.history.executeQuery(query, options);
let notifications = accumulateNotifications(result);
let root = PlacesUtils.asContainer(result.root);
root.containerOpen = true;
await PlacesTestUtils.addVisits({
uri: "http://mozilla.org",
title: "test",
});
notifications.check([
"nodeHistoryDetailsChanged",
"nodeInserted",
"nodeTitleChanged",
]);
root.containerOpen = false;
await PlacesUtils.history.clear();
});
add_task(async function test_history_query_no_observe() {
let query = PlacesUtils.history.getNewQuery();
let options = PlacesUtils.history.getNewQueryOptions();
let result = PlacesUtils.history.executeQuery(query, options);
// Even if we opt-out of notifications, this is an history query, thus the
// setting is pretty much ignored.
let notifications = accumulateNotifications(result, false);
let root = PlacesUtils.asContainer(result.root);
root.containerOpen = true;
await PlacesTestUtils.addVisits({
uri: "http://mozilla.org",
title: "test",
});
await PlacesTestUtils.addVisits({
uri: "http://mozilla2.org",
title: "test",
});
notifications.check([
"nodeHistoryDetailsChanged",
"nodeInserted",
"nodeTitleChanged",
"nodeHistoryDetailsChanged",
"nodeInserted",
"nodeTitleChanged",
]);
root.containerOpen = false;
await PlacesUtils.history.clear();
});
add_task(async function test_bookmarks_query_observe() {
let query = PlacesUtils.history.getNewQuery();
query.setParents([PlacesUtils.bookmarks.toolbarGuid]);
let options = PlacesUtils.history.getNewQueryOptions();
options.queryType = options.QUERY_TYPE_BOOKMARKS;
let result = PlacesUtils.history.executeQuery(query, options);
let notifications = accumulateNotifications(result);
let root = PlacesUtils.asContainer(result.root);
root.containerOpen = true;
await PlacesUtils.bookmarks.insert({
url: "http://mozilla.org",
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
title: "test",
});
await PlacesTestUtils.addVisits({
uri: "http://mozilla.org",
title: "title",
});
notifications.check([
"nodeHistoryDetailsChanged",
"nodeInserted",
"nodeHistoryDetailsChanged",
]);
root.containerOpen = false;
await PlacesUtils.history.clear();
await PlacesUtils.bookmarks.eraseEverything();
});
add_task(async function test_bookmarks_query_no_observe() {
let query = PlacesUtils.history.getNewQuery();
query.setParents([PlacesUtils.bookmarks.toolbarGuid]);
let options = PlacesUtils.history.getNewQueryOptions();
options.queryType = options.QUERY_TYPE_BOOKMARKS;
let result = PlacesUtils.history.executeQuery(query, options);
let notifications = accumulateNotifications(result, false);
let root = PlacesUtils.asContainer(result.root);
root.containerOpen = true;
await PlacesUtils.bookmarks.insert({
url: "http://mozilla.org",
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
title: "test",
});
await PlacesTestUtils.addVisits({
uri: "http://mozilla.org",
title: "title",
});
notifications.check(["nodeInserted"]);
info("Change the sorting mode to one that is based on history");
notifications = accumulateNotifications(result, false);
result.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
notifications.check(["invalidateContainer"]);
notifications = accumulateNotifications(result, false);
await PlacesTestUtils.addVisits({
uri: "http://mozilla.org",
title: "title",
});
notifications.check(["nodeHistoryDetailsChanged"]);
root.containerOpen = false;
await PlacesUtils.bookmarks.eraseEverything();
});
|