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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « content/content_tests.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <vector>
6
7 #include "content/renderer/media/audio_device_factory.h"
8 #include "content/renderer/media/audio_message_filter.h"
9 #include "content/renderer/media/media_stream_audio_renderer.h"
10 #include "content/renderer/media/mock_media_stream_dependency_factory.h"
11 #include "content/renderer/media/webrtc_audio_device_impl.h"
12 #include "content/renderer/media/webrtc_audio_renderer.h"
13 #include "media/audio/audio_output_device.h"
14 #include "media/audio/audio_output_ipc.h"
15 #include "media/base/audio_bus.h"
16 #include "media/base/mock_audio_renderer_sink.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
20
21 namespace content {
22
23 namespace {
24
25 class MockAudioOutputIPC : public media::AudioOutputIPC {
26 public:
27 MockAudioOutputIPC() {}
28 virtual ~MockAudioOutputIPC() {}
29
30 MOCK_METHOD3(CreateStream, void(media::AudioOutputIPCDelegate* delegate,
31 const media::AudioParameters& params,
32 int session_id));
33 MOCK_METHOD0(PlayStream, void());
34 MOCK_METHOD0(PauseStream, void());
35 MOCK_METHOD0(CloseStream, void());
36 MOCK_METHOD1(SetVolume, void(double volume));
37 };
38
39 class FakeAudioOutputDevice : public media::AudioOutputDevice {
40 public:
41 FakeAudioOutputDevice(
42 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.
43 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
44 : AudioOutputDevice(scoped_ptr<media::AudioOutputIPC>(ipc),
45 io_task_runner) {}
46 virtual ~FakeAudioOutputDevice() {}
47 MOCK_METHOD0(Start, void());
48 MOCK_METHOD0(Stop, void());
49 MOCK_METHOD0(Pause, void());
50 MOCK_METHOD0(Play, void());
51 MOCK_METHOD1(SetVolume, bool(double volume));
52 };
53
54 class FakeAudioDeviceFactory : public AudioDeviceFactory {
55 public:
56 explicit FakeAudioDeviceFactory(media::AudioOutputDevice* output_device)
57 : output_device_(output_device) {}
58 virtual ~FakeAudioDeviceFactory() {}
59
60 protected:
61 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.
62 int render_view_id) OVERRIDE {
63 return output_device_;
64 }
65 virtual media::AudioInputDevice* CreateInputDevice(
66 int render_view_id) OVERRIDE {
67 NOTREACHED();
68 return NULL;
69 }
70 private:
71 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.
72 };
73
74 class MockAudioRendererSource : public WebRtcAudioRendererSource {
75 public:
76 MockAudioRendererSource() {}
77 virtual ~MockAudioRendererSource() {}
78 MOCK_METHOD3(RenderData, void(media::AudioBus* audio_bus,
79 int sample_rate,
80 int audio_delay_milliseconds));
81 MOCK_METHOD1(RemoveAudioRenderer, void(WebRtcAudioRenderer* renderer));
82 };
83
84 } // namespace
85
86 class WebRtcAudioRendererTest : public testing::Test {
87 protected:
88 WebRtcAudioRendererTest()
89 : message_loop_(new base::MessageLoopForIO),
90 mock_ipc_(new MockAudioOutputIPC()),
91 mock_output_device_(new FakeAudioOutputDevice(
92 mock_ipc_, message_loop_->message_loop_proxy())),
93 factory_(new FakeAudioDeviceFactory(mock_output_device_)),
94 source_(new MockAudioRendererSource()),
95 stream_(new talk_base::RefCountedObject<MockMediaStream>("label")),
96 renderer_(new WebRtcAudioRenderer(stream_, 1, 1, 1, 44100, 441)) {
97 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
98 EXPECT_TRUE(renderer_->Initialize(source_.get()));
99 renderer_proxy_ = renderer_->CreateSharedAudioRendererProxy(stream_);
100 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.
101 }
102
103 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
104 MockAudioOutputIPC* mock_ipc_; // Owned by AudioOuputDevice.
105 scoped_refptr<FakeAudioOutputDevice> mock_output_device_;
106 scoped_ptr<FakeAudioDeviceFactory> factory_;
107 scoped_ptr<MockAudioRendererSource> source_;
108 scoped_refptr<webrtc::MediaStreamInterface> stream_;
109 scoped_refptr<WebRtcAudioRenderer> renderer_;
110 scoped_refptr<MediaStreamAudioRenderer> renderer_proxy_;
111 };
112
113 // Verify that the renderer will be stopped if the only proxy is stopped.
114 TEST_F(WebRtcAudioRendererTest, StopRenderer) {
115 // |renderer_| has only one proxy, stopping the proxy should stop the sink of
116 // |renderer_|.
117 EXPECT_CALL(*mock_output_device_, Stop());
118 EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get()));
119 renderer_proxy_->Stop();
120 }
121
122 // Verify that the renderer will not be stopped unless the last proxy is
123 // stopped.
124 TEST_F(WebRtcAudioRendererTest, MultipleRenderers) {
125 // Create a vector of renderer proxies from the |renderer_|.
126 std::vector<scoped_refptr<MediaStreamAudioRenderer> > renderer_proxies_;
127 static const int kNumberOfRendererProxy = 5;
128 for (int i = 0; i < kNumberOfRendererProxy; ++i) {
129 scoped_refptr<MediaStreamAudioRenderer> renderer_proxy(
130 renderer_->CreateSharedAudioRendererProxy(stream_));
131 renderer_proxy->Start();
132 renderer_proxies_.push_back(renderer_proxy);
133 }
134
135 // Stop the |renderer_proxy_| should not stop the sink since it is used by
136 // other proxies.
137 EXPECT_CALL(*mock_output_device_, Stop()).Times(0);
138 renderer_proxy_->Stop();
139
140 for (int i = 0; i < kNumberOfRendererProxy; ++i) {
141 if (i != kNumberOfRendererProxy -1) {
142 EXPECT_CALL(*mock_output_device_, Stop()).Times(0);
143 } else {
144 // When the last proxy is stopped, the sink will stop.
145 EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get()));
146 EXPECT_CALL(*mock_output_device_, Stop());
147 }
148 renderer_proxies_[i]->Stop();
149 }
150 }
151
152 } // namespace content
OLDNEW
« 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