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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
<!doctype html>
<meta charset=utf-8>
<title>RTCTrackEvent constructor</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
  'use strict';

  // Test is based on the following editor draft:
  // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html

  /*
    5.7.  RTCTrackEvent
      [Constructor(DOMString type, RTCTrackEventInit eventInitDict)]
      interface RTCTrackEvent : Event {
        readonly attribute RTCRtpReceiver           receiver;
        readonly attribute MediaStreamTrack         track;
        [SameObject]
        readonly attribute FrozenArray<MediaStream> streams;
        readonly attribute RTCRtpTransceiver        transceiver;
      };

      dictionary RTCTrackEventInit : EventInit {
        required RTCRtpReceiver        receiver;
        required MediaStreamTrack      track;
                 sequence<MediaStream> streams = [];
        required RTCRtpTransceiver     transceiver;
      };
   */

  test(t => {
    const pc = new RTCPeerConnection();
    const transceiver = pc.addTransceiver('audio');
    const { receiver } = transceiver;
    const { track } = receiver;

    const trackEvent = new RTCTrackEvent('track', {
      receiver, track, transceiver
    });

    assert_equals(trackEvent.receiver, receiver);
    assert_equals(trackEvent.track, track);
    assert_array_equals(trackEvent.streams, []);
    assert_equals(trackEvent.streams, trackEvent.streams, '[SameObject]');
    assert_equals(trackEvent.transceiver, transceiver);

    assert_equals(trackEvent.type, 'track');
    assert_false(trackEvent.bubbles);
    assert_false(trackEvent.cancelable);

  }, `new RTCTrackEvent() with valid receiver, track, transceiver should succeed`);

  test(t => {
    const pc = new RTCPeerConnection();
    const transceiver = pc.addTransceiver('audio');
    const { receiver } = transceiver;
    const { track } = receiver;

    const stream = new MediaStream([track]);

    const trackEvent = new RTCTrackEvent('track', {
      receiver, track, transceiver,
      streams: [stream]
    });

    assert_equals(trackEvent.receiver, receiver);
    assert_equals(trackEvent.track, track);
    assert_array_equals(trackEvent.streams, [stream]);
    assert_equals(trackEvent.transceiver, transceiver);

  }, `new RTCTrackEvent() with valid receiver, track, streams, transceiver should succeed`);

  test(t => {
    const pc = new RTCPeerConnection();
    const transceiver = pc.addTransceiver('audio');
    const { receiver } = transceiver;
    const { track } = receiver;

    const stream1 = new MediaStream([track]);
    const stream2 = new MediaStream([track]);

    const trackEvent = new RTCTrackEvent('track', {
      receiver, track, transceiver,
      streams: [stream1, stream2]
    });

    assert_equals(trackEvent.receiver, receiver);
    assert_equals(trackEvent.track, track);
    assert_array_equals(trackEvent.streams, [stream1, stream2]);
    assert_equals(trackEvent.transceiver, transceiver);

  }, `new RTCTrackEvent() with valid receiver, track, multiple streams, transceiver should succeed`);

  test(t => {
    const pc = new RTCPeerConnection();
    const transceiver = pc.addTransceiver('audio');
    const receiver = pc.addTransceiver('audio').receiver;
    const track =  pc.addTransceiver('audio').receiver.track;

    const stream = new MediaStream();

    const trackEvent = new RTCTrackEvent('track', {
      receiver, track, transceiver,
      streams: [stream]
    });

    assert_equals(trackEvent.receiver, receiver);
    assert_equals(trackEvent.track, track);
    assert_array_equals(trackEvent.streams, [stream]);
    assert_equals(trackEvent.transceiver, transceiver);

  }, `new RTCTrackEvent() with unrelated receiver, track, streams, transceiver should succeed`);

  test(t => {
    const pc = new RTCPeerConnection();
    const transceiver = pc.addTransceiver('audio');
    const { receiver } = transceiver;
    const { track } = receiver;

    assert_throws_js(TypeError, () =>
      new RTCTrackEvent('track', {
        receiver, track
      }));

  }, `new RTCTrackEvent() with no transceiver should throw TypeError`);

  test(t => {
    const pc = new RTCPeerConnection();
    const transceiver = pc.addTransceiver('audio');
    const { receiver } = transceiver;

    assert_throws_js(TypeError, () =>
      new RTCTrackEvent('track', {
        receiver, transceiver
      }));

  }, `new RTCTrackEvent() with no track should throw TypeError`);

  test(t => {
    const pc = new RTCPeerConnection();
    const transceiver = pc.addTransceiver('audio');
    const { receiver } = transceiver;
    const { track } = receiver;

    assert_throws_js(TypeError, () =>
      new RTCTrackEvent('track', {
        track, transceiver
      }));

  }, `new RTCTrackEvent() with no receiver should throw TypeError`);

  /*
    Coverage Report
      Interface tests are counted as 1 trivial test

      Tested         1
      Total          1
   */
</script>