From eda0ff85ea50b006abbbb73abab847dec08c943f Mon Sep 17 00:00:00 2001 From: "Nils Ohlmeier [:drno]" Date: Wed, 16 Apr 2014 18:02:00 +0200 Subject: [PATCH] Bug 989936 - fire the onsignalingstatechanged event if close was called locally. r=jesup --- dom/media/tests/mochitest/pc.js | 26 ++++++++++++++----- .../test_peerConnection_bug827843.html | 10 +++++++ .../test_peerConnection_bug835370.html | 2 ++ .../src/peerconnection/PeerConnectionImpl.cpp | 6 ++++- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/dom/media/tests/mochitest/pc.js b/dom/media/tests/mochitest/pc.js index 63c31ada67c..757899f086b 100644 --- a/dom/media/tests/mochitest/pc.js +++ b/dom/media/tests/mochitest/pc.js @@ -493,12 +493,21 @@ function PeerConnectionTest(options) { PeerConnectionTest.prototype.close = function PCT_close(onSuccess) { info("Closing peer connections. Connection state=" + this.connected); + function signalingstatechangeClose(state) { + info("'onsignalingstatechange' event '" + state + "' received"); + is(state, "closed", "onsignalingstatechange event is closed"); + } + // There is no onclose event for the remote peer existent yet. So close it // side-by-side with the local peer. - if (this.pcLocal) + if (this.pcLocal) { + this.pcLocal.onsignalingstatechange = signalingstatechangeClose; this.pcLocal.close(); - if (this.pcRemote) + } + if (this.pcRemote) { + this.pcRemote.onsignalingstatechange = signalingstatechangeClose; this.pcRemote.close(); + } this.connected = false; onSuccess(); @@ -585,8 +594,9 @@ function PCT_setLocalDescription(peer, desc, onSuccess) { } } - peer.onsignalingstatechange = function () { - info(peer + ": 'onsignalingstatechange' event registered, signalingState: " + peer.signalingState); + peer.onsignalingstatechange = function (state) { + //info(peer + ": 'onsignalingstatechange' event registered, signalingState: " + peer.signalingState); + info(peer + ": 'onsignalingstatechange' event '" + state + "' received"); eventFired = true; check_next_test(); @@ -646,8 +656,8 @@ function PCT_setRemoteDescription(peer, desc, onSuccess) { } } - peer.onsignalingstatechange = function () { - info(peer + ": 'onsignalingstatechange' event registered, signalingState: " + peer.signalingState); + peer.onsignalingstatechange = function (state) { + info(peer + ": 'onsignalingstatechange' event '" + state + "' received"); eventFired = true; check_next_test(); @@ -1168,7 +1178,9 @@ function PeerConnectionWrapper(label, configuration) { this._pc.onsignalingstatechange = function (aEvent) { info(self + ": 'onsignalingstatechange' event fired"); - self.onsignalingstatechange(); + // this calls the eventhandler only once and then overwrites it with the + // default unexpectedEvent handler + self.onsignalingstatechange(aEvent); self.onsignalingstatechange = unexpectedEventAndFinish(self, 'onsignalingstatechange'); }; } diff --git a/dom/media/tests/mochitest/test_peerConnection_bug827843.html b/dom/media/tests/mochitest/test_peerConnection_bug827843.html index ea67db710a3..04e2d832ff5 100644 --- a/dom/media/tests/mochitest/test_peerConnection_bug827843.html +++ b/dom/media/tests/mochitest/test_peerConnection_bug827843.html @@ -56,6 +56,11 @@ var description; var exception = null; + // handle the event which the close() triggers + test.pcLocal.onsignalingstatechange = function (state) { + is(state, "closed", "Received expected onsignalingstatechange event 'closed'"); + } + test.pcLocal.close(); try { description = test.pcLocal.localDescription; } catch (e) { exception = e; } @@ -66,6 +71,11 @@ ok(exception, "Attempt to access remoteDescription of pcLocal after close throws exception"); exception = null; + // handle the event which the close() triggers + test.pcRemote.onsignalingstatechange = function (state) { + is(state, "closed", "Received expected onsignalingstatechange event 'closed'"); + } + test.pcRemote.close(); try { description = test.pcRemote.localDescription; } catch (e) { exception = e; } diff --git a/dom/media/tests/mochitest/test_peerConnection_bug835370.html b/dom/media/tests/mochitest/test_peerConnection_bug835370.html index 9242bed2619..b375d0c71e2 100644 --- a/dom/media/tests/mochitest/test_peerConnection_bug835370.html +++ b/dom/media/tests/mochitest/test_peerConnection_bug835370.html @@ -49,6 +49,8 @@ exception = null; try { pconnects.createOffer(step1, failed, { mandatory: { OfferToReceiveVideo: false, OfferToReceiveAudio: true, MozDontOfferDataChannel: true}, optional: [{ VoiceActivityDetection: true }, { FooBar: "42" }] }); } catch (e) { exception = e; } ok(!exception, "createOffer(step1, failed, { mandatory: { OfferToReceiveVideo: false, OfferToReceiveAudio: true, MozDontOfferDataChannel: true}, optional: [{ VoiceActivityDetection: true }, { FooBar: \"42\" }] }) succeeds"); + pconnect.close(); + pconnects.close(); pconnect = null; pconnects = null; SimpleTest.finish(); diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp index 1a0d0f40c95..2447a6b0eb1 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp @@ -1600,7 +1600,11 @@ PeerConnectionImpl::Close() CSFLogDebug(logTag, "%s: for %s", __FUNCTION__, mHandle.c_str()); PC_AUTO_ENTER_API_CALL_NO_CHECK(); - return CloseInt(); + nsresult res = CloseInt(); + + SetSignalingState_m(PCImplSignalingState::SignalingClosed); + + return res; }