toolkit/devtools/server/tests/unit/test_sourcemaps-12.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_sourcemaps-12.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     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 we continue stepping when a single original source's line
     1.9 + * corresponds to multiple generated js lines.
    1.10 + */
    1.11 +
    1.12 +var gDebuggee;
    1.13 +var gClient;
    1.14 +var gThreadClient;
    1.15 +
    1.16 +Components.utils.import('resource:///modules/devtools/SourceMap.jsm');
    1.17 +
    1.18 +function run_test() {
    1.19 +  initTestDebuggerServer();
    1.20 +  gDebuggee = addTestGlobal("test-source-map");
    1.21 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.22 +  gClient.connect(function() {
    1.23 +    attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) {
    1.24 +      gThreadClient = aThreadClient;
    1.25 +      define_code();
    1.26 +    });
    1.27 +  });
    1.28 +  do_test_pending();
    1.29 +}
    1.30 +
    1.31 +function define_code() {
    1.32 +  let { code, map } = (new SourceNode(null, null, null, [
    1.33 +    new SourceNode(1, 0, "a.js", "function runTest() {\n"),
    1.34 +    // A bunch of js lines map to the same original source line.
    1.35 +    new SourceNode(2, 0, "a.js", "  debugger;\n"),
    1.36 +    new SourceNode(2, 0, "a.js", "  var sum = 0;\n"),
    1.37 +    new SourceNode(2, 0, "a.js", "  for (var i = 0; i < 5; i++) {\n"),
    1.38 +    new SourceNode(2, 0, "a.js", "    sum += i;\n"),
    1.39 +    new SourceNode(2, 0, "a.js", "  }\n"),
    1.40 +    // And now we have a new line in the original source that we should stop at.
    1.41 +    new SourceNode(3, 0, "a.js", "  sum;\n"),
    1.42 +    new SourceNode(3, 0, "a.js", "}\n"),
    1.43 +  ])).toStringWithSourceMap({
    1.44 +    file: "abc.js",
    1.45 +    sourceRoot: "http://example.com/"
    1.46 +  });
    1.47 +
    1.48 +  code += "//# sourceMappingURL=data:text/json," + map.toString();
    1.49 +
    1.50 +  Components.utils.evalInSandbox(code, gDebuggee, "1.8",
    1.51 +                                 "http://example.com/abc.js", 1);
    1.52 +
    1.53 +  run_code();
    1.54 +}
    1.55 +
    1.56 +function run_code() {
    1.57 +  gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.58 +    do_check_eq(aPacket.why.type, "debuggerStatement");
    1.59 +    step_in();
    1.60 +  });
    1.61 +  gDebuggee.runTest();
    1.62 +}
    1.63 +
    1.64 +function step_in() {
    1.65 +  gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.66 +    do_check_eq(aPacket.why.type, "resumeLimit");
    1.67 +    let { frame: { environment, where: { url, line } } } = aPacket;
    1.68 +    // Stepping should have moved us to the next source mapped line.
    1.69 +    do_check_eq(url, "http://example.com/a.js");
    1.70 +    do_check_eq(line, 3);
    1.71 +    // Which should have skipped over the for loop in the generated js and sum
    1.72 +    // should be calculated.
    1.73 +    do_check_eq(environment.bindings.variables.sum.value, 10);
    1.74 +    finishClient(gClient);
    1.75 +  });
    1.76 +  gThreadClient.stepIn();
    1.77 +}
    1.78 +

mercurial