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 | /** |
michael@0 | 8 | * Checks to see that a URI is in the database. |
michael@0 | 9 | * |
michael@0 | 10 | * @param aURI |
michael@0 | 11 | * The URI to check. |
michael@0 | 12 | * @returns true if the URI is in the DB, false otherwise. |
michael@0 | 13 | */ |
michael@0 | 14 | function uri_in_db(aURI) { |
michael@0 | 15 | var options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 16 | options.maxResults = 1; |
michael@0 | 17 | options.resultType = options.RESULTS_AS_URI |
michael@0 | 18 | var query = PlacesUtils.history.getNewQuery(); |
michael@0 | 19 | query.uri = aURI; |
michael@0 | 20 | var result = PlacesUtils.history.executeQuery(query, options); |
michael@0 | 21 | var root = result.root; |
michael@0 | 22 | root.containerOpen = true; |
michael@0 | 23 | var cc = root.childCount; |
michael@0 | 24 | root.containerOpen = false; |
michael@0 | 25 | return (cc == 1); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | const TOTAL_SITES = 20; |
michael@0 | 29 | |
michael@0 | 30 | // main |
michael@0 | 31 | function run_test() |
michael@0 | 32 | { |
michael@0 | 33 | run_next_test(); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | add_task(function test_execute() |
michael@0 | 37 | { |
michael@0 | 38 | // add pages to global history |
michael@0 | 39 | for (var i = 0; i < TOTAL_SITES; i++) { |
michael@0 | 40 | let site = "http://www.test-" + i + ".com/"; |
michael@0 | 41 | let testURI = uri(site); |
michael@0 | 42 | let when = Date.now() * 1000 + (i * TOTAL_SITES); |
michael@0 | 43 | yield promiseAddVisits({ uri: testURI, visitDate: when }); |
michael@0 | 44 | } |
michael@0 | 45 | for (var i = 0; i < TOTAL_SITES; i++) { |
michael@0 | 46 | let site = "http://www.test.com/" + i + "/"; |
michael@0 | 47 | let testURI = uri(site); |
michael@0 | 48 | let when = Date.now() * 1000 + (i * TOTAL_SITES); |
michael@0 | 49 | yield promiseAddVisits({ uri: testURI, visitDate: when }); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | // set a page annotation on one of the urls that will be removed |
michael@0 | 53 | var testAnnoDeletedURI = uri("http://www.test.com/1/"); |
michael@0 | 54 | var testAnnoDeletedName = "foo"; |
michael@0 | 55 | var testAnnoDeletedValue = "bar"; |
michael@0 | 56 | PlacesUtils.annotations.setPageAnnotation(testAnnoDeletedURI, |
michael@0 | 57 | testAnnoDeletedName, |
michael@0 | 58 | testAnnoDeletedValue, 0, |
michael@0 | 59 | PlacesUtils.annotations.EXPIRE_WITH_HISTORY); |
michael@0 | 60 | |
michael@0 | 61 | // set a page annotation on one of the urls that will NOT be removed |
michael@0 | 62 | var testAnnoRetainedURI = uri("http://www.test-1.com/"); |
michael@0 | 63 | var testAnnoRetainedName = "foo"; |
michael@0 | 64 | var testAnnoRetainedValue = "bar"; |
michael@0 | 65 | PlacesUtils.annotations.setPageAnnotation(testAnnoRetainedURI, |
michael@0 | 66 | testAnnoRetainedName, |
michael@0 | 67 | testAnnoRetainedValue, 0, |
michael@0 | 68 | PlacesUtils.annotations.EXPIRE_WITH_HISTORY); |
michael@0 | 69 | |
michael@0 | 70 | // remove pages from www.test.com |
michael@0 | 71 | PlacesUtils.history.removePagesFromHost("www.test.com", false); |
michael@0 | 72 | |
michael@0 | 73 | // check that all pages in www.test.com have been removed |
michael@0 | 74 | for (var i = 0; i < TOTAL_SITES; i++) { |
michael@0 | 75 | let site = "http://www.test.com/" + i + "/"; |
michael@0 | 76 | let testURI = uri(site); |
michael@0 | 77 | do_check_false(uri_in_db(testURI)); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | // check that all pages in www.test-X.com have NOT been removed |
michael@0 | 81 | for (var i = 0; i < TOTAL_SITES; i++) { |
michael@0 | 82 | let site = "http://www.test-" + i + ".com/"; |
michael@0 | 83 | let testURI = uri(site); |
michael@0 | 84 | do_check_true(uri_in_db(testURI)); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | // check that annotation on the removed item does not exists |
michael@0 | 88 | try { |
michael@0 | 89 | PlacesUtils.annotations.getPageAnnotation(testAnnoDeletedURI, testAnnoName); |
michael@0 | 90 | do_throw("fetching page-annotation that doesn't exist, should've thrown"); |
michael@0 | 91 | } catch(ex) {} |
michael@0 | 92 | |
michael@0 | 93 | // check that annotation on the NOT removed item still exists |
michael@0 | 94 | try { |
michael@0 | 95 | var annoVal = PlacesUtils.annotations.getPageAnnotation(testAnnoRetainedURI, |
michael@0 | 96 | testAnnoRetainedName); |
michael@0 | 97 | } catch(ex) { |
michael@0 | 98 | do_throw("The annotation has been removed erroneously"); |
michael@0 | 99 | } |
michael@0 | 100 | do_check_eq(annoVal, testAnnoRetainedValue); |
michael@0 | 101 | |
michael@0 | 102 | }); |