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"> |
michael@0 | 10 | <input id="fileList" type="file"></input> |
michael@0 | 11 | </p> |
michael@0 | 12 | <div id="content" style="display: none"> |
michael@0 | 13 | </div> |
michael@0 | 14 | <pre id="test"> |
michael@0 | 15 | |
michael@0 | 16 | <script class="testbody" type="text/javascript"> |
michael@0 | 17 | |
michael@0 | 18 | function startsWith(target, prefix) |
michael@0 | 19 | { |
michael@0 | 20 | return target.indexOf(prefix) === 0; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function createDOMFile(fileName, fileData) |
michael@0 | 24 | { |
michael@0 | 25 | // create File in profile dir |
michael@0 | 26 | var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"] |
michael@0 | 27 | .getService(SpecialPowers.Ci.nsIProperties); |
michael@0 | 28 | var testFile = dirSvc.get("ProfD", SpecialPowers.Ci.nsIFile); |
michael@0 | 29 | testFile.append(fileName); |
michael@0 | 30 | var outStream = SpecialPowers.Cc["@mozilla.org/network/file-output-stream;1"] |
michael@0 | 31 | .createInstance(SpecialPowers.Ci.nsIFileOutputStream); |
michael@0 | 32 | outStream.init(testFile, 0x02 | 0x08 | 0x20, 0666, 0); |
michael@0 | 33 | if (fileData) { |
michael@0 | 34 | outStream.write(fileData, fileData.length); |
michael@0 | 35 | outStream.close(); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | // Set filename into DOM <input> field, as if selected by user |
michael@0 | 39 | var fileList = document.getElementById('fileList'); |
michael@0 | 40 | SpecialPowers.wrap(fileList).value = testFile.path; |
michael@0 | 41 | |
michael@0 | 42 | // return JS File object, aka Blob |
michael@0 | 43 | return fileList.files[0]; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | |
michael@0 | 47 | function createBlobContainingHelloWorld() |
michael@0 | 48 | { |
michael@0 | 49 | return createDOMFile("hellofile", "Hello, world!"); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function createEmptyBlob() |
michael@0 | 53 | { |
michael@0 | 54 | return createDOMFile("emptyfile"); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function createBlobContainingAllDistinctBytes() |
michael@0 | 58 | { |
michael@0 | 59 | var array = new Array(); |
michael@0 | 60 | for (var i = 0; i < 256; ++i) |
michael@0 | 61 | array[i] = i; |
michael@0 | 62 | // Concatenates chars into a single binary string |
michael@0 | 63 | binaryString = String.fromCharCode.apply(null, array); |
michael@0 | 64 | return createDOMFile("allchars", binaryString); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | var ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/websocket_hybi/file_check-binary-messages"); |
michael@0 | 68 | var closeEvent; |
michael@0 | 69 | |
michael@0 | 70 | ws.onopen = function() |
michael@0 | 71 | { |
michael@0 | 72 | ws.send(createBlobContainingHelloWorld()); |
michael@0 | 73 | ws.send(createEmptyBlob()); |
michael@0 | 74 | ws.send(createBlobContainingAllDistinctBytes()); |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | ws.onmessage = function(event) |
michael@0 | 78 | { |
michael@0 | 79 | var message = event.data; |
michael@0 | 80 | if (startsWith(message, "PASS")) |
michael@0 | 81 | ok(true, message); |
michael@0 | 82 | else |
michael@0 | 83 | ok(false, message); |
michael@0 | 84 | }; |
michael@0 | 85 | |
michael@0 | 86 | ws.onclose = function(event) |
michael@0 | 87 | { |
michael@0 | 88 | ok(event.wasClean, "should have closed cleanly"); |
michael@0 | 89 | SimpleTest.finish(); |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 93 | |
michael@0 | 94 | </script> |
michael@0 | 95 | </body> |
michael@0 | 96 | </html> |