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
<!doctype html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>RTCDataChannel.prototype.close</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script>
'use strict';

promise_test(async t => {
  let pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  let [channel1, channel2] = await createDataChannelPair(pc1);
  let closeHandler = new Promise(resolve => {
    channel2.onclose = event => {
      resolve();
    };
  });
  let closingSeen = false;
  channel1.onclosing = t.unreached_func();
  channel2.onclosing = event => {
    assert_equals(channel2.readyState, 'closing');
    closingSeen = true;
  }
  channel2.addEventListener('error', t.unreached_func());
  channel1.close();
  await closeHandler;
  assert_equals(channel2.readyState, 'closed');
  assert_true(closingSeen, 'Closing event was seen');
}, 'Close datachannel causes onclosing and onclose to be called');

promise_test(async t => {
  // This is the same test as above, but using addEventListener
  // rather than the "onclose" attribute.
  let pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  let [channel1, channel2] = await createDataChannelPair(pc1);
  let closeHandler = new Promise(resolve => {
    channel2.addEventListener('close', event => {
      resolve();
    });
  });
  let closingSeen = false;
  channel1.addEventListener('closing', t.unreached_func());
  channel2.addEventListener('closing', event => {
    assert_equals(channel2.readyState, 'closing');
    closingSeen = true;
  });
  channel2.addEventListener('error', t.unreached_func());
  channel1.close();
  await closeHandler;
  assert_equals(channel2.readyState, 'closed');
  assert_true(closingSeen, 'Closing event was seen');
}, 'Close datachannel causes closing and close event to be called');

promise_test(async t => {
  let pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  let [channel1, channel2] = await createDataChannelPair(pc1);
  let events = [];
  let error = null;
  let closeHandler = new Promise(resolve => {
    channel2.addEventListener('close', event => {
      events.push('close');
      resolve();
    });
  });
  let errorHandler = new Promise((resolve, reject) => {
    channel2.addEventListener('error', event => {
      events.push('error');
      try {
        assert_true(event instanceof RTCErrorEvent);
        error = event.error;
      } catch (e) {
        // Prevent test from hanging when an assert in the error handler fails.
        reject('Error event wrong: ' + e);
      }
      resolve();
    });
  });
  pc1.close();
  await errorHandler;
  await closeHandler;
  // Error should fire before close.
  assert_array_equals(['error', 'close'], events);
  assert_true(error instanceof RTCError);
  assert_equals(error.name, 'OperationError');
}, 'Close peerconnection causes close event and error to be called');

</script>