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 "base/message_loop/message_loop.h" |
8 #include "chromeos/dbus/dbus_thread_manager.h" | 9 #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" | 10 #include "chromeos/dbus/fake_power_manager_client.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 using ::testing::_; | 14 using ::testing::_; |
15 using ::testing::SaveArg; | 15 using ::testing::SaveArg; |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 | 18 |
19 class PowerPolicyControllerTest : public testing::Test { | 19 class PowerPolicyControllerTest : public testing::Test { |
20 public: | 20 public: |
21 PowerPolicyControllerTest() {} | 21 PowerPolicyControllerTest() {} |
22 virtual ~PowerPolicyControllerTest() {} | 22 virtual ~PowerPolicyControllerTest() {} |
23 | 23 |
24 virtual void SetUp() OVERRIDE { | 24 virtual void SetUp() OVERRIDE { |
25 dbus_manager_ = new FakeDBusThreadManager; | 25 scoped_ptr<DBusThreadManagerTestHelper> dbus_helper = |
| 26 chromeos::DBusThreadManager::GetDBusThreadManagerTestHelper(); |
26 fake_power_client_ = new FakePowerManagerClient; | 27 fake_power_client_ = new FakePowerManagerClient; |
27 dbus_manager_->SetPowerManagerClient( | 28 dbus_helper->SetPowerManagerClient( |
28 scoped_ptr<PowerManagerClient>(fake_power_client_)); | 29 scoped_ptr<PowerManagerClient>(fake_power_client_)); |
29 DBusThreadManager::InitializeForTesting(dbus_manager_); // Takes ownership. | |
30 | 30 |
31 policy_controller_.reset(new PowerPolicyController); | 31 policy_controller_.reset(new PowerPolicyController); |
32 policy_controller_->Init(dbus_manager_); | 32 policy_controller_->Init(DBusThreadManager::Get()); |
33 } | 33 } |
34 | 34 |
35 virtual void TearDown() OVERRIDE { | 35 virtual void TearDown() OVERRIDE { |
36 policy_controller_.reset(); | 36 policy_controller_.reset(); |
37 DBusThreadManager::Shutdown(); | 37 DBusThreadManager::Shutdown(); |
38 } | 38 } |
39 | 39 |
40 protected: | 40 protected: |
41 FakeDBusThreadManager* dbus_manager_; // Not owned. | |
42 FakePowerManagerClient* fake_power_client_; | 41 FakePowerManagerClient* fake_power_client_; |
43 scoped_ptr<PowerPolicyController> policy_controller_; | 42 scoped_ptr<PowerPolicyController> policy_controller_; |
| 43 base::MessageLoop message_loop_; |
44 }; | 44 }; |
45 | 45 |
46 TEST_F(PowerPolicyControllerTest, Prefs) { | 46 TEST_F(PowerPolicyControllerTest, Prefs) { |
47 PowerPolicyController::PrefValues prefs; | 47 PowerPolicyController::PrefValues prefs; |
48 prefs.ac_screen_dim_delay_ms = 600000; | 48 prefs.ac_screen_dim_delay_ms = 600000; |
49 prefs.ac_screen_off_delay_ms = 660000; | 49 prefs.ac_screen_off_delay_ms = 660000; |
50 prefs.ac_idle_delay_ms = 720000; | 50 prefs.ac_idle_delay_ms = 720000; |
51 prefs.battery_screen_dim_delay_ms = 300000; | 51 prefs.battery_screen_dim_delay_ms = 300000; |
52 prefs.battery_screen_off_delay_ms = 360000; | 52 prefs.battery_screen_off_delay_ms = 360000; |
53 prefs.battery_idle_delay_ms = 420000; | 53 prefs.battery_idle_delay_ms = 420000; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 TEST_F(PowerPolicyControllerTest, AvoidSendingEmptyPolicies) { | 209 TEST_F(PowerPolicyControllerTest, AvoidSendingEmptyPolicies) { |
210 // Check that empty policies aren't sent when PowerPolicyController is created | 210 // Check that empty policies aren't sent when PowerPolicyController is created |
211 // or destroyed. | 211 // or destroyed. |
212 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); | 212 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); |
213 policy_controller_.reset(); | 213 policy_controller_.reset(); |
214 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); | 214 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); |
215 } | 215 } |
216 | 216 |
217 } // namespace chromeos | 217 } // namespace chromeos |
OLD | NEW |