toolkit/devtools/server/tests/unit/test_nsjsinspector.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:29bd8a582987
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 // Test the basic functionality of the nsIJSInspector component.
5 var gCount = 0;
6 const MAX = 10;
7 var inspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
8 var tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
9
10 // Emulate 10 simultaneously-debugged windows from 3 separate client connections.
11 var requestor = (count) => ({
12 url:"http://foo/bar/" + count,
13 connection: "conn" + (count % 3)
14 });
15
16 function run_test()
17 {
18 test_nesting();
19 }
20
21 function test_nesting()
22 {
23 do_check_eq(inspector.eventLoopNestLevel, 0);
24
25 tm.currentThread.dispatch({ run: enterEventLoop}, 0);
26
27 do_check_eq(inspector.enterNestedEventLoop(requestor(gCount)), 0);
28 do_check_eq(inspector.eventLoopNestLevel, 0);
29 do_check_eq(inspector.lastNestRequestor, null);
30 }
31
32 function enterEventLoop() {
33 if (gCount++ < MAX) {
34 tm.currentThread.dispatch({ run: enterEventLoop}, 0);
35
36 let r = Object.create(requestor(gCount));
37
38 do_check_eq(inspector.eventLoopNestLevel, gCount);
39 do_check_eq(inspector.lastNestRequestor.url, requestor(gCount - 1).url);
40 do_check_eq(inspector.lastNestRequestor.connection, requestor(gCount - 1).connection);
41 do_check_eq(inspector.enterNestedEventLoop(requestor(gCount)), gCount);
42 } else {
43 do_check_eq(gCount, MAX + 1);
44 tm.currentThread.dispatch({ run: exitEventLoop}, 0);
45 }
46 }
47
48 function exitEventLoop() {
49 if (inspector.lastNestRequestor != null) {
50 do_check_eq(inspector.lastNestRequestor.url, requestor(gCount - 1).url);
51 do_check_eq(inspector.lastNestRequestor.connection, requestor(gCount - 1).connection);
52 if (gCount-- > 1) {
53 tm.currentThread.dispatch({ run: exitEventLoop}, 0);
54 }
55
56 do_check_eq(inspector.exitNestedEventLoop(), gCount);
57 do_check_eq(inspector.eventLoopNestLevel, gCount);
58 }
59 }

mercurial