1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_source-maps-02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,146 @@ 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 toggle between the original and generated sources. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_binary_search.html"; 1.12 +const JS_URL = EXAMPLE_URL + "code_binary_search.js"; 1.13 + 1.14 +let gDebuggee, gPanel, gDebugger, gEditor; 1.15 +let gSources, gFrames, gPrefs, gOptions; 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 + gPrefs = gDebugger.Prefs; 1.26 + gOptions = gDebugger.DebuggerView.Options; 1.27 + 1.28 + waitForSourceShown(gPanel, ".coffee") 1.29 + .then(testToggleGeneratedSource) 1.30 + .then(testSetBreakpoint) 1.31 + .then(testToggleOnPause) 1.32 + .then(testResume) 1.33 + .then(() => closeDebuggerAndFinish(gPanel)) 1.34 + .then(null, aError => { 1.35 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.36 + }); 1.37 + }); 1.38 +} 1.39 + 1.40 +function testToggleGeneratedSource() { 1.41 + let finished = waitForSourceShown(gPanel, ".js").then(() => { 1.42 + is(gPrefs.sourceMapsEnabled, false, 1.43 + "The source maps pref should have been set to false."); 1.44 + is(gOptions._showOriginalSourceItem.getAttribute("checked"), "false", 1.45 + "Source maps should now be disabled.") 1.46 + 1.47 + is(gSources.selectedValue.indexOf(".coffee"), -1, 1.48 + "The debugger should not show the source mapped coffee source file."); 1.49 + isnot(gSources.selectedValue.indexOf(".js"), -1, 1.50 + "The debugger should show the generated js source file."); 1.51 + 1.52 + is(gEditor.getText().indexOf("isnt"), -1, 1.53 + "The debugger's editor should not have the coffee source source displayed."); 1.54 + is(gEditor.getText().indexOf("function"), 36, 1.55 + "The debugger's editor should have the JS source displayed."); 1.56 + }); 1.57 + 1.58 + gOptions._showOriginalSourceItem.setAttribute("checked", "false"); 1.59 + gOptions._toggleShowOriginalSource(); 1.60 + gOptions._onPopupHidden(); 1.61 + 1.62 + return finished; 1.63 +} 1.64 + 1.65 +function testSetBreakpoint() { 1.66 + let deferred = promise.defer(); 1.67 + 1.68 + gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 7 }, aResponse => { 1.69 + ok(!aResponse.error, 1.70 + "Should be able to set a breakpoint in a js file."); 1.71 + 1.72 + gDebugger.gClient.addOneTimeListener("resumed", () => { 1.73 + waitForCaretAndScopes(gPanel, 7).then(() => { 1.74 + // Make sure that we have JavaScript stack frames. 1.75 + is(gFrames.itemCount, 1, 1.76 + "Should have only one frame."); 1.77 + is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".coffee"), -1, 1.78 + "First frame should not be a coffee source frame."); 1.79 + isnot(gFrames.getItemAtIndex(0).attachment.url.indexOf(".js"), -1, 1.80 + "First frame should be a JS frame."); 1.81 + 1.82 + deferred.resolve(); 1.83 + }); 1.84 + 1.85 + // This will cause the breakpoint to be hit, and put us back in the 1.86 + // paused state. 1.87 + gDebuggee.binary_search([0, 2, 3, 5, 7, 10], 5); 1.88 + }); 1.89 + }); 1.90 + 1.91 + return deferred.promise; 1.92 +} 1.93 + 1.94 +function testToggleOnPause() { 1.95 + let finished = waitForSourceAndCaretAndScopes(gPanel, ".coffee", 5).then(() => { 1.96 + is(gPrefs.sourceMapsEnabled, true, 1.97 + "The source maps pref should have been set to true."); 1.98 + is(gOptions._showOriginalSourceItem.getAttribute("checked"), "true", 1.99 + "Source maps should now be enabled.") 1.100 + 1.101 + isnot(gSources.selectedValue.indexOf(".coffee"), -1, 1.102 + "The debugger should show the source mapped coffee source file."); 1.103 + is(gSources.selectedValue.indexOf(".js"), -1, 1.104 + "The debugger should not show the generated js source file."); 1.105 + 1.106 + is(gEditor.getText().indexOf("isnt"), 218, 1.107 + "The debugger's editor should have the coffee source source displayed."); 1.108 + is(gEditor.getText().indexOf("function"), -1, 1.109 + "The debugger's editor should not have the JS source displayed."); 1.110 + 1.111 + // Make sure that we have coffee source stack frames. 1.112 + is(gFrames.itemCount, 1, 1.113 + "Should have only one frame."); 1.114 + is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".js"), -1, 1.115 + "First frame should not be a JS frame."); 1.116 + isnot(gFrames.getItemAtIndex(0).attachment.url.indexOf(".coffee"), -1, 1.117 + "First frame should be a coffee source frame."); 1.118 + }); 1.119 + 1.120 + gOptions._showOriginalSourceItem.setAttribute("checked", "true"); 1.121 + gOptions._toggleShowOriginalSource(); 1.122 + gOptions._onPopupHidden(); 1.123 + 1.124 + return finished; 1.125 +} 1.126 + 1.127 +function testResume() { 1.128 + let deferred = promise.defer(); 1.129 + 1.130 + gDebugger.gThreadClient.resume(aResponse => { 1.131 + ok(!aResponse.error, "Shouldn't get an error resuming."); 1.132 + is(aResponse.type, "resumed", "Type should be 'resumed'."); 1.133 + 1.134 + deferred.resolve(); 1.135 + }); 1.136 + 1.137 + return deferred.promise; 1.138 +} 1.139 + 1.140 +registerCleanupFunction(function() { 1.141 + gDebuggee = null; 1.142 + gPanel = null; 1.143 + gDebugger = null; 1.144 + gEditor = null; 1.145 + gSources = null; 1.146 + gFrames = null; 1.147 + gPrefs = null; 1.148 + gOptions = null; 1.149 +});