async function testRTCRtpSenderReplaceTrackSendsNewVideoTrack() {
  const redCanvas = document.getElementById('redCanvas');
  const redCanvasStream = redCanvas.captureStream(10);
  const blueCanvas = document.getElementById('blueCanvas');
  const blueCanvasStream = blueCanvas.captureStream(10);
  const remoteVideo = document.getElementById('remote-view');
  const remoteVideoCanvas = document.getElementById('whiteCanvas');

  const caller = new RTCPeerConnection();
  const callee = new RTCPeerConnection();

  // Connect and send "redCanvas" to callee.
  const sender = caller.addTrack(redCanvasStream.getTracks()[0],
                                 redCanvasStream);
  const connectPromise = connect(caller, callee);
  const trackEvent = await eventAsAsyncFunction(callee, 'ontrack');
  remoteVideo.srcObject = trackEvent.streams[0];
  await connectPromise;

  // Ensure a red frame is sent by redrawing the canvas while polling.
  function fillRedCanvas() { fillCanvas(redCanvas, 'red'); }
  let receivedColor = await pollNextVideoColor(
      fillRedCanvas, remoteVideo, remoteVideoCanvas);
  if (receivedColor != 'red')
    throw failTest('Expected red, but received: ' + receivedColor);

  // Send "blueCanvas" to callee using the existing sender.
  await sender.replaceTrack(blueCanvasStream.getTracks()[0]);

  // Ensure a blue frame is sent by redrawing the canvas while polling.
  function fillBlueCanvas() { fillCanvas(blueCanvas, 'blue'); }
  receivedColor = await pollNextVideoColor(
      fillBlueCanvas, remoteVideo, remoteVideoCanvas);
  if (receivedColor != 'blue')
    throw failTest('Expected blue, but received: ' + receivedColor);

  returnToTest('test-passed');
}
// updated by received webrtc streams in content_shell. https://crbug.com/793808
updated by received webrtc streams in content_shell.
updated by received webrtc streams in content_shell .
async function testRTCRtpSenderReplaceTrackSendsNewVideoTrack() {
  const redCanvas = document.getElementById('redCanvas');
  const redCanvasStream = redCanvas.captureStream(10);
  const blueCanvas = document.getElementById('blueCanvas');
  const blueCanvasStream = blueCanvas.captureStream(10);
  const remoteVideo = document.getElementById('remote-view');
  const remoteVideoCanvas = document.getElementById('whiteCanvas');
  const caller = new RTCPeerConnection();
  const callee = new RTCPeerConnection();
  const sender = caller.addTrack(redCanvasStream.getTracks()[0],
                                 redCanvasStream);
  const connectPromise = connect(caller, callee);
  const trackEvent = await eventAsAsyncFunction(callee, 'ontrack');
  remoteVideo.srcObject = trackEvent.streams[0];
  await connectPromise;
  function fillRedCanvas() { fillCanvas(redCanvas, 'red'); }
  let receivedColor = await pollNextVideoColor(
      fillRedCanvas, remoteVideo, remoteVideoCanvas);
  if (receivedColor != 'red')
    throw failTest('Expected red, but received: ' + receivedColor);
  await sender.replaceTrack(blueCanvasStream.getTracks()[0]);
  function fillBlueCanvas() { fillCanvas(blueCanvas, 'blue'); }
  receivedColor = await pollNextVideoColor(
      fillBlueCanvas, remoteVideo, remoteVideoCanvas);
  if (receivedColor != 'blue')
    throw failTest('Expected blue, but received: ' + receivedColor);
  returnToTest('test-passed');
}
async function testRTCRtpSenderReplaceTrackSendsNewVideoTrack ( ) { const redCanvas = document . getElementById ( 'redCanvas' ) ; const redCanvasStream = redCanvas . captureStream ( 10 ) ; const blueCanvas = document . getElementById ( 'blueCanvas' ) ; const blueCanvasStream = blueCanvas . captureStream ( 10 ) ; const remoteVideo = document . getElementById ( 'remote-view' ) ; const remoteVideoCanvas = document . getElementById ( 'whiteCanvas' ) ; const caller = new RTCPeerConnection ( ) ; const callee = new RTCPeerConnection ( ) ; const sender = caller . addTrack ( redCanvasStream . getTracks ( ) [ 0 ] , redCanvasStream ) ; const connectPromise = connect ( caller , callee ) ; const trackEvent = await eventAsAsyncFunction ( callee , 'ontrack' ) ; remoteVideo . srcObject = trackEvent . streams [ 0 ] ; await connectPromise ; function fillRedCanvas ( ) { fillCanvas ( redCanvas , 'red' ) ; } let receivedColor = await pollNextVideoColor ( fillRedCanvas , remoteVideo , remoteVideoCanvas ) ; if ( receivedColor != 'red' ) throw failTest ( 'Expected red, but received: ' + receivedColor ) ; await sender . replaceTrack ( blueCanvasStream . getTracks ( ) [ 0 ] ) ; function fillBlueCanvas ( ) { fillCanvas ( blueCanvas , 'blue' ) ; } receivedColor = await pollNextVideoColor ( fillBlueCanvas , remoteVideo , remoteVideoCanvas ) ; if ( receivedColor != 'blue' ) throw failTest ( 'Expected blue, but received: ' + receivedColor ) ; returnToTest ( 'test-passed' ) ; }
updated by received webrtc streams in content_shell.
updated by received webrtc streams in content_shell .
// Connect and send "redCanvas" to callee. // Ensure a red frame is sent by redrawing the canvas while polling. // Send "blueCanvas" to callee using the existing sender. // Ensure a blue frame is sent by redrawing the canvas while polling.