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

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

Issue 11359193: media: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix rebase error Created 8 years, 1 month 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
« no previous file with comments | « media/audio/audio_output_device_unittest.cc ('k') | media/base/pipeline_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "media/audio/audio_output_dispatcher_impl.h" 10 #include "media/audio/audio_output_dispatcher_impl.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 .WillRepeatedly(Return(message_loop_.message_loop_proxy())); 150 .WillRepeatedly(Return(message_loop_.message_loop_proxy()));
151 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); 151 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
152 } 152 }
153 153
154 virtual void TearDown() { 154 virtual void TearDown() {
155 // All paused proxies should have been closed at this point. 155 // All paused proxies should have been closed at this point.
156 EXPECT_EQ(0u, dispatcher_impl_->paused_proxies_); 156 EXPECT_EQ(0u, dispatcher_impl_->paused_proxies_);
157 157
158 // This is necessary to free all proxy objects that have been 158 // This is necessary to free all proxy objects that have been
159 // closed by the test. 159 // closed by the test.
160 message_loop_.RunAllPending(); 160 message_loop_.RunUntilIdle();
161 } 161 }
162 162
163 virtual void InitDispatcher(base::TimeDelta close_delay) { 163 virtual void InitDispatcher(base::TimeDelta close_delay) {
164 // Use a low sample rate and large buffer size when testing otherwise the 164 // Use a low sample rate and large buffer size when testing otherwise the
165 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., 165 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e.,
166 // RunAllPending() will never terminate. 166 // RunUntilIdle() will never terminate.
167 params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 167 params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
168 CHANNEL_LAYOUT_STEREO, 8000, 16, 2048); 168 CHANNEL_LAYOUT_STEREO, 8000, 16, 2048);
169 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), 169 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(),
170 params_, 170 params_,
171 close_delay); 171 close_delay);
172 #if defined(ENABLE_AUDIO_MIXER) 172 #if defined(ENABLE_AUDIO_MIXER)
173 mixer_ = new AudioOutputMixer(&manager(), params_, close_delay); 173 mixer_ = new AudioOutputMixer(&manager(), params_, close_delay);
174 #endif 174 #endif
175 175
176 // Necessary to know how long the dispatcher will wait before posting 176 // Necessary to know how long the dispatcher will wait before posting
177 // StopStreamTask. 177 // StopStreamTask.
178 pause_delay_ = dispatcher_impl_->pause_delay_; 178 pause_delay_ = dispatcher_impl_->pause_delay_;
179 } 179 }
180 180
181 virtual void OnStart() {} 181 virtual void OnStart() {}
182 182
183 MockAudioManager& manager() { 183 MockAudioManager& manager() {
184 return manager_; 184 return manager_;
185 } 185 }
186 186
187 // Wait for the close timer to fire. 187 // Wait for the close timer to fire.
188 void WaitForCloseTimer(const int timer_delay_ms) { 188 void WaitForCloseTimer(const int timer_delay_ms) {
189 message_loop_.RunAllPending(); // OpenTask() may reset the timer. 189 message_loop_.RunUntilIdle(); // OpenTask() may reset the timer.
190 base::PlatformThread::Sleep( 190 base::PlatformThread::Sleep(
191 base::TimeDelta::FromMilliseconds(timer_delay_ms) * 2); 191 base::TimeDelta::FromMilliseconds(timer_delay_ms) * 2);
192 message_loop_.RunAllPending(); 192 message_loop_.RunUntilIdle();
193 } 193 }
194 194
195 // Methods that do actual tests. 195 // Methods that do actual tests.
196 void OpenAndClose(AudioOutputDispatcher* dispatcher) { 196 void OpenAndClose(AudioOutputDispatcher* dispatcher) {
197 MockAudioOutputStream stream(&manager_, params_); 197 MockAudioOutputStream stream(&manager_, params_);
198 198
199 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 199 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
200 .WillOnce(Return(&stream)); 200 .WillOnce(Return(&stream));
201 EXPECT_CALL(stream, Open()) 201 EXPECT_CALL(stream, Open())
202 .WillOnce(Return(true)); 202 .WillOnce(Return(true));
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 .WillOnce(Return(true)); 317 .WillOnce(Return(true));
318 EXPECT_CALL(stream, Close()) 318 EXPECT_CALL(stream, Close())
319 .Times(1); 319 .Times(1);
320 320
321 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); 321 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher);
322 EXPECT_TRUE(proxy->Open()); 322 EXPECT_TRUE(proxy->Open());
323 323
324 // Simulate a delay. 324 // Simulate a delay.
325 base::PlatformThread::Sleep( 325 base::PlatformThread::Sleep(
326 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); 326 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
327 message_loop_.RunAllPending(); 327 message_loop_.RunUntilIdle();
328 328
329 // Verify expectation before calling Close(). 329 // Verify expectation before calling Close().
330 Mock::VerifyAndClear(&stream); 330 Mock::VerifyAndClear(&stream);
331 331
332 proxy->Close(); 332 proxy->Close();
333 EXPECT_FALSE(stream.stop_called()); 333 EXPECT_FALSE(stream.stop_called());
334 EXPECT_FALSE(stream.start_called()); 334 EXPECT_FALSE(stream.start_called());
335 } 335 }
336 336
337 void TwoStreams_OnePlaying(AudioOutputDispatcher* dispatcher) { 337 void TwoStreams_OnePlaying(AudioOutputDispatcher* dispatcher) {
(...skipping 15 matching lines...) Expand all
353 .WillOnce(Return(true)); 353 .WillOnce(Return(true));
354 EXPECT_CALL(stream2, Close()) 354 EXPECT_CALL(stream2, Close())
355 .Times(1); 355 .Times(1);
356 356
357 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); 357 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher);
358 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); 358 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher);
359 EXPECT_TRUE(proxy1->Open()); 359 EXPECT_TRUE(proxy1->Open());
360 EXPECT_TRUE(proxy2->Open()); 360 EXPECT_TRUE(proxy2->Open());
361 361
362 proxy1->Start(&callback_); 362 proxy1->Start(&callback_);
363 message_loop_.RunAllPending(); 363 message_loop_.RunUntilIdle();
364 OnStart(); 364 OnStart();
365 proxy1->Stop(); 365 proxy1->Stop();
366 366
367 proxy1->Close(); 367 proxy1->Close();
368 proxy2->Close(); 368 proxy2->Close();
369 EXPECT_TRUE(stream1.stop_called()); 369 EXPECT_TRUE(stream1.stop_called());
370 EXPECT_TRUE(stream1.start_called()); 370 EXPECT_TRUE(stream1.start_called());
371 EXPECT_FALSE(stream2.stop_called()); 371 EXPECT_FALSE(stream2.stop_called());
372 EXPECT_FALSE(stream2.start_called()); 372 EXPECT_FALSE(stream2.start_called());
373 } 373 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 .WillOnce(Return(true)); 422 .WillOnce(Return(true));
423 EXPECT_CALL(stream, Close()) 423 EXPECT_CALL(stream, Close())
424 .Times(1); 424 .Times(1);
425 425
426 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); 426 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
427 EXPECT_TRUE(proxy->Open()); 427 EXPECT_TRUE(proxy->Open());
428 428
429 // Simulate a delay. 429 // Simulate a delay.
430 base::PlatformThread::Sleep( 430 base::PlatformThread::Sleep(
431 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); 431 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
432 message_loop_.RunAllPending(); 432 message_loop_.RunUntilIdle();
433 433
434 // Verify expectation before calling Close(). 434 // Verify expectation before calling Close().
435 Mock::VerifyAndClear(&stream); 435 Mock::VerifyAndClear(&stream);
436 436
437 // |stream| is closed at this point. Start() should reopen it again. 437 // |stream| is closed at this point. Start() should reopen it again.
438 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 438 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
439 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL))); 439 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL)));
440 440
441 EXPECT_CALL(callback_, OnError(_, _)) 441 EXPECT_CALL(callback_, OnError(_, _))
442 .Times(1); 442 .Times(1);
(...skipping 19 matching lines...) Expand all
462 class AudioOutputResamplerTest : public AudioOutputProxyTest { 462 class AudioOutputResamplerTest : public AudioOutputProxyTest {
463 public: 463 public:
464 virtual void TearDown() { 464 virtual void TearDown() {
465 AudioOutputProxyTest::TearDown(); 465 AudioOutputProxyTest::TearDown();
466 } 466 }
467 467
468 virtual void InitDispatcher(base::TimeDelta close_delay) { 468 virtual void InitDispatcher(base::TimeDelta close_delay) {
469 AudioOutputProxyTest::InitDispatcher(close_delay); 469 AudioOutputProxyTest::InitDispatcher(close_delay);
470 // Use a low sample rate and large buffer size when testing otherwise the 470 // Use a low sample rate and large buffer size when testing otherwise the
471 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., 471 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e.,
472 // RunAllPending() will never terminate. 472 // RunUntilIdle() will never terminate.
473 resampler_params_ = AudioParameters( 473 resampler_params_ = AudioParameters(
474 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, 474 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
475 16000, 16, 1024); 475 16000, 16, 1024);
476 resampler_ = new AudioOutputResampler( 476 resampler_ = new AudioOutputResampler(
477 &manager(), params_, resampler_params_, close_delay); 477 &manager(), params_, resampler_params_, close_delay);
478 } 478 }
479 479
480 virtual void OnStart() { 480 virtual void OnStart() {
481 // Let start run for a bit. 481 // Let start run for a bit.
482 message_loop_.RunAllPending(); 482 message_loop_.RunUntilIdle();
483 base::PlatformThread::Sleep( 483 base::PlatformThread::Sleep(
484 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); 484 base::TimeDelta::FromMilliseconds(kStartRunTimeMs));
485 } 485 }
486 486
487 protected: 487 protected:
488 AudioParameters resampler_params_; 488 AudioParameters resampler_params_;
489 scoped_refptr<AudioOutputResampler> resampler_; 489 scoped_refptr<AudioOutputResampler> resampler_;
490 }; 490 };
491 491
492 TEST_F(AudioOutputProxyTest, CreateAndClose) { 492 TEST_F(AudioOutputProxyTest, CreateAndClose) {
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 WaitForCloseTimer(kTestCloseDelayMs); 891 WaitForCloseTimer(kTestCloseDelayMs);
892 EXPECT_TRUE(stream1.stop_called()); 892 EXPECT_TRUE(stream1.stop_called());
893 EXPECT_TRUE(stream1.start_called()); 893 EXPECT_TRUE(stream1.start_called());
894 EXPECT_TRUE(stream2.stop_called()); 894 EXPECT_TRUE(stream2.stop_called());
895 EXPECT_TRUE(stream2.start_called()); 895 EXPECT_TRUE(stream2.start_called());
896 EXPECT_FALSE(stream3.stop_called()); 896 EXPECT_FALSE(stream3.stop_called());
897 EXPECT_FALSE(stream3.start_called()); 897 EXPECT_FALSE(stream3.start_called());
898 } 898 }
899 899
900 } // namespace media 900 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_device_unittest.cc ('k') | media/base/pipeline_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698