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 a different name should not be the same as a worker with no name.
64 var worker = new SharedWorker('resources/shared-worker-common.js', 'name');
65 worker.port.postMessage("eval self.foo");
66 worker.port.onmessage = function(event) {
67 shouldBeEqual("creating worker with different name but same URL", event.data, "self.foo: undefined");
74 // Creating a worker for an alternate URL with no name should work.
75 var worker = new SharedWorker('resources/shared-worker-common.js?url=1');
76 worker.port.postMessage("eval self.foo");
77 worker.port.onmessage = function(event) {
78 shouldBeEqual("creating no-name worker with alternate URL", event.data, "self.foo: undefined");
85 // Creating a worker for an alternate URL with empty name should work.
86 var worker = new SharedWorker('resources/shared-worker-common.js?url=2', '');
87 worker.port.postMessage("eval self.foo");
88 worker.port.onmessage = function(event) {
89 shouldBeEqual("creating empty name worker with alternate URL", event.data, "self.foo: undefined");
96 // Make sure we can create a shared worker with name 'null'.
98 var worker = new SharedWorker('resources/shared-worker-common.js', 'null');
99 testPassed("created SharedWorker with name 'null'");
100 worker.port.postMessage("eval self.foo = 5678");
101 worker.port.onmessage = function(event) {
102 shouldBeEqual("setting self.foo", event.data, "self.foo = 5678: 5678");
106 testFailed("SharedWorker with name 'null' threw an exception: " + e);
113 // Creating a worker with a null name should match an existing worker with name 'null'
114 var worker = new SharedWorker('resources/shared-worker-common.js', null);
115 worker.port.postMessage("eval self.foo");
116 worker.port.onmessage = function(event) {
117 shouldBeEqual("creating worker with a null name", event.data, "self.foo: 5678");
124 // Make sure we can create a shared worker with name 'undefined'.
126 var worker = new SharedWorker('resources/shared-worker-common.js', 'undefined');
127 testPassed("created SharedWorker with name 'undefined'");
128 worker.port.postMessage("eval self.foo = 1111");
129 worker.port.onmessage = function(event) {
130 shouldBeEqual("setting self.foo", event.data, "self.foo = 1111: 1111");
134 testFailed("SharedWorker with name 'undefined' threw an exception: " + e);
141 // Creating a worker with an undefined name should match an existing worker with name 'undefined'
142 var worker = new SharedWorker('resources/shared-worker-common.js', undefined);
143 worker.port.postMessage("eval self.foo");
144 worker.port.onmessage = function(event) {
145 shouldBeEqual("creating worker with an undefined name", event.data, "self.foo: 1111");
152 // Creating a worker with a specific name, the name attribute should be set to worker correctly.
153 var worker = new SharedWorker('resources/shared-worker-common.js', "testingNameAttribute");
154 worker.port.postMessage("testingNameAttribute");
155 worker.port.onmessage = function(event) {
156 shouldBeEqual("the name attribute of worker can be set correctly", event.data, "testingNameAttribute");
161 function shouldBeEqual(description, a, b)
164 testPassed(description);
166 testFailed(description + " - passed value: " + a + ", expected value: " + b);