1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_variables-view-webidl.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 WebIDL attributes in DOM 1.9 + * objects. 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(expandGlobalScope) 1.30 + .then(performTest) 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 expandGlobalScope() { 1.43 + let deferred = promise.defer(); 1.44 + 1.45 + let globalScope = gVariables.getScopeAtIndex(1); 1.46 + is(globalScope.expanded, false, 1.47 + "The global scope should not be expanded by default."); 1.48 + 1.49 + gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve); 1.50 + 1.51 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.52 + globalScope.target.querySelector(".name"), 1.53 + gDebugger); 1.54 + 1.55 + return deferred.promise; 1.56 +} 1.57 + 1.58 +function performTest() { 1.59 + let deferred = promise.defer(); 1.60 + let globalScope = gVariables.getScopeAtIndex(1); 1.61 + 1.62 + let buttonVar = globalScope.get("button"); 1.63 + let buttonAsProtoVar = globalScope.get("buttonAsProto"); 1.64 + let documentVar = globalScope.get("document"); 1.65 + 1.66 + is(buttonVar.target.querySelector(".name").getAttribute("value"), "button", 1.67 + "Should have the right property name for 'button'."); 1.68 + is(buttonVar.target.querySelector(".value").getAttribute("value"), "<button>", 1.69 + "Should have the right property value for 'button'."); 1.70 + ok(buttonVar.target.querySelector(".value").className.contains("token-domnode"), 1.71 + "Should have the right token class for 'button'."); 1.72 + 1.73 + is(buttonAsProtoVar.target.querySelector(".name").getAttribute("value"), "buttonAsProto", 1.74 + "Should have the right property name for 'buttonAsProto'."); 1.75 + is(buttonAsProtoVar.target.querySelector(".value").getAttribute("value"), "Object", 1.76 + "Should have the right property value for 'buttonAsProto'."); 1.77 + ok(buttonAsProtoVar.target.querySelector(".value").className.contains("token-other"), 1.78 + "Should have the right token class for 'buttonAsProto'."); 1.79 + 1.80 + is(documentVar.target.querySelector(".name").getAttribute("value"), "document", 1.81 + "Should have the right property name for 'document'."); 1.82 + is(documentVar.target.querySelector(".value").getAttribute("value"), 1.83 + "HTMLDocument \u2192 doc_frame-parameters.html", 1.84 + "Should have the right property value for 'document'."); 1.85 + ok(documentVar.target.querySelector(".value").className.contains("token-domnode"), 1.86 + "Should have the right token class for 'document'."); 1.87 + 1.88 + is(buttonVar.expanded, false, 1.89 + "The buttonVar should not be expanded at this point."); 1.90 + is(buttonAsProtoVar.expanded, false, 1.91 + "The buttonAsProtoVar should not be expanded at this point."); 1.92 + is(documentVar.expanded, false, 1.93 + "The documentVar should not be expanded at this point."); 1.94 + 1.95 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 3).then(() => { 1.96 + is(buttonVar.get("type").target.querySelector(".name").getAttribute("value"), "type", 1.97 + "Should have the right property name for 'type'."); 1.98 + is(buttonVar.get("type").target.querySelector(".value").getAttribute("value"), "\"submit\"", 1.99 + "Should have the right property value for 'type'."); 1.100 + ok(buttonVar.get("type").target.querySelector(".value").className.contains("token-string"), 1.101 + "Should have the right token class for 'type'."); 1.102 + 1.103 + is(buttonVar.get("childNodes").target.querySelector(".name").getAttribute("value"), "childNodes", 1.104 + "Should have the right property name for 'childNodes'."); 1.105 + is(buttonVar.get("childNodes").target.querySelector(".value").getAttribute("value"), "NodeList[1]", 1.106 + "Should have the right property value for 'childNodes'."); 1.107 + ok(buttonVar.get("childNodes").target.querySelector(".value").className.contains("token-other"), 1.108 + "Should have the right token class for 'childNodes'."); 1.109 + 1.110 + is(buttonVar.get("onclick").target.querySelector(".name").getAttribute("value"), "onclick", 1.111 + "Should have the right property name for 'onclick'."); 1.112 + is(buttonVar.get("onclick").target.querySelector(".value").getAttribute("value"), "onclick(event)", 1.113 + "Should have the right property value for 'onclick'."); 1.114 + ok(buttonVar.get("onclick").target.querySelector(".value").className.contains("token-other"), 1.115 + "Should have the right token class for 'onclick'."); 1.116 + 1.117 + is(documentVar.get("title").target.querySelector(".name").getAttribute("value"), "title", 1.118 + "Should have the right property name for 'title'."); 1.119 + is(documentVar.get("title").target.querySelector(".value").getAttribute("value"), "\"Debugger test page\"", 1.120 + "Should have the right property value for 'title'."); 1.121 + ok(documentVar.get("title").target.querySelector(".value").className.contains("token-string"), 1.122 + "Should have the right token class for 'title'."); 1.123 + 1.124 + is(documentVar.get("childNodes").target.querySelector(".name").getAttribute("value"), "childNodes", 1.125 + "Should have the right property name for 'childNodes'."); 1.126 + is(documentVar.get("childNodes").target.querySelector(".value").getAttribute("value"), "NodeList[3]", 1.127 + "Should have the right property value for 'childNodes'."); 1.128 + ok(documentVar.get("childNodes").target.querySelector(".value").className.contains("token-other"), 1.129 + "Should have the right token class for 'childNodes'."); 1.130 + 1.131 + is(documentVar.get("onclick").target.querySelector(".name").getAttribute("value"), "onclick", 1.132 + "Should have the right property name for 'onclick'."); 1.133 + is(documentVar.get("onclick").target.querySelector(".value").getAttribute("value"), "null", 1.134 + "Should have the right property value for 'onclick'."); 1.135 + ok(documentVar.get("onclick").target.querySelector(".value").className.contains("token-null"), 1.136 + "Should have the right token class for 'onclick'."); 1.137 + 1.138 + let buttonProtoVar = buttonVar.get("__proto__"); 1.139 + let buttonAsProtoProtoVar = buttonAsProtoVar.get("__proto__"); 1.140 + let documentProtoVar = documentVar.get("__proto__"); 1.141 + 1.142 + is(buttonProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__", 1.143 + "Should have the right property name for '__proto__'."); 1.144 + is(buttonProtoVar.target.querySelector(".value").getAttribute("value"), "HTMLButtonElementPrototype", 1.145 + "Should have the right property value for '__proto__'."); 1.146 + ok(buttonProtoVar.target.querySelector(".value").className.contains("token-other"), 1.147 + "Should have the right token class for '__proto__'."); 1.148 + 1.149 + is(buttonAsProtoProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__", 1.150 + "Should have the right property name for '__proto__'."); 1.151 + is(buttonAsProtoProtoVar.target.querySelector(".value").getAttribute("value"), "<button>", 1.152 + "Should have the right property value for '__proto__'."); 1.153 + ok(buttonAsProtoProtoVar.target.querySelector(".value").className.contains("token-domnode"), 1.154 + "Should have the right token class for '__proto__'."); 1.155 + 1.156 + is(documentProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__", 1.157 + "Should have the right property name for '__proto__'."); 1.158 + is(documentProtoVar.target.querySelector(".value").getAttribute("value"), "HTMLDocumentPrototype", 1.159 + "Should have the right property value for '__proto__'."); 1.160 + ok(documentProtoVar.target.querySelector(".value").className.contains("token-other"), 1.161 + "Should have the right token class for '__proto__'."); 1.162 + 1.163 + is(buttonProtoVar.expanded, false, 1.164 + "The buttonProtoVar should not be expanded at this point."); 1.165 + is(buttonAsProtoProtoVar.expanded, false, 1.166 + "The buttonAsProtoProtoVar should not be expanded at this point."); 1.167 + is(documentProtoVar.expanded, false, 1.168 + "The documentProtoVar should not be expanded at this point."); 1.169 + 1.170 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 3).then(() => { 1.171 + is(buttonAsProtoProtoVar.get("type").target.querySelector(".name").getAttribute("value"), "type", 1.172 + "Should have the right property name for 'type'."); 1.173 + is(buttonAsProtoProtoVar.get("type").target.querySelector(".value").getAttribute("value"), "\"submit\"", 1.174 + "Should have the right property value for 'type'."); 1.175 + ok(buttonAsProtoProtoVar.get("type").target.querySelector(".value").className.contains("token-string"), 1.176 + "Should have the right token class for 'type'."); 1.177 + 1.178 + is(buttonAsProtoProtoVar.get("childNodes").target.querySelector(".name").getAttribute("value"), "childNodes", 1.179 + "Should have the right property name for 'childNodes'."); 1.180 + is(buttonAsProtoProtoVar.get("childNodes").target.querySelector(".value").getAttribute("value"), "NodeList[1]", 1.181 + "Should have the right property value for 'childNodes'."); 1.182 + ok(buttonAsProtoProtoVar.get("childNodes").target.querySelector(".value").className.contains("token-other"), 1.183 + "Should have the right token class for 'childNodes'."); 1.184 + 1.185 + is(buttonAsProtoProtoVar.get("onclick").target.querySelector(".name").getAttribute("value"), "onclick", 1.186 + "Should have the right property name for 'onclick'."); 1.187 + is(buttonAsProtoProtoVar.get("onclick").target.querySelector(".value").getAttribute("value"), "onclick(event)", 1.188 + "Should have the right property value for 'onclick'."); 1.189 + ok(buttonAsProtoProtoVar.get("onclick").target.querySelector(".value").className.contains("token-other"), 1.190 + "Should have the right token class for 'onclick'."); 1.191 + 1.192 + let buttonProtoProtoVar = buttonProtoVar.get("__proto__"); 1.193 + let buttonAsProtoProtoProtoVar = buttonAsProtoProtoVar.get("__proto__"); 1.194 + let documentProtoProtoVar = documentProtoVar.get("__proto__"); 1.195 + 1.196 + is(buttonProtoProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__", 1.197 + "Should have the right property name for '__proto__'."); 1.198 + is(buttonProtoProtoVar.target.querySelector(".value").getAttribute("value"), "HTMLElementPrototype", 1.199 + "Should have the right property value for '__proto__'."); 1.200 + ok(buttonProtoProtoVar.target.querySelector(".value").className.contains("token-other"), 1.201 + "Should have the right token class for '__proto__'."); 1.202 + 1.203 + is(buttonAsProtoProtoProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__", 1.204 + "Should have the right property name for '__proto__'."); 1.205 + is(buttonAsProtoProtoProtoVar.target.querySelector(".value").getAttribute("value"), "HTMLButtonElementPrototype", 1.206 + "Should have the right property value for '__proto__'."); 1.207 + ok(buttonAsProtoProtoProtoVar.target.querySelector(".value").className.contains("token-other"), 1.208 + "Should have the right token class for '__proto__'."); 1.209 + 1.210 + is(documentProtoProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__", 1.211 + "Should have the right property name for '__proto__'."); 1.212 + is(documentProtoProtoVar.target.querySelector(".value").getAttribute("value"), "DocumentPrototype", 1.213 + "Should have the right property value for '__proto__'."); 1.214 + ok(documentProtoProtoVar.target.querySelector(".value").className.contains("token-other"), 1.215 + "Should have the right token class for '__proto__'.") 1.216 + 1.217 + is(buttonAsProtoProtoProtoVar.expanded, false, 1.218 + "The buttonAsProtoProtoProtoVar should not be expanded at this point."); 1.219 + is(buttonAsProtoProtoProtoVar.expanded, false, 1.220 + "The buttonAsProtoProtoProtoVar should not be expanded at this point."); 1.221 + is(documentProtoProtoVar.expanded, false, 1.222 + "The documentProtoProtoVar should not be expanded at this point."); 1.223 + 1.224 + deferred.resolve(); 1.225 + }); 1.226 + 1.227 + // Similarly, expand the 'button.__proto__', 'buttonAsProto.__proto__' and 1.228 + // 'document.__proto__' variables view nodes. 1.229 + buttonProtoVar.expand(); 1.230 + buttonAsProtoProtoVar.expand(); 1.231 + documentProtoVar.expand(); 1.232 + 1.233 + is(buttonProtoVar.expanded, true, 1.234 + "The buttonProtoVar should be immediately marked as expanded."); 1.235 + is(buttonAsProtoProtoVar.expanded, true, 1.236 + "The buttonAsProtoProtoVar should be immediately marked as expanded."); 1.237 + is(documentProtoVar.expanded, true, 1.238 + "The documentProtoVar should be immediately marked as expanded."); 1.239 + }); 1.240 + 1.241 + // Expand the 'button', 'buttonAsProto' and 'document' variables view nodes. 1.242 + // This causes their properties to be retrieved and displayed. 1.243 + buttonVar.expand(); 1.244 + buttonAsProtoVar.expand(); 1.245 + documentVar.expand(); 1.246 + 1.247 + is(buttonVar.expanded, true, 1.248 + "The buttonVar should be immediately marked as expanded."); 1.249 + is(buttonAsProtoVar.expanded, true, 1.250 + "The buttonAsProtoVar should be immediately marked as expanded."); 1.251 + is(documentVar.expanded, true, 1.252 + "The documentVar should be immediately marked as expanded."); 1.253 + 1.254 + return deferred.promise; 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 +});