forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_onlyBookmarked.js
135 lines (115 loc) · 4.23 KB
/
test_onlyBookmarked.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* The next thing we do is create a test database for us. Each test runs with
* its own database (tail_queries.js will clear it after the run). Take a look
* at the queryData object in head_queries.js, and you'll see how this object
* works. You can call it anything you like, but I usually use "testData".
* I'll include a couple of example entries in the database.
*
* Note that to use the compareArrayToResult API, you need to put all the
* results that are in the query set at the top of the testData list, and those
* results MUST be in the same sort order as the items in the resulting query.
*/
var testData = [
// Add a bookmark that should be in the results
{ isBookmark: true,
uri: "http://bookmarked.com/",
parentFolder: PlacesUtils.toolbarFolderId,
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
title: "",
isInQuery: true },
// Add a bookmark that should not be in the results
{ isBookmark: true,
uri: "http://bookmarked-elsewhere.com/",
parentFolder: PlacesUtils.bookmarksMenuFolderId,
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
title: "",
isInQuery: false },
// Add an un-bookmarked visit
{ isVisit: true,
uri: "http://notbookmarked.com/",
isInQuery: false }
];
/**
* run_test is where the magic happens. This is automatically run by the test
* harness. It is where you do the work of creating the query, running it, and
* playing with the result set.
*/
function run_test()
{
run_next_test();
}
add_task(function test_onlyBookmarked()
{
// This function in head_queries.js creates our database with the above data
yield task_populateDB(testData);
// Query
var query = PlacesUtils.history.getNewQuery();
query.setFolders([PlacesUtils.toolbarFolderId], 1);
query.onlyBookmarked = true;
// query options
var options = PlacesUtils.history.getNewQueryOptions();
options.queryType = options.QUERY_TYPE_HISTORY;
// Results - this gets the result set and opens it for reading and modification.
var result = PlacesUtils.history.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
// You can use this to compare the data in the array with the result set,
// if the array's isInQuery: true items are sorted the same way as the result
// set.
LOG("begin first test");
compareArrayToResult(testData, root);
LOG("end first test");
/* ******************
Test live-update
********************/
var liveUpdateTestData = [
//Add a bookmark that should show up
{ isBookmark: true,
uri: "http://bookmarked2.com/",
parentFolder: PlacesUtils.toolbarFolderId,
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
title: "",
isInQuery: true },
//Add a bookmark that should not show up
{ isBookmark: true,
uri: "http://bookmarked-elsewhere2.com/",
parentFolder: PlacesUtils.bookmarksMenuFolderId,
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
title: "",
isInQuery: false }
];
yield task_populateDB(liveUpdateTestData); // add to the db
// add to the test data
testData.push(liveUpdateTestData[0]);
testData.push(liveUpdateTestData[1]);
// re-query and test
LOG("begin live-update test");
compareArrayToResult(testData, root);
LOG("end live-update test");
/*
// we are actually not updating during a batch.
// see bug 432706 for details.
// Here's a batch update
var updateBatch = {
runBatched: function (aUserData) {
liveUpdateTestData[0].uri = "http://bookmarked3.com";
liveUpdateTestData[1].uri = "http://bookmarked-elsewhere3.com";
populateDB(liveUpdateTestData);
testData.push(liveUpdateTestData[0]);
testData.push(liveUpdateTestData[1]);
}
};
PlacesUtils.history.runInBatchMode(updateBatch, null);
// re-query and test
LOG("begin batched test");
compareArrayToResult(testData, root);
LOG("end batched test");
*/
// Close the container when finished
root.containerOpen = false;
});