summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/websockets/cookies/support
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/websockets/cookies/support')
-rw-r--r--testing/web-platform/tests/websockets/cookies/support/set-cookie.py7
-rw-r--r--testing/web-platform/tests/websockets/cookies/support/websocket-cookies-helper.sub.js57
2 files changed, 64 insertions, 0 deletions
diff --git a/testing/web-platform/tests/websockets/cookies/support/set-cookie.py b/testing/web-platform/tests/websockets/cookies/support/set-cookie.py
new file mode 100644
index 0000000000..71cd8bca60
--- /dev/null
+++ b/testing/web-platform/tests/websockets/cookies/support/set-cookie.py
@@ -0,0 +1,7 @@
+from urllib.parse import unquote
+
+from wptserve.utils import isomorphic_encode
+
+def main(request, response):
+ response.headers.set(b'Set-Cookie', isomorphic_encode(unquote(request.url_parts.query)))
+ return [(b"Content-Type", b"text/plain")], b""
diff --git a/testing/web-platform/tests/websockets/cookies/support/websocket-cookies-helper.sub.js b/testing/web-platform/tests/websockets/cookies/support/websocket-cookies-helper.sub.js
new file mode 100644
index 0000000000..a7fae2551e
--- /dev/null
+++ b/testing/web-platform/tests/websockets/cookies/support/websocket-cookies-helper.sub.js
@@ -0,0 +1,57 @@
+// Set up global variables.
+(_ => {
+ var HOST = '{{host}}';
+ var CROSS_ORIGIN_HOST = '{{hosts[alt][]}}';
+ var WSS_PORT = ':{{ports[wss][0]}}';
+ var HTTPS_PORT = ':{{ports[https][0]}}';
+
+ window.WSS_ORIGIN = 'wss://' + HOST + WSS_PORT;
+ window.WSS_CROSS_SITE_ORIGIN = 'wss://' + CROSS_ORIGIN_HOST + WSS_PORT;
+ window.HTTPS_ORIGIN = 'https://' + HOST + HTTPS_PORT;
+ window.HTTPS_CROSS_SITE_ORIGIN = 'https://' + CROSS_ORIGIN_HOST + HTTPS_PORT;
+})();
+
+// Sets a cookie with each SameSite option.
+function setSameSiteCookies(origin, value) {
+ return new Promise(resolve => {
+ const ws = new WebSocket(origin + '/set-cookies-samesite?value=' + value);
+ ws.onopen = () => {
+ ws.close();
+ };
+ ws.onclose = resolve;
+ });
+}
+
+// Clears cookies set by setSameSiteCookies().
+function clearSameSiteCookies(origin) {
+ return new Promise(resolve => {
+ const ws = new WebSocket(origin + '/set-cookies-samesite?clear');
+ ws.onopen = () => ws.close();
+ ws.onclose = resolve;
+ });
+}
+
+// Gets value of Cookie header sent in request.
+function connectAndGetRequestCookiesFrom(origin) {
+ return new Promise((resolve, reject) => {
+ var ws = new WebSocket(origin + '/echo-cookie');
+ ws.onmessage = evt => {
+ var cookies = evt.data
+ resolve(cookies);
+ ws.onerror = undefined;
+ ws.onclose = undefined;
+ };
+ ws.onerror = () => reject('Unexpected error event');
+ ws.onclose = evt => reject('Unexpected close event: ' + JSON.stringify(evt));
+ });
+}
+
+// Assert that a given cookie is or is not present in the string |cookies|.
+function assertCookie(cookies, name, value, present) {
+ var assertion = present ? assert_true : assert_false;
+ var description = name + '=' + value + ' cookie is' +
+ (present ? ' ' : ' not ') + 'present.';
+ var re = new RegExp('(?:^|; )' + name + '=' + value + '(?:$|;)');
+ assertion(re.test(cookies), description);
+}
+