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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/server/tests/unit/test_nsjsinspector.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Test the basic functionality of the nsIJSInspector component.
     1.8 +var gCount = 0;
     1.9 +const MAX = 10;
    1.10 +var inspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
    1.11 +var tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
    1.12 +
    1.13 +// Emulate 10 simultaneously-debugged windows from 3 separate client connections.
    1.14 +var requestor = (count) => ({
    1.15 +  url:"http://foo/bar/" + count,
    1.16 +  connection: "conn" + (count % 3)
    1.17 +});
    1.18 +
    1.19 +function run_test()
    1.20 +{
    1.21 +  test_nesting();
    1.22 +}
    1.23 +
    1.24 +function test_nesting()
    1.25 +{
    1.26 +  do_check_eq(inspector.eventLoopNestLevel, 0);
    1.27 +
    1.28 +  tm.currentThread.dispatch({ run: enterEventLoop}, 0);
    1.29 +
    1.30 +  do_check_eq(inspector.enterNestedEventLoop(requestor(gCount)), 0);
    1.31 +  do_check_eq(inspector.eventLoopNestLevel, 0);
    1.32 +  do_check_eq(inspector.lastNestRequestor, null);
    1.33 +}
    1.34 +
    1.35 +function enterEventLoop() {
    1.36 +  if (gCount++ < MAX) {
    1.37 +    tm.currentThread.dispatch({ run: enterEventLoop}, 0);
    1.38 +
    1.39 +    let r = Object.create(requestor(gCount));
    1.40 +
    1.41 +    do_check_eq(inspector.eventLoopNestLevel, gCount);
    1.42 +    do_check_eq(inspector.lastNestRequestor.url, requestor(gCount - 1).url);
    1.43 +    do_check_eq(inspector.lastNestRequestor.connection, requestor(gCount - 1).connection);
    1.44 +    do_check_eq(inspector.enterNestedEventLoop(requestor(gCount)), gCount);
    1.45 +  } else {
    1.46 +    do_check_eq(gCount, MAX + 1);
    1.47 +    tm.currentThread.dispatch({ run: exitEventLoop}, 0);
    1.48 +  }
    1.49 +}
    1.50 +
    1.51 +function exitEventLoop() {
    1.52 +  if (inspector.lastNestRequestor != null) {
    1.53 +    do_check_eq(inspector.lastNestRequestor.url, requestor(gCount - 1).url);
    1.54 +    do_check_eq(inspector.lastNestRequestor.connection, requestor(gCount - 1).connection);
    1.55 +    if (gCount-- > 1) {
    1.56 +      tm.currentThread.dispatch({ run: exitEventLoop}, 0);
    1.57 +    }
    1.58 +
    1.59 +    do_check_eq(inspector.exitNestedEventLoop(), gCount);
    1.60 +    do_check_eq(inspector.eventLoopNestLevel, gCount);
    1.61 +  }
    1.62 +}

mercurial