michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); michael@0: Cu.import("resource://gre/modules/devtools/dbg-client.jsm"); michael@0: michael@0: var gClient; michael@0: var gTabClient; michael@0: var gDebuggee; michael@0: michael@0: function run_test() michael@0: { michael@0: initTestDebuggerServer(); michael@0: gDebuggee = testGlobal("test-1"); michael@0: DebuggerServer.addTestGlobal(gDebuggee); michael@0: michael@0: let transport = DebuggerServer.connectPipe(); michael@0: gClient = new DebuggerClient(transport); michael@0: gClient.connect(function(aType, aTraits) { michael@0: attachTestTab(gClient, "test-1", function(aReply, aTabClient) { michael@0: gTabClient = aTabClient; michael@0: test_threadAttach(aReply.threadActor); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function test_threadAttach(aThreadActorID) michael@0: { michael@0: do_print("Trying to attach to thread " + aThreadActorID); michael@0: gTabClient.attachThread({}, function(aResponse, aThreadClient) { michael@0: do_check_eq(aThreadClient.state, "paused"); michael@0: do_check_eq(aThreadClient.actor, aThreadActorID); michael@0: aThreadClient.resume(function() { michael@0: do_check_eq(aThreadClient.state, "attached"); michael@0: test_debugger_statement(aThreadClient); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function test_debugger_statement(aThreadClient) michael@0: { michael@0: aThreadClient.addListener("paused", function(aEvent, aPacket) { michael@0: do_check_eq(aThreadClient.state, "paused"); michael@0: // Reach around the protocol to check that the debuggee is in the state michael@0: // we expect. michael@0: do_check_true(gDebuggee.a); michael@0: do_check_false(gDebuggee.b); michael@0: michael@0: let xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); michael@0: do_check_eq(xpcInspector.eventLoopNestLevel, 1); michael@0: michael@0: aThreadClient.resume(cleanup); michael@0: }); michael@0: michael@0: Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", gDebuggee); michael@0: michael@0: // Now make sure that we've run the code after the debugger statement... michael@0: do_check_true(gDebuggee.b); michael@0: } michael@0: michael@0: function cleanup() michael@0: { michael@0: gClient.addListener("closed", function(aEvent) { michael@0: do_test_finished(); michael@0: }); michael@0: michael@0: try { michael@0: let xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); michael@0: do_check_eq(xpcInspector.eventLoopNestLevel, 0); michael@0: } catch(e) { michael@0: dump(e); michael@0: } michael@0: michael@0: gClient.close(); michael@0: }