browser/devtools/debugger/test/browser_dbg_variables-view-reexpand-02.js

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

mercurial