Index: chromeos/dbus/power_policy_controller_unittest.cc |
diff --git a/chromeos/dbus/power_policy_controller_unittest.cc b/chromeos/dbus/power_policy_controller_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bc9d1e6b20276c6bbf7b7c92ebc42535447c66f4 |
--- /dev/null |
+++ b/chromeos/dbus/power_policy_controller_unittest.cc |
@@ -0,0 +1,85 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chromeos/dbus/power_policy_controller.h" |
+ |
+#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
|
+ |
+#include "chromeos/dbus/dbus_thread_manager.h" |
+#include "chromeos/dbus/mock_dbus_thread_manager.h" |
+#include "chromeos/dbus/mock_power_manager_client.h" |
+#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.
|
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using ::testing::_; |
+using ::testing::SaveArg; |
+ |
+namespace chromeos { |
+ |
+class PowerPolicyControllerTest : public testing::Test { |
+ public: |
+ PowerPolicyControllerTest() {} |
+ virtual ~PowerPolicyControllerTest() {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ dbus_manager_ = new MockDBusThreadManager; |
+ 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.
|
+ |
+ power_client_ = dbus_manager_->mock_power_manager_client(); |
+ EXPECT_CALL(*power_client_, SetPolicy(_)) |
+ .WillRepeatedly(SaveArg<0>(&last_policy_)); |
+ |
+ policy_controller_ = dbus_manager_->GetPowerPolicyController(); |
+ |
+ // 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
|
+ // amount of code to register prefs so that UpdatePolicyFromPrefs() can |
+ // be tested. |
+ } |
+ |
+ virtual void TearDown() OVERRIDE { |
+ DBusThreadManager::Shutdown(); |
+ } |
+ |
+ protected: |
+ MockDBusThreadManager* dbus_manager_; |
bartfab (slow)
2013/03/21 14:22:26
Nit: // Not owned.
Daniel Erat
2013/03/21 14:48:46
Done.
|
+ MockPowerManagerClient* power_client_; |
bartfab (slow)
2013/03/21 14:22:26
Nit: // Not owned.
Daniel Erat
2013/03/21 14:48:46
Done.
|
+ PowerPolicyController* policy_controller_; |
bartfab (slow)
2013/03/21 14:22:26
Nit: // Not owned.
Daniel Erat
2013/03/21 14:48:46
Done.
|
+ |
+ power_manager::PowerManagementPolicy last_policy_; |
+}; |
+ |
+TEST_F(PowerPolicyControllerTest, Blocks) { |
+ const char kSuspendBlockReason[] = "suspend"; |
+ 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.
|
+ power_manager::PowerManagementPolicy expected_policy; |
+ expected_policy.set_idle_action( |
+ power_manager::PowerManagementPolicy_Action_DO_NOTHING); |
+ expected_policy.set_reason(kSuspendBlockReason); |
+ EXPECT_EQ(expected_policy.SerializeAsString(), |
+ last_policy_.SerializeAsString()); |
+ |
+ const char kScreenBlockReason[] = "screen"; |
+ 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.
|
+ expected_policy.mutable_ac_delays()->set_screen_dim_ms(0); |
+ expected_policy.mutable_ac_delays()->set_screen_off_ms(0); |
+ expected_policy.mutable_battery_delays()->set_screen_dim_ms(0); |
+ expected_policy.mutable_battery_delays()->set_screen_off_ms(0); |
+ expected_policy.set_reason( |
+ std::string(kScreenBlockReason) + ", " + kSuspendBlockReason); |
+ EXPECT_EQ(expected_policy.SerializeAsString(), |
+ last_policy_.SerializeAsString()); |
+ |
+ policy_controller_->RemoveBlock(suspend_id); |
+ expected_policy.set_reason(kScreenBlockReason); |
+ EXPECT_EQ(expected_policy.SerializeAsString(), |
+ last_policy_.SerializeAsString()); |
+ |
+ policy_controller_->RemoveBlock(screen_id); |
+ expected_policy.Clear(); |
+ EXPECT_EQ(expected_policy.SerializeAsString(), |
+ last_policy_.SerializeAsString()); |
+} |
+ |
+} // namespace chromeos |