[WebSocket]The minimal number of bytes MUST be used to encode the length
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / hybi / masked-frames.html
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <script src="../../../../js-test-resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <div id="description"></div>
8 <div id="console"></div>
9 <script>
10 description("Receive masked WebSocket frames.");
11
12 window.jsTestIsAsync = true;
13 if (window.layoutTestController)
14     layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
15
16 var url = "ws://localhost:8880/websocket/tests/hybi/masked-frames";
17 var ws = new WebSocket(url);
18 var closeEvent;
19 var expectedMessages = ["First message", "Fragmented message", ""];
20 var actualMessages = [];
21
22 ws.onopen = function()
23 {
24     debug("onopen() was called.");
25     ws.close();
26 };
27
28 ws.onmessage = function(event)
29 {
30     var message = event.data;
31     debug("onmessage() was called. (message = \"" + message + "\")");
32     if (message === "END") {
33         ws.close();
34         return;
35     }
36     actualMessages.push(message);
37 };
38
39 ws.onclose = function(event)
40 {
41     closeEvent = event;
42     shouldBeTrue("actualMessages.length === expectedMessages.length");
43     for (var i = 0; i < expectedMessages.length; ++i)
44         shouldBeEqualToString("actualMessages[" + i + "]", expectedMessages[i]);
45     shouldBeTrue("closeEvent.wasClean");
46     finishJSTest();
47 };
48
49 </script>
50 <script src="../../../../js-test-resources/js-test-post.js"></script>
51 </body>
52 </html>