diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/base/test/test_websocket_permessage_deflate.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-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/test_websocket_permessage_deflate.html')
-rw-r--r-- | dom/base/test/test_websocket_permessage_deflate.html | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/dom/base/test/test_websocket_permessage_deflate.html b/dom/base/test/test_websocket_permessage_deflate.html new file mode 100644 index 000000000..5c40600c4 --- /dev/null +++ b/dom/base/test/test_websocket_permessage_deflate.html @@ -0,0 +1,110 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Basic test of permessage compression websocket extension</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body onload="loadDeflate()"> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=792831">Mozilla Bug </a> +<p id="display"></p> +<div id="content" style="display: none"> +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +var ws; +var textMessage = "This is a text message"; +var binaryMessage = "This is a binary message"; +var testIdx = 0; +var sendText = true; + +tests = [ + // enable PMCE + [ true, true, "ws://mochi.test:8888/tests/dom/base/test/file_websocket_permessage_deflate" ], + // disable PMCE + [ false, false, "ws://mochi.test:8888/tests/dom/base/test/file_websocket_permessage_deflate_disabled" ], + // server rejects offered PMCE + [ true, false, "ws://mochi.test:8888/tests/dom/base/test/file_websocket_permessage_deflate_rejected" ], + // server returns parameters in the handshake + [ true, true, "ws://mochi.test:8888/tests/dom/base/test/file_websocket_permessage_deflate_params" ] +] + +function ab2str(buf) { + return String.fromCharCode.apply(null, new Uint16Array(buf)); +} + +function str2ab(str) { + var buf = new ArrayBuffer(str.length*2); + var bufView = new Uint16Array(buf); + for (var i=0, strLen=str.length; i<strLen; i++) { + bufView[i] = str.charCodeAt(i); + } + return buf; +} + +function sendMessage() { + if (sendText) { + ws.send(textMessage); + } else { + ws.binaryType = "arraybuffer"; + ws.send(str2ab(binaryMessage)); + } +} + +function testDeflate() { + ws = new WebSocket(tests[testIdx][2]); + + ws.onopen = function(e) { + if (tests[testIdx][1]) { + is(ws.extensions, "permessage-deflate", "permessage-deflate not negotiated!"); + } else { + is(ws.extensions, "", "permessage-deflate should not be negotiated!"); + } + + sendMessage(); + } + + ws.onclose = function(e) { + if (!e.wasClean) { + ok(false, "Connection should be closed cleanly!"); + SimpleTest.finish(); + } + } + + ws.onerror = function(e) { + ok(false, "onerror called!"); + SimpleTest.finish(); + } + + ws.onmessage = function(e) { + if (sendText) { + is(e.data, textMessage, "Text message not received successfully!"); + sendText = false; + sendMessage(); + } else { + ok(e.data instanceof ArrayBuffer, "Should receive an arraybuffer!"); + is(ab2str(e.data), binaryMessage, "Binary message not received successfully!"); + ws.close(); + + sendText = true; + testIdx++; + if (testIdx < tests.length) { + loadDeflate(); + } else { + SimpleTest.finish(); + } + } + } +} + +function loadDeflate() { + SpecialPowers.pushPrefEnv({"set":[['network.websocket.extensions.permessage-deflate', tests[testIdx][0]]]}, testDeflate); +} + +SimpleTest.waitForExplicitFinish(); + +</script> +</pre> +</body> +</html> |