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

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

Issue 199063002: Added unittest to WebRtcAudioRenderer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: use AudioDeviceFactory 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
« no previous file with comments | « content/content_tests.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/webrtc_audio_renderer_unittest.cc
diff --git a/content/renderer/media/webrtc_audio_renderer_unittest.cc b/content/renderer/media/webrtc_audio_renderer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c49b9fc756e91dd79d1e0b316f9ca17fa2d2b8e5
--- /dev/null
+++ b/content/renderer/media/webrtc_audio_renderer_unittest.cc
@@ -0,0 +1,152 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <vector>
+
+#include "content/renderer/media/audio_device_factory.h"
+#include "content/renderer/media/audio_message_filter.h"
+#include "content/renderer/media/media_stream_audio_renderer.h"
+#include "content/renderer/media/mock_media_stream_dependency_factory.h"
+#include "content/renderer/media/webrtc_audio_device_impl.h"
+#include "content/renderer/media/webrtc_audio_renderer.h"
+#include "media/audio/audio_output_device.h"
+#include "media/audio/audio_output_ipc.h"
+#include "media/base/audio_bus.h"
+#include "media/base/mock_audio_renderer_sink.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
+
+namespace content {
+
+namespace {
+
+class MockAudioOutputIPC : public media::AudioOutputIPC {
+ public:
+ MockAudioOutputIPC() {}
+ virtual ~MockAudioOutputIPC() {}
+
+ MOCK_METHOD3(CreateStream, void(media::AudioOutputIPCDelegate* delegate,
+ const media::AudioParameters& params,
+ int session_id));
+ MOCK_METHOD0(PlayStream, void());
+ MOCK_METHOD0(PauseStream, void());
+ MOCK_METHOD0(CloseStream, void());
+ MOCK_METHOD1(SetVolume, void(double volume));
+};
+
+class FakeAudioOutputDevice : public media::AudioOutputDevice {
+ public:
+ FakeAudioOutputDevice(
+ MockAudioOutputIPC* ipc,
tommi (sloooow) - chröme 2014/03/13 17:33:44 can we make this scoped_ptr<media::AudioOutputIPC>
no longer working on chromium 2014/03/14 09:42:00 Done.
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
+ : AudioOutputDevice(scoped_ptr<media::AudioOutputIPC>(ipc),
+ io_task_runner) {}
+ virtual ~FakeAudioOutputDevice() {}
+ MOCK_METHOD0(Start, void());
+ MOCK_METHOD0(Stop, void());
+ MOCK_METHOD0(Pause, void());
+ MOCK_METHOD0(Play, void());
+ MOCK_METHOD1(SetVolume, bool(double volume));
+};
+
+class FakeAudioDeviceFactory : public AudioDeviceFactory {
+ public:
+ explicit FakeAudioDeviceFactory(media::AudioOutputDevice* output_device)
+ : output_device_(output_device) {}
+ virtual ~FakeAudioDeviceFactory() {}
+
+ protected:
+ virtual media::AudioOutputDevice* CreateOutputDevice(
tommi (sloooow) - chröme 2014/03/13 17:33:44 It would be good to also make this class a mock cl
no longer working on chromium 2014/03/14 09:42:00 Done.
+ int render_view_id) OVERRIDE {
+ return output_device_;
+ }
+ virtual media::AudioInputDevice* CreateInputDevice(
+ int render_view_id) OVERRIDE {
+ NOTREACHED();
+ return NULL;
+ }
+ private:
+ scoped_refptr<media::AudioOutputDevice> output_device_;
tommi (sloooow) - chröme 2014/03/13 17:33:44 then we also don't need member variables here
no longer working on chromium 2014/03/14 09:42:00 Done.
+};
+
+class MockAudioRendererSource : public WebRtcAudioRendererSource {
+ public:
+ MockAudioRendererSource() {}
+ virtual ~MockAudioRendererSource() {}
+ MOCK_METHOD3(RenderData, void(media::AudioBus* audio_bus,
+ int sample_rate,
+ int audio_delay_milliseconds));
+ MOCK_METHOD1(RemoveAudioRenderer, void(WebRtcAudioRenderer* renderer));
+};
+
+} // namespace
+
+class WebRtcAudioRendererTest : public testing::Test {
+ protected:
+ WebRtcAudioRendererTest()
+ : message_loop_(new base::MessageLoopForIO),
+ mock_ipc_(new MockAudioOutputIPC()),
+ mock_output_device_(new FakeAudioOutputDevice(
+ mock_ipc_, message_loop_->message_loop_proxy())),
+ factory_(new FakeAudioDeviceFactory(mock_output_device_)),
+ source_(new MockAudioRendererSource()),
+ stream_(new talk_base::RefCountedObject<MockMediaStream>("label")),
+ renderer_(new WebRtcAudioRenderer(stream_, 1, 1, 1, 44100, 441)) {
+ EXPECT_CALL(*mock_output_device_, Start());
tommi (sloooow) - chröme 2014/03/13 17:33:44 would it make sense to extract this part into a se
no longer working on chromium 2014/03/14 09:42:00 Done with moving renderer_proxy_->Start(); to the
+ EXPECT_TRUE(renderer_->Initialize(source_.get()));
+ renderer_proxy_ = renderer_->CreateSharedAudioRendererProxy(stream_);
+ renderer_proxy_->Start();
tommi (sloooow) - chröme 2014/03/13 17:33:44 Maybe it's enough to just remove this line and put
no longer working on chromium 2014/03/14 09:42:00 Done.
+ }
+
+ scoped_ptr<base::MessageLoopForIO> message_loop_;
tommi (sloooow) - chröme 2014/03/13 17:33:44 add a comment here that explains that this variabl
no longer working on chromium 2014/03/14 09:42:00 Done with a comment to explain they are used to co
+ MockAudioOutputIPC* mock_ipc_; // Owned by AudioOuputDevice.
+ scoped_refptr<FakeAudioOutputDevice> mock_output_device_;
+ scoped_ptr<FakeAudioDeviceFactory> factory_;
+ scoped_ptr<MockAudioRendererSource> source_;
+ scoped_refptr<webrtc::MediaStreamInterface> stream_;
+ scoped_refptr<WebRtcAudioRenderer> renderer_;
+ scoped_refptr<MediaStreamAudioRenderer> renderer_proxy_;
+};
+
+// Verify that the renderer will be stopped if the only proxy is stopped.
+TEST_F(WebRtcAudioRendererTest, StopRenderer) {
+ // |renderer_| has only one proxy, stopping the proxy should stop the sink of
+ // |renderer_|.
+ EXPECT_CALL(*mock_output_device_, Stop());
+ EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get()));
+ renderer_proxy_->Stop();
+}
+
+// Verify that the renderer will not be stopped unless the last proxy is
+// stopped.
+TEST_F(WebRtcAudioRendererTest, MultipleRenderers) {
+ // Create a vector of renderer proxies from the |renderer_|.
+ std::vector<scoped_refptr<MediaStreamAudioRenderer> > renderer_proxies_;
+ static const int kNumberOfRendererProxy = 5;
+ for (int i = 0; i < kNumberOfRendererProxy; ++i) {
+ scoped_refptr<MediaStreamAudioRenderer> renderer_proxy(
+ renderer_->CreateSharedAudioRendererProxy(stream_));
+ renderer_proxy->Start();
+ renderer_proxies_.push_back(renderer_proxy);
+ }
+
+ // Stop the |renderer_proxy_| should not stop the sink since it is used by
+ // other proxies.
+ EXPECT_CALL(*mock_output_device_, Stop()).Times(0);
+ renderer_proxy_->Stop();
+
+ for (int i = 0; i < kNumberOfRendererProxy; ++i) {
+ if (i != kNumberOfRendererProxy -1) {
+ EXPECT_CALL(*mock_output_device_, Stop()).Times(0);
+ } else {
+ // When the last proxy is stopped, the sink will stop.
+ EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get()));
+ EXPECT_CALL(*mock_output_device_, Stop());
+ }
+ renderer_proxies_[i]->Stop();
+ }
+}
+
+} // namespace content
« no previous file with comments | « content/content_tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698