1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_variables-view-reexpand-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,209 @@ 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 the variables view correctly re-expands nodes after pauses. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_with-frame.html"; 1.12 + 1.13 +let gTab, gDebuggee, gPanel, gDebugger; 1.14 +let gBreakpoints, gSources, gVariables; 1.15 + 1.16 +function test() { 1.17 + // Debug test slaves are a bit slow at this test. 1.18 + requestLongerTimeout(4); 1.19 + 1.20 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.21 + gTab = aTab; 1.22 + gDebuggee = aDebuggee; 1.23 + gPanel = aPanel; 1.24 + gDebugger = gPanel.panelWin; 1.25 + gBreakpoints = gDebugger.DebuggerController.Breakpoints; 1.26 + gSources = gDebugger.DebuggerView.Sources; 1.27 + gVariables = gDebugger.DebuggerView.Variables; 1.28 + 1.29 + // Always expand all items between pauses except 'window' variables. 1.30 + gVariables.commitHierarchyIgnoredItems = Object.create(null, { window: { value: true } }); 1.31 + 1.32 + waitForSourceShown(gPanel, ".html") 1.33 + .then(addBreakpoint) 1.34 + .then(() => ensureThreadClientState(gPanel, "resumed")) 1.35 + .then(pauseDebuggee) 1.36 + .then(prepareVariablesAndProperties) 1.37 + .then(stepInDebuggee) 1.38 + .then(testVariablesExpand) 1.39 + .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) 1.40 + .then(null, aError => { 1.41 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.42 + }); 1.43 + }); 1.44 +} 1.45 + 1.46 +function addBreakpoint() { 1.47 + return gBreakpoints.addBreakpoint({ url: gSources.selectedValue, line: 21 }); 1.48 +} 1.49 + 1.50 +function pauseDebuggee() { 1.51 + // Spin the event loop before causing the debuggee to pause, to allow 1.52 + // this function to return first. 1.53 + executeSoon(() => { 1.54 + EventUtils.sendMouseEvent({ type: "click" }, 1.55 + gDebuggee.document.querySelector("button"), 1.56 + gDebuggee); 1.57 + }); 1.58 + 1.59 + // The first 'with' scope should be expanded by default, but the 1.60 + // variables haven't been fetched yet. This is how 'with' scopes work. 1.61 + return promise.all([ 1.62 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES), 1.63 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES) 1.64 + ]); 1.65 +} 1.66 + 1.67 +function stepInDebuggee() { 1.68 + // Spin the event loop before causing the debuggee to pause, to allow 1.69 + // this function to return first. 1.70 + executeSoon(() => { 1.71 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.72 + gDebugger.document.querySelector("#step-in"), 1.73 + gDebugger); 1.74 + }); 1.75 + 1.76 + return promise.all([ 1.77 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES, 1), 1.78 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES, 3), 1.79 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1), 1.80 + ]); 1.81 +} 1.82 + 1.83 +function testVariablesExpand() { 1.84 + let localScope = gVariables.getScopeAtIndex(0); 1.85 + let withScope = gVariables.getScopeAtIndex(1); 1.86 + let functionScope = gVariables.getScopeAtIndex(2); 1.87 + let globalScope = gVariables.getScopeAtIndex(3); 1.88 + 1.89 + let thisVar = localScope.get("this"); 1.90 + let windowVar = thisVar.get("window"); 1.91 + 1.92 + is(localScope.target.querySelector(".arrow").hasAttribute("open"), true, 1.93 + "The localScope arrow should still be expanded."); 1.94 + is(withScope.target.querySelector(".arrow").hasAttribute("open"), true, 1.95 + "The withScope arrow should still be expanded."); 1.96 + is(functionScope.target.querySelector(".arrow").hasAttribute("open"), true, 1.97 + "The functionScope arrow should still be expanded."); 1.98 + is(globalScope.target.querySelector(".arrow").hasAttribute("open"), true, 1.99 + "The globalScope arrow should still be expanded."); 1.100 + is(thisVar.target.querySelector(".arrow").hasAttribute("open"), true, 1.101 + "The thisVar arrow should still be expanded."); 1.102 + is(windowVar.target.querySelector(".arrow").hasAttribute("open"), false, 1.103 + "The windowVar arrow should not be expanded."); 1.104 + 1.105 + is(localScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, 1.106 + "The localScope enumerables should still be expanded."); 1.107 + is(withScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, 1.108 + "The withScope enumerables should still be expanded."); 1.109 + is(functionScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, 1.110 + "The functionScope enumerables should still be expanded."); 1.111 + is(globalScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, 1.112 + "The globalScope enumerables should still be expanded."); 1.113 + is(thisVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, 1.114 + "The thisVar enumerables should still be expanded."); 1.115 + is(windowVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), false, 1.116 + "The windowVar enumerables should not be expanded."); 1.117 + 1.118 + is(localScope.expanded, true, 1.119 + "The localScope expanded getter should return true."); 1.120 + is(withScope.expanded, true, 1.121 + "The withScope expanded getter should return true."); 1.122 + is(functionScope.expanded, true, 1.123 + "The functionScope expanded getter should return true."); 1.124 + is(globalScope.expanded, true, 1.125 + "The globalScope expanded getter should return true."); 1.126 + is(thisVar.expanded, true, 1.127 + "The thisVar expanded getter should return true."); 1.128 + is(windowVar.expanded, false, 1.129 + "The windowVar expanded getter should return true."); 1.130 +} 1.131 + 1.132 +function prepareVariablesAndProperties() { 1.133 + let deferred = promise.defer(); 1.134 + 1.135 + let localScope = gVariables.getScopeAtIndex(0); 1.136 + let withScope = gVariables.getScopeAtIndex(1); 1.137 + let functionScope = gVariables.getScopeAtIndex(2); 1.138 + let globalScope = gVariables.getScopeAtIndex(3); 1.139 + 1.140 + is(localScope.expanded, true, 1.141 + "The localScope should be expanded."); 1.142 + is(withScope.expanded, false, 1.143 + "The withScope should not be expanded yet."); 1.144 + is(functionScope.expanded, false, 1.145 + "The functionScope should not be expanded yet."); 1.146 + is(globalScope.expanded, false, 1.147 + "The globalScope should not be expanded yet."); 1.148 + 1.149 + // Wait for only two events to be triggered, because the Function scope is 1.150 + // an environment to which scope arguments and variables are already attached. 1.151 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES, 2).then(() => { 1.152 + is(localScope.expanded, true, 1.153 + "The localScope should now be expanded."); 1.154 + is(withScope.expanded, true, 1.155 + "The withScope should now be expanded."); 1.156 + is(functionScope.expanded, true, 1.157 + "The functionScope should now be expanded."); 1.158 + is(globalScope.expanded, true, 1.159 + "The globalScope should now be expanded."); 1.160 + 1.161 + let thisVar = localScope.get("this"); 1.162 + 1.163 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { 1.164 + let windowVar = thisVar.get("window"); 1.165 + 1.166 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { 1.167 + let documentVar = windowVar.get("document"); 1.168 + 1.169 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { 1.170 + let locationVar = documentVar.get("location"); 1.171 + 1.172 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { 1.173 + is(thisVar.expanded, true, 1.174 + "The local scope 'this' should be expanded."); 1.175 + is(windowVar.expanded, true, 1.176 + "The local scope 'this.window' should be expanded."); 1.177 + is(documentVar.expanded, true, 1.178 + "The local scope 'this.window.document' should be expanded."); 1.179 + is(locationVar.expanded, true, 1.180 + "The local scope 'this.window.document.location' should be expanded."); 1.181 + 1.182 + deferred.resolve(); 1.183 + }); 1.184 + 1.185 + locationVar.expand(); 1.186 + }); 1.187 + 1.188 + documentVar.expand(); 1.189 + }); 1.190 + 1.191 + windowVar.expand(); 1.192 + }); 1.193 + 1.194 + thisVar.expand(); 1.195 + }); 1.196 + 1.197 + withScope.expand(); 1.198 + functionScope.expand(); 1.199 + globalScope.expand(); 1.200 + 1.201 + return deferred.promise; 1.202 +} 1.203 + 1.204 +registerCleanupFunction(function() { 1.205 + gTab = null; 1.206 + gDebuggee = null; 1.207 + gPanel = null; 1.208 + gDebugger = null; 1.209 + gBreakpoints = null; 1.210 + gSources = null; 1.211 + gVariables = null; 1.212 +});