1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_scripts-switching-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,197 @@ 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 + * Make sure that switching the displayed source in the UI works as advertised. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; 1.12 + 1.13 +let gTab, gDebuggee, gPanel, gDebugger; 1.14 +let gEditor, gSources; 1.15 + 1.16 +function test() { 1.17 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.18 + gTab = aTab; 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 + 1.25 + ok(gDebugger.document.title.endsWith(EXAMPLE_URL + gLabel1), 1.26 + "Title with first source is correct."); 1.27 + 1.28 + waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) 1.29 + .then(testSourcesDisplay) 1.30 + .then(testSwitchPaused1) 1.31 + .then(testSwitchPaused2) 1.32 + .then(testSwitchRunning) 1.33 + .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) 1.34 + .then(null, aError => { 1.35 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.36 + }); 1.37 + 1.38 + gDebuggee.firstCall(); 1.39 + }); 1.40 +} 1.41 + 1.42 +let gLabel1 = "code_script-switching-01.js"; 1.43 +let gLabel2 = "code_script-switching-02.js"; 1.44 + 1.45 +function testSourcesDisplay() { 1.46 + let deferred = promise.defer(); 1.47 + 1.48 + is(gSources.itemCount, 2, 1.49 + "Found the expected number of sources."); 1.50 + 1.51 + is(gSources.items[0].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"), 1.52 + EXAMPLE_URL + "code_script-switching-01.js", 1.53 + "The correct tooltip text is displayed for the first source."); 1.54 + is(gSources.items[1].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"), 1.55 + EXAMPLE_URL + "code_script-switching-02.js", 1.56 + "The correct tooltip text is displayed for the second source."); 1.57 + 1.58 + ok(gSources.containsValue(EXAMPLE_URL + gLabel1), 1.59 + "First source url is incorrect."); 1.60 + ok(gSources.containsValue(EXAMPLE_URL + gLabel2), 1.61 + "Second source url is incorrect."); 1.62 + 1.63 + ok(gSources.getItemForAttachment(e => e.label == gLabel1), 1.64 + "First source label is incorrect."); 1.65 + ok(gSources.getItemForAttachment(e => e.label == gLabel2), 1.66 + "Second source label is incorrect."); 1.67 + 1.68 + ok(gSources.selectedItem, 1.69 + "There should be a selected item in the sources pane."); 1.70 + is(gSources.selectedValue, EXAMPLE_URL + gLabel2, 1.71 + "The selected value is the sources pane is incorrect."); 1.72 + 1.73 + is(gEditor.getText().search(/firstCall/), -1, 1.74 + "The first source is not displayed."); 1.75 + is(gEditor.getText().search(/debugger/), 172, 1.76 + "The second source is displayed."); 1.77 + 1.78 + ok(gDebugger.document.title.endsWith(EXAMPLE_URL + gLabel2), 1.79 + "Title with second source is correct."); 1.80 + 1.81 + ok(isCaretPos(gPanel, 1), 1.82 + "Editor caret location is correct."); 1.83 + 1.84 + // The editor's debug location takes a tick to update. 1.85 + executeSoon(() => { 1.86 + is(gEditor.getDebugLocation(), 0, 1.87 + "Editor debugger location is correct."); 1.88 + ok(gEditor.hasLineClass(0, "debug-line"), 1.89 + "The debugged line is highlighted appropriately (1)."); 1.90 + 1.91 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); 1.92 + gSources.selectedIndex = 0; 1.93 + }); 1.94 + 1.95 + return deferred.promise; 1.96 +} 1.97 + 1.98 +function testSwitchPaused1() { 1.99 + let deferred = promise.defer(); 1.100 + 1.101 + ok(gSources.selectedItem, 1.102 + "There should be a selected item in the sources pane."); 1.103 + is(gSources.selectedValue, EXAMPLE_URL + gLabel1, 1.104 + "The selected value is the sources pane is incorrect."); 1.105 + 1.106 + is(gEditor.getText().search(/firstCall/), 118, 1.107 + "The first source is displayed."); 1.108 + is(gEditor.getText().search(/debugger/), -1, 1.109 + "The second source is not displayed."); 1.110 + 1.111 + // The editor's debug location takes a tick to update. 1.112 + executeSoon(() => { 1.113 + ok(isCaretPos(gPanel, 1), 1.114 + "Editor caret location is correct."); 1.115 + is(gEditor.getDebugLocation(), null, 1.116 + "Editor debugger location is correct."); 1.117 + ok(!gEditor.hasLineClass(5, "debug-line"), 1.118 + "The debugged line highlight was removed."); 1.119 + 1.120 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); 1.121 + gSources.selectedIndex = 1; 1.122 + }); 1.123 + 1.124 + return deferred.promise; 1.125 +} 1.126 + 1.127 +function testSwitchPaused2() { 1.128 + let deferred = promise.defer(); 1.129 + 1.130 + ok(gSources.selectedItem, 1.131 + "There should be a selected item in the sources pane."); 1.132 + is(gSources.selectedValue, EXAMPLE_URL + gLabel2, 1.133 + "The selected value is the sources pane is incorrect."); 1.134 + 1.135 + is(gEditor.getText().search(/firstCall/), -1, 1.136 + "The first source is not displayed."); 1.137 + is(gEditor.getText().search(/debugger/), 172, 1.138 + "The second source is displayed."); 1.139 + 1.140 + // The editor's debug location takes a tick to update. 1.141 + executeSoon(() => { 1.142 + ok(isCaretPos(gPanel, 1), 1.143 + "Editor caret location is correct."); 1.144 + is(gEditor.getDebugLocation(), 0, 1.145 + "Editor debugger location is correct."); 1.146 + ok(gEditor.hasLineClass(0, "debug-line"), 1.147 + "The debugged line is highlighted appropriately (2)."); 1.148 + 1.149 + // Step out three times. 1.150 + waitForThreadEvents(gPanel, "paused").then(() => { 1.151 + waitForThreadEvents(gPanel, "paused").then(() => { 1.152 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); 1.153 + gDebugger.gThreadClient.stepOut(); 1.154 + }); 1.155 + gDebugger.gThreadClient.stepOut(); 1.156 + }); 1.157 + gDebugger.gThreadClient.stepOut(); 1.158 + }); 1.159 + 1.160 + return deferred.promise; 1.161 +} 1.162 + 1.163 +function testSwitchRunning() { 1.164 + let deferred = promise.defer(); 1.165 + 1.166 + ok(gSources.selectedItem, 1.167 + "There should be a selected item in the sources pane."); 1.168 + is(gSources.selectedValue, EXAMPLE_URL + gLabel1, 1.169 + "The selected value is the sources pane is incorrect."); 1.170 + 1.171 + is(gEditor.getText().search(/firstCall/), 118, 1.172 + "The first source is displayed."); 1.173 + is(gEditor.getText().search(/debugger/), -1, 1.174 + "The second source is not displayed."); 1.175 + 1.176 + // The editor's debug location takes a tick to update. 1.177 + executeSoon(() => { 1.178 + ok(isCaretPos(gPanel, 1), 1.179 + "Editor caret location is correct."); 1.180 + is(gEditor.getDebugLocation(), 0, 1.181 + "Editor debugger location is correct."); 1.182 + ok(gEditor.hasLineClass(0, "debug-line"), 1.183 + "The debugged line is highlighted appropriately (3)."); 1.184 + 1.185 + deferred.resolve(); 1.186 + }); 1.187 + 1.188 + return deferred.promise; 1.189 +} 1.190 + 1.191 +registerCleanupFunction(function() { 1.192 + gTab = null; 1.193 + gDebuggee = null; 1.194 + gPanel = null; 1.195 + gDebugger = null; 1.196 + gEditor = null; 1.197 + gSources = null; 1.198 + gLabel1 = null; 1.199 + gLabel2 = null; 1.200 +});