Chromium Code Reviews| Index: net/data/websocket/websocket_worker_simple.js |
| diff --git a/net/data/websocket/websocket_worker_simple.js b/net/data/websocket/websocket_worker_simple.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..175d51fad15695d423e990fe14cbf2af83cea015 |
| --- /dev/null |
| +++ b/net/data/websocket/websocket_worker_simple.js |
| @@ -0,0 +1,33 @@ |
| +if (!self.postMessage) { |
| + // This is a shared worker - mimic dedicated worker APIs |
| + onconnect = function(event) { |
| + event.ports[0].onmessage = function(e) { |
| + self.postMessage = function (msg) { |
| + event.ports[0].postMessage(msg); |
| + }; |
| + runTests(e.data); |
| + }; |
| + }; |
| +} else { |
| + runTests(event.data); |
| +} |
| + |
| +// This test is compatible with shared-worker-simple.html layout test. |
| +runTests = function (url) { |
| + var ws; |
| + try { |
| + ws = new WebSocket(url); |
| + ws.onopen = function() { |
| + ws.send("hello"); |
| + }; |
| + ws.onmessage = function() { |
| + // Receive echoed "hello". |
|
Yuta Kitamura
2012/10/15 07:44:37
Don't you check the received message?
Takashi Toyoshima
2012/10/15 08:14:34
Done.
|
| + ws.close(); |
| + }; |
| + ws.onclose = function(e) { |
|
Yuta Kitamura
2012/10/15 07:44:37
Also it's nice to check |e| if possible.
Takashi Toyoshima
2012/10/15 08:14:34
I'll check e.wasClean here.
If you think we shoul
|
| + postMessage("DONE"); |
| + }; |
| + } catch (e) { |
| + postMessage("FAIL: worker: Unexpected exception: " + e); |
| + } |
| +}; |