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

Side by Side Diff: media/audio/audio_output_proxy_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698