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. 4import time 5 6from autotest_lib.client.common_lib import error 7from autotest_lib.client.cros.enterprise import enterprise_policy_base 8from autotest_lib.client.cros.input_playback import keyboard 9 10DEFAULT_SEARCH_ENGINE_URL = 'google.com' 11 12 13class policy_DefaultSearchProviderEnabled( 14 enterprise_policy_base.EnterprisePolicyTest): 15 """ 16 Tests the DefaultSearchProviderEnabled policy in Chrome OS. 17 If the policy is set to True/Not Set then typing search queries in the 18 omnibox will result in searching on google.com. 19 If the policy is set to False then typing search queries in the 20 omnibox will not result in searching on google.com. 21 22 """ 23 version = 1 24 25 def _default_search_provider_enabled(self, case): 26 """ 27 Open a new tab and try using the omnibox as a search box. 28 29 @param case: policy value. 30 31 """ 32 33 self.keyboard = keyboard.Keyboard() 34 35 # Open new tab. 36 self.keyboard.press_key('ctrl+t') 37 38 time.sleep(1) 39 # Input random characters into the omnibox and hit Enter. This will 40 # either perform the search or not. 41 self.keyboard.press_key('f') 42 self.keyboard.press_key('s') 43 self.keyboard.press_key('w') 44 self.keyboard.press_key('enter') 45 46 current_url = self.cr.browser.tabs[1].GetUrl() 47 48 if case is False: 49 if DEFAULT_SEARCH_ENGINE_URL in current_url: 50 raise error.TestFail( 51 'Search engine is on in the omnibox and it should not be') 52 53 else: 54 if DEFAULT_SEARCH_ENGINE_URL not in current_url: 55 raise error.TestFail( 56 'Search engine is off in the omnibox and it should be on') 57 58 59 def run_once(self, case): 60 """ 61 Setup and run the test configured for the specified test case. 62 63 @param case: Name of the test case to run. 64 65 """ 66 POLICIES = {'DefaultSearchProviderEnabled': case} 67 self.setup_case(user_policies=POLICIES) 68 self._default_search_provider_enabled(case)