| 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/environment.h" | 5 #include "base/environment.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/win/scoped_com_initializer.h" | |
| 8 #include "media/audio/audio_manager.h" | 7 #include "media/audio/audio_manager.h" |
| 9 #include "media/audio/audio_manager_base.h" | 8 #include "media/audio/audio_manager_base.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 10 |
| 12 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 12 #include "base/win/scoped_com_initializer.h" |
| 13 #include "media/audio/win/audio_manager_win.h" | 13 #include "media/audio/win/audio_manager_win.h" |
| 14 #include "media/audio/win/wavein_input_win.h" | 14 #include "media/audio/win/wavein_input_win.h" |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 using base::win::ScopedCOMInitializer; | |
| 18 | |
| 19 namespace media { | 17 namespace media { |
| 20 | 18 |
| 21 // Test fixture which allows us to override the default enumeration API on | 19 // Test fixture which allows us to override the default enumeration API on |
| 22 // Windows. | 20 // Windows. |
| 23 class AudioInputDeviceTest | 21 class AudioInputDeviceTest |
| 24 : public ::testing::Test { | 22 : public ::testing::Test { |
| 25 protected: | 23 protected: |
| 26 AudioInputDeviceTest() | 24 AudioInputDeviceTest() |
| 27 : audio_manager_(AudioManager::Create()), | 25 : audio_manager_(AudioManager::Create()) |
| 28 com_init_(ScopedCOMInitializer::kMTA) { | 26 #if defined(OS_WIN) |
| 27 , com_init_(base::win::ScopedCOMInitializer::kMTA) |
| 28 #endif |
| 29 { |
| 29 } | 30 } |
| 30 | 31 |
| 31 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 32 bool SetMMDeviceEnumeration() { | 33 bool SetMMDeviceEnumeration() { |
| 33 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); | 34 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); |
| 34 // Windows Wave is used as default if Windows XP was detected => | 35 // Windows Wave is used as default if Windows XP was detected => |
| 35 // return false since MMDevice is not supported on XP. | 36 // return false since MMDevice is not supported on XP. |
| 36 if (amw->enumeration_type() == AudioManagerWin::kWaveEnumeration) | 37 if (amw->enumeration_type() == AudioManagerWin::kWaveEnumeration) |
| 37 return false; | 38 return false; |
| 38 | 39 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } else { | 86 } else { |
| 86 // Log a warning so we can see the status on the build bots. No need to | 87 // Log a warning so we can see the status on the build bots. No need to |
| 87 // break the test though since this does successfully test the code and | 88 // break the test though since this does successfully test the code and |
| 88 // some failure cases. | 89 // some failure cases. |
| 89 LOG(WARNING) << "No input devices detected"; | 90 LOG(WARNING) << "No input devices detected"; |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| 93 scoped_ptr<AudioManager> audio_manager_; | 94 scoped_ptr<AudioManager> audio_manager_; |
| 94 | 95 |
| 96 #if defined(OS_WIN) |
| 95 // The MMDevice API requires COM to be initialized on the current thread. | 97 // The MMDevice API requires COM to be initialized on the current thread. |
| 96 ScopedCOMInitializer com_init_; | 98 base::win::ScopedCOMInitializer com_init_; |
| 99 #endif |
| 97 }; | 100 }; |
| 98 | 101 |
| 99 // Test that devices can be enumerated. | 102 // Test that devices can be enumerated. |
| 100 TEST_F(AudioInputDeviceTest, EnumerateDevices) { | 103 TEST_F(AudioInputDeviceTest, EnumerateDevices) { |
| 101 AudioDeviceNames device_names; | 104 AudioDeviceNames device_names; |
| 102 audio_manager_->GetAudioInputDeviceNames(&device_names); | 105 audio_manager_->GetAudioInputDeviceNames(&device_names); |
| 103 CheckDeviceNames(device_names); | 106 CheckDeviceNames(device_names); |
| 104 } | 107 } |
| 105 | 108 |
| 106 // Run additional tests for Windows since enumeration can be done using | 109 // Run additional tests for Windows since enumeration can be done using |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // MMDevice-style device IDs should be converted to WaveIn-style device | 170 // MMDevice-style device IDs should be converted to WaveIn-style device |
| 168 // IDs. | 171 // IDs. |
| 169 EXPECT_NE(i->unique_id, converted_id); | 172 EXPECT_NE(i->unique_id, converted_id); |
| 170 } | 173 } |
| 171 } | 174 } |
| 172 } | 175 } |
| 173 | 176 |
| 174 #endif | 177 #endif |
| 175 | 178 |
| 176 } // namespace media | 179 } // namespace media |
| OLD | NEW |