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

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
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 ui::Accelerator dummy;
66 volume_controller_.HandleVolumeMute(dummy);
Daniel Erat 2012/05/19 00:02:06 nit: can you shorten this to: ...HandleVolumeMu
Jun Mukai 2012/05/19 00:18:32 Done.
67 }
68
69 void VolumeUp() {
70 ui::Accelerator dummy;
71 volume_controller_.HandleVolumeUp(dummy);
Daniel Erat 2012/05/19 00:02:06 same here
Jun Mukai 2012/05/19 00:18:32 Done.
72 }
73
74 void VolumeDown() {
75 ui::Accelerator dummy;
76 volume_controller_.HandleVolumeDown(dummy);
Daniel Erat 2012/05/19 00:02:06 and here
Jun Mukai 2012/05/19 00:18:32 Done.
77 }
78
79 MockAudioMixer* audio_mixer() { return audio_mixer_; }
80
81 private:
82 VolumeController volume_controller_;
83 MockAudioMixer* audio_mixer_;
84 };
85
86 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) {
87 double initial_volume = audio_mixer()->GetVolumePercent();
Daniel Erat 2012/05/19 00:02:06 nit: call SetVolumePercent(50.0) at the beginning
Jun Mukai 2012/05/19 00:18:32 Done.
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 EXPECT_FALSE(audio_mixer()->IsMuted());
Daniel Erat 2012/05/19 00:02:06 nit: s/EXPECT_FALSE/ASSERT_FALSE/, since the rest
Jun Mukai 2012/05/19 00:18:32 Done.
123 double initial_volume = audio_mixer()->GetVolumePercent();
124
125 VolumeMute();
126 EXPECT_TRUE(audio_mixer()->IsMuted());
127
128 // Further mute buttons doesn't make effects.
Daniel Erat 2012/05/19 00:02:06 nit: s/make/have/
Jun Mukai 2012/05/19 00:18:32 Done.
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

Powered by Google App Engine
This is Rietveld 408576698