Commit 5a456030 authored by derat's avatar derat Committed by Commit bot

app_shell: Shut down in response to power button.

Also fix a dependency issue in
chromeos_test_support_without_gmock, make
ExtensionsTestSuite call
GLSurface::InitializeOneOffForTests(), and avoid
double-initializating Aura in app_shell.

BUG=405967

Review URL: https://codereview.chromium.org/468393005

Cr-Commit-Position: refs/heads/master@{#291607}
parent 4d6acafd
...@@ -491,6 +491,10 @@ ...@@ -491,6 +491,10 @@
{ {
'target_name': 'chromeos_test_support_without_gmock', 'target_name': 'chromeos_test_support_without_gmock',
'type': 'static_library', 'type': 'static_library',
'export_dependent_settings': [
# fake_power_manager_client.h includes pb.h files.
'power_manager_proto',
],
'dependencies': [ 'dependencies': [
'../build/linux/system.gyp:dbus', '../build/linux/system.gyp:dbus',
'../crypto/crypto.gyp:crypto', '../crypto/crypto.gyp:crypto',
......
...@@ -11,6 +11,7 @@ namespace chromeos { ...@@ -11,6 +11,7 @@ namespace chromeos {
FakePowerManagerClient::FakePowerManagerClient() FakePowerManagerClient::FakePowerManagerClient()
: num_request_restart_calls_(0), : num_request_restart_calls_(0),
num_request_shutdown_calls_(0),
num_set_policy_calls_(0), num_set_policy_calls_(0),
num_set_is_projecting_calls_(0), num_set_is_projecting_calls_(0),
is_projecting_(false) { is_projecting_(false) {
...@@ -30,19 +31,14 @@ void FakePowerManagerClient::RemoveObserver(Observer* observer) { ...@@ -30,19 +31,14 @@ void FakePowerManagerClient::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer); observers_.RemoveObserver(observer);
} }
void FakePowerManagerClient::RequestStatusUpdate() { bool FakePowerManagerClient::HasObserver(Observer* observer) {
} return false;
void FakePowerManagerClient::SetPolicy(
const power_manager::PowerManagementPolicy& policy) {
policy_ = policy;
++num_set_policy_calls_;
} }
void FakePowerManagerClient::RequestShutdown() { void FakePowerManagerClient::DecreaseScreenBrightness(bool allow_off) {
} }
void FakePowerManagerClient::DecreaseScreenBrightness(bool allow_off) { void FakePowerManagerClient::IncreaseScreenBrightness() {
} }
void FakePowerManagerClient::SetScreenBrightnessPercent(double percent, void FakePowerManagerClient::SetScreenBrightnessPercent(double percent,
...@@ -53,32 +49,34 @@ void FakePowerManagerClient::GetScreenBrightnessPercent( ...@@ -53,32 +49,34 @@ void FakePowerManagerClient::GetScreenBrightnessPercent(
const GetScreenBrightnessPercentCallback& callback) { const GetScreenBrightnessPercentCallback& callback) {
} }
base::Closure FakePowerManagerClient::GetSuspendReadinessCallback() { void FakePowerManagerClient::DecreaseKeyboardBrightness() {
return base::Closure();
} }
int FakePowerManagerClient::GetNumPendingSuspendReadinessCallbacks() { void FakePowerManagerClient::IncreaseKeyboardBrightness() {
return 0;
} }
bool FakePowerManagerClient::HasObserver(Observer* observer) { void FakePowerManagerClient::RequestStatusUpdate() {
return false;
} }
void FakePowerManagerClient::RequestRestart() { void FakePowerManagerClient::RequestRestart() {
++num_request_restart_calls_; ++num_request_restart_calls_;
} }
void FakePowerManagerClient::IncreaseKeyboardBrightness() { void FakePowerManagerClient::RequestShutdown() {
++num_request_shutdown_calls_;
} }
void FakePowerManagerClient::IncreaseScreenBrightness() { void FakePowerManagerClient::NotifyUserActivity(
power_manager::UserActivityType type) {
} }
void FakePowerManagerClient::NotifyVideoActivity(bool is_fullscreen) { void FakePowerManagerClient::NotifyVideoActivity(bool is_fullscreen) {
} }
void FakePowerManagerClient::DecreaseKeyboardBrightness() { void FakePowerManagerClient::SetPolicy(
const power_manager::PowerManagementPolicy& policy) {
policy_ = policy;
++num_set_policy_calls_;
} }
void FakePowerManagerClient::SetIsProjecting(bool is_projecting) { void FakePowerManagerClient::SetIsProjecting(bool is_projecting) {
...@@ -86,8 +84,12 @@ void FakePowerManagerClient::SetIsProjecting(bool is_projecting) { ...@@ -86,8 +84,12 @@ void FakePowerManagerClient::SetIsProjecting(bool is_projecting) {
is_projecting_ = is_projecting; is_projecting_ = is_projecting;
} }
void FakePowerManagerClient::NotifyUserActivity( base::Closure FakePowerManagerClient::GetSuspendReadinessCallback() {
power_manager::UserActivityType type) { return base::Closure();
}
int FakePowerManagerClient::GetNumPendingSuspendReadinessCallbacks() {
return 0;
} }
void FakePowerManagerClient::SendSuspendImminent() { void FakePowerManagerClient::SendSuspendImminent() {
...@@ -102,4 +104,11 @@ void FakePowerManagerClient::SendDarkSuspendImminent() { ...@@ -102,4 +104,11 @@ void FakePowerManagerClient::SendDarkSuspendImminent() {
FOR_EACH_OBSERVER(Observer, observers_, DarkSuspendImminent()); FOR_EACH_OBSERVER(Observer, observers_, DarkSuspendImminent());
} }
void FakePowerManagerClient::SendPowerButtonEvent(
bool down,
const base::TimeTicks& timestamp) {
FOR_EACH_OBSERVER(Observer, observers_,
PowerButtonEventReceived(down, timestamp));
}
} // namespace chromeos } // namespace chromeos
...@@ -24,18 +24,13 @@ class FakePowerManagerClient : public PowerManagerClient { ...@@ -24,18 +24,13 @@ class FakePowerManagerClient : public PowerManagerClient {
virtual ~FakePowerManagerClient(); virtual ~FakePowerManagerClient();
power_manager::PowerManagementPolicy& policy() { return policy_; } power_manager::PowerManagementPolicy& policy() { return policy_; }
int num_request_restart_calls() const { int num_request_restart_calls() const { return num_request_restart_calls_; }
return num_request_restart_calls_; int num_request_shutdown_calls() const { return num_request_shutdown_calls_; }
} int num_set_policy_calls() const { return num_set_policy_calls_; }
int num_set_policy_calls() const {
return num_set_policy_calls_;
}
int num_set_is_projecting_calls() const { int num_set_is_projecting_calls() const {
return num_set_is_projecting_calls_; return num_set_is_projecting_calls_;
} }
bool is_projecting() const { bool is_projecting() const { return is_projecting_; }
return is_projecting_;
}
// PowerManagerClient overrides // PowerManagerClient overrides
virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void Init(dbus::Bus* bus) OVERRIDE;
...@@ -68,19 +63,19 @@ class FakePowerManagerClient : public PowerManagerClient { ...@@ -68,19 +63,19 @@ class FakePowerManagerClient : public PowerManagerClient {
void SendSuspendDone(); void SendSuspendDone();
void SendDarkSuspendImminent(); void SendDarkSuspendImminent();
// Notifies observers that the power button has been pressed or released.
void SendPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
private: private:
ObserverList<Observer> observers_; ObserverList<Observer> observers_;
// Last policy passed to SetPolicy(). // Last policy passed to SetPolicy().
power_manager::PowerManagementPolicy policy_; power_manager::PowerManagementPolicy policy_;
// Number of times that RequestRestart() has been called. // Number of times that various methods have been called.
int num_request_restart_calls_; int num_request_restart_calls_;
int num_request_shutdown_calls_;
// Number of times that SetPolicy() has been called.
int num_set_policy_calls_; int num_set_policy_calls_;
// Count the number of times SetIsProjecting() has been called.
int num_set_is_projecting_calls_; int num_set_is_projecting_calls_;
// Last projecting state set in SetIsProjecting(). // Last projecting state set in SetIsProjecting().
......
...@@ -198,9 +198,11 @@ ...@@ -198,9 +198,11 @@
'<(DEPTH)/extensions/extensions.gyp:extensions_shell_and_test_pak', '<(DEPTH)/extensions/extensions.gyp:extensions_shell_and_test_pak',
'<(DEPTH)/extensions/extensions.gyp:extensions_test_support', '<(DEPTH)/extensions/extensions.gyp:extensions_test_support',
'<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/ui/aura/aura.gyp:aura_test_support',
], ],
'sources': [ 'sources': [
'../test/extensions_unittests_main.cc', '../test/extensions_unittests_main.cc',
'browser/shell_desktop_controller_unittest.cc',
'browser/shell_nacl_browser_delegate_unittest.cc', 'browser/shell_nacl_browser_delegate_unittest.cc',
], ],
'conditions': [ 'conditions': [
...@@ -209,6 +211,11 @@ ...@@ -209,6 +211,11 @@
'browser/shell_nacl_browser_delegate_unittest.cc', 'browser/shell_nacl_browser_delegate_unittest.cc',
], ],
}], }],
['chromeos==1', {
'dependencies': [
'<(DEPTH)/chromeos/chromeos.gyp:chromeos_test_support_without_gmock',
],
}],
], ],
}, },
{ {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/omaha_query_params/omaha_query_params.h" #include "components/omaha_query_params/omaha_query_params.h"
#include "content/public/browser/context_factory.h"
#include "content/public/common/result_codes.h" #include "content/public/common/result_codes.h"
#include "content/shell/browser/shell_devtools_delegate.h" #include "content/shell/browser/shell_devtools_delegate.h"
#include "content/shell/browser/shell_net_log.h" #include "content/shell/browser/shell_net_log.h"
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
#include "extensions/shell/browser/shell_omaha_query_params_delegate.h" #include "extensions/shell/browser/shell_omaha_query_params_delegate.h"
#include "extensions/shell/common/shell_extensions_client.h" #include "extensions/shell/common/shell_extensions_client.h"
#include "extensions/shell/common/switches.h" #include "extensions/shell/common/switches.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/base/ime/input_method_initializer.h" #include "ui/base/ime/input_method_initializer.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -95,8 +97,9 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { ...@@ -95,8 +97,9 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
// Initialize our "profile" equivalent. // Initialize our "profile" equivalent.
browser_context_.reset(new ShellBrowserContext); browser_context_.reset(new ShellBrowserContext);
aura::Env::GetInstance()->set_context_factory(content::GetContextFactory());
desktop_controller_.reset(browser_main_delegate_->CreateDesktopController()); desktop_controller_.reset(browser_main_delegate_->CreateDesktopController());
desktop_controller_->CreateRootWindow();
// NOTE: Much of this is culled from chrome/test/base/chrome_test_suite.cc // NOTE: Much of this is culled from chrome/test/base/chrome_test_suite.cc
// TODO(jamescook): Initialize user_manager::UserManager. // TODO(jamescook): Initialize user_manager::UserManager.
......
...@@ -5,12 +5,10 @@ ...@@ -5,12 +5,10 @@
#include "extensions/shell/browser/shell_desktop_controller.h" #include "extensions/shell/browser/shell_desktop_controller.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "content/public/browser/context_factory.h"
#include "extensions/shell/browser/shell_app_window_controller.h" #include "extensions/shell/browser/shell_app_window_controller.h"
#include "extensions/shell/common/switches.h" #include "extensions/shell/common/switches.h"
#include "ui/aura/client/cursor_client.h" #include "ui/aura/client/cursor_client.h"
#include "ui/aura/client/default_capture_client.h" #include "ui/aura/client/default_capture_client.h"
#include "ui/aura/env.h"
#include "ui/aura/layout_manager.h" #include "ui/aura/layout_manager.h"
#include "ui/aura/test/test_screen.h" #include "ui/aura/test/test_screen.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -31,6 +29,7 @@ ...@@ -31,6 +29,7 @@
#include "ui/wm/core/user_activity_detector.h" #include "ui/wm/core/user_activity_detector.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
#include "ui/chromeos/user_activity_power_manager_notifier.h" #include "ui/chromeos/user_activity_power_manager_notifier.h"
#include "ui/display/types/chromeos/display_mode.h" #include "ui/display/types/chromeos/display_mode.h"
#include "ui/display/types/chromeos/display_snapshot.h" #include "ui/display/types/chromeos/display_snapshot.h"
...@@ -157,14 +156,18 @@ ShellDesktopController* g_instance = NULL; ...@@ -157,14 +156,18 @@ ShellDesktopController* g_instance = NULL;
} // namespace } // namespace
ShellDesktopController::ShellDesktopController() { ShellDesktopController::ShellDesktopController() {
CHECK(!g_instance) << "ShellDesktopController already exists";
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
AddObserver(this);
display_configurator_.reset(new ui::DisplayConfigurator); display_configurator_.reset(new ui::DisplayConfigurator);
display_configurator_->Init(false); display_configurator_->Init(false);
display_configurator_->ForceInitialConfigure(0); display_configurator_->ForceInitialConfigure(0);
display_configurator_->AddObserver(this); display_configurator_->AddObserver(this);
#endif #endif
aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(content::GetContextFactory()); CreateRootWindow();
g_instance = this; g_instance = this;
} }
...@@ -173,7 +176,10 @@ ShellDesktopController::~ShellDesktopController() { ...@@ -173,7 +176,10 @@ ShellDesktopController::~ShellDesktopController() {
app_window_controller_.reset(); app_window_controller_.reset();
g_instance = NULL; g_instance = NULL;
DestroyRootWindow(); DestroyRootWindow();
aura::Env::DeleteInstance(); #if defined(OS_CHROMEOS)
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
RemoveObserver(this);
#endif
} }
// static // static
...@@ -210,6 +216,15 @@ aura::Window* ShellDesktopController::GetDefaultParent( ...@@ -210,6 +216,15 @@ aura::Window* ShellDesktopController::GetDefaultParent(
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
void ShellDesktopController::PowerButtonEventReceived(
bool down,
const base::TimeTicks& timestamp) {
if (down) {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
RequestShutdown();
}
}
void ShellDesktopController::OnDisplayModeChanged( void ShellDesktopController::OnDisplayModeChanged(
const std::vector<ui::DisplayConfigurator::DisplayState>& displays) { const std::vector<ui::DisplayConfigurator::DisplayState>& displays) {
gfx::Size size = GetPrimaryDisplaySize(); gfx::Size size = GetPrimaryDisplaySize();
...@@ -226,40 +241,6 @@ void ShellDesktopController::OnHostCloseRequested( ...@@ -226,40 +241,6 @@ void ShellDesktopController::OnHostCloseRequested(
base::MessageLoop::QuitClosure()); base::MessageLoop::QuitClosure());
} }
void ShellDesktopController::CreateRootWindow() {
// Set up basic pieces of ui::wm.
gfx::Size size;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kAppShellHostWindowBounds)) {
const std::string size_str =
command_line->GetSwitchValueASCII(switches::kAppShellHostWindowBounds);
int width, height;
CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height));
size = gfx::Size(width, height);
} else {
size = GetPrimaryDisplaySize();
}
if (size.IsEmpty())
size = gfx::Size(1280, 720);
test_screen_.reset(aura::TestScreen::Create(size));
// TODO(jamescook): Replace this with a real Screen implementation.
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get());
// TODO(mukai): Set up input method.
host_.reset(test_screen_->CreateHostForPrimaryDisplay());
host_->InitHost();
aura::client::SetWindowTreeClient(host_->window(), this);
root_window_event_filter_.reset(new wm::CompoundEventFilter);
host_->window()->AddPreTargetHandler(root_window_event_filter_.get());
InitWindowManager();
host_->AddObserver(this);
// Ensure the X window gets mapped.
host_->Show();
}
void ShellDesktopController::InitWindowManager() { void ShellDesktopController::InitWindowManager() {
wm::FocusController* focus_controller = wm::FocusController* focus_controller =
new wm::FocusController(CreateFocusRules()); new wm::FocusController(CreateFocusRules());
...@@ -300,6 +281,40 @@ wm::FocusRules* ShellDesktopController::CreateFocusRules() { ...@@ -300,6 +281,40 @@ wm::FocusRules* ShellDesktopController::CreateFocusRules() {
return new AppsFocusRules(); return new AppsFocusRules();
} }
void ShellDesktopController::CreateRootWindow() {
// Set up basic pieces of ui::wm.
gfx::Size size;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kAppShellHostWindowBounds)) {
const std::string size_str =
command_line->GetSwitchValueASCII(switches::kAppShellHostWindowBounds);
int width, height;
CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height));
size = gfx::Size(width, height);
} else {
size = GetPrimaryDisplaySize();
}
if (size.IsEmpty())
size = gfx::Size(1280, 720);
test_screen_.reset(aura::TestScreen::Create(size));
// TODO(jamescook): Replace this with a real Screen implementation.
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get());
// TODO(mukai): Set up input method.
host_.reset(test_screen_->CreateHostForPrimaryDisplay());
host_->InitHost();
aura::client::SetWindowTreeClient(host_->window(), this);
root_window_event_filter_.reset(new wm::CompoundEventFilter);
host_->window()->AddPreTargetHandler(root_window_event_filter_.get());
InitWindowManager();
host_->AddObserver(this);
// Ensure the X window gets mapped.
host_->Show();
}
void ShellDesktopController::DestroyRootWindow() { void ShellDesktopController::DestroyRootWindow() {
host_->RemoveObserver(this); host_->RemoveObserver(this);
if (input_method_filter_) if (input_method_filter_)
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ui/aura/window_tree_host_observer.h" #include "ui/aura/window_tree_host_observer.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chromeos/dbus/power_manager_client.h"
#include "ui/display/chromeos/display_configurator.h" #include "ui/display/chromeos/display_configurator.h"
#endif #endif
...@@ -56,12 +57,11 @@ class ShellAppWindowController; ...@@ -56,12 +57,11 @@ class ShellAppWindowController;
// Handles desktop-related tasks for app_shell. // Handles desktop-related tasks for app_shell.
class ShellDesktopController : public aura::client::WindowTreeClient, class ShellDesktopController : public aura::client::WindowTreeClient,
public aura::WindowTreeHostObserver
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
, public chromeos::PowerManagerClient::Observer,
public ui::DisplayConfigurator::Observer public ui::DisplayConfigurator::Observer,
#endif #endif
{ public aura::WindowTreeHostObserver {
public: public:
ShellDesktopController(); ShellDesktopController();
virtual ~ShellDesktopController(); virtual ~ShellDesktopController();
...@@ -73,9 +73,6 @@ class ShellDesktopController : public aura::client::WindowTreeClient, ...@@ -73,9 +73,6 @@ class ShellDesktopController : public aura::client::WindowTreeClient,
aura::WindowTreeHost* host() { return host_.get(); } aura::WindowTreeHost* host() { return host_.get(); }
// Creates the window that hosts the app.
void CreateRootWindow();
// Sets the controller to create/close the app windows. Takes the ownership of // Sets the controller to create/close the app windows. Takes the ownership of
// |app_window_controller|. // |app_window_controller|.
void SetAppWindowController(ShellAppWindowController* app_window_controller); void SetAppWindowController(ShellAppWindowController* app_window_controller);
...@@ -92,12 +89,17 @@ class ShellDesktopController : public aura::client::WindowTreeClient, ...@@ -92,12 +89,17 @@ class ShellDesktopController : public aura::client::WindowTreeClient,
// Sets the screen's work area insets. // Sets the screen's work area insets.
void SetDisplayWorkAreaInsets(const gfx::Insets& insets); void SetDisplayWorkAreaInsets(const gfx::Insets& insets);
// Overridden from aura::client::WindowTreeClient: // aura::client::WindowTreeClient overrides:
virtual aura::Window* GetDefaultParent(aura::Window* context, virtual aura::Window* GetDefaultParent(aura::Window* context,
aura::Window* window, aura::Window* window,
const gfx::Rect& bounds) OVERRIDE; const gfx::Rect& bounds) OVERRIDE;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// chromeos::PowerManagerClient::Observer overrides:
virtual void PowerButtonEventReceived(bool down,
const base::TimeTicks& timestamp)
OVERRIDE;
// ui::DisplayConfigurator::Observer overrides. // ui::DisplayConfigurator::Observer overrides.
virtual void OnDisplayModeChanged(const std::vector< virtual void OnDisplayModeChanged(const std::vector<
ui::DisplayConfigurator::DisplayState>& displays) OVERRIDE; ui::DisplayConfigurator::DisplayState>& displays) OVERRIDE;
...@@ -115,6 +117,9 @@ class ShellDesktopController : public aura::client::WindowTreeClient, ...@@ -115,6 +117,9 @@ class ShellDesktopController : public aura::client::WindowTreeClient,
virtual wm::FocusRules* CreateFocusRules(); virtual wm::FocusRules* CreateFocusRules();
private: private:
// Creates the window that hosts the app.
void CreateRootWindow();
// Closes and destroys the root window hosting the app. // Closes and destroys the root window hosting the app.
void DestroyRootWindow(); void DestroyRootWindow();
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/shell/browser/shell_desktop_controller.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "ui/aura/test/aura_test_base.h"
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_dbus_thread_manager.h"
#include "chromeos/dbus/fake_power_manager_client.h"
#endif
namespace extensions {
class ShellDesktopControllerTest : public aura::test::AuraTestBase {
public:
ShellDesktopControllerTest()
#if defined(OS_CHROMEOS)
: power_manager_client_(NULL)
#endif
{
}
virtual ~ShellDesktopControllerTest() {}
virtual void SetUp() OVERRIDE {
#if defined(OS_CHROMEOS)
chromeos::FakeDBusThreadManager* manager =
new chromeos::FakeDBusThreadManager();
power_manager_client_ = new chromeos::FakePowerManagerClient();
manager->SetPowerManagerClient(make_scoped_ptr(power_manager_client_).
PassAs<chromeos::PowerManagerClient>());
chromeos::DBusThreadManager::InitializeForTesting(manager);
#endif
aura::test::AuraTestBase::SetUp();
controller_.reset(new ShellDesktopController());
}
virtual void TearDown() OVERRIDE {
controller_.reset();
aura::test::AuraTestBase::TearDown();
#if defined(OS_CHROMEOS)
chromeos::DBusThreadManager::Shutdown();
#endif
}
protected:
scoped_ptr<ShellDesktopController> controller_;
#if defined(OS_CHROMEOS)
chromeos::FakePowerManagerClient* power_manager_client_; // Not owned.
#endif
private:
DISALLOW_COPY_AND_ASSIGN(ShellDesktopControllerTest);
};
#if defined(OS_CHROMEOS)
// Tests that a shutdown request is sent to the power manager when the power
// button is pressed.
TEST_F(ShellDesktopControllerTest, PowerButton) {
// Ignore button releases.
power_manager_client_->SendPowerButtonEvent(false /* down */,
base::TimeTicks());
EXPECT_EQ(0, power_manager_client_->num_request_shutdown_calls());
// A button press should trigger a shutdown request.
power_manager_client_->SendPowerButtonEvent(true /* down */,
base::TimeTicks());
EXPECT_EQ(1, power_manager_client_->num_request_shutdown_calls());
}
#endif
} // namespace extensions
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "extensions/test/test_extensions_client.h" #include "extensions/test/test_extensions_client.h"
#include "mojo/embedder/test_embedder.h" #include "mojo/embedder/test_embedder.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gl/gl_surface.h"
namespace { namespace {
...@@ -64,6 +65,7 @@ ExtensionsTestSuite::~ExtensionsTestSuite() {} ...@@ -64,6 +65,7 @@ ExtensionsTestSuite::~ExtensionsTestSuite() {}
void ExtensionsTestSuite::Initialize() { void ExtensionsTestSuite::Initialize() {
content::ContentTestSuiteBase::Initialize(); content::ContentTestSuiteBase::Initialize();
gfx::GLSurface::InitializeOneOffForTests();
// Register the chrome-extension:// scheme via this circuitous path. Note // Register the chrome-extension:// scheme via this circuitous path. Note
// that this does not persistently set up a ContentClient; individual tests // that this does not persistently set up a ContentClient; individual tests
......
...@@ -20,7 +20,10 @@ namespace ui { ...@@ -20,7 +20,10 @@ namespace ui {
InProcessContextFactory::InProcessContextFactory() InProcessContextFactory::InProcessContextFactory()
: shared_bitmap_manager_(new cc::TestSharedBitmapManager()) { : shared_bitmap_manager_(new cc::TestSharedBitmapManager()) {
DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone)
<< "If running tests, ensure that main() is calling "
<< "gfx::GLSurface::InitializeOneOffForTests()";
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
bool use_thread = !CommandLine::ForCurrentProcess()->HasSwitch( bool use_thread = !CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUIDisableThreadedCompositing); switches::kUIDisableThreadedCompositing);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment