summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-13 17:33:12 +0000
committerjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-13 17:33:12 +0000
commit6d8c8f05dfb699ff860908602f86b7a14a2c0be1 (patch)
tree14123ded1941244e7b292bae12e9bf454cb32a19 /ash
parentbfa6ecc67b157bc3f54cbce4e37f20e9b3915cf2 (diff)
downloadchromium_src-6d8c8f05dfb699ff860908602f86b7a14a2c0be1.zip
chromium_src-6d8c8f05dfb699ff860908602f86b7a14a2c0be1.tar.gz
chromium_src-6d8c8f05dfb699ff860908602f86b7a14a2c0be1.tar.bz2
Initialize CrasAudioHandler for testing in ash_unittests and ash_shell startup cases.
BUG=237513 R=jamescook@chromium.org, xiyuan@chromium.org Review URL: https://codereview.chromium.org/14757010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199757 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/ash_switches.cc14
-rw-r--r--ash/ash_switches.h6
-rw-r--r--ash/shell/content_client/shell_browser_main_parts.cc18
-rw-r--r--ash/system/chromeos/audio/tray_audio.cc37
-rw-r--r--ash/test/ash_test_helper.cc24
5 files changed, 68 insertions, 31 deletions
diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc
index 72cfd9d..fe707f2 100644
--- a/ash/ash_switches.cc
+++ b/ash/ash_switches.cc
@@ -4,6 +4,8 @@
#include "ash/ash_switches.h"
+#include "base/command_line.h"
+
namespace ash {
namespace switches {
@@ -148,5 +150,17 @@ const char kAshDragAndDropAppListToLauncher[] =
// Enables a mode which enforces all browser & application windows to be created
// in maximized mode.
const char kForcedMaximizeMode[] = "forced-maximize-mode";
+
+bool UseNewAudioHandler() {
+ return !CommandLine::ForCurrentProcess()->
+ HasSwitch(ash::switches::kAshDisableNewAudioHandler);
+}
+
+bool ShowAudioDeviceMenu() {
+ return ash::switches::UseNewAudioHandler() &&
+ CommandLine::ForCurrentProcess()->
+ HasSwitch(ash::switches::kAshEnableAudioDeviceMenu);
+}
+
} // namespace switches
} // namespace ash
diff --git a/ash/ash_switches.h b/ash/ash_switches.h
index c195c3e..139a27b 100644
--- a/ash/ash_switches.h
+++ b/ash/ash_switches.h
@@ -57,6 +57,12 @@ ASH_EXPORT extern const char kForceAshToDesktop[];
#endif
ASH_EXPORT extern const char kForcedMaximizeMode[];
+// Returns true if new audio handler should be used.
+ASH_EXPORT bool UseNewAudioHandler();
+
+// Returns true if we should show the audio device switching UI.
+ASH_EXPORT bool ShowAudioDeviceMenu();
+
} // namespace switches
} // namespace ash
diff --git a/ash/shell/content_client/shell_browser_main_parts.cc b/ash/shell/content_client/shell_browser_main_parts.cc
index b2393e6..eab497b 100644
--- a/ash/shell/content_client/shell_browser_main_parts.cc
+++ b/ash/shell/content_client/shell_browser_main_parts.cc
@@ -4,6 +4,7 @@
#include "ash/shell/content_client/shell_browser_main_parts.h"
+#include "ash/ash_switches.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/shell.h"
#include "ash/shell/shell_delegate_impl.h"
@@ -40,6 +41,7 @@
#endif
#if defined(OS_CHROMEOS)
+#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#endif
@@ -48,6 +50,7 @@ namespace shell {
void InitWindowTypeLauncher();
namespace {
+
class ShellViewsDelegate : public views::TestViewsDelegate {
public:
ShellViewsDelegate() {}
@@ -114,6 +117,15 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
// g_browser_process.
message_center::MessageCenter::Initialize();
#endif
+
+#if defined(OS_CHROMEOS)
+ if (ash::switches::UseNewAudioHandler()) {
+ // Create CrasAudioHandler for testing since g_browser_process
+ // is absent.
+ chromeos::CrasAudioHandler::InitializeForTesting();
+ }
+#endif
+
ash::Shell::CreateInstance(delegate_);
ash::Shell::GetInstance()->set_browser_context(browser_context_.get());
@@ -147,6 +159,12 @@ void ShellBrowserMainParts::PostMainMessageLoopRun() {
// g_browser_process.
message_center::MessageCenter::Shutdown();
#endif
+
+#if defined(OS_CHROMEOS)
+ if (ash::switches::UseNewAudioHandler())
+ chromeos::CrasAudioHandler::Shutdown();
+#endif
+
aura::Env::DeleteInstance();
// The keyboard may have created a WebContents. The WebContents is destroyed
diff --git a/ash/system/chromeos/audio/tray_audio.cc b/ash/system/chromeos/audio/tray_audio.cc
index 102bb29..7d85e08 100644
--- a/ash/system/chromeos/audio/tray_audio.cc
+++ b/ash/system/chromeos/audio/tray_audio.cc
@@ -17,7 +17,6 @@
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/volume_control_delegate.h"
-#include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "grit/ash_resources.h"
@@ -56,20 +55,8 @@ const int kNoAudioDeviceIcon = -1;
// four are used for ascending volume levels.
const int kVolumeLevels = 4;
-bool UseNewAudioHandler() {
- return !CommandLine::ForCurrentProcess()->
- HasSwitch(ash::switches::kAshDisableNewAudioHandler);
-}
-
-// Returns true if we should show the audio device switching UI.
-bool ShowAudioDeviceMenu() {
- return UseNewAudioHandler() &&
- CommandLine::ForCurrentProcess()->
- HasSwitch(ash::switches::kAshEnableAudioDeviceMenu);
-}
-
bool IsAudioMuted() {
- if(UseNewAudioHandler()) {
+ if(ash::switches::UseNewAudioHandler()) {
return chromeos::CrasAudioHandler::Get()->IsOutputMuted();
} else {
return Shell::GetInstance()->system_tray_delegate()->
@@ -78,7 +65,7 @@ bool IsAudioMuted() {
}
float GetVolumeLevel() {
- if (UseNewAudioHandler()) {
+ if (ash::switches::UseNewAudioHandler()) {
return chromeos::CrasAudioHandler::Get()->GetOutputVolumePercent() / 100.0f;
} else {
return Shell::GetInstance()->system_tray_delegate()->
@@ -248,7 +235,7 @@ class VolumeView : public ActionableView,
private:
// Updates bar_, device_type_ icon, and more_ buttons.
void UpdateDeviceTypeAndMore() {
- if (!ShowAudioDeviceMenu() || !is_default_view_) {
+ if (!ash::switches::ShowAudioDeviceMenu() || !is_default_view_) {
more_->SetVisible(false);
bar_->SetVisible(false);
device_type_->SetVisible(false);
@@ -321,7 +308,7 @@ class VolumeView : public ActionableView,
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE {
CHECK(sender == icon_);
- if (UseNewAudioHandler()) {
+ if (ash::switches::UseNewAudioHandler()) {
chromeos::CrasAudioHandler::Get()->SetOutputMute(!IsAudioMuted());
} else {
ash::Shell::GetInstance()->system_tray_delegate()->
@@ -335,7 +322,7 @@ class VolumeView : public ActionableView,
float old_value,
views::SliderChangeReason reason) OVERRIDE {
if (reason == views::VALUE_CHANGED_BY_USER) {
- if (UseNewAudioHandler()) {
+ if (ash::switches::UseNewAudioHandler()) {
chromeos::CrasAudioHandler::Get()->
SetOutputVolumePercent(value * 100.0f);
}
@@ -486,14 +473,14 @@ TrayAudio::TrayAudio(SystemTray* system_tray)
volume_view_(NULL),
audio_detail_(NULL),
pop_up_volume_view_(false) {
- if (UseNewAudioHandler())
+ if (ash::switches::UseNewAudioHandler())
chromeos::CrasAudioHandler::Get()->AddAudioObserver(this);
else
Shell::GetInstance()->system_tray_notifier()->AddAudioObserver(this);
}
TrayAudio::~TrayAudio() {
- if (UseNewAudioHandler()) {
+ if (ash::switches::UseNewAudioHandler()) {
if (chromeos::CrasAudioHandler::IsInitialized())
chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this);
} else {
@@ -511,7 +498,7 @@ views::View* TrayAudio::CreateDefaultView(user::LoginStatus status) {
}
views::View* TrayAudio::CreateDetailedView(user::LoginStatus status) {
- if (!ShowAudioDeviceMenu() || pop_up_volume_view_) {
+ if (!ash::switches::ShowAudioDeviceMenu() || pop_up_volume_view_) {
volume_view_ = new tray::VolumeView(this, false);
return volume_view_;
} else {
@@ -542,7 +529,7 @@ bool TrayAudio::ShouldShowLauncher() const {
}
void TrayAudio::OnVolumeChanged(float percent) {
- DCHECK(!UseNewAudioHandler());
+ DCHECK(!ash::switches::UseNewAudioHandler());
if (tray_view())
tray_view()->SetVisible(GetInitialVisibility());
@@ -557,7 +544,7 @@ void TrayAudio::OnVolumeChanged(float percent) {
}
void TrayAudio::OnMuteToggled() {
- DCHECK(!UseNewAudioHandler());
+ DCHECK(!ash::switches::UseNewAudioHandler());
if (tray_view())
tray_view()->SetVisible(GetInitialVisibility());
@@ -569,7 +556,7 @@ void TrayAudio::OnMuteToggled() {
void TrayAudio::OnOutputVolumeChanged() {
- DCHECK(UseNewAudioHandler());
+ DCHECK(ash::switches::UseNewAudioHandler());
float percent = GetVolumeLevel();
if (tray_view())
tray_view()->SetVisible(GetInitialVisibility());
@@ -584,7 +571,7 @@ void TrayAudio::OnOutputVolumeChanged() {
}
void TrayAudio::OnOutputMuteChanged() {
- DCHECK(UseNewAudioHandler());
+ DCHECK(ash::switches::UseNewAudioHandler());
if (tray_view())
tray_view()->SetVisible(GetInitialVisibility());
diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc
index c95fe28..6392f3a 100644
--- a/ash/test/ash_test_helper.cc
+++ b/ash/test/ash_test_helper.cc
@@ -9,17 +9,19 @@
#include "ash/test/display_manager_test_api.h"
#include "ash/test/shell_test_api.h"
#include "ash/test/test_shell_delegate.h"
-#include "base/command_line.h"
#include "base/run_loop.h"
#include "ui/aura/env.h"
#include "ui/base/ime/text_input_test_support.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
-
#if defined(ENABLE_MESSAGE_CENTER)
#include "ui/message_center/message_center.h"
#endif
+#if defined(OS_CHROMEOS)
+#include "chromeos/audio/cras_audio_handler.h"
+#endif
+
namespace ash {
namespace test {
@@ -33,10 +35,6 @@ AshTestHelper::~AshTestHelper() {
}
void AshTestHelper::SetUp() {
- // TODO(jennyz): Create mock or test AudioHandler so we can instantiate
- // an ash::Shell with the new CrasAudioHandler. crbug.com/233266
- CommandLine::ForCurrentProcess()->AppendSwitch(
- ash::switches::kAshDisableNewAudioHandler);
// Disable animations during tests.
zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
@@ -50,6 +48,15 @@ void AshTestHelper::SetUp() {
// tests.
message_center::MessageCenter::Initialize();
#endif
+
+#if defined(OS_CHROMEOS)
+ if (ash::switches::UseNewAudioHandler()) {
+ // Create CrasAuidoHandler for testing since g_browser_process is not
+ // created in AshTestBase tests.
+ chromeos::CrasAudioHandler::InitializeForTesting();
+ }
+#endif
+
ash::Shell::CreateInstance(test_shell_delegate_);
Shell* shell = Shell::GetInstance();
test::DisplayManagerTestApi(shell->display_manager()).
@@ -67,6 +74,11 @@ void AshTestHelper::TearDown() {
message_center::MessageCenter::Shutdown();
#endif
+#if defined(OS_CHROMEOS)
+ if (ash::switches::UseNewAudioHandler())
+ chromeos::CrasAudioHandler::Shutdown();
+#endif
+
aura::Env::DeleteInstance();
ui::TextInputTestSupport::Shutdown();