2 <p>Test Worker constructor functionality. Should print a series of PASS messages, followed with DONE.</p>
7 document.getElementById("result").innerHTML += message + "<br>";
11 "testArgumentException",
12 "testRecursiveWorkerCreation",
15 "testInvalidScriptUrl",
16 "testNotExistentScriptUrl",
17 "testSuccessWorkerCreation",
21 function runNextTest()
23 if (testIndex < testCases.length) {
25 window[testCases[testIndex - 1]]();
28 if (window.layoutTestController)
29 layoutTestController.notifyDone();
33 function testArgumentException()
36 new Worker({toString:function(){throw "exception"}})
37 log("FAIL: toString exception not propagated.");
39 if (ex == "exception")
40 log("PASS: toString exception propagated correctly.");
42 log("FAIL: unexpected exception (" + ex + ") received instead of one propagated from toString.");
47 function testRecursiveWorkerCreation()
50 var foo = {toString:function(){new Worker(foo)}}
52 log("FAIL: no exception when trying to create workers recursively");
54 log("PASS: trying to create workers recursively resulted in an exception (" + ex + ")");
59 function testNoArgument()
63 log("FAIL: invoking Worker constructor without arguments did not result in an exception");
65 log("PASS: invoking Worker constructor without arguments resulted in an exception (" + ex + ")");
70 function testEmptyScriptUrl()
73 var worker = new Worker("");
74 worker.onerror = function() {
75 log("PASS: onerror invoked for an empty script URL.");
79 log("FAIL: unexpected exception " + ex);
84 function testInvalidScriptUrl()
87 var worker = new Worker("invalidurl://");
88 worker.onerror = function() {
89 log("PASS: onerror invoked for an invalid script URL.");
93 log("FAIL: unexpected exception " + ex);
98 function testNotExistentScriptUrl()
101 var worker = new Worker("does-not-exist.js");
102 worker.onerror = function() {
103 log("PASS: onerror invoked for a script that could not be loaded.");
107 log("FAIL: unexpected exception " + ex);
112 function testSuccessWorkerCreation()
115 var worker = new Worker("resources/worker-common.js");
116 // Make sure attributes from both Worker and AbstractWorker are visible.
117 if (!worker.postMessage)
118 log("FAIL: worker.postMessage did not exist.");
119 else if (!worker.addEventListener)
120 log("FAIL: worker.addEventListener did not exist.");
122 log("PASS: Successfully created worker.");
124 log("FAIL: unexpected exception (" + ex + ") thrown when creating worker");
129 if (window.layoutTestController) {
130 layoutTestController.dumpAsText();
131 layoutTestController.waitUntilDone();