toolkit/devtools/server/tests/unit/test_blackboxing-03.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_blackboxing-03.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     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 + * Test that we don't stop at debugger statements inside black boxed sources.
     1.9 + */
    1.10 +
    1.11 +var gDebuggee;
    1.12 +var gClient;
    1.13 +var gThreadClient;
    1.14 +var gBpClient;
    1.15 +
    1.16 +function run_test()
    1.17 +{
    1.18 +  initTestDebuggerServer();
    1.19 +  gDebuggee = addTestGlobal("test-black-box");
    1.20 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.21 +  gClient.connect(function() {
    1.22 +    attachTestTabAndResume(gClient, "test-black-box", function(aResponse, aTabClient, aThreadClient) {
    1.23 +      gThreadClient = aThreadClient;
    1.24 +      test_black_box();
    1.25 +    });
    1.26 +  });
    1.27 +  do_test_pending();
    1.28 +}
    1.29 +
    1.30 +const BLACK_BOXED_URL = "http://example.com/blackboxme.js";
    1.31 +const SOURCE_URL = "http://example.com/source.js";
    1.32 +
    1.33 +function test_black_box()
    1.34 +{
    1.35 +  gClient.addOneTimeListener("paused", function () {
    1.36 +    gThreadClient.setBreakpoint({
    1.37 +      url: SOURCE_URL,
    1.38 +      line: 4
    1.39 +    }, function ({error}, bpClient) {
    1.40 +      gBpClient = bpClient;
    1.41 +      do_check_true(!error, "Should not get an error: " + error);
    1.42 +      gThreadClient.resume(test_black_box_dbg_statement);
    1.43 +    });
    1.44 +  });
    1.45 +
    1.46 +  Components.utils.evalInSandbox(
    1.47 +    "" + function doStuff(k) { // line 1
    1.48 +      debugger;                // line 2 - Break here
    1.49 +      k(100);                  // line 3
    1.50 +    },                         // line 4
    1.51 +    gDebuggee,
    1.52 +    "1.8",
    1.53 +    BLACK_BOXED_URL,
    1.54 +    1
    1.55 +  );
    1.56 +
    1.57 +  Components.utils.evalInSandbox(
    1.58 +    "" + function runTest() { // line 1
    1.59 +      doStuff(                // line 2
    1.60 +        function (n) {        // line 3
    1.61 +          Math.abs(n);        // line 4 - Break here
    1.62 +        }                     // line 5
    1.63 +      );                      // line 6
    1.64 +    }                         // line 7
    1.65 +    + "\n debugger;",         // line 8
    1.66 +    gDebuggee,
    1.67 +    "1.8",
    1.68 +    SOURCE_URL,
    1.69 +    1
    1.70 +  );
    1.71 +}
    1.72 +
    1.73 +function test_black_box_dbg_statement() {
    1.74 +  gThreadClient.getSources(function ({error, sources}) {
    1.75 +    do_check_true(!error, "Should not get an error: " + error);
    1.76 +    let sourceClient = gThreadClient.source(sources.filter(s => s.url == BLACK_BOXED_URL)[0]);
    1.77 +
    1.78 +    sourceClient.blackBox(function ({error}) {
    1.79 +      do_check_true(!error, "Should not get an error: " + error);
    1.80 +
    1.81 +      gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.82 +        do_check_eq(aPacket.why.type, "breakpoint",
    1.83 +                    "We should pass over the debugger statement.");
    1.84 +        gBpClient.remove(function ({error}) {
    1.85 +          do_check_true(!error, "Should not get an error: " + error);
    1.86 +          gThreadClient.resume(test_unblack_box_dbg_statement.bind(null, sourceClient));
    1.87 +        });
    1.88 +      });
    1.89 +      gDebuggee.runTest();
    1.90 +    });
    1.91 +  });
    1.92 +}
    1.93 +
    1.94 +function test_unblack_box_dbg_statement(aSourceClient) {
    1.95 +  aSourceClient.unblackBox(function ({error}) {
    1.96 +    do_check_true(!error, "Should not get an error: " + error);
    1.97 +
    1.98 +    gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.99 +      do_check_eq(aPacket.why.type, "debuggerStatement",
   1.100 +                  "We should stop at the debugger statement again");
   1.101 +      finishClient(gClient);
   1.102 +    });
   1.103 +    gDebuggee.runTest();
   1.104 +  });
   1.105 +}

mercurial