Truly independent web browser
Tests/LibWeb: Add a test for a WebSocket handshake that gets no response
Andreas Klinga8f7726f25fa
diff --git a/Tests/LibWeb/Fixtures/http-test-server.py b/Tests/LibWeb/Fixtures/http-test-server.pyindex 397cdc8248b..7bff6391fe3 100755--- a/Tests/LibWeb/Fixtures/http-test-server.py+++ b/Tests/LibWeb/Fixtures/http-test-server.py@@ -45,6 +45,8 @@ Endpoints:server first sends a binary frame of that many bytes: a 1, zeros, and then a 2.- GET /reflect-websocket-cookie with an "Upgrade: websocket" header: As above, but first sends thehandshake's Cookie header (or an empty string) as a text frame.+ - GET /websocket-close-without-response with an "Upgrade: websocket" header: Closes the connection without+ responding to the handshake.- GET /recorded-request-count/<echo path>: Responds with the number of requests the server has seen at <echo path>,with any query ignored.- GET /downloads/<name>: Reports the browser's download of <name> into the --downloads-directory: 404 while@@ -789,6 +791,10 @@ class TestHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):# text/binary frame it sends is echoed back verbatim.def _serve_websocket_echo(self):+ if self.path == "/websocket-close-without-response":+ self.close_connection = True+ return+key = self.headers.get("Sec-WebSocket-Key")if not key:self.send_error(400, "Missing Sec-WebSocket-Key")diff --git a/Tests/LibWeb/Text/expected/WebSocket/handshake-without-response.txt b/Tests/LibWeb/Text/expected/WebSocket/handshake-without-response.txtnew file mode 100644index 00000000000..a6755773c88--- /dev/null+++ b/Tests/LibWeb/Text/expected/WebSocket/handshake-without-response.txt@@ -0,0 +1,2 @@+open+close, readyState: 3, wasClean: true, code: 1005diff --git a/Tests/LibWeb/Text/input/WebSocket/handshake-without-response.html b/Tests/LibWeb/Text/input/WebSocket/handshake-without-response.htmlnew file mode 100644index 00000000000..b468b8f4c49--- /dev/null+++ b/Tests/LibWeb/Text/input/WebSocket/handshake-without-response.html@@ -0,0 +1,18 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ // A server that closes the connection without responding to the opening handshake must fail the connection.+ asyncTest(done => {+ const ws = new WebSocket(`ws://localhost:${internals.getEchoServerPort()}/websocket-close-without-response`);+ ws.onopen = () => {+ println("open");+ };+ ws.onerror = () => {+ println(`error, readyState: ${ws.readyState}`);+ };+ ws.onclose = event => {+ println(`close, readyState: ${ws.readyState}, wasClean: ${event.wasClean}, code: ${event.code}`);+ done();+ };+ });+</script>