| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/power_policy_controller.h" | 5 #include "chromeos/dbus/power_policy_controller.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/fake_dbus_thread_manager.h" | |
| 10 #include "chromeos/dbus/fake_power_manager_client.h" | 9 #include "chromeos/dbus/fake_power_manager_client.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 12 |
| 14 using ::testing::_; | 13 using ::testing::_; |
| 15 using ::testing::SaveArg; | 14 using ::testing::SaveArg; |
| 16 | 15 |
| 17 namespace chromeos { | 16 namespace chromeos { |
| 18 | 17 |
| 19 class PowerPolicyControllerTest : public testing::Test { | 18 class PowerPolicyControllerTest : public testing::Test { |
| 20 public: | 19 public: |
| 21 PowerPolicyControllerTest() {} | 20 PowerPolicyControllerTest() {} |
| 22 virtual ~PowerPolicyControllerTest() {} | 21 virtual ~PowerPolicyControllerTest() {} |
| 23 | 22 |
| 24 virtual void SetUp() OVERRIDE { | 23 virtual void SetUp() OVERRIDE { |
| 25 dbus_manager_ = new FakeDBusThreadManager; | 24 scoped_ptr<DBusThreadManagerTestHelper> dbus_helper = |
| 25 chromeos::DBusThreadManager::InitializeForTesting(); |
| 26 fake_power_client_ = new FakePowerManagerClient; | 26 fake_power_client_ = new FakePowerManagerClient; |
| 27 dbus_manager_->SetPowerManagerClient( | 27 dbus_helper->SetPowerManagerClient( |
| 28 scoped_ptr<PowerManagerClient>(fake_power_client_)); | 28 scoped_ptr<PowerManagerClient>(fake_power_client_)); |
| 29 DBusThreadManager::InitializeForTesting(dbus_manager_); // Takes ownership. | |
| 30 | 29 |
| 31 policy_controller_.reset(new PowerPolicyController); | 30 policy_controller_.reset(new PowerPolicyController); |
| 32 policy_controller_->Init(dbus_manager_); | 31 policy_controller_->Init(DBusThreadManager::Get()); |
| 33 } | 32 } |
| 34 | 33 |
| 35 virtual void TearDown() OVERRIDE { | 34 virtual void TearDown() OVERRIDE { |
| 36 policy_controller_.reset(); | 35 policy_controller_.reset(); |
| 37 DBusThreadManager::Shutdown(); | 36 DBusThreadManager::Shutdown(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 protected: | 39 protected: |
| 41 FakeDBusThreadManager* dbus_manager_; // Not owned. | |
| 42 FakePowerManagerClient* fake_power_client_; | 40 FakePowerManagerClient* fake_power_client_; |
| 43 scoped_ptr<PowerPolicyController> policy_controller_; | 41 scoped_ptr<PowerPolicyController> policy_controller_; |
| 44 }; | 42 }; |
| 45 | 43 |
| 46 TEST_F(PowerPolicyControllerTest, Prefs) { | 44 TEST_F(PowerPolicyControllerTest, Prefs) { |
| 47 PowerPolicyController::PrefValues prefs; | 45 PowerPolicyController::PrefValues prefs; |
| 48 prefs.ac_screen_dim_delay_ms = 600000; | 46 prefs.ac_screen_dim_delay_ms = 600000; |
| 49 prefs.ac_screen_off_delay_ms = 660000; | 47 prefs.ac_screen_off_delay_ms = 660000; |
| 50 prefs.ac_idle_delay_ms = 720000; | 48 prefs.ac_idle_delay_ms = 720000; |
| 51 prefs.battery_screen_dim_delay_ms = 300000; | 49 prefs.battery_screen_dim_delay_ms = 300000; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 206 |
| 209 TEST_F(PowerPolicyControllerTest, AvoidSendingEmptyPolicies) { | 207 TEST_F(PowerPolicyControllerTest, AvoidSendingEmptyPolicies) { |
| 210 // Check that empty policies aren't sent when PowerPolicyController is created | 208 // Check that empty policies aren't sent when PowerPolicyController is created |
| 211 // or destroyed. | 209 // or destroyed. |
| 212 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); | 210 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); |
| 213 policy_controller_.reset(); | 211 policy_controller_.reset(); |
| 214 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); | 212 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); |
| 215 } | 213 } |
| 216 | 214 |
| 217 } // namespace chromeos | 215 } // namespace chromeos |
| OLD | NEW |