| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 11 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 11 #include "content/browser/renderer_host/media/audio_input_device_manager_event_h
andler.h" | 12 #include "content/browser/renderer_host/media/audio_input_device_manager_event_h
andler.h" |
| 12 #include "content/test/test_browser_thread.h" | |
| 13 #include "media/audio/audio_manager.h" | 13 #include "media/audio/audio_manager.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using ::testing::_; | 17 using ::testing::_; |
| 18 using ::testing::AnyNumber; | 18 using ::testing::AnyNumber; |
| 19 using ::testing::InSequence; | 19 using ::testing::InSequence; |
| 20 using ::testing::Return; | 20 using ::testing::Return; |
| 21 | 21 |
| 22 using content::BrowserThreadImpl; |
| 23 |
| 22 namespace media_stream { | 24 namespace media_stream { |
| 23 | 25 |
| 24 class MockAudioInputDeviceManagerListener | 26 class MockAudioInputDeviceManagerListener |
| 25 : public MediaStreamProviderListener { | 27 : public MediaStreamProviderListener { |
| 26 public: | 28 public: |
| 27 MockAudioInputDeviceManagerListener() {} | 29 MockAudioInputDeviceManagerListener() {} |
| 28 virtual ~MockAudioInputDeviceManagerListener() {} | 30 virtual ~MockAudioInputDeviceManagerListener() {} |
| 29 | 31 |
| 30 MOCK_METHOD2(Opened, void(MediaStreamType, const int)); | 32 MOCK_METHOD2(Opened, void(MediaStreamType, const int)); |
| 31 MOCK_METHOD2(Closed, void(MediaStreamType, const int)); | 33 MOCK_METHOD2(Closed, void(MediaStreamType, const int)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 AudioInputDeviceManagerTest() | 80 AudioInputDeviceManagerTest() |
| 79 : message_loop_(), | 81 : message_loop_(), |
| 80 io_thread_(), | 82 io_thread_(), |
| 81 manager_(), | 83 manager_(), |
| 82 audio_input_listener_() {} | 84 audio_input_listener_() {} |
| 83 | 85 |
| 84 protected: | 86 protected: |
| 85 virtual void SetUp() { | 87 virtual void SetUp() { |
| 86 // The test must run on Browser::IO. | 88 // The test must run on Browser::IO. |
| 87 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 89 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
| 88 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO, | 90 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
| 89 message_loop_.get())); | 91 message_loop_.get())); |
| 90 manager_.reset(new media_stream::AudioInputDeviceManager()); | 92 manager_.reset(new media_stream::AudioInputDeviceManager()); |
| 91 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); | 93 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); |
| 92 manager_->Register(audio_input_listener_.get()); | 94 manager_->Register(audio_input_listener_.get()); |
| 93 | 95 |
| 94 // Get the enumerated device list from the AudioInputDeviceManager. | 96 // Get the enumerated device list from the AudioInputDeviceManager. |
| 95 manager_->EnumerateDevices(); | 97 manager_->EnumerateDevices(); |
| 96 EXPECT_CALL(*audio_input_listener_, DevicesEnumerated(_)) | 98 EXPECT_CALL(*audio_input_listener_, DevicesEnumerated(_)) |
| 97 .Times(1); | 99 .Times(1); |
| 98 // Sync up the threads to make sure we get the list. | 100 // Sync up the threads to make sure we get the list. |
| 99 SyncWithAudioInputDeviceManagerThread(); | 101 SyncWithAudioInputDeviceManagerThread(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 121 // pending task in message_loop_ on the current thread. | 123 // pending task in message_loop_ on the current thread. |
| 122 void SyncWithAudioInputDeviceManagerThread() { | 124 void SyncWithAudioInputDeviceManagerThread() { |
| 123 message_loop_->PostTask( | 125 message_loop_->PostTask( |
| 124 FROM_HERE, | 126 FROM_HERE, |
| 125 base::Bind(&PostQuitOnAudioInputDeviceManagerThread, | 127 base::Bind(&PostQuitOnAudioInputDeviceManagerThread, |
| 126 message_loop_.get(), | 128 message_loop_.get(), |
| 127 manager_.get())); | 129 manager_.get())); |
| 128 message_loop_->Run(); | 130 message_loop_->Run(); |
| 129 } | 131 } |
| 130 scoped_ptr<MessageLoop> message_loop_; | 132 scoped_ptr<MessageLoop> message_loop_; |
| 131 scoped_ptr<content::TestBrowserThread> io_thread_; | 133 scoped_ptr<BrowserThreadImpl> io_thread_; |
| 132 scoped_ptr<AudioInputDeviceManager> manager_; | 134 scoped_ptr<AudioInputDeviceManager> manager_; |
| 133 scoped_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_; | 135 scoped_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_; |
| 134 | 136 |
| 135 private: | 137 private: |
| 136 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManagerTest); | 138 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManagerTest); |
| 137 }; | 139 }; |
| 138 | 140 |
| 139 // Test the devices can be opened and closed. | 141 // Test the devices can be opened and closed. |
| 140 TEST_F(AudioInputDeviceManagerTest, OpenAndCloseDevice) { | 142 TEST_F(AudioInputDeviceManagerTest, OpenAndCloseDevice) { |
| 141 if (!CanRunAudioInputDeviceTests()) | 143 if (!CanRunAudioInputDeviceTests()) |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 OnDeviceStarted(second_session_id, 0)) | 391 OnDeviceStarted(second_session_id, 0)) |
| 390 .Times(1); | 392 .Times(1); |
| 391 EXPECT_CALL(*audio_input_listener_, Closed(kAudioCapture, first_session_id)) | 393 EXPECT_CALL(*audio_input_listener_, Closed(kAudioCapture, first_session_id)) |
| 392 .Times(1); | 394 .Times(1); |
| 393 EXPECT_CALL(*audio_input_listener_, Closed(kAudioCapture, second_session_id)) | 395 EXPECT_CALL(*audio_input_listener_, Closed(kAudioCapture, second_session_id)) |
| 394 .Times(1); | 396 .Times(1); |
| 395 SyncWithAudioInputDeviceManagerThread(); | 397 SyncWithAudioInputDeviceManagerThread(); |
| 396 } | 398 } |
| 397 | 399 |
| 398 } // namespace media_stream | 400 } // namespace media_stream |
| OLD | NEW |