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 debug minified javascript with source maps. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_minified.html"; michael@0: const JS_URL = EXAMPLE_URL + "code_math.js"; michael@0: michael@0: let gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gSources, gFrames; 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: michael@0: waitForSourceShown(gPanel, JS_URL) michael@0: .then(checkInitialSource) michael@0: .then(testSetBreakpoint) 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 checkInitialSource() { michael@0: isnot(gSources.selectedValue.indexOf(".js"), -1, michael@0: "The debugger should not show the minified js file."); michael@0: is(gSources.selectedValue.indexOf(".min.js"), -1, michael@0: "The debugger should show the original js file."); michael@0: is(gEditor.getText().split("\n").length, 46, michael@0: "The debugger's editor should have the original source displayed, " + michael@0: "not the whitespace stripped minified version."); 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: 30, column: 21 }, aResponse => { michael@0: ok(!aResponse.error, michael@0: "Should be able to set a breakpoint in a js file."); michael@0: ok(!aResponse.actualLocation, michael@0: "Should be able to set a breakpoint on line 30 and column 10."); michael@0: michael@0: gDebugger.gClient.addOneTimeListener("resumed", () => { michael@0: waitForCaretAndScopes(gPanel, 30).then(() => { michael@0: // Make sure that we have the right stack frames. michael@0: is(gFrames.itemCount, 9, michael@0: "Should have nine frames."); michael@0: is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".min.js"), -1, michael@0: "First frame should not be a minified JS 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.arithmetic(); michael@0: }); 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: });