DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (205d1b4e8f69)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

'use strict';

// In this test, the promises should resolve in the execution order
// (setLocalDescription, setLocalDescription, addIceCandidate) as is ensured by
// the Operations Chain; if an operation is pending, executing another operation
// will queue it. This test will fail if an Operations Chain is not implemented,
// but it gives the implementation some slack: it only ensures that
// addIceCandidate() is not resolved first, allowing timing issues in resolving
// promises where the test still passes even if addIceCandidate() is resolved
// *before* the second setLocalDescription().
//
// This test covers Chrome issue (https://crbug.com/1019222), but does not
// require setLocalDescription-promises to resolve immediately which is another
// Chrome bug (https://crbug.com/1019232). The true order is covered by the next
// test.
// TODO(https://crbug.com/1019232): Delete this test when the next test passes
// in Chrome.
promise_test(async t => {
  const caller = new RTCPeerConnection();
  t.add_cleanup(() => caller.close());
  const callee = new RTCPeerConnection();
  t.add_cleanup(() => callee.close());
  caller.addTransceiver('audio');

  const candidatePromise = new Promise(resolve => {
    caller.onicecandidate = e => resolve(e.candidate);
  });
  await caller.setLocalDescription(await caller.createOffer());
  await callee.setRemoteDescription(caller.localDescription);
  const candidate = await candidatePromise;

  // Chain setLocalDescription(), setLocalDescription() and addIceCandidate()
  // without performing await between the calls.
  const pendingPromises = [];
  const resolveOrder = [];
  pendingPromises.push(callee.setLocalDescription().then(() => {
    resolveOrder.push('setLocalDescription 1');
  }));
  pendingPromises.push(callee.setLocalDescription().then(() => {
    resolveOrder.push('setLocalDescription 2');
  }));
  pendingPromises.push(callee.addIceCandidate(candidate).then(() => {
    resolveOrder.push('addIceCandidate');
  }));
  await Promise.all(pendingPromises);

  assert_equals(resolveOrder[0], 'setLocalDescription 1');
}, 'addIceCandidate is not resolved first if 2x setLocalDescription ' +
   'operations are pending');

promise_test(async t => {
  const caller = new RTCPeerConnection();
  t.add_cleanup(() => caller.close());
  const callee = new RTCPeerConnection();
  t.add_cleanup(() => callee.close());
  caller.addTransceiver('audio');

  const candidatePromise = new Promise(resolve => {
    caller.onicecandidate = e => resolve(e.candidate);
  });
  await caller.setLocalDescription(await caller.createOffer());
  await callee.setRemoteDescription(caller.localDescription);
  const candidate = await candidatePromise;

  // Chain setLocalDescription(), setLocalDescription() and addIceCandidate()
  // without performing await between the calls.
  const pendingPromises = [];
  const resolveOrder = [];
  pendingPromises.push(callee.setLocalDescription().then(() => {
    resolveOrder.push('setLocalDescription 1');
  }));
  pendingPromises.push(callee.setLocalDescription().then(() => {
    resolveOrder.push('setLocalDescription 2');
  }));
  pendingPromises.push(callee.addIceCandidate(candidate).then(() => {
    resolveOrder.push('addIceCandidate');
  }));
  await Promise.all(pendingPromises);

  // This test verifies that both issues described in https://crbug.com/1019222
  // and https://crbug.com/1019232 are fixed. If this test passes in Chrome, the
  // ICE candidate exchange issues described in
  // https://github.com/web-platform-tests/wpt/issues/19866 should be resolved.
  assert_array_equals(
      resolveOrder,
      ['setLocalDescription 1', 'setLocalDescription 2', 'addIceCandidate']);
}, 'addIceCandidate and setLocalDescription are resolved in the correct ' +
   'order, as defined by the operations chain specification');

</script>