1 # Copyright 2016 The Chromium OS 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 import logging 6 7 from autotest_lib.client.bin import utils 8 from autotest_lib.client.common_lib import error 9 from autotest_lib.client.cros import power_status 10 from autotest_lib.client.cros.enterprise import enterprise_policy_base 11 12 13 class policy_ChromeOsLockOnIdleSuspend( 14 enterprise_policy_base.EnterprisePolicyTest): 15 """ 16 Test effect of ChromeOsLockOnIdleSuspend policy on Chrome OS behavior. 17 18 This test verifies the behaviour and appearance of the 'Require password 19 to wake from sleep' check box setting in the Security: Idle Settings 20 section of the chrome://settings page for all valid values of the user 21 policy ChromeOsLockOnIdleSuspend: True, False, and Not set. The 22 corresponding test cases are: True_Lock, False_Unlock, NotSet_Unlock. 23 24 Note: True_Lock case is not run as part of the regression suite due to 25 bug crbug.com/666430. See control.true_lock for details. 26 27 """ 28 version = 1 29 30 POLICY_NAME = 'ChromeOsLockOnIdleSuspend' 31 TEST_CASES = { 32 'True_Lock': True, 33 'False_Unlock': False, 34 'NotSet_Unlock': None 35 } 36 IDLE_ACTION_DELAY = 5 37 POWER_MANAGEMENT_IDLE_SETTINGS = { 38 'AC': { 39 'Delays': { 40 'ScreenDim': 2000, 41 'ScreenOff': 3000, 42 'IdleWarning': 4000, 43 'Idle': (IDLE_ACTION_DELAY * 1000) 44 }, 45 'IdleAction': 'Suspend' 46 }, 47 'Battery': { 48 'Delays': { 49 'ScreenDim': 2000, 50 'ScreenOff': 3000, 51 'IdleWarning': 4000, 52 'Idle': (IDLE_ACTION_DELAY * 1000) 53 }, 54 'IdleAction': 'Suspend' 55 } 56 } 57 PERCENT_CHARGE_MIN = 10 58 STARTUP_URLS = ['chrome://policy', 'chrome://settings'] 59 SUPPORTING_POLICIES = { 60 'AllowScreenLock': True, 61 'LidCloseAction': 0, 62 'PowerManagementIdleSettings': POWER_MANAGEMENT_IDLE_SETTINGS, 63 'RestoreOnStartup': 4, 64 'RestoreOnStartupURLs': STARTUP_URLS 65 } 66 67 68 def initialize(self, **kwargs): 69 """Set up local variables and ensure sufficient battery charge.""" 70 self._power_status = power_status.get_status() 71 if not self._power_status.on_ac(): 72 # Ensure that the battery has sufficient minimum charge. 73 self._power_status.assert_battery_state(self.PERCENT_CHARGE_MIN) 74 75 logging.info('Device power type is "%s"', self._power_type) 76 super(policy_ChromeOsLockOnIdleSuspend, self).initialize(**kwargs) 77 78 79 @property 80 def _power_type(self): 81 """Return type of power used by DUT: AC or Battery.""" 82 return 'AC' if self._power_status.on_ac() else 'Battery' 83 84 85 def _is_screen_locked(self): 86 """Return true if login status indicates that screen is locked.""" 87 login_status = utils.wait_for_value( 88 lambda: self.cr.login_status['isScreenLocked'], 89 expected_value=True, 90 timeout_sec=self.IDLE_ACTION_DELAY) 91 return login_status 92 93 94 def _test_require_password_to_wake(self, policy_value): 95 """ 96 Verify CrOS enforces ChromeOsLockOnIdleSuspend policy value. 97 98 @param policy_value: policy value for this case. 99 @raises: TestFail if behavior is incorrect. 100 101 """ 102 # Screen shall be locked if the policy is True, else unlocked. 103 screen_is_locked = self._is_screen_locked() 104 if policy_value == True: 105 if not screen_is_locked: 106 raise error.TestFail('Screen should be locked.') 107 else: 108 if screen_is_locked: 109 raise error.TestFail('Screen should be unlocked.') 110 111 112 def run_test_case(self, case): 113 """ 114 Setup and run the test configured for the specified test case. 115 116 @param case: Name of the test case to run. 117 118 """ 119 case_value = self.TEST_CASES[case] 120 self.setup_case(self.POLICY_NAME, case_value, self.SUPPORTING_POLICIES) 121 self._test_require_password_to_wake(case_value) 122