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.enterprise import enterprise_policy_base 7 8 9class policy_PasswordManager( 10 enterprise_policy_base.EnterprisePolicyTest): 11 """ 12 Test effect of PasswordManager policy on Chrome OS. 13 14 This test will set the policy, then navigate to the password page 15 within the chrome settings and verify the setting. 16 17 """ 18 19 version = 1 20 TEST_OBJ = '/Offer/' 21 ROLE = 'toggleButton' 22 EXP_RESULTS = {True: {'restrict': True, 23 'value': 'true', 24 'icon': True}, 25 False: {'restrict': True, 26 'value': 'false'}, 27 None: {'restrict': False, 28 'value': 'true'}} 29 30 def _check_pword_mgr(self, case): 31 """ 32 Check the status of the 'Offer to Save Passwords' toggle button via 33 verifing the buttons current setting (ie enabled/disabled), and verify 34 the setting is not able to be controlled by the user when the 35 policy is set. 36 37 Additionally there will be a check to verify the "controlled by policy" 38 icon is present. 39 40 @param case: Value of the policy settings. 41 42 """ 43 expected_result = self.EXP_RESULTS[case] 44 self.cr.browser.tabs[0].Navigate('chrome://settings/passwords') 45 self._wait_for_page() 46 icon_present = self.ui.item_present(name=self.TEST_OBJ, 47 isRegex=True, 48 role='genericContainer') 49 button_restricted = self.ui.is_obj_restricted( 50 name=self.TEST_OBJ, 51 isRegex=True, 52 role=self.ROLE) 53 button_setting = self.ui.doCommand_on_obj( 54 name=self.TEST_OBJ, 55 cmd='checked', 56 isRegex=True, 57 role=self.ROLE) 58 59 if expected_result['restrict'] and ( 60 not button_restricted or not icon_present): 61 raise error.TestError('Password manager controlable by user.') 62 elif not expected_result['restrict'] and ( 63 button_restricted or icon_present): 64 raise error.TestError( 65 'Password manager controlled by policy when not set.') 66 67 if expected_result['value'] != button_setting: 68 raise error.TestError( 69 'Password Manager setting is {} when it should be {}' 70 .format(button_setting, expected_result['value'])) 71 72 def _wait_for_page(self): 73 """Wait for the page to load via all the expected elements loading.""" 74 self.ui.wait_for_ui_obj(name=self.TEST_OBJ, isRegex=True, timeout=18) 75 76 def run_once(self, case): 77 """Setup and run the test configured for the specified test case.""" 78 self.setup_case(real_gaia=True, 79 user_policies={'PasswordManagerEnabled': case}) 80 self.ui.start_ui_root(self.cr) 81 self._check_pword_mgr(case) 82