Bug 1461563 - Update RTCPeerConnection-setRemoteDescription.html to spec, and avoid hang-prone test_state_change_event(). r=bwc
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 14 May 2018 10:38:55 -0400
changeset 472716 1d34216b7f19e85e28b52d5e900b5c0a0d9728bb
parent 472715 23b5cf2c6824961ffb77a4a1f9d5d0888d678281
child 472717 14fb6876d99650f5fbcca42c000703fc198abe59
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwc
bugs1461563
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1461563 - Update RTCPeerConnection-setRemoteDescription.html to spec, and avoid hang-prone test_state_change_event(). r=bwc MozReview-Commit-ID: 1YuFJsv74dJ
testing/web-platform/meta/webrtc/RTCPeerConnection-setRemoteDescription.html.ini
testing/web-platform/tests/webrtc/RTCPeerConnection-setRemoteDescription.html
--- a/testing/web-platform/meta/webrtc/RTCPeerConnection-setRemoteDescription.html.ini
+++ b/testing/web-platform/meta/webrtc/RTCPeerConnection-setRemoteDescription.html.ini
@@ -1,42 +1,3 @@
 [RTCPeerConnection-setRemoteDescription.html]
-  expected: TIMEOUT
-  [Malformed SDP description should be rejected with RTCError]
-    expected: FAIL
-
-  [SDP type that is invalid for current signaling state should be rejected with InvalidStateError]
-    expected: FAIL
-
-  [setRemoteDescription with valid offer should succeed]
-    expected: FAIL
-
-  [Setting remote description multiple times with different offer should succeed]
-    expected: FAIL
-
-  [setRemoteDescription(offer) should never resolve if connection is closed in parallel]
-    disabled: unstable
-    expected: FAIL
-
-  [setRemoteDescription(offer) with invalid SDP should reject with RTCError]
-    expected: FAIL
-
-  [setRemoteDescription() with valid state and answer should succeed]
-    expected: FAIL
-
   [Switching role from offerer to answerer after going back to stable state should succeed]
     expected: FAIL
-
-  [Calling setRemoteDescription(answer) from stable state should reject with InvalidStateError]
-    expected: FAIL
-
-  [Calling setRemoteDescription(offer) from have-local-offer state should reject with InvalidStateError]
-    expected: FAIL
-
-  [Calling setRemoteDescription(answer) from have-remote-offer state should reject with InvalidStateError]
-    expected: FAIL
-
-  [setRemoteDescription should trigger ontrack event when the MSID of the stream is is parsed.]
-    expected: FAIL
-
-  [Test onsignalingstatechange event for Switching role from offerer to answerer after going back to stable state should succeed]
-    expected: TIMEOUT
-
--- a/testing/web-platform/tests/webrtc/RTCPeerConnection-setRemoteDescription.html
+++ b/testing/web-platform/tests/webrtc/RTCPeerConnection-setRemoteDescription.html
@@ -6,21 +6,18 @@
 <script src="RTCPeerConnection-helper.js"></script>
 <script>
   'use strict';
 
   // Test is based on the following editor draft:
   // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html
 
   // The following helper functions are called from RTCPeerConnection-helper.js:
-  //   generateOffer()
-  //   generateAnswer()
   //   assert_session_desc_not_equals()
   //   assert_session_desc_equals()
-  //   test_state_change_event()
 
   /*
     4.3.2.  Interface Definition
       [Constructor(optional RTCConfiguration configuration)]
       interface RTCPeerConnection : EventTarget {
         Promise<void>                      setRemoteDescription(
             RTCSessionDescriptionInit description);
 
@@ -43,86 +40,111 @@
         "answer",
         "rollback"
       };
    */
 
   /*
     4.6.1.  enum RTCSdpType
    */
-  promise_test(t => {
+  promise_test(async t => {
     const pc = new RTCPeerConnection();
+    t.add_cleanup(() => pc.close());
 
     // SDP is validated after WebIDL validation
-    return promise_rejects(t, new TypeError(),
-      pc.setRemoteDescription({
-        type: 'bogus',
-        sdp: 'bogus'
-      }));
+    try {
+      await pc.setRemoteDescription({ type: 'bogus', sdp: 'bogus' });
+      t.unreached_func("Should have rejected.");
+    } catch (e) {
+      assert_throws(new TypeError(), () => { throw e });
+    }
   }, 'setRemoteDescription with invalid type and invalid SDP should reject with TypeError');
 
-  promise_test(t => {
+  promise_test(async t => {
     const pc = new RTCPeerConnection();
+    t.add_cleanup(() => pc.close());
 
     // SDP is validated after validating type
-    return promise_rejects(t, 'InvalidStateError',
-      pc.setRemoteDescription({
-        type: 'answer',
-        sdp: 'invalid'
-      }));
+    try {
+      await pc.setRemoteDescription({ type: 'answer', sdp: 'invalid' });
+      t.unreached_func("Should have rejected.");
+    } catch (e) {
+      assert_throws('InvalidStateError', () => { throw e });
+    }
   }, 'setRemoteDescription() with invalid SDP and stable state should reject with InvalidStateError');
 
+  /* Dedicated signalingstate events test. */
+
+  promise_test(async t => {
+    const pc = new RTCPeerConnection();
+    const pc2 = new RTCPeerConnection();
+    t.add_cleanup(() => pc.close());
+    t.add_cleanup(() => pc2.close());
+
+    let eventCount = 0;
+    const states = [
+      'stable', 'have-local-offer', 'stable', 'have-remote-offer', 'closed'
+    ];
+    pc.onsignalingstatechange = () =>
+        assert_equals(pc.signalingState, states[++eventCount]);
+
+    const assert_state = state => {
+      assert_equals(state, pc.signalingState);
+      assert_equals(state, states[eventCount]);
+    };
+
+    const offer = await pc.createOffer({ offerToReceiveAudio: true });
+    assert_state('stable');
+    await pc.setLocalDescription(offer);
+    assert_state('have-local-offer');
+    await pc2.setRemoteDescription(offer);
+    await pc2.setLocalDescription(await pc2.createAnswer());
+    await pc.setRemoteDescription(pc2.localDescription);
+    assert_state('stable');
+    await pc.setRemoteDescription(await pc2.createOffer());
+    assert_state('have-remote-offer');
+    pc.close();
+    assert_state('closed');
+  }, 'Negotiation should fire signalingsstate events');
+
   /* Operations after returning to stable state */
 
-  promise_test(t => {
+  promise_test(async t => {
     const pc = new RTCPeerConnection();
     const pc2 = new RTCPeerConnection();
-
-    test_state_change_event(t, pc,
-      ['have-remote-offer', 'stable', 'have-remote-offer']);
+    t.add_cleanup(() => pc.close());
+    t.add_cleanup(() => pc2.close());
 
-    return pc2.createOffer({ offerToReceiveAudio: true })
-    .then(offer1 =>
-      pc.setRemoteDescription(offer1)
-      .then(() => pc.createAnswer())
-      .then(answer => pc.setLocalDescription(answer))
-      .then(() => pc2.createOffer({ offerToReceiveVideo: true }))
-      .then(offer2 => {
-        return pc.setRemoteDescription(offer2)
-        .then(() => {
-          assert_equals(pc.signalingState, 'have-remote-offer');
-          assert_session_desc_not_equals(offer1, offer2);
-          assert_session_desc_equals(pc.remoteDescription, offer2);
-          assert_session_desc_equals(pc.currentRemoteDescription, offer1);
-          assert_session_desc_equals(pc.pendingRemoteDescription, offer2);
-        });
-      }));
+    const offer1 = await pc2.createOffer({ offerToReceiveAudio: true });
+    await pc.setRemoteDescription(offer1);
+    await pc.setLocalDescription(await pc.createAnswer());
+    const offer2 = await pc2.createOffer({ offerToReceiveVideo: true });
+    await pc.setRemoteDescription(offer2);
+    assert_session_desc_not_equals(offer1, offer2);
+    assert_session_desc_equals(pc.remoteDescription, offer2);
+    assert_session_desc_equals(pc.currentRemoteDescription, offer1);
+    assert_session_desc_equals(pc.pendingRemoteDescription, offer2);
   }, 'Calling setRemoteDescription() again after one round of remote-offer/local-answer should succeed');
 
-  promise_test(t => {
+  promise_test(async t => {
     const pc = new RTCPeerConnection();
-
-    test_state_change_event(t, pc,
-       ['have-local-offer', 'stable', 'have-remote-offer']);
+    const pc2 = new RTCPeerConnection();
+    t.add_cleanup(() => pc.close());
+    t.add_cleanup(() => pc2.close());
 
-    return pc.createOffer({ offerToReceiveAudio: true })
-    .then(offer =>
-      pc.setLocalDescription(offer)
-      .then(() => generateAnswer(offer)))
-    .then(answer =>
-      pc.setRemoteDescription(answer)
-      .then(() => generateOffer({ pc, data: true }))
-      .then(offer =>
-        pc.setRemoteDescription(offer)
-        .then(() => {
-          assert_equals(pc.signalingState, 'have-remote-offer');
-          assert_session_desc_equals(pc.remoteDescription, offer);
-          assert_session_desc_equals(pc.currentRemoteDescription, answer);
-          assert_session_desc_equals(pc.pendingRemoteDescription, offer);
-        })));
+    const offer = await pc.createOffer({ offerToReceiveAudio: true });
+    await pc.setLocalDescription(offer);
+    await pc2.setRemoteDescription(offer);
+    const answer = await pc2.createAnswer();
+    await pc2.setLocalDescription(answer);
+    await pc.setRemoteDescription(answer);
+    await pc.setRemoteDescription(await pc2.createOffer());
+    assert_equals(pc.remoteDescription.sdp, pc.pendingRemoteDescription.sdp);
+    assert_session_desc_equals(pc.remoteDescription, offer);
+    assert_session_desc_equals(pc.currentRemoteDescription, answer);
   }, 'Switching role from offerer to answerer after going back to stable state should succeed');
 
   /*
     TODO
     4.3.2.  setRemoteDescription
       - If an a=identity attribute is present in the session description, the browser
         validates the identity assertion.
    */