summaryrefslogtreecommitdiffstats
path: root/dom/base/test/websocket_hybi/test_receive-arraybuffer.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/base/test/websocket_hybi/test_receive-arraybuffer.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/base/test/websocket_hybi/test_receive-arraybuffer.html')
-rw-r--r--dom/base/test/websocket_hybi/test_receive-arraybuffer.html97
1 files changed, 97 insertions, 0 deletions
diff --git a/dom/base/test/websocket_hybi/test_receive-arraybuffer.html b/dom/base/test/websocket_hybi/test_receive-arraybuffer.html
new file mode 100644
index 000000000..0bd1cfefc
--- /dev/null
+++ b/dom/base/test/websocket_hybi/test_receive-arraybuffer.html
@@ -0,0 +1,97 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+
+<script class="testbody" type="text/javascript">
+
+function debug(msg) {
+ ok(1, msg);
+}
+
+function createArrayBufferContainingHelloWorld()
+{
+ var hello = "Hello, world!";
+ var array = new Uint8Array(hello.length);
+ for (var i = 0; i < hello.length; ++i)
+ array[i] = hello.charCodeAt(i);
+ return array.buffer;
+}
+
+function createEmptyArrayBuffer()
+{
+ return new ArrayBuffer(0);
+}
+
+function createArrayBufferContainingAllDistinctBytes()
+{
+ var array = new Uint8Array(256);
+ for (var i = 0; i < 256; ++i)
+ array[i] = i;
+ return array.buffer;
+}
+
+var ws = new WebSocket("ws://mochi.test:8888/tests/dom/base/test/websocket_hybi/file_binary-frames");
+ws.binaryType = "arraybuffer";
+is(ws.binaryType, "arraybuffer", "should be equal to 'arraybuffer'");
+
+var closeEvent;
+var receivedMessages = [];
+var expectedValues = [createArrayBufferContainingHelloWorld(), createEmptyArrayBuffer(), createArrayBufferContainingAllDistinctBytes()];
+
+ws.onmessage = function(event)
+{
+ receivedMessages.push(event.data);
+};
+
+ws.onclose = function(event)
+{
+ closeEvent = event;
+
+ is(receivedMessages.length, expectedValues.length, "lengths not equal");
+ for (var i = 0; i < expectedValues.length; ++i)
+ check(i);
+ SimpleTest.finish();
+};
+
+var responseType;
+
+function check(index)
+{
+ debug("Checking message #" + index + ".");
+ ok(receivedMessages[index] instanceof ArrayBuffer,
+ "Should receive an arraybuffer!");
+ checkArrayBuffer(index, receivedMessages[index], expectedValues[index]);
+}
+
+var actualArray;
+var expectedArray;
+
+function checkArrayBuffer(testIndex, actual, expected)
+{
+ actualArray = new Uint8Array(actual);
+ expectedArray = new Uint8Array(expected);
+ is(actualArray.length, expectedArray.length, "lengths not equal");
+ // Print only the first mismatched byte in order not to flood console.
+ for (var i = 0; i < expectedArray.length; ++i) {
+ if (actualArray[i] != expectedArray[i]) {
+ ok(false, "Value mismatch: actualArray[" + i + "] = " + actualArray[i] + ", expectedArray[" + i + "] = " + expectedArray[i]);
+ return;
+ }
+ }
+ ok(true, "Passed: Message #" + testIndex + ".");
+}
+
+SimpleTest.waitForExplicitFinish();
+
+</script>
+</body>
+</html>