toJSON.html (1587B)
1 <!doctype html> 2 <title>WebRTC objects toJSON() methods</title> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <script> 6 'use strict'; 7 // The tests for 8 // * RTCSessionDescription.toJSON() 9 // * RTCIceCandidate.toJSON() 10 // are kept in a single file since they are similar and typically 11 // would need to be changed together. 12 test(t => { 13 const desc = new RTCSessionDescription({ 14 type: 'offer', 15 sdp: 'bogus sdp', 16 }); 17 const json = desc.toJSON(); 18 19 // Assert that candidates which should be serialized are present. 20 assert_equals(json.type, desc.type); 21 assert_equals(json.sdp, desc.sdp); 22 23 // Assert that no other attributes are present by checking the size. 24 assert_equals(Object.keys(json).length, 2); 25 26 }, 'RTCSessionDescription.toJSON serializes only specific attributes'); 27 28 test(t => { 29 const candidate = new RTCIceCandidate({ 30 sdpMLineIndex: 0, 31 sdpMid: '0', 32 candidate: 'candidate:1905690388 1 udp 2113937151 192.168.0.1 58041 typ host', 33 usernameFragment: 'test' 34 }); 35 const json = candidate.toJSON(); 36 37 // Assert that candidates which should be serialized are present. 38 assert_equals(json.sdpMLineIndex, candidate.sdpMLineIndex); 39 assert_equals(json.sdpMid, candidate.sdpMid); 40 assert_equals(json.candidate, candidate.candidate); 41 assert_equals(json.usernameFragment, candidate.usernameFragment); 42 43 // Assert that no other attributes are present by checking the size. 44 assert_equals(Object.keys(json).length, 4); 45 46 }, 'RTCIceCandidate.toJSON serializes only specific attributes'); 47 48 </script>