js/xpconnect/tests/unit/head_watchdog.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 //
     6 // Pref management.
     7 //
     9 const Cc = Components.classes;
    10 const Ci = Components.interfaces;
    11 const Cu = Components.utils;
    13 var gPrefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
    15 function setWatchdogEnabled(enabled) {
    16   gPrefs.setBoolPref("dom.use_watchdog", enabled);
    17 }
    19 function isWatchdogEnabled() {
    20   return gPrefs.getBoolPref("dom.use_watchdog");
    21 }
    23 //
    24 // Utilities.
    25 //
    27 function busyWait(ms) {
    28   var start = new Date();
    29   while ((new Date()) - start < ms) {}
    30 }
    32 function do_log_info(aMessage)
    33 {
    34   print("TEST-INFO | " + _TEST_FILE + " | " + aMessage);
    35 }
    37 // We don't use do_execute_soon, because that inserts a
    38 // do_test_{pending,finished} pair that gets screwed up when we terminate scripts
    39 // from the operation callback.
    40 function executeSoon(fn) {
    41   var tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
    42   tm.mainThread.dispatch({run: fn}, Ci.nsIThread.DISPATCH_NORMAL);
    43 }
    45 //
    46 // Asynchronous watchdog diagnostics.
    47 //
    48 // When running, the watchdog wakes up every second, and fires the operation
    49 // callback if the script has been running for >= one second. As such, a script
    50 // should never be able to run for two seconds or longer without servicing the
    51 // operation callback. We wait 3 seconds, just to be safe.
    52 //
    54 function checkWatchdog(expectInterrupt, continuation) {
    55   var lastWatchdogWakeup = Cu.getWatchdogTimestamp("WatchdogWakeup");
    56   setInterruptCallback(function() {
    57     // If the watchdog didn't actually trigger the operation callback, ignore
    58     // this call. This allows us to test the actual watchdog behavior without
    59     // interference from other sites where we trigger the operation callback.
    60     if (lastWatchdogWakeup == Cu.getWatchdogTimestamp("WatchdogWakeup")) {
    61       return true;
    62     }
    63     do_check_true(expectInterrupt);
    64     setInterruptCallback(undefined);
    65     // Schedule our continuation before we kill this script.
    66     executeSoon(continuation);
    67     return false;
    68   });
    69   executeSoon(function() {
    70     busyWait(3000);
    71     do_check_true(!expectInterrupt);
    72     setInterruptCallback(undefined);
    73     continuation();
    74   });
    75 }
    77 var gGenerator;
    78 function continueTest() {
    79   gGenerator.next();
    80 }
    82 function run_test() {
    84   // Run async.
    85   do_test_pending();
    87   // Instantiate the generator and kick it off.
    88   gGenerator = testBody();
    89   gGenerator.next();
    90 }

mercurial