blob: 8d9fb3cd7d89d32f9c947c096315e7993df18a0b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// 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 "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/mock_dbus_thread_manager.h"
#include "chromeos/dbus/mock_power_manager_client.h"
#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.
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
// amount of code to register prefs so that UpdatePolicyFromPrefs() can
// be tested.
}
virtual void TearDown() OVERRIDE {
DBusThreadManager::Shutdown();
}
protected:
MockDBusThreadManager* dbus_manager_; // Not owned.
MockPowerManagerClient* power_client_; // Not owned.
PowerPolicyController* policy_controller_; // Not owned.
power_manager::PowerManagementPolicy last_policy_;
};
TEST_F(PowerPolicyControllerTest, Blocks) {
const char kSuspendBlockReason[] = "suspend";
const int suspend_id =
policy_controller_->AddSuspendBlock(kSuspendBlockReason);
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";
const int screen_id = policy_controller_->AddScreenBlock(kScreenBlockReason);
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
|