1# Copyright 2015 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_ForceGoogleSafeSearch(enterprise_policy_base.EnterprisePolicyTest): 10 """Test effect of ForceGoogleSafeSearch policy on Chrome OS behavior. 11 12 This test verifies that the ForceGoogleSafeSearch user policy controls 13 whether Chrome OS enforces the use of Google Safe Search. The test covers 14 all valid policy values across three test cases: NotSet_NotSafe, 15 False_NotSafe, and True_Safe. 16 17 A test case shall pass if the omnibox appends (or does not append) the 18 safe parameter to the search URL when the policy is set true (or is set 19 false or is not set). A test case shall fail if the above behavior is 20 not enforced. 21 22 Note that DefaultSearchProviderEnabled must be not set (i.e., set to 23 None) for this test to work. 24 25 """ 26 version = 1 27 28 POLICY_NAME = 'ForceGoogleSafeSearch' 29 TEST_CASES = { 30 'True_Safe': True, 31 'False_NotSafe': False, 32 'NotSet_NotSafe': None 33 } 34 SUPPORTING_POLICIES = { 35 'DefaultSearchProviderEnabled': None 36 } 37 GOOGLE_SEARCH_URL = 'https://www.google.com/search?q=kittens' 38 39 def _test_force_safe_search(self, policy_value): 40 """Verify CrOS enforces ForceGoogleSafeSearch policy. 41 42 When ForceGoogleSafeSearch is set true, then Chrome OS shall append 43 the safe search parameter to the Google Search URL, and set it active. 44 When set false or is not set, then Chrome OS shall not append the safe 45 search parameter to the search URL. 46 47 @param policy_value: policy value for this case. 48 49 """ 50 tab = self.navigate_to_url(self.GOOGLE_SEARCH_URL) 51 is_safe_search_active = True if '&safe=active' in tab.url else False 52 if policy_value == True: 53 if not is_safe_search_active: 54 raise error.TestFail('Safe search should be active.') 55 else: 56 if is_safe_search_active: 57 raise error.TestFail('Safe search should not be active.') 58 59 def run_test_case(self, case): 60 """Setup and run the test configured for the specified test case. 61 62 @param case: Name of the test case to run. 63 64 """ 65 case_value = self.TEST_CASES[case] 66 self.setup_case(self.POLICY_NAME, case_value, self.SUPPORTING_POLICIES) 67 self._test_force_safe_search(case_value) 68