Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Make sure that prettifying JS sources with type errors works as expected. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TAB_URL = EXAMPLE_URL + "doc_included-script.html"; |
michael@0 | 9 | const JS_URL = EXAMPLE_URL + "code_location-changes.js"; |
michael@0 | 10 | |
michael@0 | 11 | let gTab, gDebuggee, gPanel, gDebugger, gClient; |
michael@0 | 12 | let gEditor, gSources, gControllerSources, gPrettyPrinted; |
michael@0 | 13 | |
michael@0 | 14 | function test() { |
michael@0 | 15 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 16 | gTab = aTab; |
michael@0 | 17 | gDebuggee = aDebuggee; |
michael@0 | 18 | gPanel = aPanel; |
michael@0 | 19 | gDebugger = gPanel.panelWin; |
michael@0 | 20 | gClient = gDebugger.gClient; |
michael@0 | 21 | gEditor = gDebugger.DebuggerView.editor; |
michael@0 | 22 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 23 | gControllerSources = gDebugger.DebuggerController.SourceScripts; |
michael@0 | 24 | |
michael@0 | 25 | // We can't feed javascript files with syntax errors to the debugger, |
michael@0 | 26 | // because they will never run, thus sometimes getting gc'd before the |
michael@0 | 27 | // debugger is opened, or even before the target finishes navigating. |
michael@0 | 28 | // Make the client lie about being able to parse perfectly fine code. |
michael@0 | 29 | gClient.request = (function (aOriginalRequestMethod) { |
michael@0 | 30 | return function (aPacket, aCallback) { |
michael@0 | 31 | if (aPacket.type == "prettyPrint") { |
michael@0 | 32 | gPrettyPrinted = true; |
michael@0 | 33 | return executeSoon(() => aCallback({ error: "prettyPrintError" })); |
michael@0 | 34 | } |
michael@0 | 35 | return aOriginalRequestMethod(aPacket, aCallback); |
michael@0 | 36 | }; |
michael@0 | 37 | }(gClient.request)); |
michael@0 | 38 | |
michael@0 | 39 | Task.spawn(function() { |
michael@0 | 40 | yield waitForSourceShown(gPanel, JS_URL); |
michael@0 | 41 | |
michael@0 | 42 | // From this point onward, the source editor's text should never change. |
michael@0 | 43 | gEditor.once("change", () => { |
michael@0 | 44 | ok(false, "The source editor text shouldn't have changed."); |
michael@0 | 45 | }); |
michael@0 | 46 | |
michael@0 | 47 | is(gSources.selectedValue, JS_URL, |
michael@0 | 48 | "The correct source is currently selected."); |
michael@0 | 49 | ok(gEditor.getText().contains("myFunction"), |
michael@0 | 50 | "The source shouldn't be pretty printed yet."); |
michael@0 | 51 | |
michael@0 | 52 | clickPrettyPrintButton(); |
michael@0 | 53 | |
michael@0 | 54 | let { source } = gSources.selectedItem.attachment; |
michael@0 | 55 | try { |
michael@0 | 56 | yield gControllerSources.togglePrettyPrint(source); |
michael@0 | 57 | ok(false, "The promise for a prettified source should be rejected!"); |
michael@0 | 58 | } catch ([source, error]) { |
michael@0 | 59 | ok(error.contains("prettyPrintError"), |
michael@0 | 60 | "The promise was correctly rejected with a meaningful message."); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | let [source, text] = yield gControllerSources.getText(source); |
michael@0 | 64 | is(gSources.selectedValue, JS_URL, |
michael@0 | 65 | "The correct source is still selected."); |
michael@0 | 66 | ok(gEditor.getText().contains("myFunction"), |
michael@0 | 67 | "The displayed source hasn't changed."); |
michael@0 | 68 | ok(text.contains("myFunction"), |
michael@0 | 69 | "The cached source text wasn't altered in any way."); |
michael@0 | 70 | |
michael@0 | 71 | is(gPrettyPrinted, true, |
michael@0 | 72 | "The hijacked pretty print method was executed."); |
michael@0 | 73 | |
michael@0 | 74 | yield closeDebuggerAndFinish(gPanel); |
michael@0 | 75 | }); |
michael@0 | 76 | }); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function clickPrettyPrintButton() { |
michael@0 | 80 | gDebugger.document.getElementById("pretty-print").click(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | registerCleanupFunction(function() { |
michael@0 | 84 | gTab = null; |
michael@0 | 85 | gDebuggee = null; |
michael@0 | 86 | gPanel = null; |
michael@0 | 87 | gDebugger = null; |
michael@0 | 88 | gClient = null; |
michael@0 | 89 | gEditor = null; |
michael@0 | 90 | gSources = null; |
michael@0 | 91 | gControllerSources = null; |
michael@0 | 92 | gPrettyPrinted = null; |
michael@0 | 93 | }); |