Chromium Code Reviews| 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/environment.h" | |
| 6 #include "base/memory/scoped_ptr.h" | |
| 7 #include "base/win/scoped_com_initializer.h" | |
| 5 #include "media/audio/audio_manager.h" | 8 #include "media/audio/audio_manager.h" |
| 9 #if defined(OS_WIN) | |
| 10 #include "media/audio/win/audio_manager_win.h" | |
| 11 #endif | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 13 |
| 8 namespace media { | 14 using base::win::ScopedCOMInitializer; |
| 15 using media::AudioDeviceNames; | |
| 16 | |
| 17 // Test fixture which allows us to override the default enumeration API on | |
| 18 // Windows. | |
| 19 class AudioInputDeviceTest | |
| 20 : public ::testing::Test { | |
| 21 protected: | |
| 22 #if defined(OS_WIN) | |
| 23 bool SetMMDeviceEnumeration() { | |
| 24 // Windows Wave is used as default if Windows XP was detected => | |
| 25 // return false since MMDevice is not supported on XP. | |
| 26 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.
| |
| 27 AudioManagerWin::kWaveEnumeration) | |
| 28 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.
| |
| 29 AudioManagerWin::SetEnumerationType(AudioManagerWin::kMMDeviceEnumeration); | |
| 30 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.
| |
| 31 } | |
| 32 void SetWaveEnumeration() { | |
| 33 AudioManagerWin::SetEnumerationType(AudioManagerWin::kWaveEnumeration); | |
| 34 } | |
| 35 #endif | |
| 36 }; | |
| 37 | |
| 38 // Convenience method which ensures that we are not running on the build | |
| 39 // bots which lacks audio device support. | |
| 40 static bool CanRunAudioTests() { | |
| 41 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
| 42 if (env->HasVar("CHROME_HEADLESS")) | |
| 43 return false; | |
| 44 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
| |
| 45 return (audio_man != NULL); | |
| 46 } | |
| 9 | 47 |
| 10 // Test that devices can be enumerated. | 48 // Test that devices can be enumerated. |
| 11 TEST(AudioInputDeviceTest, EnumerateDevices) { | 49 TEST_F(AudioInputDeviceTest, EnumerateDevices) { |
| 50 if (!CanRunAudioTests()) | |
| 51 return; | |
| 52 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.
| |
| 12 AudioDeviceNames device_names; | 53 AudioDeviceNames device_names; |
| 13 ASSERT_TRUE(AudioManager::GetAudioManager() != NULL); | |
| 14 AudioManager::GetAudioManager()->GetAudioInputDeviceNames( | 54 AudioManager::GetAudioManager()->GetAudioInputDeviceNames( |
| 15 &device_names); | 55 &device_names); |
| 16 if (!device_names.empty()) { | 56 if (!device_names.empty()) { |
| 17 AudioDeviceNames::const_iterator it = device_names.begin(); | 57 AudioDeviceNames::const_iterator it = device_names.begin(); |
| 18 // The first device in the list is the prepended default device. | 58 // The first device in the list should always be the default device. |
| 19 EXPECT_EQ("Default", it->device_name); | 59 EXPECT_EQ("Default", it->device_name); |
| 20 EXPECT_EQ("0", it->unique_id); | 60 EXPECT_EQ("0", it->unique_id); |
| 21 ++it; | 61 ++it; |
| 22 | 62 |
| 23 // Other devices should have non-empty name and id. | 63 // Other devices should have non-empty name and id. |
| 24 while (it != device_names.end()) { | 64 while (it != device_names.end()) { |
| 25 EXPECT_NE("", it->device_name); | 65 EXPECT_NE("", it->device_name); |
| 26 EXPECT_NE("", it->unique_id); | 66 EXPECT_NE("", it->unique_id); |
| 27 ++it; | 67 ++it; |
| 28 } | 68 } |
| 29 } | 69 } |
| 30 } | 70 } |
| 31 | 71 |
| 32 } // namespace media | 72 // Run additional tests for Windows since enumeration can be done using |
| 73 // two different APIs. MMDevice is default for Vista and higher and Wave | |
| 74 // is default for XP and lower. | |
| 75 #if defined(OS_WIN) | |
| 76 | |
| 77 // Override default enumeration API and force usage of Windows MMDevice. | |
| 78 // This test will only run on Windows Vista and higher. | |
| 79 TEST_F(AudioInputDeviceTest, EnumerateDevicesWinMMDevice) { | |
| 80 if (!CanRunAudioTests()) | |
| 81 return; | |
| 82 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | |
| 83 AudioDeviceNames device_names; | |
| 84 if (!SetMMDeviceEnumeration()) { | |
| 85 // Usage of MMDevice will fail on XP and lower. | |
| 86 return; | |
| 87 } | |
| 88 AudioManager::GetAudioManager()->GetAudioInputDeviceNames( | |
| 89 &device_names); | |
| 90 if (!device_names.empty()) { | |
| 91 AudioDeviceNames::const_iterator it = device_names.begin(); | |
| 92 // The first device in the list should always be the default device. | |
| 93 EXPECT_EQ("Default", it->device_name); | |
| 94 EXPECT_EQ("0", it->unique_id); | |
| 95 ++it; | |
| 96 | |
| 97 // Other devices should have non-empty name and id. | |
| 98 while (it != device_names.end()) { | |
| 99 EXPECT_NE("", it->device_name); | |
| 100 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
| |
| 101 ++it; | |
| 102 } | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 // Override default enumeration API and force usage of Windows Wave. | |
| 107 // This test will run on Windows XP, Windows Vista and Windows 7. | |
| 108 TEST_F(AudioInputDeviceTest, EnumerateDevicesWinWave) { | |
| 109 if (!CanRunAudioTests()) | |
| 110 return; | |
| 111 AudioDeviceNames device_names; | |
| 112 SetWaveEnumeration(); | |
| 113 AudioManager::GetAudioManager()->GetAudioInputDeviceNames( | |
| 114 &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
| |
| 115 if (!device_names.empty()) { | |
| 116 AudioDeviceNames::const_iterator it = device_names.begin(); | |
| 117 // The first device in the list should always be the default device. | |
| 118 EXPECT_EQ("Default", it->device_name); | |
| 119 EXPECT_EQ("0", it->unique_id); | |
| 120 ++it; | |
| 121 | |
| 122 // Other devices should have non-empty name and id. | |
| 123 while (it != device_names.end()) { | |
| 124 EXPECT_NE("", it->device_name); | |
|
tommi (sloooow) - chröme
2011/11/22 12:52:37
same here.
Atually, this looks like the same exac
| |
| 125 EXPECT_NE("", it->unique_id); | |
| 126 ++it; | |
| 127 } | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 #endif | |
| OLD | NEW |