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.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 Cu.import("resource://services-common/utils.js");
6 function run_test() {
7 run_next_test();
8 }
10 add_test(function test_required_args() {
11 try {
12 CommonUtils.namedTimer(function callback() {
13 do_throw("Shouldn't fire.");
14 }, 0);
15 do_throw("Should have thrown!");
16 } catch(ex) {
17 run_next_test();
18 }
19 });
21 add_test(function test_simple() {
22 _("Test basic properties of CommonUtils.namedTimer.");
24 const delay = 200;
25 let that = {};
26 let t0 = Date.now();
27 CommonUtils.namedTimer(function callback(timer) {
28 do_check_eq(this, that);
29 do_check_eq(this._zetimer, null);
30 do_check_true(timer instanceof Ci.nsITimer);
31 // Difference should be ~delay, but hard to predict on all platforms,
32 // particularly Windows XP.
33 do_check_true(Date.now() > t0);
34 run_next_test();
35 }, delay, that, "_zetimer");
36 });
38 add_test(function test_delay() {
39 _("Test delaying a timer that hasn't fired yet.");
41 const delay = 100;
42 let that = {};
43 let t0 = Date.now();
44 function callback(timer) {
45 // Difference should be ~2*delay, but hard to predict on all platforms,
46 // particularly Windows XP.
47 do_check_true((Date.now() - t0) > delay);
48 run_next_test();
49 }
50 CommonUtils.namedTimer(callback, delay, that, "_zetimer");
51 CommonUtils.namedTimer(callback, 2 * delay, that, "_zetimer");
52 run_next_test();
53 });
55 add_test(function test_clear() {
56 _("Test clearing a timer that hasn't fired yet.");
58 const delay = 0;
59 let that = {};
60 CommonUtils.namedTimer(function callback(timer) {
61 do_throw("Shouldn't fire!");
62 }, delay, that, "_zetimer");
64 that._zetimer.clear();
65 do_check_eq(that._zetimer, null);
66 CommonUtils.nextTick(run_next_test);
68 run_next_test();
69 });