• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 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.bin import utils
6from autotest_lib.client.common_lib import error
7from autotest_lib.client.cros.enterprise import enterprise_policy_base
8
9
10class policy_SafeBrowsingEnabled(
11        enterprise_policy_base.EnterprisePolicyTest):
12    """
13    Tests the SafeBrowsingEnabled policy in Chrome OS.
14
15    If the policy is set to True then Safety Browsing will be enabled.
16    If the policy is set to False then Safety Browsing will be disabled.
17    If the policy is set to None then Safety Browsing will be enabled.
18
19    """
20    version = 1
21    safety_browsing_test_page = 'chrome://safe-browsing/'
22    safety_browsing_enabled = "Enabled: safebrowsing.enabled"
23    safety_browsing_disabled = "Disabled: safebrowsing.enabled"
24
25
26    def _check_safety_browsing_page(self, case):
27        """
28        Opens a new chrome://safe-browsing/ page and checks the settings for
29        the Safety Browsing mode.
30
31        @param case: policy value.
32
33        """
34        active_tab = self.navigate_to_url(self.safety_browsing_test_page)
35        page_scrape_cmd = (
36            'document.getElementById("preferences-list").'
37            'children[0].innerText;')
38        utils.poll_for_condition(
39            lambda: self.check_page_readiness(
40                active_tab, page_scrape_cmd),
41            exception=error.TestFail('Page is not ready.'),
42            timeout=5,
43            sleep_interval=1)
44        safety_status = active_tab.EvaluateJavaScript(page_scrape_cmd)
45
46        if case == True or case == None:
47            if safety_status != self.safety_browsing_enabled:
48                raise error.TestFail('Safety Browsing is disabled'
49                                     ' but should be enabled.')
50        else:
51            if safety_status != self.safety_browsing_disabled:
52                raise error.TestFail('Safety Browsing is enabled'
53                                     ' but should be disabled.')
54
55
56    def run_once(self, case):
57        """
58        Setup and run the test configured for the specified test case.
59
60        @param case: Name of the test case to run.
61
62        """
63        POLICIES = {'SafeBrowsingEnabled': case}
64        self.setup_case(user_policies=POLICIES)
65        self._check_safety_browsing_page(case)
66