Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/websocket/resources/simple.js |
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/websocket/resources/simple.js b/third_party/WebKit/LayoutTests/http/tests/serviceworker/websocket/resources/simple.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6b7c5ec81fb115c2628306115ca512eb66c7f77d |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/websocket/resources/simple.js |
@@ -0,0 +1,35 @@ |
+let port; |
+let received = false; |
+ |
+function reportFailure(details) { |
+ port.postMessage('FAIL: ' + details); |
+} |
+ |
+onmessage = event => { |
+ port = event.source; |
+ |
+ const ws = new WebSocket('ws://localhost:8880/echo'); |
+ ws.onopen = () => { |
+ ws.send('Hello'); |
+ }; |
+ ws.onmessage = msg => { |
+ if (msg.data !== 'Hello') { |
+ reportFailure('Unexpected reply: ' + msg.data); |
+ return; |
+ } |
+ |
+ received = true; |
+ ws.close(); |
+ }; |
+ ws.onclose = () => { |
+ if (!received) { |
+ reportFailure('Closed before receiving reply'); |
+ return; |
+ } |
+ |
+ port.postMessage('PASS'); |
+ }; |
+ ws.onerror = () => { |
+ reportFailure('Got an error event'); |
+ }; |
+}; |