1# Copyright 2019 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 5from autotest_lib.client.common_lib import error 6from autotest_lib.client.cros.input_playback import keyboard 7from autotest_lib.client.cros.enterprise import enterprise_policy_base 8 9 10class policy_AllowScreenLock( 11 enterprise_policy_base.EnterprisePolicyTest): 12 """ 13 Test effect of AllowScreenLock policy on Chrome OS. 14 15 This test will set the policy, attempt to lock the screen, then check to 16 see if the screen is locked. 17 18 """ 19 version = 1 20 POLICY_NAME = 'AllowScreenLock' 21 22 def _test_lock_status(self, case): 23 """ 24 Verify the screen lock status. 25 26 @param case: bool or None, setting of AllowScreenLock policy. 27 28 """ 29 _keyboard = keyboard.Keyboard() 30 lock_state = self.cr.login_status['isScreenLocked'] 31 if lock_state: 32 raise error.TestFail('Screen was locked prior to test') 33 34 # Lock the screen with the screenlock hotkey 35 _keyboard.press_key('search+L') 36 is_locked = self.cr.login_status['isScreenLocked'] 37 38 # Policy is None or True 39 if case is not False and not is_locked: 40 raise error.TestFail('Screen was NOT locked when should be') 41 elif case is False and is_locked: 42 raise error.TestFail('Screen was LOCKED when should not be') 43 _keyboard.close() 44 45 def run_once(self, case): 46 """ 47 Setup and run the test configured for the specified test case. 48 49 @param case: Name of the test case to run. 50 51 """ 52 self.setup_case(user_policies={self.POLICY_NAME: case}) 53 self._test_lock_status(case) 54