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

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

Issue 10421010: Revert 138278 - 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 VolumeControllerTest() {}
52
53 virtual void SetUpOnMainThread() OVERRIDE {
54 // First we should shutdown the default audio handler.
55 chromeos::AudioHandler::Shutdown();
56 audio_mixer_ = new MockAudioMixer;
57 chromeos::AudioHandler::InitializeForTesting(audio_mixer_);
58 }
59
60 virtual void CleanUpOnMainThread() OVERRIDE {
61 chromeos::AudioHandler::Shutdown();
62 audio_mixer_ = NULL;
63 }
64
65 protected:
66 void VolumeMute() {
67 volume_controller_.HandleVolumeMute(ui::Accelerator());
68 }
69
70 void VolumeUp() {
71 volume_controller_.HandleVolumeUp(ui::Accelerator());
72 }
73
74 void VolumeDown() {
75 volume_controller_.HandleVolumeDown(ui::Accelerator());
76 }
77
78 MockAudioMixer* audio_mixer() { return audio_mixer_; }
79
80 private:
81 VolumeController volume_controller_;
82 MockAudioMixer* audio_mixer_;
83
84 DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest);
85 };
86
87 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) {
88 // Set initial value as 50%
89 audio_mixer()->SetVolumePercent(50.0);
90
91 double initial_volume = audio_mixer()->GetVolumePercent();
92
93 VolumeUp();
94 EXPECT_LT(initial_volume, audio_mixer()->GetVolumePercent());
95 VolumeDown();
96 EXPECT_DOUBLE_EQ(initial_volume, audio_mixer()->GetVolumePercent());
97 VolumeDown();
98 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent());
99 }
100
101 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeDownToZero) {
102 // Setting to very small
103 audio_mixer()->SetVolumePercent(0.1);
104
105 VolumeDown();
106 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent());
107 VolumeDown();
108 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent());
109 VolumeUp();
110 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent());
111 }
112
113 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpTo100) {
114 // Setting to almost max
115 audio_mixer()->SetVolumePercent(99.0);
116
117 VolumeUp();
118 EXPECT_DOUBLE_EQ(100.0, audio_mixer()->GetVolumePercent());
119 VolumeUp();
120 EXPECT_DOUBLE_EQ(100.0, audio_mixer()->GetVolumePercent());
121 VolumeDown();
122 EXPECT_GT(100.0, audio_mixer()->GetVolumePercent());
123 }
124
125 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, Mutes) {
126 ASSERT_FALSE(audio_mixer()->IsMuted());
127 double initial_volume = audio_mixer()->GetVolumePercent();
128
129 VolumeMute();
130 EXPECT_TRUE(audio_mixer()->IsMuted());
131
132 // Further mute buttons doesn't have effects.
133 VolumeMute();
134 EXPECT_TRUE(audio_mixer()->IsMuted());
135
136 // Right after the volume up after set_mute recovers to original volume.
137 VolumeUp();
138 EXPECT_FALSE(audio_mixer()->IsMuted());
139 EXPECT_DOUBLE_EQ(initial_volume, audio_mixer()->GetVolumePercent());
140
141 VolumeMute();
142 // After the volume down, the volume goes down to zero explicitly.
143 VolumeDown();
144 EXPECT_TRUE(audio_mixer()->IsMuted());
145 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent());
146
147 // Thus, further VolumeUp doesn't recover the volume, it's just slightly
148 // bigger than 0.
149 VolumeUp();
150 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent());
151 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent());
152 }
153
154 } // 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