Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Tests that VariablesView methods responsible for styling variables |
michael@0 | 6 | * as overridden work properly. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | const TAB_URL = EXAMPLE_URL + "doc_scope-variable-2.html"; |
michael@0 | 10 | |
michael@0 | 11 | function test() { |
michael@0 | 12 | Task.spawn(function() { |
michael@0 | 13 | let [tab, debuggee, panel] = yield initDebugger(TAB_URL); |
michael@0 | 14 | let win = panel.panelWin; |
michael@0 | 15 | let events = win.EVENTS; |
michael@0 | 16 | let variables = win.DebuggerView.Variables; |
michael@0 | 17 | |
michael@0 | 18 | // Allow this generator function to yield first. |
michael@0 | 19 | executeSoon(() => debuggee.test()); |
michael@0 | 20 | yield waitForSourceAndCaretAndScopes(panel, ".html", 23); |
michael@0 | 21 | |
michael@0 | 22 | let firstScope = variables.getScopeAtIndex(0); |
michael@0 | 23 | let secondScope = variables.getScopeAtIndex(1); |
michael@0 | 24 | let thirdScope = variables.getScopeAtIndex(2); |
michael@0 | 25 | let globalScope = variables.getScopeAtIndex(3); |
michael@0 | 26 | |
michael@0 | 27 | ok(firstScope, "The first scope is available."); |
michael@0 | 28 | ok(secondScope, "The second scope is available."); |
michael@0 | 29 | ok(thirdScope, "The third scope is available."); |
michael@0 | 30 | ok(globalScope, "The global scope is available."); |
michael@0 | 31 | |
michael@0 | 32 | is(firstScope.name, "Function scope [secondNest]", |
michael@0 | 33 | "The first scope's name is correct."); |
michael@0 | 34 | is(secondScope.name, "Function scope [firstNest]", |
michael@0 | 35 | "The second scope's name is correct."); |
michael@0 | 36 | is(thirdScope.name, "Function scope [test]", |
michael@0 | 37 | "The third scope's name is correct."); |
michael@0 | 38 | is(globalScope.name, "Global scope [Window]", |
michael@0 | 39 | "The global scope's name is correct."); |
michael@0 | 40 | |
michael@0 | 41 | is(firstScope.expanded, true, |
michael@0 | 42 | "The first scope's expansion state is correct."); |
michael@0 | 43 | is(secondScope.expanded, false, |
michael@0 | 44 | "The second scope's expansion state is correct."); |
michael@0 | 45 | is(thirdScope.expanded, false, |
michael@0 | 46 | "The third scope's expansion state is correct."); |
michael@0 | 47 | is(globalScope.expanded, false, |
michael@0 | 48 | "The global scope's expansion state is correct."); |
michael@0 | 49 | |
michael@0 | 50 | is(firstScope._store.size, 3, |
michael@0 | 51 | "The first scope should have all the variables available."); |
michael@0 | 52 | is(secondScope._store.size, 0, |
michael@0 | 53 | "The second scope should have no variables available yet."); |
michael@0 | 54 | is(thirdScope._store.size, 0, |
michael@0 | 55 | "The third scope should have no variables available yet."); |
michael@0 | 56 | is(globalScope._store.size, 0, |
michael@0 | 57 | "The global scope should have no variables available yet."); |
michael@0 | 58 | |
michael@0 | 59 | // Test getOwnerScopeForVariableOrProperty with simple variables. |
michael@0 | 60 | |
michael@0 | 61 | let thisVar = firstScope.get("this"); |
michael@0 | 62 | let thisOwner = variables.getOwnerScopeForVariableOrProperty(thisVar); |
michael@0 | 63 | is(thisOwner, firstScope, |
michael@0 | 64 | "The getOwnerScopeForVariableOrProperty method works properly (1)."); |
michael@0 | 65 | |
michael@0 | 66 | let someVar1 = firstScope.get("a"); |
michael@0 | 67 | let someOwner1 = variables.getOwnerScopeForVariableOrProperty(someVar1); |
michael@0 | 68 | is(someOwner1, firstScope, |
michael@0 | 69 | "The getOwnerScopeForVariableOrProperty method works properly (2)."); |
michael@0 | 70 | |
michael@0 | 71 | // Test getOwnerScopeForVariableOrProperty with first-degree properties. |
michael@0 | 72 | |
michael@0 | 73 | let argsVar1 = firstScope.get("arguments"); |
michael@0 | 74 | let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
michael@0 | 75 | argsVar1.expand(); |
michael@0 | 76 | yield fetched; |
michael@0 | 77 | |
michael@0 | 78 | let calleeProp1 = argsVar1.get("callee"); |
michael@0 | 79 | let calleeOwner1 = variables.getOwnerScopeForVariableOrProperty(calleeProp1); |
michael@0 | 80 | is(calleeOwner1, firstScope, |
michael@0 | 81 | "The getOwnerScopeForVariableOrProperty method works properly (3)."); |
michael@0 | 82 | |
michael@0 | 83 | // Test getOwnerScopeForVariableOrProperty with second-degree properties. |
michael@0 | 84 | |
michael@0 | 85 | let protoVar1 = argsVar1.get("__proto__"); |
michael@0 | 86 | let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
michael@0 | 87 | protoVar1.expand(); |
michael@0 | 88 | yield fetched; |
michael@0 | 89 | |
michael@0 | 90 | let constrProp1 = protoVar1.get("constructor"); |
michael@0 | 91 | let constrOwner1 = variables.getOwnerScopeForVariableOrProperty(constrProp1); |
michael@0 | 92 | is(constrOwner1, firstScope, |
michael@0 | 93 | "The getOwnerScopeForVariableOrProperty method works properly (4)."); |
michael@0 | 94 | |
michael@0 | 95 | // Test getOwnerScopeForVariableOrProperty with a simple variable |
michael@0 | 96 | // from non-topmost scopes. |
michael@0 | 97 | |
michael@0 | 98 | // Only need to wait for a single FETCHED_VARIABLES event, just for the |
michael@0 | 99 | // global scope, because the other local scopes already have the |
michael@0 | 100 | // arguments and variables available as evironment bindings. |
michael@0 | 101 | let fetched = waitForDebuggerEvents(panel, events.FETCHED_VARIABLES); |
michael@0 | 102 | secondScope.expand(); |
michael@0 | 103 | thirdScope.expand(); |
michael@0 | 104 | globalScope.expand(); |
michael@0 | 105 | yield fetched; |
michael@0 | 106 | |
michael@0 | 107 | let someVar2 = secondScope.get("a"); |
michael@0 | 108 | let someOwner2 = variables.getOwnerScopeForVariableOrProperty(someVar2); |
michael@0 | 109 | is(someOwner2, secondScope, |
michael@0 | 110 | "The getOwnerScopeForVariableOrProperty method works properly (5)."); |
michael@0 | 111 | |
michael@0 | 112 | let someVar3 = thirdScope.get("a"); |
michael@0 | 113 | let someOwner3 = variables.getOwnerScopeForVariableOrProperty(someVar3); |
michael@0 | 114 | is(someOwner3, thirdScope, |
michael@0 | 115 | "The getOwnerScopeForVariableOrProperty method works properly (6)."); |
michael@0 | 116 | |
michael@0 | 117 | // Test getOwnerScopeForVariableOrProperty with first-degree properies |
michael@0 | 118 | // from non-topmost scopes. |
michael@0 | 119 | |
michael@0 | 120 | let argsVar2 = secondScope.get("arguments"); |
michael@0 | 121 | let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
michael@0 | 122 | argsVar2.expand(); |
michael@0 | 123 | yield fetched; |
michael@0 | 124 | |
michael@0 | 125 | let calleeProp2 = argsVar2.get("callee"); |
michael@0 | 126 | let calleeOwner2 = variables.getOwnerScopeForVariableOrProperty(calleeProp2); |
michael@0 | 127 | is(calleeOwner2, secondScope, |
michael@0 | 128 | "The getOwnerScopeForVariableOrProperty method works properly (7)."); |
michael@0 | 129 | |
michael@0 | 130 | let argsVar3 = thirdScope.get("arguments"); |
michael@0 | 131 | let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
michael@0 | 132 | argsVar3.expand(); |
michael@0 | 133 | yield fetched; |
michael@0 | 134 | |
michael@0 | 135 | let calleeProp3 = argsVar3.get("callee"); |
michael@0 | 136 | let calleeOwner3 = variables.getOwnerScopeForVariableOrProperty(calleeProp3); |
michael@0 | 137 | is(calleeOwner3, thirdScope, |
michael@0 | 138 | "The getOwnerScopeForVariableOrProperty method works properly (8)."); |
michael@0 | 139 | |
michael@0 | 140 | // Test getOwnerScopeForVariableOrProperty with second-degree properties |
michael@0 | 141 | // from non-topmost scopes. |
michael@0 | 142 | |
michael@0 | 143 | let protoVar2 = argsVar2.get("__proto__"); |
michael@0 | 144 | let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
michael@0 | 145 | protoVar2.expand(); |
michael@0 | 146 | yield fetched; |
michael@0 | 147 | |
michael@0 | 148 | let constrProp2 = protoVar2.get("constructor"); |
michael@0 | 149 | let constrOwner2 = variables.getOwnerScopeForVariableOrProperty(constrProp2); |
michael@0 | 150 | is(constrOwner2, secondScope, |
michael@0 | 151 | "The getOwnerScopeForVariableOrProperty method works properly (9)."); |
michael@0 | 152 | |
michael@0 | 153 | let protoVar3 = argsVar3.get("__proto__"); |
michael@0 | 154 | let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES); |
michael@0 | 155 | protoVar3.expand(); |
michael@0 | 156 | yield fetched; |
michael@0 | 157 | |
michael@0 | 158 | let constrProp3 = protoVar3.get("constructor"); |
michael@0 | 159 | let constrOwner3 = variables.getOwnerScopeForVariableOrProperty(constrProp3); |
michael@0 | 160 | is(constrOwner3, thirdScope, |
michael@0 | 161 | "The getOwnerScopeForVariableOrProperty method works properly (10)."); |
michael@0 | 162 | |
michael@0 | 163 | // Test getParentScopesForVariableOrProperty with simple variables. |
michael@0 | 164 | |
michael@0 | 165 | let varOwners1 = variables.getParentScopesForVariableOrProperty(someVar1); |
michael@0 | 166 | let varOwners2 = variables.getParentScopesForVariableOrProperty(someVar2); |
michael@0 | 167 | let varOwners3 = variables.getParentScopesForVariableOrProperty(someVar3); |
michael@0 | 168 | |
michael@0 | 169 | is(varOwners1.length, 0, |
michael@0 | 170 | "There should be no owner scopes for the first variable."); |
michael@0 | 171 | |
michael@0 | 172 | is(varOwners2.length, 1, |
michael@0 | 173 | "There should be one owner scope for the second variable."); |
michael@0 | 174 | is(varOwners2[0], firstScope, |
michael@0 | 175 | "The only owner scope for the second variable is correct."); |
michael@0 | 176 | |
michael@0 | 177 | is(varOwners3.length, 2, |
michael@0 | 178 | "There should be two owner scopes for the third variable."); |
michael@0 | 179 | is(varOwners3[0], firstScope, |
michael@0 | 180 | "The first owner scope for the third variable is correct."); |
michael@0 | 181 | is(varOwners3[1], secondScope, |
michael@0 | 182 | "The second owner scope for the third variable is correct."); |
michael@0 | 183 | |
michael@0 | 184 | // Test getParentScopesForVariableOrProperty with first-degree properties. |
michael@0 | 185 | |
michael@0 | 186 | let propOwners1 = variables.getParentScopesForVariableOrProperty(calleeProp1); |
michael@0 | 187 | let propOwners2 = variables.getParentScopesForVariableOrProperty(calleeProp2); |
michael@0 | 188 | let propOwners3 = variables.getParentScopesForVariableOrProperty(calleeProp3); |
michael@0 | 189 | |
michael@0 | 190 | is(propOwners1.length, 0, |
michael@0 | 191 | "There should be no owner scopes for the first property."); |
michael@0 | 192 | |
michael@0 | 193 | is(propOwners2.length, 1, |
michael@0 | 194 | "There should be one owner scope for the second property."); |
michael@0 | 195 | is(propOwners2[0], firstScope, |
michael@0 | 196 | "The only owner scope for the second property is correct."); |
michael@0 | 197 | |
michael@0 | 198 | is(propOwners3.length, 2, |
michael@0 | 199 | "There should be two owner scopes for the third property."); |
michael@0 | 200 | is(propOwners3[0], firstScope, |
michael@0 | 201 | "The first owner scope for the third property is correct."); |
michael@0 | 202 | is(propOwners3[1], secondScope, |
michael@0 | 203 | "The second owner scope for the third property is correct."); |
michael@0 | 204 | |
michael@0 | 205 | // Test getParentScopesForVariableOrProperty with second-degree properties. |
michael@0 | 206 | |
michael@0 | 207 | let secPropOwners1 = variables.getParentScopesForVariableOrProperty(constrProp1); |
michael@0 | 208 | let secPropOwners2 = variables.getParentScopesForVariableOrProperty(constrProp2); |
michael@0 | 209 | let secPropOwners3 = variables.getParentScopesForVariableOrProperty(constrProp3); |
michael@0 | 210 | |
michael@0 | 211 | is(secPropOwners1.length, 0, |
michael@0 | 212 | "There should be no owner scopes for the first inner property."); |
michael@0 | 213 | |
michael@0 | 214 | is(secPropOwners2.length, 1, |
michael@0 | 215 | "There should be one owner scope for the second inner property."); |
michael@0 | 216 | is(secPropOwners2[0], firstScope, |
michael@0 | 217 | "The only owner scope for the second inner property is correct."); |
michael@0 | 218 | |
michael@0 | 219 | is(secPropOwners3.length, 2, |
michael@0 | 220 | "There should be two owner scopes for the third inner property."); |
michael@0 | 221 | is(secPropOwners3[0], firstScope, |
michael@0 | 222 | "The first owner scope for the third inner property is correct."); |
michael@0 | 223 | is(secPropOwners3[1], secondScope, |
michael@0 | 224 | "The second owner scope for the third inner property is correct."); |
michael@0 | 225 | |
michael@0 | 226 | yield resumeDebuggerThenCloseAndFinish(panel); |
michael@0 | 227 | }); |
michael@0 | 228 | } |