Chromium Code Reviews| 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 <string> | |
|
bartfab (slow)
2013/03/21 14:22:26
Already included by power_policy_controller.h
Daniel Erat
2013/03/21 14:48:46
I prefer explicitly including stuff wherever it's
bartfab (slow)
2013/03/21 15:34:38
People have different styles I guess. I always fol
| |
| 8 | |
| 9 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 10 #include "chromeos/dbus/mock_dbus_thread_manager.h" | |
| 11 #include "chromeos/dbus/mock_power_manager_client.h" | |
| 12 #include "chromeos/dbus/power_manager/policy.pb.h" | |
|
bartfab (slow)
2013/03/21 14:22:26
Already included by power_policy_controller.h
Daniel Erat
2013/03/21 14:48:46
Done.
| |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 using ::testing::_; | |
| 17 using ::testing::SaveArg; | |
| 18 | |
| 19 namespace chromeos { | |
| 20 | |
| 21 class PowerPolicyControllerTest : public testing::Test { | |
| 22 public: | |
| 23 PowerPolicyControllerTest() {} | |
| 24 virtual ~PowerPolicyControllerTest() {} | |
| 25 | |
| 26 virtual void SetUp() OVERRIDE { | |
| 27 dbus_manager_ = new MockDBusThreadManager; | |
| 28 DBusThreadManager::InitializeForTesting(dbus_manager_); // takes ownership | |
|
bartfab (slow)
2013/03/21 14:22:26
Nits: Capitalize comment, add period at the end.
Daniel Erat
2013/03/21 14:48:46
Done.
| |
| 29 | |
| 30 power_client_ = dbus_manager_->mock_power_manager_client(); | |
| 31 EXPECT_CALL(*power_client_, SetPolicy(_)) | |
| 32 .WillRepeatedly(SaveArg<0>(&last_policy_)); | |
| 33 | |
| 34 policy_controller_ = dbus_manager_->GetPowerPolicyController(); | |
| 35 | |
| 36 // TODO(derat): Write what looks like it will be a ridiculously large | |
|
bartfab (slow)
2013/03/21 14:22:26
You can always invoke UpdatePolicyFromPrefs() dire
Daniel Erat
2013/03/21 14:48:46
Preference's c'tor says that PrefService::Register
bartfab (slow)
2013/03/21 15:34:38
We should discuss this offline. I am not sure what
| |
| 37 // amount of code to register prefs so that UpdatePolicyFromPrefs() can | |
| 38 // be tested. | |
| 39 } | |
| 40 | |
| 41 virtual void TearDown() OVERRIDE { | |
| 42 DBusThreadManager::Shutdown(); | |
| 43 } | |
| 44 | |
| 45 protected: | |
| 46 MockDBusThreadManager* dbus_manager_; | |
|
bartfab (slow)
2013/03/21 14:22:26
Nit: // Not owned.
Daniel Erat
2013/03/21 14:48:46
Done.
| |
| 47 MockPowerManagerClient* power_client_; | |
|
bartfab (slow)
2013/03/21 14:22:26
Nit: // Not owned.
Daniel Erat
2013/03/21 14:48:46
Done.
| |
| 48 PowerPolicyController* policy_controller_; | |
|
bartfab (slow)
2013/03/21 14:22:26
Nit: // Not owned.
Daniel Erat
2013/03/21 14:48:46
Done.
| |
| 49 | |
| 50 power_manager::PowerManagementPolicy last_policy_; | |
| 51 }; | |
| 52 | |
| 53 TEST_F(PowerPolicyControllerTest, Blocks) { | |
| 54 const char kSuspendBlockReason[] = "suspend"; | |
| 55 int suspend_id = policy_controller_->AddSuspendBlock(kSuspendBlockReason); | |
|
bartfab (slow)
2013/03/21 14:22:26
Nit: const
Daniel Erat
2013/03/21 14:48:46
Done.
| |
| 56 power_manager::PowerManagementPolicy expected_policy; | |
| 57 expected_policy.set_idle_action( | |
| 58 power_manager::PowerManagementPolicy_Action_DO_NOTHING); | |
| 59 expected_policy.set_reason(kSuspendBlockReason); | |
| 60 EXPECT_EQ(expected_policy.SerializeAsString(), | |
| 61 last_policy_.SerializeAsString()); | |
| 62 | |
| 63 const char kScreenBlockReason[] = "screen"; | |
| 64 int screen_id = policy_controller_->AddScreenBlock(kScreenBlockReason); | |
|
bartfab (slow)
2013/03/21 14:22:26
Nit: const
Daniel Erat
2013/03/21 14:48:46
Done.
| |
| 65 expected_policy.mutable_ac_delays()->set_screen_dim_ms(0); | |
| 66 expected_policy.mutable_ac_delays()->set_screen_off_ms(0); | |
| 67 expected_policy.mutable_battery_delays()->set_screen_dim_ms(0); | |
| 68 expected_policy.mutable_battery_delays()->set_screen_off_ms(0); | |
| 69 expected_policy.set_reason( | |
| 70 std::string(kScreenBlockReason) + ", " + kSuspendBlockReason); | |
| 71 EXPECT_EQ(expected_policy.SerializeAsString(), | |
| 72 last_policy_.SerializeAsString()); | |
| 73 | |
| 74 policy_controller_->RemoveBlock(suspend_id); | |
| 75 expected_policy.set_reason(kScreenBlockReason); | |
| 76 EXPECT_EQ(expected_policy.SerializeAsString(), | |
| 77 last_policy_.SerializeAsString()); | |
| 78 | |
| 79 policy_controller_->RemoveBlock(screen_id); | |
| 80 expected_policy.Clear(); | |
| 81 EXPECT_EQ(expected_policy.SerializeAsString(), | |
| 82 last_policy_.SerializeAsString()); | |
| 83 } | |
| 84 | |
| 85 } // namespace chromeos | |
| OLD | NEW |