volume_controller_browsertest_chromeos.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <vector>
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/ash_switches.h"
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/command_line.h"
9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/browser_process.h"
11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/ui/ash/volume_controller_chromeos.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/audio/chromeos_sounds.h"
14558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "chromeos/audio/cras_audio_handler.h"
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/chromeos_switches.h"
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "media/audio/sounds/sounds_manager.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/accelerators/accelerator.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class SoundsManagerTestImpl : public media::SoundsManager {
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SoundsManagerTestImpl()
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : is_sound_initialized_(chromeos::SOUND_COUNT),
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      num_play_requests_(chromeos::SOUND_COUNT) {
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~SoundsManagerTestImpl() {}
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool Initialize(SoundKey key,
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                          const base::StringPiece& /* data */) OVERRIDE {
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    is_sound_initialized_[key] = true;
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool Play(SoundKey key) OVERRIDE {
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ++num_play_requests_[key];
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::TimeDelta GetDuration(SoundKey /* key */) OVERRIDE {
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::TimeDelta();
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool is_sound_initialized(SoundKey key) const {
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return is_sound_initialized_[key];
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int num_play_requests(SoundKey key) const {
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return num_play_requests_[key];
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<bool> is_sound_initialized_;
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<int> num_play_requests_;
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SoundsManagerTestImpl);
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class VolumeControllerTest : public InProcessBrowserTest {
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeControllerTest() {}
63558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  virtual ~VolumeControllerTest() {}
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetUpOnMainThread() OVERRIDE {
66c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    volume_controller_.reset(new VolumeController());
67558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch    audio_handler_ = chromeos::CrasAudioHandler::Get();
68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void VolumeMute() {
72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    volume_controller_->HandleVolumeMute(ui::Accelerator());
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void VolumeUp() {
76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    volume_controller_->HandleVolumeUp(ui::Accelerator());
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void VolumeDown() {
80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    volume_controller_->HandleVolumeDown(ui::Accelerator());
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
83558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  chromeos::CrasAudioHandler* audio_handler_;  // Not owned.
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  scoped_ptr<VolumeController> volume_controller_;
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest);
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) {
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set initial value as 50%
93558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  const int kInitVolume = 50;
94558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  audio_handler_->SetOutputVolumePercent(kInitVolume);
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
96558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_EQ(audio_handler_->GetOutputVolumePercent(), kInitVolume);
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeUp();
99558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_LT(kInitVolume, audio_handler_->GetOutputVolumePercent());
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeDown();
101558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_EQ(kInitVolume, audio_handler_->GetOutputVolumePercent());
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeDown();
103558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_GT(kInitVolume, audio_handler_->GetOutputVolumePercent());
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeDownToZero) {
107558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Setting to very small volume.
108558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  audio_handler_->SetOutputVolumePercent(1);
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeDown();
111558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent());
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeDown();
113558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent());
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeUp();
115558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_LT(0, audio_handler_->GetOutputVolumePercent());
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpTo100) {
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Setting to almost max
120558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  audio_handler_->SetOutputVolumePercent(99);
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeUp();
123558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_EQ(100, audio_handler_->GetOutputVolumePercent());
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeUp();
125558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_EQ(100, audio_handler_->GetOutputVolumePercent());
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeDown();
127558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_GT(100, audio_handler_->GetOutputVolumePercent());
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(VolumeControllerTest, Mutes) {
131558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  ASSERT_FALSE(audio_handler_->IsOutputMuted());
132558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  const int initial_volume = audio_handler_->GetOutputVolumePercent();
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeMute();
135558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_TRUE(audio_handler_->IsOutputMuted());
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Further mute buttons doesn't have effects.
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeMute();
139558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_TRUE(audio_handler_->IsOutputMuted());
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Right after the volume up after set_mute recovers to original volume.
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeUp();
143558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_FALSE(audio_handler_->IsOutputMuted());
144558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_EQ(initial_volume, audio_handler_->GetOutputVolumePercent());
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeMute();
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // After the volume down, the volume goes down to zero explicitly.
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeDown();
149558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_TRUE(audio_handler_->IsOutputMuted());
150558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_EQ(0, audio_handler_->GetOutputVolumePercent());
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Thus, further VolumeUp doesn't recover the volume, it's just slightly
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // bigger than 0.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VolumeUp();
155558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_LT(0, audio_handler_->GetOutputVolumePercent());
156558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  EXPECT_GT(initial_volume, audio_handler_->GetOutputVolumePercent());
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class VolumeControllerSoundsTest : public VolumeControllerTest {
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeControllerSoundsTest() : sounds_manager_(NULL) {}
1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~VolumeControllerSoundsTest() {}
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    sounds_manager_ = new SoundsManagerTestImpl();
1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    media::SoundsManager::InitializeForTesting(sounds_manager_);
1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    VolumeControllerTest::SetUpCommandLine(command_line);
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    command_line->AppendSwitch(ash::switches::kAshEnableSystemSounds);
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool is_sound_initialized() const {
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return sounds_manager_->is_sound_initialized(
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        chromeos::SOUND_VOLUME_ADJUST);
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int num_play_requests() const {
1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return sounds_manager_->num_play_requests(chromeos::SOUND_VOLUME_ADJUST);
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SoundsManagerTestImpl* sounds_manager_;
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(VolumeControllerSoundsTest);
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(VolumeControllerSoundsTest, VolumeAdjustSounds) {
1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(is_sound_initialized());
1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Check that sound is played on volume up and volume down.
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  audio_handler_->SetOutputVolumePercent(50);
1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeUp();
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(1, num_play_requests());
1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeDown();
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(2, num_play_requests());
1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  audio_handler_->SetOutputVolumePercent(99);
2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeUp();
2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(3, num_play_requests());
2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  audio_handler_->SetOutputVolumePercent(100);
2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeUp();
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(3, num_play_requests());
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Check that sound isn't played when audio is muted.
2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  audio_handler_->SetOutputVolumePercent(50);
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeMute();
2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeDown();
2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(audio_handler_->IsOutputMuted());
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(3, num_play_requests());
2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Check that audio is unmuted and sound is played.
2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeUp();
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_FALSE(audio_handler_->IsOutputMuted());
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(4, num_play_requests());
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class VolumeControllerSoundsDisabledTest : public VolumeControllerSoundsTest {
2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeControllerSoundsDisabledTest() {}
2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~VolumeControllerSoundsDisabledTest() {}
2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    VolumeControllerSoundsTest::SetUpCommandLine(command_line);
2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    command_line->AppendSwitch(chromeos::switches::kDisableVolumeAdjustSound);
2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(VolumeControllerSoundsDisabledTest);
2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(VolumeControllerSoundsDisabledTest,
2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       VolumeAdjustSounds) {
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(is_sound_initialized());
2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Check that sound isn't played on volume up and volume down.
2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  audio_handler_->SetOutputVolumePercent(50);
2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeUp();
2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VolumeDown();
2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(0, num_play_requests());
2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
246