| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/threading/platform_thread.h" | 6 #include "base/threading/platform_thread.h" |
| 7 #include "media/audio/audio_output_dispatcher.h" | 7 #include "media/audio/audio_output_dispatcher.h" |
| 8 #include "media/audio/audio_output_proxy.h" | 8 #include "media/audio/audio_output_proxy.h" |
| 9 #include "media/audio/audio_manager.h" | 9 #include "media/audio/audio_manager.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 // This is necessary to free all proxy objects that have been | 79 // This is necessary to free all proxy objects that have been |
| 80 // closed by the test. | 80 // closed by the test. |
| 81 message_loop_.RunAllPending(); | 81 message_loop_.RunAllPending(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void InitDispatcher(int close_delay_ms) { | 84 void InitDispatcher(int close_delay_ms) { |
| 85 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 85 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 86 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); | 86 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); |
| 87 dispatcher_ = new AudioOutputDispatcher(&manager_, params, close_delay_ms); | 87 dispatcher_ = new AudioOutputDispatcher(&manager_, params, close_delay_ms); |
| 88 |
| 89 // Necessary to know how long the dispatcher will wait before posting |
| 90 // StopStreamTask. |
| 91 pause_delay_milliseconds_ = dispatcher_->pause_delay_milliseconds_; |
| 88 } | 92 } |
| 89 | 93 |
| 90 MessageLoop message_loop_; | 94 MessageLoop message_loop_; |
| 91 scoped_refptr<AudioOutputDispatcher> dispatcher_; | 95 scoped_refptr<AudioOutputDispatcher> dispatcher_; |
| 96 int64 pause_delay_milliseconds_; |
| 92 MockAudioManager manager_; | 97 MockAudioManager manager_; |
| 93 MockAudioSourceCallback callback_; | 98 MockAudioSourceCallback callback_; |
| 94 }; | 99 }; |
| 95 | 100 |
| 96 TEST_F(AudioOutputProxyTest, CreateAndClose) { | 101 TEST_F(AudioOutputProxyTest, CreateAndClose) { |
| 97 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); | 102 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); |
| 98 proxy->Close(); | 103 proxy->Close(); |
| 99 } | 104 } |
| 100 | 105 |
| 101 TEST_F(AudioOutputProxyTest, OpenAndClose) { | 106 TEST_F(AudioOutputProxyTest, OpenAndClose) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 .Times(1); | 185 .Times(1); |
| 181 EXPECT_CALL(stream, Close()) | 186 EXPECT_CALL(stream, Close()) |
| 182 .Times(1); | 187 .Times(1); |
| 183 | 188 |
| 184 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); | 189 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); |
| 185 EXPECT_TRUE(proxy->Open()); | 190 EXPECT_TRUE(proxy->Open()); |
| 186 | 191 |
| 187 proxy->Start(&callback_); | 192 proxy->Start(&callback_); |
| 188 proxy->Stop(); | 193 proxy->Stop(); |
| 189 | 194 |
| 190 // Simulate a delay. | 195 // Wait for StreamStopped() to post StopStreamTask(). |
| 196 base::PlatformThread::Sleep(pause_delay_milliseconds_ * 2); |
| 191 message_loop_.RunAllPending(); | 197 message_loop_.RunAllPending(); |
| 192 base::PlatformThread::Sleep(kTestCloseDelayMs * 10); | 198 |
| 199 // Wait for the close timer to fire. |
| 200 base::PlatformThread::Sleep(kTestCloseDelayMs * 2); |
| 193 message_loop_.RunAllPending(); | 201 message_loop_.RunAllPending(); |
| 194 | 202 |
| 195 // Verify expectation before calling Close(). | 203 // Verify expectation before calling Close(). |
| 196 Mock::VerifyAndClear(&stream); | 204 Mock::VerifyAndClear(&stream); |
| 197 | 205 |
| 198 proxy->Close(); | 206 proxy->Close(); |
| 199 } | 207 } |
| 200 | 208 |
| 201 // Create two streams, but don't start them. Only one device must be open. | 209 // Create two streams, but don't start them. Only one device must be open. |
| 202 TEST_F(AudioOutputProxyTest, TwoStreams) { | 210 TEST_F(AudioOutputProxyTest, TwoStreams) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 .WillOnce(Return(&stream)); | 337 .WillOnce(Return(&stream)); |
| 330 EXPECT_CALL(stream, Open()) | 338 EXPECT_CALL(stream, Open()) |
| 331 .WillOnce(Return(true)); | 339 .WillOnce(Return(true)); |
| 332 EXPECT_CALL(stream, Close()) | 340 EXPECT_CALL(stream, Close()) |
| 333 .Times(1); | 341 .Times(1); |
| 334 | 342 |
| 335 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); | 343 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_); |
| 336 EXPECT_TRUE(proxy->Open()); | 344 EXPECT_TRUE(proxy->Open()); |
| 337 | 345 |
| 338 // Simulate a delay. | 346 // Simulate a delay. |
| 339 base::PlatformThread::Sleep(kTestCloseDelayMs); | 347 base::PlatformThread::Sleep(kTestCloseDelayMs * 2); |
| 340 message_loop_.RunAllPending(); | 348 message_loop_.RunAllPending(); |
| 341 | 349 |
| 342 // Verify expectation before calling Close(). | 350 // Verify expectation before calling Close(). |
| 343 Mock::VerifyAndClear(&stream); | 351 Mock::VerifyAndClear(&stream); |
| 344 | 352 |
| 345 // |stream| is closed at this point. Start() should reopen it again. | 353 // |stream| is closed at this point. Start() should reopen it again. |
| 346 EXPECT_CALL(manager_, MakeAudioOutputStream(_)) | 354 EXPECT_CALL(manager_, MakeAudioOutputStream(_)) |
| 347 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL))); | 355 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL))); |
| 348 | 356 |
| 349 EXPECT_CALL(callback_, OnError(_, _)) | 357 EXPECT_CALL(callback_, OnError(_, _)) |
| 350 .Times(1); | 358 .Times(1); |
| 351 | 359 |
| 352 proxy->Start(&callback_); | 360 proxy->Start(&callback_); |
| 353 | 361 |
| 354 Mock::VerifyAndClear(&callback_); | 362 Mock::VerifyAndClear(&callback_); |
| 355 | 363 |
| 356 proxy->Close(); | 364 proxy->Close(); |
| 357 } | 365 } |
| OLD | NEW |