1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_breakpoint-12.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 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 + * Make sure that setting a breakpoint twice in a line without bytecodes works 1.9 + * as expected. 1.10 + */ 1.11 + 1.12 +const NUM_BREAKPOINTS = 10; 1.13 +var gDebuggee; 1.14 +var gClient; 1.15 +var gThreadClient; 1.16 +var gPath = getFilePath('test_breakpoint-12.js'); 1.17 +var gBpActor; 1.18 +var gCount = 1; 1.19 + 1.20 +function run_test() 1.21 +{ 1.22 + initTestDebuggerServer(); 1.23 + gDebuggee = addTestGlobal("test-stack"); 1.24 + gClient = new DebuggerClient(DebuggerServer.connectPipe()); 1.25 + gClient.connect(function () { 1.26 + attachTestTabAndResume(gClient, "test-stack", function (aResponse, aTabClient, aThreadClient) { 1.27 + gThreadClient = aThreadClient; 1.28 + test_child_skip_breakpoint(); 1.29 + }); 1.30 + }); 1.31 + do_test_pending(); 1.32 +} 1.33 + 1.34 +function test_child_skip_breakpoint() 1.35 +{ 1.36 + gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.37 + let location = { url: gPath, line: gDebuggee.line0 + 3}; 1.38 + gThreadClient.setBreakpoint(location, function (aResponse, bpClient) { 1.39 + // Check that the breakpoint has properly skipped forward one line. 1.40 + do_check_eq(aResponse.actualLocation.url, location.url); 1.41 + do_check_eq(aResponse.actualLocation.line, location.line + 1); 1.42 + gBpActor = aResponse.actor; 1.43 + 1.44 + // Set more breakpoints at the same location. 1.45 + set_breakpoints(location); 1.46 + }); 1.47 + 1.48 + }); 1.49 + 1.50 + gDebuggee.eval("var line0 = Error().lineNumber;\n" + 1.51 + "function foo() {\n" + // line0 + 1 1.52 + " this.a = 1;\n" + // line0 + 2 1.53 + " // A comment.\n" + // line0 + 3 1.54 + " this.b = 2;\n" + // line0 + 4 1.55 + "}\n" + // line0 + 5 1.56 + "debugger;\n" + // line0 + 6 1.57 + "foo();\n"); // line0 + 7 1.58 +} 1.59 + 1.60 +// Set many breakpoints at the same location. 1.61 +function set_breakpoints(location) { 1.62 + do_check_neq(gCount, NUM_BREAKPOINTS); 1.63 + gThreadClient.setBreakpoint(location, function (aResponse, bpClient) { 1.64 + // Check that the breakpoint has properly skipped forward one line. 1.65 + do_check_eq(aResponse.actualLocation.url, location.url); 1.66 + do_check_eq(aResponse.actualLocation.line, location.line + 1); 1.67 + // Check that the same breakpoint actor was returned. 1.68 + do_check_eq(aResponse.actor, gBpActor); 1.69 + 1.70 + if (++gCount < NUM_BREAKPOINTS) { 1.71 + set_breakpoints(location); 1.72 + return; 1.73 + } 1.74 + 1.75 + // After setting all the breakpoints, check that only one has effectively 1.76 + // remained. 1.77 + gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.78 + // Check the return value. 1.79 + do_check_eq(aPacket.type, "paused"); 1.80 + do_check_eq(aPacket.frame.where.url, gPath); 1.81 + do_check_eq(aPacket.frame.where.line, location.line + 1); 1.82 + do_check_eq(aPacket.why.type, "breakpoint"); 1.83 + do_check_eq(aPacket.why.actors[0], bpClient.actor); 1.84 + // Check that the breakpoint worked. 1.85 + do_check_eq(gDebuggee.a, 1); 1.86 + do_check_eq(gDebuggee.b, undefined); 1.87 + 1.88 + gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { 1.89 + // We don't expect any more pauses after the breakpoint was hit once. 1.90 + do_check_true(false); 1.91 + }); 1.92 + gThreadClient.resume(function () { 1.93 + // Give any remaining breakpoints a chance to trigger. 1.94 + do_timeout(1000, finishClient.bind(null, gClient)); 1.95 + }); 1.96 + 1.97 + }); 1.98 + // Continue until the breakpoint is hit. 1.99 + gThreadClient.resume(); 1.100 + }); 1.101 + 1.102 +}