toolkit/devtools/server/tests/unit/test_breakpoint-14.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/server/tests/unit/test_breakpoint-14.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     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 a breakpoint or a debugger statement cause execution to pause even
     1.9 + * in a stepped-over function.
    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-14.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 +          // Reached the breakpoint.
    1.43 +          do_check_eq(aPacket.frame.where.line, location.line);
    1.44 +          do_check_eq(aPacket.why.type, "breakpoint");
    1.45 +          do_check_neq(aPacket.why.type, "resumeLimit");
    1.46 +
    1.47 +          gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.48 +            // The frame is about to be popped while stepping.
    1.49 +            do_check_eq(aPacket.frame.where.line, location.line);
    1.50 +            do_check_neq(aPacket.why.type, "breakpoint");
    1.51 +            do_check_eq(aPacket.why.type, "resumeLimit");
    1.52 +            do_check_eq(aPacket.why.frameFinished.return.type, "undefined");
    1.53 +
    1.54 +            gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.55 +              // The foo function call frame was just popped from the stack.
    1.56 +              do_check_eq(gDebuggee.a, 1);
    1.57 +              do_check_eq(gDebuggee.b, undefined);
    1.58 +              do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 5);
    1.59 +              do_check_eq(aPacket.why.type, "resumeLimit");
    1.60 +              do_check_eq(aPacket.poppedFrames.length, 1);
    1.61 +
    1.62 +              gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.63 +                // Check that the debugger statement wasn't the reason for this pause.
    1.64 +                do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 6);
    1.65 +                do_check_neq(aPacket.why.type, "debuggerStatement");
    1.66 +                do_check_eq(aPacket.why.type, "resumeLimit");
    1.67 +
    1.68 +                gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.69 +                  // Check that the debugger statement wasn't the reason for this pause.
    1.70 +                  do_check_eq(aPacket.frame.where.line, gDebuggee.line0 + 7);
    1.71 +                  do_check_neq(aPacket.why.type, "debuggerStatement");
    1.72 +                  do_check_eq(aPacket.why.type, "resumeLimit");
    1.73 +
    1.74 +                  // Remove the breakpoint and finish.
    1.75 +                  bpClient.remove(() => gThreadClient.resume(() => finishClient(gClient)));
    1.76 +
    1.77 +                });
    1.78 +                // Step past the debugger statement.
    1.79 +                gThreadClient.stepOver();
    1.80 +              });
    1.81 +              // Step over the debugger statement.
    1.82 +              gThreadClient.stepOver();
    1.83 +            });
    1.84 +            // Get back to the frame above.
    1.85 +            gThreadClient.stepOver();
    1.86 +          });
    1.87 +          // Step to the end of the function call frame.
    1.88 +          gThreadClient.stepOver();
    1.89 +        });
    1.90 +        // Step over the function call.
    1.91 +        gThreadClient.stepOver();
    1.92 +      });
    1.93 +      // Step over to the next line with the function call.
    1.94 +      gThreadClient.stepOver();
    1.95 +    });
    1.96 +  });
    1.97 +
    1.98 +  gDebuggee.eval("var line0 = Error().lineNumber;\n" +
    1.99 +                 "function foo() {\n" + // line0 + 1
   1.100 +                 "  this.a = 1;\n" +    // line0 + 2 <-- Breakpoint is set here.
   1.101 +                 "}\n" +                // line0 + 3
   1.102 +                 "debugger;\n" +        // line0 + 4
   1.103 +                 "foo();\n" +           // line0 + 5
   1.104 +                 "debugger;\n" +        // line0 + 6
   1.105 +                 "var b = 2;\n");       // line0 + 7
   1.106 +}

mercurial