OLD | NEW |
1 if (window.testRunner) { | 1 if (window.testRunner) { |
2 testRunner.dumpAsText(); | 2 testRunner.dumpAsText(); |
3 testRunner.waitUntilDone(); | 3 testRunner.waitUntilDone(); |
4 } | 4 } |
5 | 5 |
6 description("Checks the various use cases around the SharedWorker constructor's
optional name parameter"); | 6 description("Checks the various use cases around the SharedWorker constructor's
optional name parameter"); |
7 | 7 |
8 var currentTest = 0; | 8 var currentTest = 0; |
9 nextTest(); | 9 nextTest(); |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 var worker = new SharedWorker('resources/shared-worker-common.js', ''); | 53 var worker = new SharedWorker('resources/shared-worker-common.js', ''); |
54 worker.port.postMessage("eval self.foo"); | 54 worker.port.postMessage("eval self.foo"); |
55 worker.port.onmessage = function(event) { | 55 worker.port.onmessage = function(event) { |
56 shouldBeEqual("creating worker with empty name", event.data, "self.foo:
1234"); | 56 shouldBeEqual("creating worker with empty name", event.data, "self.foo:
1234"); |
57 nextTest(); | 57 nextTest(); |
58 }; | 58 }; |
59 } | 59 } |
60 | 60 |
61 function test4() | 61 function test4() |
62 { | 62 { |
| 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, "sel
f.foo: 1234"); |
| 68 nextTest(); |
| 69 } |
| 70 } |
| 71 |
| 72 function test5() |
| 73 { |
63 // Creating a worker with a different name should not be the same as a worke
r with no name. | 74 // Creating a worker with a different name should not be the same as a worke
r with no name. |
64 var worker = new SharedWorker('resources/shared-worker-common.js', 'name'); | 75 var worker = new SharedWorker('resources/shared-worker-common.js', 'name'); |
65 worker.port.postMessage("eval self.foo"); | 76 worker.port.postMessage("eval self.foo"); |
66 worker.port.onmessage = function(event) { | 77 worker.port.onmessage = function(event) { |
67 shouldBeEqual("creating worker with different name but same URL", event.
data, "self.foo: undefined"); | 78 shouldBeEqual("creating worker with different name but same URL", event.
data, "self.foo: undefined"); |
68 nextTest(); | 79 nextTest(); |
69 }; | 80 }; |
70 } | 81 } |
71 | 82 |
72 function test5() | 83 function test6() |
73 { | 84 { |
74 // Creating a worker for an alternate URL with no name should work. | 85 // Creating a worker for an alternate URL with no name should work. |
75 var worker = new SharedWorker('resources/shared-worker-common.js?url=1'); | 86 var worker = new SharedWorker('resources/shared-worker-common.js?url=1'); |
76 worker.port.postMessage("eval self.foo"); | 87 worker.port.postMessage("eval self.foo"); |
77 worker.port.onmessage = function(event) { | 88 worker.port.onmessage = function(event) { |
78 shouldBeEqual("creating no-name worker with alternate URL", event.data,
"self.foo: undefined"); | 89 shouldBeEqual("creating no-name worker with alternate URL", event.data,
"self.foo: undefined"); |
79 nextTest(); | 90 nextTest(); |
80 }; | 91 }; |
81 } | 92 } |
82 | 93 |
83 function test6() | 94 function test7() |
84 { | 95 { |
85 // Creating a worker for an alternate URL with empty name should work. | 96 // Creating a worker for an alternate URL with empty name should work. |
86 var worker = new SharedWorker('resources/shared-worker-common.js?url=2', '')
; | 97 var worker = new SharedWorker('resources/shared-worker-common.js?url=2', '')
; |
87 worker.port.postMessage("eval self.foo"); | 98 worker.port.postMessage("eval self.foo"); |
88 worker.port.onmessage = function(event) { | 99 worker.port.onmessage = function(event) { |
89 shouldBeEqual("creating empty name worker with alternate URL", event.dat
a, "self.foo: undefined"); | 100 shouldBeEqual("creating empty name worker with alternate URL", event.dat
a, "self.foo: undefined"); |
90 nextTest(); | 101 nextTest(); |
91 }; | 102 }; |
92 } | 103 } |
93 | 104 |
94 function test7() | 105 function test8() |
95 { | 106 { |
96 // Make sure we can create a shared worker with name 'null'. | 107 // Make sure we can create a shared worker with name 'null'. |
97 try { | 108 try { |
98 var worker = new SharedWorker('resources/shared-worker-common.js', 'null
'); | 109 var worker = new SharedWorker('resources/shared-worker-common.js', 'null
'); |
99 testPassed("created SharedWorker with name 'null'"); | 110 testPassed("created SharedWorker with name 'null'"); |
100 worker.port.postMessage("eval self.foo = 5678"); | 111 worker.port.postMessage("eval self.foo = 5678"); |
101 worker.port.onmessage = function(event) { | 112 worker.port.onmessage = function(event) { |
102 shouldBeEqual("setting self.foo", event.data, "self.foo = 5678: 5678
"); | 113 shouldBeEqual("setting self.foo", event.data, "self.foo = 5678: 5678
"); |
103 nextTest(); | 114 nextTest(); |
104 }; | 115 }; |
105 } catch (e) { | 116 } catch (e) { |
106 testFailed("SharedWorker with name 'null' threw an exception: " + e); | 117 testFailed("SharedWorker with name 'null' threw an exception: " + e); |
107 done(); | 118 done(); |
108 } | 119 } |
109 } | 120 } |
110 | 121 |
111 function test8() | 122 function test9() |
112 { | 123 { |
113 // Creating a worker with a null name should match an existing worker with n
ame 'null' | 124 // Creating a worker with a null name should match an existing worker with n
ame 'null' |
114 var worker = new SharedWorker('resources/shared-worker-common.js', null); | 125 var worker = new SharedWorker('resources/shared-worker-common.js', null); |
115 worker.port.postMessage("eval self.foo"); | 126 worker.port.postMessage("eval self.foo"); |
116 worker.port.onmessage = function(event) { | 127 worker.port.onmessage = function(event) { |
117 shouldBeEqual("creating worker with a null name", event.data, "self.foo:
5678"); | 128 shouldBeEqual("creating worker with a null name", event.data, "self.foo:
5678"); |
118 nextTest(); | 129 nextTest(); |
119 } | 130 } |
120 } | 131 } |
121 | 132 |
122 function test9() | |
123 { | |
124 // Make sure we can create a shared worker with name 'undefined'. | |
125 try { | |
126 var worker = new SharedWorker('resources/shared-worker-common.js', 'unde
fined'); | |
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
"); | |
131 nextTest(); | |
132 }; | |
133 } catch (e) { | |
134 testFailed("SharedWorker with name 'undefined' threw an exception: " + e
); | |
135 done(); | |
136 } | |
137 } | |
138 | |
139 function test10() | 133 function test10() |
140 { | 134 { |
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, "sel
f.foo: 1111"); | |
146 nextTest(); | |
147 } | |
148 } | |
149 | |
150 function test11() | |
151 { | |
152 // Creating a worker with a specific name, the name attribute should be set
to worker correctly. | 135 // 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', "testingN
ameAttribute"); | 136 var worker = new SharedWorker('resources/shared-worker-common.js', "testingN
ameAttribute"); |
154 worker.port.postMessage("testingNameAttribute"); | 137 worker.port.postMessage("testingNameAttribute"); |
155 worker.port.onmessage = function(event) { | 138 worker.port.onmessage = function(event) { |
156 shouldBeEqual("the name attribute of worker can be set correctly", event
.data, "testingNameAttribute"); | 139 shouldBeEqual("the name attribute of worker can be set correctly", event
.data, "testingNameAttribute"); |
157 nextTest(); | 140 nextTest(); |
158 } | 141 } |
159 } | 142 } |
160 | 143 |
161 function shouldBeEqual(description, a, b) | 144 function shouldBeEqual(description, a, b) |
162 { | 145 { |
163 if (a == b) | 146 if (a == b) |
164 testPassed(description); | 147 testPassed(description); |
165 else | 148 else |
166 testFailed(description + " - passed value: " + a + ", expected value: "
+ b); | 149 testFailed(description + " - passed value: " + a + ", expected value: "
+ b); |
167 } | 150 } |
OLD | NEW |