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 "ash/ash_switches.h" | |
6 #include "base/command_line.h" | |
5 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
6 #include "chrome/browser/chromeos/audio/audio_handler.h" | 8 #include "chrome/browser/chromeos/audio/audio_handler.h" |
7 #include "chrome/browser/chromeos/audio/audio_mixer.h" | 9 #include "chrome/browser/chromeos/audio/audio_mixer.h" |
8 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" | 10 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" |
9 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
11 #include "chromeos/audio/audio_pref_handler.h" | 13 #include "chromeos/audio/audio_pref_handler.h" |
12 #include "ui/base/accelerators/accelerator.h" | 14 #include "ui/base/accelerators/accelerator.h" |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
18 void SetupSwitch() { | |
James Cook
2013/04/30 20:55:05
InProcessBrowserTest via BrowserTestBase has a Set
rkc
2013/04/30 23:04:57
Done.
| |
19 CommandLine::ForCurrentProcess()->AppendSwitch( | |
20 ash::switches::kAshDisableNewAudioHandler); | |
21 } | |
22 | |
16 // Default volume as a percentage in the range [0.0, 100.0]. | 23 // Default volume as a percentage in the range [0.0, 100.0]. |
17 const double kDefaultVolumePercent = 75.0; | 24 const double kDefaultVolumePercent = 75.0; |
18 | 25 |
19 class MockAudioMixer : public chromeos::AudioMixer { | 26 class MockAudioMixer : public chromeos::AudioMixer { |
20 public: | 27 public: |
21 MockAudioMixer() | 28 MockAudioMixer() |
22 : volume_(kDefaultVolumePercent), | 29 : volume_(kDefaultVolumePercent), |
23 is_muted_(false) { | 30 is_muted_(false) { |
24 } | 31 } |
25 | 32 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 bool is_capture_muted_; | 80 bool is_capture_muted_; |
74 bool is_capture_mute_locked_; | 81 bool is_capture_mute_locked_; |
75 | 82 |
76 DISALLOW_COPY_AND_ASSIGN(MockAudioMixer); | 83 DISALLOW_COPY_AND_ASSIGN(MockAudioMixer); |
77 }; | 84 }; |
78 | 85 |
79 // This class has to be browsertest because AudioHandler uses prefs_service. | 86 // This class has to be browsertest because AudioHandler uses prefs_service. |
80 class VolumeControllerTest : public InProcessBrowserTest { | 87 class VolumeControllerTest : public InProcessBrowserTest { |
81 public: | 88 public: |
82 VolumeControllerTest() {} | 89 VolumeControllerTest() {} |
83 | |
84 virtual void SetUpOnMainThread() OVERRIDE { | 90 virtual void SetUpOnMainThread() OVERRIDE { |
85 // First we should shutdown the default audio handler. | 91 // First we should shutdown the default audio handler. |
86 chromeos::AudioHandler::Shutdown(); | 92 chromeos::AudioHandler::Shutdown(); |
87 audio_mixer_ = new MockAudioMixer; | 93 audio_mixer_ = new MockAudioMixer; |
88 chromeos::AudioHandler::InitializeForTesting(audio_mixer_, | 94 chromeos::AudioHandler::InitializeForTesting(audio_mixer_, |
89 chromeos::AudioPrefHandler::Create(g_browser_process->local_state())); | 95 chromeos::AudioPrefHandler::Create(g_browser_process->local_state())); |
90 } | 96 } |
91 | 97 |
92 virtual void CleanUpOnMainThread() OVERRIDE { | 98 virtual void CleanUpOnMainThread() OVERRIDE { |
93 chromeos::AudioHandler::Shutdown(); | 99 chromeos::AudioHandler::Shutdown(); |
(...skipping 24 matching lines...) Expand all Loading... | |
118 MockAudioMixer* audio_mixer() { return audio_mixer_; } | 124 MockAudioMixer* audio_mixer() { return audio_mixer_; } |
119 | 125 |
120 private: | 126 private: |
121 VolumeController volume_controller_; | 127 VolumeController volume_controller_; |
122 MockAudioMixer* audio_mixer_; | 128 MockAudioMixer* audio_mixer_; |
123 | 129 |
124 DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest); | 130 DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest); |
125 }; | 131 }; |
126 | 132 |
127 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) { | 133 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) { |
134 SetupSwitch(); | |
128 // Set initial value as 50% | 135 // Set initial value as 50% |
129 audio_mixer()->SetVolumePercent(50.0); | 136 audio_mixer()->SetVolumePercent(50.0); |
130 | 137 |
131 double initial_volume = audio_mixer()->GetVolumePercent(); | 138 double initial_volume = audio_mixer()->GetVolumePercent(); |
132 | 139 |
133 VolumeUp(); | 140 VolumeUp(); |
134 EXPECT_LT(initial_volume, audio_mixer()->GetVolumePercent()); | 141 EXPECT_LT(initial_volume, audio_mixer()->GetVolumePercent()); |
135 VolumeDown(); | 142 VolumeDown(); |
136 EXPECT_DOUBLE_EQ(initial_volume, audio_mixer()->GetVolumePercent()); | 143 EXPECT_DOUBLE_EQ(initial_volume, audio_mixer()->GetVolumePercent()); |
137 VolumeDown(); | 144 VolumeDown(); |
138 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent()); | 145 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent()); |
139 } | 146 } |
140 | 147 |
141 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeDownToZero) { | 148 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeDownToZero) { |
149 SetupSwitch(); | |
142 // Setting to very small | 150 // Setting to very small |
143 audio_mixer()->SetVolumePercent(0.1); | 151 audio_mixer()->SetVolumePercent(0.1); |
144 | 152 |
145 VolumeDown(); | 153 VolumeDown(); |
146 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent()); | 154 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent()); |
147 VolumeDown(); | 155 VolumeDown(); |
148 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent()); | 156 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent()); |
149 VolumeUp(); | 157 VolumeUp(); |
150 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent()); | 158 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent()); |
151 } | 159 } |
152 | 160 |
153 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeAutoMute) { | 161 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeAutoMute) { |
162 SetupSwitch(); | |
154 // Setting to very small | 163 // Setting to very small |
155 | 164 |
156 // kMuteThresholdPercent = 0.1 in audio_handler.cc. | 165 // kMuteThresholdPercent = 0.1 in audio_handler.cc. |
157 SetVolumePercent(0.1); | 166 SetVolumePercent(0.1); |
158 EXPECT_EQ(0.0, audio_mixer()->GetVolumePercent()); | 167 EXPECT_EQ(0.0, audio_mixer()->GetVolumePercent()); |
159 EXPECT_TRUE(audio_mixer()->IsMuted()); | 168 EXPECT_TRUE(audio_mixer()->IsMuted()); |
160 } | 169 } |
161 | 170 |
162 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUnmuteFromZero) { | 171 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUnmuteFromZero) { |
172 SetupSwitch(); | |
163 // Setting to 0% | 173 // Setting to 0% |
164 audio_mixer()->SetVolumePercent(0.0); | 174 audio_mixer()->SetVolumePercent(0.0); |
165 | 175 |
166 VolumeUnmute(); | 176 VolumeUnmute(); |
167 EXPECT_EQ(4.0 /* kDefaultUnmuteVolumePercent in audio_handler.cc */, | 177 EXPECT_EQ(4.0 /* kDefaultUnmuteVolumePercent in audio_handler.cc */, |
168 audio_mixer()->GetVolumePercent()); | 178 audio_mixer()->GetVolumePercent()); |
169 EXPECT_FALSE(audio_mixer()->IsMuted()); | 179 EXPECT_FALSE(audio_mixer()->IsMuted()); |
170 } | 180 } |
171 | 181 |
172 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpTo100) { | 182 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpTo100) { |
183 SetupSwitch(); | |
173 // Setting to almost max | 184 // Setting to almost max |
174 audio_mixer()->SetVolumePercent(99.0); | 185 audio_mixer()->SetVolumePercent(99.0); |
175 | 186 |
176 VolumeUp(); | 187 VolumeUp(); |
177 EXPECT_DOUBLE_EQ(100.0, audio_mixer()->GetVolumePercent()); | 188 EXPECT_DOUBLE_EQ(100.0, audio_mixer()->GetVolumePercent()); |
178 VolumeUp(); | 189 VolumeUp(); |
179 EXPECT_DOUBLE_EQ(100.0, audio_mixer()->GetVolumePercent()); | 190 EXPECT_DOUBLE_EQ(100.0, audio_mixer()->GetVolumePercent()); |
180 VolumeDown(); | 191 VolumeDown(); |
181 EXPECT_GT(100.0, audio_mixer()->GetVolumePercent()); | 192 EXPECT_GT(100.0, audio_mixer()->GetVolumePercent()); |
182 } | 193 } |
183 | 194 |
184 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, Mutes) { | 195 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, Mutes) { |
196 SetupSwitch(); | |
185 ASSERT_FALSE(audio_mixer()->IsMuted()); | 197 ASSERT_FALSE(audio_mixer()->IsMuted()); |
186 double initial_volume = audio_mixer()->GetVolumePercent(); | 198 double initial_volume = audio_mixer()->GetVolumePercent(); |
187 | 199 |
188 VolumeMute(); | 200 VolumeMute(); |
189 EXPECT_TRUE(audio_mixer()->IsMuted()); | 201 EXPECT_TRUE(audio_mixer()->IsMuted()); |
190 | 202 |
191 // Further mute buttons doesn't have effects. | 203 // Further mute buttons doesn't have effects. |
192 VolumeMute(); | 204 VolumeMute(); |
193 EXPECT_TRUE(audio_mixer()->IsMuted()); | 205 EXPECT_TRUE(audio_mixer()->IsMuted()); |
194 | 206 |
195 // Right after the volume up after set_mute recovers to original volume. | 207 // Right after the volume up after set_mute recovers to original volume. |
196 VolumeUp(); | 208 VolumeUp(); |
197 EXPECT_FALSE(audio_mixer()->IsMuted()); | 209 EXPECT_FALSE(audio_mixer()->IsMuted()); |
198 EXPECT_DOUBLE_EQ(initial_volume, audio_mixer()->GetVolumePercent()); | 210 EXPECT_DOUBLE_EQ(initial_volume, audio_mixer()->GetVolumePercent()); |
199 | 211 |
200 VolumeMute(); | 212 VolumeMute(); |
201 // After the volume down, the volume goes down to zero explicitly. | 213 // After the volume down, the volume goes down to zero explicitly. |
202 VolumeDown(); | 214 VolumeDown(); |
203 EXPECT_TRUE(audio_mixer()->IsMuted()); | 215 EXPECT_TRUE(audio_mixer()->IsMuted()); |
204 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent()); | 216 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent()); |
205 | 217 |
206 // Thus, further VolumeUp doesn't recover the volume, it's just slightly | 218 // Thus, further VolumeUp doesn't recover the volume, it's just slightly |
207 // bigger than 0. | 219 // bigger than 0. |
208 VolumeUp(); | 220 VolumeUp(); |
209 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent()); | 221 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent()); |
210 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent()); | 222 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent()); |
211 } | 223 } |
212 | 224 |
213 } // namespace | 225 } // namespace |
OLD | NEW |