summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_variables-view-override-01.js
blob: f923d7f53f559d334ea072bba52bf737a838a60d (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests that VariablesView methods responsible for styling variables
 * as overridden work properly.
 */

const TAB_URL = EXAMPLE_URL + "doc_scope-variable-2.html";

function test() {
  Task.spawn(function* () {
    let options = {
      source: TAB_URL,
      line: 1
    };
    let [tab,, panel] = yield initDebugger(TAB_URL, options);
    let win = panel.panelWin;
    let events = win.EVENTS;
    let variables = win.DebuggerView.Variables;

    callInTab(tab, "test");
    yield waitForCaretAndScopes(panel, 23);

    let firstScope = variables.getScopeAtIndex(0);
    let secondScope = variables.getScopeAtIndex(1);
    let thirdScope = variables.getScopeAtIndex(2);
    let globalLexicalScope = variables.getScopeAtIndex(3);
    let globalScope = variables.getScopeAtIndex(4);

    ok(firstScope, "The first scope is available.");
    ok(secondScope, "The second scope is available.");
    ok(thirdScope, "The third scope is available.");
    ok(globalLexicalScope, "The global lexical scope is available.");
    ok(globalScope, "The global scope is available.");

    is(firstScope.name, "Function scope [secondNest]",
      "The first scope's name is correct.");
    is(secondScope.name, "Function scope [firstNest]",
      "The second scope's name is correct.");
    is(thirdScope.name, "Function scope [test]",
      "The third scope's name is correct.");
    is(globalLexicalScope.name, "Block scope",
      "The global lexical scope's name is correct.");
    is(globalScope.name, "Global scope [Window]",
      "The global scope's name is correct.");

    is(firstScope.expanded, true,
      "The first scope's expansion state is correct.");
    is(secondScope.expanded, false,
      "The second scope's expansion state is correct.");
    is(thirdScope.expanded, false,
      "The third scope's expansion state is correct.");
    is(globalLexicalScope.expanded, false,
      "The global lexical scope's expansion state is correct.");
    is(globalScope.expanded, false,
      "The global scope's expansion state is correct.");

    is(firstScope._store.size, 3,
      "The first scope should have all the variables available.");
    is(secondScope._store.size, 0,
      "The second scope should have no variables available yet.");
    is(thirdScope._store.size, 0,
      "The third scope should have no variables available yet.");
    is(globalLexicalScope._store.size, 0,
      "The global scope should have no variables available yet.");
    is(globalScope._store.size, 0,
      "The global scope should have no variables available yet.");

    // Test getOwnerScopeForVariableOrProperty with simple variables.

    let thisVar = firstScope.get("this");
    let thisOwner = variables.getOwnerScopeForVariableOrProperty(thisVar);
    is(thisOwner, firstScope,
      "The getOwnerScopeForVariableOrProperty method works properly (1).");

    let someVar1 = firstScope.get("a");
    let someOwner1 = variables.getOwnerScopeForVariableOrProperty(someVar1);
    is(someOwner1, firstScope,
      "The getOwnerScopeForVariableOrProperty method works properly (2).");

    // Test getOwnerScopeForVariableOrProperty with first-degree properties.

    let argsVar1 = firstScope.get("arguments");
    let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
    argsVar1.expand();
    yield fetched;

    let calleeProp1 = argsVar1.get("callee");
    let calleeOwner1 = variables.getOwnerScopeForVariableOrProperty(calleeProp1);
    is(calleeOwner1, firstScope,
      "The getOwnerScopeForVariableOrProperty method works properly (3).");

    // Test getOwnerScopeForVariableOrProperty with second-degree properties.

    let protoVar1 = argsVar1.get("__proto__");
    fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
    protoVar1.expand();
    yield fetched;

    let constrProp1 = protoVar1.get("constructor");
    let constrOwner1 = variables.getOwnerScopeForVariableOrProperty(constrProp1);
    is(constrOwner1, firstScope,
      "The getOwnerScopeForVariableOrProperty method works properly (4).");

    // Test getOwnerScopeForVariableOrProperty with a simple variable
    // from non-topmost scopes.

    // Only need to wait for a single FETCHED_VARIABLES event, just for the
    // global scope, because the other local scopes already have the
    // arguments and variables available as evironment bindings.
    fetched = waitForDebuggerEvents(panel, events.FETCHED_VARIABLES);
    secondScope.expand();
    thirdScope.expand();
    globalLexicalScope.expand();
    globalScope.expand();
    yield fetched;

    let someVar2 = secondScope.get("a");
    let someOwner2 = variables.getOwnerScopeForVariableOrProperty(someVar2);
    is(someOwner2, secondScope,
      "The getOwnerScopeForVariableOrProperty method works properly (5).");

    let someVar3 = thirdScope.get("a");
    let someOwner3 = variables.getOwnerScopeForVariableOrProperty(someVar3);
    is(someOwner3, thirdScope,
      "The getOwnerScopeForVariableOrProperty method works properly (6).");

    // Test getOwnerScopeForVariableOrProperty with first-degree properies
    // from non-topmost scopes.

    let argsVar2 = secondScope.get("arguments");
    fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
    argsVar2.expand();
    yield fetched;

    let calleeProp2 = argsVar2.get("callee");
    let calleeOwner2 = variables.getOwnerScopeForVariableOrProperty(calleeProp2);
    is(calleeOwner2, secondScope,
      "The getOwnerScopeForVariableOrProperty method works properly (7).");

    let argsVar3 = thirdScope.get("arguments");
    fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
    argsVar3.expand();
    yield fetched;

    let calleeProp3 = argsVar3.get("callee");
    let calleeOwner3 = variables.getOwnerScopeForVariableOrProperty(calleeProp3);
    is(calleeOwner3, thirdScope,
      "The getOwnerScopeForVariableOrProperty method works properly (8).");

    // Test getOwnerScopeForVariableOrProperty with second-degree properties
    // from non-topmost scopes.

    let protoVar2 = argsVar2.get("__proto__");
    fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
    protoVar2.expand();
    yield fetched;

    let constrProp2 = protoVar2.get("constructor");
    let constrOwner2 = variables.getOwnerScopeForVariableOrProperty(constrProp2);
    is(constrOwner2, secondScope,
      "The getOwnerScopeForVariableOrProperty method works properly (9).");

    let protoVar3 = argsVar3.get("__proto__");
    fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
    protoVar3.expand();
    yield fetched;

    let constrProp3 = protoVar3.get("constructor");
    let constrOwner3 = variables.getOwnerScopeForVariableOrProperty(constrProp3);
    is(constrOwner3, thirdScope,
      "The getOwnerScopeForVariableOrProperty method works properly (10).");

    // Test getParentScopesForVariableOrProperty with simple variables.

    let varOwners1 = variables.getParentScopesForVariableOrProperty(someVar1);
    let varOwners2 = variables.getParentScopesForVariableOrProperty(someVar2);
    let varOwners3 = variables.getParentScopesForVariableOrProperty(someVar3);

    is(varOwners1.length, 0,
      "There should be no owner scopes for the first variable.");

    is(varOwners2.length, 1,
      "There should be one owner scope for the second variable.");
    is(varOwners2[0], firstScope,
      "The only owner scope for the second variable is correct.");

    is(varOwners3.length, 2,
      "There should be two owner scopes for the third variable.");
    is(varOwners3[0], firstScope,
      "The first owner scope for the third variable is correct.");
    is(varOwners3[1], secondScope,
      "The second owner scope for the third variable is correct.");

    // Test getParentScopesForVariableOrProperty with first-degree properties.

    let propOwners1 = variables.getParentScopesForVariableOrProperty(calleeProp1);
    let propOwners2 = variables.getParentScopesForVariableOrProperty(calleeProp2);
    let propOwners3 = variables.getParentScopesForVariableOrProperty(calleeProp3);

    is(propOwners1.length, 0,
      "There should be no owner scopes for the first property.");

    is(propOwners2.length, 1,
      "There should be one owner scope for the second property.");
    is(propOwners2[0], firstScope,
      "The only owner scope for the second property is correct.");

    is(propOwners3.length, 2,
      "There should be two owner scopes for the third property.");
    is(propOwners3[0], firstScope,
      "The first owner scope for the third property is correct.");
    is(propOwners3[1], secondScope,
      "The second owner scope for the third property is correct.");

    // Test getParentScopesForVariableOrProperty with second-degree properties.

    let secPropOwners1 = variables.getParentScopesForVariableOrProperty(constrProp1);
    let secPropOwners2 = variables.getParentScopesForVariableOrProperty(constrProp2);
    let secPropOwners3 = variables.getParentScopesForVariableOrProperty(constrProp3);

    is(secPropOwners1.length, 0,
      "There should be no owner scopes for the first inner property.");

    is(secPropOwners2.length, 1,
      "There should be one owner scope for the second inner property.");
    is(secPropOwners2[0], firstScope,
      "The only owner scope for the second inner property is correct.");

    is(secPropOwners3.length, 2,
      "There should be two owner scopes for the third inner property.");
    is(secPropOwners3[0], firstScope,
      "The first owner scope for the third inner property is correct.");
    is(secPropOwners3[1], secondScope,
      "The second owner scope for the third inner property is correct.");

    yield resumeDebuggerThenCloseAndFinish(panel);
  });
}