Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 switching the displayed source in the UI works as advertised. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
michael@0 | 9 | |
michael@0 | 10 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 11 | let gEditor, gSources; |
michael@0 | 12 | |
michael@0 | 13 | function test() { |
michael@0 | 14 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 15 | gTab = aTab; |
michael@0 | 16 | gDebuggee = aDebuggee; |
michael@0 | 17 | gPanel = aPanel; |
michael@0 | 18 | gDebugger = gPanel.panelWin; |
michael@0 | 19 | gEditor = gDebugger.DebuggerView.editor; |
michael@0 | 20 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 21 | |
michael@0 | 22 | ok(gDebugger.document.title.endsWith(EXAMPLE_URL + gLabel1), |
michael@0 | 23 | "Title with first source is correct."); |
michael@0 | 24 | |
michael@0 | 25 | waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) |
michael@0 | 26 | .then(testSourcesDisplay) |
michael@0 | 27 | .then(testSwitchPaused1) |
michael@0 | 28 | .then(testSwitchPaused2) |
michael@0 | 29 | .then(testSwitchRunning) |
michael@0 | 30 | .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
michael@0 | 31 | .then(null, aError => { |
michael@0 | 32 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 33 | }); |
michael@0 | 34 | |
michael@0 | 35 | gDebuggee.firstCall(); |
michael@0 | 36 | }); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | let gLabel1 = "code_script-switching-01.js"; |
michael@0 | 40 | let gLabel2 = "code_script-switching-02.js"; |
michael@0 | 41 | |
michael@0 | 42 | function testSourcesDisplay() { |
michael@0 | 43 | let deferred = promise.defer(); |
michael@0 | 44 | |
michael@0 | 45 | is(gSources.itemCount, 2, |
michael@0 | 46 | "Found the expected number of sources."); |
michael@0 | 47 | |
michael@0 | 48 | is(gSources.items[0].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"), |
michael@0 | 49 | EXAMPLE_URL + "code_script-switching-01.js", |
michael@0 | 50 | "The correct tooltip text is displayed for the first source."); |
michael@0 | 51 | is(gSources.items[1].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"), |
michael@0 | 52 | EXAMPLE_URL + "code_script-switching-02.js", |
michael@0 | 53 | "The correct tooltip text is displayed for the second source."); |
michael@0 | 54 | |
michael@0 | 55 | ok(gSources.containsValue(EXAMPLE_URL + gLabel1), |
michael@0 | 56 | "First source url is incorrect."); |
michael@0 | 57 | ok(gSources.containsValue(EXAMPLE_URL + gLabel2), |
michael@0 | 58 | "Second source url is incorrect."); |
michael@0 | 59 | |
michael@0 | 60 | ok(gSources.getItemForAttachment(e => e.label == gLabel1), |
michael@0 | 61 | "First source label is incorrect."); |
michael@0 | 62 | ok(gSources.getItemForAttachment(e => e.label == gLabel2), |
michael@0 | 63 | "Second source label is incorrect."); |
michael@0 | 64 | |
michael@0 | 65 | ok(gSources.selectedItem, |
michael@0 | 66 | "There should be a selected item in the sources pane."); |
michael@0 | 67 | is(gSources.selectedValue, EXAMPLE_URL + gLabel2, |
michael@0 | 68 | "The selected value is the sources pane is incorrect."); |
michael@0 | 69 | |
michael@0 | 70 | is(gEditor.getText().search(/firstCall/), -1, |
michael@0 | 71 | "The first source is not displayed."); |
michael@0 | 72 | is(gEditor.getText().search(/debugger/), 172, |
michael@0 | 73 | "The second source is displayed."); |
michael@0 | 74 | |
michael@0 | 75 | ok(gDebugger.document.title.endsWith(EXAMPLE_URL + gLabel2), |
michael@0 | 76 | "Title with second source is correct."); |
michael@0 | 77 | |
michael@0 | 78 | ok(isCaretPos(gPanel, 1), |
michael@0 | 79 | "Editor caret location is correct."); |
michael@0 | 80 | |
michael@0 | 81 | // The editor's debug location takes a tick to update. |
michael@0 | 82 | executeSoon(() => { |
michael@0 | 83 | is(gEditor.getDebugLocation(), 0, |
michael@0 | 84 | "Editor debugger location is correct."); |
michael@0 | 85 | ok(gEditor.hasLineClass(0, "debug-line"), |
michael@0 | 86 | "The debugged line is highlighted appropriately (1)."); |
michael@0 | 87 | |
michael@0 | 88 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); |
michael@0 | 89 | gSources.selectedIndex = 0; |
michael@0 | 90 | }); |
michael@0 | 91 | |
michael@0 | 92 | return deferred.promise; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | function testSwitchPaused1() { |
michael@0 | 96 | let deferred = promise.defer(); |
michael@0 | 97 | |
michael@0 | 98 | ok(gSources.selectedItem, |
michael@0 | 99 | "There should be a selected item in the sources pane."); |
michael@0 | 100 | is(gSources.selectedValue, EXAMPLE_URL + gLabel1, |
michael@0 | 101 | "The selected value is the sources pane is incorrect."); |
michael@0 | 102 | |
michael@0 | 103 | is(gEditor.getText().search(/firstCall/), 118, |
michael@0 | 104 | "The first source is displayed."); |
michael@0 | 105 | is(gEditor.getText().search(/debugger/), -1, |
michael@0 | 106 | "The second source is not displayed."); |
michael@0 | 107 | |
michael@0 | 108 | // The editor's debug location takes a tick to update. |
michael@0 | 109 | executeSoon(() => { |
michael@0 | 110 | ok(isCaretPos(gPanel, 1), |
michael@0 | 111 | "Editor caret location is correct."); |
michael@0 | 112 | is(gEditor.getDebugLocation(), null, |
michael@0 | 113 | "Editor debugger location is correct."); |
michael@0 | 114 | ok(!gEditor.hasLineClass(5, "debug-line"), |
michael@0 | 115 | "The debugged line highlight was removed."); |
michael@0 | 116 | |
michael@0 | 117 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); |
michael@0 | 118 | gSources.selectedIndex = 1; |
michael@0 | 119 | }); |
michael@0 | 120 | |
michael@0 | 121 | return deferred.promise; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function testSwitchPaused2() { |
michael@0 | 125 | let deferred = promise.defer(); |
michael@0 | 126 | |
michael@0 | 127 | ok(gSources.selectedItem, |
michael@0 | 128 | "There should be a selected item in the sources pane."); |
michael@0 | 129 | is(gSources.selectedValue, EXAMPLE_URL + gLabel2, |
michael@0 | 130 | "The selected value is the sources pane is incorrect."); |
michael@0 | 131 | |
michael@0 | 132 | is(gEditor.getText().search(/firstCall/), -1, |
michael@0 | 133 | "The first source is not displayed."); |
michael@0 | 134 | is(gEditor.getText().search(/debugger/), 172, |
michael@0 | 135 | "The second source is displayed."); |
michael@0 | 136 | |
michael@0 | 137 | // The editor's debug location takes a tick to update. |
michael@0 | 138 | executeSoon(() => { |
michael@0 | 139 | ok(isCaretPos(gPanel, 1), |
michael@0 | 140 | "Editor caret location is correct."); |
michael@0 | 141 | is(gEditor.getDebugLocation(), 0, |
michael@0 | 142 | "Editor debugger location is correct."); |
michael@0 | 143 | ok(gEditor.hasLineClass(0, "debug-line"), |
michael@0 | 144 | "The debugged line is highlighted appropriately (2)."); |
michael@0 | 145 | |
michael@0 | 146 | // Step out three times. |
michael@0 | 147 | waitForThreadEvents(gPanel, "paused").then(() => { |
michael@0 | 148 | waitForThreadEvents(gPanel, "paused").then(() => { |
michael@0 | 149 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); |
michael@0 | 150 | gDebugger.gThreadClient.stepOut(); |
michael@0 | 151 | }); |
michael@0 | 152 | gDebugger.gThreadClient.stepOut(); |
michael@0 | 153 | }); |
michael@0 | 154 | gDebugger.gThreadClient.stepOut(); |
michael@0 | 155 | }); |
michael@0 | 156 | |
michael@0 | 157 | return deferred.promise; |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | function testSwitchRunning() { |
michael@0 | 161 | let deferred = promise.defer(); |
michael@0 | 162 | |
michael@0 | 163 | ok(gSources.selectedItem, |
michael@0 | 164 | "There should be a selected item in the sources pane."); |
michael@0 | 165 | is(gSources.selectedValue, EXAMPLE_URL + gLabel1, |
michael@0 | 166 | "The selected value is the sources pane is incorrect."); |
michael@0 | 167 | |
michael@0 | 168 | is(gEditor.getText().search(/firstCall/), 118, |
michael@0 | 169 | "The first source is displayed."); |
michael@0 | 170 | is(gEditor.getText().search(/debugger/), -1, |
michael@0 | 171 | "The second source is not displayed."); |
michael@0 | 172 | |
michael@0 | 173 | // The editor's debug location takes a tick to update. |
michael@0 | 174 | executeSoon(() => { |
michael@0 | 175 | ok(isCaretPos(gPanel, 1), |
michael@0 | 176 | "Editor caret location is correct."); |
michael@0 | 177 | is(gEditor.getDebugLocation(), 0, |
michael@0 | 178 | "Editor debugger location is correct."); |
michael@0 | 179 | ok(gEditor.hasLineClass(0, "debug-line"), |
michael@0 | 180 | "The debugged line is highlighted appropriately (3)."); |
michael@0 | 181 | |
michael@0 | 182 | deferred.resolve(); |
michael@0 | 183 | }); |
michael@0 | 184 | |
michael@0 | 185 | return deferred.promise; |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | registerCleanupFunction(function() { |
michael@0 | 189 | gTab = null; |
michael@0 | 190 | gDebuggee = null; |
michael@0 | 191 | gPanel = null; |
michael@0 | 192 | gDebugger = null; |
michael@0 | 193 | gEditor = null; |
michael@0 | 194 | gSources = null; |
michael@0 | 195 | gLabel1 = null; |
michael@0 | 196 | gLabel2 = null; |
michael@0 | 197 | }); |