Add a binary data channel webrtc test
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Jun 2017 23:21:37 +0000 (23:21 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Jun 2017 23:21:37 +0000 (23:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173787

Patch by Youenn Fablet <youenn@apple.com> on 2017-06-23
Reviewed by Alex Christensen.

* webrtc/datachannel/binary-expected.txt: Added.
* webrtc/datachannel/binary.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218774 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/webrtc/datachannel/binary-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/datachannel/binary.html [new file with mode: 0644]

index fb04c11..590cc67 100644 (file)
@@ -1,5 +1,15 @@
 2017-06-23  Youenn Fablet  <youenn@apple.com>
 
+        Add a binary data channel webrtc test
+        https://bugs.webkit.org/show_bug.cgi?id=173787
+
+        Reviewed by Alex Christensen.
+
+        * webrtc/datachannel/binary-expected.txt: Added.
+        * webrtc/datachannel/binary.html: Added.
+
+2017-06-23  Youenn Fablet  <youenn@apple.com>
+
         Set getUserMedia permission to true by default on WTR
         https://bugs.webkit.org/show_bug.cgi?id=173610
 
diff --git a/LayoutTests/webrtc/datachannel/binary-expected.txt b/LayoutTests/webrtc/datachannel/binary-expected.txt
new file mode 100644 (file)
index 0000000..2ed28ed
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Basic binary data channel exchange from offerer to receiver 
+
diff --git a/LayoutTests/webrtc/datachannel/binary.html b/LayoutTests/webrtc/datachannel/binary.html
new file mode 100644 (file)
index 0000000..ab92eca
--- /dev/null
@@ -0,0 +1,91 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Testing basic binary data channel from offerer to receiver</title>
+    <script src="../../resources/testharness.js"></script>
+    <script src="../../resources/testharnessreport.js"></script>
+  </head>
+  <body>
+    <script src ="../routines.js"></script>
+    <script>
+var localChannel;
+var remoteChannel;
+
+function closeDataChannels() {
+    localChannel.close();
+    remoteChannel.close();
+    closeConnections();
+}
+
+function createArrayBuffer(length)
+{
+    var array = new Uint8Array(length);
+    for (var cptr = 0; cptr < length; cptr++)
+        array[cptr] = cptr + 1;
+    return array;
+}
+
+function checkArrayBuffer(array, length)
+{
+    if (array.byteLength !== length)
+        return false;
+
+    var a = new Uint8Array(array);
+    for (var cptr = 0; cptr < length; cptr++) {
+        if (a[cptr] !== cptr + 1)
+             return false;
+    }
+    return true;
+}
+
+function receiveMessages(event) {
+    try {
+        if (++counter === 1)
+            assert_true(checkArrayBuffer(event.data, 1));
+        else if (counter === 2)
+            assert_true(checkArrayBuffer(event.data, 2));
+        else if (counter === 3)
+            assert_true(checkArrayBuffer(event.data, 3));
+        else if (counter === 4) {
+            assert_true(checkArrayBuffer(event.data, 4));
+            closeDataChannels();
+            finishTest();
+        } else
+            assert_unreached();
+    } catch(e) {
+        console.log(e);
+    }
+}
+
+function sendMessages(channel)
+{
+    channel.send(createArrayBuffer(1));
+    channel.send(createArrayBuffer(2));
+    channel.send(createArrayBuffer(3));
+    channel.send(createArrayBuffer(4));
+}
+
+var finishTest;
+promise_test((test) => {
+    counter = 0;
+    return new Promise((resolve, reject) => {
+        finishTest = resolve;
+        createConnections((localConnection) => {
+            localChannel = localConnection.createDataChannel('sendDataChannel');
+            localChannel.binaryType = "arraybuffer";
+            localChannel.onopen = () => { sendMessages(localChannel) };
+        }, (remoteConnection) => {
+            remoteConnection.ondatachannel = (event) => {
+                remoteChannel = event.channel;
+                remoteChannel.binaryType = "arraybuffer";
+                remoteChannel.onmessage = receiveMessages;
+            };
+        });
+        setTimeout(() => { reject("Test timed out"); }, 5000);
+    });
+}, "Basic binary data channel exchange from offerer to receiver");
+
+    </script>
+  </body>
+</html>