| Index: chrome/test/data/subresource_filter/websocket_connection.js
|
| diff --git a/chrome/test/data/subresource_filter/websocket_connection.js b/chrome/test/data/subresource_filter/websocket_connection.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4d5db4cb67fb48281f0c2b8abd3eb0bae616ba03
|
| --- /dev/null
|
| +++ b/chrome/test/data/subresource_filter/websocket_connection.js
|
| @@ -0,0 +1,32 @@
|
| +// Note: This JS can run either in a worker or as a script in the main document
|
| +// context.
|
| +function connectWebSocket(url, inWorker) {
|
| + function messageMainContext(data) {
|
| + if (inWorker)
|
| + self.postMessage(data);
|
| + else
|
| + self.postMessage(data, location);
|
| + }
|
| + var ws = new WebSocket(url);
|
| +
|
| + ws.addEventListener('open', function() {
|
| + ws.send('hello world');
|
| + });
|
| +
|
| + ws.addEventListener('close', function() {
|
| + messageMainContext("onclose");
|
| + });
|
| +
|
| + ws.addEventListener('message', function() {
|
| + messageMainContext('onmessage');
|
| + });
|
| +}
|
| +
|
| +self.addEventListener('message', function(e) {
|
| + // Will only receive a message with a URL in it if this JS is executing in a
|
| + // worker.
|
| + if (e.data.url) {
|
| + connectWebSocket(e.data.url, true /* inWorker */);
|
| + }
|
| +});
|
| +
|
|
|