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