toolkit/devtools/server/tests/unit/test_blackboxing-05.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-05.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     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 exceptions inside black boxed sources.
     1.9 + */
    1.10 +
    1.11 +var gDebuggee;
    1.12 +var gClient;
    1.13 +var gThreadClient;
    1.14 +
    1.15 +function run_test()
    1.16 +{
    1.17 +  initTestDebuggerServer();
    1.18 +  gDebuggee = addTestGlobal("test-black-box");
    1.19 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.20 +  gClient.connect(function() {
    1.21 +    attachTestTabAndResume(gClient, "test-black-box", function(aResponse, aTabClient, aThreadClient) {
    1.22 +      gThreadClient = aThreadClient;
    1.23 +      // XXX: We have to do an executeSoon so that the error isn't caught and
    1.24 +      // reported by DebuggerClient.requester (because we are using the local
    1.25 +      // transport and share a stack) which causes the test to fail.
    1.26 +      Services.tm.mainThread.dispatch({
    1.27 +        run: test_black_box
    1.28 +      }, Ci.nsIThread.DISPATCH_NORMAL);
    1.29 +    });
    1.30 +  });
    1.31 +  do_test_pending();
    1.32 +}
    1.33 +
    1.34 +const BLACK_BOXED_URL = "http://example.com/blackboxme.js";
    1.35 +const SOURCE_URL = "http://example.com/source.js";
    1.36 +
    1.37 +function test_black_box()
    1.38 +{
    1.39 +  gClient.addOneTimeListener("paused", test_black_box_exception);
    1.40 +
    1.41 +  Components.utils.evalInSandbox(
    1.42 +    "" + function doStuff(k) {                                   // line 1
    1.43 +      throw new Error("wu tang clan ain't nuthin' ta fuck wit"); // line 2
    1.44 +      k(100);                                                    // line 3
    1.45 +    },                                                           // line 4
    1.46 +    gDebuggee,
    1.47 +    "1.8",
    1.48 +    BLACK_BOXED_URL,
    1.49 +    1
    1.50 +  );
    1.51 +
    1.52 +  Components.utils.evalInSandbox(
    1.53 +    "" + function runTest() {                   // line 1
    1.54 +      doStuff(                                  // line 2
    1.55 +        function (n) {                          // line 3
    1.56 +          debugger;                             // line 4
    1.57 +        }                                       // line 5
    1.58 +      );                                        // line 6
    1.59 +    }                                           // line 7
    1.60 +    + "\ndebugger;\n"                           // line 8
    1.61 +    + "try { runTest() } catch (ex) { }",       // line 9
    1.62 +    gDebuggee,
    1.63 +    "1.8",
    1.64 +    SOURCE_URL,
    1.65 +    1
    1.66 +  );
    1.67 +}
    1.68 +
    1.69 +function test_black_box_exception() {
    1.70 +  gThreadClient.getSources(function ({error, sources}) {
    1.71 +    do_check_true(!error, "Should not get an error: " + error);
    1.72 +    let sourceClient = gThreadClient.source(sources.filter(s => s.url == BLACK_BOXED_URL)[0]);
    1.73 +
    1.74 +    sourceClient.blackBox(function ({error}) {
    1.75 +      do_check_true(!error, "Should not get an error: " + error);
    1.76 +      gThreadClient.pauseOnExceptions(true);
    1.77 +
    1.78 +      gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.79 +        do_check_neq(aPacket.frame.where.url, BLACK_BOXED_URL,
    1.80 +                     "We shouldn't pause while in the black boxed source.");
    1.81 +        finishClient(gClient);
    1.82 +      });
    1.83 +
    1.84 +      gThreadClient.resume();
    1.85 +    });
    1.86 +  });
    1.87 +}

mercurial