From 0e6e49d74dedfb1414cfaccd30c06a641e2f1c16 Mon Sep 17 00:00:00 2001 From: "Byron Campen [:bwc]" Date: Mon, 27 Apr 2020 16:42:49 +0000 Subject: [PATCH] Bug 1629565: Test that we do not transition to "gathering" on a simple reoffer. r=jib Differential Revision: https://phabricator.services.mozilla.com/D72236 --- .../RTCPeerConnection-iceGatheringState.html | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/testing/web-platform/tests/webrtc/RTCPeerConnection-iceGatheringState.html b/testing/web-platform/tests/webrtc/RTCPeerConnection-iceGatheringState.html index b20dac60239a..089a82b97b96 100644 --- a/testing/web-platform/tests/webrtc/RTCPeerConnection-iceGatheringState.html +++ b/testing/web-platform/tests/webrtc/RTCPeerConnection-iceGatheringState.html @@ -84,10 +84,53 @@ assert_unreached(`Unhandled rejection ${err.name}: ${err.message}`))); }, 'iceGatheringState should eventually become complete after setLocalDescription'); + const iceGatheringStateTransitions = async (pc, ...states) => { + for (const state of states) { + await new Promise((resolve, reject) => { + pc.addEventListener('icegatheringstatechange', () => { + if (pc.iceGatheringState == state) { + resolve(); + } else { + reject(`Unexpected gathering state: ${pc.iceGatheringState}, was expecting ${state}`); + } + }, {once: true}); + }); + } + }; + + const initialOfferAnswer = async (pc1, pc2, offerOptions) => { + await pc1.setLocalDescription( + await pc1.createOffer(offerOptions)); + const pc1Transitions = iceGatheringStateTransitions(pc1, 'gathering', 'complete'); + await pc2.setRemoteDescription(pc1.localDescription); + await pc2.setLocalDescription(await pc2.createAnswer()); + const pc2Transitions = iceGatheringStateTransitions(pc2, 'gathering', 'complete'); + await pc1.setRemoteDescription(pc2.localDescription); + + await pc1Transitions; + await pc2Transitions; + }; + const expectNoMoreGatheringStateChanges = async (t, pc) => { pc.onicegatheringstatechange = t.step_func(() => assert_unreached('Should not get an icegatheringstatechange right now!')); }; + promise_test(async t => { + const pc1 = new RTCPeerConnection(); + t.add_cleanup(() => pc1.close()); + const pc2 = new RTCPeerConnection(); + t.add_cleanup(() => pc2.close()); + await initialOfferAnswer(pc1, pc2, {offerToReceiveAudio:true}); + + expectNoMoreGatheringStateChanges(t, pc1); + expectNoMoreGatheringStateChanges(t, pc2); + + await pc1.setLocalDescription(await pc1.createOffer()); + await pc2.setLocalDescription(await pc2.createOffer()); + + await new Promise(r => t.step_timeout(r, 500)); + }, 'setLocalDescription(reoffer) with no new transports should not cause iceGatheringState to change'); + promise_test(async t => { const pc1 = new RTCPeerConnection(); t.add_cleanup(() => pc1.close());