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
.testRunner
)
29 testRunner
.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(e
) {
75 log("PASS: onerror invoked for an empty script URL, resolving to this HTML document's URL.");
80 log("FAIL: invoking Worker constructor with empty script URL resulted in a exception (" + ex
+ ")");
85 function testInvalidScriptUrl()
88 var worker
= new Worker("http://invalid:123$");
89 worker
.onerror = function() {
90 log("FAIL: onerror invoked for an invalid script URL.");
94 log("PASS: invoking Worker constructor with invalid script URL resulted in an exception (" + ex
+ ")");
99 function testNotExistentScriptUrl()
102 var worker
= new Worker("does-not-exist.js");
103 worker
.onerror = function() {
104 log("PASS: onerror invoked for a script that could not be loaded.");
108 log("FAIL: unexpected exception " + ex
);
113 function testSuccessWorkerCreation()
116 var worker
= new Worker("resources/worker-common.js");
117 // Make sure attributes from both Worker and AbstractWorker are visible.
118 if (!worker
.postMessage
)
119 log("FAIL: worker.postMessage did not exist.");
120 else if (!worker
.addEventListener
)
121 log("FAIL: worker.addEventListener did not exist.");
123 log("PASS: Successfully created worker.");
125 log("FAIL: unexpected exception (" + ex
+ ") thrown when creating worker");
130 if (window
.testRunner
) {
131 testRunner
.dumpAsText();
132 testRunner
.waitUntilDone();