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.
5 #include "ash/ash_switches.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/ui/ash/volume_controller_chromeos.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chromeos/audio/cras_audio_handler.h"
11 #include "ui/base/accelerators/accelerator.h"
15 class VolumeControllerTest
: public InProcessBrowserTest
{
17 VolumeControllerTest() {}
18 virtual ~VolumeControllerTest() {}
20 virtual void SetUpOnMainThread() OVERRIDE
{
21 volume_controller_
.reset(new VolumeController());
22 audio_handler_
= chromeos::CrasAudioHandler::Get();
27 volume_controller_
->HandleVolumeMute(ui::Accelerator());
31 volume_controller_
->HandleVolumeUp(ui::Accelerator());
35 volume_controller_
->HandleVolumeDown(ui::Accelerator());
38 chromeos::CrasAudioHandler
* audio_handler_
; // Not owned.
41 scoped_ptr
<VolumeController
> volume_controller_
;
43 DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest
);
46 IN_PROC_BROWSER_TEST_F(VolumeControllerTest
, VolumeUpAndDown
) {
47 // Set initial value as 50%
48 const int kInitVolume
= 50;
49 audio_handler_
->SetOutputVolumePercent(kInitVolume
);
51 EXPECT_EQ(audio_handler_
->GetOutputVolumePercent(), kInitVolume
);
54 EXPECT_LT(kInitVolume
, audio_handler_
->GetOutputVolumePercent());
56 EXPECT_EQ(kInitVolume
, audio_handler_
->GetOutputVolumePercent());
58 EXPECT_GT(kInitVolume
, audio_handler_
->GetOutputVolumePercent());
61 IN_PROC_BROWSER_TEST_F(VolumeControllerTest
, VolumeDownToZero
) {
62 // Setting to very small volume.
63 audio_handler_
->SetOutputVolumePercent(1);
66 EXPECT_EQ(0, audio_handler_
->GetOutputVolumePercent());
68 EXPECT_EQ(0, audio_handler_
->GetOutputVolumePercent());
70 EXPECT_LT(0, audio_handler_
->GetOutputVolumePercent());
73 IN_PROC_BROWSER_TEST_F(VolumeControllerTest
, VolumeUpTo100
) {
74 // Setting to almost max
75 audio_handler_
->SetOutputVolumePercent(99);
78 EXPECT_EQ(100, audio_handler_
->GetOutputVolumePercent());
80 EXPECT_EQ(100, audio_handler_
->GetOutputVolumePercent());
82 EXPECT_GT(100, audio_handler_
->GetOutputVolumePercent());
85 IN_PROC_BROWSER_TEST_F(VolumeControllerTest
, Mutes
) {
86 ASSERT_FALSE(audio_handler_
->IsOutputMuted());
87 const int initial_volume
= audio_handler_
->GetOutputVolumePercent();
90 EXPECT_TRUE(audio_handler_
->IsOutputMuted());
92 // Further mute buttons doesn't have effects.
94 EXPECT_TRUE(audio_handler_
->IsOutputMuted());
96 // Right after the volume up after set_mute recovers to original volume.
98 EXPECT_FALSE(audio_handler_
->IsOutputMuted());
99 EXPECT_EQ(initial_volume
, audio_handler_
->GetOutputVolumePercent());
102 // After the volume down, the volume goes down to zero explicitly.
104 EXPECT_TRUE(audio_handler_
->IsOutputMuted());
105 EXPECT_EQ(0, audio_handler_
->GetOutputVolumePercent());
107 // Thus, further VolumeUp doesn't recover the volume, it's just slightly
110 EXPECT_LT(0, audio_handler_
->GetOutputVolumePercent());
111 EXPECT_GT(initial_volume
, audio_handler_
->GetOutputVolumePercent());