1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_watch-expressions-02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,372 @@ 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 + * Bug 727429: Test the debugger watch expressions. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_watch-expressions.html"; 1.12 + 1.13 +function test() { 1.14 + // Debug test slaves are a bit slow at this test. 1.15 + requestLongerTimeout(2); 1.16 + 1.17 + let gTab, gDebuggee, gPanel, gDebugger; 1.18 + let gWatch, gVariables; 1.19 + 1.20 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.21 + gTab = aTab; 1.22 + gDebuggee = aDebuggee; 1.23 + gPanel = aPanel; 1.24 + gDebugger = gPanel.panelWin; 1.25 + gWatch = gDebugger.DebuggerView.WatchExpressions; 1.26 + gVariables = gDebugger.DebuggerView.Variables; 1.27 + 1.28 + gDebugger.DebuggerView.toggleInstrumentsPane({ visible: true, animated: false }); 1.29 + 1.30 + waitForSourceShown(gPanel, ".html", 1) 1.31 + .then(() => addExpressions()) 1.32 + .then(() => performTest()) 1.33 + .then(() => finishTest()) 1.34 + .then(() => closeDebuggerAndFinish(gPanel)) 1.35 + .then(null, aError => { 1.36 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.37 + }); 1.38 + }); 1.39 + 1.40 + function addExpressions() { 1.41 + gWatch.addExpression("'a'"); 1.42 + gWatch.addExpression("\"a\""); 1.43 + gWatch.addExpression("'a\"\"'"); 1.44 + gWatch.addExpression("\"a''\""); 1.45 + gWatch.addExpression("?"); 1.46 + gWatch.addExpression("a"); 1.47 + gWatch.addExpression("this"); 1.48 + gWatch.addExpression("this.canada"); 1.49 + gWatch.addExpression("[1, 2, 3]"); 1.50 + gWatch.addExpression("x = [1, 2, 3]"); 1.51 + gWatch.addExpression("y = [1, 2, 3]; y.test = 4"); 1.52 + gWatch.addExpression("z = [1, 2, 3]; z.test = 4; z"); 1.53 + gWatch.addExpression("t = [1, 2, 3]; t.test = 4; !t"); 1.54 + gWatch.addExpression("arguments[0]"); 1.55 + gWatch.addExpression("encodeURI(\"\\\")"); 1.56 + gWatch.addExpression("decodeURI(\"\\\")"); 1.57 + gWatch.addExpression("decodeURIComponent(\"%\")"); 1.58 + gWatch.addExpression("//"); 1.59 + gWatch.addExpression("// 42"); 1.60 + gWatch.addExpression("{}.foo"); 1.61 + gWatch.addExpression("{}.foo()"); 1.62 + gWatch.addExpression("({}).foo()"); 1.63 + gWatch.addExpression("new Array(-1)"); 1.64 + gWatch.addExpression("4.2.toExponential(-4.2)"); 1.65 + gWatch.addExpression("throw new Error(\"bazinga\")"); 1.66 + gWatch.addExpression("({ get error() { throw new Error(\"bazinga\") } }).error"); 1.67 + gWatch.addExpression("throw { get name() { throw \"bazinga\" } }"); 1.68 + } 1.69 + 1.70 + function performTest() { 1.71 + let deferred = promise.defer(); 1.72 + 1.73 + is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 0, 1.74 + "There should be 0 hidden nodes in the watch expressions container"); 1.75 + is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 27, 1.76 + "There should be 27 visible nodes in the watch expressions container"); 1.77 + 1.78 + test1(function() { 1.79 + test2(function() { 1.80 + test3(function() { 1.81 + test4(function() { 1.82 + test5(function() { 1.83 + test6(function() { 1.84 + test7(function() { 1.85 + test8(function() { 1.86 + test9(function() { 1.87 + deferred.resolve(); 1.88 + }); 1.89 + }); 1.90 + }); 1.91 + }); 1.92 + }); 1.93 + }); 1.94 + }); 1.95 + }); 1.96 + }); 1.97 + 1.98 + return deferred.promise; 1.99 + } 1.100 + 1.101 + function finishTest() { 1.102 + is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 0, 1.103 + "There should be 0 hidden nodes in the watch expressions container"); 1.104 + is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 27, 1.105 + "There should be 27 visible nodes in the watch expressions container"); 1.106 + } 1.107 + 1.108 + function test1(aCallback) { 1.109 + gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => { 1.110 + checkWatchExpressions(26, { 1.111 + a: "ReferenceError: a is not defined", 1.112 + this: { type: "object", class: "Object" }, 1.113 + prop: { type: "object", class: "String" }, 1.114 + args: { type: "undefined" } 1.115 + }); 1.116 + aCallback(); 1.117 + }); 1.118 + 1.119 + gDebuggee.test(); 1.120 + } 1.121 + 1.122 + function test2(aCallback) { 1.123 + gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => { 1.124 + checkWatchExpressions(26, { 1.125 + a: { type: "undefined" }, 1.126 + this: { type: "object", class: "Window" }, 1.127 + prop: { type: "undefined" }, 1.128 + args: "sensational" 1.129 + }); 1.130 + aCallback(); 1.131 + }); 1.132 + 1.133 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.134 + gDebugger.document.getElementById("resume"), 1.135 + gDebugger); 1.136 + } 1.137 + 1.138 + function test3(aCallback) { 1.139 + gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => { 1.140 + checkWatchExpressions(26, { 1.141 + a: { type: "object", class: "Object" }, 1.142 + this: { type: "object", class: "Window" }, 1.143 + prop: { type: "undefined" }, 1.144 + args: "sensational" 1.145 + }); 1.146 + aCallback(); 1.147 + }); 1.148 + 1.149 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.150 + gDebugger.document.getElementById("resume"), 1.151 + gDebugger); 1.152 + } 1.153 + 1.154 + function test4(aCallback) { 1.155 + gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => { 1.156 + checkWatchExpressions(27, { 1.157 + a: 5, 1.158 + this: { type: "object", class: "Window" }, 1.159 + prop: { type: "undefined" }, 1.160 + args: "sensational" 1.161 + }); 1.162 + aCallback(); 1.163 + }); 1.164 + 1.165 + gWatch.addExpression("a = 5"); 1.166 + EventUtils.sendKey("RETURN", gDebugger); 1.167 + } 1.168 + 1.169 + function test5(aCallback) { 1.170 + gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => { 1.171 + checkWatchExpressions(27, { 1.172 + a: 5, 1.173 + this: { type: "object", class: "Window" }, 1.174 + prop: { type: "undefined" }, 1.175 + args: "sensational" 1.176 + }); 1.177 + aCallback(); 1.178 + }); 1.179 + 1.180 + gWatch.addExpression("encodeURI(\"\\\")"); 1.181 + EventUtils.sendKey("RETURN", gDebugger); 1.182 + } 1.183 + 1.184 + function test6(aCallback) { 1.185 + gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => { 1.186 + checkWatchExpressions(27, { 1.187 + a: 5, 1.188 + this: { type: "object", class: "Window" }, 1.189 + prop: { type: "undefined" }, 1.190 + args: "sensational" 1.191 + }); 1.192 + aCallback(); 1.193 + }) 1.194 + 1.195 + gWatch.addExpression("decodeURI(\"\\\")"); 1.196 + EventUtils.sendKey("RETURN", gDebugger); 1.197 + } 1.198 + 1.199 + function test7(aCallback) { 1.200 + gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => { 1.201 + checkWatchExpressions(27, { 1.202 + a: 5, 1.203 + this: { type: "object", class: "Window" }, 1.204 + prop: { type: "undefined" }, 1.205 + args: "sensational" 1.206 + }); 1.207 + aCallback(); 1.208 + }); 1.209 + 1.210 + gWatch.addExpression("?"); 1.211 + EventUtils.sendKey("RETURN", gDebugger); 1.212 + } 1.213 + 1.214 + function test8(aCallback) { 1.215 + gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => { 1.216 + checkWatchExpressions(27, { 1.217 + a: 5, 1.218 + this: { type: "object", class: "Window" }, 1.219 + prop: { type: "undefined" }, 1.220 + args: "sensational" 1.221 + }); 1.222 + aCallback(); 1.223 + }); 1.224 + 1.225 + gWatch.addExpression("a"); 1.226 + EventUtils.sendKey("RETURN", gDebugger); 1.227 + } 1.228 + 1.229 + function test9(aCallback) { 1.230 + gDebugger.once(gDebugger.EVENTS.AFTER_FRAMES_CLEARED, () => { 1.231 + aCallback(); 1.232 + }); 1.233 + 1.234 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.235 + gDebugger.document.getElementById("resume"), 1.236 + gDebugger); 1.237 + } 1.238 + 1.239 + function checkWatchExpressions(aTotal, aExpectedExpressions) { 1.240 + let { 1.241 + a: expected_a, 1.242 + this: expected_this, 1.243 + prop: expected_prop, 1.244 + args: expected_args 1.245 + } = aExpectedExpressions; 1.246 + 1.247 + is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, aTotal, 1.248 + "There should be " + aTotal + " hidden nodes in the watch expressions container."); 1.249 + is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 0, 1.250 + "There should be 0 visible nodes in the watch expressions container."); 1.251 + 1.252 + let label = gDebugger.L10N.getStr("watchExpressionsScopeLabel"); 1.253 + let scope = gVariables._currHierarchy.get(label); 1.254 + 1.255 + ok(scope, "There should be a wach expressions scope in the variables view."); 1.256 + is(scope._store.size, aTotal, "There should be " + aTotal + " evaluations availalble."); 1.257 + 1.258 + let w1 = scope.get("'a'"); 1.259 + let w2 = scope.get("\"a\""); 1.260 + let w3 = scope.get("'a\"\"'"); 1.261 + let w4 = scope.get("\"a''\""); 1.262 + let w5 = scope.get("?"); 1.263 + let w6 = scope.get("a"); 1.264 + let w7 = scope.get("this"); 1.265 + let w8 = scope.get("this.canada"); 1.266 + let w9 = scope.get("[1, 2, 3]"); 1.267 + let w10 = scope.get("x = [1, 2, 3]"); 1.268 + let w11 = scope.get("y = [1, 2, 3]; y.test = 4"); 1.269 + let w12 = scope.get("z = [1, 2, 3]; z.test = 4; z"); 1.270 + let w13 = scope.get("t = [1, 2, 3]; t.test = 4; !t"); 1.271 + let w14 = scope.get("arguments[0]"); 1.272 + let w15 = scope.get("encodeURI(\"\\\")"); 1.273 + let w16 = scope.get("decodeURI(\"\\\")"); 1.274 + let w17 = scope.get("decodeURIComponent(\"%\")"); 1.275 + let w18 = scope.get("//"); 1.276 + let w19 = scope.get("// 42"); 1.277 + let w20 = scope.get("{}.foo"); 1.278 + let w21 = scope.get("{}.foo()"); 1.279 + let w22 = scope.get("({}).foo()"); 1.280 + let w23 = scope.get("new Array(-1)"); 1.281 + let w24 = scope.get("4.2.toExponential(-4.2)"); 1.282 + let w25 = scope.get("throw new Error(\"bazinga\")"); 1.283 + let w26 = scope.get("({ get error() { throw new Error(\"bazinga\") } }).error"); 1.284 + let w27 = scope.get("throw { get name() { throw \"bazinga\" } }"); 1.285 + 1.286 + ok(w1, "The first watch expression should be present in the scope."); 1.287 + ok(w2, "The second watch expression should be present in the scope."); 1.288 + ok(w3, "The third watch expression should be present in the scope."); 1.289 + ok(w4, "The fourth watch expression should be present in the scope."); 1.290 + ok(w5, "The fifth watch expression should be present in the scope."); 1.291 + ok(w6, "The sixth watch expression should be present in the scope."); 1.292 + ok(w7, "The seventh watch expression should be present in the scope."); 1.293 + ok(w8, "The eight watch expression should be present in the scope."); 1.294 + ok(w9, "The ninth watch expression should be present in the scope."); 1.295 + ok(w10, "The tenth watch expression should be present in the scope."); 1.296 + ok(w11, "The eleventh watch expression should be present in the scope."); 1.297 + ok(w12, "The twelfth watch expression should be present in the scope."); 1.298 + ok(w13, "The 13th watch expression should be present in the scope."); 1.299 + ok(w14, "The 14th watch expression should be present in the scope."); 1.300 + ok(w15, "The 15th watch expression should be present in the scope."); 1.301 + ok(w16, "The 16th watch expression should be present in the scope."); 1.302 + ok(w17, "The 17th watch expression should be present in the scope."); 1.303 + ok(w18, "The 18th watch expression should be present in the scope."); 1.304 + ok(w19, "The 19th watch expression should be present in the scope."); 1.305 + ok(w20, "The 20th watch expression should be present in the scope."); 1.306 + ok(w21, "The 21st watch expression should be present in the scope."); 1.307 + ok(w22, "The 22nd watch expression should be present in the scope."); 1.308 + ok(w23, "The 23nd watch expression should be present in the scope."); 1.309 + ok(w24, "The 24th watch expression should be present in the scope."); 1.310 + ok(w25, "The 25th watch expression should be present in the scope."); 1.311 + ok(w26, "The 26th watch expression should be present in the scope."); 1.312 + ok(!w27, "The 27th watch expression should not be present in the scope."); 1.313 + 1.314 + is(w1.value, "a", "The first value is correct."); 1.315 + is(w2.value, "a", "The second value is correct."); 1.316 + is(w3.value, "a\"\"", "The third value is correct."); 1.317 + is(w4.value, "a''", "The fourth value is correct."); 1.318 + is(w5.value, "SyntaxError: syntax error", "The fifth value is correct."); 1.319 + 1.320 + if (typeof expected_a == "object") { 1.321 + is(w6.value.type, expected_a.type, "The sixth value type is correct."); 1.322 + is(w6.value.class, expected_a.class, "The sixth value class is correct."); 1.323 + } else { 1.324 + is(w6.value, expected_a, "The sixth value is correct."); 1.325 + } 1.326 + 1.327 + if (typeof expected_this == "object") { 1.328 + is(w7.value.type, expected_this.type, "The seventh value type is correct."); 1.329 + is(w7.value.class, expected_this.class, "The seventh value class is correct."); 1.330 + } else { 1.331 + is(w7.value, expected_this, "The seventh value is correct."); 1.332 + } 1.333 + 1.334 + if (typeof expected_prop == "object") { 1.335 + is(w8.value.type, expected_prop.type, "The eighth value type is correct."); 1.336 + is(w8.value.class, expected_prop.class, "The eighth value class is correct."); 1.337 + } else { 1.338 + is(w8.value, expected_prop, "The eighth value is correct."); 1.339 + } 1.340 + 1.341 + is(w9.value.type, "object", "The ninth value type is correct."); 1.342 + is(w9.value.class, "Array", "The ninth value class is correct."); 1.343 + is(w10.value.type, "object", "The tenth value type is correct."); 1.344 + is(w10.value.class, "Array", "The tenth value class is correct."); 1.345 + is(w11.value, "4", "The eleventh value is correct."); 1.346 + is(w12.value.type, "object", "The eleventh value type is correct."); 1.347 + is(w12.value.class, "Array", "The twelfth value class is correct."); 1.348 + is(w13.value, false, "The 13th value is correct."); 1.349 + 1.350 + if (typeof expected_args == "object") { 1.351 + is(w14.value.type, expected_args.type, "The 14th value type is correct."); 1.352 + is(w14.value.class, expected_args.class, "The 14th value class is correct."); 1.353 + } else { 1.354 + is(w14.value, expected_args, "The 14th value is correct."); 1.355 + } 1.356 + 1.357 + is(w15.value, "SyntaxError: unterminated string literal", "The 15th value is correct."); 1.358 + is(w16.value, "SyntaxError: unterminated string literal", "The 16th value is correct."); 1.359 + is(w17.value, "URIError: malformed URI sequence", "The 17th value is correct."); 1.360 + 1.361 + is(w18.value.type, "undefined", "The 18th value type is correct."); 1.362 + is(w18.value.class, undefined, "The 18th value class is correct."); 1.363 + 1.364 + is(w19.value.type, "undefined", "The 19th value type is correct."); 1.365 + is(w19.value.class, undefined, "The 19th value class is correct."); 1.366 + 1.367 + is(w20.value, "SyntaxError: syntax error", "The 20th value is correct."); 1.368 + is(w21.value, "SyntaxError: syntax error", "The 21th value is correct."); 1.369 + is(w22.value, "TypeError: (intermediate value).foo is not a function", "The 22th value is correct."); 1.370 + is(w23.value, "RangeError: invalid array length", "The 23th value is correct."); 1.371 + is(w24.value, "RangeError: precision -4 out of range", "The 24th value is correct."); 1.372 + is(w25.value, "Error: bazinga", "The 25th value is correct."); 1.373 + is(w26.value, "Error: bazinga", "The 26th value is correct."); 1.374 + } 1.375 +}