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

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 // Methods that do actual tests.
106 void OpenAndClose(AudioOutputDispatcher* dispatcher) {
107 MockAudioOutputStream stream;
108
109 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
110 .WillOnce(Return(&stream));
111 EXPECT_CALL(stream, Open())
112 .WillOnce(Return(true));
113 EXPECT_CALL(stream, Close())
114 .Times(1);
115
116 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher);
117 EXPECT_TRUE(proxy->Open());
118 proxy->Close();
119
120 // Wait for the close timer to fire.
121 base::PlatformThread::Sleep(
122 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
123 message_loop_.RunAllPending();
124 }
125
126 // Create a stream, and then calls Start() and Stop().
127 void StartAndStop(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, Start(_))
135 .Times(1);
136 EXPECT_CALL(stream, SetVolume(_))
137 .Times(1);
138 EXPECT_CALL(stream, Stop())
139 .Times(1);
140 EXPECT_CALL(stream, Close())
141 .Times(1);
142
143 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher);
144 EXPECT_TRUE(proxy->Open());
145
146 proxy->Start(&callback_);
147 proxy->Stop();
148
149 proxy->Close();
150
151 // Wait for the close timer to fire.
152 base::PlatformThread::Sleep(
153 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
154 message_loop_.RunAllPending();
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 StreamStopped() to post StopStreamTask().
181 base::PlatformThread::Sleep(pause_delay_ * 2);
182 message_loop_.RunAllPending();
183
184 // Wait for the close timer to fire.
185 base::PlatformThread::Sleep(
186 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
187 message_loop_.RunAllPending();
188
189 // Verify expectation before calling Close().
190 Mock::VerifyAndClear(&stream);
191
192 proxy->Close();
193 }
194
195 // Create two streams, but don't start them. Only one device must be open.
196 void TwoStreams(AudioOutputDispatcher* dispatcher) {
197 MockAudioOutputStream stream;
198
199 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
200 .WillOnce(Return(&stream));
201 EXPECT_CALL(stream, Open())
202 .WillOnce(Return(true));
203 EXPECT_CALL(stream, Close())
204 .Times(1);
205
206 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher);
207 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher);
208 EXPECT_TRUE(proxy1->Open());
209 EXPECT_TRUE(proxy2->Open());
210 proxy1->Close();
211 proxy2->Close();
212
213 // Wait for the close timer to fire.
214 base::PlatformThread::Sleep(
215 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
216 message_loop_.RunAllPending();
217 }
218
219 // Open() method failed.
220 void OpenFailed(AudioOutputDispatcher* dispatcher) {
221 MockAudioOutputStream stream;
222
223 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
224 .WillOnce(Return(&stream));
225 EXPECT_CALL(stream, Open())
226 .WillOnce(Return(false));
227 EXPECT_CALL(stream, Close())
228 .Times(1);
229
230 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher);
231 EXPECT_FALSE(proxy->Open());
232 proxy->Close();
233
234 // Wait for the close timer to fire.
235 base::PlatformThread::Sleep(
236 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
237 message_loop_.RunAllPending();
238 }
239
99 MessageLoop message_loop_; 240 MessageLoop message_loop_;
100 scoped_refptr<AudioOutputDispatcher> dispatcher_; 241 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_;
242 scoped_refptr<AudioOutputMixer> mixer_;
101 base::TimeDelta pause_delay_; 243 base::TimeDelta pause_delay_;
102 MockAudioManager manager_; 244 MockAudioManager manager_;
103 MockAudioSourceCallback callback_; 245 MockAudioSourceCallback callback_;
104 }; 246 };
105 247
106 TEST_F(AudioOutputProxyTest, CreateAndClose) { 248 TEST_F(AudioOutputProxyTest, CreateAndClose) {
107 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_);
108 proxy->Close(); 255 proxy->Close();
109 } 256 }
110 257
111 TEST_F(AudioOutputProxyTest, OpenAndClose) { 258 TEST_F(AudioOutputProxyTest, OpenAndClose) {
112 MockAudioOutputStream stream; 259 OpenAndClose(dispatcher_impl_);
260 }
113 261
114 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 262 TEST_F(AudioOutputProxyTest, OpenAndClose_Mixer) {
115 .WillOnce(Return(&stream)); 263 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 } 264 }
125 265
126 // Create a stream, and verify that it is closed after kTestCloseDelayMs. 266 // Create a stream, and verify that it is closed after kTestCloseDelayMs.
127 // if it doesn't start playing. 267 // if it doesn't start playing.
128 TEST_F(AudioOutputProxyTest, CreateAndWait) { 268 TEST_F(AudioOutputProxyTest, CreateAndWait) {
129 MockAudioOutputStream stream; 269 MockAudioOutputStream stream;
130 270
131 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 271 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
132 .WillOnce(Return(&stream)); 272 .WillOnce(Return(&stream));
133 EXPECT_CALL(stream, Open()) 273 EXPECT_CALL(stream, Open())
134 .WillOnce(Return(true)); 274 .WillOnce(Return(true));
135 EXPECT_CALL(stream, Close()) 275 EXPECT_CALL(stream, Close())
136 .Times(1); 276 .Times(1);
137 277
138 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); 278 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
139 EXPECT_TRUE(proxy->Open()); 279 EXPECT_TRUE(proxy->Open());
140 280
141 // Simulate a delay. 281 // Simulate a delay.
142 base::PlatformThread::Sleep( 282 base::PlatformThread::Sleep(
143 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); 283 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
144 message_loop_.RunAllPending(); 284 message_loop_.RunAllPending();
145 285
146 // Verify expectation before calling Close(). 286 // Verify expectation before calling Close().
147 Mock::VerifyAndClear(&stream); 287 Mock::VerifyAndClear(&stream);
148 288
149 proxy->Close(); 289 proxy->Close();
150 } 290 }
151 291
152 // Create a stream, and then calls Start() and Stop().
153 TEST_F(AudioOutputProxyTest, StartAndStop) { 292 TEST_F(AudioOutputProxyTest, StartAndStop) {
154 MockAudioOutputStream stream; 293 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 } 294 }
177 295
178 // Verify that the stream is closed after Stop is called. 296 TEST_F(AudioOutputProxyTest, StartAndStop_Mixer) {
179 TEST_F(AudioOutputProxyTest, CloseAfterStop) { 297 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 } 298 }
215 299
216 // 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
217 TEST_F(AudioOutputProxyTest, TwoStreams) { 308 TEST_F(AudioOutputProxyTest, TwoStreams) {
218 MockAudioOutputStream stream; 309 TwoStreams(dispatcher_impl_);
310 }
219 311
220 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 312 TEST_F(AudioOutputProxyTest, TwoStreams_Mixer) {
221 .WillOnce(Return(&stream)); 313 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 } 314 }
234 315
235 // Two streams: verify that second stream is allocated when the first 316 // Two streams: verify that second stream is allocated when the first
236 // starts playing. 317 // starts playing.
237 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) { 318 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) {
238 MockAudioOutputStream stream1; 319 MockAudioOutputStream stream1;
239 MockAudioOutputStream stream2; 320 MockAudioOutputStream stream2;
240 321
241 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); 322 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
242 323
(...skipping 10 matching lines...) Expand all
253 EXPECT_CALL(stream1, Stop()) 334 EXPECT_CALL(stream1, Stop())
254 .Times(1); 335 .Times(1);
255 EXPECT_CALL(stream1, Close()) 336 EXPECT_CALL(stream1, Close())
256 .Times(1); 337 .Times(1);
257 338
258 EXPECT_CALL(stream2, Open()) 339 EXPECT_CALL(stream2, Open())
259 .WillOnce(Return(true)); 340 .WillOnce(Return(true));
260 EXPECT_CALL(stream2, Close()) 341 EXPECT_CALL(stream2, Close())
261 .Times(1); 342 .Times(1);
262 343
263 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_); 344 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_impl_);
264 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_); 345 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_impl_);
265 EXPECT_TRUE(proxy1->Open()); 346 EXPECT_TRUE(proxy1->Open());
266 EXPECT_TRUE(proxy2->Open()); 347 EXPECT_TRUE(proxy2->Open());
267 348
268 proxy1->Start(&callback_); 349 proxy1->Start(&callback_);
269 message_loop_.RunAllPending(); 350 message_loop_.RunAllPending();
270 proxy1->Stop(); 351 proxy1->Stop();
271 352
272 proxy1->Close(); 353 proxy1->Close();
273 proxy2->Close(); 354 proxy2->Close();
274 } 355 }
275 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
388 // Wait for the close timer to fire.
389 base::PlatformThread::Sleep(
390 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
391 message_loop_.RunAllPending();
392 }
393
276 // Two streams, both are playing. Dispatcher should not open a third stream. 394 // Two streams, both are playing. Dispatcher should not open a third stream.
277 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { 395 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) {
278 MockAudioOutputStream stream1; 396 MockAudioOutputStream stream1;
279 MockAudioOutputStream stream2; 397 MockAudioOutputStream stream2;
280 398
281 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); 399 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
282 400
283 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 401 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
284 .WillOnce(Return(&stream1)) 402 .WillOnce(Return(&stream1))
285 .WillOnce(Return(&stream2)); 403 .WillOnce(Return(&stream2));
(...skipping 13 matching lines...) Expand all
299 .WillOnce(Return(true)); 417 .WillOnce(Return(true));
300 EXPECT_CALL(stream2, Start(_)) 418 EXPECT_CALL(stream2, Start(_))
301 .Times(1); 419 .Times(1);
302 EXPECT_CALL(stream2, SetVolume(_)) 420 EXPECT_CALL(stream2, SetVolume(_))
303 .Times(1); 421 .Times(1);
304 EXPECT_CALL(stream2, Stop()) 422 EXPECT_CALL(stream2, Stop())
305 .Times(1); 423 .Times(1);
306 EXPECT_CALL(stream2, Close()) 424 EXPECT_CALL(stream2, Close())
307 .Times(1); 425 .Times(1);
308 426
309 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_); 427 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_impl_);
310 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_); 428 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_impl_);
311 EXPECT_TRUE(proxy1->Open()); 429 EXPECT_TRUE(proxy1->Open());
312 EXPECT_TRUE(proxy2->Open()); 430 EXPECT_TRUE(proxy2->Open());
313 431
314 proxy1->Start(&callback_); 432 proxy1->Start(&callback_);
315 proxy2->Start(&callback_); 433 proxy2->Start(&callback_);
316 proxy1->Stop(); 434 proxy1->Stop();
317 proxy2->Stop(); 435 proxy2->Stop();
318 436
319 proxy1->Close(); 437 proxy1->Close();
320 proxy2->Close(); 438 proxy2->Close();
321 } 439 }
322 440
323 // Open() method failed. 441 // Two streams, both are playing. Still have to use single device.
324 TEST_F(AudioOutputProxyTest, OpenFailed) { 442 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) {
325 MockAudioOutputStream stream; 443 MockAudioOutputStream stream;
326 444
445 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
446
327 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 447 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
328 .WillOnce(Return(&stream)); 448 .WillOnce(Return(&stream));
449
329 EXPECT_CALL(stream, Open()) 450 EXPECT_CALL(stream, Open())
330 .WillOnce(Return(false)); 451 .WillOnce(Return(true));
452 EXPECT_CALL(stream, Start(_))
453 .Times(1);
454 EXPECT_CALL(stream, SetVolume(_))
455 .Times(1);
456 EXPECT_CALL(stream, Stop())
457 .Times(1);
331 EXPECT_CALL(stream, Close()) 458 EXPECT_CALL(stream, Close())
332 .Times(1); 459 .Times(1);
333 460
334 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); 461 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_);
335 EXPECT_FALSE(proxy->Open()); 462 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_);
336 proxy->Close(); 463 EXPECT_TRUE(proxy1->Open());
464 EXPECT_TRUE(proxy2->Open());
465
466 proxy1->Start(&callback_);
467 proxy2->Start(&callback_);
468 proxy1->Stop();
469 proxy2->Stop();
470
471 proxy1->Close();
472 proxy2->Close();
473
474 // Wait for the close timer to fire.
475 base::PlatformThread::Sleep(
476 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
477 message_loop_.RunAllPending();
478 }
479
480 TEST_F(AudioOutputProxyTest, OpenFailed) {
481 OpenFailed(dispatcher_impl_);
482 }
483
484 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) {
485 OpenFailed(mixer_);
337 } 486 }
338 487
339 // Start() method failed. 488 // Start() method failed.
340 TEST_F(AudioOutputProxyTest, StartFailed) { 489 TEST_F(AudioOutputProxyTest, StartFailed) {
341 MockAudioOutputStream stream; 490 MockAudioOutputStream stream;
342 491
343 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 492 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
344 .WillOnce(Return(&stream)); 493 .WillOnce(Return(&stream));
345 EXPECT_CALL(stream, Open()) 494 EXPECT_CALL(stream, Open())
346 .WillOnce(Return(true)); 495 .WillOnce(Return(true));
347 EXPECT_CALL(stream, Close()) 496 EXPECT_CALL(stream, Close())
348 .Times(1); 497 .Times(1);
349 498
350 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); 499 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
351 EXPECT_TRUE(proxy->Open()); 500 EXPECT_TRUE(proxy->Open());
352 501
353 // Simulate a delay. 502 // Simulate a delay.
354 base::PlatformThread::Sleep( 503 base::PlatformThread::Sleep(
355 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); 504 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
356 message_loop_.RunAllPending(); 505 message_loop_.RunAllPending();
357 506
358 // Verify expectation before calling Close(). 507 // Verify expectation before calling Close().
359 Mock::VerifyAndClear(&stream); 508 Mock::VerifyAndClear(&stream);
360 509
361 // |stream| is closed at this point. Start() should reopen it again. 510 // |stream| is closed at this point. Start() should reopen it again.
362 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 511 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
363 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL))); 512 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL)));
364 513
365 EXPECT_CALL(callback_, OnError(_, _)) 514 EXPECT_CALL(callback_, OnError(_, _))
366 .Times(1); 515 .Times(1);
367 516
368 proxy->Start(&callback_); 517 proxy->Start(&callback_);
369 518
370 Mock::VerifyAndClear(&callback_); 519 Mock::VerifyAndClear(&callback_);
371 520
372 proxy->Close(); 521 proxy->Close();
373 } 522 }
523
524 // Start() method failed.
525 TEST_F(AudioOutputProxyTest, StartFailed_Mixer) {
526 MockAudioOutputStream stream;
527
528 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
529 .WillOnce(Return(&stream));
530 EXPECT_CALL(stream, Open())
531 .WillOnce(Return(true));
532 EXPECT_CALL(stream, Close())
533 .Times(1);
534 EXPECT_CALL(stream, Start(_))
535 .Times(1);
536 EXPECT_CALL(stream, SetVolume(_))
537 .Times(1);
538 EXPECT_CALL(stream, Stop())
539 .Times(1);
540
541 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_);
542 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_);
543 EXPECT_TRUE(proxy1->Open());
544 EXPECT_TRUE(proxy2->Open());
545 proxy1->Start(&callback_);
546 proxy1->Stop();
547 proxy1->Close();
548
549 // Wait for the close timer to fire.
550 base::PlatformThread::Sleep(
551 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
552 message_loop_.RunAllPending();
553
554 // Verify expectation before continueing.
555 Mock::VerifyAndClear(&stream);
556
557 // |stream| is closed at this point. Start() should reopen it again.
558 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
559 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL)));
560
561 EXPECT_CALL(callback_, OnError(_, _))
562 .Times(1);
563
564 proxy2->Start(&callback_);
565
566 Mock::VerifyAndClear(&callback_);
567
568 proxy2->Close();
569
570 // Wait for the close timer to fire.
571 base::PlatformThread::Sleep(
572 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
573 message_loop_.RunAllPending();
574 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698