| OLD | NEW |
| (Empty) |
| 1 // svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump tex
t + pixel results | |
| 2 if (self.testRunner) { | |
| 3 if (self.enablePixelTesting) | |
| 4 testRunner.dumpAsTextWithPixelResults(); | |
| 5 else | |
| 6 testRunner.dumpAsText(); | |
| 7 } | |
| 8 | |
| 9 var description, debug, successfullyParsed, errorMessage; | |
| 10 | |
| 11 (function() { | |
| 12 | |
| 13 function getOrCreate(id, tagName) | |
| 14 { | |
| 15 var element = document.getElementById(id); | |
| 16 if (element) | |
| 17 return element; | |
| 18 | |
| 19 element = document.createElement(tagName); | |
| 20 element.id = id; | |
| 21 var refNode; | |
| 22 var parent = document.body || document.documentElement; | |
| 23 if (id == "description") | |
| 24 refNode = getOrCreate("console", "div"); | |
| 25 else | |
| 26 refNode = parent.firstChild; | |
| 27 | |
| 28 parent.insertBefore(element, refNode); | |
| 29 return element; | |
| 30 } | |
| 31 | |
| 32 description = function description(msg, quiet) | |
| 33 { | |
| 34 // For MSIE 6 compatibility | |
| 35 var span = document.createElement("span"); | |
| 36 if (quiet) | |
| 37 span.innerHTML = '<p>' + msg + '</p><p>On success, you will see no "
<span class="fail">FAIL</span>" messages, followed by "<span class="pass">TEST C
OMPLETE</span>".</p>'; | |
| 38 else | |
| 39 span.innerHTML = '<p>' + msg + '</p><p>On success, you will see a se
ries of "<span class="pass">PASS</span>" messages, followed by "<span class="pas
s">TEST COMPLETE</span>".</p>'; | |
| 40 | |
| 41 var description = getOrCreate("description", "p"); | |
| 42 if (description.firstChild) | |
| 43 description.replaceChild(span, description.firstChild); | |
| 44 else | |
| 45 description.appendChild(span); | |
| 46 }; | |
| 47 | |
| 48 debug = function debug(msg) | |
| 49 { | |
| 50 var span = document.createElement("span"); | |
| 51 getOrCreate("console", "div").appendChild(span); // insert it first so X
HTML knows the namespace | |
| 52 span.innerHTML = msg + '<br />'; | |
| 53 }; | |
| 54 | |
| 55 var css = | |
| 56 ".pass {" + | |
| 57 "font-weight: bold;" + | |
| 58 "color: green;" + | |
| 59 "}" + | |
| 60 ".fail {" + | |
| 61 "font-weight: bold;" + | |
| 62 "color: red;" + | |
| 63 "}" + | |
| 64 "#console {" + | |
| 65 "white-space: pre-wrap;" + | |
| 66 "font-family: monospace;" + | |
| 67 "}"; | |
| 68 | |
| 69 function insertStyleSheet() | |
| 70 { | |
| 71 var styleElement = document.createElement("style"); | |
| 72 styleElement.textContent = css; | |
| 73 (document.head || document.documentElement).appendChild(styleElement); | |
| 74 } | |
| 75 | |
| 76 function handleTestFinished() | |
| 77 { | |
| 78 // FIXME: Get rid of this boolean. | |
| 79 wasPostTestScriptParsed = true; | |
| 80 if (window.jsTestIsAsync) { | |
| 81 if (window.testRunner) | |
| 82 testRunner.waitUntilDone(); | |
| 83 if (window.wasFinishJSTestCalled) | |
| 84 finishJSTest(); | |
| 85 } else | |
| 86 finishJSTest(); | |
| 87 } | |
| 88 | |
| 89 if (!isWorker()) { | |
| 90 window.addEventListener('DOMContentLoaded', handleTestFinished, false); | |
| 91 insertStyleSheet(); | |
| 92 } | |
| 93 | |
| 94 if (!self.isOnErrorTest) { | |
| 95 self.onerror = function(message) | |
| 96 { | |
| 97 errorMessage = message; | |
| 98 }; | |
| 99 } | |
| 100 })(); | |
| 101 | |
| 102 function isWorker() | |
| 103 { | |
| 104 // It's conceivable that someone would stub out 'document' in a worker so | |
| 105 // also check for childNodes, an arbitrary DOM-related object that is | |
| 106 // meaningless in a WorkerContext. | |
| 107 return (typeof document === 'undefined' || typeof document.childNodes === 'u
ndefined') && !!self.importScripts; | |
| 108 } | |
| 109 | |
| 110 function descriptionQuiet(msg) { description(msg, true); } | |
| 111 | |
| 112 function escapeHTML(text) | |
| 113 { | |
| 114 return text.replace(/&/g, "&").replace(/</g, "<").replace(/\0/g, "\\0
"); | |
| 115 } | |
| 116 | |
| 117 function testPassed(msg) | |
| 118 { | |
| 119 debug('<span><span class="pass">PASS</span> ' + escapeHTML(msg) + '</span>')
; | |
| 120 } | |
| 121 | |
| 122 function testFailed(msg) | |
| 123 { | |
| 124 debug('<span><span class="fail">FAIL</span> ' + escapeHTML(msg) + '</span>')
; | |
| 125 } | |
| 126 | |
| 127 function areArraysEqual(_a, _b) | |
| 128 { | |
| 129 try { | |
| 130 if (_a.length !== _b.length) | |
| 131 return false; | |
| 132 for (var i = 0; i < _a.length; i++) | |
| 133 if (_a[i] !== _b[i]) | |
| 134 return false; | |
| 135 } catch (ex) { | |
| 136 return false; | |
| 137 } | |
| 138 return true; | |
| 139 } | |
| 140 | |
| 141 function isMinusZero(n) | |
| 142 { | |
| 143 // the only way to tell 0 from -0 in JS is the fact that 1/-0 is | |
| 144 // -Infinity instead of Infinity | |
| 145 return n === 0 && 1/n < 0; | |
| 146 } | |
| 147 | |
| 148 function isResultCorrect(_actual, _expected) | |
| 149 { | |
| 150 if (_expected === 0) | |
| 151 return _actual === _expected && (1/_actual) === (1/_expected); | |
| 152 if (_actual === _expected) | |
| 153 return true; | |
| 154 if (typeof(_expected) == "number" && isNaN(_expected)) | |
| 155 return typeof(_actual) == "number" && isNaN(_actual); | |
| 156 if (_expected && (Object.prototype.toString.call(_expected) == Object.protot
ype.toString.call([]))) | |
| 157 return areArraysEqual(_actual, _expected); | |
| 158 return false; | |
| 159 } | |
| 160 | |
| 161 function stringify(v) | |
| 162 { | |
| 163 if (v === 0 && 1/v < 0) | |
| 164 return "-0"; | |
| 165 else return "" + v; | |
| 166 } | |
| 167 | |
| 168 function evalAndLog(_a, _quiet) | |
| 169 { | |
| 170 if (typeof _a != "string") | |
| 171 debug("WARN: tryAndLog() expects a string argument"); | |
| 172 | |
| 173 // Log first in case things go horribly wrong or this causes a sync event. | |
| 174 if (!_quiet) | |
| 175 debug(_a); | |
| 176 | |
| 177 var _av; | |
| 178 try { | |
| 179 _av = eval(_a); | |
| 180 } catch (e) { | |
| 181 testFailed(_a + " threw exception " + e); | |
| 182 } | |
| 183 return _av; | |
| 184 } | |
| 185 | |
| 186 function shouldBe(_a, _b, quiet) | |
| 187 { | |
| 188 if (typeof _a != "string" || typeof _b != "string") | |
| 189 debug("WARN: shouldBe() expects string arguments"); | |
| 190 var exception; | |
| 191 var _av; | |
| 192 try { | |
| 193 _av = eval(_a); | |
| 194 } catch (e) { | |
| 195 exception = e; | |
| 196 } | |
| 197 var _bv = eval(_b); | |
| 198 | |
| 199 if (exception) | |
| 200 testFailed(_a + " should be " + _bv + ". Threw exception " + exception); | |
| 201 else if (isResultCorrect(_av, _bv)) { | |
| 202 if (!quiet) { | |
| 203 testPassed(_a + " is " + _b); | |
| 204 } | |
| 205 } else if (typeof(_av) == typeof(_bv)) | |
| 206 testFailed(_a + " should be " + _bv + ". Was " + stringify(_av) + "."); | |
| 207 else | |
| 208 testFailed(_a + " should be " + _bv + " (of type " + typeof _bv + "). Was "
+ _av + " (of type " + typeof _av + ")."); | |
| 209 } | |
| 210 | |
| 211 // Execute condition every 5 milliseconds until it succeed or failureTime is rea
ched. | |
| 212 // completionHandler is executed on success, failureHandler is executed on timeo
ut. | |
| 213 function _waitForCondition(condition, failureTime, completionHandler, failureHan
dler) | |
| 214 { | |
| 215 if (condition()) { | |
| 216 completionHandler(); | |
| 217 } else if (Date.now() > failureTime) { | |
| 218 failureHandler(); | |
| 219 } else { | |
| 220 setTimeout(_waitForCondition, 5, condition, failureTime, completionHandler,
failureHandler); | |
| 221 } | |
| 222 } | |
| 223 | |
| 224 function shouldBecomeEqual(_a, _b, completionHandler, timeout) | |
| 225 { | |
| 226 if (typeof _a != "string" || typeof _b != "string") | |
| 227 debug("WARN: shouldBecomeEqual() expects string arguments"); | |
| 228 | |
| 229 if (timeout === undefined) | |
| 230 timeout = 500; | |
| 231 | |
| 232 var condition = function() { | |
| 233 var exception; | |
| 234 var _av; | |
| 235 try { | |
| 236 _av = eval(_a); | |
| 237 } catch (e) { | |
| 238 exception = e; | |
| 239 } | |
| 240 var _bv = eval(_b); | |
| 241 if (exception) | |
| 242 testFailed(_a + " should become " + _bv + ". Threw exception " + exception
); | |
| 243 if (isResultCorrect(_av, _bv)) { | |
| 244 testPassed(_a + " became " + _b); | |
| 245 return true; | |
| 246 } | |
| 247 return false; | |
| 248 }; | |
| 249 var failureTime = Date.now() + timeout; | |
| 250 var failureHandler = function () { | |
| 251 testFailed(_a + " failed to change to " + _b + " in " + (timeout / 1000) + "
seconds."); | |
| 252 completionHandler(); | |
| 253 }; | |
| 254 _waitForCondition(condition, failureTime, completionHandler, failureHandler); | |
| 255 } | |
| 256 | |
| 257 function shouldBecomeEqualToString(value, reference, completionHandler, timeout) | |
| 258 { | |
| 259 if (typeof value !== "string" || typeof reference !== "string") | |
| 260 debug("WARN: shouldBecomeEqualToString() expects string arguments"); | |
| 261 var unevaledString = JSON.stringify(reference); | |
| 262 shouldBecomeEqual(value, unevaledString, completionHandler, timeout); | |
| 263 } | |
| 264 | |
| 265 function shouldBeType(_a, _type) { | |
| 266 var exception; | |
| 267 var _av; | |
| 268 try { | |
| 269 _av = eval(_a); | |
| 270 } catch (e) { | |
| 271 exception = e; | |
| 272 } | |
| 273 | |
| 274 var _typev = eval(_type); | |
| 275 if (_av instanceof _typev) { | |
| 276 testPassed(_a + " is an instance of " + _type); | |
| 277 } else { | |
| 278 testFailed(_a + " is not an instance of " + _type); | |
| 279 } | |
| 280 } | |
| 281 | |
| 282 // Variant of shouldBe()--confirms that result of eval(_to_eval) is within | |
| 283 // numeric _tolerance of numeric _target. | |
| 284 function shouldBeCloseTo(_to_eval, _target, _tolerance, quiet) | |
| 285 { | |
| 286 if (typeof _to_eval != "string") { | |
| 287 testFailed("shouldBeCloseTo() requires string argument _to_eval. was type "
+ typeof _to_eval); | |
| 288 return; | |
| 289 } | |
| 290 if (typeof _target != "number") { | |
| 291 testFailed("shouldBeCloseTo() requires numeric argument _target. was type "
+ typeof _target); | |
| 292 return; | |
| 293 } | |
| 294 if (typeof _tolerance != "number") { | |
| 295 testFailed("shouldBeCloseTo() requires numeric argument _tolerance. was type
" + typeof _tolerance); | |
| 296 return; | |
| 297 } | |
| 298 | |
| 299 var _result; | |
| 300 try { | |
| 301 _result = eval(_to_eval); | |
| 302 } catch (e) { | |
| 303 testFailed(_to_eval + " should be within " + _tolerance + " of " | |
| 304 + _target + ". Threw exception " + e); | |
| 305 return; | |
| 306 } | |
| 307 | |
| 308 if (typeof(_result) != typeof(_target)) { | |
| 309 testFailed(_to_eval + " should be of type " + typeof _target | |
| 310 + " but was of type " + typeof _result); | |
| 311 } else if (Math.abs(_result - _target) <= _tolerance) { | |
| 312 if (!quiet) { | |
| 313 testPassed(_to_eval + " is within " + _tolerance + " of " + _target); | |
| 314 } | |
| 315 } else { | |
| 316 testFailed(_to_eval + " should be within " + _tolerance + " of " + _target | |
| 317 + ". Was " + _result + "."); | |
| 318 } | |
| 319 } | |
| 320 | |
| 321 function shouldNotBe(_a, _b, quiet) | |
| 322 { | |
| 323 if (typeof _a != "string" || typeof _b != "string") | |
| 324 debug("WARN: shouldNotBe() expects string arguments"); | |
| 325 var exception; | |
| 326 var _av; | |
| 327 try { | |
| 328 _av = eval(_a); | |
| 329 } catch (e) { | |
| 330 exception = e; | |
| 331 } | |
| 332 var _bv = eval(_b); | |
| 333 | |
| 334 if (exception) | |
| 335 testFailed(_a + " should not be " + _bv + ". Threw exception " + exception); | |
| 336 else if (!isResultCorrect(_av, _bv)) { | |
| 337 if (!quiet) { | |
| 338 testPassed(_a + " is not " + _b); | |
| 339 } | |
| 340 } else | |
| 341 testFailed(_a + " should not be " + _bv + "."); | |
| 342 } | |
| 343 | |
| 344 function shouldBecomeDifferent(_a, _b, completionHandler, timeout) | |
| 345 { | |
| 346 if (typeof _a != "string" || typeof _b != "string") | |
| 347 debug("WARN: shouldBecomeDifferent() expects string arguments"); | |
| 348 if (timeout === undefined) | |
| 349 timeout = 500; | |
| 350 | |
| 351 var condition = function() { | |
| 352 var exception; | |
| 353 var _av; | |
| 354 try { | |
| 355 _av = eval(_a); | |
| 356 } catch (e) { | |
| 357 exception = e; | |
| 358 } | |
| 359 var _bv = eval(_b); | |
| 360 if (exception) | |
| 361 testFailed(_a + " should became not equal to " + _bv + ". Threw exception
" + exception); | |
| 362 if (!isResultCorrect(_av, _bv)) { | |
| 363 testPassed(_a + " became different from " + _b); | |
| 364 return true; | |
| 365 } | |
| 366 return false; | |
| 367 }; | |
| 368 var failureTime = Date.now() + timeout; | |
| 369 var failureHandler = function () { | |
| 370 testFailed(_a + " did not become different from " + _b + " in " + (timeout /
1000) + " seconds."); | |
| 371 completionHandler(); | |
| 372 }; | |
| 373 _waitForCondition(condition, failureTime, completionHandler, failureHandler); | |
| 374 } | |
| 375 | |
| 376 function shouldBeTrue(_a) { shouldBe(_a, "true"); } | |
| 377 function shouldBeTrueQuiet(_a) { shouldBe(_a, "true", true); } | |
| 378 function shouldBeFalse(_a) { shouldBe(_a, "false"); } | |
| 379 function shouldBeNaN(_a) { shouldBe(_a, "NaN"); } | |
| 380 function shouldBeNull(_a) { shouldBe(_a, "null"); } | |
| 381 function shouldBeZero(_a) { shouldBe(_a, "0"); } | |
| 382 | |
| 383 function shouldBeEqualToString(a, b) | |
| 384 { | |
| 385 if (typeof a !== "string" || typeof b !== "string") | |
| 386 debug("WARN: shouldBeEqualToString() expects string arguments"); | |
| 387 var unevaledString = JSON.stringify(b); | |
| 388 shouldBe(a, unevaledString); | |
| 389 } | |
| 390 | |
| 391 function shouldBeEmptyString(_a) { shouldBeEqualToString(_a, ""); } | |
| 392 | |
| 393 function shouldEvaluateTo(actual, expected) { | |
| 394 // A general-purpose comparator. 'actual' should be a string to be | |
| 395 // evaluated, as for shouldBe(). 'expected' may be any type and will be | |
| 396 // used without being eval'ed. | |
| 397 if (expected == null) { | |
| 398 // Do this before the object test, since null is of type 'object'. | |
| 399 shouldBeNull(actual); | |
| 400 } else if (typeof expected == "undefined") { | |
| 401 shouldBeUndefined(actual); | |
| 402 } else if (typeof expected == "function") { | |
| 403 // All this fuss is to avoid the string-arg warning from shouldBe(). | |
| 404 try { | |
| 405 actualValue = eval(actual); | |
| 406 } catch (e) { | |
| 407 testFailed("Evaluating " + actual + ": Threw exception " + e); | |
| 408 return; | |
| 409 } | |
| 410 shouldBe("'" + actualValue.toString().replace(/\n/g, "") + "'", | |
| 411 "'" + expected.toString().replace(/\n/g, "") + "'"); | |
| 412 } else if (typeof expected == "object") { | |
| 413 shouldBeTrue(actual + " == '" + expected + "'"); | |
| 414 } else if (typeof expected == "string") { | |
| 415 shouldBe(actual, expected); | |
| 416 } else if (typeof expected == "boolean") { | |
| 417 shouldBe("typeof " + actual, "'boolean'"); | |
| 418 if (expected) | |
| 419 shouldBeTrue(actual); | |
| 420 else | |
| 421 shouldBeFalse(actual); | |
| 422 } else if (typeof expected == "number") { | |
| 423 shouldBe(actual, stringify(expected)); | |
| 424 } else { | |
| 425 debug(expected + " is unknown type " + typeof expected); | |
| 426 shouldBeTrue(actual, "'" +expected.toString() + "'"); | |
| 427 } | |
| 428 } | |
| 429 | |
| 430 function shouldBeNonZero(_a) | |
| 431 { | |
| 432 var exception; | |
| 433 var _av; | |
| 434 try { | |
| 435 _av = eval(_a); | |
| 436 } catch (e) { | |
| 437 exception = e; | |
| 438 } | |
| 439 | |
| 440 if (exception) | |
| 441 testFailed(_a + " should be non-zero. Threw exception " + exception); | |
| 442 else if (_av != 0) | |
| 443 testPassed(_a + " is non-zero."); | |
| 444 else | |
| 445 testFailed(_a + " should be non-zero. Was " + _av); | |
| 446 } | |
| 447 | |
| 448 function shouldBeNonNull(_a) | |
| 449 { | |
| 450 var exception; | |
| 451 var _av; | |
| 452 try { | |
| 453 _av = eval(_a); | |
| 454 } catch (e) { | |
| 455 exception = e; | |
| 456 } | |
| 457 | |
| 458 if (exception) | |
| 459 testFailed(_a + " should be non-null. Threw exception " + exception); | |
| 460 else if (_av != null) | |
| 461 testPassed(_a + " is non-null."); | |
| 462 else | |
| 463 testFailed(_a + " should be non-null. Was " + _av); | |
| 464 } | |
| 465 | |
| 466 function shouldBeUndefined(_a) | |
| 467 { | |
| 468 var exception; | |
| 469 var _av; | |
| 470 try { | |
| 471 _av = eval(_a); | |
| 472 } catch (e) { | |
| 473 exception = e; | |
| 474 } | |
| 475 | |
| 476 if (exception) | |
| 477 testFailed(_a + " should be undefined. Threw exception " + exception); | |
| 478 else if (typeof _av == "undefined") | |
| 479 testPassed(_a + " is undefined."); | |
| 480 else | |
| 481 testFailed(_a + " should be undefined. Was " + _av); | |
| 482 } | |
| 483 | |
| 484 function shouldBeDefined(_a) | |
| 485 { | |
| 486 var exception; | |
| 487 var _av; | |
| 488 try { | |
| 489 _av = eval(_a); | |
| 490 } catch (e) { | |
| 491 exception = e; | |
| 492 } | |
| 493 | |
| 494 if (exception) | |
| 495 testFailed(_a + " should be defined. Threw exception " + exception); | |
| 496 else if (_av !== undefined) | |
| 497 testPassed(_a + " is defined."); | |
| 498 else | |
| 499 testFailed(_a + " should be defined. Was " + _av); | |
| 500 } | |
| 501 | |
| 502 function shouldBeGreaterThanOrEqual(_a, _b) { | |
| 503 if (typeof _a != "string" || typeof _b != "string") | |
| 504 debug("WARN: shouldBeGreaterThanOrEqual expects string arguments"); | |
| 505 | |
| 506 var exception; | |
| 507 var _av; | |
| 508 try { | |
| 509 _av = eval(_a); | |
| 510 } catch (e) { | |
| 511 exception = e; | |
| 512 } | |
| 513 var _bv = eval(_b); | |
| 514 | |
| 515 if (exception) | |
| 516 testFailed(_a + " should be >= " + _b + ". Threw exception " + exception
); | |
| 517 else if (typeof _av == "undefined" || _av < _bv) | |
| 518 testFailed(_a + " should be >= " + _b + ". Was " + _av + " (of type " +
typeof _av + ")."); | |
| 519 else | |
| 520 testPassed(_a + " is >= " + _b); | |
| 521 } | |
| 522 | |
| 523 function shouldNotThrow(_a) { | |
| 524 try { | |
| 525 eval(_a); | |
| 526 testPassed(_a + " did not throw exception."); | |
| 527 } catch (e) { | |
| 528 testFailed(_a + " should not throw exception. Threw exception " + e + ".
"); | |
| 529 } | |
| 530 } | |
| 531 | |
| 532 function shouldThrow(_a, _e) | |
| 533 { | |
| 534 var exception; | |
| 535 var _av; | |
| 536 try { | |
| 537 _av = eval(_a); | |
| 538 } catch (e) { | |
| 539 exception = e; | |
| 540 } | |
| 541 | |
| 542 var _ev; | |
| 543 if (_e) | |
| 544 _ev = eval(_e); | |
| 545 | |
| 546 if (exception) { | |
| 547 if (typeof _e == "undefined" || exception == _ev) | |
| 548 testPassed(_a + " threw exception " + exception + "."); | |
| 549 else | |
| 550 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an excepti
on" : _ev) + ". Threw exception " + exception + "."); | |
| 551 } else if (typeof _av == "undefined") | |
| 552 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception
" : _ev) + ". Was undefined."); | |
| 553 else | |
| 554 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception
" : _ev) + ". Was " + _av + "."); | |
| 555 } | |
| 556 | |
| 557 function shouldHaveHadError(message) | |
| 558 { | |
| 559 if (errorMessage) { | |
| 560 if (!message) | |
| 561 testPassed("Got expected error"); | |
| 562 else if (errorMessage.indexOf(message) !== -1) | |
| 563 testPassed("Got expected error: '" + message + "'"); | |
| 564 else | |
| 565 testFailed("Unexpexted error '" + message + "'"); | |
| 566 } else | |
| 567 testFailed("Missing expexted error"); | |
| 568 errorMessage = undefined; | |
| 569 } | |
| 570 | |
| 571 function gc() { | |
| 572 if (typeof GCController !== "undefined") | |
| 573 GCController.collect(); | |
| 574 else { | |
| 575 var gcRec = function (n) { | |
| 576 if (n < 1) | |
| 577 return {}; | |
| 578 var temp = {i: "ab" + i + (i / 100000)}; | |
| 579 temp += "foo"; | |
| 580 gcRec(n-1); | |
| 581 }; | |
| 582 for (var i = 0; i < 1000; i++) | |
| 583 gcRec(10) | |
| 584 } | |
| 585 } | |
| 586 | |
| 587 function minorGC() { | |
| 588 if (typeof GCController !== "undefined") | |
| 589 GCController.minorCollect(); | |
| 590 else | |
| 591 testFailed("Minor GC is available only when you enable the --expose-gc o
ption in V8."); | |
| 592 } | |
| 593 | |
| 594 function isSuccessfullyParsed() | |
| 595 { | |
| 596 // FIXME: Remove this and only report unexpected syntax errors. | |
| 597 if (!errorMessage) | |
| 598 successfullyParsed = true; | |
| 599 shouldBeTrue("successfullyParsed"); | |
| 600 debug('<br /><span class="pass">TEST COMPLETE</span>'); | |
| 601 } | |
| 602 | |
| 603 // It's possible for an async test to call finishJSTest() before js-test-post.js | |
| 604 // has been parsed. | |
| 605 function finishJSTest() | |
| 606 { | |
| 607 wasFinishJSTestCalled = true; | |
| 608 if (!self.wasPostTestScriptParsed) | |
| 609 return; | |
| 610 isSuccessfullyParsed(); | |
| 611 if (self.jsTestIsAsync && self.testRunner) | |
| 612 testRunner.notifyDone(); | |
| 613 } | |
| 614 | |
| 615 function startWorker(testScriptURL, shared) | |
| 616 { | |
| 617 self.jsTestIsAsync = true; | |
| 618 debug('Starting worker: ' + testScriptURL); | |
| 619 var worker = shared ? new SharedWorker(testScriptURL, "Shared Worker") : new
Worker(testScriptURL); | |
| 620 worker.onmessage = function(event) | |
| 621 { | |
| 622 var workerPrefix = "[Worker] "; | |
| 623 if (event.data.length < 5 || event.data.charAt(4) != ':') { | |
| 624 debug(workerPrefix + event.data); | |
| 625 return; | |
| 626 } | |
| 627 var code = event.data.substring(0, 4); | |
| 628 var payload = workerPrefix + event.data.substring(5); | |
| 629 if (code == "PASS") | |
| 630 testPassed(payload); | |
| 631 else if (code == "FAIL") | |
| 632 testFailed(payload); | |
| 633 else if (code == "DESC") | |
| 634 description(payload); | |
| 635 else if (code == "DONE") | |
| 636 finishJSTest(); | |
| 637 else | |
| 638 debug(workerPrefix + event.data); | |
| 639 }; | |
| 640 | |
| 641 worker.onerror = function(event) | |
| 642 { | |
| 643 debug('Got error from worker: ' + event.message); | |
| 644 finishJSTest(); | |
| 645 } | |
| 646 | |
| 647 if (shared) { | |
| 648 worker.port.onmessage = function(event) { worker.onmessage(event); }; | |
| 649 worker.port.start(); | |
| 650 } | |
| 651 return worker; | |
| 652 } | |
| 653 | |
| 654 if (isWorker()) { | |
| 655 var workerPort = self; | |
| 656 if (self.name == "Shared Worker") { | |
| 657 self.onconnect = function(e) { | |
| 658 workerPort = e.ports[0]; | |
| 659 workerPort.onmessage = function(event) | |
| 660 { | |
| 661 var colon = event.data.indexOf(":"); | |
| 662 if (colon == -1) { | |
| 663 testFailed("Unrecognized message to shared worker: " + event
.data); | |
| 664 return; | |
| 665 } | |
| 666 var code = event.data.substring(0, colon); | |
| 667 var payload = event.data.substring(colon + 1); | |
| 668 try { | |
| 669 if (code == "IMPORT") | |
| 670 importScripts(payload); | |
| 671 else | |
| 672 testFailed("Unrecognized message to shared worker: " + e
vent.data); | |
| 673 } catch (ex) { | |
| 674 testFailed("Caught exception in shared worker onmessage: " +
ex); | |
| 675 } | |
| 676 }; | |
| 677 }; | |
| 678 } | |
| 679 description = function(msg, quiet) { | |
| 680 workerPort.postMessage('DESC:' + msg); | |
| 681 } | |
| 682 testFailed = function(msg) { | |
| 683 workerPort.postMessage('FAIL:' + msg); | |
| 684 } | |
| 685 testPassed = function(msg) { | |
| 686 workerPort.postMessage('PASS:' + msg); | |
| 687 } | |
| 688 finishJSTest = function() { | |
| 689 workerPort.postMessage('DONE:'); | |
| 690 } | |
| 691 debug = function(msg) { | |
| 692 workerPort.postMessage(msg); | |
| 693 } | |
| 694 } | |
| OLD | NEW |