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 <string> |
| 6 |
5 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
6 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
7 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
8 #include "media/audio/audio_output_dispatcher.h" | 10 #include "media/audio/audio_output_dispatcher_impl.h" |
| 11 #include "media/audio/audio_output_mixer.h" |
9 #include "media/audio/audio_output_proxy.h" | 12 #include "media/audio/audio_output_proxy.h" |
10 #include "media/audio/audio_manager.h" | 13 #include "media/audio/audio_manager.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
13 | 16 |
14 using ::testing::_; | 17 using ::testing::_; |
15 using ::testing::Mock; | 18 using ::testing::Mock; |
16 using ::testing::Return; | 19 using ::testing::Return; |
17 using media::AudioBuffersState; | 20 using media::AudioBuffersState; |
18 using media::AudioInputStream; | 21 using media::AudioInputStream; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 class AudioOutputProxyTest : public testing::Test { | 84 class AudioOutputProxyTest : public testing::Test { |
82 protected: | 85 protected: |
83 virtual void SetUp() { | 86 virtual void SetUp() { |
84 EXPECT_CALL(manager_, GetMessageLoop()) | 87 EXPECT_CALL(manager_, GetMessageLoop()) |
85 .WillRepeatedly(Return(message_loop_.message_loop_proxy())); | 88 .WillRepeatedly(Return(message_loop_.message_loop_proxy())); |
86 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); | 89 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); |
87 } | 90 } |
88 | 91 |
89 virtual void TearDown() { | 92 virtual void TearDown() { |
90 // All paused proxies should have been closed at this point. | 93 // All paused proxies should have been closed at this point. |
91 EXPECT_EQ(0u, dispatcher_->paused_proxies_); | 94 EXPECT_EQ(0u, dispatcher_impl_->paused_proxies_); |
92 | 95 |
93 // This is necessary to free all proxy objects that have been | 96 // This is necessary to free all proxy objects that have been |
94 // closed by the test. | 97 // closed by the test. |
95 message_loop_.RunAllPending(); | 98 message_loop_.RunAllPending(); |
96 } | 99 } |
97 | 100 |
98 void InitDispatcher(base::TimeDelta close_delay) { | 101 void InitDispatcher(base::TimeDelta close_delay) { |
99 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 102 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
100 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); | 103 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); |
101 dispatcher_ = new AudioOutputDispatcher(&manager(), params, close_delay); | 104 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), |
| 105 params, |
| 106 close_delay); |
| 107 mixer_ = new AudioOutputMixer(&manager(), params, close_delay); |
102 | 108 |
103 // Necessary to know how long the dispatcher will wait before posting | 109 // Necessary to know how long the dispatcher will wait before posting |
104 // StopStreamTask. | 110 // StopStreamTask. |
105 pause_delay_ = dispatcher_->pause_delay_; | 111 pause_delay_ = dispatcher_impl_->pause_delay_; |
106 } | 112 } |
107 | 113 |
108 MockAudioManager& manager() { | 114 MockAudioManager& manager() { |
109 return manager_; | 115 return manager_; |
110 } | 116 } |
111 | 117 |
| 118 // Wait for the close timer to fire. |
| 119 void WaitForCloseTimer(const int timer_delay_ms) { |
| 120 message_loop_.RunAllPending(); // OpenTask() may reset the timer. |
| 121 base::PlatformThread::Sleep( |
| 122 base::TimeDelta::FromMilliseconds(timer_delay_ms) * 2); |
| 123 message_loop_.RunAllPending(); |
| 124 } |
| 125 |
| 126 // Methods that do actual tests. |
| 127 void OpenAndClose(AudioOutputDispatcher* dispatcher) { |
| 128 MockAudioOutputStream stream; |
| 129 |
| 130 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 131 .WillOnce(Return(&stream)); |
| 132 EXPECT_CALL(stream, Open()) |
| 133 .WillOnce(Return(true)); |
| 134 EXPECT_CALL(stream, Close()) |
| 135 .Times(1); |
| 136 |
| 137 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 138 EXPECT_TRUE(proxy->Open()); |
| 139 proxy->Close(); |
| 140 WaitForCloseTimer(kTestCloseDelayMs); |
| 141 } |
| 142 |
| 143 // Create a stream, and then calls Start() and Stop(). |
| 144 void StartAndStop(AudioOutputDispatcher* dispatcher) { |
| 145 MockAudioOutputStream stream; |
| 146 |
| 147 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 148 .WillOnce(Return(&stream)); |
| 149 EXPECT_CALL(stream, Open()) |
| 150 .WillOnce(Return(true)); |
| 151 EXPECT_CALL(stream, Start(_)) |
| 152 .Times(1); |
| 153 EXPECT_CALL(stream, SetVolume(_)) |
| 154 .Times(1); |
| 155 EXPECT_CALL(stream, Stop()) |
| 156 .Times(1); |
| 157 EXPECT_CALL(stream, Close()) |
| 158 .Times(1); |
| 159 |
| 160 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 161 EXPECT_TRUE(proxy->Open()); |
| 162 |
| 163 proxy->Start(&callback_); |
| 164 proxy->Stop(); |
| 165 |
| 166 proxy->Close(); |
| 167 WaitForCloseTimer(kTestCloseDelayMs); |
| 168 } |
| 169 |
| 170 // Verify that the stream is closed after Stop is called. |
| 171 void CloseAfterStop(AudioOutputDispatcher* dispatcher) { |
| 172 MockAudioOutputStream stream; |
| 173 |
| 174 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 175 .WillOnce(Return(&stream)); |
| 176 EXPECT_CALL(stream, Open()) |
| 177 .WillOnce(Return(true)); |
| 178 EXPECT_CALL(stream, Start(_)) |
| 179 .Times(1); |
| 180 EXPECT_CALL(stream, SetVolume(_)) |
| 181 .Times(1); |
| 182 EXPECT_CALL(stream, Stop()) |
| 183 .Times(1); |
| 184 EXPECT_CALL(stream, Close()) |
| 185 .Times(1); |
| 186 |
| 187 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 188 EXPECT_TRUE(proxy->Open()); |
| 189 |
| 190 proxy->Start(&callback_); |
| 191 proxy->Stop(); |
| 192 |
| 193 // Wait for StopStream() to post StopStreamTask(). |
| 194 base::PlatformThread::Sleep(pause_delay_ * 2); |
| 195 WaitForCloseTimer(kTestCloseDelayMs); |
| 196 |
| 197 // Verify expectation before calling Close(). |
| 198 Mock::VerifyAndClear(&stream); |
| 199 |
| 200 proxy->Close(); |
| 201 } |
| 202 |
| 203 // Create two streams, but don't start them. Only one device must be open. |
| 204 void TwoStreams(AudioOutputDispatcher* dispatcher) { |
| 205 MockAudioOutputStream stream; |
| 206 |
| 207 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 208 .WillOnce(Return(&stream)); |
| 209 EXPECT_CALL(stream, Open()) |
| 210 .WillOnce(Return(true)); |
| 211 EXPECT_CALL(stream, Close()) |
| 212 .Times(1); |
| 213 |
| 214 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); |
| 215 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); |
| 216 EXPECT_TRUE(proxy1->Open()); |
| 217 EXPECT_TRUE(proxy2->Open()); |
| 218 proxy1->Close(); |
| 219 proxy2->Close(); |
| 220 WaitForCloseTimer(kTestCloseDelayMs); |
| 221 } |
| 222 |
| 223 // Open() method failed. |
| 224 void OpenFailed(AudioOutputDispatcher* dispatcher) { |
| 225 MockAudioOutputStream stream; |
| 226 |
| 227 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 228 .WillOnce(Return(&stream)); |
| 229 EXPECT_CALL(stream, Open()) |
| 230 .WillOnce(Return(false)); |
| 231 EXPECT_CALL(stream, Close()) |
| 232 .Times(1); |
| 233 |
| 234 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 235 EXPECT_FALSE(proxy->Open()); |
| 236 proxy->Close(); |
| 237 WaitForCloseTimer(kTestCloseDelayMs); |
| 238 } |
| 239 |
112 MessageLoop message_loop_; | 240 MessageLoop message_loop_; |
113 scoped_refptr<AudioOutputDispatcher> dispatcher_; | 241 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_; |
| 242 scoped_refptr<AudioOutputMixer> mixer_; |
114 base::TimeDelta pause_delay_; | 243 base::TimeDelta pause_delay_; |
115 MockAudioManager manager_; | 244 MockAudioManager manager_; |
116 MockAudioSourceCallback callback_; | 245 MockAudioSourceCallback callback_; |
117 }; | 246 }; |
118 | 247 |
119 TEST_F(AudioOutputProxyTest, CreateAndClose) { | 248 TEST_F(AudioOutputProxyTest, CreateAndClose) { |
120 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); | 249 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); |
| 250 proxy->Close(); |
| 251 } |
| 252 |
| 253 TEST_F(AudioOutputProxyTest, CreateAndClose_Mixer) { |
| 254 AudioOutputProxy* proxy = new AudioOutputProxy(mixer_); |
121 proxy->Close(); | 255 proxy->Close(); |
122 } | 256 } |
123 | 257 |
124 TEST_F(AudioOutputProxyTest, OpenAndClose) { | 258 TEST_F(AudioOutputProxyTest, OpenAndClose) { |
125 MockAudioOutputStream stream; | 259 OpenAndClose(dispatcher_impl_); |
| 260 } |
126 | 261 |
127 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 262 TEST_F(AudioOutputProxyTest, OpenAndClose_Mixer) { |
128 .WillOnce(Return(&stream)); | 263 OpenAndClose(mixer_); |
129 EXPECT_CALL(stream, Open()) | |
130 .WillOnce(Return(true)); | |
131 EXPECT_CALL(stream, Close()) | |
132 .Times(1); | |
133 | |
134 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); | |
135 EXPECT_TRUE(proxy->Open()); | |
136 proxy->Close(); | |
137 } | 264 } |
138 | 265 |
139 // Create a stream, and verify that it is closed after kTestCloseDelayMs. | 266 // Create a stream, and verify that it is closed after kTestCloseDelayMs. |
140 // if it doesn't start playing. | 267 // if it doesn't start playing. |
141 TEST_F(AudioOutputProxyTest, CreateAndWait) { | 268 TEST_F(AudioOutputProxyTest, CreateAndWait) { |
142 MockAudioOutputStream stream; | 269 MockAudioOutputStream stream; |
143 | 270 |
144 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 271 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
145 .WillOnce(Return(&stream)); | 272 .WillOnce(Return(&stream)); |
146 EXPECT_CALL(stream, Open()) | 273 EXPECT_CALL(stream, Open()) |
147 .WillOnce(Return(true)); | 274 .WillOnce(Return(true)); |
148 EXPECT_CALL(stream, Close()) | 275 EXPECT_CALL(stream, Close()) |
149 .Times(1); | 276 .Times(1); |
150 | 277 |
151 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); | 278 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); |
152 EXPECT_TRUE(proxy->Open()); | 279 EXPECT_TRUE(proxy->Open()); |
153 | 280 |
154 // Simulate a delay. | 281 // Simulate a delay. |
155 base::PlatformThread::Sleep( | 282 base::PlatformThread::Sleep( |
156 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); | 283 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); |
157 message_loop_.RunAllPending(); | 284 message_loop_.RunAllPending(); |
158 | 285 |
159 // Verify expectation before calling Close(). | 286 // Verify expectation before calling Close(). |
160 Mock::VerifyAndClear(&stream); | 287 Mock::VerifyAndClear(&stream); |
161 | 288 |
162 proxy->Close(); | 289 proxy->Close(); |
163 } | 290 } |
164 | 291 |
165 // Create a stream, and then calls Start() and Stop(). | |
166 TEST_F(AudioOutputProxyTest, StartAndStop) { | 292 TEST_F(AudioOutputProxyTest, StartAndStop) { |
167 MockAudioOutputStream stream; | 293 StartAndStop(dispatcher_impl_); |
168 | |
169 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | |
170 .WillOnce(Return(&stream)); | |
171 EXPECT_CALL(stream, Open()) | |
172 .WillOnce(Return(true)); | |
173 EXPECT_CALL(stream, Start(_)) | |
174 .Times(1); | |
175 EXPECT_CALL(stream, SetVolume(_)) | |
176 .Times(1); | |
177 EXPECT_CALL(stream, Stop()) | |
178 .Times(1); | |
179 EXPECT_CALL(stream, Close()) | |
180 .Times(1); | |
181 | |
182 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); | |
183 EXPECT_TRUE(proxy->Open()); | |
184 | |
185 proxy->Start(&callback_); | |
186 proxy->Stop(); | |
187 | |
188 proxy->Close(); | |
189 } | 294 } |
190 | 295 |
191 // Verify that the stream is closed after Stop is called. | 296 TEST_F(AudioOutputProxyTest, StartAndStop_Mixer) { |
192 TEST_F(AudioOutputProxyTest, CloseAfterStop) { | 297 StartAndStop(mixer_); |
193 MockAudioOutputStream stream; | |
194 | |
195 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | |
196 .WillOnce(Return(&stream)); | |
197 EXPECT_CALL(stream, Open()) | |
198 .WillOnce(Return(true)); | |
199 EXPECT_CALL(stream, Start(_)) | |
200 .Times(1); | |
201 EXPECT_CALL(stream, SetVolume(_)) | |
202 .Times(1); | |
203 EXPECT_CALL(stream, Stop()) | |
204 .Times(1); | |
205 EXPECT_CALL(stream, Close()) | |
206 .Times(1); | |
207 | |
208 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); | |
209 EXPECT_TRUE(proxy->Open()); | |
210 | |
211 proxy->Start(&callback_); | |
212 proxy->Stop(); | |
213 | |
214 // Wait for StreamStopped() to post StopStreamTask(). | |
215 base::PlatformThread::Sleep(pause_delay_ * 2); | |
216 message_loop_.RunAllPending(); | |
217 | |
218 // Wait for the close timer to fire. | |
219 base::PlatformThread::Sleep( | |
220 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); | |
221 message_loop_.RunAllPending(); | |
222 | |
223 // Verify expectation before calling Close(). | |
224 Mock::VerifyAndClear(&stream); | |
225 | |
226 proxy->Close(); | |
227 } | 298 } |
228 | 299 |
229 // Create two streams, but don't start them. Only one device must be open. | 300 TEST_F(AudioOutputProxyTest, CloseAfterStop) { |
| 301 CloseAfterStop(dispatcher_impl_); |
| 302 } |
| 303 |
| 304 TEST_F(AudioOutputProxyTest, CloseAfterStop_Mixer) { |
| 305 CloseAfterStop(mixer_); |
| 306 } |
| 307 |
230 TEST_F(AudioOutputProxyTest, TwoStreams) { | 308 TEST_F(AudioOutputProxyTest, TwoStreams) { |
231 MockAudioOutputStream stream; | 309 TwoStreams(dispatcher_impl_); |
| 310 } |
232 | 311 |
233 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 312 TEST_F(AudioOutputProxyTest, TwoStreams_Mixer) { |
234 .WillOnce(Return(&stream)); | 313 TwoStreams(mixer_); |
235 EXPECT_CALL(stream, Open()) | |
236 .WillOnce(Return(true)); | |
237 EXPECT_CALL(stream, Close()) | |
238 .Times(1); | |
239 | |
240 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_); | |
241 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_); | |
242 EXPECT_TRUE(proxy1->Open()); | |
243 EXPECT_TRUE(proxy2->Open()); | |
244 proxy1->Close(); | |
245 proxy2->Close(); | |
246 } | 314 } |
247 | 315 |
248 // Two streams: verify that second stream is allocated when the first | 316 // Two streams: verify that second stream is allocated when the first |
249 // starts playing. | 317 // starts playing. |
250 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) { | 318 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) { |
251 MockAudioOutputStream stream1; | 319 MockAudioOutputStream stream1; |
252 MockAudioOutputStream stream2; | 320 MockAudioOutputStream stream2; |
253 | 321 |
254 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); | 322 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); |
255 | 323 |
(...skipping 10 matching lines...) Expand all Loading... |
266 EXPECT_CALL(stream1, Stop()) | 334 EXPECT_CALL(stream1, Stop()) |
267 .Times(1); | 335 .Times(1); |
268 EXPECT_CALL(stream1, Close()) | 336 EXPECT_CALL(stream1, Close()) |
269 .Times(1); | 337 .Times(1); |
270 | 338 |
271 EXPECT_CALL(stream2, Open()) | 339 EXPECT_CALL(stream2, Open()) |
272 .WillOnce(Return(true)); | 340 .WillOnce(Return(true)); |
273 EXPECT_CALL(stream2, Close()) | 341 EXPECT_CALL(stream2, Close()) |
274 .Times(1); | 342 .Times(1); |
275 | 343 |
276 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_); | 344 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_impl_); |
277 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_); | 345 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_impl_); |
278 EXPECT_TRUE(proxy1->Open()); | 346 EXPECT_TRUE(proxy1->Open()); |
279 EXPECT_TRUE(proxy2->Open()); | 347 EXPECT_TRUE(proxy2->Open()); |
280 | 348 |
281 proxy1->Start(&callback_); | 349 proxy1->Start(&callback_); |
282 message_loop_.RunAllPending(); | 350 message_loop_.RunAllPending(); |
283 proxy1->Stop(); | 351 proxy1->Stop(); |
284 | 352 |
285 proxy1->Close(); | 353 proxy1->Close(); |
286 proxy2->Close(); | 354 proxy2->Close(); |
287 } | 355 } |
288 | 356 |
| 357 // Two streams: verify that only one device will be created. |
| 358 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Mixer) { |
| 359 MockAudioOutputStream stream; |
| 360 |
| 361 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); |
| 362 |
| 363 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 364 .WillOnce(Return(&stream)); |
| 365 |
| 366 EXPECT_CALL(stream, Open()) |
| 367 .WillOnce(Return(true)); |
| 368 EXPECT_CALL(stream, Start(_)) |
| 369 .Times(1); |
| 370 EXPECT_CALL(stream, SetVolume(_)) |
| 371 .Times(1); |
| 372 EXPECT_CALL(stream, Stop()) |
| 373 .Times(1); |
| 374 EXPECT_CALL(stream, Close()) |
| 375 .Times(1); |
| 376 |
| 377 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_); |
| 378 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_); |
| 379 EXPECT_TRUE(proxy1->Open()); |
| 380 EXPECT_TRUE(proxy2->Open()); |
| 381 |
| 382 proxy1->Start(&callback_); |
| 383 proxy1->Stop(); |
| 384 |
| 385 proxy1->Close(); |
| 386 proxy2->Close(); |
| 387 WaitForCloseTimer(kTestCloseDelayMs); |
| 388 } |
| 389 |
289 // Two streams, both are playing. Dispatcher should not open a third stream. | 390 // Two streams, both are playing. Dispatcher should not open a third stream. |
290 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { | 391 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { |
291 MockAudioOutputStream stream1; | 392 MockAudioOutputStream stream1; |
292 MockAudioOutputStream stream2; | 393 MockAudioOutputStream stream2; |
293 | 394 |
294 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); | 395 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); |
295 | 396 |
296 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 397 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
297 .WillOnce(Return(&stream1)) | 398 .WillOnce(Return(&stream1)) |
298 .WillOnce(Return(&stream2)); | 399 .WillOnce(Return(&stream2)); |
(...skipping 13 matching lines...) Expand all Loading... |
312 .WillOnce(Return(true)); | 413 .WillOnce(Return(true)); |
313 EXPECT_CALL(stream2, Start(_)) | 414 EXPECT_CALL(stream2, Start(_)) |
314 .Times(1); | 415 .Times(1); |
315 EXPECT_CALL(stream2, SetVolume(_)) | 416 EXPECT_CALL(stream2, SetVolume(_)) |
316 .Times(1); | 417 .Times(1); |
317 EXPECT_CALL(stream2, Stop()) | 418 EXPECT_CALL(stream2, Stop()) |
318 .Times(1); | 419 .Times(1); |
319 EXPECT_CALL(stream2, Close()) | 420 EXPECT_CALL(stream2, Close()) |
320 .Times(1); | 421 .Times(1); |
321 | 422 |
322 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_); | 423 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_impl_); |
323 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_); | 424 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_impl_); |
324 EXPECT_TRUE(proxy1->Open()); | 425 EXPECT_TRUE(proxy1->Open()); |
325 EXPECT_TRUE(proxy2->Open()); | 426 EXPECT_TRUE(proxy2->Open()); |
326 | 427 |
327 proxy1->Start(&callback_); | 428 proxy1->Start(&callback_); |
328 proxy2->Start(&callback_); | 429 proxy2->Start(&callback_); |
329 proxy1->Stop(); | 430 proxy1->Stop(); |
330 proxy2->Stop(); | 431 proxy2->Stop(); |
331 | 432 |
332 proxy1->Close(); | 433 proxy1->Close(); |
333 proxy2->Close(); | 434 proxy2->Close(); |
334 } | 435 } |
335 | 436 |
336 // Open() method failed. | 437 // Two streams, both are playing. Still have to use single device. |
337 TEST_F(AudioOutputProxyTest, OpenFailed) { | 438 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) { |
338 MockAudioOutputStream stream; | 439 MockAudioOutputStream stream; |
339 | 440 |
| 441 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); |
| 442 |
340 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 443 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
341 .WillOnce(Return(&stream)); | 444 .WillOnce(Return(&stream)); |
| 445 |
342 EXPECT_CALL(stream, Open()) | 446 EXPECT_CALL(stream, Open()) |
343 .WillOnce(Return(false)); | 447 .WillOnce(Return(true)); |
| 448 EXPECT_CALL(stream, Start(_)) |
| 449 .Times(1); |
| 450 EXPECT_CALL(stream, SetVolume(_)) |
| 451 .Times(1); |
| 452 EXPECT_CALL(stream, Stop()) |
| 453 .Times(1); |
344 EXPECT_CALL(stream, Close()) | 454 EXPECT_CALL(stream, Close()) |
345 .Times(1); | 455 .Times(1); |
346 | 456 |
347 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); | 457 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_); |
348 EXPECT_FALSE(proxy->Open()); | 458 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_); |
349 proxy->Close(); | 459 EXPECT_TRUE(proxy1->Open()); |
| 460 EXPECT_TRUE(proxy2->Open()); |
| 461 |
| 462 proxy1->Start(&callback_); |
| 463 proxy2->Start(&callback_); |
| 464 proxy1->Stop(); |
| 465 proxy2->Stop(); |
| 466 |
| 467 proxy1->Close(); |
| 468 proxy2->Close(); |
| 469 WaitForCloseTimer(kTestCloseDelayMs); |
| 470 } |
| 471 |
| 472 TEST_F(AudioOutputProxyTest, OpenFailed) { |
| 473 OpenFailed(dispatcher_impl_); |
| 474 } |
| 475 |
| 476 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) { |
| 477 OpenFailed(mixer_); |
350 } | 478 } |
351 | 479 |
352 // Start() method failed. | 480 // Start() method failed. |
353 TEST_F(AudioOutputProxyTest, StartFailed) { | 481 TEST_F(AudioOutputProxyTest, StartFailed) { |
354 MockAudioOutputStream stream; | 482 MockAudioOutputStream stream; |
355 | 483 |
356 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 484 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
357 .WillOnce(Return(&stream)); | 485 .WillOnce(Return(&stream)); |
358 EXPECT_CALL(stream, Open()) | 486 EXPECT_CALL(stream, Open()) |
359 .WillOnce(Return(true)); | 487 .WillOnce(Return(true)); |
360 EXPECT_CALL(stream, Close()) | 488 EXPECT_CALL(stream, Close()) |
361 .Times(1); | 489 .Times(1); |
362 | 490 |
363 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); | 491 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); |
364 EXPECT_TRUE(proxy->Open()); | 492 EXPECT_TRUE(proxy->Open()); |
365 | 493 |
366 // Simulate a delay. | 494 // Simulate a delay. |
367 base::PlatformThread::Sleep( | 495 base::PlatformThread::Sleep( |
368 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); | 496 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); |
369 message_loop_.RunAllPending(); | 497 message_loop_.RunAllPending(); |
370 | 498 |
371 // Verify expectation before calling Close(). | 499 // Verify expectation before calling Close(). |
372 Mock::VerifyAndClear(&stream); | 500 Mock::VerifyAndClear(&stream); |
373 | 501 |
374 // |stream| is closed at this point. Start() should reopen it again. | 502 // |stream| is closed at this point. Start() should reopen it again. |
375 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 503 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
376 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL))); | 504 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL))); |
377 | 505 |
378 EXPECT_CALL(callback_, OnError(_, _)) | 506 EXPECT_CALL(callback_, OnError(_, _)) |
379 .Times(1); | 507 .Times(1); |
380 | 508 |
381 proxy->Start(&callback_); | 509 proxy->Start(&callback_); |
382 | 510 |
383 Mock::VerifyAndClear(&callback_); | 511 Mock::VerifyAndClear(&callback_); |
384 | 512 |
385 proxy->Close(); | 513 proxy->Close(); |
386 } | 514 } |
387 | 515 |
| 516 // Start() method failed. |
| 517 TEST_F(AudioOutputProxyTest, StartFailed_Mixer) { |
| 518 MockAudioOutputStream stream; |
| 519 |
| 520 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 521 .WillOnce(Return(&stream)); |
| 522 EXPECT_CALL(stream, Open()) |
| 523 .WillOnce(Return(true)); |
| 524 EXPECT_CALL(stream, Close()) |
| 525 .Times(1); |
| 526 EXPECT_CALL(stream, Start(_)) |
| 527 .Times(1); |
| 528 EXPECT_CALL(stream, SetVolume(_)) |
| 529 .Times(1); |
| 530 EXPECT_CALL(stream, Stop()) |
| 531 .Times(1); |
| 532 |
| 533 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_); |
| 534 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_); |
| 535 EXPECT_TRUE(proxy1->Open()); |
| 536 EXPECT_TRUE(proxy2->Open()); |
| 537 proxy1->Start(&callback_); |
| 538 proxy1->Stop(); |
| 539 proxy1->Close(); |
| 540 WaitForCloseTimer(kTestCloseDelayMs); |
| 541 |
| 542 // Verify expectation before continueing. |
| 543 Mock::VerifyAndClear(&stream); |
| 544 |
| 545 // |stream| is closed at this point. Start() should reopen it again. |
| 546 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 547 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL))); |
| 548 |
| 549 EXPECT_CALL(callback_, OnError(_, _)) |
| 550 .Times(1); |
| 551 |
| 552 proxy2->Start(&callback_); |
| 553 |
| 554 Mock::VerifyAndClear(&callback_); |
| 555 |
| 556 proxy2->Close(); |
| 557 WaitForCloseTimer(kTestCloseDelayMs); |
| 558 } |
| 559 |
388 } // namespace media | 560 } // namespace media |
OLD | NEW |