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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial