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 gDebuggee; michael@0: michael@0: const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); 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.addListener("connected", function(aEvent, aType, aTraits) { michael@0: gClient.listTabs((aResponse) => { michael@0: do_check_true('tabs' in aResponse); michael@0: for (let tab of aResponse.tabs) { michael@0: if (tab.title == "test-1") { michael@0: test_attach_tab(tab.actor); michael@0: return false; michael@0: } michael@0: } michael@0: do_check_true(false); // We should have found our tab in the list. michael@0: return undefined; michael@0: }); michael@0: }); michael@0: michael@0: gClient.connect(); michael@0: michael@0: do_test_pending(); michael@0: } michael@0: michael@0: // Attach to |aTabActor|, and check the response. michael@0: function test_attach_tab(aTabActor) michael@0: { michael@0: gClient.request({ to: aTabActor, type: "attach" }, function(aResponse) { michael@0: do_check_false("error" in aResponse); michael@0: do_check_eq(aResponse.from, aTabActor); michael@0: do_check_eq(aResponse.type, "tabAttached"); michael@0: do_check_true(typeof aResponse.threadActor === "string"); michael@0: michael@0: test_attach_thread(aResponse.threadActor); michael@0: }); michael@0: } michael@0: michael@0: // Attach to |aThreadActor|, check the response, and resume it. michael@0: function test_attach_thread(aThreadActor) michael@0: { michael@0: gClient.request({ to: aThreadActor, type: "attach" }, function(aResponse) { michael@0: do_check_false("error" in aResponse); michael@0: do_check_eq(aResponse.from, aThreadActor); michael@0: do_check_eq(aResponse.type, "paused"); michael@0: do_check_true("why" in aResponse); michael@0: do_check_eq(aResponse.why.type, "attached"); michael@0: michael@0: test_resume_thread(aThreadActor); michael@0: }); michael@0: } michael@0: michael@0: // Resume |aThreadActor|, and see that it stops at the 'debugger' michael@0: // statement. michael@0: function test_resume_thread(aThreadActor) michael@0: { michael@0: // Allow the client to resume execution. michael@0: gClient.request({ to: aThreadActor, type: "resume" }, function (aResponse) { michael@0: do_check_false("error" in aResponse); michael@0: do_check_eq(aResponse.from, aThreadActor); michael@0: do_check_eq(aResponse.type, "resumed"); michael@0: michael@0: do_check_eq(xpcInspector.eventLoopNestLevel, 0); michael@0: michael@0: // Now that we know we're resumed, we can make the debuggee do something. michael@0: Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", gDebuggee); 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: gClient.addListener("paused", function(aName, aPacket) { michael@0: do_check_eq(aName, "paused"); michael@0: do_check_false("error" in aPacket); michael@0: do_check_eq(aPacket.from, aThreadActor); michael@0: do_check_eq(aPacket.type, "paused"); michael@0: do_check_true("actor" in aPacket); michael@0: do_check_true("why" in aPacket) michael@0: do_check_eq(aPacket.why.type, "debuggerStatement"); michael@0: 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: do_check_eq(xpcInspector.eventLoopNestLevel, 1); michael@0: michael@0: // Let the debuggee continue execution. michael@0: gClient.request({ to: aThreadActor, type: "resume" }, cleanup); michael@0: }); michael@0: } michael@0: michael@0: function cleanup() michael@0: { michael@0: gClient.addListener("closed", function(aEvent, aResult) { 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: }