Bug 1368065 - Add a test for WebSocket and non-ascii char, r=qdot
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 31 May 2017 21:16:42 +0200
changeset 409773 7bd0e6b5a99a7401f4e17abeff03b366f07955e6
parent 409772 313abe9e730ed46ac008d9867cc1e9619eb881c8
child 409774 0f4474710f24dbce9a92ebc75610fe8ab34bd638
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1368065
milestone55.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 1368065 - Add a test for WebSocket and non-ascii char, r=qdot
dom/base/test/test_websocket_basic.html
--- a/dom/base/test/test_websocket_basic.html
+++ b/dom/base/test/test_websocket_basic.html
@@ -233,23 +233,57 @@ function testWebSocket5() {
     is(this.bufferedAmount, 0, "[5] Length of empty buffer after closing");
 
     var msg = "test message to be buffered";
     this.send(msg);
     is(this.bufferedAmount, msg.length, "[5] Length of buffered message sent after closing");
 
     gTestElement.textContent += "\ntestWebSocket5() completed";
 
-    SimpleTest.executeSoon(SimpleTest.finish);
+    SimpleTest.executeSoon(testWebSocket6);
   };
   ws.onerror = function(e) {
     ok(false, "[5] onerror() should not have been called!");
     gTestElement.textContent += "\nonerror() should not have been called!";
     SimpleTest.executeSoon(SimpleTest.finish);
   };
 }
 
+function testWebSocket6() {
+  gTestElement.textContent = "Running testWebSocket6()";
+
+  var msgReceived = false;
+  ws = new WebSocket(kUrl, "test");
+  ws.onopen = function(e) {
+    gTestElement.textContent += "\nSending ©";
+    ws.send("©");
+    gTestElement.textContent += " end";
+    ws.send("end");
+  };
+  ws.onclose = function(e) {
+    ok(msgReceived, "[6] Number of received messages");
+    ok(e.wasClean, "[6] Connection closed cleanly");
+
+    SimpleTest.executeSoon(SimpleTest.finish);
+  };
+  ws.onerror = function(e) {
+    ok(false, "[6] onerror() should not have been called!");
+    gTestElement.textContent += "\nonerror() should not have been called!";
+    SimpleTest.executeSoon(SimpleTest.finish);
+  };
+
+  ws.onmessage = function(e) {
+    if (msgReceived) {
+      is(e.data, "end", "[6] Received message");
+    } else {
+      gTestElement.textContent += "\nReceived: " + e.data;
+      is(e.data, "©", "[6] Received message");
+      msgReceived = true;
+    }
+  };
+}
+
 SimpleTest.waitForExplicitFinish();
 
 </script>
 </pre>
 </body>
 </html>