toolkit/devtools/server/tests/unit/test_blackboxing-06.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-06.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 can black box source mapped sources.
     1.9 + */
    1.10 +
    1.11 +var gDebuggee;
    1.12 +var gClient;
    1.13 +var gThreadClient;
    1.14 +
    1.15 +Components.utils.import('resource:///modules/devtools/SourceMap.jsm');
    1.16 +
    1.17 +function run_test()
    1.18 +{
    1.19 +  initTestDebuggerServer();
    1.20 +  gDebuggee = addTestGlobal("test-black-box");
    1.21 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.22 +  gClient.connect(function() {
    1.23 +    attachTestTabAndResume(gClient, "test-black-box", function(aResponse, aTabClient, aThreadClient) {
    1.24 +      gThreadClient = aThreadClient;
    1.25 +
    1.26 +      promise.resolve(setup_code())
    1.27 +        .then(black_box_code)
    1.28 +        .then(run_code)
    1.29 +        .then(test_correct_location)
    1.30 +        .then(null, function (error) {
    1.31 +          do_check_true(false, "Should not get an error, got " + error);
    1.32 +        })
    1.33 +        .then(function () {
    1.34 +          finishClient(gClient);
    1.35 +        });
    1.36 +    });
    1.37 +  });
    1.38 +  do_test_pending();
    1.39 +}
    1.40 +
    1.41 +function setup_code() {
    1.42 +  let { code, map } = (new SourceNode(null, null, null, [
    1.43 +    new SourceNode(1, 0, "a.js", "" + function a() {
    1.44 +      return b();
    1.45 +    }),
    1.46 +    "\n",
    1.47 +    new SourceNode(1, 0, "b.js", "" + function b() {
    1.48 +      debugger; // Don't want to stop here.
    1.49 +      return c();
    1.50 +    }),
    1.51 +    "\n",
    1.52 +    new SourceNode(1, 0, "c.js", "" + function c() {
    1.53 +      debugger; // Want to stop here.
    1.54 +    }),
    1.55 +    "\n"
    1.56 +  ])).toStringWithSourceMap({
    1.57 +    file: "abc.js",
    1.58 +    sourceRoot: "http://example.com/"
    1.59 +  });
    1.60 +
    1.61 +  code += "//# sourceMappingURL=data:text/json," + map.toString();
    1.62 +
    1.63 +  Components.utils.evalInSandbox(code,
    1.64 +                                 gDebuggee,
    1.65 +                                 "1.8",
    1.66 +                                 "http://example.com/abc.js");
    1.67 +}
    1.68 +
    1.69 +function black_box_code() {
    1.70 +  const d = promise.defer();
    1.71 +
    1.72 +  gThreadClient.getSources(function ({ sources, error }) {
    1.73 +    do_check_true(!error, "Shouldn't get an error getting sources");
    1.74 +    const source = sources.filter((s) => {
    1.75 +      return s.url.indexOf("b.js") !== -1;
    1.76 +    })[0];
    1.77 +    do_check_true(!!source, "We should have our source in the sources list");
    1.78 +
    1.79 +    gThreadClient.source(source).blackBox(function ({ error }) {
    1.80 +      do_check_true(!error, "Should not get an error black boxing");
    1.81 +      d.resolve(true);
    1.82 +    });
    1.83 +  });
    1.84 +
    1.85 +  return d.promise;
    1.86 +}
    1.87 +
    1.88 +function run_code() {
    1.89 +  const d = promise.defer();
    1.90 +
    1.91 +  gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.92 +    d.resolve(aPacket);
    1.93 +    gThreadClient.resume();
    1.94 +  });
    1.95 +  gDebuggee.a();
    1.96 +
    1.97 +  return d.promise;
    1.98 +}
    1.99 +
   1.100 +function test_correct_location(aPacket) {
   1.101 +  do_check_eq(aPacket.why.type, "debuggerStatement",
   1.102 +              "Should hit a debugger statement.");
   1.103 +  do_check_eq(aPacket.frame.where.url, "http://example.com/c.js",
   1.104 +              "Should have skipped over the debugger statement in the black boxed source");
   1.105 +}

mercurial