Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | const TEST_URI = "http://example.com/browser/dom/tests/browser/test-console-api.html"; |
michael@0 | 7 | |
michael@0 | 8 | var gWindow, gLevel, gArgs, gTestDriver, gStyle; |
michael@0 | 9 | |
michael@0 | 10 | function test() { |
michael@0 | 11 | waitForExplicitFinish(); |
michael@0 | 12 | |
michael@0 | 13 | var tab = gBrowser.addTab(TEST_URI); |
michael@0 | 14 | gBrowser.selectedTab = tab; |
michael@0 | 15 | var browser = gBrowser.selectedBrowser; |
michael@0 | 16 | |
michael@0 | 17 | registerCleanupFunction(function () { |
michael@0 | 18 | gWindow = gLevel = gArgs = gTestDriver = null; |
michael@0 | 19 | gBrowser.removeTab(tab); |
michael@0 | 20 | }); |
michael@0 | 21 | |
michael@0 | 22 | ConsoleObserver.init(); |
michael@0 | 23 | |
michael@0 | 24 | browser.addEventListener("DOMContentLoaded", function onLoad(event) { |
michael@0 | 25 | browser.removeEventListener("DOMContentLoaded", onLoad, false); |
michael@0 | 26 | executeSoon(function test_executeSoon() { |
michael@0 | 27 | gWindow = browser.contentWindow; |
michael@0 | 28 | consoleAPISanityTest(); |
michael@0 | 29 | gTestDriver = observeConsoleTest(); |
michael@0 | 30 | gTestDriver.next(); |
michael@0 | 31 | }); |
michael@0 | 32 | |
michael@0 | 33 | }, false); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function testConsoleData(aMessageObject) { |
michael@0 | 37 | let messageWindow = Services.wm.getOuterWindowWithId(aMessageObject.ID); |
michael@0 | 38 | is(messageWindow, gWindow, "found correct window by window ID"); |
michael@0 | 39 | |
michael@0 | 40 | is(aMessageObject.level, gLevel, "expected level received"); |
michael@0 | 41 | ok(aMessageObject.arguments, "we have arguments"); |
michael@0 | 42 | |
michael@0 | 43 | switch (gLevel) { |
michael@0 | 44 | case "trace": { |
michael@0 | 45 | is(aMessageObject.arguments.length, 0, "arguments.length matches"); |
michael@0 | 46 | is(aMessageObject.stacktrace.toSource(), gArgs.toSource(), |
michael@0 | 47 | "stack trace is correct"); |
michael@0 | 48 | break |
michael@0 | 49 | } |
michael@0 | 50 | case "count": { |
michael@0 | 51 | is(aMessageObject.counter.label, gArgs[0].label, "label matches"); |
michael@0 | 52 | is(aMessageObject.counter.count, gArgs[0].count, "count matches"); |
michael@0 | 53 | break; |
michael@0 | 54 | } |
michael@0 | 55 | default: { |
michael@0 | 56 | is(aMessageObject.arguments.length, gArgs.length, "arguments.length matches"); |
michael@0 | 57 | gArgs.forEach(function (a, i) { |
michael@0 | 58 | // Waive Xray so that we don't get messed up by Xray ToString. |
michael@0 | 59 | // |
michael@0 | 60 | // It'd be nice to just use XPCNativeWrapper.unwrap here, but there are |
michael@0 | 61 | // a number of dumb reasons we can't. See bug 868675. |
michael@0 | 62 | var arg = aMessageObject.arguments[i]; |
michael@0 | 63 | if (Components.utils.isXrayWrapper(arg)) |
michael@0 | 64 | arg = arg.wrappedJSObject; |
michael@0 | 65 | is(arg, a, "correct arg " + i); |
michael@0 | 66 | }); |
michael@0 | 67 | |
michael@0 | 68 | if (gStyle) { |
michael@0 | 69 | is(aMessageObject.styles.length, gStyle.length, "styles.length matches"); |
michael@0 | 70 | is(aMessageObject.styles + "", gStyle + "", "styles match"); |
michael@0 | 71 | } else { |
michael@0 | 72 | ok(!aMessageObject.styles || aMessageObject.styles.length === 0, |
michael@0 | 73 | "styles match"); |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | gTestDriver.next(); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function testLocationData(aMessageObject) { |
michael@0 | 82 | let messageWindow = Services.wm.getOuterWindowWithId(aMessageObject.ID); |
michael@0 | 83 | is(messageWindow, gWindow, "found correct window by window ID"); |
michael@0 | 84 | |
michael@0 | 85 | is(aMessageObject.level, gLevel, "expected level received"); |
michael@0 | 86 | ok(aMessageObject.arguments, "we have arguments"); |
michael@0 | 87 | |
michael@0 | 88 | is(aMessageObject.filename, gArgs[0].filename, "filename matches"); |
michael@0 | 89 | is(aMessageObject.lineNumber, gArgs[0].lineNumber, "lineNumber matches"); |
michael@0 | 90 | is(aMessageObject.functionName, gArgs[0].functionName, "functionName matches"); |
michael@0 | 91 | is(aMessageObject.arguments.length, gArgs[0].arguments.length, "arguments.length matches"); |
michael@0 | 92 | gArgs[0].arguments.forEach(function (a, i) { |
michael@0 | 93 | is(aMessageObject.arguments[i], a, "correct arg " + i); |
michael@0 | 94 | }); |
michael@0 | 95 | |
michael@0 | 96 | startNativeCallbackTest(); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function startNativeCallbackTest() { |
michael@0 | 100 | // Reset the observer function to cope with the fabricated test data. |
michael@0 | 101 | ConsoleObserver.observe = function CO_observe(aSubject, aTopic, aData) { |
michael@0 | 102 | try { |
michael@0 | 103 | testNativeCallback(aSubject.wrappedJSObject); |
michael@0 | 104 | } catch (ex) { |
michael@0 | 105 | // XXX Bug 906593 - Exceptions in this function currently aren't |
michael@0 | 106 | // reported, because of some XPConnect weirdness, so report them manually |
michael@0 | 107 | ok(false, "Exception thrown in CO_observe: " + ex); |
michael@0 | 108 | } |
michael@0 | 109 | }; |
michael@0 | 110 | |
michael@0 | 111 | let button = gWindow.document.getElementById("test-nativeCallback"); |
michael@0 | 112 | ok(button, "found #test-nativeCallback button"); |
michael@0 | 113 | EventUtils.synthesizeMouseAtCenter(button, {}, gWindow); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function testNativeCallback(aMessageObject) { |
michael@0 | 117 | is(aMessageObject.level, "log", "expected level received"); |
michael@0 | 118 | is(aMessageObject.filename, "", "filename matches"); |
michael@0 | 119 | is(aMessageObject.lineNumber, 0, "lineNumber matches"); |
michael@0 | 120 | is(aMessageObject.functionName, "", "functionName matches"); |
michael@0 | 121 | |
michael@0 | 122 | startGroupTest(); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | function startGroupTest() { |
michael@0 | 126 | // Reset the observer function to cope with the fabricated test data. |
michael@0 | 127 | ConsoleObserver.observe = function CO_observe(aSubject, aTopic, aData) { |
michael@0 | 128 | try { |
michael@0 | 129 | testConsoleGroup(aSubject.wrappedJSObject); |
michael@0 | 130 | } catch (ex) { |
michael@0 | 131 | // XXX Bug 906593 - Exceptions in this function currently aren't |
michael@0 | 132 | // reported, because of some XPConnect weirdness, so report them manually |
michael@0 | 133 | ok(false, "Exception thrown in CO_observe: " + ex); |
michael@0 | 134 | } |
michael@0 | 135 | }; |
michael@0 | 136 | let button = gWindow.document.getElementById("test-groups"); |
michael@0 | 137 | ok(button, "found #test-groups button"); |
michael@0 | 138 | EventUtils.synthesizeMouseAtCenter(button, {}, gWindow); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | function testConsoleGroup(aMessageObject) { |
michael@0 | 142 | let messageWindow = Services.wm.getOuterWindowWithId(aMessageObject.ID); |
michael@0 | 143 | is(messageWindow, gWindow, "found correct window by window ID"); |
michael@0 | 144 | |
michael@0 | 145 | ok(aMessageObject.level == "group" || |
michael@0 | 146 | aMessageObject.level == "groupCollapsed" || |
michael@0 | 147 | aMessageObject.level == "groupEnd", |
michael@0 | 148 | "expected level received"); |
michael@0 | 149 | |
michael@0 | 150 | is(aMessageObject.functionName, "testGroups", "functionName matches"); |
michael@0 | 151 | ok(aMessageObject.lineNumber >= 46 && aMessageObject.lineNumber <= 50, |
michael@0 | 152 | "lineNumber matches"); |
michael@0 | 153 | if (aMessageObject.level == "groupCollapsed") { |
michael@0 | 154 | is(aMessageObject.groupName, "a group", "groupCollapsed groupName matches"); |
michael@0 | 155 | is(aMessageObject.arguments[0], "a", "groupCollapsed arguments[0] matches"); |
michael@0 | 156 | is(aMessageObject.arguments[1], "group", "groupCollapsed arguments[0] matches"); |
michael@0 | 157 | } |
michael@0 | 158 | else if (aMessageObject.level == "group") { |
michael@0 | 159 | is(aMessageObject.groupName, "b group", "group groupName matches"); |
michael@0 | 160 | is(aMessageObject.arguments[0], "b", "group arguments[0] matches"); |
michael@0 | 161 | is(aMessageObject.arguments[1], "group", "group arguments[1] matches"); |
michael@0 | 162 | } |
michael@0 | 163 | else if (aMessageObject.level == "groupEnd") { |
michael@0 | 164 | let groupName = Array.prototype.join.call(aMessageObject.arguments, " "); |
michael@0 | 165 | is(groupName,"b group", "groupEnd arguments matches"); |
michael@0 | 166 | is(aMessageObject.groupName, "b group", "groupEnd groupName matches"); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | if (aMessageObject.level == "groupEnd") { |
michael@0 | 170 | startTimeTest(); |
michael@0 | 171 | } |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | function startTraceTest() { |
michael@0 | 175 | gLevel = "trace"; |
michael@0 | 176 | gArgs = [ |
michael@0 | 177 | {filename: TEST_URI, functionName: "window.foobar585956c", language: 2, lineNumber: 6}, |
michael@0 | 178 | {filename: TEST_URI, functionName: "foobar585956b", language: 2, lineNumber: 11}, |
michael@0 | 179 | {filename: TEST_URI, functionName: "foobar585956a", language: 2, lineNumber: 15}, |
michael@0 | 180 | {filename: TEST_URI, functionName: "onclick", language: 2, lineNumber: 1} |
michael@0 | 181 | ]; |
michael@0 | 182 | |
michael@0 | 183 | let button = gWindow.document.getElementById("test-trace"); |
michael@0 | 184 | ok(button, "found #test-trace button"); |
michael@0 | 185 | EventUtils.synthesizeMouseAtCenter(button, {}, gWindow); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | function startLocationTest() { |
michael@0 | 189 | // Reset the observer function to cope with the fabricated test data. |
michael@0 | 190 | ConsoleObserver.observe = function CO_observe(aSubject, aTopic, aData) { |
michael@0 | 191 | try { |
michael@0 | 192 | testLocationData(aSubject.wrappedJSObject); |
michael@0 | 193 | } catch (ex) { |
michael@0 | 194 | // XXX Bug 906593 - Exceptions in this function currently aren't |
michael@0 | 195 | // reported, because of some XPConnect weirdness, so report them manually |
michael@0 | 196 | ok(false, "Exception thrown in CO_observe: " + ex); |
michael@0 | 197 | } |
michael@0 | 198 | }; |
michael@0 | 199 | gLevel = "log"; |
michael@0 | 200 | gArgs = [ |
michael@0 | 201 | {filename: TEST_URI, functionName: "foobar646025", arguments: ["omg", "o", "d"], lineNumber: 19} |
michael@0 | 202 | ]; |
michael@0 | 203 | |
michael@0 | 204 | let button = gWindow.document.getElementById("test-location"); |
michael@0 | 205 | ok(button, "found #test-location button"); |
michael@0 | 206 | EventUtils.synthesizeMouseAtCenter(button, {}, gWindow); |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | function expect(level) { |
michael@0 | 210 | gLevel = level; |
michael@0 | 211 | gArgs = Array.slice(arguments, 1); |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | function observeConsoleTest() { |
michael@0 | 215 | let win = XPCNativeWrapper.unwrap(gWindow); |
michael@0 | 216 | expect("log", "arg"); |
michael@0 | 217 | win.console.log("arg"); |
michael@0 | 218 | yield undefined; |
michael@0 | 219 | |
michael@0 | 220 | expect("info", "arg", "extra arg"); |
michael@0 | 221 | win.console.info("arg", "extra arg"); |
michael@0 | 222 | yield undefined; |
michael@0 | 223 | |
michael@0 | 224 | expect("warn", "Lesson 1: PI is approximately equal to 3"); |
michael@0 | 225 | win.console.warn("Lesson %d: %s is approximately equal to %1.0f", |
michael@0 | 226 | 1, |
michael@0 | 227 | "PI", |
michael@0 | 228 | 3.14159); |
michael@0 | 229 | yield undefined; |
michael@0 | 230 | |
michael@0 | 231 | expect("warn", "Lesson 1: PI is approximately equal to 3.14"); |
michael@0 | 232 | win.console.warn("Lesson %d: %s is approximately equal to %1.2f", |
michael@0 | 233 | 1, |
michael@0 | 234 | "PI", |
michael@0 | 235 | 3.14159); |
michael@0 | 236 | yield undefined; |
michael@0 | 237 | |
michael@0 | 238 | expect("warn", "Lesson 1: PI is approximately equal to 3.141590"); |
michael@0 | 239 | win.console.warn("Lesson %d: %s is approximately equal to %f", |
michael@0 | 240 | 1, |
michael@0 | 241 | "PI", |
michael@0 | 242 | 3.14159); |
michael@0 | 243 | yield undefined; |
michael@0 | 244 | |
michael@0 | 245 | expect("warn", "Lesson 1: PI is approximately equal to 3.1415900"); |
michael@0 | 246 | win.console.warn("Lesson %d: %s is approximately equal to %0.7f", |
michael@0 | 247 | 1, |
michael@0 | 248 | "PI", |
michael@0 | 249 | 3.14159); |
michael@0 | 250 | yield undefined; |
michael@0 | 251 | |
michael@0 | 252 | expect("log", "%d, %s, %l"); |
michael@0 | 253 | win.console.log("%d, %s, %l"); |
michael@0 | 254 | yield undefined; |
michael@0 | 255 | |
michael@0 | 256 | expect("log", "%a %b %g"); |
michael@0 | 257 | win.console.log("%a %b %g"); |
michael@0 | 258 | yield undefined; |
michael@0 | 259 | |
michael@0 | 260 | expect("log", "%a %b %g", "a", "b"); |
michael@0 | 261 | win.console.log("%a %b %g", "a", "b"); |
michael@0 | 262 | yield undefined; |
michael@0 | 263 | |
michael@0 | 264 | expect("log", "2, a, %l", 3); |
michael@0 | 265 | win.console.log("%d, %s, %l", 2, "a", 3); |
michael@0 | 266 | yield undefined; |
michael@0 | 267 | |
michael@0 | 268 | // Bug #692550 handle null and undefined. |
michael@0 | 269 | expect("log", "null, undefined"); |
michael@0 | 270 | win.console.log("%s, %s", null, undefined); |
michael@0 | 271 | yield undefined; |
michael@0 | 272 | |
michael@0 | 273 | // Bug #696288 handle object as first argument. |
michael@0 | 274 | let obj = { a: 1 }; |
michael@0 | 275 | expect("log", obj, "a"); |
michael@0 | 276 | win.console.log(obj, "a"); |
michael@0 | 277 | yield undefined; |
michael@0 | 278 | |
michael@0 | 279 | expect("dir", win.toString()); |
michael@0 | 280 | win.console.dir(win); |
michael@0 | 281 | yield undefined; |
michael@0 | 282 | |
michael@0 | 283 | expect("error", "arg"); |
michael@0 | 284 | win.console.error("arg"); |
michael@0 | 285 | yield undefined; |
michael@0 | 286 | |
michael@0 | 287 | expect("exception", "arg"); |
michael@0 | 288 | win.console.exception("arg"); |
michael@0 | 289 | yield undefined; |
michael@0 | 290 | |
michael@0 | 291 | expect("log", "foobar"); |
michael@0 | 292 | gStyle = ["color:red;foobar;;"]; |
michael@0 | 293 | win.console.log("%cfoobar", gStyle[0]); |
michael@0 | 294 | yield undefined; |
michael@0 | 295 | |
michael@0 | 296 | let obj4 = { d: 4 }; |
michael@0 | 297 | expect("warn", "foobar", obj4, "test", "bazbazstr", "last"); |
michael@0 | 298 | gStyle = [null, null, null, "color:blue;", "color:red"]; |
michael@0 | 299 | win.console.warn("foobar%Otest%cbazbaz%s%clast", obj4, gStyle[3], "str", gStyle[4]); |
michael@0 | 300 | yield undefined; |
michael@0 | 301 | |
michael@0 | 302 | let obj3 = { c: 3 }; |
michael@0 | 303 | expect("info", "foobar", "bazbaz", obj3, "%comg", "color:yellow"); |
michael@0 | 304 | gStyle = [null, "color:pink;"]; |
michael@0 | 305 | win.console.info("foobar%cbazbaz", gStyle[1], obj3, "%comg", "color:yellow"); |
michael@0 | 306 | yield undefined; |
michael@0 | 307 | |
michael@0 | 308 | gStyle = null; |
michael@0 | 309 | let obj2 = { b: 2 }; |
michael@0 | 310 | expect("log", "omg ", obj, " foo ", 4, obj2); |
michael@0 | 311 | win.console.log("omg %o foo %o", obj, 4, obj2); |
michael@0 | 312 | yield undefined; |
michael@0 | 313 | |
michael@0 | 314 | expect("assert", "message"); |
michael@0 | 315 | win.console.assert(false, "message"); |
michael@0 | 316 | yield undefined; |
michael@0 | 317 | |
michael@0 | 318 | expect("count", { label: "label a", count: 1 }) |
michael@0 | 319 | win.console.count("label a"); |
michael@0 | 320 | yield undefined; |
michael@0 | 321 | |
michael@0 | 322 | expect("count", { label: "label b", count: 1 }) |
michael@0 | 323 | win.console.count("label b"); |
michael@0 | 324 | yield undefined; |
michael@0 | 325 | |
michael@0 | 326 | expect("count", { label: "label a", count: 2 }) |
michael@0 | 327 | win.console.count("label a"); |
michael@0 | 328 | yield undefined; |
michael@0 | 329 | |
michael@0 | 330 | expect("count", { label: "label b", count: 2 }) |
michael@0 | 331 | win.console.count("label b"); |
michael@0 | 332 | yield undefined; |
michael@0 | 333 | |
michael@0 | 334 | startTraceTest(); |
michael@0 | 335 | yield undefined; |
michael@0 | 336 | |
michael@0 | 337 | startLocationTest(); |
michael@0 | 338 | yield undefined; |
michael@0 | 339 | } |
michael@0 | 340 | |
michael@0 | 341 | function consoleAPISanityTest() { |
michael@0 | 342 | let win = XPCNativeWrapper.unwrap(gWindow); |
michael@0 | 343 | ok(win.console, "we have a console attached"); |
michael@0 | 344 | ok(win.console, "we have a console attached, 2nd attempt"); |
michael@0 | 345 | |
michael@0 | 346 | ok(win.console.log, "console.log is here"); |
michael@0 | 347 | ok(win.console.info, "console.info is here"); |
michael@0 | 348 | ok(win.console.warn, "console.warn is here"); |
michael@0 | 349 | ok(win.console.error, "console.error is here"); |
michael@0 | 350 | ok(win.console.exception, "console.exception is here"); |
michael@0 | 351 | ok(win.console.trace, "console.trace is here"); |
michael@0 | 352 | ok(win.console.dir, "console.dir is here"); |
michael@0 | 353 | ok(win.console.group, "console.group is here"); |
michael@0 | 354 | ok(win.console.groupCollapsed, "console.groupCollapsed is here"); |
michael@0 | 355 | ok(win.console.groupEnd, "console.groupEnd is here"); |
michael@0 | 356 | ok(win.console.time, "console.time is here"); |
michael@0 | 357 | ok(win.console.timeEnd, "console.timeEnd is here"); |
michael@0 | 358 | ok(win.console.assert, "console.assert is here"); |
michael@0 | 359 | ok(win.console.count, "console.count is here"); |
michael@0 | 360 | } |
michael@0 | 361 | |
michael@0 | 362 | function startTimeTest() { |
michael@0 | 363 | // Reset the observer function to cope with the fabricated test data. |
michael@0 | 364 | ConsoleObserver.observe = function CO_observe(aSubject, aTopic, aData) { |
michael@0 | 365 | try { |
michael@0 | 366 | testConsoleTime(aSubject.wrappedJSObject); |
michael@0 | 367 | } catch (ex) { |
michael@0 | 368 | // XXX Bug 906593 - Exceptions in this function currently aren't |
michael@0 | 369 | // reported, because of some XPConnect weirdness, so report them manually |
michael@0 | 370 | ok(false, "Exception thrown in CO_observe: " + ex); |
michael@0 | 371 | } |
michael@0 | 372 | }; |
michael@0 | 373 | gLevel = "time"; |
michael@0 | 374 | gArgs = [ |
michael@0 | 375 | {filename: TEST_URI, lineNumber: 23, functionName: "startTimer", |
michael@0 | 376 | arguments: ["foo"], |
michael@0 | 377 | timer: { name: "foo" }, |
michael@0 | 378 | } |
michael@0 | 379 | ]; |
michael@0 | 380 | |
michael@0 | 381 | let button = gWindow.document.getElementById("test-time"); |
michael@0 | 382 | ok(button, "found #test-time button"); |
michael@0 | 383 | EventUtils.synthesizeMouseAtCenter(button, {}, gWindow); |
michael@0 | 384 | } |
michael@0 | 385 | |
michael@0 | 386 | function testConsoleTime(aMessageObject) { |
michael@0 | 387 | let messageWindow = Services.wm.getOuterWindowWithId(aMessageObject.ID); |
michael@0 | 388 | is(messageWindow, gWindow, "found correct window by window ID"); |
michael@0 | 389 | |
michael@0 | 390 | is(aMessageObject.level, gLevel, "expected level received"); |
michael@0 | 391 | |
michael@0 | 392 | is(aMessageObject.filename, gArgs[0].filename, "filename matches"); |
michael@0 | 393 | is(aMessageObject.lineNumber, gArgs[0].lineNumber, "lineNumber matches"); |
michael@0 | 394 | is(aMessageObject.functionName, gArgs[0].functionName, "functionName matches"); |
michael@0 | 395 | is(aMessageObject.timer.name, gArgs[0].timer.name, "timer.name matches"); |
michael@0 | 396 | ok(aMessageObject.timer.started, "timer.started exists"); |
michael@0 | 397 | |
michael@0 | 398 | gArgs[0].arguments.forEach(function (a, i) { |
michael@0 | 399 | is(aMessageObject.arguments[i], a, "correct arg " + i); |
michael@0 | 400 | }); |
michael@0 | 401 | |
michael@0 | 402 | startTimeEndTest(); |
michael@0 | 403 | } |
michael@0 | 404 | |
michael@0 | 405 | function startTimeEndTest() { |
michael@0 | 406 | // Reset the observer function to cope with the fabricated test data. |
michael@0 | 407 | ConsoleObserver.observe = function CO_observe(aSubject, aTopic, aData) { |
michael@0 | 408 | try { |
michael@0 | 409 | testConsoleTimeEnd(aSubject.wrappedJSObject); |
michael@0 | 410 | } catch (ex) { |
michael@0 | 411 | // XXX Bug 906593 - Exceptions in this function currently aren't |
michael@0 | 412 | // reported, because of some XPConnect weirdness, so report them manually |
michael@0 | 413 | ok(false, "Exception thrown in CO_observe: " + ex); |
michael@0 | 414 | } |
michael@0 | 415 | }; |
michael@0 | 416 | gLevel = "timeEnd"; |
michael@0 | 417 | gArgs = [ |
michael@0 | 418 | {filename: TEST_URI, lineNumber: 27, functionName: "stopTimer", |
michael@0 | 419 | arguments: ["foo"], |
michael@0 | 420 | timer: { name: "foo" }, |
michael@0 | 421 | }, |
michael@0 | 422 | ]; |
michael@0 | 423 | |
michael@0 | 424 | let button = gWindow.document.getElementById("test-timeEnd"); |
michael@0 | 425 | ok(button, "found #test-timeEnd button"); |
michael@0 | 426 | EventUtils.synthesizeMouseAtCenter(button, {}, gWindow); |
michael@0 | 427 | } |
michael@0 | 428 | |
michael@0 | 429 | function testConsoleTimeEnd(aMessageObject) { |
michael@0 | 430 | let messageWindow = Services.wm.getOuterWindowWithId(aMessageObject.ID); |
michael@0 | 431 | is(messageWindow, gWindow, "found correct window by window ID"); |
michael@0 | 432 | |
michael@0 | 433 | is(aMessageObject.level, gLevel, "expected level received"); |
michael@0 | 434 | ok(aMessageObject.arguments, "we have arguments"); |
michael@0 | 435 | |
michael@0 | 436 | is(aMessageObject.filename, gArgs[0].filename, "filename matches"); |
michael@0 | 437 | is(aMessageObject.lineNumber, gArgs[0].lineNumber, "lineNumber matches"); |
michael@0 | 438 | is(aMessageObject.functionName, gArgs[0].functionName, "functionName matches"); |
michael@0 | 439 | is(aMessageObject.arguments.length, gArgs[0].arguments.length, "arguments.length matches"); |
michael@0 | 440 | is(aMessageObject.timer.name, gArgs[0].timer.name, "timer name matches"); |
michael@0 | 441 | is(typeof aMessageObject.timer.duration, "number", "timer duration is a number"); |
michael@0 | 442 | info("timer duration: " + aMessageObject.timer.duration); |
michael@0 | 443 | ok(aMessageObject.timer.duration >= 0, "timer duration is positive"); |
michael@0 | 444 | |
michael@0 | 445 | gArgs[0].arguments.forEach(function (a, i) { |
michael@0 | 446 | is(aMessageObject.arguments[i], a, "correct arg " + i); |
michael@0 | 447 | }); |
michael@0 | 448 | |
michael@0 | 449 | startEmptyTimerTest(); |
michael@0 | 450 | } |
michael@0 | 451 | |
michael@0 | 452 | function startEmptyTimerTest() { |
michael@0 | 453 | // Reset the observer function to cope with the fabricated test data. |
michael@0 | 454 | ConsoleObserver.observe = function CO_observe(aSubject, aTopic, aData) { |
michael@0 | 455 | try { |
michael@0 | 456 | testEmptyTimer(aSubject.wrappedJSObject); |
michael@0 | 457 | } catch (ex) { |
michael@0 | 458 | // XXX Bug 906593 - Exceptions in this function currently aren't |
michael@0 | 459 | // reported, because of some XPConnect weirdness, so report them manually |
michael@0 | 460 | ok(false, "Exception thrown in CO_observe: " + ex); |
michael@0 | 461 | } |
michael@0 | 462 | }; |
michael@0 | 463 | |
michael@0 | 464 | let button = gWindow.document.getElementById("test-namelessTimer"); |
michael@0 | 465 | ok(button, "found #test-namelessTimer button"); |
michael@0 | 466 | EventUtils.synthesizeMouseAtCenter(button, {}, gWindow); |
michael@0 | 467 | } |
michael@0 | 468 | |
michael@0 | 469 | function testEmptyTimer(aMessageObject) { |
michael@0 | 470 | let messageWindow = Services.wm.getOuterWindowWithId(aMessageObject.ID); |
michael@0 | 471 | is(messageWindow, gWindow, "found correct window by window ID"); |
michael@0 | 472 | |
michael@0 | 473 | ok(aMessageObject.level == "time" || aMessageObject.level == "timeEnd", |
michael@0 | 474 | "expected level received"); |
michael@0 | 475 | is(aMessageObject.arguments.length, 0, "we don't have arguments"); |
michael@0 | 476 | ok(!aMessageObject.timer, "we don't have a timer"); |
michael@0 | 477 | |
michael@0 | 478 | is(aMessageObject.functionName, "namelessTimer", "functionName matches"); |
michael@0 | 479 | ok(aMessageObject.lineNumber == 31 || aMessageObject.lineNumber == 32, |
michael@0 | 480 | "lineNumber matches"); |
michael@0 | 481 | // Test finished |
michael@0 | 482 | ConsoleObserver.destroy(); |
michael@0 | 483 | finish(); |
michael@0 | 484 | } |
michael@0 | 485 | |
michael@0 | 486 | var ConsoleObserver = { |
michael@0 | 487 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), |
michael@0 | 488 | |
michael@0 | 489 | init: function CO_init() { |
michael@0 | 490 | Services.obs.addObserver(this, "console-api-log-event", false); |
michael@0 | 491 | }, |
michael@0 | 492 | |
michael@0 | 493 | destroy: function CO_destroy() { |
michael@0 | 494 | Services.obs.removeObserver(this, "console-api-log-event"); |
michael@0 | 495 | }, |
michael@0 | 496 | |
michael@0 | 497 | observe: function CO_observe(aSubject, aTopic, aData) { |
michael@0 | 498 | try { |
michael@0 | 499 | testConsoleData(aSubject.wrappedJSObject); |
michael@0 | 500 | } catch (ex) { |
michael@0 | 501 | // XXX Bug 906593 - Exceptions in this function currently aren't |
michael@0 | 502 | // reported, because of some XPConnect weirdness, so report them manually |
michael@0 | 503 | ok(false, "Exception thrown in CO_observe: " + ex); |
michael@0 | 504 | } |
michael@0 | 505 | } |
michael@0 | 506 | }; |
michael@0 | 507 | |
michael@0 | 508 | function getWindowId(aWindow) |
michael@0 | 509 | { |
michael@0 | 510 | return aWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 511 | .getInterface(Ci.nsIDOMWindowUtils) |
michael@0 | 512 | .outerWindowID; |
michael@0 | 513 | } |