OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromeos/dbus/power_policy_controller.h" |
| 6 |
| 7 #include "chromeos/dbus/dbus_thread_manager.h" |
| 8 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/mock_power_manager_client.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 using ::testing::_; |
| 14 using ::testing::SaveArg; |
| 15 |
| 16 namespace chromeos { |
| 17 |
| 18 class PowerPolicyControllerTest : public testing::Test { |
| 19 public: |
| 20 PowerPolicyControllerTest() {} |
| 21 virtual ~PowerPolicyControllerTest() {} |
| 22 |
| 23 virtual void SetUp() OVERRIDE { |
| 24 dbus_manager_ = new MockDBusThreadManager; |
| 25 DBusThreadManager::InitializeForTesting(dbus_manager_); // Takes ownership. |
| 26 power_client_ = dbus_manager_->mock_power_manager_client(); |
| 27 EXPECT_CALL(*power_client_, SetPolicy(_)) |
| 28 .WillRepeatedly(SaveArg<0>(&last_policy_)); |
| 29 |
| 30 policy_controller_ = dbus_manager_->GetPowerPolicyController(); |
| 31 |
| 32 // TODO(derat): Write what looks like it will be a ridiculously large |
| 33 // amount of code to register prefs so that UpdatePolicyFromPrefs() can |
| 34 // be tested. |
| 35 } |
| 36 |
| 37 virtual void TearDown() OVERRIDE { |
| 38 DBusThreadManager::Shutdown(); |
| 39 } |
| 40 |
| 41 protected: |
| 42 MockDBusThreadManager* dbus_manager_; // Not owned. |
| 43 MockPowerManagerClient* power_client_; // Not owned. |
| 44 PowerPolicyController* policy_controller_; // Not owned. |
| 45 |
| 46 power_manager::PowerManagementPolicy last_policy_; |
| 47 }; |
| 48 |
| 49 TEST_F(PowerPolicyControllerTest, Blocks) { |
| 50 const char kSuspendBlockReason[] = "suspend"; |
| 51 const int suspend_id = |
| 52 policy_controller_->AddSuspendBlock(kSuspendBlockReason); |
| 53 power_manager::PowerManagementPolicy expected_policy; |
| 54 expected_policy.set_idle_action( |
| 55 power_manager::PowerManagementPolicy_Action_DO_NOTHING); |
| 56 expected_policy.set_reason(kSuspendBlockReason); |
| 57 EXPECT_EQ(expected_policy.SerializeAsString(), |
| 58 last_policy_.SerializeAsString()); |
| 59 |
| 60 const char kScreenBlockReason[] = "screen"; |
| 61 const int screen_id = policy_controller_->AddScreenBlock(kScreenBlockReason); |
| 62 expected_policy.mutable_ac_delays()->set_screen_dim_ms(0); |
| 63 expected_policy.mutable_ac_delays()->set_screen_off_ms(0); |
| 64 expected_policy.mutable_battery_delays()->set_screen_dim_ms(0); |
| 65 expected_policy.mutable_battery_delays()->set_screen_off_ms(0); |
| 66 expected_policy.set_reason( |
| 67 std::string(kScreenBlockReason) + ", " + kSuspendBlockReason); |
| 68 EXPECT_EQ(expected_policy.SerializeAsString(), |
| 69 last_policy_.SerializeAsString()); |
| 70 |
| 71 policy_controller_->RemoveBlock(suspend_id); |
| 72 expected_policy.set_reason(kScreenBlockReason); |
| 73 EXPECT_EQ(expected_policy.SerializeAsString(), |
| 74 last_policy_.SerializeAsString()); |
| 75 |
| 76 policy_controller_->RemoveBlock(screen_id); |
| 77 expected_policy.Clear(); |
| 78 EXPECT_EQ(expected_policy.SerializeAsString(), |
| 79 last_policy_.SerializeAsString()); |
| 80 } |
| 81 |
| 82 } // namespace chromeos |
OLD | NEW |