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 from autotest_lib.client.common_lib import error 5 from autotest_lib.client.cros.enterprise import enterprise_policy_base 6 from autotest_lib.client.cros.input_playback import keyboard 7 8 from telemetry.core import exceptions 9 10 11 class policy_NewTabPageLocation( 12 enterprise_policy_base.EnterprisePolicyTest): 13 """ 14 Tests the NewTabPageLocation policy in Chrome OS. 15 16 If the NewTabPageLocation policy is set, when a NewTab is opened, 17 the page configured page will be directly loaded. 18 19 """ 20 version = 1 21 22 def _homepage_check(self, case_value): 23 """ 24 Open a new tab and checks the proper page is opened. 25 26 @param case_value: policy value for this case. 27 28 """ 29 self.keyboard.press_key('ctrl+t') 30 31 # Try to get a policy from the current tab. If it works, that means the 32 # policy page is open, and the newtab policy set it. Default (not set) 33 # would be chrome://newtab, and this try would not work. 34 try: 35 self._get_policy_stats_shown(self.cr.browser.tabs[-1], 36 'NewTabPageLocation') 37 if not case_value: 38 raise error.TestFail( 39 'NewTabPageLocation was set when it should not be!') 40 41 except exceptions.EvaluateException: 42 if case_value: 43 raise error.TestFail( 44 'NewTabPageLocation was not set when it should be!') 45 46 if not case_value: 47 url = self.cr.browser.tabs[-1].GetUrl() 48 if url != 'chrome://newtab/': 49 raise error.TestFail( 50 'NewTab was not "chrome://newtab/" instead got {}' 51 .format(url)) 52 53 def run_once(self, case): 54 """ 55 Setup and run the test configured for the specified test case. 56 57 @param case: Name of the test case to run. 58 59 """ 60 self.keyboard = keyboard.Keyboard() 61 TEST_CASES = {'Set': 'chrome://policy', 62 'NotSet': None} 63 64 case_value = TEST_CASES[case] 65 policy_setting = {'NewTabPageLocation': case_value} 66 self.setup_case(user_policies=policy_setting) 67 self._homepage_check(case_value) 68