• 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
5import logging
6
7from autotest_lib.client.common_lib import error
8from autotest_lib.client.cros.enterprise import enterprise_policy_base
9
10
11class policy_EditBookmarksEnabled(enterprise_policy_base.EnterprisePolicyTest):
12    """
13    Test effect of EditBookmarksEnabled policy on Chrome OS behavior.
14
15    This test verifies the behavior of Chrome OS for all valid values of the
16    EditBookmarksEnabled user policy: True, False, and not set. 'Not set'
17    means that the policy value is undefined. This should induce the default
18    behavior, equivalent to what is seen by an un-managed user.
19
20    When set True or not set, bookmarks can be added, removed, or modified.
21    When set False, bookmarks cannot be added, removed, or modified, though
22    existing bookmarks (if any) are still available.
23
24    """
25    version = 1
26
27    POLICY_NAME = 'EditBookmarksEnabled'
28
29    # Dictionary of named test cases and policy data.
30    TEST_CASES = {
31        'True_Enable': True,
32        'False_Disable': False,
33        'NotSet_Enable': None
34    }
35
36    def is_edit_bookmark_disabled(self):
37        """
38        Check whether bookmarks can be edited.
39
40        Checks the value of the 'globalCanEdit_' boolean, which controls whether
41        the user can add, edit, or delete bookmarks. Its value should mirror
42        the edit bookmark policy.
43
44        @returns: True if globalCanEdit_ is disabled.
45        """
46        tab = self.navigate_to_url('chrome://bookmarks')
47
48        is_disabled = tab.EvaluateJavaScript(
49                'var bcm = bookmarks.CommandManager.getInstance(); '
50                '!bcm.globalCanEdit_;')
51        logging.info('editing bookmarks is disabled: %s' % is_disabled)
52        tab.Close()
53
54        return is_disabled
55
56    def _test_edit_bookmarks_enabled(self, policy_value):
57        """
58        Verify CrOS enforces EditBookmarksEnabled policy.
59
60        When EditBookmarksEnabled is true or not set, the UI allows the user
61        to add bookmarks. When false, the UI does not allow the user to add
62        bookmarks.
63
64        Warning: When the 'Bookmark Editing' setting on the CPanel User
65        Settings page is set to 'Enable bookmark editing', then the
66        EditBookmarksEnabled policy on the client will be not set. Thus, to
67        verify the 'Enable bookmark editing' choice from a production or
68        staging DMS, use case=NotSet_Enable.
69
70        @param policy_value: policy value for this case.
71
72        """
73        edit_bookmark_is_disabled = self.is_edit_bookmark_disabled()
74        if policy_value or policy_value is None:
75            if edit_bookmark_is_disabled:
76                raise error.TestFail('Edit Bookmark should be enabled.')
77        else:
78            if not edit_bookmark_is_disabled:
79                raise error.TestFail('Edit Bookmark should be disabled.')
80
81    def run_once(self, case):
82        """
83        Set up and run the test configured for the specified test case.
84
85        @param case: Name of the test case to run.
86
87        """
88        case_value = self.TEST_CASES[case]
89        self.setup_case(user_policies={self.POLICY_NAME: case_value})
90        self._test_edit_bookmarks_enabled(case_value)
91