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/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" |
11 #include "content/browser/browser_thread.h" | |
12 #include "content/browser/mock_resource_context.h" | 11 #include "content/browser/mock_resource_context.h" |
13 #include "content/browser/renderer_host/media/audio_renderer_host.h" | 12 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
14 #include "content/browser/renderer_host/media/mock_media_observer.h" | 13 #include "content/browser/renderer_host/media/mock_media_observer.h" |
15 #include "content/common/media/audio_messages.h" | 14 #include "content/common/media/audio_messages.h" |
| 15 #include "content/test/test_browser_thread.h" |
16 #include "ipc/ipc_message_utils.h" | 16 #include "ipc/ipc_message_utils.h" |
17 #include "media/audio/audio_manager.h" | 17 #include "media/audio/audio_manager.h" |
18 #include "media/audio/fake_audio_output_stream.h" | 18 #include "media/audio/fake_audio_output_stream.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 using ::testing::_; | 22 using ::testing::_; |
23 using ::testing::AtLeast; | 23 using ::testing::AtLeast; |
24 using ::testing::DoAll; | 24 using ::testing::DoAll; |
25 using ::testing::InSequence; | 25 using ::testing::InSequence; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 AudioRendererHostTest() | 168 AudioRendererHostTest() |
169 : mock_stream_(true) { | 169 : mock_stream_(true) { |
170 } | 170 } |
171 | 171 |
172 protected: | 172 protected: |
173 virtual void SetUp() { | 173 virtual void SetUp() { |
174 // Create a message loop so AudioRendererHost can use it. | 174 // Create a message loop so AudioRendererHost can use it. |
175 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 175 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
176 | 176 |
177 // Claim to be on both the UI and IO threads to pass all the DCHECKS. | 177 // Claim to be on both the UI and IO threads to pass all the DCHECKS. |
178 io_thread_.reset(new BrowserThread(BrowserThread::IO, message_loop_.get())); | 178 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO, |
179 ui_thread_.reset(new BrowserThread(BrowserThread::UI, message_loop_.get())); | 179 message_loop_.get())); |
| 180 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, |
| 181 message_loop_.get())); |
180 | 182 |
181 observer_.reset(new MockMediaObserver()); | 183 observer_.reset(new MockMediaObserver()); |
182 content::MockResourceContext* context = | 184 content::MockResourceContext* context = |
183 content::MockResourceContext::GetInstance(); | 185 content::MockResourceContext::GetInstance(); |
184 context->set_media_observer(observer_.get()); | 186 context->set_media_observer(observer_.get()); |
185 host_ = new MockAudioRendererHost(context); | 187 host_ = new MockAudioRendererHost(context); |
186 | 188 |
187 // Simulate IPC channel connected. | 189 // Simulate IPC channel connected. |
188 host_->OnChannelConnected(base::GetCurrentProcId()); | 190 host_->OnChannelConnected(base::GetCurrentProcId()); |
189 } | 191 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 352 |
351 MessageLoop* message_loop() { return message_loop_.get(); } | 353 MessageLoop* message_loop() { return message_loop_.get(); } |
352 MockAudioRendererHost* host() { return host_; } | 354 MockAudioRendererHost* host() { return host_; } |
353 void EnableRealDevice() { mock_stream_ = false; } | 355 void EnableRealDevice() { mock_stream_ = false; } |
354 | 356 |
355 private: | 357 private: |
356 bool mock_stream_; | 358 bool mock_stream_; |
357 scoped_ptr<MockMediaObserver> observer_; | 359 scoped_ptr<MockMediaObserver> observer_; |
358 scoped_refptr<MockAudioRendererHost> host_; | 360 scoped_refptr<MockAudioRendererHost> host_; |
359 scoped_ptr<MessageLoop> message_loop_; | 361 scoped_ptr<MessageLoop> message_loop_; |
360 scoped_ptr<BrowserThread> io_thread_; | 362 scoped_ptr<content::TestBrowserThread> io_thread_; |
361 scoped_ptr<BrowserThread> ui_thread_; | 363 scoped_ptr<content::TestBrowserThread> ui_thread_; |
362 | 364 |
363 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); | 365 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); |
364 }; | 366 }; |
365 | 367 |
366 TEST_F(AudioRendererHostTest, CreateAndClose) { | 368 TEST_F(AudioRendererHostTest, CreateAndClose) { |
367 if (!IsRunningHeadless()) | 369 if (!IsRunningHeadless()) |
368 EnableRealDevice(); | 370 EnableRealDevice(); |
369 | 371 |
370 Create(); | 372 Create(); |
371 Close(); | 373 Close(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 494 |
493 // Simulate the case where a stream is not properly closed. | 495 // Simulate the case where a stream is not properly closed. |
494 TEST_F(AudioRendererHostTest, CreateLowLatencyAndShutdown) { | 496 TEST_F(AudioRendererHostTest, CreateLowLatencyAndShutdown) { |
495 if (!IsRunningHeadless()) | 497 if (!IsRunningHeadless()) |
496 EnableRealDevice(); | 498 EnableRealDevice(); |
497 | 499 |
498 CreateLowLatency(); | 500 CreateLowLatency(); |
499 } | 501 } |
500 | 502 |
501 // TODO(hclam): Add tests for data conversation in low latency mode. | 503 // TODO(hclam): Add tests for data conversation in low latency mode. |
OLD | NEW |