1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_source-maps-03.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Test that we can debug minified javascript with source maps. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_minified.html"; 1.12 +const JS_URL = EXAMPLE_URL + "code_math.js"; 1.13 + 1.14 +let gDebuggee, gPanel, gDebugger; 1.15 +let gEditor, gSources, gFrames; 1.16 + 1.17 +function test() { 1.18 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.19 + gDebuggee = aDebuggee; 1.20 + gPanel = aPanel; 1.21 + gDebugger = gPanel.panelWin; 1.22 + gEditor = gDebugger.DebuggerView.editor; 1.23 + gSources = gDebugger.DebuggerView.Sources; 1.24 + gFrames = gDebugger.DebuggerView.StackFrames; 1.25 + 1.26 + waitForSourceShown(gPanel, JS_URL) 1.27 + .then(checkInitialSource) 1.28 + .then(testSetBreakpoint) 1.29 + .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) 1.30 + .then(null, aError => { 1.31 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.32 + }); 1.33 + }); 1.34 +} 1.35 + 1.36 +function checkInitialSource() { 1.37 + isnot(gSources.selectedValue.indexOf(".js"), -1, 1.38 + "The debugger should not show the minified js file."); 1.39 + is(gSources.selectedValue.indexOf(".min.js"), -1, 1.40 + "The debugger should show the original js file."); 1.41 + is(gEditor.getText().split("\n").length, 46, 1.42 + "The debugger's editor should have the original source displayed, " + 1.43 + "not the whitespace stripped minified version."); 1.44 +} 1.45 + 1.46 +function testSetBreakpoint() { 1.47 + let deferred = promise.defer(); 1.48 + 1.49 + gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 30, column: 21 }, aResponse => { 1.50 + ok(!aResponse.error, 1.51 + "Should be able to set a breakpoint in a js file."); 1.52 + ok(!aResponse.actualLocation, 1.53 + "Should be able to set a breakpoint on line 30 and column 10."); 1.54 + 1.55 + gDebugger.gClient.addOneTimeListener("resumed", () => { 1.56 + waitForCaretAndScopes(gPanel, 30).then(() => { 1.57 + // Make sure that we have the right stack frames. 1.58 + is(gFrames.itemCount, 9, 1.59 + "Should have nine frames."); 1.60 + is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".min.js"), -1, 1.61 + "First frame should not be a minified JS frame."); 1.62 + isnot(gFrames.getItemAtIndex(0).attachment.url.indexOf(".js"), -1, 1.63 + "First frame should be a JS frame."); 1.64 + 1.65 + deferred.resolve(); 1.66 + }); 1.67 + 1.68 + // This will cause the breakpoint to be hit, and put us back in the 1.69 + // paused state. 1.70 + gDebuggee.arithmetic(); 1.71 + }); 1.72 + }); 1.73 + 1.74 + return deferred.promise; 1.75 +} 1.76 + 1.77 +registerCleanupFunction(function() { 1.78 + gDebuggee = null; 1.79 + gPanel = null; 1.80 + gDebugger = null; 1.81 + gEditor = null; 1.82 + gSources = null; 1.83 + gFrames = null; 1.84 +});