| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/ash_switches.h" |
| 6 #include "base/command_line.h" |
| 7 #include "base/memory/scoped_ptr.h" |
| 5 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 6 #include "chrome/browser/chromeos/audio/audio_handler.h" | 9 #include "chrome/browser/chromeos/audio/audio_handler.h" |
| 7 #include "chrome/browser/chromeos/audio/audio_mixer.h" | 10 #include "chrome/browser/chromeos/audio/audio_mixer.h" |
| 8 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" | 11 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" |
| 9 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "chromeos/audio/audio_pref_handler.h" | 14 #include "chromeos/audio/audio_pref_handler.h" |
| 12 #include "ui/base/accelerators/accelerator.h" | 15 #include "ui/base/accelerators/accelerator.h" |
| 13 | 16 |
| 14 namespace { | 17 namespace { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 78 |
| 76 DISALLOW_COPY_AND_ASSIGN(MockAudioMixer); | 79 DISALLOW_COPY_AND_ASSIGN(MockAudioMixer); |
| 77 }; | 80 }; |
| 78 | 81 |
| 79 // This class has to be browsertest because AudioHandler uses prefs_service. | 82 // This class has to be browsertest because AudioHandler uses prefs_service. |
| 80 class VolumeControllerTest : public InProcessBrowserTest { | 83 class VolumeControllerTest : public InProcessBrowserTest { |
| 81 public: | 84 public: |
| 82 VolumeControllerTest() {} | 85 VolumeControllerTest() {} |
| 83 | 86 |
| 84 virtual void SetUpOnMainThread() OVERRIDE { | 87 virtual void SetUpOnMainThread() OVERRIDE { |
| 88 volume_controller_.reset(new VolumeController()); |
| 89 |
| 85 // First we should shutdown the default audio handler. | 90 // First we should shutdown the default audio handler. |
| 86 chromeos::AudioHandler::Shutdown(); | 91 chromeos::AudioHandler::Shutdown(); |
| 87 audio_mixer_ = new MockAudioMixer; | 92 audio_mixer_ = new MockAudioMixer; |
| 88 chromeos::AudioHandler::InitializeForTesting(audio_mixer_, | 93 chromeos::AudioHandler::InitializeForTesting(audio_mixer_, |
| 89 chromeos::AudioPrefHandler::Create(g_browser_process->local_state())); | 94 chromeos::AudioPrefHandler::Create(g_browser_process->local_state())); |
| 90 } | 95 } |
| 91 | 96 |
| 92 virtual void CleanUpOnMainThread() OVERRIDE { | 97 virtual void CleanUpOnMainThread() OVERRIDE { |
| 93 chromeos::AudioHandler::Shutdown(); | 98 chromeos::AudioHandler::Shutdown(); |
| 94 audio_mixer_ = NULL; | 99 audio_mixer_ = NULL; |
| 95 } | 100 } |
| 96 | 101 |
| 102 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 103 // TODO(rkc,jennyz): Remove this once we remove the old Audio Handler. |
| 104 command_line->AppendSwitch(ash::switches::kAshDisableNewAudioHandler); |
| 105 } |
| 106 |
| 97 protected: | 107 protected: |
| 98 void SetVolumePercent(double percent) { | 108 void SetVolumePercent(double percent) { |
| 99 volume_controller_.SetVolumePercent(percent); | 109 volume_controller_->SetVolumePercent(percent); |
| 100 } | 110 } |
| 101 | 111 |
| 102 void VolumeMute() { | 112 void VolumeMute() { |
| 103 volume_controller_.HandleVolumeMute(ui::Accelerator()); | 113 volume_controller_->HandleVolumeMute(ui::Accelerator()); |
| 104 } | 114 } |
| 105 | 115 |
| 106 void VolumeUnmute() { | 116 void VolumeUnmute() { |
| 107 volume_controller_.SetAudioMuted(false); | 117 volume_controller_->SetAudioMuted(false); |
| 108 } | 118 } |
| 109 | 119 |
| 110 void VolumeUp() { | 120 void VolumeUp() { |
| 111 volume_controller_.HandleVolumeUp(ui::Accelerator()); | 121 volume_controller_->HandleVolumeUp(ui::Accelerator()); |
| 112 } | 122 } |
| 113 | 123 |
| 114 void VolumeDown() { | 124 void VolumeDown() { |
| 115 volume_controller_.HandleVolumeDown(ui::Accelerator()); | 125 volume_controller_->HandleVolumeDown(ui::Accelerator()); |
| 116 } | 126 } |
| 117 | 127 |
| 118 MockAudioMixer* audio_mixer() { return audio_mixer_; } | 128 MockAudioMixer* audio_mixer() { return audio_mixer_; } |
| 119 | 129 |
| 120 private: | 130 private: |
| 121 VolumeController volume_controller_; | 131 scoped_ptr<VolumeController> volume_controller_; |
| 122 MockAudioMixer* audio_mixer_; | 132 MockAudioMixer* audio_mixer_; |
| 123 | 133 |
| 124 DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest); | 134 DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest); |
| 125 }; | 135 }; |
| 126 | 136 |
| 127 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) { | 137 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) { |
| 128 // Set initial value as 50% | 138 // Set initial value as 50% |
| 129 audio_mixer()->SetVolumePercent(50.0); | 139 audio_mixer()->SetVolumePercent(50.0); |
| 130 | 140 |
| 131 double initial_volume = audio_mixer()->GetVolumePercent(); | 141 double initial_volume = audio_mixer()->GetVolumePercent(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent()); | 214 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent()); |
| 205 | 215 |
| 206 // Thus, further VolumeUp doesn't recover the volume, it's just slightly | 216 // Thus, further VolumeUp doesn't recover the volume, it's just slightly |
| 207 // bigger than 0. | 217 // bigger than 0. |
| 208 VolumeUp(); | 218 VolumeUp(); |
| 209 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent()); | 219 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent()); |
| 210 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent()); | 220 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent()); |
| 211 } | 221 } |
| 212 | 222 |
| 213 } // namespace | 223 } // namespace |
| OLD | NEW |