1 if (window.testRunner) {
2 testRunner.dumpAsText();
3 testRunner.waitUntilDone();
6 description("Checks the various use cases around the SharedWorker constructor's optional name parameter");
11 // Iterates through the tests until none are left.
15 var testFunction = window["test" + currentTest];
24 // Make sure we can create a shared worker with no name.
26 var worker = new SharedWorker('resources/shared-worker-common.js');
27 testPassed("created SharedWorker with no name");
28 worker.port.postMessage("eval self.foo = 1234");
29 worker.port.onmessage = function(event) {
30 shouldBeEqual("setting self.foo", event.data, "self.foo = 1234: 1234");
34 testFailed("SharedWorker with no name threw an exception: " + e);
41 // Creating a worker with no name should match an existing worker with no name
42 var worker = new SharedWorker('resources/shared-worker-common.js');
43 worker.port.postMessage("eval self.foo");
44 worker.port.onmessage = function(event) {
45 shouldBeEqual("creating worker with no name", event.data, "self.foo: 1234");
52 // Creating a worker with an empty name should be the same as a worker with no name.
53 var worker = new SharedWorker('resources/shared-worker-common.js', '');
54 worker.port.postMessage("eval self.foo");
55 worker.port.onmessage = function(event) {
56 shouldBeEqual("creating worker with empty name", event.data, "self.foo: 1234");
63 // Creating a worker with an undefined name should match an existing worker with no name.
64 var worker = new SharedWorker('resources/shared-worker-common.js', undefined);
65 worker.port.postMessage("eval self.foo");
66 worker.port.onmessage = function(event) {
67 shouldBeEqual("creating worker with an undefined name", event.data, "self.foo: 1234");
74 // Creating a worker with a different name should not be the same as a worker with no name.
75 var worker = new SharedWorker('resources/shared-worker-common.js', 'name');
76 worker.port.postMessage("eval self.foo");
77 worker.port.onmessage = function(event) {
78 shouldBeEqual("creating worker with different name but same URL", event.data, "self.foo: undefined");
85 // Creating a worker for an alternate URL with no name should work.
86 var worker = new SharedWorker('resources/shared-worker-common.js?url=1');
87 worker.port.postMessage("eval self.foo");
88 worker.port.onmessage = function(event) {
89 shouldBeEqual("creating no-name worker with alternate URL", event.data, "self.foo: undefined");
96 // Creating a worker for an alternate URL with empty name should work.
97 var worker = new SharedWorker('resources/shared-worker-common.js?url=2', '');
98 worker.port.postMessage("eval self.foo");
99 worker.port.onmessage = function(event) {
100 shouldBeEqual("creating empty name worker with alternate URL", event.data, "self.foo: undefined");
107 // Make sure we can create a shared worker with name 'null'.
109 var worker = new SharedWorker('resources/shared-worker-common.js', 'null');
110 testPassed("created SharedWorker with name 'null'");
111 worker.port.postMessage("eval self.foo = 5678");
112 worker.port.onmessage = function(event) {
113 shouldBeEqual("setting self.foo", event.data, "self.foo = 5678: 5678");
117 testFailed("SharedWorker with name 'null' threw an exception: " + e);
124 // Creating a worker with a null name should match an existing worker with name 'null'
125 var worker = new SharedWorker('resources/shared-worker-common.js', null);
126 worker.port.postMessage("eval self.foo");
127 worker.port.onmessage = function(event) {
128 shouldBeEqual("creating worker with a null name", event.data, "self.foo: 5678");
135 // Creating a worker with a specific name, the name attribute should be set to worker correctly.
136 var worker = new SharedWorker('resources/shared-worker-common.js', "testingNameAttribute");
137 worker.port.postMessage("testingNameAttribute");
138 worker.port.onmessage = function(event) {
139 shouldBeEqual("the name attribute of worker can be set correctly", event.data, "testingNameAttribute");
144 function shouldBeEqual(description, a, b)
147 testPassed(description);
149 testFailed(description + " - passed value: " + a + ", expected value: " + b);