Bug 1227136 - test for the crash, r=bagder
authorMichal Novotny <michal.novotny@gmail.com>
Tue, 29 Mar 2016 22:28:27 +0200
changeset 290965 ef5527cc71fce46f65a9b55b0014083c371c6236
parent 290964 d4dce7faceace88b269122e96994b3f737618cd9
child 290966 91dd7f2ddda610da16d335078ad447c492a2045c
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1227136
milestone48.0a1
Bug 1227136 - test for the crash, r=bagder
dom/base/test/test_websocket5.html
dom/base/test/websocket_tests.js
--- a/dom/base/test/test_websocket5.html
+++ b/dom/base/test/test_websocket5.html
@@ -14,16 +14,18 @@
 var tests = [
   test41, // HSTS
   test42, // non-char utf-8 sequences
   test43, // Test setting binaryType attribute
   test44, // Test sending/receving binary ArrayBuffer
   test45, // Test sending/receving binary Blob
   test46, // Test that we don't dispatch incoming msgs once in CLOSING state
   test47, // Make sure onerror/onclose aren't called during close()
+  test48, // see bug 1227136 - client calls close() from onopen() and waits
+          // until WebSocketChannel::mSocketIn is nulled out on socket thread
 ];
 
 function testWebSocket() {
   doTest();
 }
 
 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...");
--- a/dom/base/test/websocket_tests.js
+++ b/dom/base/test/websocket_tests.js
@@ -1208,8 +1208,37 @@ function test47() {
     // Make sure we call onerror/onclose asynchronously
     ws._withinClose = 1;
     ws.close(3333, "Closed before we were open: error");
     ws._withinClose = 0;
     is(ws.readyState, 2, "test-47: readyState should be CLOSING(2) after close(): got "
        + ws.readyState);
   });
 }
+
+// test48: see bug 1227136 - client calls close() from onopen() and waits until
+// WebSocketChannel::mSocketIn is nulled out on socket thread.
+function test48() {
+  return new Promise(function(resolve, reject) {
+    const pref_close = "network.websocket.timeout.close";
+    SpecialPowers.setIntPref(pref_close, 1);
+
+    var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", "test-48");
+
+    ws.onopen = function() {
+      ws.close();
+
+      var date = new Date();
+      var curDate = null;
+      do {
+        curDate = new Date();
+      } while(curDate-date < 1500);
+
+    }
+
+    ws.onclose = function(e) {
+      ok(true, "ws close in test 48");
+      resolve();
+    }
+
+    SpecialPowers.clearUserPref(pref_close);
+  });
+}