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
|
add_task(async function invalid_input_throws() {
Assert.throws(
() => PlacesUtils.bookmarks.getRecent(),
/numberOfItems argument is required/
);
Assert.throws(
() => PlacesUtils.bookmarks.getRecent("abc"),
/numberOfItems argument must be an integer/
);
Assert.throws(
() => PlacesUtils.bookmarks.getRecent(1.2),
/numberOfItems argument must be an integer/
);
Assert.throws(
() => PlacesUtils.bookmarks.getRecent(0),
/numberOfItems argument must be greater than zero/
);
Assert.throws(
() => PlacesUtils.bookmarks.getRecent(-1),
/numberOfItems argument must be greater than zero/
);
});
add_task(async function getRecent_returns_recent_bookmarks() {
await PlacesUtils.bookmarks.eraseEverything();
let bm1 = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.com/",
title: "a bookmark",
});
let bm2 = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.org/path",
title: "another bookmark",
});
let bm3 = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.net/",
title: "another bookmark",
});
let bm4 = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.net/path",
title: "yet another bookmark",
});
checkBookmarkObject(bm1);
checkBookmarkObject(bm2);
checkBookmarkObject(bm3);
checkBookmarkObject(bm4);
// Add a tag to the most recent url to prove it doesn't get returned.
PlacesUtils.tagging.tagURI(uri(bm4.url), ["Test Tag"]);
// Add a separator.
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
});
// Add a query bookmark.
let queryURL = `place:parent=${PlacesUtils.bookmarks.menuGuid}&queryType=1`;
let bm5 = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: queryURL,
title: "a test query",
});
checkBookmarkObject(bm5);
// Verify that getRecent only returns actual bookmarks.
let results = await PlacesUtils.bookmarks.getRecent(100);
Assert.equal(
results.length,
4,
"The expected number of bookmarks was returned."
);
checkBookmarkObject(results[0]);
Assert.deepEqual(
bm4,
results[0],
"The first result is the expected bookmark."
);
checkBookmarkObject(results[1]);
Assert.deepEqual(
bm3,
results[1],
"The second result is the expected bookmark."
);
checkBookmarkObject(results[2]);
Assert.deepEqual(
bm2,
results[2],
"The third result is the expected bookmark."
);
checkBookmarkObject(results[3]);
Assert.deepEqual(
bm1,
results[3],
"The fourth result is the expected bookmark."
);
// Verify that getRecent utilizes the numberOfItems argument.
results = await PlacesUtils.bookmarks.getRecent(1);
Assert.equal(
results.length,
1,
"The expected number of bookmarks was returned."
);
checkBookmarkObject(results[0]);
Assert.deepEqual(
bm4,
results[0],
"The first result is the expected bookmark."
);
await PlacesUtils.bookmarks.eraseEverything();
});
|