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, ...@@ -59,7 +59,7 @@ class WebRtcBrowserTest : public WebRtcContentBrowserTest,
#endif #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. // the page, kick off some javascript and wait for the title to change to OK.
void MakeTypicalPeerConnectionCall(const std::string& javascript) { void MakeTypicalPeerConnectionCall(const std::string& javascript) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
...@@ -71,6 +71,27 @@ class WebRtcBrowserTest : public WebRtcContentBrowserTest, ...@@ -71,6 +71,27 @@ class WebRtcBrowserTest : public WebRtcContentBrowserTest,
ExecuteJavascriptAndWaitForOk(javascript); 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() { void DisableOpusIfOnAndroid() {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Always force iSAC 16K on Android for now (Opus is broken). // Always force iSAC 16K on Android for now (Opus is broken).
...@@ -327,39 +348,22 @@ IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, AddTwoMediaStreamsToOnePC) { ...@@ -327,39 +348,22 @@ IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, AddTwoMediaStreamsToOnePC) {
} }
IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
EstablishAudioVideoCallAndMeasureOutputLevel) { EstablishAudioVideoCallAndEnsureAudioIsPlaying) {
if (!media::AudioManager::Get()->HasAudioOutputDevices()) { MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
// Bots with no output devices will force the audio code into a different "callAndEnsureAudioIsPlaying(%s, {audio:true, video:true});",
// path where it doesn't manage to set either the low or high latency path. kUseLenientAudioChecking));
// 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(base::StringPrintf( IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
"callAndEnsureAudioIsPlaying(%s);", kUseLenientAudioChecking)); EstablishAudioOnlyCallAndEnsureAudioIsPlaying) {
MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
"callAndEnsureAudioIsPlaying(%s, {audio:true});",
kUseLenientAudioChecking));
} }
IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
EstablishAudioVideoCallAndVerifyMutingWorks) { EstablishAudioVideoCallAndVerifyMutingWorks) {
if (!media::AudioManager::Get()->HasAudioOutputDevices()) { MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
// 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(
"callAndEnsureAudioTrackMutingWorks(%s);", kUseLenientAudioChecking)); "callAndEnsureAudioTrackMutingWorks(%s);", kUseLenientAudioChecking));
} }
...@@ -373,18 +377,7 @@ IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, ...@@ -373,18 +377,7 @@ IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
#endif #endif
IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest,
MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks) { MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks) {
if (!media::AudioManager::Get()->HasAudioOutputDevices()) { MakeAudioDetectingPeerConnectionCall(base::StringPrintf(
// 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(
"callAndEnsureAudioTrackUnmutingWorks(%s);", kUseLenientAudioChecking)); "callAndEnsureAudioTrackUnmutingWorks(%s);", kUseLenientAudioChecking));
} }
......
...@@ -301,9 +301,9 @@ ...@@ -301,9 +301,9 @@
remoteAudioTrack.enabled = enabled; remoteAudioTrack.enabled = enabled;
} }
function callAndEnsureAudioIsPlaying(beLenient) { function callAndEnsureAudioIsPlaying(beLenient, constraints) {
createConnections(null); createConnections(null);
navigator.webkitGetUserMedia({audio: true, video: true}, navigator.webkitGetUserMedia(constraints,
addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); addStreamToBothConnectionsAndNegotiate, printGetUserMediaError);
// Wait until we have gathered samples and can conclude if audio is playing. // Wait until we have gathered samples and can conclude if audio is playing.
...@@ -314,16 +314,13 @@ ...@@ -314,16 +314,13 @@
verifyAudioIsPlaying(samples, beLenient); verifyAudioIsPlaying(samples, beLenient);
eventOccured(); eventOccured();
}); });
// (Also, ensure video muting doesn't affect audio).
enableRemoteVideo(gSecondConnection, false);
}; };
detectVideoPlaying('remote-view-2', onCallEstablished); waitForConnectionToStabilize(gFirstConnection, onCallEstablished);
} }
function callAndEnsureAudioTrackMutingWorks(beLenient) { function callAndEnsureAudioTrackMutingWorks(beLenient) {
callAndEnsureAudioIsPlaying(beLenient); callAndEnsureAudioIsPlaying(beLenient, {audio: true, video: true});
setAllEventsOccuredHandler(function() { setAllEventsOccuredHandler(function() {
// Call is up, now mute the track and check everything goes silent (give // 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). // it a small delay though, we don't expect it to happen instantly).
...@@ -339,10 +336,12 @@ ...@@ -339,10 +336,12 @@
} }
function callAndEnsureAudioTrackUnmutingWorks(beLenient) { function callAndEnsureAudioTrackUnmutingWorks(beLenient) {
callAndEnsureAudioIsPlaying(beLenient); callAndEnsureAudioIsPlaying(beLenient, {audio: true, video: true});
setAllEventsOccuredHandler(function() { setAllEventsOccuredHandler(function() {
// Mute, wait a while, unmute, verify audio gets back up. // Mute, wait a while, unmute, verify audio gets back up.
// (Also, ensure video muting doesn't affect audio).
enableRemoteAudio(gSecondConnection, false); enableRemoteAudio(gSecondConnection, false);
enableRemoteVideo(gSecondConnection, false);
setTimeout(function() { setTimeout(function() {
enableRemoteAudio(gSecondConnection, true); enableRemoteAudio(gSecondConnection, true);
......
...@@ -15,7 +15,16 @@ function gatherAudioLevelSamples(peerConnection, numSamples, frequency, ...@@ -15,7 +15,16 @@ function gatherAudioLevelSamples(peerConnection, numSamples, frequency,
var audioLevelSamples = [] var audioLevelSamples = []
var gatherSamples = setInterval(function() { var gatherSamples = setInterval(function() {
peerConnection.getStats(function(response) { 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) { if (audioLevelSamples.length == numSamples) {
console.log('Gathered all samples.'); console.log('Gathered all samples.');
clearInterval(gatherSamples); clearInterval(gatherSamples);
...@@ -83,8 +92,5 @@ function getAudioLevelFromStats_(response) { ...@@ -83,8 +92,5 @@ function getAudioLevelFromStats_(response) {
audioOutputLevels.push(report.stat('audioOutputLevel')); audioOutputLevels.push(report.stat('audioOutputLevel'));
} }
} }
// Should only be one audio level reported, otherwise we get confused. return audioOutputLevels;
assertEquals(1, audioOutputLevels.length);
return audioOutputLevels[0];
} }
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