michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Test that we can set breakpoints and step through source mapped michael@0: * coffee script. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_binary_search.html"; michael@0: const COFFEE_URL = EXAMPLE_URL + "code_binary_search.coffee"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gSources; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gEditor = gDebugger.DebuggerView.editor; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: michael@0: checkSourceMapsEnabled(); michael@0: michael@0: waitForSourceShown(gPanel, ".coffee") michael@0: .then(checkInitialSource) michael@0: .then(testSetBreakpoint) michael@0: .then(testSetBreakpointBlankLine) michael@0: .then(testHitBreakpoint) michael@0: .then(testStepping) michael@0: .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function checkSourceMapsEnabled() { michael@0: is(Services.prefs.getBoolPref("devtools.debugger.source-maps-enabled"), true, michael@0: "The source maps functionality should be enabled by default."); michael@0: is(gDebugger.Prefs.sourceMapsEnabled, true, michael@0: "The source maps pref should be true from startup."); michael@0: is(gDebugger.DebuggerView.Options._showOriginalSourceItem.getAttribute("checked"), "true", michael@0: "Source maps should be enabled from startup.") michael@0: } michael@0: michael@0: function checkInitialSource() { michael@0: isnot(gSources.selectedValue.indexOf(".coffee"), -1, michael@0: "The debugger should show the source mapped coffee source file."); michael@0: is(gSources.selectedValue.indexOf(".js"), -1, michael@0: "The debugger should not show the generated js source file."); michael@0: is(gEditor.getText().indexOf("isnt"), 218, michael@0: "The debugger's editor should have the coffee source source displayed."); michael@0: is(gEditor.getText().indexOf("function"), -1, michael@0: "The debugger's editor should not have the JS source displayed."); michael@0: } michael@0: michael@0: function testSetBreakpoint() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.interrupt(aResponse => { michael@0: gDebugger.gThreadClient.setBreakpoint({ url: COFFEE_URL, line: 5 }, aResponse => { michael@0: ok(!aResponse.error, michael@0: "Should be able to set a breakpoint in a coffee source file."); michael@0: ok(!aResponse.actualLocation, michael@0: "Should be able to set a breakpoint on line 5."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testSetBreakpointBlankLine() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.setBreakpoint({ url: COFFEE_URL, line: 3 }, aResponse => { michael@0: ok(!aResponse.error, michael@0: "Should be able to set a breakpoint in a coffee source file on a blank line."); michael@0: ok(aResponse.actualLocation, michael@0: "Because 3 is empty, we should have an actualLocation."); michael@0: is(aResponse.actualLocation.url, COFFEE_URL, michael@0: "actualLocation.url should be source mapped to the coffee file."); michael@0: is(aResponse.actualLocation.line, 2, michael@0: "actualLocation.line should be source mapped back to 2."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testHitBreakpoint() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.resume(aResponse => { michael@0: ok(!aResponse.error, "Shouldn't get an error resuming."); michael@0: is(aResponse.type, "resumed", "Type should be 'resumed'."); michael@0: michael@0: gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { michael@0: is(aPacket.type, "paused", michael@0: "We should now be paused again."); michael@0: is(aPacket.why.type, "breakpoint", michael@0: "and the reason we should be paused is because we hit a breakpoint."); michael@0: michael@0: // Check that we stopped at the right place, by making sure that the michael@0: // environment is in the state that we expect. michael@0: is(aPacket.frame.environment.bindings.variables.start.value, 0, michael@0: "'start' is 0."); michael@0: is(aPacket.frame.environment.bindings.variables.stop.value.type, "undefined", michael@0: "'stop' hasn't been assigned to yet."); michael@0: is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined", michael@0: "'pivot' hasn't been assigned to yet."); michael@0: michael@0: waitForCaretUpdated(gPanel, 5).then(deferred.resolve); michael@0: }); michael@0: michael@0: // This will cause the breakpoint to be hit, and put us back in the michael@0: // paused state. michael@0: gDebuggee.binary_search([0, 2, 3, 5, 7, 10], 5); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testStepping() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.stepIn(aResponse => { michael@0: ok(!aResponse.error, "Shouldn't get an error resuming."); michael@0: is(aResponse.type, "resumed", "Type should be 'resumed'."); michael@0: michael@0: // After stepping, we will pause again, so listen for that. michael@0: gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { michael@0: is(aPacket.type, "paused", michael@0: "We should now be paused again."); michael@0: is(aPacket.why.type, "resumeLimit", michael@0: "and the reason we should be paused is because we hit the resume limit."); michael@0: michael@0: // Check that we stopped at the right place, by making sure that the michael@0: // environment is in the state that we expect. michael@0: is(aPacket.frame.environment.bindings.variables.start.value, 0, michael@0: "'start' is 0."); michael@0: is(aPacket.frame.environment.bindings.variables.stop.value, 5, michael@0: "'stop' hasn't been assigned to yet."); michael@0: is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined", michael@0: "'pivot' hasn't been assigned to yet."); michael@0: michael@0: waitForCaretUpdated(gPanel, 6).then(deferred.resolve); michael@0: }); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gEditor = null; michael@0: gSources = null; michael@0: });