Title: [278842] trunk
Revision
278842
Author
you...@apple.com
Date
2021-06-14 11:40:54 -0700 (Mon, 14 Jun 2021)

Log Message

Fix RTCDataChannelInit::decode
https://bugs.webkit.org/show_bug.cgi?id=226968

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

* web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https-expected.txt: Added.
* web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https.html: Added.
* web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.js: Added.
(onmessage):

Source/WebCore:

Test: imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https.html

* platform/mediastream/RTCDataChannelHandler.h:
(WebCore::RTCDataChannelInit::decode):
Make sure to use optionals of optionals.

LayoutTests:

* platform/mac-wk1/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (278841 => 278842)


--- trunk/LayoutTests/ChangeLog	2021-06-14 18:39:02 UTC (rev 278841)
+++ trunk/LayoutTests/ChangeLog	2021-06-14 18:40:54 UTC (rev 278842)
@@ -1,3 +1,12 @@
+2021-06-14  Youenn Fablet  <you...@apple.com>
+
+        Fix RTCDataChannelInit::decode
+        https://bugs.webkit.org/show_bug.cgi?id=226968
+
+        Reviewed by Eric Carlson.
+
+        * platform/mac-wk1/TestExpectations:
+
 2021-06-14  Robert Jenner  <jen...@apple.com>
 
         [LayoutTests] Delete unused LayoutTests/plugins resources

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (278841 => 278842)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-06-14 18:39:02 UTC (rev 278841)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-06-14 18:40:54 UTC (rev 278842)
@@ -1,5 +1,17 @@
 2021-06-14  Youenn Fablet  <you...@apple.com>
 
+        Fix RTCDataChannelInit::decode
+        https://bugs.webkit.org/show_bug.cgi?id=226968
+
+        Reviewed by Eric Carlson.
+
+        * web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https-expected.txt: Added.
+        * web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https.html: Added.
+        * web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.js: Added.
+        (onmessage):
+
+2021-06-14  Youenn Fablet  <you...@apple.com>
+
         Move Transferable RTCDataChannel tests to WPT
         https://bugs.webkit.org/show_bug.cgi?id=226967
 

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https-expected.txt (0 => 278842)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https-expected.txt	2021-06-14 18:40:54 UTC (rev 278842)
@@ -0,0 +1,3 @@
+
+PASS offerer data channel in service worker
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https.html (0 => 278842)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https.html	2021-06-14 18:40:54 UTC (rev 278842)
@@ -0,0 +1,83 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+        <script src=""
+        <script>
+async function createConnections(test, firstConnectionCallback, secondConnectionCallback)
+{
+    const pc1 = new RTCPeerConnection();
+    const pc2 = new RTCPeerConnection();
+
+    test.add_cleanup(() => pc1.close());
+    test.add_cleanup(() => pc2.close());
+
+    pc1._onicecandidate_ = (e) => pc2.addIceCandidate(e.candidate);
+    pc2._onicecandidate_ = (e) => pc1.addIceCandidate(e.candidate);
+
+    firstConnectionCallback(pc1);
+
+    const offer = await pc1.createOffer();
+    await pc1.setLocalDescription(offer);
+    await pc2.setRemoteDescription(offer);
+
+    secondConnectionCallback(pc2);
+
+    const answer = await pc2.createAnswer();
+    await pc2.setLocalDescription(answer);
+    await pc1.setRemoteDescription(answer);
+}
+
+async function waitForMessage(receiver, data)
+{
+    while (true) {
+        const received = await new Promise(resolve => receiver._onmessage_ = (event) => resolve(event.data));
+        if (data ="" received)
+            return;
+    }
+}
+
+promise_test(async (test) => {
+    let frame;
+    const scope = 'resources/';
+    const script = 'transfer-datachannel-service-worker.js';
+
+    await service_worker_unregister(test, scope);
+    const registration = await navigator.serviceWorker.register(script, {scope});
+    test.add_cleanup(async () => {
+        return service_worker_unregister(test, scope);
+    });
+    const worker = registration.installing;
+
+    const messageChannel = new MessageChannel();
+
+    let localChannel;
+    let remoteChannel;
+
+    await new Promise((resolve, reject) => {
+        createConnections(test, (firstConnection) => {
+            localChannel = firstConnection.createDataChannel('sendDataChannel');
+            worker.postMessage({channel: localChannel, port: messageChannel.port2}, [localChannel, messageChannel.port2]);
+        }, (secondConnection) => {
+            secondConnection._ondatachannel_ = (event) => {
+                remoteChannel = event.channel;
+                remoteChannel._onopen_ = resolve;
+            };
+        });
+    });
+
+    const promise = waitForMessage(messageChannel.port1, "OK");
+    remoteChannel.send("OK");
+    await promise;
+
+    const data = "" Promise(resolve => remoteChannel._onmessage_ = (event) => resolve(event.data));
+    messageChannel.port1.postMessage({message: "OK2"});
+    assert_equals(await data, "OK2");
+}, "offerer data channel in service worker");
+        </script>
+    </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.js (0 => 278842)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.js	2021-06-14 18:40:54 UTC (rev 278842)
@@ -0,0 +1,15 @@
+let channel;
+let port;
+_onmessage_ = (e) => {
+    if (e.data.port) {
+        port = e.data.port;
+        port._onmessage_ = (event) => channel.send(event.data.message);
+    }
+    if (e.data.channel) {
+        channel = e.data.channel;
+        channel._onopen_ = () => port.postMessage("opened");
+        channel._onerror_ = () => port.postMessage("errored");
+        channel._onclose_ = () => port.postMessage("closed");
+        channel._onmessage_ = (event) => port.postMessage(event.data);
+    }
+};

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (278841 => 278842)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2021-06-14 18:39:02 UTC (rev 278841)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2021-06-14 18:40:54 UTC (rev 278842)
@@ -376,6 +376,7 @@
 imported/w3c/web-platform-tests/worklets/audio-worklet-service-worker-interception.https.html [ Skip ]
 imported/w3c/web-platform-tests/worklets/layout-worklet-service-worker-interception.https.html [ Skip ]
 imported/w3c/web-platform-tests/worklets/paint-worklet-service-worker-interception.https.html [ Skip ]
+imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https.html [ Skip ]
 
 # Quota check missing in WK1
 http/tests/IndexedDB/storage-limit.https.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (278841 => 278842)


--- trunk/Source/WebCore/ChangeLog	2021-06-14 18:39:02 UTC (rev 278841)
+++ trunk/Source/WebCore/ChangeLog	2021-06-14 18:40:54 UTC (rev 278842)
@@ -1,3 +1,16 @@
+2021-06-14  Youenn Fablet  <you...@apple.com>
+
+        Fix RTCDataChannelInit::decode
+        https://bugs.webkit.org/show_bug.cgi?id=226968
+
+        Reviewed by Eric Carlson.
+
+        Test: imported/w3c/web-platform-tests/webrtc-extensions/transfer-datachannel-service-worker.https.html
+
+        * platform/mediastream/RTCDataChannelHandler.h:
+        (WebCore::RTCDataChannelInit::decode):
+        Make sure to use optionals of optionals.
+
 2021-06-14  Per Arne  <pvol...@apple.com>
 
         [AppleWin] Fix build failure

Modified: trunk/Source/WebCore/platform/mediastream/RTCDataChannelHandler.h (278841 => 278842)


--- trunk/Source/WebCore/platform/mediastream/RTCDataChannelHandler.h	2021-06-14 18:39:02 UTC (rev 278841)
+++ trunk/Source/WebCore/platform/mediastream/RTCDataChannelHandler.h	2021-06-14 18:40:54 UTC (rev 278842)
@@ -62,17 +62,17 @@
 
 template<class Decoder> std::optional<RTCDataChannelInit> RTCDataChannelInit::decode(Decoder& decoder)
 {
-    std::optional<bool> ordered;
+    std::optional<std::optional<bool>> ordered;
     decoder >> ordered;
     if (!ordered)
         return { };
 
-    std::optional<unsigned short> maxPacketLifeTime;
+    std::optional<std::optional<unsigned short>> maxPacketLifeTime;
     decoder >> maxPacketLifeTime;
     if (!maxPacketLifeTime)
         return { };
 
-    std::optional<unsigned short> maxRetransmits;
+    std::optional<std::optional<unsigned short>> maxRetransmits;
     decoder >> maxRetransmits;
     if (!maxRetransmits)
         return { };
@@ -81,12 +81,12 @@
     if (!decoder.decode(protocol))
         return { };
 
-    std::optional<bool> negotiated;
+    std::optional<std::optional<bool>> negotiated;
     decoder >> negotiated;
     if (!negotiated)
         return { };
 
-    std::optional<unsigned short> id;
+    std::optional<std::optional<unsigned short>> id;
     decoder >> id;
     if (!id)
         return { };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to