summaryrefslogtreecommitdiff
path: root/devtools/client/debugger/test/mochitest/browser_dbg_variables-view-01.js
blob: c5c846978df363899452615713a132d1d3187e4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests that creating, collpasing and expanding scopes in the
 * variables view works as expected.
 */

const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";

function test() {
  let options = {
    source: TAB_URL,
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    let variables = aPanel.panelWin.DebuggerView.Variables;
    let testScope = variables.addScope("test");

    ok(testScope,
      "Should have created a scope.");
    ok(testScope.id.includes("test"),
      "The newly created scope should have the default id set.");
    is(testScope.name, "test",
      "The newly created scope should have the desired name set.");

    ok(!testScope.displayValue,
      "The newly created scope should not have a displayed value (1).");
    ok(!testScope.displayValueClassName,
      "The newly created scope should not have a displayed value (2).");

    ok(testScope.target,
      "The newly created scope should point to a target node.");
    ok(testScope.target.id.includes("test"),
      "Should have the correct scope id on the element.");

    is(testScope.target.querySelector(".name").getAttribute("value"), "test",
      "Any new scope should have the designated name.");
    is(testScope.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
      "Any new scope should have a container with no enumerable child nodes.");
    is(testScope.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
      "Any new scope should have a container with no non-enumerable child nodes.");

    ok(!testScope.expanded,
      "Any new created scope should be initially collapsed.");
    ok(testScope.visible,
      "Any new created scope should be initially visible.");

    let expandCallbackArg = null;
    let collapseCallbackArg = null;
    let toggleCallbackArg = null;
    let hideCallbackArg = null;
    let showCallbackArg = null;

    testScope.onexpand = aScope => expandCallbackArg = aScope;
    testScope.oncollapse = aScope => collapseCallbackArg = aScope;
    testScope.ontoggle = aScope => toggleCallbackArg = aScope;
    testScope.onhide = aScope => hideCallbackArg = aScope;
    testScope.onshow = aScope => showCallbackArg = aScope;

    testScope.expand();
    ok(testScope.expanded,
      "The testScope shouldn't be collapsed anymore.");
    is(expandCallbackArg, testScope,
      "The expandCallback wasn't called as it should.");

    testScope.collapse();
    ok(!testScope.expanded,
      "The testScope should be collapsed again.");
    is(collapseCallbackArg, testScope,
      "The collapseCallback wasn't called as it should.");

    testScope.expanded = true;
    ok(testScope.expanded,
      "The testScope shouldn't be collapsed anymore.");

    testScope.toggle();
    ok(!testScope.expanded,
      "The testScope should be collapsed again.");
    is(toggleCallbackArg, testScope,
      "The toggleCallback wasn't called as it should.");

    testScope.hide();
    ok(!testScope.visible,
      "The testScope should be invisible after hiding.");
    is(hideCallbackArg, testScope,
      "The hideCallback wasn't called as it should.");

    testScope.show();
    ok(testScope.visible,
      "The testScope should be visible again.");
    is(showCallbackArg, testScope,
      "The showCallback wasn't called as it should.");

    testScope.visible = false;
    ok(!testScope.visible,
      "The testScope should be invisible after hiding.");
    ok(!testScope.expanded,
      "The testScope should remember it is collapsed even if it is hidden.");

    testScope.visible = true;
    ok(testScope.visible,
      "The testScope should be visible after reshowing.");
    ok(!testScope.expanded,
      "The testScope should remember it is collapsed after it is reshown.");

    EventUtils.sendMouseEvent({ type: "mousedown", button: 1 },
      testScope.target.querySelector(".title"),
      aPanel.panelWin);

    ok(!testScope.expanded,
      "Clicking the testScope title with the right mouse button should't expand it.");

    EventUtils.sendMouseEvent({ type: "mousedown" },
      testScope.target.querySelector(".title"),
      aPanel.panelWin);

    ok(testScope.expanded,
      "Clicking the testScope title should expand it.");

    EventUtils.sendMouseEvent({ type: "mousedown" },
      testScope.target.querySelector(".title"),
      aPanel.panelWin);

    ok(!testScope.expanded,
      "Clicking again the testScope title should collapse it.");

    closeDebuggerAndFinish(aPanel);
  });
}