Sat, 03 Jan 2015 20:18:00 +0100
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 | // get bookmarks root id |
michael@0 | 8 | var root = PlacesUtils.bookmarksMenuFolderId; |
michael@0 | 9 | |
michael@0 | 10 | // a search term that matches a default bookmark |
michael@0 | 11 | const searchTerm = "about"; |
michael@0 | 12 | |
michael@0 | 13 | var testRoot; |
michael@0 | 14 | |
michael@0 | 15 | // main |
michael@0 | 16 | function run_test() { |
michael@0 | 17 | // create a folder to hold all the tests |
michael@0 | 18 | // this makes the tests more tolerant of changes to the default bookmarks set |
michael@0 | 19 | // also, name it using the search term, for testing that containers that match don't show up in query results |
michael@0 | 20 | testRoot = PlacesUtils.bookmarks.createFolder( |
michael@0 | 21 | root, searchTerm, PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 22 | |
michael@0 | 23 | run_next_test(); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | add_test(function test_savedsearches_bookmarks() { |
michael@0 | 27 | // add a bookmark that matches the search term |
michael@0 | 28 | var bookmarkId = PlacesUtils.bookmarks.insertBookmark( |
michael@0 | 29 | root, uri("http://foo.com"), PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 30 | searchTerm); |
michael@0 | 31 | |
michael@0 | 32 | // create a saved-search that matches a default bookmark |
michael@0 | 33 | var searchId = PlacesUtils.bookmarks.insertBookmark( |
michael@0 | 34 | testRoot, uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=1"), |
michael@0 | 35 | PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm); |
michael@0 | 36 | |
michael@0 | 37 | // query for the test root, expandQueries=0 |
michael@0 | 38 | // the query should show up as a regular bookmark |
michael@0 | 39 | try { |
michael@0 | 40 | var options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 41 | options.expandQueries = 0; |
michael@0 | 42 | var query = PlacesUtils.history.getNewQuery(); |
michael@0 | 43 | query.setFolders([testRoot], 1); |
michael@0 | 44 | var result = PlacesUtils.history.executeQuery(query, options); |
michael@0 | 45 | var rootNode = result.root; |
michael@0 | 46 | rootNode.containerOpen = true; |
michael@0 | 47 | var cc = rootNode.childCount; |
michael@0 | 48 | do_check_eq(cc, 1); |
michael@0 | 49 | for (var i = 0; i < cc; i++) { |
michael@0 | 50 | var node = rootNode.getChild(i); |
michael@0 | 51 | // test that queries have valid itemId |
michael@0 | 52 | do_check_true(node.itemId > 0); |
michael@0 | 53 | // test that the container is closed |
michael@0 | 54 | node.QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 55 | do_check_eq(node.containerOpen, false); |
michael@0 | 56 | } |
michael@0 | 57 | rootNode.containerOpen = false; |
michael@0 | 58 | } |
michael@0 | 59 | catch(ex) { |
michael@0 | 60 | do_throw("expandQueries=0 query error: " + ex); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | // bookmark saved search |
michael@0 | 64 | // query for the test root, expandQueries=1 |
michael@0 | 65 | // the query should show up as a query container, with 1 child |
michael@0 | 66 | try { |
michael@0 | 67 | var options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 68 | options.expandQueries = 1; |
michael@0 | 69 | var query = PlacesUtils.history.getNewQuery(); |
michael@0 | 70 | query.setFolders([testRoot], 1); |
michael@0 | 71 | var result = PlacesUtils.history.executeQuery(query, options); |
michael@0 | 72 | var rootNode = result.root; |
michael@0 | 73 | rootNode.containerOpen = true; |
michael@0 | 74 | var cc = rootNode.childCount; |
michael@0 | 75 | do_check_eq(cc, 1); |
michael@0 | 76 | for (var i = 0; i < cc; i++) { |
michael@0 | 77 | var node = rootNode.getChild(i); |
michael@0 | 78 | // test that query node type is container when expandQueries=1 |
michael@0 | 79 | do_check_eq(node.type, node.RESULT_TYPE_QUERY); |
michael@0 | 80 | // test that queries (as containers) have valid itemId |
michael@0 | 81 | do_check_true(node.itemId > 0); |
michael@0 | 82 | node.QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 83 | node.containerOpen = true; |
michael@0 | 84 | |
michael@0 | 85 | // test that queries have children when excludeItems=1 |
michael@0 | 86 | // test that query nodes don't show containers (shouldn't have our folder that matches) |
michael@0 | 87 | // test that queries don't show themselves in query results (shouldn't have our saved search) |
michael@0 | 88 | do_check_eq(node.childCount, 1); |
michael@0 | 89 | |
michael@0 | 90 | // test that bookmark shows in query results |
michael@0 | 91 | var item = node.getChild(0); |
michael@0 | 92 | do_check_eq(item.itemId, bookmarkId); |
michael@0 | 93 | |
michael@0 | 94 | // XXX - FAILING - test live-update of query results - add a bookmark that matches the query |
michael@0 | 95 | //var tmpBmId = PlacesUtils.bookmarks.insertBookmark( |
michael@0 | 96 | // root, uri("http://" + searchTerm + ".com"), |
michael@0 | 97 | // PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm + "blah"); |
michael@0 | 98 | //do_check_eq(query.childCount, 2); |
michael@0 | 99 | |
michael@0 | 100 | // XXX - test live-update of query results - delete a bookmark that matches the query |
michael@0 | 101 | //PlacesUtils.bookmarks.removeItem(tmpBMId); |
michael@0 | 102 | //do_check_eq(query.childCount, 1); |
michael@0 | 103 | |
michael@0 | 104 | // test live-update of query results - add a folder that matches the query |
michael@0 | 105 | PlacesUtils.bookmarks.createFolder( |
michael@0 | 106 | root, searchTerm + "zaa", PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 107 | do_check_eq(node.childCount, 1); |
michael@0 | 108 | // test live-update of query results - add a query that matches the query |
michael@0 | 109 | PlacesUtils.bookmarks.insertBookmark( |
michael@0 | 110 | root, uri("place:terms=foo&excludeQueries=1&expandQueries=1&queryType=1"), |
michael@0 | 111 | PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm + "blah"); |
michael@0 | 112 | do_check_eq(node.childCount, 1); |
michael@0 | 113 | } |
michael@0 | 114 | rootNode.containerOpen = false; |
michael@0 | 115 | } |
michael@0 | 116 | catch(ex) { |
michael@0 | 117 | do_throw("expandQueries=1 bookmarks query: " + ex); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | // delete the bookmark search |
michael@0 | 121 | PlacesUtils.bookmarks.removeItem(searchId); |
michael@0 | 122 | |
michael@0 | 123 | run_next_test(); |
michael@0 | 124 | }); |
michael@0 | 125 | |
michael@0 | 126 | add_task(function test_savedsearches_history() { |
michael@0 | 127 | // add a visit that matches the search term |
michael@0 | 128 | var testURI = uri("http://" + searchTerm + ".com"); |
michael@0 | 129 | yield promiseAddVisits({ uri: testURI, title: searchTerm }); |
michael@0 | 130 | |
michael@0 | 131 | // create a saved-search that matches the visit we added |
michael@0 | 132 | var searchId = PlacesUtils.bookmarks.insertBookmark(testRoot, |
michael@0 | 133 | uri("place:terms=" + searchTerm + "&excludeQueries=1&expandQueries=1&queryType=0"), |
michael@0 | 134 | PlacesUtils.bookmarks.DEFAULT_INDEX, searchTerm); |
michael@0 | 135 | |
michael@0 | 136 | // query for the test root, expandQueries=1 |
michael@0 | 137 | // the query should show up as a query container, with 1 child |
michael@0 | 138 | try { |
michael@0 | 139 | var options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 140 | options.expandQueries = 1; |
michael@0 | 141 | var query = PlacesUtils.history.getNewQuery(); |
michael@0 | 142 | query.setFolders([testRoot], 1); |
michael@0 | 143 | var result = PlacesUtils.history.executeQuery(query, options); |
michael@0 | 144 | var rootNode = result.root; |
michael@0 | 145 | rootNode.containerOpen = true; |
michael@0 | 146 | var cc = rootNode.childCount; |
michael@0 | 147 | do_check_eq(cc, 1); |
michael@0 | 148 | for (var i = 0; i < cc; i++) { |
michael@0 | 149 | var node = rootNode.getChild(i); |
michael@0 | 150 | // test that query node type is container when expandQueries=1 |
michael@0 | 151 | do_check_eq(node.type, node.RESULT_TYPE_QUERY); |
michael@0 | 152 | // test that queries (as containers) have valid itemId |
michael@0 | 153 | do_check_eq(node.itemId, searchId); |
michael@0 | 154 | node.QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 155 | node.containerOpen = true; |
michael@0 | 156 | |
michael@0 | 157 | // test that queries have children when excludeItems=1 |
michael@0 | 158 | // test that query nodes don't show containers (shouldn't have our folder that matches) |
michael@0 | 159 | // test that queries don't show themselves in query results (shouldn't have our saved search) |
michael@0 | 160 | do_check_eq(node.childCount, 1); |
michael@0 | 161 | |
michael@0 | 162 | // test that history visit shows in query results |
michael@0 | 163 | var item = node.getChild(0); |
michael@0 | 164 | do_check_eq(item.type, item.RESULT_TYPE_URI); |
michael@0 | 165 | do_check_eq(item.itemId, -1); // history visit |
michael@0 | 166 | do_check_eq(item.uri, testURI.spec); // history visit |
michael@0 | 167 | |
michael@0 | 168 | // test live-update of query results - add a history visit that matches the query |
michael@0 | 169 | yield promiseAddVisits({ |
michael@0 | 170 | uri: uri("http://foo.com"), |
michael@0 | 171 | title: searchTerm + "blah" |
michael@0 | 172 | }); |
michael@0 | 173 | do_check_eq(node.childCount, 2); |
michael@0 | 174 | |
michael@0 | 175 | // test live-update of query results - delete a history visit that matches the query |
michael@0 | 176 | PlacesUtils.history.removePage(uri("http://foo.com")); |
michael@0 | 177 | do_check_eq(node.childCount, 1); |
michael@0 | 178 | node.containerOpen = false; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | // test live-update of moved queries |
michael@0 | 182 | var tmpFolderId = PlacesUtils.bookmarks.createFolder( |
michael@0 | 183 | testRoot, "foo", PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 184 | PlacesUtils.bookmarks.moveItem( |
michael@0 | 185 | searchId, tmpFolderId, PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 186 | var tmpFolderNode = rootNode.getChild(0); |
michael@0 | 187 | do_check_eq(tmpFolderNode.itemId, tmpFolderId); |
michael@0 | 188 | tmpFolderNode.QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 189 | tmpFolderNode.containerOpen = true; |
michael@0 | 190 | do_check_eq(tmpFolderNode.childCount, 1); |
michael@0 | 191 | |
michael@0 | 192 | // test live-update of renamed queries |
michael@0 | 193 | PlacesUtils.bookmarks.setItemTitle(searchId, "foo"); |
michael@0 | 194 | do_check_eq(tmpFolderNode.title, "foo"); |
michael@0 | 195 | |
michael@0 | 196 | // test live-update of deleted queries |
michael@0 | 197 | PlacesUtils.bookmarks.removeItem(searchId); |
michael@0 | 198 | try { |
michael@0 | 199 | var tmpFolderNode = root.getChild(1); |
michael@0 | 200 | do_throw("query was not removed"); |
michael@0 | 201 | } catch(ex) {} |
michael@0 | 202 | |
michael@0 | 203 | tmpFolderNode.containerOpen = false; |
michael@0 | 204 | rootNode.containerOpen = false; |
michael@0 | 205 | } |
michael@0 | 206 | catch(ex) { |
michael@0 | 207 | do_throw("expandQueries=1 bookmarks query: " + ex); |
michael@0 | 208 | } |
michael@0 | 209 | }); |