tor-browser

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

RTCDataChannelInit-maxRetransmits-enforce-range.html (3279B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>RTCDataChannelInit maxRetransmits [EnforceRange] unsigned short tests</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script>
      7 'use strict';
      8 
      9 // Helper to create a basic RTCPeerConnection
     10 function createPC() {
     11  return new RTCPeerConnection();
     12 }
     13 
     14 // Test valid values within unsigned short range (0-65535)
     15 test(() => {
     16  const pc = createPC();
     17  const channel = pc.createDataChannel('test', { maxRetransmits: 0 });
     18  assert_equals(channel.maxRetransmits, 0);
     19  pc.close();
     20 }, 'maxRetransmits with value 0 should succeed');
     21 
     22 test(() => {
     23  const pc = createPC();
     24  const channel = pc.createDataChannel('test', { maxRetransmits: 1 });
     25  assert_equals(channel.maxRetransmits, 1);
     26  pc.close();
     27 }, 'maxRetransmits with value 1 should succeed');
     28 
     29 test(() => {
     30  const pc = createPC();
     31  const channel = pc.createDataChannel('test', { maxRetransmits: 1000 });
     32  assert_equals(channel.maxRetransmits, 1000);
     33  pc.close();
     34 }, 'maxRetransmits with value 1000 should succeed');
     35 
     36 test(() => {
     37  const pc = createPC();
     38  const channel = pc.createDataChannel('test', { maxRetransmits: 65535 });
     39  assert_equals(channel.maxRetransmits, 65535);
     40  pc.close();
     41 }, 'maxRetransmits with maximum value 65535 should succeed');
     42 
     43 test(() => {
     44  const pc = createPC();
     45  const channel = pc.createDataChannel('test', { maxRetransmits: 65534 });
     46  assert_equals(channel.maxRetransmits, 65534);
     47  pc.close();
     48 }, 'maxRetransmits with value 65534 (max-1) should succeed');
     49 
     50 test(() => {
     51  const pc = createPC();
     52  const channel = pc.createDataChannel('test', { maxRetransmits: 3 });
     53  assert_equals(channel.maxRetransmits, 3);
     54  pc.close();
     55 }, 'maxRetransmits with value 3 should succeed');
     56 
     57 test(() => {
     58  const pc = createPC();
     59  const channel = pc.createDataChannel('test', { maxRetransmits: 10 });
     60  assert_equals(channel.maxRetransmits, 10);
     61  pc.close();
     62 }, 'maxRetransmits with value 10 should succeed');
     63 
     64 // Test [EnforceRange] behavior - values outside range should throw TypeError
     65 const badValues = [
     66  { value: -1, description: 'value -1' },
     67  { value: -100, description: 'value -100' },
     68  { value: 65536, description: 'value 65536' },
     69  { value: 100000, description: 'value 100000' },
     70  { value: Infinity, description: 'Infinity' },
     71  { value: -Infinity, description: '-Infinity' },
     72  { value: NaN, description: 'NaN' },
     73  { value: "65536", description: 'string "65536"' }
     74 ];
     75 
     76 badValues.forEach(({ value, description }) => {
     77  test(() => {
     78    const pc = createPC();
     79    assert_throws_js(TypeError, () => {
     80      pc.createDataChannel('test', { maxRetransmits: value });
     81    });
     82    pc.close();
     83  }, `maxRetransmits with ${description} should throw TypeError`);
     84 });
     85 
     86 // Test numeric strings (should be converted to numbers)
     87 test(() => {
     88  const pc = createPC();
     89  const channel = pc.createDataChannel('test', { maxRetransmits: "100" });
     90  assert_equals(channel.maxRetransmits, 100);
     91  pc.close();
     92 }, 'maxRetransmits with numeric string "100" should be converted to 100');
     93 
     94 test(() => {
     95  const pc = createPC();
     96  const channel = pc.createDataChannel('test', {});
     97  assert_equals(channel.maxRetransmits, null);
     98  pc.close();
     99 }, 'maxRetransmits when omitted should be null');
    100 
    101 </script>