Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Unified Diff: content/renderer/media/webrtc_local_audio_track_unittest.cc

Issue 218763007: Update MediaStreamTrack::Stop to latest draft. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments and added tests. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/webrtc_local_audio_track_unittest.cc
diff --git a/content/renderer/media/webrtc_local_audio_track_unittest.cc b/content/renderer/media/webrtc_local_audio_track_unittest.cc
index 8c387bbe3e6c35d9d98515bf8b8b6ec8d2db6467..06e16d89aa3fbae0406c549665b183aa4f0515af 100644
--- a/content/renderer/media/webrtc_local_audio_track_unittest.cc
+++ b/content/renderer/media/webrtc_local_audio_track_unittest.cc
@@ -4,6 +4,7 @@
#include "base/synchronization/waitable_event.h"
#include "base/test/test_timeouts.h"
+#include "content/renderer/media/media_stream_audio_source.h"
#include "content/renderer/media/mock_media_constraint_factory.h"
#include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
#include "content/renderer/media/webrtc_audio_capturer.h"
@@ -171,10 +172,17 @@ class WebRtcLocalAudioTrackTest : public ::testing::Test {
params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480);
blink::WebMediaConstraints constraints;
+ blink_source_.initialize("dummy", blink::WebMediaStreamSource::TypeAudio,
+ "dummy");
+ MediaStreamAudioSource* audio_source = new MediaStreamAudioSource();
+ blink_source_.setExtraData(audio_source);
+
StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE,
std::string(), std::string());
capturer_ = WebRtcAudioCapturer::CreateCapturer(-1, device,
- constraints, NULL);
+ constraints, NULL,
+ audio_source);
+ audio_source->SetAudioCapturer(capturer_);
capturer_source_ = new MockCapturerSource(capturer_.get());
EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), -1))
.WillOnce(Return());
@@ -182,6 +190,7 @@ class WebRtcLocalAudioTrackTest : public ::testing::Test {
}
media::AudioParameters params_;
+ blink::WebMediaStreamSource blink_source_;
scoped_refptr<MockCapturerSource> capturer_source_;
scoped_refptr<WebRtcAudioCapturer> capturer_;
};
@@ -328,15 +337,13 @@ TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) {
EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout()));
track_1->RemoveSink(sink_1.get());
- track_1->Stop();
+ track_1->StopTrack();
track_1.reset();
EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return());
track_2->RemoveSink(sink_2.get());
- track_2->Stop();
+ track_2->StopTrack();
track_2.reset();
-
- capturer_->Stop();
}
@@ -356,10 +363,39 @@ TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) {
// When the track goes away, it will automatically stop the
// |capturer_source_|.
EXPECT_CALL(*capturer_source_.get(), OnStop());
- capturer_->Stop();
track.reset();
}
+// Start two tracks and verify the capturer is correctly starting its source.
+// When the last track connected to the capturer is stopped, the source is
+// stopped.
+TEST_F(WebRtcLocalAudioTrackTest, StartTwoAudioTracks) {
+ EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
+ EXPECT_CALL(*capturer_source_.get(), OnStart());
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter1(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track1(
+ new WebRtcLocalAudioTrack(adapter1, capturer_, NULL));
+ static_cast<WebRtcLocalAudioSourceProvider*>(
+ track1->audio_source_provider())->SetSinkParamsForTesting(params_);
+ track1->Start();
+
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter2(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track2(
+ new WebRtcLocalAudioTrack(adapter2, capturer_, NULL));
+ static_cast<WebRtcLocalAudioSourceProvider*>(
+ track2->audio_source_provider())->SetSinkParamsForTesting(params_);
+ track2->Start();
+
+ track1->StopTrack();
+ // When the last track is stopped, it will automatically stop the
+ // |capturer_source_|.
+ EXPECT_CALL(*capturer_source_.get(), OnStop());
+ track2->StopTrack();
+}
+
+
// Start/Stop tracks and verify the capturer is correctly starting/stopping
// its source.
TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) {
@@ -448,7 +484,7 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE,
std::string(), std::string());
scoped_refptr<WebRtcAudioCapturer> new_capturer(
- WebRtcAudioCapturer::CreateCapturer(-1, device, constraints, NULL));
+ WebRtcAudioCapturer::CreateCapturer(-1, device, constraints, NULL, NULL));
scoped_refptr<MockCapturerSource> new_source(
new MockCapturerSource(new_capturer.get()));
EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), -1));
@@ -515,7 +551,7 @@ TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) {
params.channel_layout(),
params.frames_per_buffer()),
factory.CreateWebMediaConstraints(),
- NULL));
+ NULL, NULL));
scoped_refptr<MockCapturerSource> source(
new MockCapturerSource(capturer.get()));
EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1));

Powered by Google App Engine
This is Rietveld 408576698