browser/devtools/debugger/test/browser_dbg_variables-view-01.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-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     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 scopes 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 +
    1.19 +    ok(testScope,
    1.20 +      "Should have created a scope.");
    1.21 +    ok(testScope.id.contains("test"),
    1.22 +      "The newly created scope should have the default id set.");
    1.23 +    is(testScope.name, "test",
    1.24 +      "The newly created scope should have the desired name set.");
    1.25 +
    1.26 +    ok(!testScope.displayValue,
    1.27 +      "The newly created scope should not have a displayed value (1).");
    1.28 +    ok(!testScope.displayValueClassName,
    1.29 +      "The newly created scope should not have a displayed value (2).");
    1.30 +
    1.31 +    ok(testScope.target,
    1.32 +      "The newly created scope should point to a target node.");
    1.33 +    ok(testScope.target.id.contains("test"),
    1.34 +      "Should have the correct scope id on the element.");
    1.35 +
    1.36 +    is(testScope.target.querySelector(".name").getAttribute("value"), "test",
    1.37 +      "Any new scope should have the designated name.");
    1.38 +    is(testScope.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
    1.39 +      "Any new scope should have a container with no enumerable child nodes.");
    1.40 +    is(testScope.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
    1.41 +      "Any new scope should have a container with no non-enumerable child nodes.");
    1.42 +
    1.43 +    ok(!testScope.expanded,
    1.44 +      "Any new created scope should be initially collapsed.");
    1.45 +    ok(testScope.visible,
    1.46 +      "Any new created scope should be initially visible.");
    1.47 +
    1.48 +    let expandCallbackArg = null;
    1.49 +    let collapseCallbackArg = null;
    1.50 +    let toggleCallbackArg = null;
    1.51 +    let hideCallbackArg = null;
    1.52 +    let showCallbackArg = null;
    1.53 +
    1.54 +    testScope.onexpand = aScope => expandCallbackArg = aScope;
    1.55 +    testScope.oncollapse = aScope => collapseCallbackArg = aScope;
    1.56 +    testScope.ontoggle = aScope => toggleCallbackArg = aScope;
    1.57 +    testScope.onhide = aScope => hideCallbackArg = aScope;
    1.58 +    testScope.onshow = aScope => showCallbackArg = aScope;
    1.59 +
    1.60 +    testScope.expand();
    1.61 +    ok(testScope.expanded,
    1.62 +      "The testScope shouldn't be collapsed anymore.");
    1.63 +    is(expandCallbackArg, testScope,
    1.64 +      "The expandCallback wasn't called as it should.");
    1.65 +
    1.66 +    testScope.collapse();
    1.67 +    ok(!testScope.expanded,
    1.68 +      "The testScope should be collapsed again.");
    1.69 +    is(collapseCallbackArg, testScope,
    1.70 +      "The collapseCallback wasn't called as it should.");
    1.71 +
    1.72 +    testScope.expanded = true;
    1.73 +    ok(testScope.expanded,
    1.74 +      "The testScope shouldn't be collapsed anymore.");
    1.75 +
    1.76 +    testScope.toggle();
    1.77 +    ok(!testScope.expanded,
    1.78 +      "The testScope should be collapsed again.");
    1.79 +    is(toggleCallbackArg, testScope,
    1.80 +      "The toggleCallback wasn't called as it should.");
    1.81 +
    1.82 +    testScope.hide();
    1.83 +    ok(!testScope.visible,
    1.84 +      "The testScope should be invisible after hiding.");
    1.85 +    is(hideCallbackArg, testScope,
    1.86 +      "The hideCallback wasn't called as it should.");
    1.87 +
    1.88 +    testScope.show();
    1.89 +    ok(testScope.visible,
    1.90 +      "The testScope should be visible again.");
    1.91 +    is(showCallbackArg, testScope,
    1.92 +      "The showCallback wasn't called as it should.");
    1.93 +
    1.94 +    testScope.visible = false;
    1.95 +    ok(!testScope.visible,
    1.96 +      "The testScope should be invisible after hiding.");
    1.97 +    ok(!testScope.expanded,
    1.98 +      "The testScope should remember it is collapsed even if it is hidden.");
    1.99 +
   1.100 +    testScope.visible = true;
   1.101 +    ok(testScope.visible,
   1.102 +      "The testScope should be visible after reshowing.");
   1.103 +    ok(!testScope.expanded,
   1.104 +      "The testScope should remember it is collapsed after it is reshown.");
   1.105 +
   1.106 +    EventUtils.sendMouseEvent({ type: "mousedown", button: 1 },
   1.107 +      testScope.target.querySelector(".title"),
   1.108 +      aPanel.panelWin);
   1.109 +
   1.110 +    ok(!testScope.expanded,
   1.111 +      "Clicking the testScope title with the right mouse button should't expand it.");
   1.112 +
   1.113 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.114 +      testScope.target.querySelector(".title"),
   1.115 +      aPanel.panelWin);
   1.116 +
   1.117 +    ok(testScope.expanded,
   1.118 +      "Clicking the testScope title should expand it.");
   1.119 +
   1.120 +    EventUtils.sendMouseEvent({ type: "mousedown" },
   1.121 +      testScope.target.querySelector(".title"),
   1.122 +      aPanel.panelWin);
   1.123 +
   1.124 +    ok(!testScope.expanded,
   1.125 +      "Clicking again the testScope title should collapse it.");
   1.126 +
   1.127 +    closeDebuggerAndFinish(aPanel);
   1.128 +  });
   1.129 +}

mercurial