| 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 "base/message_loop/message_loop.h" |
| 9 #include "chromeos/dbus/fake_power_manager_client.h" | 9 #include "chromeos/dbus/fake_power_manager_client.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 prefs.battery_idle_action = PowerPolicyController::ACTION_STOP_SESSION; | 47 prefs.battery_idle_action = PowerPolicyController::ACTION_STOP_SESSION; |
| 48 prefs.lid_closed_action = PowerPolicyController::ACTION_SHUT_DOWN; | 48 prefs.lid_closed_action = PowerPolicyController::ACTION_SHUT_DOWN; |
| 49 prefs.use_audio_activity = true; | 49 prefs.use_audio_activity = true; |
| 50 prefs.use_video_activity = true; | 50 prefs.use_video_activity = true; |
| 51 prefs.ac_brightness_percent = 87.0; | 51 prefs.ac_brightness_percent = 87.0; |
| 52 prefs.battery_brightness_percent = 43.0; | 52 prefs.battery_brightness_percent = 43.0; |
| 53 prefs.enable_auto_screen_lock = false; | 53 prefs.enable_auto_screen_lock = false; |
| 54 prefs.presentation_screen_dim_delay_factor = 3.0; | 54 prefs.presentation_screen_dim_delay_factor = 3.0; |
| 55 prefs.user_activity_screen_dim_delay_factor = 2.0; | 55 prefs.user_activity_screen_dim_delay_factor = 2.0; |
| 56 prefs.wait_for_initial_user_activity = true; | 56 prefs.wait_for_initial_user_activity = true; |
| 57 prefs.force_nonzero_brightness_for_user_activity = false; |
| 57 policy_controller_->ApplyPrefs(prefs); | 58 policy_controller_->ApplyPrefs(prefs); |
| 58 | 59 |
| 59 power_manager::PowerManagementPolicy expected_policy; | 60 power_manager::PowerManagementPolicy expected_policy; |
| 60 expected_policy.mutable_ac_delays()->set_screen_dim_ms(600000); | 61 expected_policy.mutable_ac_delays()->set_screen_dim_ms(600000); |
| 61 expected_policy.mutable_ac_delays()->set_screen_off_ms(660000); | 62 expected_policy.mutable_ac_delays()->set_screen_off_ms(660000); |
| 62 expected_policy.mutable_ac_delays()->set_screen_lock_ms(-1); | 63 expected_policy.mutable_ac_delays()->set_screen_lock_ms(-1); |
| 63 expected_policy.mutable_ac_delays()->set_idle_warning_ms(-1); | 64 expected_policy.mutable_ac_delays()->set_idle_warning_ms(-1); |
| 64 expected_policy.mutable_ac_delays()->set_idle_ms(720000); | 65 expected_policy.mutable_ac_delays()->set_idle_ms(720000); |
| 65 expected_policy.mutable_battery_delays()->set_screen_dim_ms(300000); | 66 expected_policy.mutable_battery_delays()->set_screen_dim_ms(300000); |
| 66 expected_policy.mutable_battery_delays()->set_screen_off_ms(360000); | 67 expected_policy.mutable_battery_delays()->set_screen_off_ms(360000); |
| 67 expected_policy.mutable_battery_delays()->set_screen_lock_ms(-1); | 68 expected_policy.mutable_battery_delays()->set_screen_lock_ms(-1); |
| 68 expected_policy.mutable_battery_delays()->set_idle_warning_ms(-1); | 69 expected_policy.mutable_battery_delays()->set_idle_warning_ms(-1); |
| 69 expected_policy.mutable_battery_delays()->set_idle_ms(420000); | 70 expected_policy.mutable_battery_delays()->set_idle_ms(420000); |
| 70 expected_policy.set_ac_idle_action( | 71 expected_policy.set_ac_idle_action( |
| 71 power_manager::PowerManagementPolicy_Action_SUSPEND); | 72 power_manager::PowerManagementPolicy_Action_SUSPEND); |
| 72 expected_policy.set_battery_idle_action( | 73 expected_policy.set_battery_idle_action( |
| 73 power_manager::PowerManagementPolicy_Action_STOP_SESSION); | 74 power_manager::PowerManagementPolicy_Action_STOP_SESSION); |
| 74 expected_policy.set_lid_closed_action( | 75 expected_policy.set_lid_closed_action( |
| 75 power_manager::PowerManagementPolicy_Action_SHUT_DOWN); | 76 power_manager::PowerManagementPolicy_Action_SHUT_DOWN); |
| 76 expected_policy.set_use_audio_activity(true); | 77 expected_policy.set_use_audio_activity(true); |
| 77 expected_policy.set_use_video_activity(true); | 78 expected_policy.set_use_video_activity(true); |
| 78 expected_policy.set_ac_brightness_percent(87.0); | 79 expected_policy.set_ac_brightness_percent(87.0); |
| 79 expected_policy.set_battery_brightness_percent(43.0); | 80 expected_policy.set_battery_brightness_percent(43.0); |
| 80 expected_policy.set_presentation_screen_dim_delay_factor(3.0); | 81 expected_policy.set_presentation_screen_dim_delay_factor(3.0); |
| 81 expected_policy.set_user_activity_screen_dim_delay_factor(2.0); | 82 expected_policy.set_user_activity_screen_dim_delay_factor(2.0); |
| 82 expected_policy.set_wait_for_initial_user_activity(true); | 83 expected_policy.set_wait_for_initial_user_activity(true); |
| 84 expected_policy.set_force_nonzero_brightness_for_user_activity(false); |
| 83 expected_policy.set_reason("Prefs"); | 85 expected_policy.set_reason("Prefs"); |
| 84 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 86 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 85 PowerPolicyController::GetPolicyDebugString( | 87 PowerPolicyController::GetPolicyDebugString( |
| 86 fake_power_client_->policy())); | 88 fake_power_client_->policy())); |
| 87 | 89 |
| 88 // Change some prefs and check that an updated policy is sent. | 90 // Change some prefs and check that an updated policy is sent. |
| 89 prefs.ac_idle_warning_delay_ms = 700000; | 91 prefs.ac_idle_warning_delay_ms = 700000; |
| 90 prefs.battery_idle_warning_delay_ms = 400000; | 92 prefs.battery_idle_warning_delay_ms = 400000; |
| 91 prefs.lid_closed_action = PowerPolicyController::ACTION_SUSPEND; | 93 prefs.lid_closed_action = PowerPolicyController::ACTION_SUSPEND; |
| 92 prefs.ac_brightness_percent = -1.0; | 94 prefs.ac_brightness_percent = -1.0; |
| 95 prefs.force_nonzero_brightness_for_user_activity = true; |
| 93 policy_controller_->ApplyPrefs(prefs); | 96 policy_controller_->ApplyPrefs(prefs); |
| 94 expected_policy.mutable_ac_delays()->set_idle_warning_ms(700000); | 97 expected_policy.mutable_ac_delays()->set_idle_warning_ms(700000); |
| 95 expected_policy.mutable_battery_delays()->set_idle_warning_ms(400000); | 98 expected_policy.mutable_battery_delays()->set_idle_warning_ms(400000); |
| 96 expected_policy.set_lid_closed_action( | 99 expected_policy.set_lid_closed_action( |
| 97 power_manager::PowerManagementPolicy_Action_SUSPEND); | 100 power_manager::PowerManagementPolicy_Action_SUSPEND); |
| 98 expected_policy.clear_ac_brightness_percent(); | 101 expected_policy.clear_ac_brightness_percent(); |
| 102 expected_policy.set_force_nonzero_brightness_for_user_activity(true); |
| 99 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), | 103 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), |
| 100 PowerPolicyController::GetPolicyDebugString( | 104 PowerPolicyController::GetPolicyDebugString( |
| 101 fake_power_client_->policy())); | 105 fake_power_client_->policy())); |
| 102 | 106 |
| 103 // The enable-auto-screen-lock pref should force the screen-lock delays to | 107 // The enable-auto-screen-lock pref should force the screen-lock delays to |
| 104 // match the screen-off delays plus a constant value. | 108 // match the screen-off delays plus a constant value. |
| 105 prefs.enable_auto_screen_lock = true; | 109 prefs.enable_auto_screen_lock = true; |
| 106 policy_controller_->ApplyPrefs(prefs); | 110 policy_controller_->ApplyPrefs(prefs); |
| 107 expected_policy.mutable_ac_delays()->set_screen_lock_ms( | 111 expected_policy.mutable_ac_delays()->set_screen_lock_ms( |
| 108 660000 + PowerPolicyController::kScreenLockAfterOffDelayMs); | 112 660000 + PowerPolicyController::kScreenLockAfterOffDelayMs); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 204 |
| 201 TEST_F(PowerPolicyControllerTest, AvoidSendingEmptyPolicies) { | 205 TEST_F(PowerPolicyControllerTest, AvoidSendingEmptyPolicies) { |
| 202 // Check that empty policies aren't sent when PowerPolicyController is created | 206 // Check that empty policies aren't sent when PowerPolicyController is created |
| 203 // or destroyed. | 207 // or destroyed. |
| 204 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); | 208 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); |
| 205 PowerPolicyController::Shutdown(); | 209 PowerPolicyController::Shutdown(); |
| 206 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); | 210 EXPECT_EQ(0, fake_power_client_->num_set_policy_calls()); |
| 207 } | 211 } |
| 208 | 212 |
| 209 } // namespace chromeos | 213 } // namespace chromeos |
| OLD | NEW |