toolkit/components/places/tests/expiration/test_pref_maxpages.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: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
     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  * What this is aimed to test:
     9  *
    10  * Expiration will obey to hardware spec, but user can set a custom maximum
    11  * number of pages to retain, to restrict history, through
    12  * "places.history.expiration.max_pages".
    13  * This limit is used at next expiration run.
    14  * If the pref is set to a number < 0 we will use the default value.
    15  */
    17 let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
    18          getService(Ci.nsINavHistoryService);
    20 let tests = [
    22   { desc: "Set max_pages to a negative value, with 1 page.",
    23     maxPages: -1,
    24     addPages: 1,
    25     expectedNotifications: 0, // Will ignore and won't expire anything.
    26   },
    28   { desc: "Set max_pages to 0.",
    29     maxPages: 0,
    30     addPages: 1,
    31     expectedNotifications: 1,
    32   },
    34   { desc: "Set max_pages to 0, with 2 pages.",
    35     maxPages: 0,
    36     addPages: 2,
    37     expectedNotifications: 2, // Will expire everything.
    38   },
    40   // Notice if we are over limit we do a full step of expiration.  So we ensure
    41   // that we will expire if we are over the limit, but we don't ensure that we
    42   // will expire exactly up to the limit.  Thus in this case we expire
    43   // everything.
    44   { desc: "Set max_pages to 1 with 2 pages.",
    45     maxPages: 1,
    46     addPages: 2,
    47     expectedNotifications: 2, // Will expire everything (in this case).
    48   },
    50   { desc: "Set max_pages to 10, with 9 pages.",
    51     maxPages: 10,
    52     addPages: 9,
    53     expectedNotifications: 0, // We are at the limit, won't expire anything.
    54   },
    56   { desc: "Set max_pages to 10 with 10 pages.",
    57     maxPages: 10,
    58     addPages: 10,
    59     expectedNotifications: 0, // We are below the limit, won't expire anything.
    60   },
    61 ];
    63 function run_test() {
    64   run_next_test();
    65 }
    67 add_task(function test_pref_maxpages() {
    68   // The pref should not exist by default.
    69   try {
    70     getMaxPages();
    71     do_throw("interval pref should not exist by default");
    72   }
    73   catch (ex) {}
    75   // Set interval to a large value so we don't expire on it.
    76   setInterval(3600); // 1h
    78   for (let testIndex = 1; testIndex <= tests.length; testIndex++) {
    79     let currentTest = tests[testIndex -1];
    80     print("\nTEST " + testIndex + ": " + currentTest.desc);
    81     currentTest.receivedNotifications = 0;
    83     // Setup visits.
    84     let now = getExpirablePRTime();
    85     for (let i = 0; i < currentTest.addPages; i++) {
    86       let page = "http://" + testIndex + "." + i + ".mozilla.org/";
    87       yield promiseAddVisits({ uri: uri(page), visitDate: now++ });
    88     }
    90     // Observe history.
    91     historyObserver = {
    92       onBeginUpdateBatch: function PEX_onBeginUpdateBatch() {},
    93       onEndUpdateBatch: function PEX_onEndUpdateBatch() {},
    94       onClearHistory: function() {},
    95       onVisit: function() {},
    96       onTitleChanged: function() {},
    97       onDeleteURI: function(aURI) {
    98         print("onDeleteURI " + aURI.spec);
    99         currentTest.receivedNotifications++;
   100       },
   101       onPageChanged: function() {},
   102       onDeleteVisits: function(aURI, aTime) {
   103         print("onDeleteVisits " + aURI.spec + " " + aTime);
   104       },
   105     };
   106     hs.addObserver(historyObserver, false);
   108     setMaxPages(currentTest.maxPages);
   110     // Expire now.
   111     yield promiseForceExpirationStep(-1);
   113     hs.removeObserver(historyObserver, false);
   115     do_check_eq(currentTest.receivedNotifications,
   116                 currentTest.expectedNotifications);
   118     // Clean up.
   119     yield promiseClearHistory();
   120   }
   122   clearMaxPages();
   123   yield promiseClearHistory();
   124 });

mercurial