• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 self.cr.browser.tabs]
55
56        # Telemetry always opens a 'newtab' tab if no startup tabs are opened.
57        if policy_value is None:
58            if len(tab_urls) != 1 or tab_urls[0] not in self.NEWTAB_URLS:
59                raise error.TestFail('Unexpected tabs: %s (expected: NEWTAB)' %
60                                     tab_urls)
61
62        # Compare open tabs with expected tabs by |policy_value|.
63        elif set(tab_urls) != set(policy_value):
64            raise error.TestFail('Unexpected tabs: %s (expected: %s)' %
65                                 (tab_urls, policy_value))
66
67
68    def run_once(self, case):
69        """Setup and run the test configured for the specified test case.
70
71        Set the expected |policy_value| string and |policies_dict| data based
72        on the test |case|. Set RestoreOnStartup=4 when there is 1 or more
73        startup urls given. Otherwise, set to None.
74
75        @param case: Name of the test case to run.
76
77        """
78        case_value = self.TEST_CASES[case]
79        if case_value == None:
80            user_policies = {'RestoreOnStartup': None}
81        else:
82            user_policies = {'RestoreOnStartup': 4}
83        user_policies[self.POLICY_NAME] = case_value
84        self.setup_case(user_policies=user_policies)
85        self._test_startup_urls(case_value)
86