summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/websockets/constants.sub.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/websockets/constants.sub.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/websockets/constants.sub.js')
-rw-r--r--testing/web-platform/tests/websockets/constants.sub.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/testing/web-platform/tests/websockets/constants.sub.js b/testing/web-platform/tests/websockets/constants.sub.js
new file mode 100644
index 0000000000..d8e340d304
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constants.sub.js
@@ -0,0 +1,88 @@
+const __SERVER__NAME = "{{host}}";
+const __PATH = "echo";
+
+var __SCHEME;
+var __PORT;
+if (url_has_variant('wss')) {
+ __SCHEME = 'wss';
+ __PORT = "{{ports[wss][0]}}";
+} else if (url_has_flag('h2')) {
+ __SCHEME = 'wss';
+ __PORT = "{{ports[h2][0]}}";
+} else {
+ __SCHEME = 'ws';
+ __PORT = "{{ports[ws][0]}}";
+}
+
+const SCHEME_DOMAIN_PORT = __SCHEME + '://' + __SERVER__NAME + ':' + __PORT;
+
+function url_has_variant(variant) {
+ const params = new URLSearchParams(location.search);
+ return params.get(variant) === "";
+}
+
+function url_has_flag(flag) {
+ const params = new URLSearchParams(location.search);
+ return params.getAll("wpt_flags").indexOf(flag) !== -1;
+}
+
+function IsWebSocket() {
+ if (!self.WebSocket) {
+ assert_true(false, "Browser does not support WebSocket");
+ }
+}
+
+function CreateWebSocketNonAsciiProtocol(nonAsciiProtocol) {
+ IsWebSocket();
+ const url = SCHEME_DOMAIN_PORT + "/" + __PATH;
+ return new WebSocket(url, nonAsciiProtocol);
+}
+
+function CreateWebSocketWithAsciiSep(asciiWithSep) {
+ IsWebSocket();
+ const url = SCHEME_DOMAIN_PORT + "/" + __PATH;
+ return new WebSocket(url, asciiWithSep);
+}
+
+function CreateWebSocketWithBlockedPort(blockedPort) {
+ IsWebSocket();
+ const url = __SCHEME + "://" + __SERVER__NAME + ":" + blockedPort + "/" + __PATH;
+ return new WebSocket(url);
+}
+
+function CreateWebSocketWithSpaceInUrl(urlWithSpace) {
+ IsWebSocket();
+ const url = __SCHEME + "://" + urlWithSpace + ":" + __PORT + "/" + __PATH;
+ return new WebSocket(url);
+}
+
+function CreateWebSocketWithSpaceInProtocol(protocolWithSpace) {
+ IsWebSocket();
+ const url = SCHEME_DOMAIN_PORT + "/" + __PATH;
+ return new WebSocket(url, protocolWithSpace);
+}
+
+function CreateWebSocketWithRepeatedProtocols() {
+ IsWebSocket();
+ const url = SCHEME_DOMAIN_PORT + "/" + __PATH;
+ return new WebSocket(url, ["echo", "echo"]);
+}
+
+function CreateWebSocketWithRepeatedProtocolsCaseInsensitive() {
+ IsWebSocket();
+ const url = SCHEME_DOMAIN_PORT + "/" + __PATH;
+ wsocket = new WebSocket(url, ["echo", "eCho"]);
+}
+
+function CreateWebSocket(isProtocol, isProtocols) {
+ IsWebSocket();
+ const url = SCHEME_DOMAIN_PORT + "/" + __PATH;
+
+ if (isProtocol) {
+ return new WebSocket(url, "echo");
+ }
+ if (isProtocols) {
+ return new WebSocket(url, ["echo", "chat"]);
+ }
+ return new WebSocket(url);
+}