summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_variables-view-frame-with.js
blob: dc98e2d9ba319b8d6270a5ba1c57726e96d887ea (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* -*- 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/ */

/**
 * Make sure that the variables view is correctly populated in 'with' frames.
 */

const TAB_URL = EXAMPLE_URL + "doc_with-frame.html";

var gTab, gPanel, gDebugger;
var gVariables;

function test() {
  let options = {
    source: TAB_URL,
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    gTab = aTab;
    gPanel = aPanel;
    gDebugger = gPanel.panelWin;
    gVariables = gDebugger.DebuggerView.Variables;

    // The first 'with' scope should be expanded by default, but the
    // variables haven't been fetched yet. This is how 'with' scopes work.
    promise.all([
      waitForCaretAndScopes(gPanel, 22),
      waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES)
    ]).then(testFirstWithScope)
      .then(expandSecondWithScope)
      .then(testSecondWithScope)
      .then(expandFunctionScope)
      .then(testFunctionScope)
      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
      .then(null, aError => {
        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
      });

    generateMouseClickInTab(gTab, "content.document.querySelector('button')");
  });
}

function testFirstWithScope() {
  let firstWithScope = gVariables.getScopeAtIndex(0);
  is(firstWithScope.expanded, true,
    "The first 'with' scope should be expanded by default.");
  ok(firstWithScope.target.querySelector(".name").getAttribute("value").includes("[Object]"),
    "The first 'with' scope should be properly identified.");

  let withEnums = firstWithScope._enum.childNodes;
  let withNonEnums = firstWithScope._nonenum.childNodes;

  is(withEnums.length, 3,
    "The first 'with' scope should contain all the created enumerable elements.");
  is(withNonEnums.length, 1,
    "The first 'with' scope should contain all the created non-enumerable elements.");

  is(withEnums[0].querySelector(".name").getAttribute("value"), "this",
    "Should have the right property name for 'this'.");
  is(withEnums[0].querySelector(".value").getAttribute("value"),
    "Window \u2192 doc_with-frame.html",
    "Should have the right property value for 'this'.");
  ok(withEnums[0].querySelector(".value").className.includes("token-other"),
    "Should have the right token class for 'this'.");

  is(withEnums[1].querySelector(".name").getAttribute("value"), "alpha",
    "Should have the right property name for 'alpha'.");
  is(withEnums[1].querySelector(".value").getAttribute("value"), "1",
    "Should have the right property value for 'alpha'.");
  ok(withEnums[1].querySelector(".value").className.includes("token-number"),
    "Should have the right token class for 'alpha'.");

  is(withEnums[2].querySelector(".name").getAttribute("value"), "beta",
    "Should have the right property name for 'beta'.");
  is(withEnums[2].querySelector(".value").getAttribute("value"), "2",
    "Should have the right property value for 'beta'.");
  ok(withEnums[2].querySelector(".value").className.includes("token-number"),
    "Should have the right token class for 'beta'.");

  is(withNonEnums[0].querySelector(".name").getAttribute("value"), "__proto__",
   "Should have the right property name for '__proto__'.");
  is(withNonEnums[0].querySelector(".value").getAttribute("value"), "Object",
   "Should have the right property value for '__proto__'.");
  ok(withNonEnums[0].querySelector(".value").className.includes("token-other"),
   "Should have the right token class for '__proto__'.");
}

function expandSecondWithScope() {
  let deferred = promise.defer();

  let secondWithScope = gVariables.getScopeAtIndex(1);
  is(secondWithScope.expanded, false,
    "The second 'with' scope should not be expanded by default.");

  gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve);

  EventUtils.sendMouseEvent({ type: "mousedown" },
    secondWithScope.target.querySelector(".name"),
    gDebugger);

  return deferred.promise;
}

function testSecondWithScope() {
  let secondWithScope = gVariables.getScopeAtIndex(1);
  is(secondWithScope.expanded, true,
    "The second 'with' scope should now be expanded.");
  ok(secondWithScope.target.querySelector(".name").getAttribute("value").includes("[Math]"),
    "The second 'with' scope should be properly identified.");

  let withEnums = secondWithScope._enum.childNodes;
  let withNonEnums = secondWithScope._nonenum.childNodes;

  is(withEnums.length, 0,
    "The second 'with' scope should contain all the created enumerable elements.");
  isnot(withNonEnums.length, 0,
    "The second 'with' scope should contain all the created non-enumerable elements.");

  is(secondWithScope.get("E").target.querySelector(".name").getAttribute("value"), "E",
    "Should have the right property name for 'E'.");
  is(secondWithScope.get("E").target.querySelector(".value").getAttribute("value"), "2.718281828459045",
    "Should have the right property value for 'E'.");
  ok(secondWithScope.get("E").target.querySelector(".value").className.includes("token-number"),
    "Should have the right token class for 'E'.");

  is(secondWithScope.get("PI").target.querySelector(".name").getAttribute("value"), "PI",
    "Should have the right property name for 'PI'.");
  is(secondWithScope.get("PI").target.querySelector(".value").getAttribute("value"), "3.141592653589793",
    "Should have the right property value for 'PI'.");
  ok(secondWithScope.get("PI").target.querySelector(".value").className.includes("token-number"),
    "Should have the right token class for 'PI'.");

  is(secondWithScope.get("random").target.querySelector(".name").getAttribute("value"), "random",
    "Should have the right property name for 'random'.");
  is(secondWithScope.get("random").target.querySelector(".value").getAttribute("value"), "random()",
    "Should have the right property value for 'random'.");
  ok(secondWithScope.get("random").target.querySelector(".value").className.includes("token-other"),
    "Should have the right token class for 'random'.");

  is(secondWithScope.get("__proto__").target.querySelector(".name").getAttribute("value"), "__proto__",
    "Should have the right property name for '__proto__'.");
  is(secondWithScope.get("__proto__").target.querySelector(".value").getAttribute("value"), "Object",
    "Should have the right property value for '__proto__'.");
  ok(secondWithScope.get("__proto__").target.querySelector(".value").className.includes("token-other"),
    "Should have the right token class for '__proto__'.");
}

function expandFunctionScope() {
  let funcScope = gVariables.getScopeAtIndex(2);
  is(funcScope.expanded, false,
    "The function scope shouldn't be expanded by default, but the " +
    "variables have been already fetched. This is how local scopes work.");

  EventUtils.sendMouseEvent({ type: "mousedown" },
    funcScope.target.querySelector(".name"),
    gDebugger);

  return promise.resolve(null);
}

function testFunctionScope() {
  let funcScope = gVariables.getScopeAtIndex(2);
  is(funcScope.expanded, true,
    "The function scope should now be expanded.");
  ok(funcScope.target.querySelector(".name").getAttribute("value").includes("[test]"),
    "The function scope should be properly identified.");

  let funcEnums = funcScope._enum.childNodes;
  let funcNonEnums = funcScope._nonenum.childNodes;

  is(funcEnums.length, 6,
    "The function scope should contain all the created enumerable elements.");
  is(funcNonEnums.length, 0,
    "The function scope should contain all the created non-enumerable elements.");

  is(funcScope.get("aNumber").target.querySelector(".name").getAttribute("value"), "aNumber",
    "Should have the right property name for 'aNumber'.");
  is(funcScope.get("aNumber").target.querySelector(".value").getAttribute("value"), "10",
    "Should have the right property value for 'aNumber'.");
  ok(funcScope.get("aNumber").target.querySelector(".value").className.includes("token-number"),
    "Should have the right token class for 'aNumber'.");

  is(funcScope.get("a").target.querySelector(".name").getAttribute("value"), "a",
    "Should have the right property name for 'a'.");
  is(funcScope.get("a").target.querySelector(".value").getAttribute("value"), "314.1592653589793",
    "Should have the right property value for 'a'.");
  ok(funcScope.get("a").target.querySelector(".value").className.includes("token-number"),
    "Should have the right token class for 'a'.");

  is(funcScope.get("r").target.querySelector(".name").getAttribute("value"), "r",
    "Should have the right property name for 'r'.");
  is(funcScope.get("r").target.querySelector(".value").getAttribute("value"), "10",
    "Should have the right property value for 'r'.");
  ok(funcScope.get("r").target.querySelector(".value").className.includes("token-number"),
    "Should have the right token class for 'r'.");

  is(funcScope.get("foo").target.querySelector(".name").getAttribute("value"), "foo",
    "Should have the right property name for 'foo'.");
  is(funcScope.get("foo").target.querySelector(".value").getAttribute("value"), "6.283185307179586",
    "Should have the right property value for 'foo'.");
  ok(funcScope.get("foo").target.querySelector(".value").className.includes("token-number"),
    "Should have the right token class for 'foo'.");
}

registerCleanupFunction(function () {
  gTab = null;
  gPanel = null;
  gDebugger = null;
  gVariables = null;
});