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

Side by Side Diff: chrome/browser/ui/views/ash/volume_controller_chromeos_browsertest.cc

Issue 10411028: Fix the volume controlling behaviors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/ash/volume_controller_chromeos.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/ash/volume_controller_chromeos.h"
6
7 #include "chrome/browser/chromeos/audio/audio_handler.h"
8 #include "chrome/browser/chromeos/audio/audio_mixer.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h"
11 #include "ui/base/accelerators/accelerator.h"
12
13 namespace {
14
15 class MockAudioMixer : public chromeos::AudioMixer {
16 public:
17 MockAudioMixer()
18 : volume_(0.0),
19 is_muted_(false) {
20 }
21
22 virtual void Init() OVERRIDE {
23 }
24
25 virtual double GetVolumePercent() OVERRIDE {
26 return volume_;
27 }
28
29 virtual void SetVolumePercent(double percent) OVERRIDE {
30 volume_ = percent;
31 }
32
33 virtual bool IsMuted() OVERRIDE {
34 return is_muted_;
35 }
36
37 virtual void SetMuted(bool do_mute) OVERRIDE {
38 is_muted_ = do_mute;
39 }
40
41 private:
42 double volume_;
43 bool is_muted_;
44
45 DISALLOW_COPY_AND_ASSIGN(MockAudioMixer);
46 };
47
48 // This class has to be browsertest because AudioHandler uses prefs_service.
49 class VolumeControllerTest : public InProcessBrowserTest {
50 public:
51 virtual void SetUpOnMainThread() OVERRIDE {
52 // First we should shutdown the default audio handler.
53 chromeos::AudioHandler::Shutdown();
54 audio_mixer_ = new MockAudioMixer;
55 chromeos::AudioHandler::InitializeForTesting(audio_mixer_);
56 }
57
58 virtual void CleanUpOnMainThread() OVERRIDE {
59 chromeos::AudioHandler::Shutdown();
60 audio_mixer_ = NULL;
61 }
62
63 protected:
64 void VolumeMute() {
65 volume_controller_.HandleVolumeMute(ui::Accelerator());
66 }
67
68 void VolumeUp() {
69 volume_controller_.HandleVolumeUp(ui::Accelerator());
70 }
71
72 void VolumeDown() {
73 volume_controller_.HandleVolumeDown(ui::Accelerator());
74 }
75
76 MockAudioMixer* audio_mixer() { return audio_mixer_; }
77
78 private:
sky 2012/05/21 14:45:27 indentation is off.
Jun Mukai 2012/05/21 17:02:09 Done.
79 VolumeController volume_controller_;
80 MockAudioMixer* audio_mixer_;
81 };
sky 2012/05/21 14:45:27 DISALLOW_...
Jun Mukai 2012/05/21 17:02:09 Done.
82
83 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) {
84 // Set initial value as 50%
85 audio_mixer()->SetVolumePercent(50.0);
86
87 double initial_volume = audio_mixer()->GetVolumePercent();
88
89 VolumeUp();
90 EXPECT_LT(initial_volume, audio_mixer()->GetVolumePercent());
91 VolumeDown();
92 EXPECT_DOUBLE_EQ(initial_volume, audio_mixer()->GetVolumePercent());
93 VolumeDown();
94 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent());
95 }
96
97 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeDownToZero) {
98 // Setting to very small
99 audio_mixer()->SetVolumePercent(0.1);
100
101 VolumeDown();
102 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent());
103 VolumeDown();
104 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent());
105 VolumeUp();
106 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent());
107 }
108
109 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpTo100) {
110 // Setting to almost max
111 audio_mixer()->SetVolumePercent(99.0);
112
113 VolumeUp();
114 EXPECT_DOUBLE_EQ(100.0, audio_mixer()->GetVolumePercent());
115 VolumeUp();
116 EXPECT_DOUBLE_EQ(100.0, audio_mixer()->GetVolumePercent());
117 VolumeDown();
118 EXPECT_GT(100.0, audio_mixer()->GetVolumePercent());
119 }
120
121 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, Mutes) {
122 ASSERT_FALSE(audio_mixer()->IsMuted());
123 double initial_volume = audio_mixer()->GetVolumePercent();
124
125 VolumeMute();
126 EXPECT_TRUE(audio_mixer()->IsMuted());
127
128 // Further mute buttons doesn't have effects.
129 VolumeMute();
130 EXPECT_TRUE(audio_mixer()->IsMuted());
131
132 // Right after the volume up after set_mute recovers to original volume.
133 VolumeUp();
134 EXPECT_FALSE(audio_mixer()->IsMuted());
135 EXPECT_DOUBLE_EQ(initial_volume, audio_mixer()->GetVolumePercent());
136
137 VolumeMute();
138 // After the volume down, the volume goes down to zero explicitly.
139 VolumeDown();
140 EXPECT_TRUE(audio_mixer()->IsMuted());
141 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent());
142
143 // Thus, further VolumeUp doesn't recover the volume, it's just slightly
144 // bigger than 0.
145 VolumeUp();
146 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent());
147 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent());
148 }
149
150 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/ash/volume_controller_chromeos.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698