1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_breakpoint-13.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Check that execution doesn't pause twice while stepping, when encountering 1.9 + * either a breakpoint or a debugger statement. 1.10 + */ 1.11 + 1.12 +var gDebuggee; 1.13 +var gClient; 1.14 +var gThreadClient; 1.15 + 1.16 +function run_test() 1.17 +{ 1.18 + initTestDebuggerServer(); 1.19 + gDebuggee = addTestGlobal("test-stack"); 1.20 + gClient = new DebuggerClient(DebuggerServer.connectPipe()); 1.21 + gClient.connect(function () { 1.22 + attachTestTabAndResume(gClient, "test-stack", function (aResponse, aTabClient, aThreadClient) { 1.23 + gThreadClient = aThreadClient; 1.24 + test_simple_breakpoint(); 1.25 + }); 1.26 + }); 1.27 + do_test_pending(); 1.28 +} 1.29 + 1.30 +function test_simple_breakpoint() 1.31 +{ 1.32 + gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.33 + let path = getFilePath('test_breakpoint-13.js'); 1.34 + let location = { url: path, line: gDebuggee.line0 + 2}; 1.35 + gThreadClient.setBreakpoint(location, function (aResponse, bpClient) { 1.36 + gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.37 + // Check that the stepping worked. 1.38 + do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 5); 1.39 + do_check_eq(aPacket.why.type, "resumeLimit"); 1.40 + 1.41 + gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.42 + // Entered the foo function call frame. 1.43 + do_check_eq(aPacket.frame.where.line, location.line); 1.44 + do_check_neq(aPacket.why.type, "breakpoint"); 1.45 + do_check_eq(aPacket.why.type, "resumeLimit"); 1.46 + 1.47 + gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.48 + // Check that the breakpoint wasn't the reason for this pause, but 1.49 + // that the frame is about to be popped while stepping. 1.50 + do_check_eq(aPacket.frame.where.line, location.line); 1.51 + do_check_neq(aPacket.why.type, "breakpoint"); 1.52 + do_check_eq(aPacket.why.type, "resumeLimit"); 1.53 + do_check_eq(aPacket.why.frameFinished.return.type, "undefined"); 1.54 + 1.55 + gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.56 + // The foo function call frame was just popped from the stack. 1.57 + do_check_eq(gDebuggee.a, 1); 1.58 + do_check_eq(gDebuggee.b, undefined); 1.59 + do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 5); 1.60 + do_check_eq(aPacket.why.type, "resumeLimit"); 1.61 + do_check_eq(aPacket.poppedFrames.length, 1); 1.62 + 1.63 + gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.64 + // Check that the debugger statement wasn't the reason for this pause. 1.65 + do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 6); 1.66 + do_check_neq(aPacket.why.type, "debuggerStatement"); 1.67 + do_check_eq(aPacket.why.type, "resumeLimit"); 1.68 + 1.69 + gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.70 + // Check that the debugger statement wasn't the reason for this pause. 1.71 + do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 7); 1.72 + do_check_neq(aPacket.why.type, "debuggerStatement"); 1.73 + do_check_eq(aPacket.why.type, "resumeLimit"); 1.74 + 1.75 + // Remove the breakpoint and finish. 1.76 + bpClient.remove(() => gThreadClient.resume(() => finishClient(gClient))); 1.77 + 1.78 + }); 1.79 + // Step past the debugger statement. 1.80 + gThreadClient.stepIn(); 1.81 + }); 1.82 + // Step into the debugger statement. 1.83 + gThreadClient.stepIn(); 1.84 + }); 1.85 + // Get back to the frame above. 1.86 + gThreadClient.stepIn(); 1.87 + }); 1.88 + // Step to the end of the function call frame. 1.89 + gThreadClient.stepIn(); 1.90 + }); 1.91 + 1.92 + // Step into the function call. 1.93 + gThreadClient.stepIn(); 1.94 + }); 1.95 + // Step into the next line with the function call. 1.96 + gThreadClient.stepIn(); 1.97 + }); 1.98 + }); 1.99 + 1.100 + gDebuggee.eval("var line0 = Error().lineNumber;\n" + 1.101 + "function foo() {\n" + // line0 + 1 1.102 + " this.a = 1;\n" + // line0 + 2 <-- Breakpoint is set here. 1.103 + "}\n" + // line0 + 3 1.104 + "debugger;\n" + // line0 + 4 1.105 + "foo();\n" + // line0 + 5 1.106 + "debugger;\n" + // line0 + 6 1.107 + "var b = 2;\n"); // line0 + 7 1.108 +}