Bug 1415081 - part 2 - mochitest for NS_ReadInputStreamToString in WebSocket, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 09 Nov 2017 11:18:08 +0100
changeset 444204 90939e355e8d9a508ab2dae5f5e98c7ab7dd67fd
parent 444203 7cf6867bed423f52c684994c77cd1db376de3bf1
child 444205 42a4f661f2d3cc79aec852c1ac6335f84a63633a
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1415081
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1415081 - part 2 - mochitest for NS_ReadInputStreamToString in WebSocket, r=smaug
dom/base/test/file_websocket_bigBlob_wsh.py
dom/base/test/mochitest.ini
dom/base/test/test_websocket_bigBlob.html
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_websocket_bigBlob_wsh.py
@@ -0,0 +1,9 @@
+from mod_pywebsocket import msgutil
+
+def web_socket_do_extra_handshake(request):
+  pass
+
+def web_socket_transfer_data(request):
+  while True:
+    line = msgutil.receive_message(request)
+    msgutil.send_message(request, line, True, True)
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -152,16 +152,17 @@ support-files =
   file_mozfiledataurl_img.jpg
   file_record_orientation.html
   file_restrictedEventSource.sjs
   file_settimeout_inner.html
   file_timer_flood.html
   file_viewport_scroll_quirks.html
   file_viewport_scroll_xml.xml
   file_websocket_basic_wsh.py
+  file_websocket_bigBlob_wsh.py
   file_websocket_hello_wsh.py
   file_websocket_http_resource.txt
   file_websocket_permessage_deflate_wsh.py
   file_websocket_permessage_deflate_disabled_wsh.py
   file_websocket_permessage_deflate_rejected_wsh.py
   file_websocket_permessage_deflate_params_wsh.py
   file_websocket_wsh.py
   file_x-frame-options_main.html
@@ -818,16 +819,18 @@ skip-if = toolkit == 'android'
 [test_websocket2.html]
 skip-if = toolkit == 'android'
 [test_websocket3.html]
 skip-if = toolkit == 'android'
 [test_websocket4.html]
 skip-if = toolkit == 'android'
 [test_websocket5.html]
 skip-if = toolkit == 'android'
+[test_websocket_bigBlob.html]
+skip-if = toolkit == 'android'
 [test_window_constructor.html]
 [test_window_content.html]
 [test_window_cross_origin_props.html]
 [test_window_define_nonconfigurable.html]
 [test_window_define_symbol.html]
 [test_window_element_enumeration.html]
 [test_window_enumeration.html]
 [test_window_extensible.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_websocket_bigBlob.html
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta>
+  <title>WebSocket test - big blob on content side</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="websocket_helpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<script class="testbody" type="text/javascript">
+
+var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket_bigBlob");
+is(ws.readyState, 0, "Initial readyState is 0");
+ws.binaryType = "blob";
+
+ws.onopen = function() {
+  is(ws.readyState, 1, "Open readyState is 1");
+  ws.send(new Blob([new Array(1024*1024).join('123456789ABCDEF')]));
+}
+
+let receivedBlob;
+ws.onmessage = function(e) {
+  ok(e.data instanceof Blob, "We should be receiving a Blob");
+  receivedBlob = e.data;
+  ws.close();
+}
+
+ws.onclose = function(e) {
+  is(ws.readyState, 3, "Close readyState is 3");
+
+  // check blob contents
+  var reader = new FileReader();
+  reader.onload = function(event) {
+    is(reader.result, new Array(1024*1024).join('123456789ABCDEF'), "All data matches");
+  }
+
+  reader.onerror = function(event) {
+    ok(false, "Something bad happen.");
+  }
+
+  reader.onloadend = function(event) {
+    SimpleTest.finish();
+  }
+
+  reader.readAsBinaryString(receivedBlob);
+}
+
+SimpleTest.requestFlakyTimeout("The web socket tests are really fragile, but avoiding timeouts might be hard, since it's testing stuff on the network. " +
+                               "Expect all sorts of flakiness in this test...");
+SimpleTest.waitForExplicitFinish();
+
+</script>
+</body>
+</html>