Skip to content

Commit

Permalink
Move RTCRtpTransceiver tests related to OfferToReceive legacy options…
Browse files Browse the repository at this point in the history
… to webrtc/legacy (#13903)
  • Loading branch information
youennf authored Nov 4, 2018
1 parent cd17e3b commit 72fa5dd
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 129 deletions.
129 changes: 0 additions & 129 deletions webrtc/RTCRtpTransceiver.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,125 +305,6 @@
]);
};

const checkAddTransceiverWithStream = async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());

const audioStream = await navigator.mediaDevices.getUserMedia({audio: true});
const videoStream = await navigator.mediaDevices.getUserMedia({video: true});
t.add_cleanup(() => stopTracks(audioStream, videoStream));

const audio = audioStream.getAudioTracks()[0];
const video = videoStream.getVideoTracks()[0];

pc.addTransceiver(audio, {streams: [audioStream]});
pc.addTransceiver(video, {streams: [videoStream]});

hasProps(pc.getTransceivers(),
[
{
receiver: {track: {kind: "audio"}},
sender: {track: audio},
direction: "sendrecv",
mid: null,
currentDirection: null,
stopped: false
},
{
receiver: {track: {kind: "video"}},
sender: {track: video},
direction: "sendrecv",
mid: null,
currentDirection: null,
stopped: false
}
]);

const offer = await pc.createOffer();
assert_true(offer.sdp.includes("a=msid:" + audioStream.id + " " + audio.id),
"offer contains the expected audio msid");
assert_true(offer.sdp.includes("a=msid:" + videoStream.id + " " + video.id),
"offer contains the expected video msid");
};

const checkAddTransceiverWithOfferToReceive = async (t, kinds) => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());

const propsToSet = kinds.map(kind => {
if (kind == "audio") {
return "offerToReceiveAudio";
} else if (kind == "video") {
return "offerToReceiveVideo";
}
});

const options = {};

for (const prop of propsToSet) {
options[prop] = true;
}

let offer = await pc.createOffer(options);

const expected = [];

if (options.offerToReceiveAudio) {
expected.push(
{
receiver: {track: {kind: "audio"}},
sender: {track: null},
direction: "recvonly",
mid: null,
currentDirection: null,
stopped: false
});
}

if (options.offerToReceiveVideo) {
expected.push(
{
receiver: {track: {kind: "video"}},
sender: {track: null},
direction: "recvonly",
mid: null,
currentDirection: null,
stopped: false
});
}

hasProps(pc.getTransceivers(), expected);

// Test offerToReceive: false
for (const prop of propsToSet) {
options[prop] = false;
}

// Check that sendrecv goes to sendonly
for (const transceiver of pc.getTransceivers()) {
transceiver.direction = "sendrecv";
}

for (const transceiverCheck of expected) {
transceiverCheck.direction = "sendonly";
}

offer = await pc.createOffer(options);
hasProps(pc.getTransceivers(), expected);

// Check that recvonly goes to inactive
for (const transceiver of pc.getTransceivers()) {
transceiver.direction = "recvonly";
}

for (const transceiverCheck of expected) {
transceiverCheck.direction = "inactive";
}

offer = await pc.createOffer(options);
hasProps(pc.getTransceivers(), expected);
};

const checkAddTransceiverWithSetRemoteOfferSending = async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
Expand Down Expand Up @@ -2312,16 +2193,6 @@
checkAddTransceiverWithTrack,
checkAddTransceiverWithAddTrack,
checkAddTransceiverWithDirection,
checkAddTransceiverWithStream,
function checkAddTransceiverWithOfferToReceiveAudio(t) {
return checkAddTransceiverWithOfferToReceive(t, ["audio"]);
},
function checkAddTransceiverWithOfferToReceiveVideo(t) {
return checkAddTransceiverWithOfferToReceive(t, ["video"]);
},
function checkAddTransceiverWithOfferToReceiveBoth(t) {
return checkAddTransceiverWithOfferToReceive(t, ["audio", "video"]);
},
checkAddTransceiverWithSetRemoteOfferSending,
checkAddTransceiverWithSetRemoteOfferNoSend,
checkAddTransceiverBadKind,
Expand Down
169 changes: 169 additions & 0 deletions webrtc/legacy/RTCRtpTransceiver-with-OfferToReceive-options.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<!doctype html>
<meta charset=utf-8>
<title>RTCRtpTransceiver with OfferToReceive legacy options</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../RTCPeerConnection-helper.js"></script>
<script>
'use strict';

const stopTracks = (...streams) => {
streams.forEach(stream => stream.getTracks().forEach(track => track.stop()));
};

// comparable() - produces copy of object that is JSON comparable.
// o = original object (required)
// t = template of what to examine. Useful if o is non-enumerable (optional)

const comparable = (o, t = o) => {
if (typeof o != 'object' || !o) {
return o;
}
if (Array.isArray(t) && Array.isArray(o)) {
return o.map((n, i) => comparable(n, t[i]));
}
return Object.keys(t).sort()
.reduce((r, key) => (r[key] = comparable(o[key], t[key]), r), {});
};

const stripKeyQuotes = s => s.replace(/"(\w+)":/g, "$1:");

const hasProps = (observed, expected) => {
const observable = comparable(observed, expected);
assert_equals(stripKeyQuotes(JSON.stringify(observable)),
stripKeyQuotes(JSON.stringify(comparable(expected))));
};

const checkAddTransceiverWithStream = async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());

const audioStream = await navigator.mediaDevices.getUserMedia({audio: true});
const videoStream = await navigator.mediaDevices.getUserMedia({video: true});
t.add_cleanup(() => stopTracks(audioStream, videoStream));

const audio = audioStream.getAudioTracks()[0];
const video = videoStream.getVideoTracks()[0];

pc.addTransceiver(audio, {streams: [audioStream]});
pc.addTransceiver(video, {streams: [videoStream]});

hasProps(pc.getTransceivers(),
[
{
receiver: {track: {kind: "audio"}},
sender: {track: audio},
direction: "sendrecv",
mid: null,
currentDirection: null,
stopped: false
},
{
receiver: {track: {kind: "video"}},
sender: {track: video},
direction: "sendrecv",
mid: null,
currentDirection: null,
stopped: false
}
]);

const offer = await pc.createOffer();
assert_true(offer.sdp.includes("a=msid:" + audioStream.id + " " + audio.id),
"offer contains the expected audio msid");
assert_true(offer.sdp.includes("a=msid:" + videoStream.id + " " + video.id),
"offer contains the expected video msid");
};

const checkAddTransceiverWithOfferToReceive = async (t, kinds) => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());

const propsToSet = kinds.map(kind => {
if (kind == "audio") {
return "offerToReceiveAudio";
} else if (kind == "video") {
return "offerToReceiveVideo";
}
});

const options = {};

for (const prop of propsToSet) {
options[prop] = true;
}

let offer = await pc.createOffer(options);

const expected = [];

if (options.offerToReceiveAudio) {
expected.push(
{
receiver: {track: {kind: "audio"}},
sender: {track: null},
direction: "recvonly",
mid: null,
currentDirection: null,
stopped: false
});
}

if (options.offerToReceiveVideo) {
expected.push(
{
receiver: {track: {kind: "video"}},
sender: {track: null},
direction: "recvonly",
mid: null,
currentDirection: null,
stopped: false
});
}

hasProps(pc.getTransceivers(), expected);

// Test offerToReceive: false
for (const prop of propsToSet) {
options[prop] = false;
}

// Check that sendrecv goes to sendonly
for (const transceiver of pc.getTransceivers()) {
transceiver.direction = "sendrecv";
}

for (const transceiverCheck of expected) {
transceiverCheck.direction = "sendonly";
}

offer = await pc.createOffer(options);
hasProps(pc.getTransceivers(), expected);

// Check that recvonly goes to inactive
for (const transceiver of pc.getTransceivers()) {
transceiver.direction = "recvonly";
}

for (const transceiverCheck of expected) {
transceiverCheck.direction = "inactive";
}

offer = await pc.createOffer(options);
hasProps(pc.getTransceivers(), expected);
};

const tests = [
checkAddTransceiverWithStream,
function checkAddTransceiverWithOfferToReceiveAudio(t) {
return checkAddTransceiverWithOfferToReceive(t, ["audio"]);
},
function checkAddTransceiverWithOfferToReceiveVideo(t) {
return checkAddTransceiverWithOfferToReceive(t, ["video"]);
},
function checkAddTransceiverWithOfferToReceiveBoth(t) {
return checkAddTransceiverWithOfferToReceive(t, ["audio", "video"]);
}
].forEach(test => promise_test(test, test.name));

</script>

0 comments on commit 72fa5dd

Please sign in to comment.