browser/devtools/debugger/test/browser_dbg_watch-expressions-02.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 * Bug 727429: Test the debugger watch expressions.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_watch-expressions.html";
michael@0 9
michael@0 10 function test() {
michael@0 11 // Debug test slaves are a bit slow at this test.
michael@0 12 requestLongerTimeout(2);
michael@0 13
michael@0 14 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 15 let gWatch, gVariables;
michael@0 16
michael@0 17 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 18 gTab = aTab;
michael@0 19 gDebuggee = aDebuggee;
michael@0 20 gPanel = aPanel;
michael@0 21 gDebugger = gPanel.panelWin;
michael@0 22 gWatch = gDebugger.DebuggerView.WatchExpressions;
michael@0 23 gVariables = gDebugger.DebuggerView.Variables;
michael@0 24
michael@0 25 gDebugger.DebuggerView.toggleInstrumentsPane({ visible: true, animated: false });
michael@0 26
michael@0 27 waitForSourceShown(gPanel, ".html", 1)
michael@0 28 .then(() => addExpressions())
michael@0 29 .then(() => performTest())
michael@0 30 .then(() => finishTest())
michael@0 31 .then(() => closeDebuggerAndFinish(gPanel))
michael@0 32 .then(null, aError => {
michael@0 33 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 34 });
michael@0 35 });
michael@0 36
michael@0 37 function addExpressions() {
michael@0 38 gWatch.addExpression("'a'");
michael@0 39 gWatch.addExpression("\"a\"");
michael@0 40 gWatch.addExpression("'a\"\"'");
michael@0 41 gWatch.addExpression("\"a''\"");
michael@0 42 gWatch.addExpression("?");
michael@0 43 gWatch.addExpression("a");
michael@0 44 gWatch.addExpression("this");
michael@0 45 gWatch.addExpression("this.canada");
michael@0 46 gWatch.addExpression("[1, 2, 3]");
michael@0 47 gWatch.addExpression("x = [1, 2, 3]");
michael@0 48 gWatch.addExpression("y = [1, 2, 3]; y.test = 4");
michael@0 49 gWatch.addExpression("z = [1, 2, 3]; z.test = 4; z");
michael@0 50 gWatch.addExpression("t = [1, 2, 3]; t.test = 4; !t");
michael@0 51 gWatch.addExpression("arguments[0]");
michael@0 52 gWatch.addExpression("encodeURI(\"\\\")");
michael@0 53 gWatch.addExpression("decodeURI(\"\\\")");
michael@0 54 gWatch.addExpression("decodeURIComponent(\"%\")");
michael@0 55 gWatch.addExpression("//");
michael@0 56 gWatch.addExpression("// 42");
michael@0 57 gWatch.addExpression("{}.foo");
michael@0 58 gWatch.addExpression("{}.foo()");
michael@0 59 gWatch.addExpression("({}).foo()");
michael@0 60 gWatch.addExpression("new Array(-1)");
michael@0 61 gWatch.addExpression("4.2.toExponential(-4.2)");
michael@0 62 gWatch.addExpression("throw new Error(\"bazinga\")");
michael@0 63 gWatch.addExpression("({ get error() { throw new Error(\"bazinga\") } }).error");
michael@0 64 gWatch.addExpression("throw { get name() { throw \"bazinga\" } }");
michael@0 65 }
michael@0 66
michael@0 67 function performTest() {
michael@0 68 let deferred = promise.defer();
michael@0 69
michael@0 70 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 0,
michael@0 71 "There should be 0 hidden nodes in the watch expressions container");
michael@0 72 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 27,
michael@0 73 "There should be 27 visible nodes in the watch expressions container");
michael@0 74
michael@0 75 test1(function() {
michael@0 76 test2(function() {
michael@0 77 test3(function() {
michael@0 78 test4(function() {
michael@0 79 test5(function() {
michael@0 80 test6(function() {
michael@0 81 test7(function() {
michael@0 82 test8(function() {
michael@0 83 test9(function() {
michael@0 84 deferred.resolve();
michael@0 85 });
michael@0 86 });
michael@0 87 });
michael@0 88 });
michael@0 89 });
michael@0 90 });
michael@0 91 });
michael@0 92 });
michael@0 93 });
michael@0 94
michael@0 95 return deferred.promise;
michael@0 96 }
michael@0 97
michael@0 98 function finishTest() {
michael@0 99 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 0,
michael@0 100 "There should be 0 hidden nodes in the watch expressions container");
michael@0 101 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 27,
michael@0 102 "There should be 27 visible nodes in the watch expressions container");
michael@0 103 }
michael@0 104
michael@0 105 function test1(aCallback) {
michael@0 106 gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => {
michael@0 107 checkWatchExpressions(26, {
michael@0 108 a: "ReferenceError: a is not defined",
michael@0 109 this: { type: "object", class: "Object" },
michael@0 110 prop: { type: "object", class: "String" },
michael@0 111 args: { type: "undefined" }
michael@0 112 });
michael@0 113 aCallback();
michael@0 114 });
michael@0 115
michael@0 116 gDebuggee.test();
michael@0 117 }
michael@0 118
michael@0 119 function test2(aCallback) {
michael@0 120 gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => {
michael@0 121 checkWatchExpressions(26, {
michael@0 122 a: { type: "undefined" },
michael@0 123 this: { type: "object", class: "Window" },
michael@0 124 prop: { type: "undefined" },
michael@0 125 args: "sensational"
michael@0 126 });
michael@0 127 aCallback();
michael@0 128 });
michael@0 129
michael@0 130 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 131 gDebugger.document.getElementById("resume"),
michael@0 132 gDebugger);
michael@0 133 }
michael@0 134
michael@0 135 function test3(aCallback) {
michael@0 136 gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => {
michael@0 137 checkWatchExpressions(26, {
michael@0 138 a: { type: "object", class: "Object" },
michael@0 139 this: { type: "object", class: "Window" },
michael@0 140 prop: { type: "undefined" },
michael@0 141 args: "sensational"
michael@0 142 });
michael@0 143 aCallback();
michael@0 144 });
michael@0 145
michael@0 146 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 147 gDebugger.document.getElementById("resume"),
michael@0 148 gDebugger);
michael@0 149 }
michael@0 150
michael@0 151 function test4(aCallback) {
michael@0 152 gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => {
michael@0 153 checkWatchExpressions(27, {
michael@0 154 a: 5,
michael@0 155 this: { type: "object", class: "Window" },
michael@0 156 prop: { type: "undefined" },
michael@0 157 args: "sensational"
michael@0 158 });
michael@0 159 aCallback();
michael@0 160 });
michael@0 161
michael@0 162 gWatch.addExpression("a = 5");
michael@0 163 EventUtils.sendKey("RETURN", gDebugger);
michael@0 164 }
michael@0 165
michael@0 166 function test5(aCallback) {
michael@0 167 gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => {
michael@0 168 checkWatchExpressions(27, {
michael@0 169 a: 5,
michael@0 170 this: { type: "object", class: "Window" },
michael@0 171 prop: { type: "undefined" },
michael@0 172 args: "sensational"
michael@0 173 });
michael@0 174 aCallback();
michael@0 175 });
michael@0 176
michael@0 177 gWatch.addExpression("encodeURI(\"\\\")");
michael@0 178 EventUtils.sendKey("RETURN", gDebugger);
michael@0 179 }
michael@0 180
michael@0 181 function test6(aCallback) {
michael@0 182 gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => {
michael@0 183 checkWatchExpressions(27, {
michael@0 184 a: 5,
michael@0 185 this: { type: "object", class: "Window" },
michael@0 186 prop: { type: "undefined" },
michael@0 187 args: "sensational"
michael@0 188 });
michael@0 189 aCallback();
michael@0 190 })
michael@0 191
michael@0 192 gWatch.addExpression("decodeURI(\"\\\")");
michael@0 193 EventUtils.sendKey("RETURN", gDebugger);
michael@0 194 }
michael@0 195
michael@0 196 function test7(aCallback) {
michael@0 197 gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => {
michael@0 198 checkWatchExpressions(27, {
michael@0 199 a: 5,
michael@0 200 this: { type: "object", class: "Window" },
michael@0 201 prop: { type: "undefined" },
michael@0 202 args: "sensational"
michael@0 203 });
michael@0 204 aCallback();
michael@0 205 });
michael@0 206
michael@0 207 gWatch.addExpression("?");
michael@0 208 EventUtils.sendKey("RETURN", gDebugger);
michael@0 209 }
michael@0 210
michael@0 211 function test8(aCallback) {
michael@0 212 gDebugger.once(gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS, () => {
michael@0 213 checkWatchExpressions(27, {
michael@0 214 a: 5,
michael@0 215 this: { type: "object", class: "Window" },
michael@0 216 prop: { type: "undefined" },
michael@0 217 args: "sensational"
michael@0 218 });
michael@0 219 aCallback();
michael@0 220 });
michael@0 221
michael@0 222 gWatch.addExpression("a");
michael@0 223 EventUtils.sendKey("RETURN", gDebugger);
michael@0 224 }
michael@0 225
michael@0 226 function test9(aCallback) {
michael@0 227 gDebugger.once(gDebugger.EVENTS.AFTER_FRAMES_CLEARED, () => {
michael@0 228 aCallback();
michael@0 229 });
michael@0 230
michael@0 231 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 232 gDebugger.document.getElementById("resume"),
michael@0 233 gDebugger);
michael@0 234 }
michael@0 235
michael@0 236 function checkWatchExpressions(aTotal, aExpectedExpressions) {
michael@0 237 let {
michael@0 238 a: expected_a,
michael@0 239 this: expected_this,
michael@0 240 prop: expected_prop,
michael@0 241 args: expected_args
michael@0 242 } = aExpectedExpressions;
michael@0 243
michael@0 244 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, aTotal,
michael@0 245 "There should be " + aTotal + " hidden nodes in the watch expressions container.");
michael@0 246 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 0,
michael@0 247 "There should be 0 visible nodes in the watch expressions container.");
michael@0 248
michael@0 249 let label = gDebugger.L10N.getStr("watchExpressionsScopeLabel");
michael@0 250 let scope = gVariables._currHierarchy.get(label);
michael@0 251
michael@0 252 ok(scope, "There should be a wach expressions scope in the variables view.");
michael@0 253 is(scope._store.size, aTotal, "There should be " + aTotal + " evaluations availalble.");
michael@0 254
michael@0 255 let w1 = scope.get("'a'");
michael@0 256 let w2 = scope.get("\"a\"");
michael@0 257 let w3 = scope.get("'a\"\"'");
michael@0 258 let w4 = scope.get("\"a''\"");
michael@0 259 let w5 = scope.get("?");
michael@0 260 let w6 = scope.get("a");
michael@0 261 let w7 = scope.get("this");
michael@0 262 let w8 = scope.get("this.canada");
michael@0 263 let w9 = scope.get("[1, 2, 3]");
michael@0 264 let w10 = scope.get("x = [1, 2, 3]");
michael@0 265 let w11 = scope.get("y = [1, 2, 3]; y.test = 4");
michael@0 266 let w12 = scope.get("z = [1, 2, 3]; z.test = 4; z");
michael@0 267 let w13 = scope.get("t = [1, 2, 3]; t.test = 4; !t");
michael@0 268 let w14 = scope.get("arguments[0]");
michael@0 269 let w15 = scope.get("encodeURI(\"\\\")");
michael@0 270 let w16 = scope.get("decodeURI(\"\\\")");
michael@0 271 let w17 = scope.get("decodeURIComponent(\"%\")");
michael@0 272 let w18 = scope.get("//");
michael@0 273 let w19 = scope.get("// 42");
michael@0 274 let w20 = scope.get("{}.foo");
michael@0 275 let w21 = scope.get("{}.foo()");
michael@0 276 let w22 = scope.get("({}).foo()");
michael@0 277 let w23 = scope.get("new Array(-1)");
michael@0 278 let w24 = scope.get("4.2.toExponential(-4.2)");
michael@0 279 let w25 = scope.get("throw new Error(\"bazinga\")");
michael@0 280 let w26 = scope.get("({ get error() { throw new Error(\"bazinga\") } }).error");
michael@0 281 let w27 = scope.get("throw { get name() { throw \"bazinga\" } }");
michael@0 282
michael@0 283 ok(w1, "The first watch expression should be present in the scope.");
michael@0 284 ok(w2, "The second watch expression should be present in the scope.");
michael@0 285 ok(w3, "The third watch expression should be present in the scope.");
michael@0 286 ok(w4, "The fourth watch expression should be present in the scope.");
michael@0 287 ok(w5, "The fifth watch expression should be present in the scope.");
michael@0 288 ok(w6, "The sixth watch expression should be present in the scope.");
michael@0 289 ok(w7, "The seventh watch expression should be present in the scope.");
michael@0 290 ok(w8, "The eight watch expression should be present in the scope.");
michael@0 291 ok(w9, "The ninth watch expression should be present in the scope.");
michael@0 292 ok(w10, "The tenth watch expression should be present in the scope.");
michael@0 293 ok(w11, "The eleventh watch expression should be present in the scope.");
michael@0 294 ok(w12, "The twelfth watch expression should be present in the scope.");
michael@0 295 ok(w13, "The 13th watch expression should be present in the scope.");
michael@0 296 ok(w14, "The 14th watch expression should be present in the scope.");
michael@0 297 ok(w15, "The 15th watch expression should be present in the scope.");
michael@0 298 ok(w16, "The 16th watch expression should be present in the scope.");
michael@0 299 ok(w17, "The 17th watch expression should be present in the scope.");
michael@0 300 ok(w18, "The 18th watch expression should be present in the scope.");
michael@0 301 ok(w19, "The 19th watch expression should be present in the scope.");
michael@0 302 ok(w20, "The 20th watch expression should be present in the scope.");
michael@0 303 ok(w21, "The 21st watch expression should be present in the scope.");
michael@0 304 ok(w22, "The 22nd watch expression should be present in the scope.");
michael@0 305 ok(w23, "The 23nd watch expression should be present in the scope.");
michael@0 306 ok(w24, "The 24th watch expression should be present in the scope.");
michael@0 307 ok(w25, "The 25th watch expression should be present in the scope.");
michael@0 308 ok(w26, "The 26th watch expression should be present in the scope.");
michael@0 309 ok(!w27, "The 27th watch expression should not be present in the scope.");
michael@0 310
michael@0 311 is(w1.value, "a", "The first value is correct.");
michael@0 312 is(w2.value, "a", "The second value is correct.");
michael@0 313 is(w3.value, "a\"\"", "The third value is correct.");
michael@0 314 is(w4.value, "a''", "The fourth value is correct.");
michael@0 315 is(w5.value, "SyntaxError: syntax error", "The fifth value is correct.");
michael@0 316
michael@0 317 if (typeof expected_a == "object") {
michael@0 318 is(w6.value.type, expected_a.type, "The sixth value type is correct.");
michael@0 319 is(w6.value.class, expected_a.class, "The sixth value class is correct.");
michael@0 320 } else {
michael@0 321 is(w6.value, expected_a, "The sixth value is correct.");
michael@0 322 }
michael@0 323
michael@0 324 if (typeof expected_this == "object") {
michael@0 325 is(w7.value.type, expected_this.type, "The seventh value type is correct.");
michael@0 326 is(w7.value.class, expected_this.class, "The seventh value class is correct.");
michael@0 327 } else {
michael@0 328 is(w7.value, expected_this, "The seventh value is correct.");
michael@0 329 }
michael@0 330
michael@0 331 if (typeof expected_prop == "object") {
michael@0 332 is(w8.value.type, expected_prop.type, "The eighth value type is correct.");
michael@0 333 is(w8.value.class, expected_prop.class, "The eighth value class is correct.");
michael@0 334 } else {
michael@0 335 is(w8.value, expected_prop, "The eighth value is correct.");
michael@0 336 }
michael@0 337
michael@0 338 is(w9.value.type, "object", "The ninth value type is correct.");
michael@0 339 is(w9.value.class, "Array", "The ninth value class is correct.");
michael@0 340 is(w10.value.type, "object", "The tenth value type is correct.");
michael@0 341 is(w10.value.class, "Array", "The tenth value class is correct.");
michael@0 342 is(w11.value, "4", "The eleventh value is correct.");
michael@0 343 is(w12.value.type, "object", "The eleventh value type is correct.");
michael@0 344 is(w12.value.class, "Array", "The twelfth value class is correct.");
michael@0 345 is(w13.value, false, "The 13th value is correct.");
michael@0 346
michael@0 347 if (typeof expected_args == "object") {
michael@0 348 is(w14.value.type, expected_args.type, "The 14th value type is correct.");
michael@0 349 is(w14.value.class, expected_args.class, "The 14th value class is correct.");
michael@0 350 } else {
michael@0 351 is(w14.value, expected_args, "The 14th value is correct.");
michael@0 352 }
michael@0 353
michael@0 354 is(w15.value, "SyntaxError: unterminated string literal", "The 15th value is correct.");
michael@0 355 is(w16.value, "SyntaxError: unterminated string literal", "The 16th value is correct.");
michael@0 356 is(w17.value, "URIError: malformed URI sequence", "The 17th value is correct.");
michael@0 357
michael@0 358 is(w18.value.type, "undefined", "The 18th value type is correct.");
michael@0 359 is(w18.value.class, undefined, "The 18th value class is correct.");
michael@0 360
michael@0 361 is(w19.value.type, "undefined", "The 19th value type is correct.");
michael@0 362 is(w19.value.class, undefined, "The 19th value class is correct.");
michael@0 363
michael@0 364 is(w20.value, "SyntaxError: syntax error", "The 20th value is correct.");
michael@0 365 is(w21.value, "SyntaxError: syntax error", "The 21th value is correct.");
michael@0 366 is(w22.value, "TypeError: (intermediate value).foo is not a function", "The 22th value is correct.");
michael@0 367 is(w23.value, "RangeError: invalid array length", "The 23th value is correct.");
michael@0 368 is(w24.value, "RangeError: precision -4 out of range", "The 24th value is correct.");
michael@0 369 is(w25.value, "Error: bazinga", "The 25th value is correct.");
michael@0 370 is(w26.value, "Error: bazinga", "The 26th value is correct.");
michael@0 371 }
michael@0 372 }

mercurial