OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "media/audio/audio_manager.h" | 10 #include "media/audio/audio_manager.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #if defined(USE_PULSEAUDIO) | 26 #if defined(USE_PULSEAUDIO) |
27 #include "media/audio/pulse/audio_manager_pulse.h" | 27 #include "media/audio/pulse/audio_manager_pulse.h" |
28 #endif // defined(USE_PULSEAUDIO) | 28 #endif // defined(USE_PULSEAUDIO) |
29 | 29 |
30 namespace media { | 30 namespace media { |
31 | 31 |
32 // Test fixture which allows us to override the default enumeration API on | 32 // Test fixture which allows us to override the default enumeration API on |
33 // Windows. | 33 // Windows. |
34 class AudioManagerTest : public ::testing::Test { | 34 class AudioManagerTest : public ::testing::Test { |
35 protected: | 35 protected: |
36 AudioManagerTest() | 36 AudioManagerTest() : audio_manager_(AudioManager::CreateForTesting()) { |
37 : audio_manager_(AudioManager::CreateForTesting()) | |
38 #if defined(OS_WIN) | |
39 , com_init_(base::win::ScopedCOMInitializer::kMTA) | |
40 #endif | |
41 { | |
42 // Wait for audio thread initialization to complete. Otherwise the | 37 // Wait for audio thread initialization to complete. Otherwise the |
43 // enumeration type may not have been set yet. | 38 // enumeration type may not have been set yet. |
44 base::WaitableEvent event(false, false); | 39 base::WaitableEvent event(false, false); |
45 audio_manager_->GetTaskRunner()->PostTask(FROM_HERE, base::Bind( | 40 audio_manager_->GetTaskRunner()->PostTask(FROM_HERE, base::Bind( |
46 &base::WaitableEvent::Signal, base::Unretained(&event))); | 41 &base::WaitableEvent::Signal, base::Unretained(&event))); |
47 event.Wait(); | 42 event.Wait(); |
48 } | 43 } |
49 | 44 |
50 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
51 bool SetMMDeviceEnumeration() { | 46 bool SetMMDeviceEnumeration() { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 143 |
149 void RunOnAudioThreadImpl(const base::Closure& closure, | 144 void RunOnAudioThreadImpl(const base::Closure& closure, |
150 base::WaitableEvent* event) { | 145 base::WaitableEvent* event) { |
151 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); | 146 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); |
152 closure.Run(); | 147 closure.Run(); |
153 event->Signal(); | 148 event->Signal(); |
154 } | 149 } |
155 | 150 |
156 FakeAudioLogFactory fake_audio_log_factory_; | 151 FakeAudioLogFactory fake_audio_log_factory_; |
157 scoped_ptr<AudioManager> audio_manager_; | 152 scoped_ptr<AudioManager> audio_manager_; |
158 | |
159 #if defined(OS_WIN) | |
160 // The MMDevice API requires COM to be initialized on the current thread. | |
161 base::win::ScopedCOMInitializer com_init_; | |
162 #endif | |
163 }; | 153 }; |
164 | 154 |
165 // Test that devices can be enumerated. | 155 // Test that devices can be enumerated. |
166 TEST_F(AudioManagerTest, EnumerateInputDevices) { | 156 TEST_F(AudioManagerTest, EnumerateInputDevices) { |
167 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 157 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
168 | 158 |
169 AudioDeviceNames device_names; | 159 AudioDeviceNames device_names; |
170 RunOnAudioThread( | 160 RunOnAudioThread( |
171 base::Bind(&AudioManager::GetAudioInputDeviceNames, | 161 base::Bind(&AudioManager::GetAudioInputDeviceNames, |
172 base::Unretained(audio_manager_.get()), | 162 base::Unretained(audio_manager_.get()), |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 DVLOG(2) << it->unique_id << " matches with " << output_device_id; | 361 DVLOG(2) << it->unique_id << " matches with " << output_device_id; |
372 found_an_associated_device = true; | 362 found_an_associated_device = true; |
373 } | 363 } |
374 } | 364 } |
375 | 365 |
376 EXPECT_TRUE(found_an_associated_device); | 366 EXPECT_TRUE(found_an_associated_device); |
377 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 367 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
378 } | 368 } |
379 | 369 |
380 } // namespace media | 370 } // namespace media |
OLD | NEW |