Home | History | Annotate | Download | only in policy_EditBookmarksEnabled
      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 
      5 import logging
      6 import time
      7 
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.client.cros.enterprise import enterprise_policy_base
     10 
     11 
     12 class policy_EditBookmarksEnabled(enterprise_policy_base.EnterprisePolicyTest):
     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     version = 1
     25 
     26     POLICY_NAME = 'EditBookmarksEnabled'
     27     BOOKMARKS = [{"name": "Google",
     28                   "url": "https://www.google.com/"},
     29                  {"name": "CNN",
     30                   "url": "http://www.cnn.com/"},
     31                  {"name": "IRS",
     32                   "url": "http://www.irs.gov/"}]
     33     SUPPORTING_POLICIES = {
     34         'BookmarkBarEnabled': True,
     35         'ManagedBookmarks': BOOKMARKS
     36     }
     37 
     38     # Dictionary of named test cases and policy data.
     39     TEST_CASES = {
     40         'True_Enable': True,
     41         'False_Disable': False,
     42         'NotSet_Enable': None
     43     }
     44 
     45     def _is_add_bookmark_disabled(self):
     46         """Check whether add-new-bookmark-command menu item is disabled.
     47 
     48         @returns: True if add-new-bookmarks-command is disabled.
     49         """
     50         tab = self.navigate_to_url('chrome://bookmarks/#1')
     51 
     52         # Wait until list.reload() is defined on bmm page.
     53         tab.WaitForJavaScriptCondition(
     54             "typeof bmm.list.reload == 'function'", timeout=60)
     55         time.sleep(1)  # Allow JS to run after reload function is defined.
     56 
     57         # Check if add-new-bookmark menu command has disabled property.
     58         is_disabled = tab.EvaluateJavaScript(
     59             '$("add-new-bookmark-command").disabled;')
     60         logging.info('add-new-bookmark-command is disabled: %s', is_disabled)
     61         tab.Close()
     62         return is_disabled
     63 
     64     def _test_edit_bookmarks_enabled(self, policy_value):
     65         """Verify CrOS enforces EditBookmarksEnabled policy.
     66 
     67         When EditBookmarksEnabled is true or not set, the UI allows the user
     68         to add bookmarks. When false, the UI does not allow the user to add
     69         bookmarks.
     70 
     71         Warning: When the 'Bookmark Editing' setting on the CPanel User
     72         Settings page is set to 'Enable bookmark editing', then the
     73         EditBookmarksEnabled policy on the client will be not set. Thus, to
     74         verify the 'Enable bookmark editing' choice from a production or
     75         staging DMS, use case=NotSet_Enable.
     76 
     77         @param policy_value: policy value for this case.
     78         """
     79         add_bookmark_is_disabled = self._is_add_bookmark_disabled()
     80         if policy_value == True or policy_value == None:
     81             if add_bookmark_is_disabled:
     82                 raise error.TestFail('Add Bookmark should be enabled.')
     83         else:
     84             if not add_bookmark_is_disabled:
     85                 raise error.TestFail('Add Bookmark should be disabled.')
     86 
     87     def run_once(self, case):
     88         """Setup and run the test configured for the specified test case.
     89 
     90         @param case: Name of the test case to run.
     91         """
     92         case_value = self.TEST_CASES[case]
     93         self.SUPPORTING_POLICIES[self.POLICY_NAME] = case_value
     94         self.setup_case(user_policies=self.SUPPORTING_POLICIES)
     95         self._test_edit_bookmarks_enabled(case_value)
     96