Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1282)

Side by Side Diff: chrome/browser/ui/ash/volume_controller_browsertest_chromeos.cc

Issue 2427913003: Use mojo volume interfaces for mash and classic ash. (Closed)
Patch Set: Split volume and system events observers; only hook up volume. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 5 #include <memory>
6 #include <vector> 6 #include <vector>
7 7
8 #include "ash/common/accessibility_delegate.h" 8 #include "ash/common/accessibility_delegate.h"
9 #include "ash/common/accessibility_types.h" 9 #include "ash/common/accessibility_types.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 public: 67 public:
68 VolumeControllerTest() {} 68 VolumeControllerTest() {}
69 ~VolumeControllerTest() override {} 69 ~VolumeControllerTest() override {}
70 70
71 void SetUpOnMainThread() override { 71 void SetUpOnMainThread() override {
72 volume_controller_.reset(new VolumeController()); 72 volume_controller_.reset(new VolumeController());
73 audio_handler_ = chromeos::CrasAudioHandler::Get(); 73 audio_handler_ = chromeos::CrasAudioHandler::Get();
74 } 74 }
75 75
76 protected: 76 protected:
77 void VolumeMute() {
78 volume_controller_->HandleVolumeMute(ui::Accelerator());
79 }
80
81 void VolumeUp() {
82 volume_controller_->HandleVolumeUp(ui::Accelerator());
83 }
84
85 void VolumeDown() {
86 volume_controller_->HandleVolumeDown(ui::Accelerator());
87 }
88
89 chromeos::CrasAudioHandler* audio_handler_; // Not owned. 77 chromeos::CrasAudioHandler* audio_handler_; // Not owned.
78 std::unique_ptr<VolumeController> volume_controller_;
90 79
91 private: 80 private:
92 std::unique_ptr<VolumeController> volume_controller_;
93
94 DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest); 81 DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest);
95 }; 82 };
96 83
97 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) { 84 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) {
98 // Set initial value as 50% 85 // Set initial value as 50%
99 const int kInitVolume = 50; 86 const int kInitVolume = 50;
100 audio_handler_->SetOutputVolumePercent(kInitVolume); 87 audio_handler_->SetOutputVolumePercent(kInitVolume);
101 88
102 EXPECT_EQ(audio_handler_->GetOutputVolumePercent(), kInitVolume); 89 EXPECT_EQ(audio_handler_->GetOutputVolumePercent(), kInitVolume);
103 90
104 VolumeUp(); 91 volume_controller_->VolumeUp();
105 EXPECT_LT(kInitVolume, audio_handler_->GetOutputVolumePercent()); 92 EXPECT_LT(kInitVolume, audio_handler_->GetOutputVolumePercent());
106 VolumeDown(); 93 volume_controller_->VolumeDown();
107 EXPECT_EQ(kInitVolume, audio_handler_->GetOutputVolumePercent()); 94 EXPECT_EQ(kInitVolume, audio_handler_->GetOutputVolumePercent());
108 VolumeDown(); 95 volume_controller_->VolumeDown();
109 EXPECT_GT(kInitVolume, audio_handler_->GetOutputVolumePercent()); 96 EXPECT_GT(kInitVolume, audio_handler_->GetOutputVolumePercent());
110 } 97 }
111 98
112 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeDownToZero) { 99 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeDownToZero) {
113 // Setting to very small volume. 100 // Setting to very small volume.
114 audio_handler_->SetOutputVolumePercent(1); 101 audio_handler_->SetOutputVolumePercent(1);
115 102
116 VolumeDown(); 103 volume_controller_->VolumeDown();
117 EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent()); 104 EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent());
118 VolumeDown(); 105 volume_controller_->VolumeDown();
119 EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent()); 106 EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent());
120 VolumeUp(); 107 volume_controller_->VolumeUp();
121 EXPECT_LT(0, audio_handler_->GetOutputVolumePercent()); 108 EXPECT_LT(0, audio_handler_->GetOutputVolumePercent());
122 } 109 }
123 110
124 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpTo100) { 111 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpTo100) {
125 // Setting to almost max 112 // Setting to almost max
126 audio_handler_->SetOutputVolumePercent(99); 113 audio_handler_->SetOutputVolumePercent(99);
127 114
128 VolumeUp(); 115 volume_controller_->VolumeUp();
129 EXPECT_EQ(100, audio_handler_->GetOutputVolumePercent()); 116 EXPECT_EQ(100, audio_handler_->GetOutputVolumePercent());
130 VolumeUp(); 117 volume_controller_->VolumeUp();
131 EXPECT_EQ(100, audio_handler_->GetOutputVolumePercent()); 118 EXPECT_EQ(100, audio_handler_->GetOutputVolumePercent());
132 VolumeDown(); 119 volume_controller_->VolumeDown();
133 EXPECT_GT(100, audio_handler_->GetOutputVolumePercent()); 120 EXPECT_GT(100, audio_handler_->GetOutputVolumePercent());
134 } 121 }
135 122
136 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, Mutes) { 123 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, Mutes) {
137 ASSERT_FALSE(audio_handler_->IsOutputMuted()); 124 ASSERT_FALSE(audio_handler_->IsOutputMuted());
138 const int initial_volume = audio_handler_->GetOutputVolumePercent(); 125 const int initial_volume = audio_handler_->GetOutputVolumePercent();
139 126
140 VolumeMute(); 127 volume_controller_->VolumeMute();
141 EXPECT_TRUE(audio_handler_->IsOutputMuted()); 128 EXPECT_TRUE(audio_handler_->IsOutputMuted());
142 129
143 // Further mute buttons doesn't have effects. 130 // Further mute buttons doesn't have effects.
144 VolumeMute(); 131 volume_controller_->VolumeMute();
145 EXPECT_TRUE(audio_handler_->IsOutputMuted()); 132 EXPECT_TRUE(audio_handler_->IsOutputMuted());
146 133
147 // Right after the volume up after set_mute recovers to original volume. 134 // Right after the volume up after set_mute recovers to original volume.
148 VolumeUp(); 135 volume_controller_->VolumeUp();
149 EXPECT_FALSE(audio_handler_->IsOutputMuted()); 136 EXPECT_FALSE(audio_handler_->IsOutputMuted());
150 EXPECT_EQ(initial_volume, audio_handler_->GetOutputVolumePercent()); 137 EXPECT_EQ(initial_volume, audio_handler_->GetOutputVolumePercent());
151 138
152 VolumeMute(); 139 volume_controller_->VolumeMute();
153 // After the volume down, the volume goes down to zero explicitly. 140 // After the volume down, the volume goes down to zero explicitly.
154 VolumeDown(); 141 volume_controller_->VolumeDown();
155 EXPECT_TRUE(audio_handler_->IsOutputMuted()); 142 EXPECT_TRUE(audio_handler_->IsOutputMuted());
156 EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent()); 143 EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent());
157 144
158 // Thus, further VolumeUp doesn't recover the volume, it's just slightly 145 // Thus, further VolumeUp doesn't recover the volume, it's just slightly
159 // bigger than 0. 146 // bigger than 0.
160 VolumeUp(); 147 volume_controller_->VolumeUp();
161 EXPECT_LT(0, audio_handler_->GetOutputVolumePercent()); 148 EXPECT_LT(0, audio_handler_->GetOutputVolumePercent());
162 EXPECT_GT(initial_volume, audio_handler_->GetOutputVolumePercent()); 149 EXPECT_GT(initial_volume, audio_handler_->GetOutputVolumePercent());
163 } 150 }
164 151
165 class VolumeControllerSoundsTest : public VolumeControllerTest { 152 class VolumeControllerSoundsTest : public VolumeControllerTest {
166 public: 153 public:
167 VolumeControllerSoundsTest() : sounds_manager_(NULL) {} 154 VolumeControllerSoundsTest() : sounds_manager_(NULL) {}
168 ~VolumeControllerSoundsTest() override {} 155 ~VolumeControllerSoundsTest() override {}
169 156
170 void SetUpInProcessBrowserTestFixture() override { 157 void SetUpInProcessBrowserTestFixture() override {
(...skipping 18 matching lines...) Expand all
189 private: 176 private:
190 SoundsManagerTestImpl* sounds_manager_; 177 SoundsManagerTestImpl* sounds_manager_;
191 178
192 DISALLOW_COPY_AND_ASSIGN(VolumeControllerSoundsTest); 179 DISALLOW_COPY_AND_ASSIGN(VolumeControllerSoundsTest);
193 }; 180 };
194 181
195 IN_PROC_BROWSER_TEST_F(VolumeControllerSoundsTest, Simple) { 182 IN_PROC_BROWSER_TEST_F(VolumeControllerSoundsTest, Simple) {
196 audio_handler_->SetOutputVolumePercent(50); 183 audio_handler_->SetOutputVolumePercent(50);
197 184
198 EnableSpokenFeedback(false /* enabled */); 185 EnableSpokenFeedback(false /* enabled */);
199 VolumeUp(); 186 volume_controller_->VolumeUp();
200 VolumeDown(); 187 volume_controller_->VolumeDown();
201 EXPECT_EQ(0, num_play_requests()); 188 EXPECT_EQ(0, num_play_requests());
202 189
203 EnableSpokenFeedback(true /* enabled */); 190 EnableSpokenFeedback(true /* enabled */);
204 VolumeUp(); 191 volume_controller_->VolumeUp();
205 VolumeDown(); 192 volume_controller_->VolumeDown();
206 EXPECT_EQ(2, num_play_requests()); 193 EXPECT_EQ(2, num_play_requests());
207 } 194 }
208 195
209 IN_PROC_BROWSER_TEST_F(VolumeControllerSoundsTest, EdgeCases) { 196 IN_PROC_BROWSER_TEST_F(VolumeControllerSoundsTest, EdgeCases) {
210 EXPECT_TRUE(is_sound_initialized()); 197 EXPECT_TRUE(is_sound_initialized());
211 EnableSpokenFeedback(true /* enabled */); 198 EnableSpokenFeedback(true /* enabled */);
212 199
213 // Check that sound is played on volume up and volume down. 200 // Check that sound is played on volume up and volume down.
214 audio_handler_->SetOutputVolumePercent(50); 201 audio_handler_->SetOutputVolumePercent(50);
215 VolumeUp(); 202 volume_controller_->VolumeUp();
216 EXPECT_EQ(1, num_play_requests()); 203 EXPECT_EQ(1, num_play_requests());
217 VolumeDown(); 204 volume_controller_->VolumeDown();
218 EXPECT_EQ(2, num_play_requests()); 205 EXPECT_EQ(2, num_play_requests());
219 206
220 audio_handler_->SetOutputVolumePercent(99); 207 audio_handler_->SetOutputVolumePercent(99);
221 VolumeUp(); 208 volume_controller_->VolumeUp();
222 EXPECT_EQ(3, num_play_requests()); 209 EXPECT_EQ(3, num_play_requests());
223 210
224 audio_handler_->SetOutputVolumePercent(100); 211 audio_handler_->SetOutputVolumePercent(100);
225 VolumeUp(); 212 volume_controller_->VolumeUp();
226 EXPECT_EQ(3, num_play_requests()); 213 EXPECT_EQ(3, num_play_requests());
227 214
228 // Check that sound isn't played when audio is muted. 215 // Check that sound isn't played when audio is muted.
229 audio_handler_->SetOutputVolumePercent(50); 216 audio_handler_->SetOutputVolumePercent(50);
230 VolumeMute(); 217 volume_controller_->VolumeMute();
231 VolumeDown(); 218 volume_controller_->VolumeDown();
232 ASSERT_TRUE(audio_handler_->IsOutputMuted()); 219 ASSERT_TRUE(audio_handler_->IsOutputMuted());
233 EXPECT_EQ(3, num_play_requests()); 220 EXPECT_EQ(3, num_play_requests());
234 221
235 // Check that audio is unmuted and sound is played. 222 // Check that audio is unmuted and sound is played.
236 VolumeUp(); 223 volume_controller_->VolumeUp();
237 ASSERT_FALSE(audio_handler_->IsOutputMuted()); 224 ASSERT_FALSE(audio_handler_->IsOutputMuted());
238 EXPECT_EQ(4, num_play_requests()); 225 EXPECT_EQ(4, num_play_requests());
239 } 226 }
240 227
241 class VolumeControllerSoundsDisabledTest : public VolumeControllerSoundsTest { 228 class VolumeControllerSoundsDisabledTest : public VolumeControllerSoundsTest {
242 public: 229 public:
243 VolumeControllerSoundsDisabledTest() {} 230 VolumeControllerSoundsDisabledTest() {}
244 ~VolumeControllerSoundsDisabledTest() override {} 231 ~VolumeControllerSoundsDisabledTest() override {}
245 232
246 void SetUpCommandLine(base::CommandLine* command_line) override { 233 void SetUpCommandLine(base::CommandLine* command_line) override {
247 VolumeControllerSoundsTest::SetUpCommandLine(command_line); 234 VolumeControllerSoundsTest::SetUpCommandLine(command_line);
248 command_line->AppendSwitch(chromeos::switches::kDisableVolumeAdjustSound); 235 command_line->AppendSwitch(chromeos::switches::kDisableVolumeAdjustSound);
249 } 236 }
250 237
251 private: 238 private:
252 DISALLOW_COPY_AND_ASSIGN(VolumeControllerSoundsDisabledTest); 239 DISALLOW_COPY_AND_ASSIGN(VolumeControllerSoundsDisabledTest);
253 }; 240 };
254 241
255 IN_PROC_BROWSER_TEST_F(VolumeControllerSoundsDisabledTest, 242 IN_PROC_BROWSER_TEST_F(VolumeControllerSoundsDisabledTest,
256 VolumeAdjustSounds) { 243 VolumeAdjustSounds) {
257 EXPECT_FALSE(is_sound_initialized()); 244 EXPECT_FALSE(is_sound_initialized());
258 245
259 // Check that sound isn't played on volume up and volume down. 246 // Check that sound isn't played on volume up and volume down.
260 audio_handler_->SetOutputVolumePercent(50); 247 audio_handler_->SetOutputVolumePercent(50);
261 VolumeUp(); 248 volume_controller_->VolumeUp();
262 VolumeDown(); 249 volume_controller_->VolumeDown();
263 EXPECT_EQ(0, num_play_requests()); 250 EXPECT_EQ(0, num_play_requests());
264 } 251 }
265 252
266 } // namespace 253 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/system_tray_delegate_chromeos.cc ('k') | chrome/browser/ui/ash/volume_controller_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698