browser/devtools/debugger/test/browser_dbg_source-maps-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_source-maps-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,165 @@
     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 set breakpoints and step through source mapped
     1.9 + * coffee script.
    1.10 + */
    1.11 +
    1.12 +const TAB_URL = EXAMPLE_URL + "doc_binary_search.html";
    1.13 +const COFFEE_URL = EXAMPLE_URL + "code_binary_search.coffee";
    1.14 +
    1.15 +let gTab, gDebuggee, gPanel, gDebugger;
    1.16 +let gEditor, gSources;
    1.17 +
    1.18 +function test() {
    1.19 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.20 +    gTab = aTab;
    1.21 +    gDebuggee = aDebuggee;
    1.22 +    gPanel = aPanel;
    1.23 +    gDebugger = gPanel.panelWin;
    1.24 +    gEditor = gDebugger.DebuggerView.editor;
    1.25 +    gSources = gDebugger.DebuggerView.Sources;
    1.26 +
    1.27 +    checkSourceMapsEnabled();
    1.28 +
    1.29 +    waitForSourceShown(gPanel, ".coffee")
    1.30 +      .then(checkInitialSource)
    1.31 +      .then(testSetBreakpoint)
    1.32 +      .then(testSetBreakpointBlankLine)
    1.33 +      .then(testHitBreakpoint)
    1.34 +      .then(testStepping)
    1.35 +      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    1.36 +      .then(null, aError => {
    1.37 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.38 +      });
    1.39 +  });
    1.40 +}
    1.41 +
    1.42 +function checkSourceMapsEnabled() {
    1.43 +  is(Services.prefs.getBoolPref("devtools.debugger.source-maps-enabled"), true,
    1.44 +    "The source maps functionality should be enabled by default.");
    1.45 +  is(gDebugger.Prefs.sourceMapsEnabled, true,
    1.46 +    "The source maps pref should be true from startup.");
    1.47 +  is(gDebugger.DebuggerView.Options._showOriginalSourceItem.getAttribute("checked"), "true",
    1.48 +    "Source maps should be enabled from startup.")
    1.49 +}
    1.50 +
    1.51 +function checkInitialSource() {
    1.52 +  isnot(gSources.selectedValue.indexOf(".coffee"), -1,
    1.53 +    "The debugger should show the source mapped coffee source file.");
    1.54 +  is(gSources.selectedValue.indexOf(".js"), -1,
    1.55 +    "The debugger should not show the generated js source file.");
    1.56 +  is(gEditor.getText().indexOf("isnt"), 218,
    1.57 +    "The debugger's editor should have the coffee source source displayed.");
    1.58 +  is(gEditor.getText().indexOf("function"), -1,
    1.59 +    "The debugger's editor should not have the JS source displayed.");
    1.60 +}
    1.61 +
    1.62 +function testSetBreakpoint() {
    1.63 +  let deferred = promise.defer();
    1.64 +
    1.65 +  gDebugger.gThreadClient.interrupt(aResponse => {
    1.66 +    gDebugger.gThreadClient.setBreakpoint({ url: COFFEE_URL, line: 5 }, aResponse => {
    1.67 +      ok(!aResponse.error,
    1.68 +        "Should be able to set a breakpoint in a coffee source file.");
    1.69 +      ok(!aResponse.actualLocation,
    1.70 +        "Should be able to set a breakpoint on line 5.");
    1.71 +
    1.72 +      deferred.resolve();
    1.73 +    });
    1.74 +  });
    1.75 +
    1.76 +  return deferred.promise;
    1.77 +}
    1.78 +
    1.79 +function testSetBreakpointBlankLine() {
    1.80 +  let deferred = promise.defer();
    1.81 +
    1.82 +  gDebugger.gThreadClient.setBreakpoint({ url: COFFEE_URL, line: 3 }, aResponse => {
    1.83 +    ok(!aResponse.error,
    1.84 +      "Should be able to set a breakpoint in a coffee source file on a blank line.");
    1.85 +    ok(aResponse.actualLocation,
    1.86 +      "Because 3 is empty, we should have an actualLocation.");
    1.87 +    is(aResponse.actualLocation.url, COFFEE_URL,
    1.88 +      "actualLocation.url should be source mapped to the coffee file.");
    1.89 +    is(aResponse.actualLocation.line, 2,
    1.90 +      "actualLocation.line should be source mapped back to 2.");
    1.91 +
    1.92 +    deferred.resolve();
    1.93 +  });
    1.94 +
    1.95 +  return deferred.promise;
    1.96 +}
    1.97 +
    1.98 +function testHitBreakpoint() {
    1.99 +  let deferred = promise.defer();
   1.100 +
   1.101 +  gDebugger.gThreadClient.resume(aResponse => {
   1.102 +    ok(!aResponse.error, "Shouldn't get an error resuming.");
   1.103 +    is(aResponse.type, "resumed", "Type should be 'resumed'.");
   1.104 +
   1.105 +    gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => {
   1.106 +      is(aPacket.type, "paused",
   1.107 +        "We should now be paused again.");
   1.108 +      is(aPacket.why.type, "breakpoint",
   1.109 +        "and the reason we should be paused is because we hit a breakpoint.");
   1.110 +
   1.111 +      // Check that we stopped at the right place, by making sure that the
   1.112 +      // environment is in the state that we expect.
   1.113 +      is(aPacket.frame.environment.bindings.variables.start.value, 0,
   1.114 +         "'start' is 0.");
   1.115 +      is(aPacket.frame.environment.bindings.variables.stop.value.type, "undefined",
   1.116 +         "'stop' hasn't been assigned to yet.");
   1.117 +      is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined",
   1.118 +         "'pivot' hasn't been assigned to yet.");
   1.119 +
   1.120 +      waitForCaretUpdated(gPanel, 5).then(deferred.resolve);
   1.121 +    });
   1.122 +
   1.123 +    // This will cause the breakpoint to be hit, and put us back in the
   1.124 +    // paused state.
   1.125 +    gDebuggee.binary_search([0, 2, 3, 5, 7, 10], 5);
   1.126 +  });
   1.127 +
   1.128 +  return deferred.promise;
   1.129 +}
   1.130 +
   1.131 +function testStepping() {
   1.132 +  let deferred = promise.defer();
   1.133 +
   1.134 +  gDebugger.gThreadClient.stepIn(aResponse => {
   1.135 +    ok(!aResponse.error, "Shouldn't get an error resuming.");
   1.136 +    is(aResponse.type, "resumed", "Type should be 'resumed'.");
   1.137 +
   1.138 +    // After stepping, we will pause again, so listen for that.
   1.139 +    gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => {
   1.140 +      is(aPacket.type, "paused",
   1.141 +        "We should now be paused again.");
   1.142 +      is(aPacket.why.type, "resumeLimit",
   1.143 +        "and the reason we should be paused is because we hit the resume limit.");
   1.144 +
   1.145 +      // Check that we stopped at the right place, by making sure that the
   1.146 +      // environment is in the state that we expect.
   1.147 +      is(aPacket.frame.environment.bindings.variables.start.value, 0,
   1.148 +         "'start' is 0.");
   1.149 +      is(aPacket.frame.environment.bindings.variables.stop.value, 5,
   1.150 +         "'stop' hasn't been assigned to yet.");
   1.151 +      is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined",
   1.152 +         "'pivot' hasn't been assigned to yet.");
   1.153 +
   1.154 +      waitForCaretUpdated(gPanel, 6).then(deferred.resolve);
   1.155 +    });
   1.156 +  });
   1.157 +
   1.158 +  return deferred.promise;
   1.159 +}
   1.160 +
   1.161 +registerCleanupFunction(function() {
   1.162 +  gTab = null;
   1.163 +  gDebuggee = null;
   1.164 +  gPanel = null;
   1.165 +  gDebugger = null;
   1.166 +  gEditor = null;
   1.167 +  gSources = null;
   1.168 +});

mercurial