RTCDataChannelInit-maxPacketLifeTime-enforce-range.html (3366B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>RTCDataChannelInit maxPacketLifeTime [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', { maxPacketLifeTime: 0 }); 18 assert_equals(channel.maxPacketLifeTime, 0); 19 pc.close(); 20 }, 'maxPacketLifeTime with value 0 should succeed'); 21 22 test(() => { 23 const pc = createPC(); 24 const channel = pc.createDataChannel('test', { maxPacketLifeTime: 1 }); 25 assert_equals(channel.maxPacketLifeTime, 1); 26 pc.close(); 27 }, 'maxPacketLifeTime with value 1 should succeed'); 28 29 test(() => { 30 const pc = createPC(); 31 const channel = pc.createDataChannel('test', { maxPacketLifeTime: 1000 }); 32 assert_equals(channel.maxPacketLifeTime, 1000); 33 pc.close(); 34 }, 'maxPacketLifeTime with value 1000 should succeed'); 35 36 test(() => { 37 const pc = createPC(); 38 const channel = pc.createDataChannel('test', { maxPacketLifeTime: 65535 }); 39 assert_equals(channel.maxPacketLifeTime, 65535); 40 pc.close(); 41 }, 'maxPacketLifeTime with maximum value 65535 should succeed'); 42 43 test(() => { 44 const pc = createPC(); 45 const channel = pc.createDataChannel('test', { maxPacketLifeTime: 65534 }); 46 assert_equals(channel.maxPacketLifeTime, 65534); 47 pc.close(); 48 }, 'maxPacketLifeTime with value 65534 (max-1) should succeed'); 49 50 test(() => { 51 const pc = createPC(); 52 const channel = pc.createDataChannel('test', { maxPacketLifeTime: 3 }); 53 assert_equals(channel.maxPacketLifeTime, 3); 54 pc.close(); 55 }, 'maxPacketLifeTime with value 3 should succeed'); 56 57 test(() => { 58 const pc = createPC(); 59 const channel = pc.createDataChannel('test', { maxPacketLifeTime: 10 }); 60 assert_equals(channel.maxPacketLifeTime, 10); 61 pc.close(); 62 }, 'maxPacketLifeTime 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', { maxPacketLifeTime: value }); 81 }); 82 pc.close(); 83 }, `maxPacketLifeTime 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', { maxPacketLifeTime: "100" }); 90 assert_equals(channel.maxPacketLifeTime, 100); 91 pc.close(); 92 }, 'maxPacketLifeTime 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.maxPacketLifeTime, null); 98 pc.close(); 99 }, 'maxPacketLifeTime when omitted should be null'); 100 101 </script>