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 toggle between the original and generated sources. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_binary_search.html"; michael@0: const JS_URL = EXAMPLE_URL + "code_binary_search.js"; michael@0: michael@0: let gDebuggee, gPanel, gDebugger, gEditor; michael@0: let gSources, gFrames, gPrefs, gOptions; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 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: gFrames = gDebugger.DebuggerView.StackFrames; michael@0: gPrefs = gDebugger.Prefs; michael@0: gOptions = gDebugger.DebuggerView.Options; michael@0: michael@0: waitForSourceShown(gPanel, ".coffee") michael@0: .then(testToggleGeneratedSource) michael@0: .then(testSetBreakpoint) michael@0: .then(testToggleOnPause) michael@0: .then(testResume) michael@0: .then(() => closeDebuggerAndFinish(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 testToggleGeneratedSource() { michael@0: let finished = waitForSourceShown(gPanel, ".js").then(() => { michael@0: is(gPrefs.sourceMapsEnabled, false, michael@0: "The source maps pref should have been set to false."); michael@0: is(gOptions._showOriginalSourceItem.getAttribute("checked"), "false", michael@0: "Source maps should now be disabled.") michael@0: michael@0: is(gSources.selectedValue.indexOf(".coffee"), -1, michael@0: "The debugger should not show the source mapped coffee source file."); michael@0: isnot(gSources.selectedValue.indexOf(".js"), -1, michael@0: "The debugger should show the generated js source file."); michael@0: michael@0: is(gEditor.getText().indexOf("isnt"), -1, michael@0: "The debugger's editor should not have the coffee source source displayed."); michael@0: is(gEditor.getText().indexOf("function"), 36, michael@0: "The debugger's editor should have the JS source displayed."); michael@0: }); michael@0: michael@0: gOptions._showOriginalSourceItem.setAttribute("checked", "false"); michael@0: gOptions._toggleShowOriginalSource(); michael@0: gOptions._onPopupHidden(); michael@0: michael@0: return finished; michael@0: } michael@0: michael@0: function testSetBreakpoint() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 7 }, aResponse => { michael@0: ok(!aResponse.error, michael@0: "Should be able to set a breakpoint in a js file."); michael@0: michael@0: gDebugger.gClient.addOneTimeListener("resumed", () => { michael@0: waitForCaretAndScopes(gPanel, 7).then(() => { michael@0: // Make sure that we have JavaScript stack frames. michael@0: is(gFrames.itemCount, 1, michael@0: "Should have only one frame."); michael@0: is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".coffee"), -1, michael@0: "First frame should not be a coffee source frame."); michael@0: isnot(gFrames.getItemAtIndex(0).attachment.url.indexOf(".js"), -1, michael@0: "First frame should be a JS frame."); michael@0: michael@0: 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: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testToggleOnPause() { michael@0: let finished = waitForSourceAndCaretAndScopes(gPanel, ".coffee", 5).then(() => { michael@0: is(gPrefs.sourceMapsEnabled, true, michael@0: "The source maps pref should have been set to true."); michael@0: is(gOptions._showOriginalSourceItem.getAttribute("checked"), "true", michael@0: "Source maps should now be enabled.") michael@0: 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: 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: // Make sure that we have coffee source stack frames. michael@0: is(gFrames.itemCount, 1, michael@0: "Should have only one frame."); michael@0: is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".js"), -1, michael@0: "First frame should not be a JS frame."); michael@0: isnot(gFrames.getItemAtIndex(0).attachment.url.indexOf(".coffee"), -1, michael@0: "First frame should be a coffee source frame."); michael@0: }); michael@0: michael@0: gOptions._showOriginalSourceItem.setAttribute("checked", "true"); michael@0: gOptions._toggleShowOriginalSource(); michael@0: gOptions._onPopupHidden(); michael@0: michael@0: return finished; michael@0: } michael@0: michael@0: function testResume() { 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: deferred.resolve(); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gEditor = null; michael@0: gSources = null; michael@0: gFrames = null; michael@0: gPrefs = null; michael@0: gOptions = null; michael@0: });