WebSocket's MessageEvent.origin attribute is an empty string
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / hybi / send-blob-onmessage-origin.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../../js-test-resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <script>
8 description("Web Socket message event origin attribute test (Blob message)");
9
10 window.jsTestIsAsync = true;
11 var data = "";
12 var origin = "";
13
14 function startsWith(target, prefix)
15 {
16     return target.indexOf(prefix) === 0;
17 }
18
19 function createBlobContainingHelloWorld()
20 {
21     return new Blob(["Hello, world!"]);
22 }
23
24 function createEmptyBlob()
25 {
26     return new Blob([]);
27 }
28
29 function createBlobContainingAllDistinctBytes()
30 {
31     var array = new Uint8Array(256);
32     for (var i = 0; i < 256; ++i)
33         array[i] = i;
34     return new Blob([array]);
35 }
36
37 var url = "ws://127.0.0.1:8880/websocket/tests/hybi/check-binary-messages";
38 var ws = new WebSocket(url);
39 var closeEvent;
40
41 ws.onopen = function()
42 {
43     ws.send(createBlobContainingHelloWorld());
44     ws.send(createEmptyBlob());
45     ws.send(createBlobContainingAllDistinctBytes());
46 };
47
48 ws.onmessage = function(event)
49 {
50     var message = event.data;
51     if (startsWith(message, "PASS"))
52         testPassed(message);
53     else
54         testFailed(message);
55     origin = event.origin;
56     shouldBeEqualToString("origin", "ws://127.0.0.1:8880");
57 };
58
59 ws.onclose = function(event)
60 {
61     closeEvent = event;
62     shouldBeTrue("closeEvent.wasClean");
63     finishJSTest();
64 };
65
66 </script>
67 <script src="../../../../js-test-resources/js-test-post.js"></script>
68 </body>
69 </html>