RTCPeerConnection is stopping its backend twice sometimes
https://bugs.webkit.org/show_bug.cgi?id=171043

Patch by Youenn Fablet <youenn@apple.com> on 2017-04-20
Reviewed by Eric Carlson.

Source/WebCore:

Test: webrtc/closing-peerconnection.html

Making sure we stop the backend only once.
Adding an internals API to close the peer connection so as to replicate frame disconnection.

* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::doClose):
(WebCore::RTCPeerConnection::doStop):
* Modules/mediastream/RTCPeerConnection.h:
* testing/Internals.cpp:
(WebCore::Internals::stopPeerConnection):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* webrtc/closing-peerconnection-expected.txt: Added.
* webrtc/closing-peerconnection.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@215558 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/webrtc/closing-peerconnection.html b/LayoutTests/webrtc/closing-peerconnection.html
new file mode 100644
index 0000000..2a5995c
--- /dev/null
+++ b/LayoutTests/webrtc/closing-peerconnection.html
@@ -0,0 +1,28 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Testing closing peer connection</title>
+        <script src="../resources/testharness.js"></script>
+        <script src="../resources/testharnessreport.js"></script>
+    </head>
+    <body>
+        <script>
+promise_test((test) => {
+  return new Promise((resolve, reject) => {
+    var pc = new RTCPeerConnection();
+    pc.onicegatheringstatechange = (event) => {
+        if (pc.iceGatheringState == "gathering") {
+            pc.close();
+            if (window.internals)
+                internals.stopPeerConnection(pc);
+            resolve();
+        }
+    }
+    pc.createDataChannel("test");
+    pc.createOffer().then((desc) => pc.setLocalDescription(desc));
+  });
+}, "closing and stopping peer connection in the middle of gathering candidates");
+        </script>
+    </body>
+</html>