1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/shell/browser/shell_desktop_controller.h"
7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
10 #include "ui/aura/test/aura_test_base.h"
12 #if defined(OS_CHROMEOS)
13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/fake_power_manager_client.h"
17 namespace extensions
{
19 class ShellDesktopControllerTest
: public aura::test::AuraTestBase
{
21 ShellDesktopControllerTest()
22 #if defined(OS_CHROMEOS)
23 : power_manager_client_(NULL
)
27 virtual ~ShellDesktopControllerTest() {}
29 virtual void SetUp() override
{
30 #if defined(OS_CHROMEOS)
31 scoped_ptr
<chromeos::DBusThreadManagerSetter
> dbus_setter
=
32 chromeos::DBusThreadManager::GetSetterForTesting();
33 power_manager_client_
= new chromeos::FakePowerManagerClient();
34 dbus_setter
->SetPowerManagerClient(make_scoped_ptr(power_manager_client_
).
35 PassAs
<chromeos::PowerManagerClient
>());
37 aura::test::AuraTestBase::SetUp();
38 controller_
.reset(new ShellDesktopController());
41 virtual void TearDown() override
{
43 aura::test::AuraTestBase::TearDown();
44 #if defined(OS_CHROMEOS)
45 chromeos::DBusThreadManager::Shutdown();
50 scoped_ptr
<ShellDesktopController
> controller_
;
52 #if defined(OS_CHROMEOS)
53 chromeos::FakePowerManagerClient
* power_manager_client_
; // Not owned.
57 DISALLOW_COPY_AND_ASSIGN(ShellDesktopControllerTest
);
60 #if defined(OS_CHROMEOS)
61 // Tests that a shutdown request is sent to the power manager when the power
63 TEST_F(ShellDesktopControllerTest
, PowerButton
) {
64 // Ignore button releases.
65 power_manager_client_
->SendPowerButtonEvent(false /* down */,
67 EXPECT_EQ(0, power_manager_client_
->num_request_shutdown_calls());
69 // A button press should trigger a shutdown request.
70 power_manager_client_
->SendPowerButtonEvent(true /* down */,
72 EXPECT_EQ(1, power_manager_client_
->num_request_shutdown_calls());
76 } // namespace extensions