Skip to content

Commit

Permalink
Fix RTCRtpTransceiver direction tests (#13914)
Browse files Browse the repository at this point in the history
* Update RTCRtpTransceiver setDirection to direction setter

* Fix currentDirection in RTCRtpTransceiver-direction.html

* Add negative test for setDirection
  • Loading branch information
markandrus authored and youennf committed Nov 7, 2018
1 parent 615bb57 commit d37a815
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion webrtc/RTCDTMFSender-ontonechange.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
// tonechange event, to make sure that tonechange is triggered
// then stopped
if(tone === 'A') {
transceiver.setDirection('recvonly');
transceiver.direction = 'recvonly';

pc.createOffer()
.then(offer =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
<!doctype html>
<meta charset=utf-8>
<title>RTCRtpTransceiver.prototype.setDirection</title>
<title>RTCRtpTransceiver.prototype.direction</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script>
'use strict';

// Test is based on the following editor draft:
// https://rawgit.com/w3c/webrtc-pc/cc8d80f455b86c8041d63bceb8b457f45c72aa89/webrtc.html
// https://rawgit.com/w3c/webrtc-pc/8495678808d126d8bc764bf944996f32981fa6fd/webrtc.html

// The following helper functions are called from RTCPeerConnection-helper.js:
// generateAnswer

/*
5.4. RTCRtpTransceiver Interface
interface RTCRtpTransceiver {
readonly attribute RTCRtpTransceiverDirection direction;
attribute RTCRtpTransceiverDirection direction;
readonly attribute RTCRtpTransceiverDirection? currentDirection;
void setDirection(RTCRtpTransceiverDirection direction);
...
};
*/

/*
5.4. setDirection
4. Set transceiver's [[Direction]] slot to newDirection.
5.4. direction
7. Set transceiver's [[Direction]] slot to newDirection.
*/
test(t => {
const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('audio');
assert_equals(transceiver.direction, 'sendrecv');
assert_equals(transceiver.currentDirection, null);

transceiver.setDirection('recvonly');
transceiver.direction = 'recvonly';
assert_equals(transceiver.direction, 'recvonly');
assert_equals(transceiver.currentDirection, null,
'Expect transceiver.currentDirection to not change');

}, 'setDirection should change transceiver.direction');
}, 'setting direction should change transceiver.direction');

/*
5.4. setDirection
5.4. direction
3. If newDirection is equal to transceiver's [[Direction]] slot, abort
these steps.
*/
test(t => {
const pc = new RTCPeerConnection();
const transceiver = pc.addTransceiver('audio', { direction: 'sendonly' });
assert_equals(transceiver.direction, 'sendonly');
transceiver.setDirection('sendonly');
transceiver.direction = 'sendonly';
assert_equals(transceiver.direction, 'sendonly');

}, 'setDirection with same direction should have no effect');
}, 'setting direction with same direction should have no effect');

promise_test(t => {
const pc = new RTCPeerConnection();
Expand All @@ -67,22 +66,22 @@
.then(() => generateAnswer(offer)))
.then(answer => pc.setRemoteDescription(answer))
.then(() => {
assert_equals(transceiver.currentDirection, 'recvonly');
transceiver.setDirection('sendrecv');
assert_equals(transceiver.currentDirection, 'inactive');
transceiver.direction = 'sendrecv';
assert_equals(transceiver.direction, 'sendrecv');
assert_equals(transceiver.currentDirection, 'recvonly');
assert_equals(transceiver.currentDirection, 'inactive');
});
}, 'setDirection should change transceiver.direction independent of transceiver.currentDirection');
}, 'setting direction should change transceiver.direction independent of transceiver.currentDirection');

/*
TODO
Calls to setDirection() do not take effect immediately. Instead, future calls
An update of directionality does not take effect immediately. Instead, future calls
to createOffer and createAnswer mark the corresponding media description as
sendrecv, sendonly, recvonly or inactive as defined in [JSEP] (section 5.2.2.
and section 5.3.2.).
Tested in RTCPeerConnection-onnegotiationneeded.html
5.4. setDirection
5.4. direction
6. Update the negotiation-needed flag for connection.
Coverage Report
Expand Down
4 changes: 2 additions & 2 deletions webrtc/RTCRtpTransceiver.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@
"InvalidStateError", "replaceTrack on stopped transceiver");

checkThrows(() => transceiver.direction = "sendrecv",
"InvalidStateError", "setDirection on stopped transceiver");
"InvalidStateError", "set direction on stopped transceiver");

checkThrows(() => transceiver.sender.dtmf.insertDTMF("111"),
"InvalidStateError", "insertDTMF on stopped transceiver");
Expand Down Expand Up @@ -1775,7 +1775,7 @@
await pc2.setRemoteDescription({type: "rollback"});

// Transceiver should be _gone_, again. replaceTrack doesn't prevent this,
// nor does setDirection.
// nor does setting direction.
hasProps(pc2.getTransceivers(), []);

// Setting the same offer for a _third_ time should do the same thing
Expand Down
8 changes: 8 additions & 0 deletions webrtc/historical.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
}, "RTCPeerConnection member " + name + " should not exist");
});

[
"setDirection",
].forEach(function(name) {
test(function() {
assert_false(name in RTCRtpTransceiver.prototype);
}, "RTCRtpTransceiver member " + name + " should not exist");
});

[
"DataChannel",
"mozRTCIceCandidate",
Expand Down

0 comments on commit d37a815

Please sign in to comment.