toolkit/components/places/tests/unit/test_415757.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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.

     1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /**
     8  * Checks to see that a URI is in the database.
     9  *
    10  * @param aURI
    11  *        The URI to check.
    12  * @returns true if the URI is in the DB, false otherwise.
    13  */
    14 function uri_in_db(aURI) {
    15   var options = PlacesUtils.history.getNewQueryOptions();
    16   options.maxResults = 1;
    17   options.resultType = options.RESULTS_AS_URI
    18   var query = PlacesUtils.history.getNewQuery();
    19   query.uri = aURI;
    20   var result = PlacesUtils.history.executeQuery(query, options);
    21   var root = result.root;
    22   root.containerOpen = true;
    23   var cc = root.childCount;
    24   root.containerOpen = false;
    25   return (cc == 1);
    26 }
    28 const TOTAL_SITES = 20;
    30 // main
    31 function run_test()
    32 {
    33   run_next_test();
    34 }
    36 add_task(function test_execute()
    37 {
    38   // add pages to global history
    39   for (var i = 0; i < TOTAL_SITES; i++) {
    40     let site = "http://www.test-" + i + ".com/";
    41     let testURI = uri(site);
    42     let when = Date.now() * 1000 + (i * TOTAL_SITES);
    43     yield promiseAddVisits({ uri: testURI, visitDate: when });
    44   }
    45   for (var i = 0; i < TOTAL_SITES; i++) {
    46     let site = "http://www.test.com/" + i + "/";
    47     let testURI = uri(site);
    48     let when = Date.now() * 1000 + (i * TOTAL_SITES);
    49     yield promiseAddVisits({ uri: testURI, visitDate: when });
    50   }
    52   // set a page annotation on one of the urls that will be removed
    53   var testAnnoDeletedURI = uri("http://www.test.com/1/");
    54   var testAnnoDeletedName = "foo";
    55   var testAnnoDeletedValue = "bar";
    56   PlacesUtils.annotations.setPageAnnotation(testAnnoDeletedURI,
    57                                             testAnnoDeletedName,
    58                                             testAnnoDeletedValue, 0,
    59                                             PlacesUtils.annotations.EXPIRE_WITH_HISTORY);
    61   // set a page annotation on one of the urls that will NOT be removed
    62   var testAnnoRetainedURI = uri("http://www.test-1.com/");
    63   var testAnnoRetainedName = "foo";
    64   var testAnnoRetainedValue = "bar";
    65   PlacesUtils.annotations.setPageAnnotation(testAnnoRetainedURI,
    66                                             testAnnoRetainedName,
    67                                             testAnnoRetainedValue, 0,
    68                                             PlacesUtils.annotations.EXPIRE_WITH_HISTORY);
    70   // remove pages from www.test.com
    71   PlacesUtils.history.removePagesFromHost("www.test.com", false);
    73   // check that all pages in www.test.com have been removed
    74   for (var i = 0; i < TOTAL_SITES; i++) {
    75     let site = "http://www.test.com/" + i + "/";
    76     let testURI = uri(site);
    77     do_check_false(uri_in_db(testURI));
    78   }
    80   // check that all pages in www.test-X.com have NOT been removed
    81   for (var i = 0; i < TOTAL_SITES; i++) {
    82     let site = "http://www.test-" + i + ".com/";
    83     let testURI = uri(site);
    84     do_check_true(uri_in_db(testURI));
    85   }
    87   // check that annotation on the removed item does not exists
    88   try {
    89     PlacesUtils.annotations.getPageAnnotation(testAnnoDeletedURI, testAnnoName);
    90     do_throw("fetching page-annotation that doesn't exist, should've thrown");
    91   } catch(ex) {}
    93   // check that annotation on the NOT removed item still exists
    94   try {
    95     var annoVal = PlacesUtils.annotations.getPageAnnotation(testAnnoRetainedURI,
    96                                                             testAnnoRetainedName);
    97   } catch(ex) {
    98     do_throw("The annotation has been removed erroneously");
    99   }
   100   do_check_eq(annoVal, testAnnoRetainedValue);
   102 });

mercurial