browser/devtools/debugger/test/browser_dbg_scripts-switching-02.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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-02.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 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
michael@0 23 .then(testSourcesDisplay)
michael@0 24 .then(testSwitchPaused1)
michael@0 25 .then(testSwitchPaused2)
michael@0 26 .then(testSwitchRunning)
michael@0 27 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
michael@0 28 .then(null, aError => {
michael@0 29 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 30 });
michael@0 31
michael@0 32 gDebuggee.firstCall();
michael@0 33 });
michael@0 34 }
michael@0 35
michael@0 36 let gLabel1 = "code_script-switching-01.js";
michael@0 37 let gLabel2 = "code_script-switching-02.js";
michael@0 38 let gParams = "?foo=bar,baz|lol";
michael@0 39
michael@0 40 function testSourcesDisplay() {
michael@0 41 let deferred = promise.defer();
michael@0 42
michael@0 43 is(gSources.itemCount, 2,
michael@0 44 "Found the expected number of sources.");
michael@0 45
michael@0 46 ok(gSources.containsValue(EXAMPLE_URL + gLabel1),
michael@0 47 "First source url is incorrect.");
michael@0 48 ok(gSources.containsValue(EXAMPLE_URL + gLabel2 + gParams),
michael@0 49 "Second source url is incorrect.");
michael@0 50
michael@0 51 ok(gSources.getItemForAttachment(e => e.label == gLabel1),
michael@0 52 "First source label is incorrect.");
michael@0 53 ok(gSources.getItemForAttachment(e => e.label == gLabel2),
michael@0 54 "Second source label is incorrect.");
michael@0 55
michael@0 56 ok(gSources.selectedItem,
michael@0 57 "There should be a selected item in the sources pane.");
michael@0 58 is(gSources.selectedValue, EXAMPLE_URL + gLabel2 + gParams,
michael@0 59 "The selected value is the sources pane is incorrect.");
michael@0 60
michael@0 61 is(gEditor.getText().search(/firstCall/), -1,
michael@0 62 "The first source is not displayed.");
michael@0 63 is(gEditor.getText().search(/debugger/), 172,
michael@0 64 "The second source is displayed.");
michael@0 65
michael@0 66 ok(isCaretPos(gPanel, 1),
michael@0 67 "Editor caret location is correct.");
michael@0 68
michael@0 69 // The editor's debug location takes a tick to update.
michael@0 70 executeSoon(() => {
michael@0 71 is(gEditor.getDebugLocation(), 0,
michael@0 72 "Editor debugger location is correct.");
michael@0 73 ok(gEditor.hasLineClass(0, "debug-line"),
michael@0 74 "The debugged line is highlighted appropriately.");
michael@0 75
michael@0 76 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
michael@0 77 gSources.selectedItem = e => e.attachment.label == gLabel1;
michael@0 78 });
michael@0 79
michael@0 80 return deferred.promise;
michael@0 81 }
michael@0 82
michael@0 83 function testSwitchPaused1() {
michael@0 84 let deferred = promise.defer();
michael@0 85
michael@0 86 ok(gSources.selectedItem,
michael@0 87 "There should be a selected item in the sources pane.");
michael@0 88 is(gSources.selectedValue, EXAMPLE_URL + gLabel1,
michael@0 89 "The selected value is the sources pane is incorrect.");
michael@0 90
michael@0 91 is(gEditor.getText().search(/firstCall/), 118,
michael@0 92 "The first source is displayed.");
michael@0 93 is(gEditor.getText().search(/debugger/), -1,
michael@0 94 "The second source is not displayed.");
michael@0 95
michael@0 96 // The editor's debug location takes a tick to update.
michael@0 97 executeSoon(() => {
michael@0 98 ok(isCaretPos(gPanel, 1),
michael@0 99 "Editor caret location is correct.");
michael@0 100
michael@0 101 is(gEditor.getDebugLocation(), null,
michael@0 102 "Editor debugger location is correct.");
michael@0 103 ok(!gEditor.hasLineClass(5, "debug-line"),
michael@0 104 "The debugged line highlight was removed.");
michael@0 105
michael@0 106 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
michael@0 107 gSources.selectedItem = e => e.attachment.label == gLabel2;
michael@0 108 });
michael@0 109
michael@0 110 return deferred.promise;
michael@0 111 }
michael@0 112
michael@0 113 function testSwitchPaused2() {
michael@0 114 let deferred = promise.defer();
michael@0 115
michael@0 116 ok(gSources.selectedItem,
michael@0 117 "There should be a selected item in the sources pane.");
michael@0 118 is(gSources.selectedValue, EXAMPLE_URL + gLabel2 + gParams,
michael@0 119 "The selected value is the sources pane is incorrect.");
michael@0 120
michael@0 121 is(gEditor.getText().search(/firstCall/), -1,
michael@0 122 "The first source is not displayed.");
michael@0 123 is(gEditor.getText().search(/debugger/), 172,
michael@0 124 "The second source is displayed.");
michael@0 125
michael@0 126 // The editor's debug location takes a tick to update.
michael@0 127 executeSoon(() => {
michael@0 128 ok(isCaretPos(gPanel, 1),
michael@0 129 "Editor caret location is correct.");
michael@0 130 is(gEditor.getDebugLocation(), 0,
michael@0 131 "Editor debugger location is correct.");
michael@0 132 ok(gEditor.hasLineClass(0, "debug-line"),
michael@0 133 "The debugged line is highlighted appropriately.");
michael@0 134
michael@0 135 // Step out three times.
michael@0 136 waitForThreadEvents(gPanel, "paused").then(() => {
michael@0 137 waitForThreadEvents(gPanel, "paused").then(() => {
michael@0 138 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
michael@0 139 gDebugger.gThreadClient.stepOut();
michael@0 140 });
michael@0 141 gDebugger.gThreadClient.stepOut();
michael@0 142 });
michael@0 143 gDebugger.gThreadClient.stepOut();
michael@0 144 });
michael@0 145
michael@0 146 return deferred.promise;
michael@0 147 }
michael@0 148
michael@0 149 function testSwitchRunning() {
michael@0 150 let deferred = promise.defer();
michael@0 151
michael@0 152 ok(gSources.selectedItem,
michael@0 153 "There should be a selected item in the sources pane.");
michael@0 154 is(gSources.selectedValue, EXAMPLE_URL + gLabel1,
michael@0 155 "The selected value is the sources pane is incorrect.");
michael@0 156
michael@0 157 is(gEditor.getText().search(/firstCall/), 118,
michael@0 158 "The first source is displayed.");
michael@0 159 is(gEditor.getText().search(/debugger/), -1,
michael@0 160 "The second source is not displayed.");
michael@0 161
michael@0 162 // The editor's debug location takes a tick to update.
michael@0 163 executeSoon(() => {
michael@0 164 ok(isCaretPos(gPanel, 1),
michael@0 165 "Editor caret location is correct.");
michael@0 166 is(gEditor.getDebugLocation(), 0,
michael@0 167 "Editor debugger location is correct.");
michael@0 168 ok(gEditor.hasLineClass(0, "debug-line"),
michael@0 169 "The debugged line is highlighted appropriately.");
michael@0 170
michael@0 171 deferred.resolve();
michael@0 172 });
michael@0 173
michael@0 174 return deferred.promise;
michael@0 175 }
michael@0 176
michael@0 177 registerCleanupFunction(function() {
michael@0 178 gTab = null;
michael@0 179 gDebuggee = null;
michael@0 180 gPanel = null;
michael@0 181 gDebugger = null;
michael@0 182 gEditor = null;
michael@0 183 gSources = null;
michael@0 184 gLabel1 = null;
michael@0 185 gLabel2 = null;
michael@0 186 gParams = null;
michael@0 187 });

mercurial