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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 // 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);
    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 });
    16 function run_test()
    17 {
    18   test_nesting();
    19 }
    21 function test_nesting()
    22 {
    23   do_check_eq(inspector.eventLoopNestLevel, 0);
    25   tm.currentThread.dispatch({ run: enterEventLoop}, 0);
    27   do_check_eq(inspector.enterNestedEventLoop(requestor(gCount)), 0);
    28   do_check_eq(inspector.eventLoopNestLevel, 0);
    29   do_check_eq(inspector.lastNestRequestor, null);
    30 }
    32 function enterEventLoop() {
    33   if (gCount++ < MAX) {
    34     tm.currentThread.dispatch({ run: enterEventLoop}, 0);
    36     let r = Object.create(requestor(gCount));
    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 }
    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     }
    56     do_check_eq(inspector.exitNestedEventLoop(), gCount);
    57     do_check_eq(inspector.eventLoopNestLevel, gCount);
    58   }
    59 }

mercurial