toolkit/components/places/tests/queries/test_onlyBookmarked.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:226865c1f3a6
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 /**
8 * The next thing we do is create a test database for us. Each test runs with
9 * its own database (tail_queries.js will clear it after the run). Take a look
10 * at the queryData object in head_queries.js, and you'll see how this object
11 * works. You can call it anything you like, but I usually use "testData".
12 * I'll include a couple of example entries in the database.
13 *
14 * Note that to use the compareArrayToResult API, you need to put all the
15 * results that are in the query set at the top of the testData list, and those
16 * results MUST be in the same sort order as the items in the resulting query.
17 */
18
19 var testData = [
20 // Add a bookmark that should be in the results
21 { isBookmark: true,
22 uri: "http://bookmarked.com/",
23 parentFolder: PlacesUtils.toolbarFolderId,
24 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
25 title: "",
26 isInQuery: true },
27
28 // Add a bookmark that should not be in the results
29 { isBookmark: true,
30 uri: "http://bookmarked-elsewhere.com/",
31 parentFolder: PlacesUtils.bookmarksMenuFolderId,
32 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
33 title: "",
34 isInQuery: false },
35
36 // Add an un-bookmarked visit
37 { isVisit: true,
38 uri: "http://notbookmarked.com/",
39 isInQuery: false }
40 ];
41
42
43 /**
44 * run_test is where the magic happens. This is automatically run by the test
45 * harness. It is where you do the work of creating the query, running it, and
46 * playing with the result set.
47 */
48 function run_test()
49 {
50 run_next_test();
51 }
52
53 add_task(function test_onlyBookmarked()
54 {
55 // This function in head_queries.js creates our database with the above data
56 yield task_populateDB(testData);
57
58 // Query
59 var query = PlacesUtils.history.getNewQuery();
60 query.setFolders([PlacesUtils.toolbarFolderId], 1);
61 query.onlyBookmarked = true;
62
63 // query options
64 var options = PlacesUtils.history.getNewQueryOptions();
65 options.queryType = options.QUERY_TYPE_HISTORY;
66
67 // Results - this gets the result set and opens it for reading and modification.
68 var result = PlacesUtils.history.executeQuery(query, options);
69 var root = result.root;
70 root.containerOpen = true;
71
72 // You can use this to compare the data in the array with the result set,
73 // if the array's isInQuery: true items are sorted the same way as the result
74 // set.
75 LOG("begin first test");
76 compareArrayToResult(testData, root);
77 LOG("end first test");
78
79 /* ******************
80 Test live-update
81 ********************/
82
83 var liveUpdateTestData = [
84 //Add a bookmark that should show up
85 { isBookmark: true,
86 uri: "http://bookmarked2.com/",
87 parentFolder: PlacesUtils.toolbarFolderId,
88 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
89 title: "",
90 isInQuery: true },
91
92 //Add a bookmark that should not show up
93 { isBookmark: true,
94 uri: "http://bookmarked-elsewhere2.com/",
95 parentFolder: PlacesUtils.bookmarksMenuFolderId,
96 index: PlacesUtils.bookmarks.DEFAULT_INDEX,
97 title: "",
98 isInQuery: false }
99 ];
100
101 yield task_populateDB(liveUpdateTestData); // add to the db
102
103 // add to the test data
104 testData.push(liveUpdateTestData[0]);
105 testData.push(liveUpdateTestData[1]);
106
107 // re-query and test
108 LOG("begin live-update test");
109 compareArrayToResult(testData, root);
110 LOG("end live-update test");
111 /*
112 // we are actually not updating during a batch.
113 // see bug 432706 for details.
114
115 // Here's a batch update
116 var updateBatch = {
117 runBatched: function (aUserData) {
118 liveUpdateTestData[0].uri = "http://bookmarked3.com";
119 liveUpdateTestData[1].uri = "http://bookmarked-elsewhere3.com";
120 populateDB(liveUpdateTestData);
121 testData.push(liveUpdateTestData[0]);
122 testData.push(liveUpdateTestData[1]);
123 }
124 };
125
126 PlacesUtils.history.runInBatchMode(updateBatch, null);
127
128 // re-query and test
129 LOG("begin batched test");
130 compareArrayToResult(testData, root);
131 LOG("end batched test");
132 */
133 // Close the container when finished
134 root.containerOpen = false;
135 });

mercurial