Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | } |