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_RestoreOnStartupURLs(enterprise_policy_base.EnterprisePolicyTest): 10 """Test effect of RestoreOnStartupURLs policy on Chrome OS behavior. 11 12 This test verifies the behavior of Chrome OS for a range of valid values 13 in the RestoreOnStartupURLs user policy. It also exercises the dependent 14 user policy RestoreOnStartup, which must be set to 4 to utilize the 15 specified startup URLs, and to None to when no URLs are specified. 16 17 The combination of policy values are covered by three test cases named: 18 NotSet_NoTabs, SingleUrl_1Tab, and MultipleUrls_3Tabs. 19 - Case NotSet_NoTabs opens no tabs. This is the default behavior for 20 un-managed user and guest user sessions. 21 - Case SingleUrl_1Tab opens a single tab to chrome://settings. 22 - Case MultipleUrls_3Tabs opens 3 tabs, in order, to the following pages: 23 'chrome://policy', 'chrome://settings', and 'chrome://histograms' 24 25 """ 26 version = 1 27 28 POLICY_NAME = 'RestoreOnStartupURLs' 29 URLS1_DATA = ['chrome://settings'] 30 URLS3_DATA = ['chrome://policy', 'chrome://settings', 31 'chrome://histograms'] 32 NEWTAB_URLS = ['chrome://newtab', 33 'https://www.google.com/_/chrome/newtab?espv=2&ie=UTF-8'] 34 35 TEST_CASES = { 36 'NotSet_NoTabs': None, 37 'SingleUrl_1Tab': URLS1_DATA, 38 'MultipleUrls_3Tabs': URLS3_DATA 39 } 40 41 def _test_startup_urls(self, policy_value): 42 """Verify CrOS enforces RestoreOnStartupURLs policy value. 43 44 When RestoreOnStartupURLs policy is set to one or more URLs, check 45 that a tab is opened to each URL. When set to None, check that no tab 46 is opened. 47 48 @param policy_value: policy value expected. 49 50 """ 51 # Get list of open tab urls from browser; Convert unicode to text; 52 # Strip any trailing '/' character reported by devtools. 53 tab_urls = [tab.url.encode('utf8').rstrip('/') 54 for tab in reversed(self.cr.browser.tabs)] 55 56 # Telemetry always opens a 'newtab' tab if no startup tabs are opened. 57 # If the only open tab is 'newtab', or a tab with the termporary url 58 # www.google.com/_/chrome/newtab..., then set tab URLs to None. 59 if len(tab_urls) == 1: 60 for newtab_url in self.NEWTAB_URLS: 61 if newtab_url in tab_urls: 62 tab_urls = None 63 break 64 65 # Compare open tabs with expected tabs by |policy_value|. 66 if tab_urls != policy_value: 67 raise error.TestFail('Unexpected tabs: %s (expected: %s)' % 68 (tab_urls, policy_value)) 69 70 71 def run_test_case(self, case): 72 """Setup and run the test configured for the specified test case. 73 74 Set the expected |policy_value| string and |policies_dict| data based 75 on the test |case|. Set RestoreOnStartup=4 when there is 1 or more 76 startup urls given. Otherwise, set to None. 77 78 @param case: Name of the test case to run. 79 80 """ 81 case_value = self.TEST_CASES[case] 82 if case_value == None: 83 supporting_policies = {'RestoreOnStartup': None} 84 else: 85 supporting_policies = {'RestoreOnStartup': 4} 86 self.setup_case(self.POLICY_NAME, case_value, supporting_policies) 87 self._test_startup_urls(case_value) 88