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.

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

mercurial