1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_variables-view-frame-with.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,211 @@ 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 is correctly populated in 'with' frames. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_with-frame.html"; 1.12 + 1.13 +let gTab, gDebuggee, gPanel, gDebugger; 1.14 +let gVariables; 1.15 + 1.16 +function test() { 1.17 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.18 + gTab = aTab; 1.19 + gDebuggee = aDebuggee; 1.20 + gPanel = aPanel; 1.21 + gDebugger = gPanel.panelWin; 1.22 + gVariables = gDebugger.DebuggerView.Variables; 1.23 + 1.24 + // The first 'with' scope should be expanded by default, but the 1.25 + // variables haven't been fetched yet. This is how 'with' scopes work. 1.26 + promise.all([ 1.27 + waitForSourceAndCaret(gPanel, ".html", 22), 1.28 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES), 1.29 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES) 1.30 + ]).then(testFirstWithScope) 1.31 + .then(expandSecondWithScope) 1.32 + .then(testSecondWithScope) 1.33 + .then(expandFunctionScope) 1.34 + .then(testFunctionScope) 1.35 + .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) 1.36 + .then(null, aError => { 1.37 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.38 + }); 1.39 + 1.40 + EventUtils.sendMouseEvent({ type: "click" }, 1.41 + gDebuggee.document.querySelector("button"), 1.42 + gDebuggee); 1.43 + }); 1.44 +} 1.45 + 1.46 +function testFirstWithScope() { 1.47 + let firstWithScope = gVariables.getScopeAtIndex(0); 1.48 + is(firstWithScope.expanded, true, 1.49 + "The first 'with' scope should be expanded by default."); 1.50 + ok(firstWithScope.target.querySelector(".name").getAttribute("value").contains("[Object]"), 1.51 + "The first 'with' scope should be properly identified."); 1.52 + 1.53 + let withEnums = firstWithScope._enum.childNodes; 1.54 + let withNonEnums = firstWithScope._nonenum.childNodes; 1.55 + 1.56 + is(withEnums.length, 3, 1.57 + "The first 'with' scope should contain all the created enumerable elements."); 1.58 + is(withNonEnums.length, 1, 1.59 + "The first 'with' scope should contain all the created non-enumerable elements."); 1.60 + 1.61 + is(withEnums[0].querySelector(".name").getAttribute("value"), "this", 1.62 + "Should have the right property name for 'this'."); 1.63 + is(withEnums[0].querySelector(".value").getAttribute("value"), 1.64 + "Window \u2192 doc_with-frame.html", 1.65 + "Should have the right property value for 'this'."); 1.66 + ok(withEnums[0].querySelector(".value").className.contains("token-other"), 1.67 + "Should have the right token class for 'this'."); 1.68 + 1.69 + is(withEnums[1].querySelector(".name").getAttribute("value"), "alpha", 1.70 + "Should have the right property name for 'alpha'."); 1.71 + is(withEnums[1].querySelector(".value").getAttribute("value"), "1", 1.72 + "Should have the right property value for 'alpha'."); 1.73 + ok(withEnums[1].querySelector(".value").className.contains("token-number"), 1.74 + "Should have the right token class for 'alpha'."); 1.75 + 1.76 + is(withEnums[2].querySelector(".name").getAttribute("value"), "beta", 1.77 + "Should have the right property name for 'beta'."); 1.78 + is(withEnums[2].querySelector(".value").getAttribute("value"), "2", 1.79 + "Should have the right property value for 'beta'."); 1.80 + ok(withEnums[2].querySelector(".value").className.contains("token-number"), 1.81 + "Should have the right token class for 'beta'."); 1.82 + 1.83 + is(withNonEnums[0].querySelector(".name").getAttribute("value"), "__proto__", 1.84 + "Should have the right property name for '__proto__'."); 1.85 + is(withNonEnums[0].querySelector(".value").getAttribute("value"), "Object", 1.86 + "Should have the right property value for '__proto__'."); 1.87 + ok(withNonEnums[0].querySelector(".value").className.contains("token-other"), 1.88 + "Should have the right token class for '__proto__'."); 1.89 +} 1.90 + 1.91 +function expandSecondWithScope() { 1.92 + let deferred = promise.defer(); 1.93 + 1.94 + let secondWithScope = gVariables.getScopeAtIndex(1); 1.95 + is(secondWithScope.expanded, false, 1.96 + "The second 'with' scope should not be expanded by default."); 1.97 + 1.98 + gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve); 1.99 + 1.100 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.101 + secondWithScope.target.querySelector(".name"), 1.102 + gDebugger); 1.103 + 1.104 + return deferred.promise; 1.105 +} 1.106 + 1.107 +function testSecondWithScope() { 1.108 + let secondWithScope = gVariables.getScopeAtIndex(1); 1.109 + is(secondWithScope.expanded, true, 1.110 + "The second 'with' scope should now be expanded."); 1.111 + ok(secondWithScope.target.querySelector(".name").getAttribute("value").contains("[Math]"), 1.112 + "The second 'with' scope should be properly identified."); 1.113 + 1.114 + let withEnums = secondWithScope._enum.childNodes; 1.115 + let withNonEnums = secondWithScope._nonenum.childNodes; 1.116 + 1.117 + is(withEnums.length, 0, 1.118 + "The second 'with' scope should contain all the created enumerable elements."); 1.119 + isnot(withNonEnums.length, 0, 1.120 + "The second 'with' scope should contain all the created non-enumerable elements."); 1.121 + 1.122 + is(secondWithScope.get("E").target.querySelector(".name").getAttribute("value"), "E", 1.123 + "Should have the right property name for 'E'."); 1.124 + is(secondWithScope.get("E").target.querySelector(".value").getAttribute("value"), "2.718281828459045", 1.125 + "Should have the right property value for 'E'."); 1.126 + ok(secondWithScope.get("E").target.querySelector(".value").className.contains("token-number"), 1.127 + "Should have the right token class for 'E'."); 1.128 + 1.129 + is(secondWithScope.get("PI").target.querySelector(".name").getAttribute("value"), "PI", 1.130 + "Should have the right property name for 'PI'."); 1.131 + is(secondWithScope.get("PI").target.querySelector(".value").getAttribute("value"), "3.141592653589793", 1.132 + "Should have the right property value for 'PI'."); 1.133 + ok(secondWithScope.get("PI").target.querySelector(".value").className.contains("token-number"), 1.134 + "Should have the right token class for 'PI'."); 1.135 + 1.136 + is(secondWithScope.get("random").target.querySelector(".name").getAttribute("value"), "random", 1.137 + "Should have the right property name for 'random'."); 1.138 + is(secondWithScope.get("random").target.querySelector(".value").getAttribute("value"), "random()", 1.139 + "Should have the right property value for 'random'."); 1.140 + ok(secondWithScope.get("random").target.querySelector(".value").className.contains("token-other"), 1.141 + "Should have the right token class for 'random'."); 1.142 + 1.143 + is(secondWithScope.get("__proto__").target.querySelector(".name").getAttribute("value"), "__proto__", 1.144 + "Should have the right property name for '__proto__'."); 1.145 + is(secondWithScope.get("__proto__").target.querySelector(".value").getAttribute("value"), "Object", 1.146 + "Should have the right property value for '__proto__'."); 1.147 + ok(secondWithScope.get("__proto__").target.querySelector(".value").className.contains("token-other"), 1.148 + "Should have the right token class for '__proto__'."); 1.149 +} 1.150 + 1.151 +function expandFunctionScope() { 1.152 + let funcScope = gVariables.getScopeAtIndex(2); 1.153 + is(funcScope.expanded, false, 1.154 + "The function scope shouldn't be expanded by default, but the " + 1.155 + "variables have been already fetched. This is how local scopes work."); 1.156 + 1.157 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.158 + funcScope.target.querySelector(".name"), 1.159 + gDebugger); 1.160 + 1.161 + return promise.resolve(null); 1.162 +} 1.163 + 1.164 +function testFunctionScope() { 1.165 + let funcScope = gVariables.getScopeAtIndex(2); 1.166 + is(funcScope.expanded, true, 1.167 + "The function scope should now be expanded."); 1.168 + ok(funcScope.target.querySelector(".name").getAttribute("value").contains("[test]"), 1.169 + "The function scope should be properly identified."); 1.170 + 1.171 + let funcEnums = funcScope._enum.childNodes; 1.172 + let funcNonEnums = funcScope._nonenum.childNodes; 1.173 + 1.174 + is(funcEnums.length, 6, 1.175 + "The function scope should contain all the created enumerable elements."); 1.176 + is(funcNonEnums.length, 0, 1.177 + "The function scope should contain all the created non-enumerable elements."); 1.178 + 1.179 + is(funcScope.get("aNumber").target.querySelector(".name").getAttribute("value"), "aNumber", 1.180 + "Should have the right property name for 'aNumber'."); 1.181 + is(funcScope.get("aNumber").target.querySelector(".value").getAttribute("value"), "10", 1.182 + "Should have the right property value for 'aNumber'."); 1.183 + ok(funcScope.get("aNumber").target.querySelector(".value").className.contains("token-number"), 1.184 + "Should have the right token class for 'aNumber'."); 1.185 + 1.186 + is(funcScope.get("a").target.querySelector(".name").getAttribute("value"), "a", 1.187 + "Should have the right property name for 'a'."); 1.188 + is(funcScope.get("a").target.querySelector(".value").getAttribute("value"), "314.1592653589793", 1.189 + "Should have the right property value for 'a'."); 1.190 + ok(funcScope.get("a").target.querySelector(".value").className.contains("token-number"), 1.191 + "Should have the right token class for 'a'."); 1.192 + 1.193 + is(funcScope.get("r").target.querySelector(".name").getAttribute("value"), "r", 1.194 + "Should have the right property name for 'r'."); 1.195 + is(funcScope.get("r").target.querySelector(".value").getAttribute("value"), "10", 1.196 + "Should have the right property value for 'r'."); 1.197 + ok(funcScope.get("r").target.querySelector(".value").className.contains("token-number"), 1.198 + "Should have the right token class for 'r'."); 1.199 + 1.200 + is(funcScope.get("foo").target.querySelector(".name").getAttribute("value"), "foo", 1.201 + "Should have the right property name for 'foo'."); 1.202 + is(funcScope.get("foo").target.querySelector(".value").getAttribute("value"), "6.283185307179586", 1.203 + "Should have the right property value for 'foo'."); 1.204 + ok(funcScope.get("foo").target.querySelector(".value").className.contains("token-number"), 1.205 + "Should have the right token class for 'foo'."); 1.206 +} 1.207 + 1.208 +registerCleanupFunction(function() { 1.209 + gTab = null; 1.210 + gDebuggee = null; 1.211 + gPanel = null; 1.212 + gDebugger = null; 1.213 + gVariables = null; 1.214 +});