Chromium Code Reviews| Index: media/audio/audio_input_device_unittest.cc |
| =================================================================== |
| --- media/audio/audio_input_device_unittest.cc (revision 110683) |
| +++ media/audio/audio_input_device_unittest.cc (working copy) |
| @@ -2,20 +2,60 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/environment.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/win/scoped_com_initializer.h" |
| #include "media/audio/audio_manager.h" |
| +#if defined(OS_WIN) |
| +#include "media/audio/win/audio_manager_win.h" |
| +#endif |
| #include "testing/gtest/include/gtest/gtest.h" |
| -namespace media { |
| +using base::win::ScopedCOMInitializer; |
| +using media::AudioDeviceNames; |
| +// Test fixture which allows us to override the default enumeration API on |
| +// Windows. |
| +class AudioInputDeviceTest |
| + : public ::testing::Test { |
| + protected: |
| +#if defined(OS_WIN) |
| + bool SetMMDeviceEnumeration() { |
| + // Windows Wave is used as default if Windows XP was detected => |
| + // return false since MMDevice is not supported on XP. |
| + if (AudioManagerWin::enumeration_type() == |
|
tommi (sloooow) - chröme
2011/11/22 12:52:37
is this stored in a global variable?
If so, won't
henrika (OOO until Aug 14)
2011/11/23 09:19:19
Done.
|
| + AudioManagerWin::kWaveEnumeration) |
| + return false; |
|
tommi (sloooow) - chröme
2011/11/22 12:52:37
nit: {} (for 3+ lines)
henrika (OOO until Aug 14)
2011/11/23 09:19:19
Rewriting.
|
| + AudioManagerWin::SetEnumerationType(AudioManagerWin::kMMDeviceEnumeration); |
| + return true; |
|
tommi (sloooow) - chröme
2011/11/22 12:52:37
fix indent
henrika (OOO until Aug 14)
2011/11/23 09:19:19
Rewriting.
|
| + } |
| + void SetWaveEnumeration() { |
| + AudioManagerWin::SetEnumerationType(AudioManagerWin::kWaveEnumeration); |
| + } |
| +#endif |
| +}; |
| + |
| +// Convenience method which ensures that we are not running on the build |
| +// bots which lacks audio device support. |
| +static bool CanRunAudioTests() { |
| + scoped_ptr<base::Environment> env(base::Environment::Create()); |
| + if (env->HasVar("CHROME_HEADLESS")) |
| + return false; |
| + AudioManager* audio_man = AudioManager::GetAudioManager(); |
|
tommi (sloooow) - chröme
2011/11/22 12:52:37
Constructing the audio manager singleton can unfor
henrika (OOO until Aug 14)
2011/11/23 09:19:19
Agree. I will modify this test when your parts are
|
| + return (audio_man != NULL); |
| +} |
| + |
| // Test that devices can be enumerated. |
| -TEST(AudioInputDeviceTest, EnumerateDevices) { |
| +TEST_F(AudioInputDeviceTest, EnumerateDevices) { |
| + if (!CanRunAudioTests()) |
| + return; |
| + ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
|
tommi (sloooow) - chröme
2011/11/22 12:52:37
maybe a note on why we use mta and not sta.
henrika (OOO until Aug 14)
2011/11/23 09:19:19
Done.
|
| AudioDeviceNames device_names; |
| - ASSERT_TRUE(AudioManager::GetAudioManager() != NULL); |
| AudioManager::GetAudioManager()->GetAudioInputDeviceNames( |
| &device_names); |
| if (!device_names.empty()) { |
| AudioDeviceNames::const_iterator it = device_names.begin(); |
| - // The first device in the list is the prepended default device. |
| + // The first device in the list should always be the default device. |
| EXPECT_EQ("Default", it->device_name); |
| EXPECT_EQ("0", it->unique_id); |
| ++it; |
| @@ -29,4 +69,63 @@ |
| } |
| } |
| -} // namespace media |
| +// Run additional tests for Windows since enumeration can be done using |
| +// two different APIs. MMDevice is default for Vista and higher and Wave |
| +// is default for XP and lower. |
| +#if defined(OS_WIN) |
| + |
| +// Override default enumeration API and force usage of Windows MMDevice. |
| +// This test will only run on Windows Vista and higher. |
| +TEST_F(AudioInputDeviceTest, EnumerateDevicesWinMMDevice) { |
| + if (!CanRunAudioTests()) |
| + return; |
| + ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
| + AudioDeviceNames device_names; |
| + if (!SetMMDeviceEnumeration()) { |
| + // Usage of MMDevice will fail on XP and lower. |
| + return; |
| + } |
| + AudioManager::GetAudioManager()->GetAudioInputDeviceNames( |
| + &device_names); |
| + if (!device_names.empty()) { |
| + AudioDeviceNames::const_iterator it = device_names.begin(); |
| + // The first device in the list should always be the default device. |
| + EXPECT_EQ("Default", it->device_name); |
| + EXPECT_EQ("0", it->unique_id); |
| + ++it; |
| + |
| + // Other devices should have non-empty name and id. |
| + while (it != device_names.end()) { |
| + EXPECT_NE("", it->device_name); |
| + EXPECT_NE("", it->unique_id); |
|
tommi (sloooow) - chröme
2011/11/22 12:52:37
should we also check that device_name is not "Defa
|
| + ++it; |
| + } |
| + } |
| +} |
| + |
| +// Override default enumeration API and force usage of Windows Wave. |
| +// This test will run on Windows XP, Windows Vista and Windows 7. |
| +TEST_F(AudioInputDeviceTest, EnumerateDevicesWinWave) { |
| + if (!CanRunAudioTests()) |
| + return; |
| + AudioDeviceNames device_names; |
| + SetWaveEnumeration(); |
| + AudioManager::GetAudioManager()->GetAudioInputDeviceNames( |
| + &device_names); |
|
tommi (sloooow) - chröme
2011/11/22 12:52:37
indent
henrika (OOO until Aug 14)
2011/11/23 09:19:19
rewritten
|
| + if (!device_names.empty()) { |
| + AudioDeviceNames::const_iterator it = device_names.begin(); |
| + // The first device in the list should always be the default device. |
| + EXPECT_EQ("Default", it->device_name); |
| + EXPECT_EQ("0", it->unique_id); |
| + ++it; |
| + |
| + // Other devices should have non-empty name and id. |
| + while (it != device_names.end()) { |
| + EXPECT_NE("", it->device_name); |
|
tommi (sloooow) - chröme
2011/11/22 12:52:37
same here.
Atually, this looks like the same exac
|
| + EXPECT_NE("", it->unique_id); |
| + ++it; |
| + } |
| + } |
| +} |
| + |
| +#endif |