Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / ash / volume_controller_browsertest_chromeos.cc
blob57fc2e7c4dd28fec85cd39ac4b8a611b35cf9bc4
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"
13 namespace {
15 class VolumeControllerTest : public InProcessBrowserTest {
16 public:
17 VolumeControllerTest() {}
18 virtual ~VolumeControllerTest() {}
20 virtual void SetUpOnMainThread() OVERRIDE {
21 volume_controller_.reset(new VolumeController());
22 audio_handler_ = chromeos::CrasAudioHandler::Get();
25 protected:
26 void VolumeMute() {
27 volume_controller_->HandleVolumeMute(ui::Accelerator());
30 void VolumeUp() {
31 volume_controller_->HandleVolumeUp(ui::Accelerator());
34 void VolumeDown() {
35 volume_controller_->HandleVolumeDown(ui::Accelerator());
38 chromeos::CrasAudioHandler* audio_handler_; // Not owned.
40 private:
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);
53 VolumeUp();
54 EXPECT_LT(kInitVolume, audio_handler_->GetOutputVolumePercent());
55 VolumeDown();
56 EXPECT_EQ(kInitVolume, audio_handler_->GetOutputVolumePercent());
57 VolumeDown();
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);
65 VolumeDown();
66 EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent());
67 VolumeDown();
68 EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent());
69 VolumeUp();
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);
77 VolumeUp();
78 EXPECT_EQ(100, audio_handler_->GetOutputVolumePercent());
79 VolumeUp();
80 EXPECT_EQ(100, audio_handler_->GetOutputVolumePercent());
81 VolumeDown();
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();
89 VolumeMute();
90 EXPECT_TRUE(audio_handler_->IsOutputMuted());
92 // Further mute buttons doesn't have effects.
93 VolumeMute();
94 EXPECT_TRUE(audio_handler_->IsOutputMuted());
96 // Right after the volume up after set_mute recovers to original volume.
97 VolumeUp();
98 EXPECT_FALSE(audio_handler_->IsOutputMuted());
99 EXPECT_EQ(initial_volume, audio_handler_->GetOutputVolumePercent());
101 VolumeMute();
102 // After the volume down, the volume goes down to zero explicitly.
103 VolumeDown();
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
108 // bigger than 0.
109 VolumeUp();
110 EXPECT_LT(0, audio_handler_->GetOutputVolumePercent());
111 EXPECT_GT(initial_volume, audio_handler_->GetOutputVolumePercent());
114 } // namespace