• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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_AutoFillEnabled(enterprise_policy_base.EnterprisePolicyTest):
10    """
11    Test effect of AutoFillEnabled policy on Chrome OS behavior.
12
13    This test verifies the behavior of Chrome OS for all valid values of the
14    AutoFillEnabled user policy: True, False, and Not set. 'Not set'
15    indicates no value, and will induce the enabled behavior by default,
16    as would be seen by an un-managed user.
17
18    When set True or not set, the Enable Autofill setting can be modified by
19    the user. When set False, Enable Autofill setting is unchecked and cannot
20    be modified.
21
22    """
23    version = 1
24
25    POLICY_NAME = 'AutoFillEnabled'
26    STARTUP_URLS = ['chrome://policy', 'chrome://settings/autofill']
27    SUPPORTING_POLICIES = {
28        'BookmarkBarEnabled': True,
29        'RestoreOnStartupURLs': STARTUP_URLS,
30        'RestoreOnStartup': 4
31    }
32
33    TEST_CASES = {
34        'True_Enable': True,
35        'False_Disable': False,
36        'NotSet_Enable': None
37    }
38
39    def _is_autofill_setting_editable(self):
40        """
41        Check whether Enabled Autofill setting is editable.
42
43        @returns: True if Enable Autofill setting is editable.
44
45        """
46        settings_tab = self.navigate_to_url(self.CHROME_SETTINGS_PAGE)
47        js_code_is_editable = ('document.getElementById('
48                               '"autofill-enabled").disabled')
49        is_editable = not settings_tab.EvaluateJavaScript(js_code_is_editable)
50        settings_tab.Close()
51        return is_editable
52
53
54    def _test_autofill_enabled(self, policy_value):
55        """
56        Verify CrOS enforces AutoFillEnabled policy.
57
58        @param policy_value: policy value for this case.
59
60        """
61        autofill_is_enabled = self._is_autofill_setting_editable()
62        if policy_value == True or policy_value == None:
63            if not autofill_is_enabled:
64                raise error.TestFail('Autofill should be enabled.')
65        else:
66            if autofill_is_enabled:
67                raise error.TestFail('Autofill should be disabled.')
68
69
70    def run_test_case(self, case):
71        """
72        Setup and run the test configured for the specified test case.
73
74        @param case: Name of the test case to run.
75
76        """
77        case_value = self.TEST_CASES[case]
78        self.setup_case(self.POLICY_NAME, case_value, self.SUPPORTING_POLICIES)
79        self._test_autofill_enabled(case_value)
80