Chromium Code Reviews| 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; |
|
James Cook
2013/04/30 23:31:21
Perhaps not necessary, but I would do volume_contr
rkc
2013/04/30 23:36:37
It's a scoped_ptr, the next .reset will cleanup th
| |
| 95 } | 100 } |
| 96 | 101 |
| 102 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 103 command_line->AppendSwitch(ash::switches::kAshDisableNewAudioHandler); | |
|
James Cook
2013/04/30 23:31:21
Maybe a todo and a bug to track fixing this test?
rkc
2013/04/30 23:36:37
Added the TODO. Once we remove the old Audio Handl
| |
| 104 } | |
| 105 | |
| 97 protected: | 106 protected: |
| 98 void SetVolumePercent(double percent) { | 107 void SetVolumePercent(double percent) { |
| 99 volume_controller_.SetVolumePercent(percent); | 108 volume_controller_->SetVolumePercent(percent); |
| 100 } | 109 } |
| 101 | 110 |
| 102 void VolumeMute() { | 111 void VolumeMute() { |
| 103 volume_controller_.HandleVolumeMute(ui::Accelerator()); | 112 volume_controller_->HandleVolumeMute(ui::Accelerator()); |
| 104 } | 113 } |
| 105 | 114 |
| 106 void VolumeUnmute() { | 115 void VolumeUnmute() { |
| 107 volume_controller_.SetAudioMuted(false); | 116 volume_controller_->SetAudioMuted(false); |
| 108 } | 117 } |
| 109 | 118 |
| 110 void VolumeUp() { | 119 void VolumeUp() { |
| 111 volume_controller_.HandleVolumeUp(ui::Accelerator()); | 120 volume_controller_->HandleVolumeUp(ui::Accelerator()); |
| 112 } | 121 } |
| 113 | 122 |
| 114 void VolumeDown() { | 123 void VolumeDown() { |
| 115 volume_controller_.HandleVolumeDown(ui::Accelerator()); | 124 volume_controller_->HandleVolumeDown(ui::Accelerator()); |
| 116 } | 125 } |
| 117 | 126 |
| 118 MockAudioMixer* audio_mixer() { return audio_mixer_; } | 127 MockAudioMixer* audio_mixer() { return audio_mixer_; } |
| 119 | 128 |
| 120 private: | 129 private: |
| 121 VolumeController volume_controller_; | 130 scoped_ptr<VolumeController> volume_controller_; |
| 122 MockAudioMixer* audio_mixer_; | 131 MockAudioMixer* audio_mixer_; |
| 123 | 132 |
| 124 DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest); | 133 DISALLOW_COPY_AND_ASSIGN(VolumeControllerTest); |
| 125 }; | 134 }; |
| 126 | 135 |
| 127 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) { | 136 IN_PROC_BROWSER_TEST_F(VolumeControllerTest, VolumeUpAndDown) { |
| 128 // Set initial value as 50% | 137 // Set initial value as 50% |
| 129 audio_mixer()->SetVolumePercent(50.0); | 138 audio_mixer()->SetVolumePercent(50.0); |
| 130 | 139 |
| 131 double initial_volume = audio_mixer()->GetVolumePercent(); | 140 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()); | 213 EXPECT_DOUBLE_EQ(0.0, audio_mixer()->GetVolumePercent()); |
| 205 | 214 |
| 206 // Thus, further VolumeUp doesn't recover the volume, it's just slightly | 215 // Thus, further VolumeUp doesn't recover the volume, it's just slightly |
| 207 // bigger than 0. | 216 // bigger than 0. |
| 208 VolumeUp(); | 217 VolumeUp(); |
| 209 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent()); | 218 EXPECT_LT(0.0, audio_mixer()->GetVolumePercent()); |
| 210 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent()); | 219 EXPECT_GT(initial_volume, audio_mixer()->GetVolumePercent()); |
| 211 } | 220 } |
| 212 | 221 |
| 213 } // namespace | 222 } // namespace |
| OLD | NEW |