Bug 1386143: fix WPT PeerConnection.onnegotiationneeded tests draft
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Wed, 23 Aug 2017 22:50:18 -0700
changeset 652512 4e160a27ebb26019a5bcdc5426311d4572f223d9
parent 651395 c86b7150523c10e1d1dbc0be2d8ed96f205be35f
child 728109 93282837765db1ea4c29eeaa04d3aff6ddc29a21
push id76080
push userdrno@ohlmeier.org
push dateThu, 24 Aug 2017 22:49:55 +0000
bugs1386143
milestone57.0a1
Bug 1386143: fix WPT PeerConnection.onnegotiationneeded tests MozReview-Commit-ID: Lq7buSDAnHt
testing/web-platform/meta/webrtc/RTCPeerConnection-onnegotiationneeded.html.ini
testing/web-platform/tests/webrtc/RTCPeerConnection-onnegotiationneeded.html
--- a/testing/web-platform/meta/webrtc/RTCPeerConnection-onnegotiationneeded.html.ini
+++ b/testing/web-platform/meta/webrtc/RTCPeerConnection-onnegotiationneeded.html.ini
@@ -1,18 +1,14 @@
 [RTCPeerConnection-onnegotiationneeded.html]
   type: testharness
-  expected: TIMEOUT
-  [task for negotiationneeded event should be enqueued for next tick]
-    expected: TIMEOUT
-
+  expected: OK
   [addTransceiver() should fire negotiationneeded event]
-    expected: NOTRUN
+    expected: FAIL
 
   [Calling addTransceiver() twice should fire negotiationneeded event once]
     expected: FAIL
 
-  [negotiationneeded event should not fire if signaling state is not stable]
+  [Calling both addTransceiver() and createDataChannel() should fire negotiationneeded event once]
     expected: FAIL
 
   [negotiationneeded event should fire only after signaling state go back to stable]
-    expected: NOTRUN
-
+    expected: FAIL
--- a/testing/web-platform/tests/webrtc/RTCPeerConnection-onnegotiationneeded.html
+++ b/testing/web-platform/tests/webrtc/RTCPeerConnection-onnegotiationneeded.html
@@ -77,35 +77,28 @@
     6.1.  RTCPeerConnection Interface Extensions
 
       createDataChannel
         14. If channel was the first RTCDataChannel created on connection,
             update the negotiation-needed flag for connection.
    */
   promise_test(t => {
     const pc = new RTCPeerConnection();
-    const promise = awaitNegotiation(pc);
-    pc.createDataChannel('test');
-    return promise;
-  }, 'Creating first data channel should fire negotiationneeded event');
+    const negotiated = awaitNegotiation(pc);
 
-  promise_test(t => {
-    const pc = new RTCPeerConnection();
     pc.createDataChannel('test');
-    // Attaching the event handler after the negotiation-needed steps
-    // are performed should still receive the event, because the event
-    // firing is queued as a task
-    return awaitNegotiation(pc);
-  }, 'task for negotiationneeded event should be enqueued for next tick');
+    return negotiated;
+  }, 'Creating first data channel should fire negotiationneeded event');
 
   test_never_resolve(t => {
     const pc = new RTCPeerConnection();
-    pc.createDataChannel('foo');
+    const negotiated = awaitNegotiation(pc);
 
-    return awaitNegotiation(pc)
+    pc.createDataChannel('foo');
+    return negotiated
       .then(({nextPromise}) => {
       pc.createDataChannel('bar');
       return nextPromise;
     });
   }, 'calling createDataChannel twice should fire negotiationneeded event once');
 
   /*
     4.7.3.  Updating the Negotiation-Needed flag
@@ -116,82 +109,89 @@
               according to [JSEP] (section 3.4.1.), return "true".
 
     5.1.  RTCPeerConnection Interface Extensions
       addTransceiver
         9.  Update the negotiation-needed flag for connection.
    */
   promise_test(t => {
     const pc = new RTCPeerConnection();
+    const negotiated = awaitNegotiation(pc);
+
     pc.addTransceiver('audio');
-    return awaitNegotiation(pc);
+    return negotiated;
   }, 'addTransceiver() should fire negotiationneeded event');
 
   /*
     4.7.3.  Updating the Negotiation-Needed flag
       To update the negotiation-needed flag
       4.  If connection's [[needNegotiation]] slot is already true, abort these steps.
    */
   test_never_resolve(t => {
     const pc = new RTCPeerConnection();
+    const negotiated = awaitNegotiation(pc);
+
     pc.addTransceiver('audio');
-    return awaitNegotiation(pc)
+    return negotiated
     .then(({nextPromise}) => {
       pc.addTransceiver('video');
       return nextPromise;
     });
   }, 'Calling addTransceiver() twice should fire negotiationneeded event once');
 
   /*
     4.7.3.  Updating the Negotiation-Needed flag
       To update the negotiation-needed flag
       4.  If connection's [[needNegotiation]] slot is already true, abort these steps.
    */
   test_never_resolve(t => {
     const pc = new RTCPeerConnection();
+    const negotiated = awaitNegotiation(pc);
+
     pc.createDataChannel('test');
-    return awaitNegotiation(pc)
+    return negotiated
     .then(({nextPromise}) => {
       pc.addTransceiver('video');
       return nextPromise;
     });
   }, 'Calling both addTransceiver() and createDataChannel() should fire negotiationneeded event once');
 
   /*
     4.7.3.  Updating the Negotiation-Needed flag
       To update the negotiation-needed flag
       2.  If connection's signaling state is not "stable", abort these steps.
    */
   test_never_resolve(t => {
     const pc = new RTCPeerConnection();
-    const promise = awaitNegotiation(pc);
+    const negotiated = awaitNegotiation(pc);
 
-    return pc.createOffer()
+    return pc.createOffer({ offerToReceiveAudio: true })
     .then(offer => pc.setLocalDescription(offer))
-    .then(() => {
+    .then(() => negotiated)
+    .then(({nextPromise}) => {
       assert_equals(pc.signalingState, 'have-local-offer');
       pc.createDataChannel('test');
-      return promise;
+      return nextPromise;
     });
   }, 'negotiationneeded event should not fire if signaling state is not stable');
 
   /*
-    4.3.1.6.  Set the RTCSessionSessionDescription
+    4.4.1.6.  Set the RTCSessionSessionDescription
       2.2.10. If connection's signaling state is now stable, update the negotiation-needed
               flag. If connection's [[NegotiationNeeded]] slot was true both before and after
               this update, queue a task that runs the following steps:
         2.  If connection's [[NegotiationNeeded]] slot is false, abort these steps.
         3.  Fire a simple event named negotiationneeded at connection.
    */
   promise_test(t => {
     const pc = new RTCPeerConnection();
 
     return assert_first_promise_fulfill_after_second(
       awaitNegotiation(pc),
-      pc.createOffer()
+      pc.createOffer({ offerToReceiveAudio: true })
       .then(offer =>
         pc.setLocalDescription(offer)
         .then(() => {
           pc.createDataChannel('test');
           return generateAnswer(offer);
         }))
       .then(answer => pc.setRemoteDescription(answer)),
       'Expect negotiationneeded promise to resolve after pc has set remote answer and go back to stable state');