Commit 10af0395 authored by phoglund@chromium.org's avatar phoglund@chromium.org

Wrote a test which exercises audio-only WebRTC calls.

Depends on https://codereview.chromium.org/260073013/ since it requires audio beeps generated even when the fake video device hasn't been acquired.

BUG=None

Review URL: https://codereview.chromium.org/252703003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275790 0039d316-1c4b-4281-b951-d872f2087c98
parent 98c3ca96
......@@ -59,7 +59,7 @@ class WebRtcBrowserTest : public WebRtcContentBrowserTest,
#endif
}
// Convenience function since most peerconnection-call.html tests just load
// Convenience method since most peerconnection-call.html tests just load
// the page, kick off some javascript and wait for the title to change to OK.
void MakeTypicalPeerConnectionCall(const std::string& javascript) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
......@@ -71,6 +71,27 @@ class WebRtcBrowserTest : public WebRtcContentBrowserTest,
ExecuteJavascriptAndWaitForOk(javascript);
}
// Convenience method for making calls that detect if audio os playing (which
// has some special prerequisites, such that there needs to be an audio output
// device on the executing machine).
void MakeAudioDetectingPeerConnectionCall(const std::string& javascript) {
if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
// Bots with no output devices will force the audio code into a state
// where it doesn't manage to set either the low or high latency path.
// This test will compute useless values in that case, so skip running on
// such bots (see crbug.com/326338).
LOG(INFO) << "Missing output devices: skipping test...";
return;
}
ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeDeviceForMediaStream))
<< "Must run with fake devices since the test will explicitly look "
<< "for the fake device signal.";
MakeTypicalPeerConnectionCall(javascript);
}
void DisableOpusIfOnAndroid() {
#if defined(OS_ANDROID)
// Always force iSAC 16K on Android for now (Opus is broken).
......@@ -327,39 +348,22 @@ IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, AddTwoMediaStreamsToOnePC) {
}
IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
EstablishAudioVideoCallAndMeasureOutputLevel) {
if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
// Bots with no output devices will force the audio code into a different
// path where it doesn't manage to set either the low or high latency path.
// This test will compute useless values in that case, so skip running on
// such bots (see crbug.com/326338).
LOG(INFO) << "Missing output devices: skipping test...";
return;
}
ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeDeviceForMediaStream))
<< "Must run with fake devices since the test will explicitly look "
<< "for the fake device signal.";
EstablishAudioVideoCallAndEnsureAudioIsPlaying) {
MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
"callAndEnsureAudioIsPlaying(%s, {audio:true, video:true});",
kUseLenientAudioChecking));
}
MakeTypicalPeerConnectionCall(base::StringPrintf(
"callAndEnsureAudioIsPlaying(%s);", kUseLenientAudioChecking));
IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
EstablishAudioOnlyCallAndEnsureAudioIsPlaying) {
MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
"callAndEnsureAudioIsPlaying(%s, {audio:true});",
kUseLenientAudioChecking));
}
IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
EstablishAudioVideoCallAndVerifyMutingWorks) {
if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
// See comment on EstablishAudioVideoCallAndMeasureOutputLevel.
LOG(INFO) << "Missing output devices: skipping test...";
return;
}
ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeDeviceForMediaStream))
<< "Must run with fake devices since the test will explicitly look "
<< "for the fake device signal.";
MakeTypicalPeerConnectionCall(base::StringPrintf(
MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
"callAndEnsureAudioTrackMutingWorks(%s);", kUseLenientAudioChecking));
}
......@@ -373,18 +377,7 @@ IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
#endif
IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks) {
if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
// See comment on EstablishAudioVideoCallAndMeasureOutputLevel.
LOG(INFO) << "Missing output devices: skipping test...";
return;
}
ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeDeviceForMediaStream))
<< "Must run with fake devices since the test will explicitly look "
<< "for the fake device signal.";
MakeTypicalPeerConnectionCall(base::StringPrintf(
MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
"callAndEnsureAudioTrackUnmutingWorks(%s);", kUseLenientAudioChecking));
}
......
......@@ -301,9 +301,9 @@
remoteAudioTrack.enabled = enabled;
}
function callAndEnsureAudioIsPlaying(beLenient) {
function callAndEnsureAudioIsPlaying(beLenient, constraints) {
createConnections(null);
navigator.webkitGetUserMedia({audio: true, video: true},
navigator.webkitGetUserMedia(constraints,
addStreamToBothConnectionsAndNegotiate, printGetUserMediaError);
// Wait until we have gathered samples and can conclude if audio is playing.
......@@ -314,16 +314,13 @@
verifyAudioIsPlaying(samples, beLenient);
eventOccured();
});
// (Also, ensure video muting doesn't affect audio).
enableRemoteVideo(gSecondConnection, false);
};
detectVideoPlaying('remote-view-2', onCallEstablished);
waitForConnectionToStabilize(gFirstConnection, onCallEstablished);
}
function callAndEnsureAudioTrackMutingWorks(beLenient) {
callAndEnsureAudioIsPlaying(beLenient);
callAndEnsureAudioIsPlaying(beLenient, {audio: true, video: true});
setAllEventsOccuredHandler(function() {
// Call is up, now mute the track and check everything goes silent (give
// it a small delay though, we don't expect it to happen instantly).
......@@ -339,10 +336,12 @@
}
function callAndEnsureAudioTrackUnmutingWorks(beLenient) {
callAndEnsureAudioIsPlaying(beLenient);
callAndEnsureAudioIsPlaying(beLenient, {audio: true, video: true});
setAllEventsOccuredHandler(function() {
// Mute, wait a while, unmute, verify audio gets back up.
// (Also, ensure video muting doesn't affect audio).
enableRemoteAudio(gSecondConnection, false);
enableRemoteVideo(gSecondConnection, false);
setTimeout(function() {
enableRemoteAudio(gSecondConnection, true);
......
......@@ -15,7 +15,16 @@ function gatherAudioLevelSamples(peerConnection, numSamples, frequency,
var audioLevelSamples = []
var gatherSamples = setInterval(function() {
peerConnection.getStats(function(response) {
audioLevelSamples.push(getAudioLevelFromStats_(response));
audioOutputLevels = getAudioLevelFromStats_(response);
if (audioOutputLevels.length == 0) {
// The call probably isn't up yet.
return;
}
// If more than one audio level is reported we get confused.
assertEquals(1, audioOutputLevels.length);
audioLevelSamples.push(audioOutputLevels[0]);
if (audioLevelSamples.length == numSamples) {
console.log('Gathered all samples.');
clearInterval(gatherSamples);
......@@ -83,8 +92,5 @@ function getAudioLevelFromStats_(response) {
audioOutputLevels.push(report.stat('audioOutputLevel'));
}
}
// Should only be one audio level reported, otherwise we get confused.
assertEquals(1, audioOutputLevels.length);
return audioOutputLevels[0];
return audioOutputLevels;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment