PeerConnection should have its connectionState closed even if doing gathering
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 May 2018 15:18:34 +0000 (15:18 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 May 2018 15:18:34 +0000 (15:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185267

Reviewed by Darin Adler.

Source/WebCore:

Test: webrtc/addICECandidate-closed.html

In case m_iceConnectionState is closed, m_connectionState should also be set to closed
and RTCPeerConnection should be closed so as to reject any other call.

* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::close):
(WebCore::RTCPeerConnection::updateConnectionState):

LayoutTests:

* webrtc/addICECandidate-closed-expected.txt: Added.
* webrtc/addICECandidate-closed.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/webrtc/addICECandidate-closed-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/addICECandidate-closed.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp

index dd74926..25096b0 100644 (file)
@@ -1,3 +1,13 @@
+2018-05-04  Youenn Fablet  <youenn@apple.com>
+
+        PeerConnection should have its connectionState closed even if doing gathering
+        https://bugs.webkit.org/show_bug.cgi?id=185267
+
+        Reviewed by Darin Adler.
+
+        * webrtc/addICECandidate-closed-expected.txt: Added.
+        * webrtc/addICECandidate-closed.html: Added.
+
 2018-05-04  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Some event tests failing after r230817
diff --git a/LayoutTests/webrtc/addICECandidate-closed-expected.txt b/LayoutTests/webrtc/addICECandidate-closed-expected.txt
new file mode 100644 (file)
index 0000000..6b7dc89
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Close a peer connection in the middle of gathering 
+
diff --git a/LayoutTests/webrtc/addICECandidate-closed.html b/LayoutTests/webrtc/addICECandidate-closed.html
new file mode 100644 (file)
index 0000000..2f5a6d6
--- /dev/null
@@ -0,0 +1,43 @@
+<!doctype html>
+<html>
+<head>
+    <script src="../resources/testharness.js"></script>
+    <script src="../resources/testharnessreport.js"></script>
+</head>
+<body>
+<script type="application/javascript">
+window.onunhandledrejection = () => false;
+promise_test(async (test) => {
+    const sender = new RTCPeerConnection();
+    const receiver = new RTCPeerConnection();
+    try {
+        const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
+        const localTracks = stream.getTracks();
+        [[sender, receiver], [receiver, sender]].forEach(([pc1, pc2]) => {
+            pc1.onicecandidate = ({ candidate }) => {
+                if (candidate)
+                    pc2.addIceCandidate(candidate);
+                pc1.close();
+            };
+        });
+        localTracks.forEach(track => sender.addTrack(track, stream));
+        receiver.addTransceiver('audio');
+        receiver.addTransceiver('video');
+        const offer1 = await sender.createOffer();
+        await sender.setLocalDescription(offer1);
+        await receiver.setRemoteDescription(offer1);
+        const answer1 = await receiver.createAnswer();
+        await receiver.setLocalDescription(answer1);
+        await sender.setRemoteDescription(answer1);
+        const offer2 = await sender.createOffer();
+        await sender.setLocalDescription(offer2);
+        await receiver.setRemoteDescription(offer2);
+        const answer2 = await receiver.createAnswer();
+        await receiver.setLocalDescription(answer2);
+        await sender.setRemoteDescription(answer2);
+    } catch (e) {
+    }
+}, "Close a peer connection in the middle of gathering");
+</script>
+</body>
+</html>
index d072cc5..9283c97 100644 (file)
@@ -1,3 +1,19 @@
+2018-05-04  Youenn Fablet  <youenn@apple.com>
+
+        PeerConnection should have its connectionState closed even if doing gathering
+        https://bugs.webkit.org/show_bug.cgi?id=185267
+
+        Reviewed by Darin Adler.
+
+        Test: webrtc/addICECandidate-closed.html
+
+        In case m_iceConnectionState is closed, m_connectionState should also be set to closed
+        and RTCPeerConnection should be closed so as to reject any other call.
+
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::RTCPeerConnection::close):
+        (WebCore::RTCPeerConnection::updateConnectionState):
+
 2018-05-04  Yacine Bandou  <yacine.bandou_ext@softathome.com>
 
         [MSE][GStreamer] Delete properly the stream from the WebKitMediaSource
index 0e3c4f6..165fa5d 100644 (file)
@@ -423,6 +423,7 @@ void RTCPeerConnection::close()
         return;
 
     updateConnectionState();
+    ASSERT(isClosed());
     scriptExecutionContext()->postTask([protectedThis = makeRef(*this)](ScriptExecutionContext&) {
         protectedThis->doStop();
     });
@@ -524,19 +525,18 @@ void RTCPeerConnection::updateConnectionState()
 {
     RTCPeerConnectionState state;
 
-    // FIXME: In case m_iceGatheringState is RTCIceGatheringState::Gathering, and m_iceConnectionState is Closed, we should have the connection state be Closed.
-    if (m_iceConnectionState == RTCIceConnectionState::New && m_iceGatheringState == RTCIceGatheringState::New)
+    if (m_iceConnectionState == RTCIceConnectionState::Closed)
+        state = RTCPeerConnectionState::Closed;
+    else if (m_iceConnectionState == RTCIceConnectionState::Disconnected)
+        state = RTCPeerConnectionState::Disconnected;
+    else if (m_iceConnectionState == RTCIceConnectionState::Failed)
+        state = RTCPeerConnectionState::Failed;
+    else if (m_iceConnectionState == RTCIceConnectionState::New && m_iceGatheringState == RTCIceGatheringState::New)
         state = RTCPeerConnectionState::New;
     else if (m_iceConnectionState == RTCIceConnectionState::Checking || m_iceGatheringState == RTCIceGatheringState::Gathering)
         state = RTCPeerConnectionState::Connecting;
     else if ((m_iceConnectionState == RTCIceConnectionState::Completed || m_iceConnectionState == RTCIceConnectionState::Connected) && m_iceGatheringState == RTCIceGatheringState::Complete)
         state = RTCPeerConnectionState::Connected;
-    else if (m_iceConnectionState == RTCIceConnectionState::Disconnected)
-        state = RTCPeerConnectionState::Disconnected;
-    else if (m_iceConnectionState == RTCIceConnectionState::Failed)
-        state = RTCPeerConnectionState::Failed;
-    else if (m_iceConnectionState == RTCIceConnectionState::Closed)
-        state = RTCPeerConnectionState::Closed;
     else
         return;