1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_variables-view-frame-parameters-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,260 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Make sure that the variables view correctly displays the properties 1.9 + * of objects when debugger is paused. 1.10 + */ 1.11 + 1.12 +const TAB_URL = EXAMPLE_URL + "doc_frame-parameters.html"; 1.13 + 1.14 +let gTab, gDebuggee, gPanel, gDebugger; 1.15 +let gVariables; 1.16 + 1.17 +function test() { 1.18 + // Debug test slaves are a bit slow at this test. 1.19 + requestLongerTimeout(2); 1.20 + 1.21 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.22 + gTab = aTab; 1.23 + gDebuggee = aDebuggee; 1.24 + gPanel = aPanel; 1.25 + gDebugger = gPanel.panelWin; 1.26 + gVariables = gDebugger.DebuggerView.Variables; 1.27 + 1.28 + waitForSourceAndCaretAndScopes(gPanel, ".html", 24) 1.29 + .then(initialChecks) 1.30 + .then(testExpandVariables) 1.31 + .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) 1.32 + .then(null, aError => { 1.33 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.34 + }); 1.35 + 1.36 + EventUtils.sendMouseEvent({ type: "click" }, 1.37 + gDebuggee.document.querySelector("button"), 1.38 + gDebuggee); 1.39 + }); 1.40 +} 1.41 + 1.42 +function initialChecks() { 1.43 + let scopeNodes = gDebugger.document.querySelectorAll(".variables-view-scope"); 1.44 + is(scopeNodes.length, 2, 1.45 + "There should be 2 scopes available."); 1.46 + 1.47 + ok(scopeNodes[0].querySelector(".name").getAttribute("value").contains("[test]"), 1.48 + "The local scope should be properly identified."); 1.49 + ok(scopeNodes[1].querySelector(".name").getAttribute("value").contains("[Window]"), 1.50 + "The global scope should be properly identified."); 1.51 + 1.52 + is(gVariables.getScopeAtIndex(0).target, scopeNodes[0], 1.53 + "getScopeAtIndex(0) didn't return the expected scope."); 1.54 + is(gVariables.getScopeAtIndex(1).target, scopeNodes[1], 1.55 + "getScopeAtIndex(1) didn't return the expected scope."); 1.56 + 1.57 + is(gVariables.getItemForNode(scopeNodes[0]).target, scopeNodes[0], 1.58 + "getItemForNode([0]) didn't return the expected scope."); 1.59 + is(gVariables.getItemForNode(scopeNodes[1]).target, scopeNodes[1], 1.60 + "getItemForNode([1]) didn't return the expected scope."); 1.61 + 1.62 + is(gVariables.getItemForNode(scopeNodes[0]).expanded, true, 1.63 + "The local scope should be expanded by default."); 1.64 + is(gVariables.getItemForNode(scopeNodes[1]).expanded, false, 1.65 + "The global scope should not be collapsed by default."); 1.66 +} 1.67 + 1.68 +function testExpandVariables() { 1.69 + let deferred = promise.defer(); 1.70 + 1.71 + let localScope = gVariables.getScopeAtIndex(0); 1.72 + let localEnums = localScope.target.querySelector(".variables-view-element-details.enum").childNodes; 1.73 + 1.74 + let thisVar = gVariables.getItemForNode(localEnums[0]); 1.75 + let argsVar = gVariables.getItemForNode(localEnums[8]); 1.76 + let cVar = gVariables.getItemForNode(localEnums[10]); 1.77 + 1.78 + is(thisVar.target.querySelector(".name").getAttribute("value"), "this", 1.79 + "Should have the right property name for 'this'."); 1.80 + is(argsVar.target.querySelector(".name").getAttribute("value"), "arguments", 1.81 + "Should have the right property name for 'arguments'."); 1.82 + is(cVar.target.querySelector(".name").getAttribute("value"), "c", 1.83 + "Should have the right property name for 'c'."); 1.84 + 1.85 + is(thisVar.expanded, false, 1.86 + "The thisVar should not be expanded at this point."); 1.87 + is(argsVar.expanded, false, 1.88 + "The argsVar should not be expanded at this point."); 1.89 + is(cVar.expanded, false, 1.90 + "The cVar should not be expanded at this point."); 1.91 + 1.92 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 3).then(() => { 1.93 + is(thisVar.get("window").target.querySelector(".name").getAttribute("value"), "window", 1.94 + "Should have the right property name for 'window'."); 1.95 + is(thisVar.get("window").target.querySelector(".value").getAttribute("value"), 1.96 + "Window \u2192 doc_frame-parameters.html", 1.97 + "Should have the right property value for 'window'."); 1.98 + ok(thisVar.get("window").target.querySelector(".value").className.contains("token-other"), 1.99 + "Should have the right token class for 'window'."); 1.100 + 1.101 + is(thisVar.get("document").target.querySelector(".name").getAttribute("value"), "document", 1.102 + "Should have the right property name for 'document'."); 1.103 + is(thisVar.get("document").target.querySelector(".value").getAttribute("value"), 1.104 + "HTMLDocument \u2192 doc_frame-parameters.html", 1.105 + "Should have the right property value for 'document'."); 1.106 + ok(thisVar.get("document").target.querySelector(".value").className.contains("token-domnode"), 1.107 + "Should have the right token class for 'document'."); 1.108 + 1.109 + let argsProps = argsVar.target.querySelectorAll(".variables-view-property"); 1.110 + is(argsProps.length, 8, 1.111 + "The 'arguments' variable should contain 5 enumerable and 3 non-enumerable properties"); 1.112 + 1.113 + is(argsProps[0].querySelector(".name").getAttribute("value"), "0", 1.114 + "Should have the right property name for '0'."); 1.115 + is(argsProps[0].querySelector(".value").getAttribute("value"), "Object", 1.116 + "Should have the right property value for '0'."); 1.117 + ok(argsProps[0].querySelector(".value").className.contains("token-other"), 1.118 + "Should have the right token class for '0'."); 1.119 + 1.120 + is(argsProps[1].querySelector(".name").getAttribute("value"), "1", 1.121 + "Should have the right property name for '1'."); 1.122 + is(argsProps[1].querySelector(".value").getAttribute("value"), "\"beta\"", 1.123 + "Should have the right property value for '1'."); 1.124 + ok(argsProps[1].querySelector(".value").className.contains("token-string"), 1.125 + "Should have the right token class for '1'."); 1.126 + 1.127 + is(argsProps[2].querySelector(".name").getAttribute("value"), "2", 1.128 + "Should have the right property name for '2'."); 1.129 + is(argsProps[2].querySelector(".value").getAttribute("value"), "3", 1.130 + "Should have the right property name for '2'."); 1.131 + ok(argsProps[2].querySelector(".value").className.contains("token-number"), 1.132 + "Should have the right token class for '2'."); 1.133 + 1.134 + is(argsProps[3].querySelector(".name").getAttribute("value"), "3", 1.135 + "Should have the right property name for '3'."); 1.136 + is(argsProps[3].querySelector(".value").getAttribute("value"), "false", 1.137 + "Should have the right property value for '3'."); 1.138 + ok(argsProps[3].querySelector(".value").className.contains("token-boolean"), 1.139 + "Should have the right token class for '3'."); 1.140 + 1.141 + is(argsProps[4].querySelector(".name").getAttribute("value"), "4", 1.142 + "Should have the right property name for '4'."); 1.143 + is(argsProps[4].querySelector(".value").getAttribute("value"), "null", 1.144 + "Should have the right property name for '4'."); 1.145 + ok(argsProps[4].querySelector(".value").className.contains("token-null"), 1.146 + "Should have the right token class for '4'."); 1.147 + 1.148 + is(gVariables.getItemForNode(argsProps[0]).target, 1.149 + argsVar.target.querySelectorAll(".variables-view-property")[0], 1.150 + "getItemForNode([0]) didn't return the expected property."); 1.151 + 1.152 + is(gVariables.getItemForNode(argsProps[1]).target, 1.153 + argsVar.target.querySelectorAll(".variables-view-property")[1], 1.154 + "getItemForNode([1]) didn't return the expected property."); 1.155 + 1.156 + is(gVariables.getItemForNode(argsProps[2]).target, 1.157 + argsVar.target.querySelectorAll(".variables-view-property")[2], 1.158 + "getItemForNode([2]) didn't return the expected property."); 1.159 + 1.160 + is(argsVar.find(argsProps[0]).target, 1.161 + argsVar.target.querySelectorAll(".variables-view-property")[0], 1.162 + "find([0]) didn't return the expected property."); 1.163 + 1.164 + is(argsVar.find(argsProps[1]).target, 1.165 + argsVar.target.querySelectorAll(".variables-view-property")[1], 1.166 + "find([1]) didn't return the expected property."); 1.167 + 1.168 + is(argsVar.find(argsProps[2]).target, 1.169 + argsVar.target.querySelectorAll(".variables-view-property")[2], 1.170 + "find([2]) didn't return the expected property."); 1.171 + 1.172 + let cProps = cVar.target.querySelectorAll(".variables-view-property"); 1.173 + is(cProps.length, 7, 1.174 + "The 'c' variable should contain 6 enumerable and 1 non-enumerable properties"); 1.175 + 1.176 + is(cProps[0].querySelector(".name").getAttribute("value"), "a", 1.177 + "Should have the right property name for 'a'."); 1.178 + is(cProps[0].querySelector(".value").getAttribute("value"), "1", 1.179 + "Should have the right property value for 'a'."); 1.180 + ok(cProps[0].querySelector(".value").className.contains("token-number"), 1.181 + "Should have the right token class for 'a'."); 1.182 + 1.183 + is(cProps[1].querySelector(".name").getAttribute("value"), "b", 1.184 + "Should have the right property name for 'b'."); 1.185 + is(cProps[1].querySelector(".value").getAttribute("value"), "\"beta\"", 1.186 + "Should have the right property value for 'b'."); 1.187 + ok(cProps[1].querySelector(".value").className.contains("token-string"), 1.188 + "Should have the right token class for 'b'."); 1.189 + 1.190 + is(cProps[2].querySelector(".name").getAttribute("value"), "c", 1.191 + "Should have the right property name for 'c'."); 1.192 + is(cProps[2].querySelector(".value").getAttribute("value"), "3", 1.193 + "Should have the right property value for 'c'."); 1.194 + ok(cProps[2].querySelector(".value").className.contains("token-number"), 1.195 + "Should have the right token class for 'c'."); 1.196 + 1.197 + is(cProps[3].querySelector(".name").getAttribute("value"), "d", 1.198 + "Should have the right property name for 'd'."); 1.199 + is(cProps[3].querySelector(".value").getAttribute("value"), "false", 1.200 + "Should have the right property value for 'd'."); 1.201 + ok(cProps[3].querySelector(".value").className.contains("token-boolean"), 1.202 + "Should have the right token class for 'd'."); 1.203 + 1.204 + is(cProps[4].querySelector(".name").getAttribute("value"), "e", 1.205 + "Should have the right property name for 'e'."); 1.206 + is(cProps[4].querySelector(".value").getAttribute("value"), "null", 1.207 + "Should have the right property value for 'e'."); 1.208 + ok(cProps[4].querySelector(".value").className.contains("token-null"), 1.209 + "Should have the right token class for 'e'."); 1.210 + 1.211 + is(cProps[5].querySelector(".name").getAttribute("value"), "f", 1.212 + "Should have the right property name for 'f'."); 1.213 + is(cProps[5].querySelector(".value").getAttribute("value"), "undefined", 1.214 + "Should have the right property value for 'f'."); 1.215 + ok(cProps[5].querySelector(".value").className.contains("token-undefined"), 1.216 + "Should have the right token class for 'f'."); 1.217 + 1.218 + is(gVariables.getItemForNode(cProps[0]).target, 1.219 + cVar.target.querySelectorAll(".variables-view-property")[0], 1.220 + "getItemForNode([0]) didn't return the expected property."); 1.221 + 1.222 + is(gVariables.getItemForNode(cProps[1]).target, 1.223 + cVar.target.querySelectorAll(".variables-view-property")[1], 1.224 + "getItemForNode([1]) didn't return the expected property."); 1.225 + 1.226 + is(gVariables.getItemForNode(cProps[2]).target, 1.227 + cVar.target.querySelectorAll(".variables-view-property")[2], 1.228 + "getItemForNode([2]) didn't return the expected property."); 1.229 + 1.230 + is(cVar.find(cProps[0]).target, 1.231 + cVar.target.querySelectorAll(".variables-view-property")[0], 1.232 + "find([0]) didn't return the expected property."); 1.233 + 1.234 + is(cVar.find(cProps[1]).target, 1.235 + cVar.target.querySelectorAll(".variables-view-property")[1], 1.236 + "find([1]) didn't return the expected property."); 1.237 + 1.238 + is(cVar.find(cProps[2]).target, 1.239 + cVar.target.querySelectorAll(".variables-view-property")[2], 1.240 + "find([2]) didn't return the expected property."); 1.241 + }); 1.242 + 1.243 + // Expand the 'this', 'arguments' and 'c' variables view nodes. This causes 1.244 + // their properties to be retrieved and displayed. 1.245 + thisVar.expand(); 1.246 + argsVar.expand(); 1.247 + cVar.expand(); 1.248 + 1.249 + is(thisVar.expanded, true, 1.250 + "The thisVar should be immediately marked as expanded."); 1.251 + is(argsVar.expanded, true, 1.252 + "The argsVar should be immediately marked as expanded."); 1.253 + is(cVar.expanded, true, 1.254 + "The cVar should be immediately marked as expanded."); 1.255 +} 1.256 + 1.257 +registerCleanupFunction(function() { 1.258 + gTab = null; 1.259 + gDebuggee = null; 1.260 + gPanel = null; 1.261 + gDebugger = null; 1.262 + gVariables = null; 1.263 +});