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 | let observer = { |
michael@0 | 8 | __proto__: NavBookmarkObserver.prototype, |
michael@0 | 9 | |
michael@0 | 10 | onItemAdded: function (id, folder, index) { |
michael@0 | 11 | this._itemAddedId = id; |
michael@0 | 12 | this._itemAddedParent = folder; |
michael@0 | 13 | this._itemAddedIndex = index; |
michael@0 | 14 | }, |
michael@0 | 15 | onItemChanged: function (id, property, isAnnotationProperty, value) { |
michael@0 | 16 | this._itemChangedId = id; |
michael@0 | 17 | this._itemChangedProperty = property; |
michael@0 | 18 | this._itemChanged_isAnnotationProperty = isAnnotationProperty; |
michael@0 | 19 | this._itemChangedValue = value; |
michael@0 | 20 | } |
michael@0 | 21 | }; |
michael@0 | 22 | PlacesUtils.bookmarks.addObserver(observer, false); |
michael@0 | 23 | |
michael@0 | 24 | do_register_cleanup(function () { |
michael@0 | 25 | PlacesUtils.bookmarks.removeObserver(observer); |
michael@0 | 26 | }); |
michael@0 | 27 | |
michael@0 | 28 | function run_test() { |
michael@0 | 29 | // We set times in the past to workaround a timing bug due to virtual |
michael@0 | 30 | // machines and the skew between PR_Now() and Date.now(), see bug 427142 and |
michael@0 | 31 | // bug 858377 for details. |
michael@0 | 32 | const PAST_PRTIME = (Date.now() - 86400000) * 1000; |
michael@0 | 33 | |
michael@0 | 34 | // Insert a new bookmark. |
michael@0 | 35 | let testFolder = PlacesUtils.bookmarks.createFolder( |
michael@0 | 36 | PlacesUtils.placesRootId, "test Folder", |
michael@0 | 37 | PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 38 | let bookmarkId = PlacesUtils.bookmarks.insertBookmark( |
michael@0 | 39 | testFolder, uri("http://google.com/"), |
michael@0 | 40 | PlacesUtils.bookmarks.DEFAULT_INDEX, ""); |
michael@0 | 41 | |
michael@0 | 42 | // Sanity check. |
michael@0 | 43 | do_check_true(observer.itemChangedProperty === undefined); |
michael@0 | 44 | |
michael@0 | 45 | // Set dateAdded in the past and verify the bookmarks cache. |
michael@0 | 46 | PlacesUtils.bookmarks.setItemDateAdded(bookmarkId, PAST_PRTIME); |
michael@0 | 47 | do_check_eq(observer._itemChangedProperty, "dateAdded"); |
michael@0 | 48 | do_check_eq(observer._itemChangedValue, PAST_PRTIME); |
michael@0 | 49 | let dateAdded = PlacesUtils.bookmarks.getItemDateAdded(bookmarkId); |
michael@0 | 50 | do_check_eq(dateAdded, PAST_PRTIME); |
michael@0 | 51 | |
michael@0 | 52 | // After just inserting, modified should be the same as dateAdded. |
michael@0 | 53 | do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId), dateAdded); |
michael@0 | 54 | |
michael@0 | 55 | // Set lastModified in the past and verify the bookmarks cache. |
michael@0 | 56 | PlacesUtils.bookmarks.setItemLastModified(bookmarkId, PAST_PRTIME); |
michael@0 | 57 | do_check_eq(observer._itemChangedProperty, "lastModified"); |
michael@0 | 58 | do_check_eq(observer._itemChangedValue, PAST_PRTIME); |
michael@0 | 59 | do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId), |
michael@0 | 60 | PAST_PRTIME); |
michael@0 | 61 | |
michael@0 | 62 | // Set bookmark title |
michael@0 | 63 | PlacesUtils.bookmarks.setItemTitle(bookmarkId, "Google"); |
michael@0 | 64 | |
michael@0 | 65 | // Test notifications. |
michael@0 | 66 | do_check_eq(observer._itemChangedId, bookmarkId); |
michael@0 | 67 | do_check_eq(observer._itemChangedProperty, "title"); |
michael@0 | 68 | do_check_eq(observer._itemChangedValue, "Google"); |
michael@0 | 69 | |
michael@0 | 70 | // Check lastModified has been updated. |
michael@0 | 71 | is_time_ordered(PAST_PRTIME, |
michael@0 | 72 | PlacesUtils.bookmarks.getItemLastModified(bookmarkId)); |
michael@0 | 73 | |
michael@0 | 74 | // Check that node properties are updated. |
michael@0 | 75 | let root = PlacesUtils.getFolderContents(testFolder).root; |
michael@0 | 76 | do_check_eq(root.childCount, 1); |
michael@0 | 77 | let childNode = root.getChild(0); |
michael@0 | 78 | |
michael@0 | 79 | // confirm current dates match node properties |
michael@0 | 80 | do_check_eq(PlacesUtils.bookmarks.getItemDateAdded(bookmarkId), |
michael@0 | 81 | childNode.dateAdded); |
michael@0 | 82 | do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId), |
michael@0 | 83 | childNode.lastModified); |
michael@0 | 84 | |
michael@0 | 85 | // Test live update of lastModified when setting title. |
michael@0 | 86 | PlacesUtils.bookmarks.setItemLastModified(bookmarkId, PAST_PRTIME); |
michael@0 | 87 | PlacesUtils.bookmarks.setItemTitle(bookmarkId, "Google"); |
michael@0 | 88 | |
michael@0 | 89 | // Check lastModified has been updated. |
michael@0 | 90 | is_time_ordered(PAST_PRTIME, childNode.lastModified); |
michael@0 | 91 | // Test that node value matches db value. |
michael@0 | 92 | do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId), |
michael@0 | 93 | childNode.lastModified); |
michael@0 | 94 | |
michael@0 | 95 | // Test live update of the exposed date apis. |
michael@0 | 96 | PlacesUtils.bookmarks.setItemDateAdded(bookmarkId, PAST_PRTIME); |
michael@0 | 97 | do_check_eq(childNode.dateAdded, PAST_PRTIME); |
michael@0 | 98 | PlacesUtils.bookmarks.setItemLastModified(bookmarkId, PAST_PRTIME); |
michael@0 | 99 | do_check_eq(childNode.lastModified, PAST_PRTIME); |
michael@0 | 100 | |
michael@0 | 101 | root.containerOpen = false; |
michael@0 | 102 | } |