Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / extensions / shell / browser / shell_desktop_controller_aura_unittest.cc
blobfc1c01a6a507a915f300ecda49f2fec7a4681d3e
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"
15 #endif
17 namespace extensions {
19 class ShellDesktopControllerAuraTest : public aura::test::AuraTestBase {
20 public:
21 ShellDesktopControllerAuraTest()
22 #if defined(OS_CHROMEOS)
23 : power_manager_client_(NULL)
24 #endif
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_));
35 #endif
36 aura::test::AuraTestBase::SetUp();
37 controller_.reset(new ShellDesktopControllerAura());
40 void TearDown() override {
41 controller_.reset();
42 aura::test::AuraTestBase::TearDown();
43 #if defined(OS_CHROMEOS)
44 chromeos::DBusThreadManager::Shutdown();
45 #endif
48 protected:
49 scoped_ptr<ShellDesktopControllerAura> controller_;
51 #if defined(OS_CHROMEOS)
52 chromeos::FakePowerManagerClient* power_manager_client_; // Not owned.
53 #endif
55 private:
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
61 // button is pressed.
62 TEST_F(ShellDesktopControllerAuraTest, PowerButton) {
63 // Ignore button releases.
64 power_manager_client_->SendPowerButtonEvent(false /* down */,
65 base::TimeTicks());
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 */,
70 base::TimeTicks());
71 EXPECT_EQ(1, power_manager_client_->num_request_shutdown_calls());
73 #endif
75 } // namespace extensions