xpcom/tests/unit/test_bug325418.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 const Cc = Components.classes;
     2 const Ci = Components.interfaces;
     4 // 5 seconds.
     5 const kExpectedDelay1 = 5;
     6 // 1 second.
     7 const kExpectedDelay2 = 1;
     9 var gStartTime1;
    10 var gStartTime2;
    11 var timer;
    13 var observer1 = {
    14   observe: function observeTC1(subject, topic, data) {
    15     if (topic == "timer-callback") {
    16       // Stop timer, so it doesn't repeat (if test runs slowly).
    17       timer.cancel();
    19       // Actual delay may not be exact, so convert to seconds and round.
    20       do_check_eq(Math.round((Date.now() - gStartTime1) / 1000),
    21                   kExpectedDelay1);
    23       timer = null;
    25       do_print("1st timer triggered (before being cancelled). Should not have happened!");
    26       do_check_true(false);
    27     }
    28   }
    29 };
    31 var observer2 = {
    32   observe: function observeTC2(subject, topic, data) {
    33     if (topic == "timer-callback") {
    34       // Stop timer, so it doesn't repeat (if test runs slowly).
    35       timer.cancel();
    37       // Actual delay may not be exact, so convert to seconds and round.
    38       do_check_eq(Math.round((Date.now() - gStartTime2) / 1000),
    39                   kExpectedDelay2);
    41       timer = null;
    43       do_test_finished();
    44     }
    45   }
    46 };
    48 function run_test() {
    49   do_test_pending();
    51   timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
    53   // Initialize the timer (with some delay), then cancel it.
    54   gStartTime1 = Date.now();
    55   timer.init(observer1, kExpectedDelay1 * 1000, timer.TYPE_REPEATING_PRECISE);
    56   timer.cancel();
    58   // Re-initialize the timer (with a different delay).
    59   gStartTime2 = Date.now();
    60   timer.init(observer2, kExpectedDelay2 * 1000, timer.TYPE_REPEATING_PRECISE);
    61 }

mercurial