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