• 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.common_lib import error
6from autotest_lib.client.cros.enterprise import enterprise_policy_base
7
8
9class policy_PolicyRefreshRate(
10        enterprise_policy_base.EnterprisePolicyTest):
11    """
12    Test effect of policy_PolicyRefreshRate policy on Chrome OS.
13
14    """
15    version = 1
16
17    def check_refresh_rate(self, case):
18        """
19        Will check the policy refresh rate from chrome://policy, and verify
20        that the text returned alligns with the policy configured.
21
22        @param case: Name of the test case to run.
23
24        """
25        tab = self.navigate_to_url('chrome://policy')
26
27        js_text_query = "document.querySelector('{}').innerText"
28        refresh_interval_js = '#status-box-container div.refresh-interval'
29
30        # Grab the policy refresh as shown at the top of the page, not from
31        # the policy table.
32        refresh_interval = tab.EvaluateJavaScript(
33                               js_text_query.format(refresh_interval_js))
34        if case <= 1800000:
35            expected_refresh = ' 30 mins'
36        elif case >= 86400000:
37            expected_refresh = ' 1 day'
38
39        if refresh_interval != expected_refresh:
40            raise error.TestFail('Policy refresh incorrect. Got {} expected {}'
41                                 .format(refresh_interval, expected_refresh))
42
43    def run_once(self, case):
44        """
45        @param case: Name of the test case to run.
46
47        """
48        self.setup_case(user_policies={'PolicyRefreshRate': case})
49        self.check_refresh_rate(case)
50