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 | * Make sure that the variables view correctly displays the properties |
michael@0 | 6 | * of objects when debugger is paused. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | const TAB_URL = EXAMPLE_URL + "doc_frame-parameters.html"; |
michael@0 | 10 | |
michael@0 | 11 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 12 | let gVariables; |
michael@0 | 13 | |
michael@0 | 14 | function test() { |
michael@0 | 15 | // Debug test slaves are a bit slow at this test. |
michael@0 | 16 | requestLongerTimeout(2); |
michael@0 | 17 | |
michael@0 | 18 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 19 | gTab = aTab; |
michael@0 | 20 | gDebuggee = aDebuggee; |
michael@0 | 21 | gPanel = aPanel; |
michael@0 | 22 | gDebugger = gPanel.panelWin; |
michael@0 | 23 | gVariables = gDebugger.DebuggerView.Variables; |
michael@0 | 24 | |
michael@0 | 25 | waitForSourceAndCaretAndScopes(gPanel, ".html", 24) |
michael@0 | 26 | .then(initialChecks) |
michael@0 | 27 | .then(testExpandVariables) |
michael@0 | 28 | .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
michael@0 | 29 | .then(null, aError => { |
michael@0 | 30 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 31 | }); |
michael@0 | 32 | |
michael@0 | 33 | EventUtils.sendMouseEvent({ type: "click" }, |
michael@0 | 34 | gDebuggee.document.querySelector("button"), |
michael@0 | 35 | gDebuggee); |
michael@0 | 36 | }); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function initialChecks() { |
michael@0 | 40 | let scopeNodes = gDebugger.document.querySelectorAll(".variables-view-scope"); |
michael@0 | 41 | is(scopeNodes.length, 2, |
michael@0 | 42 | "There should be 2 scopes available."); |
michael@0 | 43 | |
michael@0 | 44 | ok(scopeNodes[0].querySelector(".name").getAttribute("value").contains("[test]"), |
michael@0 | 45 | "The local scope should be properly identified."); |
michael@0 | 46 | ok(scopeNodes[1].querySelector(".name").getAttribute("value").contains("[Window]"), |
michael@0 | 47 | "The global scope should be properly identified."); |
michael@0 | 48 | |
michael@0 | 49 | is(gVariables.getScopeAtIndex(0).target, scopeNodes[0], |
michael@0 | 50 | "getScopeAtIndex(0) didn't return the expected scope."); |
michael@0 | 51 | is(gVariables.getScopeAtIndex(1).target, scopeNodes[1], |
michael@0 | 52 | "getScopeAtIndex(1) didn't return the expected scope."); |
michael@0 | 53 | |
michael@0 | 54 | is(gVariables.getItemForNode(scopeNodes[0]).target, scopeNodes[0], |
michael@0 | 55 | "getItemForNode([0]) didn't return the expected scope."); |
michael@0 | 56 | is(gVariables.getItemForNode(scopeNodes[1]).target, scopeNodes[1], |
michael@0 | 57 | "getItemForNode([1]) didn't return the expected scope."); |
michael@0 | 58 | |
michael@0 | 59 | is(gVariables.getItemForNode(scopeNodes[0]).expanded, true, |
michael@0 | 60 | "The local scope should be expanded by default."); |
michael@0 | 61 | is(gVariables.getItemForNode(scopeNodes[1]).expanded, false, |
michael@0 | 62 | "The global scope should not be collapsed by default."); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function testExpandVariables() { |
michael@0 | 66 | let deferred = promise.defer(); |
michael@0 | 67 | |
michael@0 | 68 | let localScope = gVariables.getScopeAtIndex(0); |
michael@0 | 69 | let localEnums = localScope.target.querySelector(".variables-view-element-details.enum").childNodes; |
michael@0 | 70 | |
michael@0 | 71 | let thisVar = gVariables.getItemForNode(localEnums[0]); |
michael@0 | 72 | let argsVar = gVariables.getItemForNode(localEnums[8]); |
michael@0 | 73 | let cVar = gVariables.getItemForNode(localEnums[10]); |
michael@0 | 74 | |
michael@0 | 75 | is(thisVar.target.querySelector(".name").getAttribute("value"), "this", |
michael@0 | 76 | "Should have the right property name for 'this'."); |
michael@0 | 77 | is(argsVar.target.querySelector(".name").getAttribute("value"), "arguments", |
michael@0 | 78 | "Should have the right property name for 'arguments'."); |
michael@0 | 79 | is(cVar.target.querySelector(".name").getAttribute("value"), "c", |
michael@0 | 80 | "Should have the right property name for 'c'."); |
michael@0 | 81 | |
michael@0 | 82 | is(thisVar.expanded, false, |
michael@0 | 83 | "The thisVar should not be expanded at this point."); |
michael@0 | 84 | is(argsVar.expanded, false, |
michael@0 | 85 | "The argsVar should not be expanded at this point."); |
michael@0 | 86 | is(cVar.expanded, false, |
michael@0 | 87 | "The cVar should not be expanded at this point."); |
michael@0 | 88 | |
michael@0 | 89 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 3).then(() => { |
michael@0 | 90 | is(thisVar.get("window").target.querySelector(".name").getAttribute("value"), "window", |
michael@0 | 91 | "Should have the right property name for 'window'."); |
michael@0 | 92 | is(thisVar.get("window").target.querySelector(".value").getAttribute("value"), |
michael@0 | 93 | "Window \u2192 doc_frame-parameters.html", |
michael@0 | 94 | "Should have the right property value for 'window'."); |
michael@0 | 95 | ok(thisVar.get("window").target.querySelector(".value").className.contains("token-other"), |
michael@0 | 96 | "Should have the right token class for 'window'."); |
michael@0 | 97 | |
michael@0 | 98 | is(thisVar.get("document").target.querySelector(".name").getAttribute("value"), "document", |
michael@0 | 99 | "Should have the right property name for 'document'."); |
michael@0 | 100 | is(thisVar.get("document").target.querySelector(".value").getAttribute("value"), |
michael@0 | 101 | "HTMLDocument \u2192 doc_frame-parameters.html", |
michael@0 | 102 | "Should have the right property value for 'document'."); |
michael@0 | 103 | ok(thisVar.get("document").target.querySelector(".value").className.contains("token-domnode"), |
michael@0 | 104 | "Should have the right token class for 'document'."); |
michael@0 | 105 | |
michael@0 | 106 | let argsProps = argsVar.target.querySelectorAll(".variables-view-property"); |
michael@0 | 107 | is(argsProps.length, 8, |
michael@0 | 108 | "The 'arguments' variable should contain 5 enumerable and 3 non-enumerable properties"); |
michael@0 | 109 | |
michael@0 | 110 | is(argsProps[0].querySelector(".name").getAttribute("value"), "0", |
michael@0 | 111 | "Should have the right property name for '0'."); |
michael@0 | 112 | is(argsProps[0].querySelector(".value").getAttribute("value"), "Object", |
michael@0 | 113 | "Should have the right property value for '0'."); |
michael@0 | 114 | ok(argsProps[0].querySelector(".value").className.contains("token-other"), |
michael@0 | 115 | "Should have the right token class for '0'."); |
michael@0 | 116 | |
michael@0 | 117 | is(argsProps[1].querySelector(".name").getAttribute("value"), "1", |
michael@0 | 118 | "Should have the right property name for '1'."); |
michael@0 | 119 | is(argsProps[1].querySelector(".value").getAttribute("value"), "\"beta\"", |
michael@0 | 120 | "Should have the right property value for '1'."); |
michael@0 | 121 | ok(argsProps[1].querySelector(".value").className.contains("token-string"), |
michael@0 | 122 | "Should have the right token class for '1'."); |
michael@0 | 123 | |
michael@0 | 124 | is(argsProps[2].querySelector(".name").getAttribute("value"), "2", |
michael@0 | 125 | "Should have the right property name for '2'."); |
michael@0 | 126 | is(argsProps[2].querySelector(".value").getAttribute("value"), "3", |
michael@0 | 127 | "Should have the right property name for '2'."); |
michael@0 | 128 | ok(argsProps[2].querySelector(".value").className.contains("token-number"), |
michael@0 | 129 | "Should have the right token class for '2'."); |
michael@0 | 130 | |
michael@0 | 131 | is(argsProps[3].querySelector(".name").getAttribute("value"), "3", |
michael@0 | 132 | "Should have the right property name for '3'."); |
michael@0 | 133 | is(argsProps[3].querySelector(".value").getAttribute("value"), "false", |
michael@0 | 134 | "Should have the right property value for '3'."); |
michael@0 | 135 | ok(argsProps[3].querySelector(".value").className.contains("token-boolean"), |
michael@0 | 136 | "Should have the right token class for '3'."); |
michael@0 | 137 | |
michael@0 | 138 | is(argsProps[4].querySelector(".name").getAttribute("value"), "4", |
michael@0 | 139 | "Should have the right property name for '4'."); |
michael@0 | 140 | is(argsProps[4].querySelector(".value").getAttribute("value"), "null", |
michael@0 | 141 | "Should have the right property name for '4'."); |
michael@0 | 142 | ok(argsProps[4].querySelector(".value").className.contains("token-null"), |
michael@0 | 143 | "Should have the right token class for '4'."); |
michael@0 | 144 | |
michael@0 | 145 | is(gVariables.getItemForNode(argsProps[0]).target, |
michael@0 | 146 | argsVar.target.querySelectorAll(".variables-view-property")[0], |
michael@0 | 147 | "getItemForNode([0]) didn't return the expected property."); |
michael@0 | 148 | |
michael@0 | 149 | is(gVariables.getItemForNode(argsProps[1]).target, |
michael@0 | 150 | argsVar.target.querySelectorAll(".variables-view-property")[1], |
michael@0 | 151 | "getItemForNode([1]) didn't return the expected property."); |
michael@0 | 152 | |
michael@0 | 153 | is(gVariables.getItemForNode(argsProps[2]).target, |
michael@0 | 154 | argsVar.target.querySelectorAll(".variables-view-property")[2], |
michael@0 | 155 | "getItemForNode([2]) didn't return the expected property."); |
michael@0 | 156 | |
michael@0 | 157 | is(argsVar.find(argsProps[0]).target, |
michael@0 | 158 | argsVar.target.querySelectorAll(".variables-view-property")[0], |
michael@0 | 159 | "find([0]) didn't return the expected property."); |
michael@0 | 160 | |
michael@0 | 161 | is(argsVar.find(argsProps[1]).target, |
michael@0 | 162 | argsVar.target.querySelectorAll(".variables-view-property")[1], |
michael@0 | 163 | "find([1]) didn't return the expected property."); |
michael@0 | 164 | |
michael@0 | 165 | is(argsVar.find(argsProps[2]).target, |
michael@0 | 166 | argsVar.target.querySelectorAll(".variables-view-property")[2], |
michael@0 | 167 | "find([2]) didn't return the expected property."); |
michael@0 | 168 | |
michael@0 | 169 | let cProps = cVar.target.querySelectorAll(".variables-view-property"); |
michael@0 | 170 | is(cProps.length, 7, |
michael@0 | 171 | "The 'c' variable should contain 6 enumerable and 1 non-enumerable properties"); |
michael@0 | 172 | |
michael@0 | 173 | is(cProps[0].querySelector(".name").getAttribute("value"), "a", |
michael@0 | 174 | "Should have the right property name for 'a'."); |
michael@0 | 175 | is(cProps[0].querySelector(".value").getAttribute("value"), "1", |
michael@0 | 176 | "Should have the right property value for 'a'."); |
michael@0 | 177 | ok(cProps[0].querySelector(".value").className.contains("token-number"), |
michael@0 | 178 | "Should have the right token class for 'a'."); |
michael@0 | 179 | |
michael@0 | 180 | is(cProps[1].querySelector(".name").getAttribute("value"), "b", |
michael@0 | 181 | "Should have the right property name for 'b'."); |
michael@0 | 182 | is(cProps[1].querySelector(".value").getAttribute("value"), "\"beta\"", |
michael@0 | 183 | "Should have the right property value for 'b'."); |
michael@0 | 184 | ok(cProps[1].querySelector(".value").className.contains("token-string"), |
michael@0 | 185 | "Should have the right token class for 'b'."); |
michael@0 | 186 | |
michael@0 | 187 | is(cProps[2].querySelector(".name").getAttribute("value"), "c", |
michael@0 | 188 | "Should have the right property name for 'c'."); |
michael@0 | 189 | is(cProps[2].querySelector(".value").getAttribute("value"), "3", |
michael@0 | 190 | "Should have the right property value for 'c'."); |
michael@0 | 191 | ok(cProps[2].querySelector(".value").className.contains("token-number"), |
michael@0 | 192 | "Should have the right token class for 'c'."); |
michael@0 | 193 | |
michael@0 | 194 | is(cProps[3].querySelector(".name").getAttribute("value"), "d", |
michael@0 | 195 | "Should have the right property name for 'd'."); |
michael@0 | 196 | is(cProps[3].querySelector(".value").getAttribute("value"), "false", |
michael@0 | 197 | "Should have the right property value for 'd'."); |
michael@0 | 198 | ok(cProps[3].querySelector(".value").className.contains("token-boolean"), |
michael@0 | 199 | "Should have the right token class for 'd'."); |
michael@0 | 200 | |
michael@0 | 201 | is(cProps[4].querySelector(".name").getAttribute("value"), "e", |
michael@0 | 202 | "Should have the right property name for 'e'."); |
michael@0 | 203 | is(cProps[4].querySelector(".value").getAttribute("value"), "null", |
michael@0 | 204 | "Should have the right property value for 'e'."); |
michael@0 | 205 | ok(cProps[4].querySelector(".value").className.contains("token-null"), |
michael@0 | 206 | "Should have the right token class for 'e'."); |
michael@0 | 207 | |
michael@0 | 208 | is(cProps[5].querySelector(".name").getAttribute("value"), "f", |
michael@0 | 209 | "Should have the right property name for 'f'."); |
michael@0 | 210 | is(cProps[5].querySelector(".value").getAttribute("value"), "undefined", |
michael@0 | 211 | "Should have the right property value for 'f'."); |
michael@0 | 212 | ok(cProps[5].querySelector(".value").className.contains("token-undefined"), |
michael@0 | 213 | "Should have the right token class for 'f'."); |
michael@0 | 214 | |
michael@0 | 215 | is(gVariables.getItemForNode(cProps[0]).target, |
michael@0 | 216 | cVar.target.querySelectorAll(".variables-view-property")[0], |
michael@0 | 217 | "getItemForNode([0]) didn't return the expected property."); |
michael@0 | 218 | |
michael@0 | 219 | is(gVariables.getItemForNode(cProps[1]).target, |
michael@0 | 220 | cVar.target.querySelectorAll(".variables-view-property")[1], |
michael@0 | 221 | "getItemForNode([1]) didn't return the expected property."); |
michael@0 | 222 | |
michael@0 | 223 | is(gVariables.getItemForNode(cProps[2]).target, |
michael@0 | 224 | cVar.target.querySelectorAll(".variables-view-property")[2], |
michael@0 | 225 | "getItemForNode([2]) didn't return the expected property."); |
michael@0 | 226 | |
michael@0 | 227 | is(cVar.find(cProps[0]).target, |
michael@0 | 228 | cVar.target.querySelectorAll(".variables-view-property")[0], |
michael@0 | 229 | "find([0]) didn't return the expected property."); |
michael@0 | 230 | |
michael@0 | 231 | is(cVar.find(cProps[1]).target, |
michael@0 | 232 | cVar.target.querySelectorAll(".variables-view-property")[1], |
michael@0 | 233 | "find([1]) didn't return the expected property."); |
michael@0 | 234 | |
michael@0 | 235 | is(cVar.find(cProps[2]).target, |
michael@0 | 236 | cVar.target.querySelectorAll(".variables-view-property")[2], |
michael@0 | 237 | "find([2]) didn't return the expected property."); |
michael@0 | 238 | }); |
michael@0 | 239 | |
michael@0 | 240 | // Expand the 'this', 'arguments' and 'c' variables view nodes. This causes |
michael@0 | 241 | // their properties to be retrieved and displayed. |
michael@0 | 242 | thisVar.expand(); |
michael@0 | 243 | argsVar.expand(); |
michael@0 | 244 | cVar.expand(); |
michael@0 | 245 | |
michael@0 | 246 | is(thisVar.expanded, true, |
michael@0 | 247 | "The thisVar should be immediately marked as expanded."); |
michael@0 | 248 | is(argsVar.expanded, true, |
michael@0 | 249 | "The argsVar should be immediately marked as expanded."); |
michael@0 | 250 | is(cVar.expanded, true, |
michael@0 | 251 | "The cVar should be immediately marked as expanded."); |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | registerCleanupFunction(function() { |
michael@0 | 255 | gTab = null; |
michael@0 | 256 | gDebuggee = null; |
michael@0 | 257 | gPanel = null; |
michael@0 | 258 | gDebugger = null; |
michael@0 | 259 | gVariables = null; |
michael@0 | 260 | }); |