idlharness.https.window.js (5418B)
1 // META: script=/resources/WebIDLParser.js 2 // META: script=/resources/idlharness.js 3 // META: script=./RTCPeerConnection-helper.js 4 // META: timeout=long 5 6 'use strict'; 7 8 // The following helper functions are called from RTCPeerConnection-helper.js: 9 // generateAnswer() 10 // getNoiseStream() 11 12 // Put the global IDL test objects under a parent object. 13 // This allows easier search for the test cases when 14 // viewing the web page 15 const idlTestObjects = {}; 16 17 // Helper function to create RTCTrackEvent object 18 function initTrackEvent() { 19 const pc = new RTCPeerConnection(); 20 const transceiver = pc.addTransceiver('audio'); 21 const { sender, receiver } = transceiver; 22 const { track } = receiver; 23 return new RTCTrackEvent('track', { 24 receiver, track, transceiver 25 }); 26 } 27 28 // List of async test driver functions 29 const asyncInitTasks = [ 30 asyncInitCertificate, 31 asyncInitTransports, 32 asyncInitMediaStreamTrack, 33 ]; 34 35 // Asynchronously generate an RTCCertificate 36 function asyncInitCertificate() { 37 return RTCPeerConnection.generateCertificate({ 38 name: 'RSASSA-PKCS1-v1_5', 39 modulusLength: 2048, 40 publicExponent: new Uint8Array([1, 0, 1]), 41 hash: 'SHA-256' 42 }).then(cert => { 43 idlTestObjects.certificate = cert; 44 }); 45 } 46 47 // Asynchronously generate instances of 48 // RTCSctpTransport, RTCDtlsTransport, 49 // and RTCIceTransport 50 async function asyncInitTransports() { 51 const pc1 = new RTCPeerConnection(); 52 const pc2 = new RTCPeerConnection(); 53 pc1.createDataChannel('test'); 54 exchangeIceCandidates(pc1, pc2); 55 await exchangeOfferAnswer(pc1, pc2); 56 const sctpTransport = pc1.sctp; 57 assert_true(sctpTransport instanceof RTCSctpTransport, 58 'Expect pc1.sctp to be instance of RTCSctpTransport'); 59 idlTestObjects.sctpTransport = sctpTransport; 60 61 const dtlsTransport = sctpTransport.transport; 62 assert_true(dtlsTransport instanceof RTCDtlsTransport, 63 'Expect dtlsTransport.transport to be instance of RTCDtlsTransport'); 64 idlTestObjects.dtlsTransport = dtlsTransport; 65 66 const iceTransport = dtlsTransport.iceTransport; 67 assert_true(iceTransport instanceof RTCIceTransport, 68 'Expect iceTransport.transport to be instance of RTCIceTransport'); 69 idlTestObjects.iceTransport = iceTransport; 70 await waitForIceStateChange(pc1, ['connected']); 71 72 assert_not_equals(iceTransport.state, "new", 'Expect iceTransport.state to be not new'); 73 assert_not_equals(iceTransport.state, "closed", 'Expect iceTransport.state to be not closed'); 74 75 const iceCandidatePair = iceTransport.getSelectedCandidatePair(); 76 77 assert_not_equals(iceCandidatePair, null, 'Expect iceTransport selected pair to be not null'); 78 assert_true(iceCandidatePair instanceof RTCIceCandidatePair, 79 'Expect iceTransport.getSelectedCandidatePair() to be instance of RTCIceTransport'); 80 idlTestObjects.iceCandidatePair = iceCandidatePair; 81 } 82 83 // Asynchoronously generate MediaStreamTrack from getUserMedia 84 function asyncInitMediaStreamTrack() { 85 return getNoiseStream({ audio: true }) 86 .then(mediaStream => { 87 idlTestObjects.mediaStreamTrack = mediaStream.getTracks()[0]; 88 }); 89 } 90 91 // Run all async test drivers, report and swallow any error 92 // thrown/rejected. Proper test for correct initialization 93 // of the objects are done in their respective test files. 94 function asyncInit() { 95 return Promise.all(asyncInitTasks.map( 96 task => { 97 const t = async_test(`Test driver for ${task.name}`); 98 let promise; 99 t.step(() => { 100 promise = task().then( 101 t.step_func_done(), 102 t.step_func(err => 103 assert_unreached(`Failed to run ${task.name}: ${err}`))); 104 }); 105 return promise; 106 })); 107 } 108 109 idl_test( 110 ['webrtc'], 111 ['webidl', 'mediacapture-streams', 'hr-time', 'dom', 'html', 'websockets'], 112 async idlArray => { 113 idlArray.add_objects({ 114 RTCPeerConnection: [`new RTCPeerConnection()`], 115 RTCSessionDescription: [`new RTCSessionDescription({ type: 'offer' })`], 116 RTCIceCandidate: [`new RTCIceCandidate({ sdpMid: 1 })`], 117 RTCDataChannel: [`new RTCPeerConnection().createDataChannel('')`], 118 RTCRtpTransceiver: [`new RTCPeerConnection().addTransceiver('audio')`], 119 RTCRtpSender: [`new RTCPeerConnection().addTransceiver('audio').sender`], 120 RTCRtpReceiver: [`new RTCPeerConnection().addTransceiver('audio').receiver`], 121 RTCPeerConnectionIceEvent: [`new RTCPeerConnectionIceEvent('ice')`], 122 RTCPeerConnectionIceErrorEvent: [ 123 `new RTCPeerConnectionIceErrorEvent('ice-error', { port: 0, errorCode: 701 });` 124 ], 125 RTCTrackEvent: [`initTrackEvent()`], 126 RTCErrorEvent: [`new RTCErrorEvent('error')`], 127 RTCDataChannelEvent: [ 128 `new RTCDataChannelEvent('channel', { 129 channel: new RTCPeerConnection().createDataChannel('') 130 })` 131 ], 132 // Async initialized objects below 133 RTCCertificate: ['idlTestObjects.certificate'], 134 RTCSctpTransport: ['idlTestObjects.sctpTransport'], 135 RTCDtlsTransport: ['idlTestObjects.dtlsTransport'], 136 RTCIceTransport: ['idlTestObjects.iceTransport'], 137 RTCIceCandidatePair: ['idlTestObjects.iceCandidatePair'], 138 MediaStreamTrack: ['idlTestObjects.mediaStreamTrack'], 139 }); 140 /* 141 TODO 142 RTCRtpContributingSource 143 RTCRtpSynchronizationSource 144 RTCDTMFSender 145 RTCDTMFToneChangeEvent 146 RTCIdentityProviderRegistrar 147 RTCIdentityAssertion 148 */ 149 150 await asyncInit(); 151 } 152 );