tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RTCError.html (3141B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>RTCError and RTCErrorInit</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="RTCPeerConnection-helper.js"></script>
      7 <script>
      8 'use strict';
      9 
     10 test(() => {
     11  const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
     12  assert_equals(error.message, 'message');
     13  assert_equals(error.errorDetail, 'data-channel-failure');
     14 }, 'RTCError constructor with errorDetail and message');
     15 
     16 test(() => {
     17  const error = new RTCError({errorDetail:'data-channel-failure'});
     18  assert_equals(error.message, '');
     19 }, 'RTCError constructor\'s message argument is optional');
     20 
     21 test(() => {
     22  assert_throws_js(TypeError, () => {
     23    new RTCError();
     24  });
     25  assert_throws_js(TypeError, () => {
     26    new RTCError({});  // {errorDetail} is missing.
     27  });
     28 }, 'RTCError constructor throws TypeError if arguments are missing');
     29 
     30 test(() => {
     31  assert_throws_js(TypeError, () => {
     32    new RTCError({errorDetail:'invalid-error-detail'}, 'message');
     33  });
     34 }, 'RTCError constructor throws TypeError if the errorDetail is invalid');
     35 
     36 test(() => {
     37  const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
     38  assert_equals(error.name, 'OperationError');
     39 }, 'RTCError.name is \'OperationError\'');
     40 
     41 test(() => {
     42  const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
     43  assert_equals(error.code, 0);
     44 }, 'RTCError.code is 0');
     45 
     46 test(() => {
     47  const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
     48  assert_throws_js(TypeError, () => {
     49    error.errorDetail = 'dtls-failure';
     50  });
     51 }, 'RTCError.errorDetail is readonly.');
     52 
     53 test(() => {
     54  // Infers what are valid RTCErrorInit objects by passing them to the RTCError
     55  // constructor.
     56  assert_throws_js(TypeError, () => {
     57    new RTCError({}, 'message');
     58  });
     59  new RTCError({errorDetail:'data-channel-failure'}, 'message');
     60 }, 'RTCErrorInit.errorDetail is the only required attribute');
     61 
     62 // All of these are number types (long or unsigned long).
     63 const nullableAttributes = ['sdpLineNumber',
     64                            'sctpCauseCode',
     65                            'receivedAlert',
     66                            'sentAlert'];
     67 
     68 nullableAttributes.forEach(attribute => {
     69  test(() => {
     70    const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
     71    assert_equals(error[attribute], null);
     72  }, 'RTCError.' + attribute + ' is null by default');
     73 
     74  test(() => {
     75    const error = new RTCError(
     76        {errorDetail:'data-channel-failure', [attribute]: 0}, 'message');
     77    assert_equals(error[attribute], 0);
     78  }, 'RTCError.' + attribute + ' is settable by constructor');
     79 
     80  test(() => {
     81    const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
     82    assert_throws_js(TypeError, () => {
     83      error[attribute] = 42;
     84    });
     85  }, 'RTCError.' + attribute + ' is readonly');
     86 });
     87 
     88 test(function() {
     89  assert_false("httpRequestStatusCode" in RTCError.prototype,
     90               "Should not be supported on the prototype");
     91 }, "RTCError httpRequestStatusCode should not be supported.");
     92 </script>