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 | const TEST_URI = NetUtil.newURI("http://mozilla.com/"); |
michael@0 | 8 | const TEST_SUBDOMAIN_URI = NetUtil.newURI("http://foobar.mozilla.com/"); |
michael@0 | 9 | |
michael@0 | 10 | add_test(function test_addPage() |
michael@0 | 11 | { |
michael@0 | 12 | promiseAddVisits(TEST_URI).then(function () { |
michael@0 | 13 | do_check_eq(1, PlacesUtils.history.hasHistoryEntries); |
michael@0 | 14 | run_next_test(); |
michael@0 | 15 | }); |
michael@0 | 16 | }); |
michael@0 | 17 | |
michael@0 | 18 | add_test(function test_removePage() |
michael@0 | 19 | { |
michael@0 | 20 | PlacesUtils.bhistory.removePage(TEST_URI); |
michael@0 | 21 | do_check_eq(0, PlacesUtils.history.hasHistoryEntries); |
michael@0 | 22 | run_next_test(); |
michael@0 | 23 | }); |
michael@0 | 24 | |
michael@0 | 25 | add_test(function test_removePages() |
michael@0 | 26 | { |
michael@0 | 27 | let pages = []; |
michael@0 | 28 | for (let i = 0; i < 8; i++) { |
michael@0 | 29 | pages.push(NetUtil.newURI(TEST_URI.spec + i)); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | promiseAddVisits(pages.map(function (uri) ({ uri: uri }))).then(function () { |
michael@0 | 33 | // Bookmarked item should not be removed from moz_places. |
michael@0 | 34 | const ANNO_INDEX = 1; |
michael@0 | 35 | const ANNO_NAME = "testAnno"; |
michael@0 | 36 | const ANNO_VALUE = "foo"; |
michael@0 | 37 | const BOOKMARK_INDEX = 2; |
michael@0 | 38 | PlacesUtils.annotations.setPageAnnotation(pages[ANNO_INDEX], |
michael@0 | 39 | ANNO_NAME, ANNO_VALUE, 0, |
michael@0 | 40 | Ci.nsIAnnotationService.EXPIRE_NEVER); |
michael@0 | 41 | PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 42 | pages[BOOKMARK_INDEX], |
michael@0 | 43 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 44 | "test bookmark"); |
michael@0 | 45 | PlacesUtils.annotations.setPageAnnotation(pages[BOOKMARK_INDEX], |
michael@0 | 46 | ANNO_NAME, ANNO_VALUE, 0, |
michael@0 | 47 | Ci.nsIAnnotationService.EXPIRE_NEVER); |
michael@0 | 48 | |
michael@0 | 49 | PlacesUtils.bhistory.removePages(pages, pages.length); |
michael@0 | 50 | do_check_eq(0, PlacesUtils.history.hasHistoryEntries); |
michael@0 | 51 | |
michael@0 | 52 | // Check that the bookmark and its annotation still exist. |
michael@0 | 53 | do_check_true(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0) > 0); |
michael@0 | 54 | do_check_eq(PlacesUtils.annotations.getPageAnnotation(pages[BOOKMARK_INDEX], ANNO_NAME), |
michael@0 | 55 | ANNO_VALUE); |
michael@0 | 56 | |
michael@0 | 57 | // Check the annotation on the non-bookmarked page does not exist anymore. |
michael@0 | 58 | try { |
michael@0 | 59 | PlacesUtils.annotations.getPageAnnotation(pages[ANNO_INDEX], ANNO_NAME); |
michael@0 | 60 | do_throw("did not expire expire_never anno on a not bookmarked item"); |
michael@0 | 61 | } catch(ex) {} |
michael@0 | 62 | |
michael@0 | 63 | // Cleanup. |
michael@0 | 64 | PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 65 | promiseClearHistory().then(run_next_test); |
michael@0 | 66 | }); |
michael@0 | 67 | }); |
michael@0 | 68 | |
michael@0 | 69 | add_test(function test_removePagesByTimeframe() |
michael@0 | 70 | { |
michael@0 | 71 | let visits = []; |
michael@0 | 72 | let startDate = Date.now() * 1000; |
michael@0 | 73 | for (let i = 0; i < 10; i++) { |
michael@0 | 74 | visits.push({ |
michael@0 | 75 | uri: NetUtil.newURI(TEST_URI.spec + i), |
michael@0 | 76 | visitDate: startDate + i |
michael@0 | 77 | }); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | promiseAddVisits(visits).then(function () { |
michael@0 | 81 | // Delete all pages except the first and the last. |
michael@0 | 82 | PlacesUtils.bhistory.removePagesByTimeframe(startDate + 1, startDate + 8); |
michael@0 | 83 | |
michael@0 | 84 | // Check that we have removed the correct pages. |
michael@0 | 85 | for (let i = 0; i < 10; i++) { |
michael@0 | 86 | do_check_eq(page_in_database(NetUtil.newURI(TEST_URI.spec + i)) == 0, |
michael@0 | 87 | i > 0 && i < 9); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | // Clear remaining items and check that all pages have been removed. |
michael@0 | 91 | PlacesUtils.bhistory.removePagesByTimeframe(startDate, startDate + 9); |
michael@0 | 92 | do_check_eq(0, PlacesUtils.history.hasHistoryEntries); |
michael@0 | 93 | run_next_test(); |
michael@0 | 94 | }); |
michael@0 | 95 | }); |
michael@0 | 96 | |
michael@0 | 97 | add_test(function test_removePagesFromHost() |
michael@0 | 98 | { |
michael@0 | 99 | promiseAddVisits(TEST_URI).then(function () { |
michael@0 | 100 | PlacesUtils.bhistory.removePagesFromHost("mozilla.com", true); |
michael@0 | 101 | do_check_eq(0, PlacesUtils.history.hasHistoryEntries); |
michael@0 | 102 | run_next_test(); |
michael@0 | 103 | }); |
michael@0 | 104 | }); |
michael@0 | 105 | |
michael@0 | 106 | add_test(function test_removePagesFromHost_keepSubdomains() |
michael@0 | 107 | { |
michael@0 | 108 | promiseAddVisits([{ uri: TEST_URI }, { uri: TEST_SUBDOMAIN_URI }]).then(function () { |
michael@0 | 109 | PlacesUtils.bhistory.removePagesFromHost("mozilla.com", false); |
michael@0 | 110 | do_check_eq(1, PlacesUtils.history.hasHistoryEntries); |
michael@0 | 111 | run_next_test(); |
michael@0 | 112 | }); |
michael@0 | 113 | }); |
michael@0 | 114 | |
michael@0 | 115 | add_test(function test_removeAllPages() |
michael@0 | 116 | { |
michael@0 | 117 | PlacesUtils.bhistory.removeAllPages(); |
michael@0 | 118 | do_check_eq(0, PlacesUtils.history.hasHistoryEntries); |
michael@0 | 119 | run_next_test(); |
michael@0 | 120 | }); |
michael@0 | 121 | |
michael@0 | 122 | function run_test() |
michael@0 | 123 | { |
michael@0 | 124 | run_next_test(); |
michael@0 | 125 | } |