summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/third_party/websockets/experiments/authentication/cookie.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/tools/third_party/websockets/experiments/authentication/cookie.js')
-rw-r--r--testing/web-platform/tests/tools/third_party/websockets/experiments/authentication/cookie.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/third_party/websockets/experiments/authentication/cookie.js b/testing/web-platform/tests/tools/third_party/websockets/experiments/authentication/cookie.js
new file mode 100644
index 0000000000..2cca34fcbb
--- /dev/null
+++ b/testing/web-platform/tests/tools/third_party/websockets/experiments/authentication/cookie.js
@@ -0,0 +1,23 @@
+// send token to iframe
+window.addEventListener("DOMContentLoaded", () => {
+ const iframe = document.querySelector("iframe");
+ iframe.addEventListener("load", () => {
+ iframe.contentWindow.postMessage(token, "http://localhost:8003");
+ });
+});
+
+// once iframe has set cookie, open WebSocket connection
+window.addEventListener("message", ({ origin }) => {
+ if (origin !== "http://localhost:8003") {
+ return;
+ }
+
+ const websocket = new WebSocket("ws://localhost:8003/");
+
+ websocket.onmessage = ({ data }) => {
+ // event.data is expected to be "Hello <user>!"
+ websocket.send(`Goodbye ${data.slice(6, -1)}.`);
+ };
+
+ runTest(websocket);
+});