Convert env to a defaultdict in run_executable() to fix other callers of that function.
[chromium-blink-merge.git] / extensions / shell / browser / shell_desktop_controller_unittest.cc
blobb5cac17792415cc04e7dbabf383fefbf059bbff7
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"
15 #endif
17 namespace extensions {
19 class ShellDesktopControllerTest : public aura::test::AuraTestBase {
20 public:
21 ShellDesktopControllerTest()
22 #if defined(OS_CHROMEOS)
23 : power_manager_client_(NULL)
24 #endif
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>());
36 #endif
37 aura::test::AuraTestBase::SetUp();
38 controller_.reset(new ShellDesktopController());
41 virtual void TearDown() override {
42 controller_.reset();
43 aura::test::AuraTestBase::TearDown();
44 #if defined(OS_CHROMEOS)
45 chromeos::DBusThreadManager::Shutdown();
46 #endif
49 protected:
50 scoped_ptr<ShellDesktopController> controller_;
52 #if defined(OS_CHROMEOS)
53 chromeos::FakePowerManagerClient* power_manager_client_; // Not owned.
54 #endif
56 private:
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
62 // button is pressed.
63 TEST_F(ShellDesktopControllerTest, PowerButton) {
64 // Ignore button releases.
65 power_manager_client_->SendPowerButtonEvent(false /* down */,
66 base::TimeTicks());
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 */,
71 base::TimeTicks());
72 EXPECT_EQ(1, power_manager_client_->num_request_shutdown_calls());
74 #endif
76 } // namespace extensions