diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/wpt/tests/websockets/constants.sub.js | |
parent | Initial commit. (diff) | |
download | node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/wpt/tests/websockets/constants.sub.js')
-rw-r--r-- | test/wpt/tests/websockets/constants.sub.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/test/wpt/tests/websockets/constants.sub.js b/test/wpt/tests/websockets/constants.sub.js new file mode 100644 index 0000000..fd3c3b8 --- /dev/null +++ b/test/wpt/tests/websockets/constants.sub.js @@ -0,0 +1,94 @@ +const __SERVER__NAME = "{{host}}"; +const __PATH = "echo"; + +let __SCHEME; +let __PORT; +if (url_has_flag('h2')) { + __SCHEME = 'wss'; + __PORT = "{{ports[h2][0]}}"; +} else if (url_has_variant('wss') || location.protocol === 'https:') { + __SCHEME = 'wss'; + __PORT = "{{ports[wss][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 CreateInsecureWebSocket() { + IsWebSocket(); + const url = `ws://${__SERVER__NAME}:{{ports[ws][0]}}/${__PATH}`; + return new WebSocket(url); +} + +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); +} |