js/xpconnect/tests/unit/test_watchdog_hibernate.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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 function testBody() {
     7   setWatchdogEnabled(true);
     9   // It's unlikely that we've ever hibernated at this point, but the timestamps
    10   // default to 0, so this should always be true.
    11   var now = Date.now() * 1000;
    12   var startHibernation = Cu.getWatchdogTimestamp("WatchdogHibernateStart");
    13   var stopHibernation = Cu.getWatchdogTimestamp("WatchdogHibernateStop");
    14   do_log_info("Pre-hibernation statistics:");
    15   do_log_info("now: " + now / 1000000);
    16   do_log_info("startHibernation: " + startHibernation / 1000000);
    17   do_log_info("stopHibernation: " + stopHibernation / 1000000);
    18   do_check_true(startHibernation < now);
    19   do_check_true(stopHibernation < now);
    21   // When the watchdog runs, it hibernates if there's been no activity for the
    22   // last 2 seconds, otherwise it sleeps for 1 second. As such, given perfect
    23   // scheduling, we should never have more than 3 seconds of inactivity without
    24   // hibernating. To add some padding for automation, we mandate that hibernation
    25   // must begin between 2 and 5 seconds from now.
    26   var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
    27   timer.initWithCallback(continueTest, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
    28   simulateActivityCallback(false);
    29   yield;
    31   simulateActivityCallback(true);
    32   busyWait(1000); // Give the watchdog time to wake up on the condvar.
    33   var stateChange = Cu.getWatchdogTimestamp("RuntimeStateChange");
    34   startHibernation = Cu.getWatchdogTimestamp("WatchdogHibernateStart");
    35   stopHibernation = Cu.getWatchdogTimestamp("WatchdogHibernateStop");
    36   do_log_info("Post-hibernation statistics:");
    37   do_log_info("stateChange: " + stateChange / 1000000);
    38   do_log_info("startHibernation: " + startHibernation / 1000000);
    39   do_log_info("stopHibernation: " + stopHibernation / 1000000);
    40   // XPCOM timers, JS times, and PR_Now() are apparently not directly
    41   // comparable, as evidenced by certain seemingly-impossible timing values
    42   // that occasionally get logged in windows automation. We're really just
    43   // making sure this behavior is roughly as expected on the macro scale,
    44   // so we add a 1 second fuzz factor here.
    45   const FUZZ_FACTOR = 1 * 1000 * 1000;
    46   do_check_true(stateChange > now + 10*1000*1000 - FUZZ_FACTOR);
    47   do_check_true(startHibernation > now + 2*1000*1000 - FUZZ_FACTOR);
    48   do_check_true(startHibernation < now + 5*1000*1000 + FUZZ_FACTOR);
    49   do_check_true(stopHibernation > now + 10*1000*1000 - FUZZ_FACTOR);
    51   do_test_finished();
    52   yield;
    53 }

mercurial