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 | var tests = []; |
michael@0 | 8 | |
michael@0 | 9 | /* |
michael@0 | 10 | |
michael@0 | 11 | Backup/restore tests example: |
michael@0 | 12 | |
michael@0 | 13 | var myTest = { |
michael@0 | 14 | populate: function () { ... add bookmarks ... }, |
michael@0 | 15 | validate: function () { ... query for your bookmarks ... } |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | this.push(myTest); |
michael@0 | 19 | |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | tests.push({ |
michael@0 | 23 | excludeItemsFromRestore: [], |
michael@0 | 24 | populate: function populate() { |
michael@0 | 25 | // check initial size |
michael@0 | 26 | var rootNode = PlacesUtils.getFolderContents(PlacesUtils.placesRootId, |
michael@0 | 27 | false, false).root; |
michael@0 | 28 | do_check_eq(rootNode.childCount, 4); |
michael@0 | 29 | |
michael@0 | 30 | // create a test root |
michael@0 | 31 | this._folderTitle = "test folder"; |
michael@0 | 32 | this._folderId = |
michael@0 | 33 | PlacesUtils.bookmarks.createFolder(PlacesUtils.placesRootId, |
michael@0 | 34 | this._folderTitle, |
michael@0 | 35 | PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 36 | do_check_eq(rootNode.childCount, 5); |
michael@0 | 37 | |
michael@0 | 38 | // add a tag |
michael@0 | 39 | this._testURI = PlacesUtils._uri("http://test"); |
michael@0 | 40 | this._tags = ["a", "b"]; |
michael@0 | 41 | PlacesUtils.tagging.tagURI(this._testURI, this._tags); |
michael@0 | 42 | |
michael@0 | 43 | // add a child to each root, including our test root |
michael@0 | 44 | this._roots = [PlacesUtils.bookmarksMenuFolderId, PlacesUtils.toolbarFolderId, |
michael@0 | 45 | PlacesUtils.unfiledBookmarksFolderId, this._folderId]; |
michael@0 | 46 | this._roots.forEach(function(aRootId) { |
michael@0 | 47 | // clean slate |
michael@0 | 48 | PlacesUtils.bookmarks.removeFolderChildren(aRootId); |
michael@0 | 49 | // add a test bookmark |
michael@0 | 50 | PlacesUtils.bookmarks.insertBookmark(aRootId, this._testURI, |
michael@0 | 51 | PlacesUtils.bookmarks.DEFAULT_INDEX, "test"); |
michael@0 | 52 | }, this); |
michael@0 | 53 | |
michael@0 | 54 | // add a folder to exclude from replacing during restore |
michael@0 | 55 | // this will still be present post-restore |
michael@0 | 56 | var excludedFolderId = |
michael@0 | 57 | PlacesUtils.bookmarks.createFolder(PlacesUtils.placesRootId, |
michael@0 | 58 | "excluded", |
michael@0 | 59 | PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 60 | do_check_eq(rootNode.childCount, 6); |
michael@0 | 61 | this.excludeItemsFromRestore.push(excludedFolderId); |
michael@0 | 62 | |
michael@0 | 63 | // add a test bookmark to it |
michael@0 | 64 | PlacesUtils.bookmarks.insertBookmark(excludedFolderId, this._testURI, |
michael@0 | 65 | PlacesUtils.bookmarks.DEFAULT_INDEX, "test"); |
michael@0 | 66 | }, |
michael@0 | 67 | |
michael@0 | 68 | inbetween: function inbetween() { |
michael@0 | 69 | // add some items that should be removed by the restore |
michael@0 | 70 | |
michael@0 | 71 | // add a folder |
michael@0 | 72 | this._litterTitle = "otter"; |
michael@0 | 73 | PlacesUtils.bookmarks.createFolder(PlacesUtils.placesRootId, |
michael@0 | 74 | this._litterTitle, 0); |
michael@0 | 75 | |
michael@0 | 76 | // add some tags |
michael@0 | 77 | PlacesUtils.tagging.tagURI(this._testURI, ["c", "d"]); |
michael@0 | 78 | }, |
michael@0 | 79 | |
michael@0 | 80 | validate: function validate() { |
michael@0 | 81 | // validate tags restored |
michael@0 | 82 | var tags = PlacesUtils.tagging.getTagsForURI(this._testURI); |
michael@0 | 83 | // also validates that litter tags are gone |
michael@0 | 84 | do_check_eq(this._tags.toString(), tags.toString()); |
michael@0 | 85 | |
michael@0 | 86 | var rootNode = PlacesUtils.getFolderContents(PlacesUtils.placesRootId, |
michael@0 | 87 | false, false).root; |
michael@0 | 88 | |
michael@0 | 89 | // validate litter is gone |
michael@0 | 90 | do_check_neq(rootNode.getChild(0).title, this._litterTitle); |
michael@0 | 91 | |
michael@0 | 92 | // test root count is the same |
michael@0 | 93 | do_check_eq(rootNode.childCount, 6); |
michael@0 | 94 | |
michael@0 | 95 | var foundTestFolder = 0; |
michael@0 | 96 | for (var i = 0; i < rootNode.childCount; i++) { |
michael@0 | 97 | var node = rootNode.getChild(i); |
michael@0 | 98 | |
michael@0 | 99 | LOG("validating " + node.title); |
michael@0 | 100 | if (node.itemId != PlacesUtils.tagsFolderId) { |
michael@0 | 101 | if (node.title == this._folderTitle) { |
michael@0 | 102 | // check the test folder's properties |
michael@0 | 103 | do_check_eq(node.type, node.RESULT_TYPE_FOLDER); |
michael@0 | 104 | do_check_eq(node.title, this._folderTitle); |
michael@0 | 105 | foundTestFolder++; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | // test contents |
michael@0 | 109 | node.QueryInterface(Ci.nsINavHistoryContainerResultNode).containerOpen = true; |
michael@0 | 110 | do_check_eq(node.childCount, 1); |
michael@0 | 111 | var child = node.getChild(0); |
michael@0 | 112 | do_check_true(PlacesUtils._uri(child.uri).equals(this._testURI)); |
michael@0 | 113 | |
michael@0 | 114 | // clean up |
michael@0 | 115 | node.containerOpen = false; |
michael@0 | 116 | } |
michael@0 | 117 | } |
michael@0 | 118 | do_check_eq(foundTestFolder, 1); |
michael@0 | 119 | rootNode.containerOpen = false; |
michael@0 | 120 | } |
michael@0 | 121 | }); |
michael@0 | 122 | |
michael@0 | 123 | function run_test() { |
michael@0 | 124 | run_next_test(); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | add_task(function () { |
michael@0 | 128 | // make json file |
michael@0 | 129 | let jsonFile = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.json"); |
michael@0 | 130 | |
michael@0 | 131 | // array of ids not to delete when restoring |
michael@0 | 132 | var excludedItemsFromRestore = []; |
michael@0 | 133 | |
michael@0 | 134 | // populate db |
michael@0 | 135 | tests.forEach(function(aTest) { |
michael@0 | 136 | aTest.populate(); |
michael@0 | 137 | // sanity |
michael@0 | 138 | aTest.validate(); |
michael@0 | 139 | |
michael@0 | 140 | if (aTest.excludedItemsFromRestore) |
michael@0 | 141 | excludedItemsFromRestore = excludedItems.concat(aTest.excludedItemsFromRestore); |
michael@0 | 142 | }); |
michael@0 | 143 | |
michael@0 | 144 | yield BookmarkJSONUtils.exportToFile(jsonFile); |
michael@0 | 145 | |
michael@0 | 146 | tests.forEach(function(aTest) { |
michael@0 | 147 | aTest.inbetween(); |
michael@0 | 148 | }); |
michael@0 | 149 | |
michael@0 | 150 | // restore json file |
michael@0 | 151 | yield BookmarkJSONUtils.importFromFile(jsonFile, true); |
michael@0 | 152 | |
michael@0 | 153 | // validate |
michael@0 | 154 | tests.forEach(function(aTest) { |
michael@0 | 155 | aTest.validate(); |
michael@0 | 156 | }); |
michael@0 | 157 | |
michael@0 | 158 | // clean up |
michael@0 | 159 | yield OS.File.remove(jsonFile); |
michael@0 | 160 | }); |