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 the variables view correctly re-expands nodes after pauses. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TAB_URL = EXAMPLE_URL + "doc_with-frame.html"; |
michael@0 | 9 | |
michael@0 | 10 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 11 | let gBreakpoints, gSources, gVariables; |
michael@0 | 12 | |
michael@0 | 13 | function test() { |
michael@0 | 14 | // Debug test slaves are a bit slow at this test. |
michael@0 | 15 | requestLongerTimeout(4); |
michael@0 | 16 | |
michael@0 | 17 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 18 | gTab = aTab; |
michael@0 | 19 | gDebuggee = aDebuggee; |
michael@0 | 20 | gPanel = aPanel; |
michael@0 | 21 | gDebugger = gPanel.panelWin; |
michael@0 | 22 | gBreakpoints = gDebugger.DebuggerController.Breakpoints; |
michael@0 | 23 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 24 | gVariables = gDebugger.DebuggerView.Variables; |
michael@0 | 25 | |
michael@0 | 26 | // Always expand all items between pauses except 'window' variables. |
michael@0 | 27 | gVariables.commitHierarchyIgnoredItems = Object.create(null, { window: { value: true } }); |
michael@0 | 28 | |
michael@0 | 29 | waitForSourceShown(gPanel, ".html") |
michael@0 | 30 | .then(addBreakpoint) |
michael@0 | 31 | .then(() => ensureThreadClientState(gPanel, "resumed")) |
michael@0 | 32 | .then(pauseDebuggee) |
michael@0 | 33 | .then(prepareVariablesAndProperties) |
michael@0 | 34 | .then(stepInDebuggee) |
michael@0 | 35 | .then(testVariablesExpand) |
michael@0 | 36 | .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
michael@0 | 37 | .then(null, aError => { |
michael@0 | 38 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 39 | }); |
michael@0 | 40 | }); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function addBreakpoint() { |
michael@0 | 44 | return gBreakpoints.addBreakpoint({ url: gSources.selectedValue, line: 21 }); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function pauseDebuggee() { |
michael@0 | 48 | // Spin the event loop before causing the debuggee to pause, to allow |
michael@0 | 49 | // this function to return first. |
michael@0 | 50 | executeSoon(() => { |
michael@0 | 51 | EventUtils.sendMouseEvent({ type: "click" }, |
michael@0 | 52 | gDebuggee.document.querySelector("button"), |
michael@0 | 53 | gDebuggee); |
michael@0 | 54 | }); |
michael@0 | 55 | |
michael@0 | 56 | // The first 'with' scope should be expanded by default, but the |
michael@0 | 57 | // variables haven't been fetched yet. This is how 'with' scopes work. |
michael@0 | 58 | return promise.all([ |
michael@0 | 59 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES), |
michael@0 | 60 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES) |
michael@0 | 61 | ]); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function stepInDebuggee() { |
michael@0 | 65 | // Spin the event loop before causing the debuggee to pause, to allow |
michael@0 | 66 | // this function to return first. |
michael@0 | 67 | executeSoon(() => { |
michael@0 | 68 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 69 | gDebugger.document.querySelector("#step-in"), |
michael@0 | 70 | gDebugger); |
michael@0 | 71 | }); |
michael@0 | 72 | |
michael@0 | 73 | return promise.all([ |
michael@0 | 74 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES, 1), |
michael@0 | 75 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES, 3), |
michael@0 | 76 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1), |
michael@0 | 77 | ]); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | function testVariablesExpand() { |
michael@0 | 81 | let localScope = gVariables.getScopeAtIndex(0); |
michael@0 | 82 | let withScope = gVariables.getScopeAtIndex(1); |
michael@0 | 83 | let functionScope = gVariables.getScopeAtIndex(2); |
michael@0 | 84 | let globalScope = gVariables.getScopeAtIndex(3); |
michael@0 | 85 | |
michael@0 | 86 | let thisVar = localScope.get("this"); |
michael@0 | 87 | let windowVar = thisVar.get("window"); |
michael@0 | 88 | |
michael@0 | 89 | is(localScope.target.querySelector(".arrow").hasAttribute("open"), true, |
michael@0 | 90 | "The localScope arrow should still be expanded."); |
michael@0 | 91 | is(withScope.target.querySelector(".arrow").hasAttribute("open"), true, |
michael@0 | 92 | "The withScope arrow should still be expanded."); |
michael@0 | 93 | is(functionScope.target.querySelector(".arrow").hasAttribute("open"), true, |
michael@0 | 94 | "The functionScope arrow should still be expanded."); |
michael@0 | 95 | is(globalScope.target.querySelector(".arrow").hasAttribute("open"), true, |
michael@0 | 96 | "The globalScope arrow should still be expanded."); |
michael@0 | 97 | is(thisVar.target.querySelector(".arrow").hasAttribute("open"), true, |
michael@0 | 98 | "The thisVar arrow should still be expanded."); |
michael@0 | 99 | is(windowVar.target.querySelector(".arrow").hasAttribute("open"), false, |
michael@0 | 100 | "The windowVar arrow should not be expanded."); |
michael@0 | 101 | |
michael@0 | 102 | is(localScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, |
michael@0 | 103 | "The localScope enumerables should still be expanded."); |
michael@0 | 104 | is(withScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, |
michael@0 | 105 | "The withScope enumerables should still be expanded."); |
michael@0 | 106 | is(functionScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, |
michael@0 | 107 | "The functionScope enumerables should still be expanded."); |
michael@0 | 108 | is(globalScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, |
michael@0 | 109 | "The globalScope enumerables should still be expanded."); |
michael@0 | 110 | is(thisVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, |
michael@0 | 111 | "The thisVar enumerables should still be expanded."); |
michael@0 | 112 | is(windowVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), false, |
michael@0 | 113 | "The windowVar enumerables should not be expanded."); |
michael@0 | 114 | |
michael@0 | 115 | is(localScope.expanded, true, |
michael@0 | 116 | "The localScope expanded getter should return true."); |
michael@0 | 117 | is(withScope.expanded, true, |
michael@0 | 118 | "The withScope expanded getter should return true."); |
michael@0 | 119 | is(functionScope.expanded, true, |
michael@0 | 120 | "The functionScope expanded getter should return true."); |
michael@0 | 121 | is(globalScope.expanded, true, |
michael@0 | 122 | "The globalScope expanded getter should return true."); |
michael@0 | 123 | is(thisVar.expanded, true, |
michael@0 | 124 | "The thisVar expanded getter should return true."); |
michael@0 | 125 | is(windowVar.expanded, false, |
michael@0 | 126 | "The windowVar expanded getter should return true."); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | function prepareVariablesAndProperties() { |
michael@0 | 130 | let deferred = promise.defer(); |
michael@0 | 131 | |
michael@0 | 132 | let localScope = gVariables.getScopeAtIndex(0); |
michael@0 | 133 | let withScope = gVariables.getScopeAtIndex(1); |
michael@0 | 134 | let functionScope = gVariables.getScopeAtIndex(2); |
michael@0 | 135 | let globalScope = gVariables.getScopeAtIndex(3); |
michael@0 | 136 | |
michael@0 | 137 | is(localScope.expanded, true, |
michael@0 | 138 | "The localScope should be expanded."); |
michael@0 | 139 | is(withScope.expanded, false, |
michael@0 | 140 | "The withScope should not be expanded yet."); |
michael@0 | 141 | is(functionScope.expanded, false, |
michael@0 | 142 | "The functionScope should not be expanded yet."); |
michael@0 | 143 | is(globalScope.expanded, false, |
michael@0 | 144 | "The globalScope should not be expanded yet."); |
michael@0 | 145 | |
michael@0 | 146 | // Wait for only two events to be triggered, because the Function scope is |
michael@0 | 147 | // an environment to which scope arguments and variables are already attached. |
michael@0 | 148 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES, 2).then(() => { |
michael@0 | 149 | is(localScope.expanded, true, |
michael@0 | 150 | "The localScope should now be expanded."); |
michael@0 | 151 | is(withScope.expanded, true, |
michael@0 | 152 | "The withScope should now be expanded."); |
michael@0 | 153 | is(functionScope.expanded, true, |
michael@0 | 154 | "The functionScope should now be expanded."); |
michael@0 | 155 | is(globalScope.expanded, true, |
michael@0 | 156 | "The globalScope should now be expanded."); |
michael@0 | 157 | |
michael@0 | 158 | let thisVar = localScope.get("this"); |
michael@0 | 159 | |
michael@0 | 160 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { |
michael@0 | 161 | let windowVar = thisVar.get("window"); |
michael@0 | 162 | |
michael@0 | 163 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { |
michael@0 | 164 | let documentVar = windowVar.get("document"); |
michael@0 | 165 | |
michael@0 | 166 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { |
michael@0 | 167 | let locationVar = documentVar.get("location"); |
michael@0 | 168 | |
michael@0 | 169 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { |
michael@0 | 170 | is(thisVar.expanded, true, |
michael@0 | 171 | "The local scope 'this' should be expanded."); |
michael@0 | 172 | is(windowVar.expanded, true, |
michael@0 | 173 | "The local scope 'this.window' should be expanded."); |
michael@0 | 174 | is(documentVar.expanded, true, |
michael@0 | 175 | "The local scope 'this.window.document' should be expanded."); |
michael@0 | 176 | is(locationVar.expanded, true, |
michael@0 | 177 | "The local scope 'this.window.document.location' should be expanded."); |
michael@0 | 178 | |
michael@0 | 179 | deferred.resolve(); |
michael@0 | 180 | }); |
michael@0 | 181 | |
michael@0 | 182 | locationVar.expand(); |
michael@0 | 183 | }); |
michael@0 | 184 | |
michael@0 | 185 | documentVar.expand(); |
michael@0 | 186 | }); |
michael@0 | 187 | |
michael@0 | 188 | windowVar.expand(); |
michael@0 | 189 | }); |
michael@0 | 190 | |
michael@0 | 191 | thisVar.expand(); |
michael@0 | 192 | }); |
michael@0 | 193 | |
michael@0 | 194 | withScope.expand(); |
michael@0 | 195 | functionScope.expand(); |
michael@0 | 196 | globalScope.expand(); |
michael@0 | 197 | |
michael@0 | 198 | return deferred.promise; |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | registerCleanupFunction(function() { |
michael@0 | 202 | gTab = null; |
michael@0 | 203 | gDebuggee = null; |
michael@0 | 204 | gPanel = null; |
michael@0 | 205 | gDebugger = null; |
michael@0 | 206 | gBreakpoints = null; |
michael@0 | 207 | gSources = null; |
michael@0 | 208 | gVariables = null; |
michael@0 | 209 | }); |