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: * Make sure that prettifying JS sources with type errors works as expected. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_included-script.html"; michael@0: const JS_URL = EXAMPLE_URL + "code_location-changes.js"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger, gClient; michael@0: let gEditor, gSources, gControllerSources, gPrettyPrinted; 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: gClient = gDebugger.gClient; michael@0: gEditor = gDebugger.DebuggerView.editor; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: gControllerSources = gDebugger.DebuggerController.SourceScripts; michael@0: michael@0: // We can't feed javascript files with syntax errors to the debugger, michael@0: // because they will never run, thus sometimes getting gc'd before the michael@0: // debugger is opened, or even before the target finishes navigating. michael@0: // Make the client lie about being able to parse perfectly fine code. michael@0: gClient.request = (function (aOriginalRequestMethod) { michael@0: return function (aPacket, aCallback) { michael@0: if (aPacket.type == "prettyPrint") { michael@0: gPrettyPrinted = true; michael@0: return executeSoon(() => aCallback({ error: "prettyPrintError" })); michael@0: } michael@0: return aOriginalRequestMethod(aPacket, aCallback); michael@0: }; michael@0: }(gClient.request)); michael@0: michael@0: Task.spawn(function() { michael@0: yield waitForSourceShown(gPanel, JS_URL); michael@0: michael@0: // From this point onward, the source editor's text should never change. michael@0: gEditor.once("change", () => { michael@0: ok(false, "The source editor text shouldn't have changed."); michael@0: }); michael@0: michael@0: is(gSources.selectedValue, JS_URL, michael@0: "The correct source is currently selected."); michael@0: ok(gEditor.getText().contains("myFunction"), michael@0: "The source shouldn't be pretty printed yet."); michael@0: michael@0: clickPrettyPrintButton(); michael@0: michael@0: let { source } = gSources.selectedItem.attachment; michael@0: try { michael@0: yield gControllerSources.togglePrettyPrint(source); michael@0: ok(false, "The promise for a prettified source should be rejected!"); michael@0: } catch ([source, error]) { michael@0: ok(error.contains("prettyPrintError"), michael@0: "The promise was correctly rejected with a meaningful message."); michael@0: } michael@0: michael@0: let [source, text] = yield gControllerSources.getText(source); michael@0: is(gSources.selectedValue, JS_URL, michael@0: "The correct source is still selected."); michael@0: ok(gEditor.getText().contains("myFunction"), michael@0: "The displayed source hasn't changed."); michael@0: ok(text.contains("myFunction"), michael@0: "The cached source text wasn't altered in any way."); michael@0: michael@0: is(gPrettyPrinted, true, michael@0: "The hijacked pretty print method was executed."); michael@0: michael@0: yield closeDebuggerAndFinish(gPanel); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function clickPrettyPrintButton() { michael@0: gDebugger.document.getElementById("pretty-print").click(); 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: gClient = null; michael@0: gEditor = null; michael@0: gSources = null; michael@0: gControllerSources = null; michael@0: gPrettyPrinted = null; michael@0: });