| Soares Chen | c049601 | 2017-07-07 15:37:09 | [diff] [blame] | 1 | <!doctype html> | 
|  | 2 | <meta charset=utf-8> | 
|  | 3 | <title>RTCRtpTransceiver.prototype.setDirection</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 is based on the following editor draft: | 
|  | 11 | // https://rawgit.com/w3c/webrtc-pc/cc8d80f455b86c8041d63bceb8b457f45c72aa89/webrtc.html | 
|  | 12 |  | 
|  | 13 | // The following helper functions are called from RTCPeerConnection-helper.js: | 
|  | 14 | // generateAnswer | 
|  | 15 |  | 
|  | 16 | /* | 
|  | 17 | 5.4. RTCRtpTransceiver Interface | 
|  | 18 | interface RTCRtpTransceiver { | 
|  | 19 | readonly attribute RTCRtpTransceiverDirection direction; | 
|  | 20 | readonly attribute RTCRtpTransceiverDirection? currentDirection; | 
|  | 21 | void setDirection(RTCRtpTransceiverDirection direction); | 
|  | 22 | ... | 
|  | 23 | }; | 
|  | 24 | */ | 
|  | 25 |  | 
|  | 26 | /* | 
|  | 27 | 5.4. setDirection | 
|  | 28 | 4. Set transceiver's [[Direction]] slot to newDirection. | 
|  | 29 | */ | 
|  | 30 | test(t => { | 
|  | 31 | const pc = new RTCPeerConnection(); | 
|  | 32 | const transceiver = pc.addTransceiver('audio'); | 
|  | 33 | assert_equals(transceiver.direction, 'sendrecv'); | 
|  | 34 | assert_equals(transceiver.currentDirection, null); | 
|  | 35 |  | 
|  | 36 | transceiver.setDirection('recvonly'); | 
|  | 37 | assert_equals(transceiver.direction, 'recvonly'); | 
|  | 38 | assert_equals(transceiver.currentDirection, null, | 
|  | 39 | 'Expect transceiver.currentDirection to not change'); | 
|  | 40 |  | 
|  | 41 | }, 'setDirection should change transceiver.direction'); | 
|  | 42 |  | 
|  | 43 | /* | 
|  | 44 | 5.4. setDirection | 
|  | 45 | 3. If newDirection is equal to transceiver's [[Direction]] slot, abort | 
|  | 46 | these steps. | 
|  | 47 | */ | 
|  | 48 | test(t => { | 
|  | 49 | const pc = new RTCPeerConnection(); | 
|  | 50 | const transceiver = pc.addTransceiver('audio', { direction: 'sendonly' }); | 
|  | 51 | assert_equals(transceiver.direction, 'sendonly'); | 
|  | 52 | transceiver.setDirection('sendonly'); | 
|  | 53 | assert_equals(transceiver.direction, 'sendonly'); | 
|  | 54 |  | 
|  | 55 | }, 'setDirection with same direction should have no effect'); | 
|  | 56 |  | 
|  | 57 | promise_test(t => { | 
|  | 58 | const pc = new RTCPeerConnection(); | 
|  | 59 | const transceiver = pc.addTransceiver('audio', { direction: 'recvonly' }); | 
|  | 60 | assert_equals(transceiver.direction, 'recvonly'); | 
|  | 61 | assert_equals(transceiver.currentDirection, null); | 
|  | 62 |  | 
|  | 63 | return pc.createOffer() | 
|  | 64 | .then(offer => | 
|  | 65 | pc.setLocalDescription(offer) | 
|  | 66 | .then(() => generateAnswer(offer))) | 
|  | 67 | .then(answer => pc.setRemoteDescription(answer)) | 
|  | 68 | .then(() => { | 
|  | 69 | assert_equals(transceiver.currentDirection, 'recvonly'); | 
|  | 70 | transceiver.setDirection('sendrecv'); | 
|  | 71 | assert_equals(transceiver.direction, 'sendrecv'); | 
|  | 72 | assert_equals(transceiver.currentDirection, 'recvonly'); | 
|  | 73 | }); | 
|  | 74 | }, 'setDirection should change transceiver.direction independent of transceiver.currentDirection'); | 
|  | 75 |  | 
|  | 76 | /* | 
|  | 77 | TODO | 
|  | 78 | Calls to setDirection() do not take effect immediately. Instead, future calls | 
|  | 79 | to createOffer and createAnswer mark the corresponding media description as | 
|  | 80 | sendrecv, sendonly, recvonly or inactive as defined in [JSEP] (section 5.2.2. | 
|  | 81 | and section 5.3.2.). | 
|  | 82 |  | 
|  | 83 | Tested in RTCPeerConnection-onnegotiationneeded.html | 
|  | 84 | 5.4. setDirection | 
|  | 85 | 6. Update the negotiation-needed flag for connection. | 
|  | 86 |  | 
|  | 87 | Coverage Report | 
|  | 88 | Tested 6 | 
|  | 89 | Not Tested 1 | 
|  | 90 | Untestable 0 | 
|  | 91 | Total 7 | 
|  | 92 | */ | 
|  | 93 |  | 
|  | 94 | </script> |