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_aura.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 ShellDesktopControllerAuraTest
: public aura::test::AuraTestBase
{
21 ShellDesktopControllerAuraTest()
22 #if defined(OS_CHROMEOS)
23 : power_manager_client_(NULL
)
27 ~ShellDesktopControllerAuraTest() override
{}
29 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_
));
36 aura::test::AuraTestBase::SetUp();
37 controller_
.reset(new ShellDesktopControllerAura());
40 void TearDown() override
{
42 aura::test::AuraTestBase::TearDown();
43 #if defined(OS_CHROMEOS)
44 chromeos::DBusThreadManager::Shutdown();
49 scoped_ptr
<ShellDesktopControllerAura
> controller_
;
51 #if defined(OS_CHROMEOS)
52 chromeos::FakePowerManagerClient
* power_manager_client_
; // Not owned.
56 DISALLOW_COPY_AND_ASSIGN(ShellDesktopControllerAuraTest
);
59 #if defined(OS_CHROMEOS)
60 // Tests that a shutdown request is sent to the power manager when the power
62 TEST_F(ShellDesktopControllerAuraTest
, PowerButton
) {
63 // Ignore button releases.
64 power_manager_client_
->SendPowerButtonEvent(false /* down */,
66 EXPECT_EQ(0, power_manager_client_
->num_request_shutdown_calls());
68 // A button press should trigger a shutdown request.
69 power_manager_client_
->SendPowerButtonEvent(true /* down */,
71 EXPECT_EQ(1, power_manager_client_
->num_request_shutdown_calls());
75 } // namespace extensions