Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 5 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 6 | </head> |
michael@0 | 7 | <body> |
michael@0 | 8 | |
michael@0 | 9 | <p id="display"></p> |
michael@0 | 10 | <div id="content" style="display: none"> |
michael@0 | 11 | </div> |
michael@0 | 12 | <pre id="test"> |
michael@0 | 13 | |
michael@0 | 14 | <script class="testbody" type="text/javascript"> |
michael@0 | 15 | |
michael@0 | 16 | function debug(msg) { |
michael@0 | 17 | ok(1, msg); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | function startsWith(target, prefix) |
michael@0 | 21 | { |
michael@0 | 22 | return target.indexOf(prefix) === 0; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | function createArrayBufferContainingHelloWorld() |
michael@0 | 26 | { |
michael@0 | 27 | var hello = "Hello, world!"; |
michael@0 | 28 | var array = new Uint8Array(hello.length); |
michael@0 | 29 | for (var i = 0; i < hello.length; ++i) |
michael@0 | 30 | array[i] = hello.charCodeAt(i); |
michael@0 | 31 | return array.buffer; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function createEmptyArrayBuffer() |
michael@0 | 35 | { |
michael@0 | 36 | return new ArrayBuffer(0); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function createArrayBufferContainingAllDistinctBytes() |
michael@0 | 40 | { |
michael@0 | 41 | var array = new Uint8Array(256); |
michael@0 | 42 | for (var i = 0; i < 256; ++i) |
michael@0 | 43 | array[i] = i; |
michael@0 | 44 | return array.buffer; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | var ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/websocket_hybi/file_check-binary-messages"); |
michael@0 | 48 | var closeEvent; |
michael@0 | 49 | |
michael@0 | 50 | ws.onopen = function() |
michael@0 | 51 | { |
michael@0 | 52 | ok(true, "onopen reached"); |
michael@0 | 53 | ws.send(createArrayBufferContainingHelloWorld()); |
michael@0 | 54 | ws.send(createEmptyArrayBuffer()); |
michael@0 | 55 | ws.send(createArrayBufferContainingAllDistinctBytes()); |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | ws.onmessage = function(event) |
michael@0 | 59 | { |
michael@0 | 60 | var message = event.data; |
michael@0 | 61 | if (startsWith(message, "PASS")) |
michael@0 | 62 | ok(true, message); |
michael@0 | 63 | else |
michael@0 | 64 | ok(false, message); |
michael@0 | 65 | }; |
michael@0 | 66 | |
michael@0 | 67 | ws.onclose = function(event) |
michael@0 | 68 | { |
michael@0 | 69 | ok(event.wasClean, "should have closed cleanly"); |
michael@0 | 70 | SimpleTest.finish(); |
michael@0 | 71 | }; |
michael@0 | 72 | |
michael@0 | 73 | ws.onerror = function(event) |
michael@0 | 74 | { |
michael@0 | 75 | ok(false, "onerror should not have been called"); |
michael@0 | 76 | }; |
michael@0 | 77 | |
michael@0 | 78 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 79 | |
michael@0 | 80 | </script> |
michael@0 | 81 | </body> |
michael@0 | 82 | </html> |