1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_dbgactor.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); 1.8 +Cu.import("resource://gre/modules/devtools/dbg-client.jsm"); 1.9 + 1.10 +var gClient; 1.11 +var gDebuggee; 1.12 + 1.13 +const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); 1.14 + 1.15 +function run_test() 1.16 +{ 1.17 + initTestDebuggerServer(); 1.18 + gDebuggee = testGlobal("test-1"); 1.19 + DebuggerServer.addTestGlobal(gDebuggee); 1.20 + 1.21 + let transport = DebuggerServer.connectPipe(); 1.22 + gClient = new DebuggerClient(transport); 1.23 + gClient.addListener("connected", function(aEvent, aType, aTraits) { 1.24 + gClient.listTabs((aResponse) => { 1.25 + do_check_true('tabs' in aResponse); 1.26 + for (let tab of aResponse.tabs) { 1.27 + if (tab.title == "test-1") { 1.28 + test_attach_tab(tab.actor); 1.29 + return false; 1.30 + } 1.31 + } 1.32 + do_check_true(false); // We should have found our tab in the list. 1.33 + return undefined; 1.34 + }); 1.35 + }); 1.36 + 1.37 + gClient.connect(); 1.38 + 1.39 + do_test_pending(); 1.40 +} 1.41 + 1.42 +// Attach to |aTabActor|, and check the response. 1.43 +function test_attach_tab(aTabActor) 1.44 +{ 1.45 + gClient.request({ to: aTabActor, type: "attach" }, function(aResponse) { 1.46 + do_check_false("error" in aResponse); 1.47 + do_check_eq(aResponse.from, aTabActor); 1.48 + do_check_eq(aResponse.type, "tabAttached"); 1.49 + do_check_true(typeof aResponse.threadActor === "string"); 1.50 + 1.51 + test_attach_thread(aResponse.threadActor); 1.52 + }); 1.53 +} 1.54 + 1.55 +// Attach to |aThreadActor|, check the response, and resume it. 1.56 +function test_attach_thread(aThreadActor) 1.57 +{ 1.58 + gClient.request({ to: aThreadActor, type: "attach" }, function(aResponse) { 1.59 + do_check_false("error" in aResponse); 1.60 + do_check_eq(aResponse.from, aThreadActor); 1.61 + do_check_eq(aResponse.type, "paused"); 1.62 + do_check_true("why" in aResponse); 1.63 + do_check_eq(aResponse.why.type, "attached"); 1.64 + 1.65 + test_resume_thread(aThreadActor); 1.66 + }); 1.67 +} 1.68 + 1.69 +// Resume |aThreadActor|, and see that it stops at the 'debugger' 1.70 +// statement. 1.71 +function test_resume_thread(aThreadActor) 1.72 +{ 1.73 + // Allow the client to resume execution. 1.74 + gClient.request({ to: aThreadActor, type: "resume" }, function (aResponse) { 1.75 + do_check_false("error" in aResponse); 1.76 + do_check_eq(aResponse.from, aThreadActor); 1.77 + do_check_eq(aResponse.type, "resumed"); 1.78 + 1.79 + do_check_eq(xpcInspector.eventLoopNestLevel, 0); 1.80 + 1.81 + // Now that we know we're resumed, we can make the debuggee do something. 1.82 + Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", gDebuggee); 1.83 + // Now make sure that we've run the code after the debugger statement... 1.84 + do_check_true(gDebuggee.b); 1.85 + }); 1.86 + 1.87 + gClient.addListener("paused", function(aName, aPacket) { 1.88 + do_check_eq(aName, "paused"); 1.89 + do_check_false("error" in aPacket); 1.90 + do_check_eq(aPacket.from, aThreadActor); 1.91 + do_check_eq(aPacket.type, "paused"); 1.92 + do_check_true("actor" in aPacket); 1.93 + do_check_true("why" in aPacket) 1.94 + do_check_eq(aPacket.why.type, "debuggerStatement"); 1.95 + 1.96 + // Reach around the protocol to check that the debuggee is in the state 1.97 + // we expect. 1.98 + do_check_true(gDebuggee.a); 1.99 + do_check_false(gDebuggee.b); 1.100 + 1.101 + do_check_eq(xpcInspector.eventLoopNestLevel, 1); 1.102 + 1.103 + // Let the debuggee continue execution. 1.104 + gClient.request({ to: aThreadActor, type: "resume" }, cleanup); 1.105 + }); 1.106 +} 1.107 + 1.108 +function cleanup() 1.109 +{ 1.110 + gClient.addListener("closed", function(aEvent, aResult) { 1.111 + do_test_finished(); 1.112 + }); 1.113 + 1.114 + try { 1.115 + let xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); 1.116 + do_check_eq(xpcInspector.eventLoopNestLevel, 0); 1.117 + } catch(e) { 1.118 + dump(e); 1.119 + } 1.120 + 1.121 + gClient.close(); 1.122 +}