OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <memory> | 6 #include <memory> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 } | 23 } |
24 | 24 |
25 namespace media { | 25 namespace media { |
26 | 26 |
27 static const int kBitsPerChannel = 16; | 27 static const int kBitsPerChannel = 16; |
28 static const int kSampleRate = 48000; | 28 static const int kSampleRate = 48000; |
29 static const int kBufferSize = 8192; | 29 static const int kBufferSize = 8192; |
30 static const int kRenderFrameId = 42; | 30 static const int kRenderFrameId = 42; |
31 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; | 31 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
32 static const char kDefaultDeviceId[] = "default"; | 32 static const char kDefaultDeviceId[] = "default"; |
| 33 static const char kAnotherDeviceId[] = "another"; |
33 static const char kUnauthorizedDeviceId[] = "unauthorized"; | 34 static const char kUnauthorizedDeviceId[] = "unauthorized"; |
34 static const char kNonexistentDeviceId[] = "nonexistent"; | 35 static const char kNonexistentDeviceId[] = "nonexistent"; |
35 | 36 |
36 class AudioRendererMixerInputTest : public testing::Test, | 37 class AudioRendererMixerInputTest : public testing::Test, |
37 AudioRendererMixerPool { | 38 AudioRendererMixerPool { |
38 public: | 39 public: |
39 AudioRendererMixerInputTest() { | 40 AudioRendererMixerInputTest() { |
40 audio_parameters_ = AudioParameters( | 41 audio_parameters_ = AudioParameters( |
41 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 42 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
42 kBitsPerChannel, kBufferSize); | 43 kBitsPerChannel, kBufferSize); |
43 | 44 |
44 CreateMixerInput(kDefaultDeviceId); | 45 CreateMixerInput(kDefaultDeviceId); |
45 fake_callback_.reset(new FakeAudioRenderCallback(0)); | 46 fake_callback_.reset(new FakeAudioRenderCallback(0)); |
46 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); | |
47 audio_bus_ = AudioBus::Create(audio_parameters_); | 47 audio_bus_ = AudioBus::Create(audio_parameters_); |
48 } | 48 } |
49 | 49 |
50 void CreateMixerInput(const std::string& device_id) { | 50 void CreateMixerInput(const std::string& device_id) { |
51 mixer_input_ = new AudioRendererMixerInput(this, kRenderFrameId, device_id, | 51 mixer_input_ = new AudioRendererMixerInput(this, kRenderFrameId, device_id, |
52 url::Origin(), | 52 url::Origin(), |
53 AudioLatency::LATENCY_PLAYBACK); | 53 AudioLatency::LATENCY_PLAYBACK); |
54 } | 54 } |
55 | 55 |
56 AudioRendererMixer* GetMixer(int owner_id, | 56 AudioRendererMixer* GetMixer(int owner_id, |
57 const AudioParameters& params, | 57 const AudioParameters& params, |
58 AudioLatency::LatencyType latency, | 58 AudioLatency::LatencyType latency, |
59 const std::string& device_id, | 59 const std::string& device_id, |
60 const url::Origin& security_origin, | 60 const url::Origin& security_origin, |
61 OutputDeviceStatus* device_status) { | 61 OutputDeviceStatus* device_status) { |
| 62 EXPECT_TRUE(params.IsValid()); |
62 if (device_id == kNonexistentDeviceId) { | 63 if (device_id == kNonexistentDeviceId) { |
63 if (device_status) | 64 if (device_status) |
64 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND; | 65 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND; |
65 return nullptr; | 66 return nullptr; |
66 } | 67 } |
67 | 68 |
68 if (device_id == kUnauthorizedDeviceId) { | 69 if (device_id == kUnauthorizedDeviceId) { |
69 if (device_status) | 70 if (device_status) |
70 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED; | 71 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED; |
71 return nullptr; | 72 return nullptr; |
(...skipping 13 matching lines...) Expand all Loading... |
85 | 86 |
86 if (device_status) | 87 if (device_status) |
87 *device_status = OUTPUT_DEVICE_STATUS_OK; | 88 *device_status = OUTPUT_DEVICE_STATUS_OK; |
88 return mixers_[idx].get(); | 89 return mixers_[idx].get(); |
89 } | 90 } |
90 | 91 |
91 double ProvideInput() { | 92 double ProvideInput() { |
92 return mixer_input_->ProvideInput(audio_bus_.get(), 0); | 93 return mixer_input_->ProvideInput(audio_bus_.get(), 0); |
93 } | 94 } |
94 | 95 |
| 96 OutputDeviceInfo GetOutputDeviceInfo(int source_render_frame_id, |
| 97 int session_id, |
| 98 const std::string& device_id, |
| 99 const url::Origin& security_origin) { |
| 100 OutputDeviceStatus status = OUTPUT_DEVICE_STATUS_OK; |
| 101 if (device_id == kNonexistentDeviceId) |
| 102 status = OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND; |
| 103 else if (device_id == kUnauthorizedDeviceId) |
| 104 status = OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED; |
| 105 |
| 106 GetOutputDeviceInfoCalled(device_id); |
| 107 return OutputDeviceInfo(device_id, status, |
| 108 AudioParameters::UnavailableDeviceParams()); |
| 109 } |
| 110 |
| 111 MOCK_METHOD1(GetOutputDeviceInfoCalled, void(const std::string&)); |
| 112 |
95 MOCK_METHOD1(ReturnMixer, void(AudioRendererMixer*)); | 113 MOCK_METHOD1(ReturnMixer, void(AudioRendererMixer*)); |
96 | 114 |
97 MOCK_METHOD4( | |
98 GetOutputDeviceInfo, | |
99 OutputDeviceInfo(int, int, const std::string&, const url::Origin&)); | |
100 | |
101 MOCK_METHOD1(SwitchCallbackCalled, void(OutputDeviceStatus)); | 115 MOCK_METHOD1(SwitchCallbackCalled, void(OutputDeviceStatus)); |
102 | 116 |
103 void SwitchCallback(base::RunLoop* loop, OutputDeviceStatus result) { | 117 void SwitchCallback(base::RunLoop* loop, OutputDeviceStatus result) { |
104 SwitchCallbackCalled(result); | 118 SwitchCallbackCalled(result); |
105 loop->Quit(); | 119 loop->Quit(); |
106 } | 120 } |
107 | 121 |
108 AudioRendererMixer* GetInputMixer() { return mixer_input_->mixer_; } | 122 AudioRendererMixer* GetInputMixer() { return mixer_input_->mixer_; } |
109 | 123 |
110 protected: | 124 protected: |
111 virtual ~AudioRendererMixerInputTest() {} | 125 virtual ~AudioRendererMixerInputTest() {} |
112 | 126 |
113 AudioParameters audio_parameters_; | 127 AudioParameters audio_parameters_; |
114 scoped_refptr<MockAudioRendererSink> sinks_[2]; | 128 scoped_refptr<MockAudioRendererSink> sinks_[2]; |
115 std::unique_ptr<AudioRendererMixer> mixers_[2]; | 129 std::unique_ptr<AudioRendererMixer> mixers_[2]; |
116 scoped_refptr<AudioRendererMixerInput> mixer_input_; | 130 scoped_refptr<AudioRendererMixerInput> mixer_input_; |
117 std::unique_ptr<FakeAudioRenderCallback> fake_callback_; | 131 std::unique_ptr<FakeAudioRenderCallback> fake_callback_; |
118 std::unique_ptr<AudioBus> audio_bus_; | 132 std::unique_ptr<AudioBus> audio_bus_; |
119 | 133 |
120 private: | 134 private: |
121 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInputTest); | 135 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInputTest); |
122 }; | 136 }; |
123 | 137 |
124 TEST_F(AudioRendererMixerInputTest, GetDeviceInfo) { | 138 TEST_F(AudioRendererMixerInputTest, GetDeviceInfo) { |
125 ON_CALL(*this, | 139 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(kDefaultDeviceId)) |
126 GetOutputDeviceInfo(testing::_, testing::_, testing::_, testing::_)) | |
127 .WillByDefault(testing::Return(OutputDeviceInfo())); | |
128 EXPECT_CALL(*this, GetOutputDeviceInfo(kRenderFrameId, 0 /* session id */, | |
129 kDefaultDeviceId, testing::_)) | |
130 .Times(testing::Exactly(1)); | 140 .Times(testing::Exactly(1)); |
131 | 141 |
| 142 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
| 143 |
132 // Calling GetOutputDeviceInfo() should result in the mock call, since there | 144 // Calling GetOutputDeviceInfo() should result in the mock call, since there |
133 // is no mixer created yet for mixer input. | 145 // is no mixer created yet for mixer input. |
134 mixer_input_->GetOutputDeviceInfo(); | 146 mixer_input_->GetOutputDeviceInfo(); |
135 mixer_input_->Start(); | 147 mixer_input_->Start(); |
136 | 148 |
137 // This call should be directed to the mixer and should not result in the mock | 149 // This call should be directed to the mixer and should not result in the mock |
138 // call. | 150 // call. |
139 EXPECT_STREQ(kDefaultDeviceId, | 151 EXPECT_STREQ(kDefaultDeviceId, |
140 mixer_input_->GetOutputDeviceInfo().device_id().c_str()); | 152 mixer_input_->GetOutputDeviceInfo().device_id().c_str()); |
141 | 153 |
142 mixer_input_->Stop(); | 154 mixer_input_->Stop(); |
143 } | 155 } |
144 | 156 |
145 // Test that getting and setting the volume work as expected. The volume is | 157 // Test that getting and setting the volume work as expected. The volume is |
146 // returned from ProvideInput() only when playing. | 158 // returned from ProvideInput() only when playing. |
147 TEST_F(AudioRendererMixerInputTest, GetSetVolume) { | 159 TEST_F(AudioRendererMixerInputTest, GetSetVolume) { |
| 160 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
148 mixer_input_->Start(); | 161 mixer_input_->Start(); |
149 mixer_input_->Play(); | 162 mixer_input_->Play(); |
150 | 163 |
151 // Starting volume should be 1.0. | 164 // Starting volume should be 1.0. |
152 EXPECT_DOUBLE_EQ(ProvideInput(), 1); | 165 EXPECT_DOUBLE_EQ(ProvideInput(), 1); |
153 | 166 |
154 const double kVolume = 0.5; | 167 const double kVolume = 0.5; |
155 EXPECT_TRUE(mixer_input_->SetVolume(kVolume)); | 168 EXPECT_TRUE(mixer_input_->SetVolume(kVolume)); |
156 EXPECT_DOUBLE_EQ(ProvideInput(), kVolume); | 169 EXPECT_DOUBLE_EQ(ProvideInput(), kVolume); |
157 | 170 |
158 mixer_input_->Stop(); | 171 mixer_input_->Stop(); |
159 } | 172 } |
160 | 173 |
161 // Test Start()/Play()/Pause()/Stop()/playing() all work as expected. Also | 174 // Test Start()/Play()/Pause()/Stop()/playing() all work as expected. Also |
162 // implicitly tests that AddMixerInput() and RemoveMixerInput() work without | 175 // implicitly tests that AddMixerInput() and RemoveMixerInput() work without |
163 // crashing; functional tests for these methods are in AudioRendererMixerTest. | 176 // crashing; functional tests for these methods are in AudioRendererMixerTest. |
164 TEST_F(AudioRendererMixerInputTest, StartPlayPauseStopPlaying) { | 177 TEST_F(AudioRendererMixerInputTest, StartPlayPauseStopPlaying) { |
| 178 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
165 mixer_input_->Start(); | 179 mixer_input_->Start(); |
166 mixer_input_->Play(); | 180 mixer_input_->Play(); |
167 EXPECT_DOUBLE_EQ(ProvideInput(), 1); | 181 EXPECT_DOUBLE_EQ(ProvideInput(), 1); |
168 mixer_input_->Pause(); | 182 mixer_input_->Pause(); |
169 mixer_input_->Play(); | 183 mixer_input_->Play(); |
170 EXPECT_DOUBLE_EQ(ProvideInput(), 1); | 184 EXPECT_DOUBLE_EQ(ProvideInput(), 1); |
171 mixer_input_->Stop(); | 185 mixer_input_->Stop(); |
172 } | 186 } |
173 | 187 |
174 // Test that Stop() can be called before Initialize() and Start(). | 188 // Test that Stop() can be called before Initialize() and Start(). |
175 TEST_F(AudioRendererMixerInputTest, StopBeforeInitializeOrStart) { | 189 TEST_F(AudioRendererMixerInputTest, StopBeforeInitializeOrStart) { |
176 // |mixer_input_| was initialized during construction. | |
177 mixer_input_->Stop(); | 190 mixer_input_->Stop(); |
178 | 191 |
179 // Verify Stop() works without Initialize() or Start(). | 192 // Verify Stop() works without Initialize() or Start(). |
180 CreateMixerInput(kDefaultDeviceId); | 193 CreateMixerInput(kDefaultDeviceId); |
181 mixer_input_->Stop(); | 194 mixer_input_->Stop(); |
182 } | 195 } |
183 | 196 |
184 // Test that Start() can be called after Stop(). | 197 // Test that Start() can be called after Stop(). |
185 TEST_F(AudioRendererMixerInputTest, StartAfterStop) { | 198 TEST_F(AudioRendererMixerInputTest, StartAfterStop) { |
| 199 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
186 mixer_input_->Stop(); | 200 mixer_input_->Stop(); |
187 mixer_input_->Start(); | 201 mixer_input_->Start(); |
188 mixer_input_->Stop(); | 202 mixer_input_->Stop(); |
189 } | 203 } |
190 | 204 |
191 // Test that Initialize() can be called again after Stop(). | 205 // Test that Initialize() can be called again after Stop(). |
192 TEST_F(AudioRendererMixerInputTest, InitializeAfterStop) { | 206 TEST_F(AudioRendererMixerInputTest, InitializeAfterStop) { |
193 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); | 207 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
194 mixer_input_->Start(); | 208 mixer_input_->Start(); |
195 mixer_input_->Stop(); | 209 mixer_input_->Stop(); |
196 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); | 210 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
197 mixer_input_->Stop(); | 211 mixer_input_->Stop(); |
198 } | 212 } |
199 | 213 |
200 // Test SwitchOutputDevice(). | 214 // Test SwitchOutputDevice(). |
201 TEST_F(AudioRendererMixerInputTest, SwitchOutputDevice) { | 215 TEST_F(AudioRendererMixerInputTest, SwitchOutputDevice) { |
| 216 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(testing::_)) |
| 217 .Times(testing::Exactly(0)); |
| 218 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
202 mixer_input_->Start(); | 219 mixer_input_->Start(); |
203 const std::string kDeviceId("mock-device-id"); | 220 const std::string kDeviceId("mock-device-id"); |
204 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); | 221 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); |
205 AudioRendererMixer* old_mixer = GetInputMixer(); | 222 AudioRendererMixer* old_mixer = GetInputMixer(); |
206 EXPECT_EQ(old_mixer, mixers_[0].get()); | 223 EXPECT_EQ(old_mixer, mixers_[0].get()); |
207 base::RunLoop run_loop; | 224 base::RunLoop run_loop; |
208 mixer_input_->SwitchOutputDevice( | 225 mixer_input_->SwitchOutputDevice( |
209 kDeviceId, url::Origin(), | 226 kDeviceId, url::Origin(), |
210 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 227 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
211 base::Unretained(this), &run_loop)); | 228 base::Unretained(this), &run_loop)); |
212 run_loop.Run(); | 229 run_loop.Run(); |
213 AudioRendererMixer* new_mixer = GetInputMixer(); | 230 AudioRendererMixer* new_mixer = GetInputMixer(); |
214 EXPECT_EQ(new_mixer, mixers_[1].get()); | 231 EXPECT_EQ(new_mixer, mixers_[1].get()); |
215 EXPECT_NE(old_mixer, new_mixer); | 232 EXPECT_NE(old_mixer, new_mixer); |
216 mixer_input_->Stop(); | 233 mixer_input_->Stop(); |
217 } | 234 } |
218 | 235 |
219 // Test SwitchOutputDevice() to the same device as the current (default) device | 236 // Test SwitchOutputDevice() to the same device as the current (default) device |
220 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceToSameDevice) { | 237 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceToSameDevice) { |
| 238 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(testing::_)) |
| 239 .Times(testing::Exactly(0)); |
| 240 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
221 mixer_input_->Start(); | 241 mixer_input_->Start(); |
222 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); | 242 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); |
223 AudioRendererMixer* old_mixer = GetInputMixer(); | 243 AudioRendererMixer* old_mixer = GetInputMixer(); |
224 base::RunLoop run_loop; | 244 base::RunLoop run_loop; |
225 mixer_input_->SwitchOutputDevice( | 245 mixer_input_->SwitchOutputDevice( |
226 kDefaultDeviceId, url::Origin(), | 246 kDefaultDeviceId, url::Origin(), |
227 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 247 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
228 base::Unretained(this), &run_loop)); | 248 base::Unretained(this), &run_loop)); |
229 run_loop.Run(); | 249 run_loop.Run(); |
230 AudioRendererMixer* new_mixer = GetInputMixer(); | 250 AudioRendererMixer* new_mixer = GetInputMixer(); |
231 EXPECT_EQ(old_mixer, new_mixer); | 251 EXPECT_EQ(old_mixer, new_mixer); |
232 mixer_input_->Stop(); | 252 mixer_input_->Stop(); |
233 } | 253 } |
234 | 254 |
| 255 // Test SwitchOutputDevice() to the new device |
| 256 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceToAnotherDevice) { |
| 257 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(testing::_)) |
| 258 .Times(testing::Exactly(0)); |
| 259 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
| 260 mixer_input_->Start(); |
| 261 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); |
| 262 AudioRendererMixer* old_mixer = GetInputMixer(); |
| 263 base::RunLoop run_loop; |
| 264 mixer_input_->SwitchOutputDevice( |
| 265 kAnotherDeviceId, url::Origin(), |
| 266 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
| 267 base::Unretained(this), &run_loop)); |
| 268 run_loop.Run(); |
| 269 AudioRendererMixer* new_mixer = GetInputMixer(); |
| 270 EXPECT_NE(old_mixer, new_mixer); |
| 271 mixer_input_->Stop(); |
| 272 } |
| 273 |
235 // Test that SwitchOutputDevice() to a nonexistent device fails. | 274 // Test that SwitchOutputDevice() to a nonexistent device fails. |
236 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceToNonexistentDevice) { | 275 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceToNonexistentDevice) { |
| 276 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(testing::_)) |
| 277 .Times(testing::Exactly(0)); |
| 278 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
237 mixer_input_->Start(); | 279 mixer_input_->Start(); |
238 EXPECT_CALL(*this, | 280 EXPECT_CALL(*this, |
239 SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND)); | 281 SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND)); |
240 base::RunLoop run_loop; | 282 base::RunLoop run_loop; |
241 mixer_input_->SwitchOutputDevice( | 283 mixer_input_->SwitchOutputDevice( |
242 kNonexistentDeviceId, url::Origin(), | 284 kNonexistentDeviceId, url::Origin(), |
243 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 285 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
244 base::Unretained(this), &run_loop)); | 286 base::Unretained(this), &run_loop)); |
245 run_loop.Run(); | 287 run_loop.Run(); |
246 mixer_input_->Stop(); | 288 mixer_input_->Stop(); |
247 } | 289 } |
248 | 290 |
249 // Test that SwitchOutputDevice() to an unauthorized device fails. | 291 // Test that SwitchOutputDevice() to an unauthorized device fails. |
250 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceToUnauthorizedDevice) { | 292 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceToUnauthorizedDevice) { |
| 293 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(testing::_)) |
| 294 .Times(testing::Exactly(0)); |
| 295 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
251 mixer_input_->Start(); | 296 mixer_input_->Start(); |
252 EXPECT_CALL(*this, | 297 EXPECT_CALL(*this, |
253 SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED)); | 298 SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED)); |
254 base::RunLoop run_loop; | 299 base::RunLoop run_loop; |
255 mixer_input_->SwitchOutputDevice( | 300 mixer_input_->SwitchOutputDevice( |
256 kUnauthorizedDeviceId, url::Origin(), | 301 kUnauthorizedDeviceId, url::Origin(), |
257 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 302 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
258 base::Unretained(this), &run_loop)); | 303 base::Unretained(this), &run_loop)); |
259 run_loop.Run(); | 304 run_loop.Run(); |
260 mixer_input_->Stop(); | 305 mixer_input_->Stop(); |
261 } | 306 } |
262 | 307 |
263 // Test that calling SwitchOutputDevice() before Start() succeeds. | 308 // Test that calling SwitchOutputDevice() before Start() succeeds. |
264 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceBeforeStart) { | 309 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceBeforeStart) { |
| 310 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(kAnotherDeviceId)) |
| 311 .Times(testing::Exactly(1)); |
| 312 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
265 base::RunLoop run_loop; | 313 base::RunLoop run_loop; |
266 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); | 314 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); |
267 mixer_input_->SwitchOutputDevice( | 315 mixer_input_->SwitchOutputDevice( |
268 kDefaultDeviceId, url::Origin(), | 316 kAnotherDeviceId, url::Origin(), |
269 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 317 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
270 base::Unretained(this), &run_loop)); | 318 base::Unretained(this), &run_loop)); |
271 mixer_input_->Start(); | 319 mixer_input_->Start(); |
272 run_loop.Run(); | 320 run_loop.Run(); |
273 mixer_input_->Stop(); | 321 mixer_input_->Stop(); |
274 } | 322 } |
275 | 323 |
276 // Test that calling SwitchOutputDevice() succeeds even if Start() is never | 324 // Test that calling SwitchOutputDevice() succeeds even if Start() is never |
277 // called. | 325 // called. |
278 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceWithoutStart) { | 326 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceWithoutStart) { |
| 327 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(kAnotherDeviceId)) |
| 328 .Times(testing::Exactly(1)); |
| 329 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
279 base::RunLoop run_loop; | 330 base::RunLoop run_loop; |
280 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); | 331 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); |
281 mixer_input_->SwitchOutputDevice( | 332 mixer_input_->SwitchOutputDevice( |
282 kDefaultDeviceId, url::Origin(), | 333 kAnotherDeviceId, url::Origin(), |
283 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 334 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
284 base::Unretained(this), &run_loop)); | 335 base::Unretained(this), &run_loop)); |
285 mixer_input_->Stop(); | 336 mixer_input_->Stop(); |
286 run_loop.Run(); | 337 run_loop.Run(); |
287 } | 338 } |
288 | 339 |
289 // Test creation with an invalid device. OnRenderError() should be called. | 340 // Test creation with an invalid device. OnRenderError() should be called. |
290 // Play(), Pause() and SwitchOutputDevice() should not cause crashes, even if | 341 // Play(), Pause() and SwitchOutputDevice() should not cause crashes, even if |
291 // they have no effect. | 342 // they have no effect. |
292 TEST_F(AudioRendererMixerInputTest, CreateWithInvalidDevice) { | 343 TEST_F(AudioRendererMixerInputTest, CreateWithInvalidDevice) { |
| 344 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(kDefaultDeviceId)) |
| 345 .Times(testing::Exactly(1)); |
293 // |mixer_input_| was initialized during construction. | 346 // |mixer_input_| was initialized during construction. |
294 mixer_input_->Stop(); | 347 mixer_input_->Stop(); |
295 | 348 |
296 CreateMixerInput(kNonexistentDeviceId); | 349 CreateMixerInput(kNonexistentDeviceId); |
297 EXPECT_CALL(*fake_callback_, OnRenderError()); | 350 EXPECT_CALL(*fake_callback_, OnRenderError()); |
298 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); | 351 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
299 mixer_input_->Start(); | 352 mixer_input_->Start(); |
300 mixer_input_->Play(); | 353 mixer_input_->Play(); |
301 mixer_input_->Pause(); | 354 mixer_input_->Pause(); |
302 base::RunLoop run_loop; | 355 base::RunLoop run_loop; |
303 EXPECT_CALL(*this, SwitchCallbackCalled(testing::_)); | 356 EXPECT_CALL(*this, SwitchCallbackCalled(testing::_)); |
304 mixer_input_->SwitchOutputDevice( | 357 mixer_input_->SwitchOutputDevice( |
305 kDefaultDeviceId, url::Origin(), | 358 kDefaultDeviceId, url::Origin(), |
306 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 359 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
307 base::Unretained(this), &run_loop)); | 360 base::Unretained(this), &run_loop)); |
308 mixer_input_->Stop(); | 361 mixer_input_->Stop(); |
309 run_loop.Run(); | 362 run_loop.Run(); |
310 } | 363 } |
311 | 364 |
312 // Test that calling SwitchOutputDevice() works after calling Stop(), and that | 365 // Test that calling SwitchOutputDevice() works after calling Stop(), and that |
313 // restarting works after the call to SwitchOutputDevice(). | 366 // restarting works after the call to SwitchOutputDevice(). |
314 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceAfterStopBeforeRestart) { | 367 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceAfterStopBeforeRestart) { |
| 368 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(kAnotherDeviceId)) |
| 369 .Times(testing::Exactly(1)); |
| 370 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
315 mixer_input_->Start(); | 371 mixer_input_->Start(); |
316 mixer_input_->Stop(); | 372 mixer_input_->Stop(); |
317 | 373 |
318 base::RunLoop run_loop; | 374 base::RunLoop run_loop; |
319 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); | 375 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); |
320 mixer_input_->SwitchOutputDevice( | 376 mixer_input_->SwitchOutputDevice( |
321 kDefaultDeviceId, url::Origin(), | 377 kAnotherDeviceId, url::Origin(), |
322 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 378 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
323 base::Unretained(this), &run_loop)); | 379 base::Unretained(this), &run_loop)); |
324 run_loop.Run(); | 380 run_loop.Run(); |
325 | 381 |
326 mixer_input_->Start(); | 382 mixer_input_->Start(); |
327 mixer_input_->Stop(); | 383 mixer_input_->Stop(); |
328 } | 384 } |
329 | 385 |
| 386 // Test that calling SwitchOutputDevice() works before calling Initialize(), |
| 387 // and that initialization and restart work after the call to |
| 388 // SwitchOutputDevice(). |
| 389 TEST_F(AudioRendererMixerInputTest, SwitchOutputDeviceBeforeInitialize) { |
| 390 EXPECT_CALL(*this, GetOutputDeviceInfoCalled(kAnotherDeviceId)) |
| 391 .Times(testing::Exactly(1)); |
| 392 base::RunLoop run_loop; |
| 393 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_OK)); |
| 394 mixer_input_->SwitchOutputDevice( |
| 395 kAnotherDeviceId, url::Origin(), |
| 396 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
| 397 base::Unretained(this), &run_loop)); |
| 398 run_loop.Run(); |
| 399 |
| 400 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
| 401 mixer_input_->Start(); |
| 402 mixer_input_->Stop(); |
| 403 } |
| 404 |
330 } // namespace media | 405 } // namespace media |
OLD | NEW |