Bug 1237807 - Split test_websocket.html - patch 4, r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 04 Mar 2016 20:38:54 +0100
changeset 323150 a06ac8e3220aa7bb49f5b755936078772a2b7464
parent 323149 9a294e361e637f2721a2a08883c92f8bbfc43c76
child 323151 b5c2b685c260410ec1fb5e6a3129517d6f5b6def
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1237807
milestone47.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 1237807 - Split test_websocket.html - patch 4, r=ehsan
dom/base/test/mochitest.ini
dom/base/test/test_websocket.html
dom/base/test/test_websocket4.html
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -812,16 +812,18 @@ skip-if = toolkit == 'android'
 [test_websocket.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' # TC: Bug 1144079 - Re-enable Mulet mochitests and reftests taskcluster-specific disables.
 [test_websocket1.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' # TC: Bug 1144079 - Re-enable Mulet mochitests and reftests taskcluster-specific disables.
 [test_websocket2.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' # TC: Bug 1144079 - Re-enable Mulet mochitests and reftests taskcluster-specific disables.
 [test_websocket3.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' # TC: Bug 1144079 - Re-enable Mulet mochitests and reftests taskcluster-specific disables.
+[test_websocket4.html]
+skip-if = buildapp == 'b2g' || toolkit == 'android' # TC: Bug 1144079 - Re-enable Mulet mochitests and reftests taskcluster-specific disables.
 [test_websocket_basic.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android'
 [test_websocket_hello.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android'
 [test_websocket_permessage_deflate.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android'
 [test_x-frame-options.html]
 [test_xbl_userdata.xhtml]
--- a/dom/base/test/test_websocket.html
+++ b/dom/base/test/test_websocket.html
@@ -66,17 +66,17 @@
  * 42. non-char utf-8 sequences
  * 43. Test setting binaryType attribute
  * 44. Test sending/receving binary ArrayBuffer
  * 45. Test sending/receving binary Blob
  * 46. Test that we don't dispatch incoming msgs once in CLOSING state
  * 47. Make sure onerror/onclose aren't called during close()
  */
 
-var first_test = 31;
+var first_test = 41;
 var last_test = 47;
 
 
 // Set this to >1 if you want to run the suite multiple times to probe for
 // random orange failures.
 // - Do NOT check into mozilla-central with a value != 1.
 // - Too large a count will wind up causing tryserver to timeout the test (which
 //   is ok, but means all testruns will be orange).  If I set first_test to >22
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_websocket4.html
@@ -0,0 +1,290 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta>
+  <title>WebSocket test</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 onload="testWebSocket()">
+<script class="testbody" type="text/javascript">
+
+function test31() {
+  return new Promise(function(resolve, reject) {
+    var prots=["test-does-not-exist", "test31"];
+    var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", prots);
+
+    ws.onopen = function(e) {
+      ok(true, "test 31 protocol array open");
+      ws.close();
+    }
+
+    ws.onclose = function(e) {
+      is(ws.protocol, "test31", "test31 subprotocol selection");
+      ok(true, "test 31 protocol array close");
+      resolve();
+    }
+  });
+}
+
+function test32() {
+  return new Promise(function(resolve, reject) {
+    var prots=["test32","test32"];
+
+    try {
+      var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", prots);
+      ok(false, "testing duplicated element sub protocol array");
+    } catch (e) {
+      ok(true, "testing duplicated sub element protocol array");
+    }
+
+    resolve();
+  });
+}
+
+function test33() {
+  return new Promise(function(resolve, reject) {
+    var prots=["test33"];
+
+    var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", prots);
+
+    ws.onopen = function(e) {
+      ok(true, "test 33 open");
+      ws.close(3131);   // pass code but not reason
+    }
+
+    ws.onclose = function(e) {
+      ok(true, "test 33 close");
+      shouldCloseCleanly(e);
+      is(e.code, 3131, "test 33 got wrong close code: " + e.code);
+      is(e.reason, "", "test 33 got wrong close reason: " + e.reason);
+      resolve();
+    }
+  });
+}
+
+function test34() {
+  return new Promise(function(resolve, reject) {
+    var prots=["test-34"];
+
+    var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", prots);
+
+    ws.onopen = function(e) {
+      ok(true, "test 34 open");
+      ws.close();
+    }
+
+    ws.onclose = function(e)
+    {
+      ok(true, "test 34 close");
+      ok(e.wasClean, "test 34 closed cleanly");
+      is(e.code, 1001, "test 34 custom server code");
+      is(e.reason, "going away now", "test 34 custom server reason");
+      resolve();
+    }
+  });
+}
+
+function test35() {
+  return new Promise(function(resolve, reject) {
+    var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", "test-35a");
+
+    ws.onopen = function(e) {
+      ok(true, "test 35a open");
+      ws.close(3500, "my code");
+    }
+
+    ws.onclose = function(e) {
+      ok(true, "test 35a close");
+      ok(e.wasClean, "test 35a closed cleanly");
+      var wsb = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", "test-35b");
+
+      wsb.onopen = function(e) {
+        ok(true, "test 35b open");
+        wsb.close();
+      }
+
+      wsb.onclose = function(e) {
+        ok(true, "test 35b close");
+        ok(e.wasClean, "test 35b closed cleanly");
+        is(e.code, 3501, "test 35 custom server code");
+        is(e.reason, "my code", "test 35 custom server reason");
+        resolve();
+      }
+    }
+  });
+}
+
+function test36() {
+  return new Promise(function(resolve, reject) {
+    var prots=["test-36"];
+
+    var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", prots);
+
+    ws.onopen = function(e) {
+      ok(true, "test 36 open");
+
+      try {
+        ws.close(13200);
+        ok(false, "testing custom close code out of range");
+       } catch (e) {
+         ok(true, "testing custom close code out of range");
+         ws.close(3200);
+       }
+    }
+
+    ws.onclose = function(e) {
+      ok(true, "test 36 close");
+      ok(e.wasClean, "test 36 closed cleanly");
+      resolve();
+    }
+  });
+}
+
+function test37() {
+  return new Promise(function(resolve, reject) {
+    var prots=["test-37"];
+
+    var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", prots);
+
+    ws.onopen = function(e) {
+      ok(true, "test 37 open");
+
+      try {
+	ws.close(3100,"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123");
+        ok(false, "testing custom close reason out of range");
+       } catch (e) {
+         ok(true, "testing custom close reason out of range");
+         ws.close(3100,"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012");
+       }
+    }
+
+    ws.onclose = function(e) {
+      ok(true, "test 37 close");
+      ok(e.wasClean, "test 37 closed cleanly");
+
+      var wsb = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", "test-37b");
+
+      wsb.onopen = function(e) {
+        // now test that a rejected close code and reason dont persist
+        ok(true, "test 37b open");
+        try {
+          wsb.close(3101,"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123");
+          ok(false, "testing custom close reason out of range 37b");
+        } catch (e) {
+          ok(true, "testing custom close reason out of range 37b");
+          wsb.close();
+        }
+      }
+
+      wsb.onclose = function(e) {
+        ok(true, "test 37b close");
+        ok(e.wasClean, "test 37b closed cleanly");
+
+        var wsc = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", "test-37c");
+
+        wsc.onopen = function(e) {
+          ok(true, "test 37c open");
+          wsc.close();
+        }
+
+        wsc.onclose = function(e) {
+          isnot(e.code, 3101, "test 37c custom server code not present");
+          is(e.reason, "", "test 37c custom server reason not present");
+          resolve();
+        }
+      }
+    }
+  });
+}
+
+function test38() {
+  return new Promise(function(resolve, reject) {
+    var prots=["test-38"];
+
+    var ws = CreateTestWS("ws://mochi.test:8888/tests/dom/base/test/file_websocket", prots);
+
+    ws.onopen = function(e) {
+      ok(true, "test 38 open");
+      isnot(ws.extensions, undefined, "extensions attribute defined");
+      //  is(ws.extensions, "deflate-stream", "extensions attribute deflate-stream");
+      ws.close();
+    }
+
+    ws.onclose = function(e) {
+      ok(true, "test 38 close");
+      resolve();
+    }
+  });
+}
+
+function test39() {
+  return new Promise(function(resolve, reject) {
+    var prots=["test-39"];
+
+    var ws = CreateTestWS("wss://example.com/tests/dom/base/test/file_websocket", prots);
+    status_test39 = "started";
+
+    ws.onopen = function(e) {
+      status_test39 = "opened";
+      ok(true, "test 39 open");
+      ws.close();
+    }
+
+    ws.onclose = function(e) {
+      ok(true, "test 39 close");
+      is(status_test39, "opened", "test 39 did open");
+      resolve();
+    }
+  });
+}
+
+function test40() {
+  return new Promise(function(resolve, reject) {
+    var prots=["test-40"];
+
+    var ws = CreateTestWS("wss://nocert.example.com/tests/dom/base/test/file_websocket", prots);
+
+    status_test40 = "started";
+    ws.onerror = ignoreError;
+
+    ws.onopen = function(e) {
+      status_test40 = "opened";
+      ok(false, "test 40 open");
+      ws.close();
+    }
+
+    ws.onclose = function(e) {
+      ok(true, "test 40 close");
+      is(status_test40, "started", "test 40 did not open");
+      resolve();
+    }
+  });
+}
+
+var tests = [
+  test31, // ctor using valid 2 element sub-protocol array with 1 element server
+          // will reject and one server will accept
+  test32, // ctor using invalid sub-protocol array that contains duplicate items
+  test33, // test for sending/receiving custom close code (but no close reason)
+  test34, // test for receiving custom close code and reason
+  test35, // test for sending custom close code and reason
+  test36, // negative test for sending out of range close code
+  test37, // negative test for too long of a close reason
+  test38, // ensure extensions attribute is defined
+  test39, // a basic wss:// connectivity test
+  test40, // negative test for wss:// with no cert
+];
+
+function testWebSocket() {
+  doTest();
+}
+
+</script>
+
+<div id="feedback">
+</div>
+
+</body>
+</html>