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 Cu.import("resource://services-sync/util.js");
2 Cu.import("resource://services-sync/service.js");
4 function run_test() {
5 _("Make sure catch when copied to an object will correctly catch stuff");
6 let ret, rightThis, didCall, didThrow, wasTen, wasLocked;
7 let obj = {
8 catch: Utils.catch,
9 _log: {
10 debug: function(str) {
11 didThrow = str.search(/^Exception: /) == 0;
12 },
13 info: function(str) {
14 wasLocked = str.indexOf("Cannot start sync: already syncing?") == 0;
15 }
16 },
18 func: function() this.catch(function() {
19 rightThis = this == obj;
20 didCall = true;
21 return 5;
22 })(),
24 throwy: function() this.catch(function() {
25 rightThis = this == obj;
26 didCall = true;
27 throw 10;
28 })(),
30 callbacky: function() this.catch(function() {
31 rightThis = this == obj;
32 didCall = true;
33 throw 10;
34 }, function(ex) {
35 wasTen = (ex == 10)
36 })(),
38 lockedy: function() this.catch(function() {
39 rightThis = this == obj;
40 didCall = true;
41 throw("Could not acquire lock.");
42 })()
43 };
45 _("Make sure a normal call will call and return");
46 rightThis = didCall = didThrow = wasLocked = false;
47 ret = obj.func();
48 do_check_eq(ret, 5);
49 do_check_true(rightThis);
50 do_check_true(didCall);
51 do_check_false(didThrow);
52 do_check_eq(wasTen, undefined);
53 do_check_false(wasLocked);
55 _("Make sure catch/throw results in debug call and caller doesn't need to handle exception");
56 rightThis = didCall = didThrow = wasLocked = false;
57 ret = obj.throwy();
58 do_check_eq(ret, undefined);
59 do_check_true(rightThis);
60 do_check_true(didCall);
61 do_check_true(didThrow);
62 do_check_eq(wasTen, undefined);
63 do_check_false(wasLocked);
65 _("Test callback for exception testing.");
66 rightThis = didCall = didThrow = wasLocked = false;
67 ret = obj.callbacky();
68 do_check_eq(ret, undefined);
69 do_check_true(rightThis);
70 do_check_true(didCall);
71 do_check_true(didThrow);
72 do_check_true(wasTen);
73 do_check_false(wasLocked);
75 _("Test the lock-aware catch that Service uses.");
76 obj.catch = Service._catch;
77 rightThis = didCall = didThrow = wasLocked = false;
78 wasTen = undefined;
79 ret = obj.lockedy();
80 do_check_eq(ret, undefined);
81 do_check_true(rightThis);
82 do_check_true(didCall);
83 do_check_true(didThrow);
84 do_check_eq(wasTen, undefined);
85 do_check_true(wasLocked);
86 }