browser/devtools/debugger/test/browser_dbg_variables-view-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-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,221 @@
     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 + * Tests that creating, collpasing and expanding variables in the
     1.9 + * variables view works as expected.
    1.10 + */
    1.11 +
    1.12 +const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
    1.13 +
    1.14 +function test() {
    1.15 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.16 +    let variables = aPanel.panelWin.DebuggerView.Variables;
    1.17 +    let testScope = variables.addScope("test");
    1.18 +    let testVar = testScope.addItem("something");
    1.19 +    let duplVar = testScope.addItem("something");
    1.20 +
    1.21 +    info("Scope id: " + testScope.id);
    1.22 +    info("Scope name: " + testScope.name);
    1.23 +    info("Variable id: " + testVar.id);
    1.24 +    info("Variable name: " + testVar.name);
    1.25 +
    1.26 +    ok(testScope,
    1.27 +      "Should have created a scope.");
    1.28 +    is(duplVar, null,
    1.29 +      "Shouldn't be able to duplicate variables in the same scope.");
    1.30 +
    1.31 +    ok(testVar,
    1.32 +      "Should have created a variable.");
    1.33 +    ok(testVar.id.contains("something"),
    1.34 +      "The newly created variable should have the default id set.");
    1.35 +    is(testVar.name, "something",
    1.36 +      "The newly created variable should have the desired name set.");
    1.37 +
    1.38 +    ok(!testVar.displayValue,
    1.39 +      "The newly created variable should not have a displayed value yet (1).");
    1.40 +    ok(!testVar.displayValueClassName,
    1.41 +      "The newly created variable should not have a displayed value yet (2).");
    1.42 +
    1.43 +    ok(testVar.target,
    1.44 +      "The newly created scope should point to a target node.");
    1.45 +    ok(testVar.target.id.contains("something"),
    1.46 +      "Should have the correct variable id on the element.");
    1.47 +
    1.48 +    is(testVar.target.querySelector(".name").getAttribute("value"), "something",
    1.49 +      "Any new variable should have the designated name.");
    1.50 +    is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
    1.51 +      "Any new variable should have a container with no enumerable child nodes.");
    1.52 +    is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
    1.53 +      "Any new variable should have a container with no non-enumerable child nodes.");
    1.54 +
    1.55 +    ok(!testVar.expanded,
    1.56 +      "Any new created scope should be initially collapsed.");
    1.57 +    ok(testVar.visible,
    1.58 +      "Any new created scope should be initially visible.");
    1.59 +
    1.60 +    let expandCallbackArg = null;
    1.61 +    let collapseCallbackArg = null;
    1.62 +    let toggleCallbackArg = null;
    1.63 +    let hideCallbackArg = null;
    1.64 +    let showCallbackArg = null;
    1.65 +
    1.66 +    testVar.onexpand = aScope => expandCallbackArg = aScope;
    1.67 +    testVar.oncollapse = aScope => collapseCallbackArg = aScope;
    1.68 +    testVar.ontoggle = aScope => toggleCallbackArg = aScope;
    1.69 +    testVar.onhide = aScope => hideCallbackArg = aScope;
    1.70 +    testVar.onshow = aScope => showCallbackArg = aScope;
    1.71 +
    1.72 +    testVar.expand();
    1.73 +    ok(testVar.expanded,
    1.74 +      "The testVar shouldn't be collapsed anymore.");
    1.75 +    is(expandCallbackArg, testVar,
    1.76 +      "The expandCallback wasn't called as it should.");
    1.77 +
    1.78 +    testVar.collapse();
    1.79 +    ok(!testVar.expanded,
    1.80 +      "The testVar should be collapsed again.");
    1.81 +    is(collapseCallbackArg, testVar,
    1.82 +      "The collapseCallback wasn't called as it should.");
    1.83 +
    1.84 +    testVar.expanded = true;
    1.85 +    ok(testVar.expanded,
    1.86 +      "The testVar shouldn't be collapsed anymore.");
    1.87 +
    1.88 +    testVar.toggle();
    1.89 +    ok(!testVar.expanded,
    1.90 +      "The testVar should be collapsed again.");
    1.91 +    is(toggleCallbackArg, testVar,
    1.92 +      "The toggleCallback wasn't called as it should.");
    1.93 +
    1.94 +    testVar.hide();
    1.95 +    ok(!testVar.visible,
    1.96 +      "The testVar should be invisible after hiding.");
    1.97 +    is(hideCallbackArg, testVar,
    1.98 +      "The hideCallback wasn't called as it should.");
    1.99 +
   1.100 +    testVar.show();
   1.101 +    ok(testVar.visible,
   1.102 +      "The testVar should be visible again.");
   1.103 +    is(showCallbackArg, testVar,
   1.104 +      "The showCallback wasn't called as it should.");
   1.105 +
   1.106 +    testVar.visible = false;
   1.107 +    ok(!testVar.visible,
   1.108 +      "The testVar should be invisible after hiding.");
   1.109 +    ok(!testVar.expanded,
   1.110 +      "The testVar should remember it is collapsed even if it is hidden.");
   1.111 +
   1.112 +    testVar.visible = true;
   1.113 +    ok(testVar.visible,
   1.114 +      "The testVar should be visible after reshowing.");
   1.115 +    ok(!testVar.expanded,
   1.116 +      "The testVar should remember it is collapsed after it is reshown.");
   1.117 +
   1.118 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.119 +      testVar.target.querySelector(".name"),
   1.120 +      aPanel.panelWin);
   1.121 +
   1.122 +    ok(testVar.expanded,
   1.123 +      "Clicking the testVar name should expand it.");
   1.124 +
   1.125 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.126 +      testVar.target.querySelector(".name"),
   1.127 +      aPanel.panelWin);
   1.128 +
   1.129 +    ok(!testVar.expanded,
   1.130 +      "Clicking again the testVar name should collapse it.");
   1.131 +
   1.132 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.133 +      testVar.target.querySelector(".arrow"),
   1.134 +      aPanel.panelWin);
   1.135 +
   1.136 +    ok(testVar.expanded,
   1.137 +      "Clicking the testVar arrow should expand it.");
   1.138 +
   1.139 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.140 +      testVar.target.querySelector(".arrow"),
   1.141 +      aPanel.panelWin);
   1.142 +
   1.143 +    ok(!testVar.expanded,
   1.144 +      "Clicking again the testVar arrow should collapse it.");
   1.145 +
   1.146 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.147 +      testVar.target.querySelector(".title"),
   1.148 +      aPanel.panelWin);
   1.149 +
   1.150 +    ok(testVar.expanded,
   1.151 +      "Clicking the testVar title should expand it again.");
   1.152 +
   1.153 +    testVar.addItem("child", {
   1.154 +      value: {
   1.155 +        type: "object",
   1.156 +        class: "Object"
   1.157 +      }
   1.158 +    });
   1.159 +
   1.160 +    let testChild = testVar.get("child");
   1.161 +    ok(testChild,
   1.162 +      "Should have created a child property.");
   1.163 +    ok(testChild.id.contains("child"),
   1.164 +      "The newly created property should have the default id set.");
   1.165 +    is(testChild.name, "child",
   1.166 +      "The newly created property should have the desired name set.");
   1.167 +
   1.168 +    is(testChild.displayValue, "Object",
   1.169 +      "The newly created property should not have a displayed value yet (1).");
   1.170 +    is(testChild.displayValueClassName, "token-other",
   1.171 +      "The newly created property should not have a displayed value yet (2).");
   1.172 +
   1.173 +    ok(testChild.target,
   1.174 +      "The newly created scope should point to a target node.");
   1.175 +    ok(testChild.target.id.contains("child"),
   1.176 +      "Should have the correct property id on the element.");
   1.177 +
   1.178 +    is(testChild.target.querySelector(".name").getAttribute("value"), "child",
   1.179 +      "Any new property should have the designated name.");
   1.180 +    is(testChild.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
   1.181 +      "Any new property should have a container with no enumerable child nodes.");
   1.182 +    is(testChild.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
   1.183 +      "Any new property should have a container with no non-enumerable child nodes.");
   1.184 +
   1.185 +    ok(!testChild.expanded,
   1.186 +      "Any new created scope should be initially collapsed.");
   1.187 +    ok(testChild.visible,
   1.188 +      "Any new created scope should be initially visible.");
   1.189 +
   1.190 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.191 +      testChild.target.querySelector(".name"),
   1.192 +      aPanel.panelWin);
   1.193 +
   1.194 +    ok(testChild.expanded,
   1.195 +      "Clicking the testChild name should expand it.");
   1.196 +
   1.197 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.198 +      testChild.target.querySelector(".name"),
   1.199 +      aPanel.panelWin);
   1.200 +
   1.201 +    ok(!testChild.expanded,
   1.202 +      "Clicking again the testChild name should collapse it.");
   1.203 +
   1.204 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.205 +      testChild.target.querySelector(".arrow"),
   1.206 +      aPanel.panelWin);
   1.207 +
   1.208 +    ok(testChild.expanded,
   1.209 +      "Clicking the testChild arrow should expand it.");
   1.210 +
   1.211 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.212 +      testChild.target.querySelector(".arrow"),
   1.213 +      aPanel.panelWin);
   1.214 +
   1.215 +    ok(!testChild.expanded,
   1.216 +      "Clicking again the testChild arrow should collapse it.");
   1.217 +
   1.218 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.219 +      testChild.target.querySelector(".title"),
   1.220 +      aPanel.panelWin);
   1.221 +
   1.222 +    closeDebuggerAndFinish(aPanel);
   1.223 +  });
   1.224 +}

mercurial