michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Make sure that the variables view correctly re-expands nodes after pauses. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_with-frame.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gBreakpoints, gSources, gVariables; michael@0: michael@0: function test() { michael@0: // Debug test slaves are a bit slow at this test. michael@0: requestLongerTimeout(4); michael@0: michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gBreakpoints = gDebugger.DebuggerController.Breakpoints; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: gVariables = gDebugger.DebuggerView.Variables; michael@0: michael@0: // Always expand all items between pauses except 'window' variables. michael@0: gVariables.commitHierarchyIgnoredItems = Object.create(null, { window: { value: true } }); michael@0: michael@0: waitForSourceShown(gPanel, ".html") michael@0: .then(addBreakpoint) michael@0: .then(() => ensureThreadClientState(gPanel, "resumed")) michael@0: .then(pauseDebuggee) michael@0: .then(prepareVariablesAndProperties) michael@0: .then(stepInDebuggee) michael@0: .then(testVariablesExpand) michael@0: .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function addBreakpoint() { michael@0: return gBreakpoints.addBreakpoint({ url: gSources.selectedValue, line: 21 }); michael@0: } michael@0: michael@0: function pauseDebuggee() { michael@0: // Spin the event loop before causing the debuggee to pause, to allow michael@0: // this function to return first. michael@0: executeSoon(() => { michael@0: EventUtils.sendMouseEvent({ type: "click" }, michael@0: gDebuggee.document.querySelector("button"), michael@0: gDebuggee); michael@0: }); michael@0: michael@0: // The first 'with' scope should be expanded by default, but the michael@0: // variables haven't been fetched yet. This is how 'with' scopes work. michael@0: return promise.all([ michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES), michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES) michael@0: ]); michael@0: } michael@0: michael@0: function stepInDebuggee() { michael@0: // Spin the event loop before causing the debuggee to pause, to allow michael@0: // this function to return first. michael@0: executeSoon(() => { michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: gDebugger.document.querySelector("#step-in"), michael@0: gDebugger); michael@0: }); michael@0: michael@0: return promise.all([ michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES, 1), michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES, 3), michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1), michael@0: ]); michael@0: } michael@0: michael@0: function testVariablesExpand() { michael@0: let localScope = gVariables.getScopeAtIndex(0); michael@0: let withScope = gVariables.getScopeAtIndex(1); michael@0: let functionScope = gVariables.getScopeAtIndex(2); michael@0: let globalScope = gVariables.getScopeAtIndex(3); michael@0: michael@0: let thisVar = localScope.get("this"); michael@0: let windowVar = thisVar.get("window"); michael@0: michael@0: is(localScope.target.querySelector(".arrow").hasAttribute("open"), true, michael@0: "The localScope arrow should still be expanded."); michael@0: is(withScope.target.querySelector(".arrow").hasAttribute("open"), true, michael@0: "The withScope arrow should still be expanded."); michael@0: is(functionScope.target.querySelector(".arrow").hasAttribute("open"), true, michael@0: "The functionScope arrow should still be expanded."); michael@0: is(globalScope.target.querySelector(".arrow").hasAttribute("open"), true, michael@0: "The globalScope arrow should still be expanded."); michael@0: is(thisVar.target.querySelector(".arrow").hasAttribute("open"), true, michael@0: "The thisVar arrow should still be expanded."); michael@0: is(windowVar.target.querySelector(".arrow").hasAttribute("open"), false, michael@0: "The windowVar arrow should not be expanded."); michael@0: michael@0: is(localScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, michael@0: "The localScope enumerables should still be expanded."); michael@0: is(withScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, michael@0: "The withScope enumerables should still be expanded."); michael@0: is(functionScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, michael@0: "The functionScope enumerables should still be expanded."); michael@0: is(globalScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, michael@0: "The globalScope enumerables should still be expanded."); michael@0: is(thisVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), true, michael@0: "The thisVar enumerables should still be expanded."); michael@0: is(windowVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), false, michael@0: "The windowVar enumerables should not be expanded."); michael@0: michael@0: is(localScope.expanded, true, michael@0: "The localScope expanded getter should return true."); michael@0: is(withScope.expanded, true, michael@0: "The withScope expanded getter should return true."); michael@0: is(functionScope.expanded, true, michael@0: "The functionScope expanded getter should return true."); michael@0: is(globalScope.expanded, true, michael@0: "The globalScope expanded getter should return true."); michael@0: is(thisVar.expanded, true, michael@0: "The thisVar expanded getter should return true."); michael@0: is(windowVar.expanded, false, michael@0: "The windowVar expanded getter should return true."); michael@0: } michael@0: michael@0: function prepareVariablesAndProperties() { michael@0: let deferred = promise.defer(); michael@0: michael@0: let localScope = gVariables.getScopeAtIndex(0); michael@0: let withScope = gVariables.getScopeAtIndex(1); michael@0: let functionScope = gVariables.getScopeAtIndex(2); michael@0: let globalScope = gVariables.getScopeAtIndex(3); michael@0: michael@0: is(localScope.expanded, true, michael@0: "The localScope should be expanded."); michael@0: is(withScope.expanded, false, michael@0: "The withScope should not be expanded yet."); michael@0: is(functionScope.expanded, false, michael@0: "The functionScope should not be expanded yet."); michael@0: is(globalScope.expanded, false, michael@0: "The globalScope should not be expanded yet."); michael@0: michael@0: // Wait for only two events to be triggered, because the Function scope is michael@0: // an environment to which scope arguments and variables are already attached. michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES, 2).then(() => { michael@0: is(localScope.expanded, true, michael@0: "The localScope should now be expanded."); michael@0: is(withScope.expanded, true, michael@0: "The withScope should now be expanded."); michael@0: is(functionScope.expanded, true, michael@0: "The functionScope should now be expanded."); michael@0: is(globalScope.expanded, true, michael@0: "The globalScope should now be expanded."); michael@0: michael@0: let thisVar = localScope.get("this"); michael@0: michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { michael@0: let windowVar = thisVar.get("window"); michael@0: michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { michael@0: let documentVar = windowVar.get("document"); michael@0: michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { michael@0: let locationVar = documentVar.get("location"); michael@0: michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => { michael@0: is(thisVar.expanded, true, michael@0: "The local scope 'this' should be expanded."); michael@0: is(windowVar.expanded, true, michael@0: "The local scope 'this.window' should be expanded."); michael@0: is(documentVar.expanded, true, michael@0: "The local scope 'this.window.document' should be expanded."); michael@0: is(locationVar.expanded, true, michael@0: "The local scope 'this.window.document.location' should be expanded."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: locationVar.expand(); michael@0: }); michael@0: michael@0: documentVar.expand(); michael@0: }); michael@0: michael@0: windowVar.expand(); michael@0: }); michael@0: michael@0: thisVar.expand(); michael@0: }); michael@0: michael@0: withScope.expand(); michael@0: functionScope.expand(); michael@0: globalScope.expand(); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gBreakpoints = null; michael@0: gSources = null; michael@0: gVariables = null; michael@0: });