michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test the basic functionality of the nsIJSInspector component. michael@0: var gCount = 0; michael@0: const MAX = 10; michael@0: var inspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); michael@0: var tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager); michael@0: michael@0: // Emulate 10 simultaneously-debugged windows from 3 separate client connections. michael@0: var requestor = (count) => ({ michael@0: url:"http://foo/bar/" + count, michael@0: connection: "conn" + (count % 3) michael@0: }); michael@0: michael@0: function run_test() michael@0: { michael@0: test_nesting(); michael@0: } michael@0: michael@0: function test_nesting() michael@0: { michael@0: do_check_eq(inspector.eventLoopNestLevel, 0); michael@0: michael@0: tm.currentThread.dispatch({ run: enterEventLoop}, 0); michael@0: michael@0: do_check_eq(inspector.enterNestedEventLoop(requestor(gCount)), 0); michael@0: do_check_eq(inspector.eventLoopNestLevel, 0); michael@0: do_check_eq(inspector.lastNestRequestor, null); michael@0: } michael@0: michael@0: function enterEventLoop() { michael@0: if (gCount++ < MAX) { michael@0: tm.currentThread.dispatch({ run: enterEventLoop}, 0); michael@0: michael@0: let r = Object.create(requestor(gCount)); michael@0: michael@0: do_check_eq(inspector.eventLoopNestLevel, gCount); michael@0: do_check_eq(inspector.lastNestRequestor.url, requestor(gCount - 1).url); michael@0: do_check_eq(inspector.lastNestRequestor.connection, requestor(gCount - 1).connection); michael@0: do_check_eq(inspector.enterNestedEventLoop(requestor(gCount)), gCount); michael@0: } else { michael@0: do_check_eq(gCount, MAX + 1); michael@0: tm.currentThread.dispatch({ run: exitEventLoop}, 0); michael@0: } michael@0: } michael@0: michael@0: function exitEventLoop() { michael@0: if (inspector.lastNestRequestor != null) { michael@0: do_check_eq(inspector.lastNestRequestor.url, requestor(gCount - 1).url); michael@0: do_check_eq(inspector.lastNestRequestor.connection, requestor(gCount - 1).connection); michael@0: if (gCount-- > 1) { michael@0: tm.currentThread.dispatch({ run: exitEventLoop}, 0); michael@0: } michael@0: michael@0: do_check_eq(inspector.exitNestedEventLoop(), gCount); michael@0: do_check_eq(inspector.eventLoopNestLevel, gCount); michael@0: } michael@0: }