function switchRemoteStreamWithoutWaitingForPromisesToResolve() {
  let pc = new RTCPeerConnection();
  let trackEventsFired = 0;
  let streamEventsFired = 0;
  pc.ontrack = (e) => {
    ++trackEventsFired;
    if (trackEventsFired == 1) {
      if (e.track.id != 'track0')
        throw failTest('Unexpected track id in first track event.');
      if (e.receiver.track != e.track)
        throw failTest('Unexpected receiver.track in first track event.');
      if (e.streams[0].id != 'stream0')
        throw failTest('Unexpected stream id in first track event.');
      // Because we did not wait for promises to resolve before calling
      // |setRemoteDescription| a second time, it may or may not have had an
      // effect here. This is inherently racey and we have to check if the
      // stream contains the track.
      if (e.streams[0].getTracks().length != 0) {
        if (e.streams[0].getTracks()[0] != e.track)
          throw failTest('Unexpected track in stream in first track event.');
      }
    } else if (trackEventsFired == 2) {
      if (e.track.id != 'track1')
        throw failTest('Unexpected track id in second track event.');
      if (e.receiver.track != e.track)
        throw failTest('Unexpected receiver.track in second track event.');
      if (e.streams[0].id != 'stream1')
        throw failTest('Unexpected stream id in second track event.');
      if (e.streams[0].getTracks()[0] != e.track)
        throw failTest('The track should belong to the stream in the second ' +
                       'track event.');
      if (streamEventsFired != trackEventsFired)
        throw failTest('All stream events should already have fired.');
      returnToTest('ok');
    }
  };
  pc.onaddstream = (e) => {
    ++streamEventsFired;
    if (streamEventsFired == 1) {
      if (e.stream.id != 'stream0')
        throw failTest('Unexpected stream id in first stream event.');
      // Because we did not wait for promises to resolve before calling
      // |setRemoteDescription| a second time, it may or may not have had an
      // effect here. This is inherently racey and we have to check if the
      // stream contains the track.
      if (e.stream.getTracks().length != 0) {
        if (e.stream.getTracks()[0].id != 'track0')
          throw failTest('Unexpected track id in first stream event.');
      }
    } else if (streamEventsFired == 2) {
      if (e.stream.id != 'stream1')
        throw failTest('Unexpected stream id in second stream event.');
      if (e.stream.getTracks()[0].id != 'track1')
        throw failTest('Unexpected track id in second stream event.');
    }
  };
  pc.setRemoteDescription(createOffer([msid('stream0', 'track0')]));
  pc.setRemoteDescription(createOffer([msid('stream1', 'track1')]));
}
// TODO(hbos): Make this a web platform test instead. https://crbug.com/773472
Make this a web platform test instead.
Make this a web platform test instead .
function switchRemoteStreamWithoutWaitingForPromisesToResolve() {
  let pc = new RTCPeerConnection();
  let trackEventsFired = 0;
  let streamEventsFired = 0;
  pc.ontrack = (e) => {
    ++trackEventsFired;
    if (trackEventsFired == 1) {
      if (e.track.id != 'track0')
        throw failTest('Unexpected track id in first track event.');
      if (e.receiver.track != e.track)
        throw failTest('Unexpected receiver.track in first track event.');
      if (e.streams[0].id != 'stream0')
        throw failTest('Unexpected stream id in first track event.');
      if (e.streams[0].getTracks().length != 0) {
        if (e.streams[0].getTracks()[0] != e.track)
          throw failTest('Unexpected track in stream in first track event.');
      }
    } else if (trackEventsFired == 2) {
      if (e.track.id != 'track1')
        throw failTest('Unexpected track id in second track event.');
      if (e.receiver.track != e.track)
        throw failTest('Unexpected receiver.track in second track event.');
      if (e.streams[0].id != 'stream1')
        throw failTest('Unexpected stream id in second track event.');
      if (e.streams[0].getTracks()[0] != e.track)
        throw failTest('The track should belong to the stream in the second ' +
                       'track event.');
      if (streamEventsFired != trackEventsFired)
        throw failTest('All stream events should already have fired.');
      returnToTest('ok');
    }
  };
  pc.onaddstream = (e) => {
    ++streamEventsFired;
    if (streamEventsFired == 1) {
      if (e.stream.id != 'stream0')
        throw failTest('Unexpected stream id in first stream event.');
      if (e.stream.getTracks().length != 0) {
        if (e.stream.getTracks()[0].id != 'track0')
          throw failTest('Unexpected track id in first stream event.');
      }
    } else if (streamEventsFired == 2) {
      if (e.stream.id != 'stream1')
        throw failTest('Unexpected stream id in second stream event.');
      if (e.stream.getTracks()[0].id != 'track1')
        throw failTest('Unexpected track id in second stream event.');
    }
  };
  pc.setRemoteDescription(createOffer([msid('stream0', 'track0')]));
  pc.setRemoteDescription(createOffer([msid('stream1', 'track1')]));
}
function switchRemoteStreamWithoutWaitingForPromisesToResolve ( ) { let pc = new RTCPeerConnection ( ) ; let trackEventsFired = 0 ; let streamEventsFired = 0 ; pc . ontrack = ( e ) => { ++ trackEventsFired ; if ( trackEventsFired == 1 ) { if ( e . track . id != 'track0' ) throw failTest ( 'Unexpected track id in first track event.' ) ; if ( e . receiver . track != e . track ) throw failTest ( 'Unexpected receiver.track in first track event.' ) ; if ( e . streams [ 0 ] . id != 'stream0' ) throw failTest ( 'Unexpected stream id in first track event.' ) ; if ( e . streams [ 0 ] . getTracks ( ) . length != 0 ) { if ( e . streams [ 0 ] . getTracks ( ) [ 0 ] != e . track ) throw failTest ( 'Unexpected track in stream in first track event.' ) ; } } else if ( trackEventsFired == 2 ) { if ( e . track . id != 'track1' ) throw failTest ( 'Unexpected track id in second track event.' ) ; if ( e . receiver . track != e . track ) throw failTest ( 'Unexpected receiver.track in second track event.' ) ; if ( e . streams [ 0 ] . id != 'stream1' ) throw failTest ( 'Unexpected stream id in second track event.' ) ; if ( e . streams [ 0 ] . getTracks ( ) [ 0 ] != e . track ) throw failTest ( 'The track should belong to the stream in the second ' + 'track event.' ) ; if ( streamEventsFired != trackEventsFired ) throw failTest ( 'All stream events should already have fired.' ) ; returnToTest ( 'ok' ) ; } } ; pc . onaddstream = ( e ) => { ++ streamEventsFired ; if ( streamEventsFired == 1 ) { if ( e . stream . id != 'stream0' ) throw failTest ( 'Unexpected stream id in first stream event.' ) ; if ( e . stream . getTracks ( ) . length != 0 ) { if ( e . stream . getTracks ( ) [ 0 ] . id != 'track0' ) throw failTest ( 'Unexpected track id in first stream event.' ) ; } } else if ( streamEventsFired == 2 ) { if ( e . stream . id != 'stream1' ) throw failTest ( 'Unexpected stream id in second stream event.' ) ; if ( e . stream . getTracks ( ) [ 0 ] . id != 'track1' ) throw failTest ( 'Unexpected track id in second stream event.' ) ; } } ; pc . setRemoteDescription ( createOffer ( [ msid ( 'stream0' , 'track0' ) ] ) ) ; pc . setRemoteDescription ( createOffer ( [ msid ( 'stream1' , 'track1' ) ] ) ) ; }
TODO(hbos): Make this a web platform test instead.
TODO ( hbos ) : Make this a web platform test instead .
// Because we did not wait for promises to resolve before calling // |setRemoteDescription| a second time, it may or may not have had an // effect here. This is inherently racey and we have to check if the // stream contains the track. // Because we did not wait for promises to resolve before calling // |setRemoteDescription| a second time, it may or may not have had an // effect here. This is inherently racey and we have to check if the // stream contains the track.