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_impl.h" |
11 #include "content/browser/mock_resource_context.h" | 12 #include "content/browser/mock_resource_context.h" |
12 #include "content/browser/renderer_host/media/audio_renderer_host.h" | 13 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
13 #include "content/browser/renderer_host/media/mock_media_observer.h" | 14 #include "content/browser/renderer_host/media/mock_media_observer.h" |
14 #include "content/common/media/audio_messages.h" | 15 #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; |
26 using ::testing::InvokeWithoutArgs; | 26 using ::testing::InvokeWithoutArgs; |
27 using ::testing::Return; | 27 using ::testing::Return; |
28 using ::testing::SaveArg; | 28 using ::testing::SaveArg; |
29 using ::testing::SetArgumentPointee; | 29 using ::testing::SetArgumentPointee; |
30 | 30 |
| 31 using content::BrowserThreadImpl; |
| 32 |
31 static const int kStreamId = 50; | 33 static const int kStreamId = 50; |
32 | 34 |
33 static bool IsRunningHeadless() { | 35 static bool IsRunningHeadless() { |
34 scoped_ptr<base::Environment> env(base::Environment::Create()); | 36 scoped_ptr<base::Environment> env(base::Environment::Create()); |
35 if (env->HasVar("CHROME_HEADLESS")) | 37 if (env->HasVar("CHROME_HEADLESS")) |
36 return true; | 38 return true; |
37 return false; | 39 return false; |
38 } | 40 } |
39 | 41 |
40 class MockAudioRendererHost : public AudioRendererHost { | 42 class MockAudioRendererHost : public AudioRendererHost { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 AudioRendererHostTest() | 170 AudioRendererHostTest() |
169 : mock_stream_(true) { | 171 : mock_stream_(true) { |
170 } | 172 } |
171 | 173 |
172 protected: | 174 protected: |
173 virtual void SetUp() { | 175 virtual void SetUp() { |
174 // Create a message loop so AudioRendererHost can use it. | 176 // Create a message loop so AudioRendererHost can use it. |
175 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 177 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
176 | 178 |
177 // Claim to be on both the UI and IO threads to pass all the DCHECKS. | 179 // Claim to be on both the UI and IO threads to pass all the DCHECKS. |
178 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO, | 180 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
179 message_loop_.get())); | 181 message_loop_.get())); |
180 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, | 182 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, |
181 message_loop_.get())); | 183 message_loop_.get())); |
182 | 184 |
183 observer_.reset(new MockMediaObserver()); | 185 observer_.reset(new MockMediaObserver()); |
184 content::MockResourceContext* context = | 186 content::MockResourceContext* context = |
185 content::MockResourceContext::GetInstance(); | 187 content::MockResourceContext::GetInstance(); |
186 context->set_media_observer(observer_.get()); | 188 context->set_media_observer(observer_.get()); |
187 host_ = new MockAudioRendererHost(context); | 189 host_ = new MockAudioRendererHost(context); |
188 | 190 |
189 // Simulate IPC channel connected. | 191 // Simulate IPC channel connected. |
190 host_->OnChannelConnected(base::GetCurrentProcId()); | 192 host_->OnChannelConnected(base::GetCurrentProcId()); |
191 } | 193 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 354 |
353 MessageLoop* message_loop() { return message_loop_.get(); } | 355 MessageLoop* message_loop() { return message_loop_.get(); } |
354 MockAudioRendererHost* host() { return host_; } | 356 MockAudioRendererHost* host() { return host_; } |
355 void EnableRealDevice() { mock_stream_ = false; } | 357 void EnableRealDevice() { mock_stream_ = false; } |
356 | 358 |
357 private: | 359 private: |
358 bool mock_stream_; | 360 bool mock_stream_; |
359 scoped_ptr<MockMediaObserver> observer_; | 361 scoped_ptr<MockMediaObserver> observer_; |
360 scoped_refptr<MockAudioRendererHost> host_; | 362 scoped_refptr<MockAudioRendererHost> host_; |
361 scoped_ptr<MessageLoop> message_loop_; | 363 scoped_ptr<MessageLoop> message_loop_; |
362 scoped_ptr<content::TestBrowserThread> io_thread_; | 364 scoped_ptr<BrowserThreadImpl> io_thread_; |
363 scoped_ptr<content::TestBrowserThread> ui_thread_; | 365 scoped_ptr<BrowserThreadImpl> ui_thread_; |
364 | 366 |
365 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); | 367 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); |
366 }; | 368 }; |
367 | 369 |
368 TEST_F(AudioRendererHostTest, CreateAndClose) { | 370 TEST_F(AudioRendererHostTest, CreateAndClose) { |
369 if (!IsRunningHeadless()) | 371 if (!IsRunningHeadless()) |
370 EnableRealDevice(); | 372 EnableRealDevice(); |
371 | 373 |
372 Create(); | 374 Create(); |
373 Close(); | 375 Close(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 496 |
495 // Simulate the case where a stream is not properly closed. | 497 // Simulate the case where a stream is not properly closed. |
496 TEST_F(AudioRendererHostTest, CreateLowLatencyAndShutdown) { | 498 TEST_F(AudioRendererHostTest, CreateLowLatencyAndShutdown) { |
497 if (!IsRunningHeadless()) | 499 if (!IsRunningHeadless()) |
498 EnableRealDevice(); | 500 EnableRealDevice(); |
499 | 501 |
500 CreateLowLatency(); | 502 CreateLowLatency(); |
501 } | 503 } |
502 | 504 |
503 // TODO(hclam): Add tests for data conversation in low latency mode. | 505 // TODO(hclam): Add tests for data conversation in low latency mode. |
OLD | NEW |