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 5from autotest_lib.client.common_lib import error 6from autotest_lib.client.cros.enterprise import enterprise_policy_base 7 8 9class policy_BlockThirdPartyCookies( 10 enterprise_policy_base.EnterprisePolicyTest): 11 """ 12 Test effect of BlockThirdPartyCookies policy on Chrome OS behavior. 13 14 This test verifies the behaviour and appearance of the 'Block third-party 15 cookies...' check box setting on the 'chrome://settings page for all valid 16 values of the BlockThirdPartyCookies user policy: True, False, and Not set. 17 The corresponding test cases are True_Block, False_Allow, and NotSet_Allow. 18 19 """ 20 version = 1 21 22 POLICY_NAME = 'BlockThirdPartyCookies' 23 TEST_CASES = { 24 'True_Block': True, 25 'False_Allow': False, 26 'NotSet_Allow': None 27 } 28 SUPPORTING_POLICIES = { 29 'DefaultCookiesSetting': 1} 30 31 32 def _test_block_3rd_party_cookies(self, policy_value): 33 """ 34 Verify CrOS enforces BlockThirdPartyCookies policy value. 35 36 When BlockThirdPartyCookies policy is set true (false), then the 37 'Block third-party cookies...' check box shall be (un)checked. When 38 set either True or False, then the check box shall be uneditable. 39 When Not set, then the check box shall be editable. 40 41 @param policy_value: policy value for this case. 42 @raises: TestFail if setting is incorrectly (un)checked or 43 (un)editable, based on the policy value. 44 45 """ 46 # Get check box status from the settings page. 47 setting_pref = 'profile.block_third_party_cookies' 48 properties = self._get_settings_checkbox_properties(setting_pref) 49 setting_label = properties[self.SETTING_LABEL] 50 setting_is_checked = properties[self.SETTING_CHECKED] 51 setting_is_disabled = properties[self.SETTING_DISABLED] 52 53 # Setting shall be checked if policy is set True, unchecked if False. 54 if policy_value == True and not setting_is_checked: 55 raise error.TestFail('Block 3rd-party cookies setting should be ' 56 'checked.') 57 if policy_value == False and setting_is_checked: 58 raise error.TestFail('Block 3rd-party cookies setting should be ' 59 'unchecked.') 60 61 # Setting shall be enabled if policy is Not set, disabled if set. 62 if policy_value == None: 63 if setting_is_disabled: 64 raise error.TestFail('Block 3rd-party cookies setting should ' 65 'be editable.') 66 else: 67 if not setting_is_disabled: 68 raise error.TestFail('Block 3rd-party cookies setting should ' 69 'be uneditable.') 70 71 72 def run_test_case(self, case): 73 """ 74 Setup and run the test configured for the specified test case. 75 76 @param case: Name of the test case to run. 77 78 """ 79 case_value = self.TEST_CASES[case] 80 self.setup_case(self.POLICY_NAME, case_value, self.SUPPORTING_POLICIES) 81 self._test_block_3rd_party_cookies(case_value) 82