| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/environment.h" | 6 #include "base/environment.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/sync_socket.h" | 10 #include "base/sync_socket.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(MockAudioMirroringManager); | 51 DISALLOW_COPY_AND_ASSIGN(MockAudioMirroringManager); |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 class MockAudioRendererHost : public AudioRendererHost { | 54 class MockAudioRendererHost : public AudioRendererHost { |
| 55 public: | 55 public: |
| 56 explicit MockAudioRendererHost( | 56 explicit MockAudioRendererHost( |
| 57 media::AudioManager* audio_manager, | 57 media::AudioManager* audio_manager, |
| 58 AudioMirroringManager* mirroring_manager, | 58 AudioMirroringManager* mirroring_manager, |
| 59 MediaObserver* media_observer) | 59 MediaInternals* media_internals) |
| 60 : AudioRendererHost( | 60 : AudioRendererHost(kRenderProcessId, |
| 61 kRenderProcessId, audio_manager, mirroring_manager, media_observer), | 61 audio_manager, |
| 62 mirroring_manager, |
| 63 media_internals), |
| 62 shared_memory_length_(0) { | 64 shared_memory_length_(0) { |
| 63 } | 65 } |
| 64 | 66 |
| 65 // A list of mock methods. | 67 // A list of mock methods. |
| 66 MOCK_METHOD2(OnStreamCreated, | 68 MOCK_METHOD2(OnStreamCreated, |
| 67 void(int stream_id, int length)); | 69 void(int stream_id, int length)); |
| 68 MOCK_METHOD1(OnStreamPlaying, void(int stream_id)); | 70 MOCK_METHOD1(OnStreamPlaying, void(int stream_id)); |
| 69 MOCK_METHOD1(OnStreamPaused, void(int stream_id)); | 71 MOCK_METHOD1(OnStreamPaused, void(int stream_id)); |
| 70 MOCK_METHOD1(OnStreamError, void(int stream_id)); | 72 MOCK_METHOD1(OnStreamError, void(int stream_id)); |
| 71 MOCK_METHOD2(OnStreamVolume, void(int stream_id, double volume)); | 73 MOCK_METHOD2(OnStreamVolume, void(int stream_id, double volume)); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 virtual void SetUp() { | 164 virtual void SetUp() { |
| 163 // Create a message loop so AudioRendererHost can use it. | 165 // Create a message loop so AudioRendererHost can use it. |
| 164 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 166 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
| 165 | 167 |
| 166 // Claim to be on both the UI and IO threads to pass all the DCHECKS. | 168 // Claim to be on both the UI and IO threads to pass all the DCHECKS. |
| 167 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, | 169 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
| 168 message_loop_.get())); | 170 message_loop_.get())); |
| 169 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, | 171 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, |
| 170 message_loop_.get())); | 172 message_loop_.get())); |
| 171 audio_manager_.reset(media::AudioManager::Create()); | 173 audio_manager_.reset(media::AudioManager::Create()); |
| 172 observer_.reset(new MockMediaObserver()); | 174 observer_.reset(new MockMediaInternals()); |
| 173 host_ = new MockAudioRendererHost( | 175 host_ = new MockAudioRendererHost( |
| 174 audio_manager_.get(), &mirroring_manager_, observer_.get()); | 176 audio_manager_.get(), &mirroring_manager_, observer_.get()); |
| 175 | 177 |
| 176 // Simulate IPC channel connected. | 178 // Simulate IPC channel connected. |
| 177 host_->OnChannelConnected(base::GetCurrentProcId()); | 179 host_->OnChannelConnected(base::GetCurrentProcId()); |
| 178 } | 180 } |
| 179 | 181 |
| 180 virtual void TearDown() { | 182 virtual void TearDown() { |
| 181 // Simulate closing the IPC channel. | 183 // Simulate closing the IPC channel. |
| 182 host_->OnChannelClosing(); | 184 host_->OnChannelClosing(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // Don't use scoped_refptr to addref the media::AudioManager when posting | 314 // Don't use scoped_refptr to addref the media::AudioManager when posting |
| 313 // to the thread that itself owns. | 315 // to the thread that itself owns. |
| 314 message_loop_->PostTask( | 316 message_loop_->PostTask( |
| 315 FROM_HERE, base::Bind(&PostQuitOnAudioThread, | 317 FROM_HERE, base::Bind(&PostQuitOnAudioThread, |
| 316 base::Unretained(audio_manager_.get()), | 318 base::Unretained(audio_manager_.get()), |
| 317 message_loop_.get())); | 319 message_loop_.get())); |
| 318 message_loop_->Run(); | 320 message_loop_->Run(); |
| 319 } | 321 } |
| 320 | 322 |
| 321 private: | 323 private: |
| 322 scoped_ptr<MockMediaObserver> observer_; | 324 scoped_ptr<MockMediaInternals> observer_; |
| 323 MockAudioMirroringManager mirroring_manager_; | 325 MockAudioMirroringManager mirroring_manager_; |
| 324 scoped_refptr<MockAudioRendererHost> host_; | 326 scoped_refptr<MockAudioRendererHost> host_; |
| 325 scoped_ptr<MessageLoop> message_loop_; | 327 scoped_ptr<MessageLoop> message_loop_; |
| 326 scoped_ptr<BrowserThreadImpl> io_thread_; | 328 scoped_ptr<BrowserThreadImpl> io_thread_; |
| 327 scoped_ptr<BrowserThreadImpl> ui_thread_; | 329 scoped_ptr<BrowserThreadImpl> ui_thread_; |
| 328 scoped_ptr<media::AudioManager> audio_manager_; | 330 scoped_ptr<media::AudioManager> audio_manager_; |
| 329 | 331 |
| 330 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); | 332 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); |
| 331 }; | 333 }; |
| 332 | 334 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 TEST_F(AudioRendererHostTest, SimulateErrorAndClose) { | 388 TEST_F(AudioRendererHostTest, SimulateErrorAndClose) { |
| 387 Create(); | 389 Create(); |
| 388 Play(); | 390 Play(); |
| 389 SimulateError(); | 391 SimulateError(); |
| 390 Close(); | 392 Close(); |
| 391 } | 393 } |
| 392 | 394 |
| 393 // TODO(hclam): Add tests for data conversation in low latency mode. | 395 // TODO(hclam): Add tests for data conversation in low latency mode. |
| 394 | 396 |
| 395 } // namespace content | 397 } // namespace content |
| OLD | NEW |