• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 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
6from autotest_lib.client.common_lib import error
7from autotest_lib.client.cros.enterprise import enterprise_policy_base
8
9
10class policy_AllowDinosaurEasterEgg(
11        enterprise_policy_base.EnterprisePolicyTest):
12    """
13    Test effect of AllowDinosaurEasterEgg policy on Chrome OS.
14
15    This test will set the policy, then check if the game is playable
16    or not, based off this policy.
17
18    The game should not be playable when the policy is not set.
19
20    It will determine if the game is playable via the presence of the
21    snackbar class inside the main-frame-error function
22
23    """
24    version = 1
25
26    POLICY_NAME = 'AllowDinosaurEasterEgg'
27
28    def _dino_check(self, policy_value):
29        """
30        Navigates to the chrome://dino page, and will check to see if the game
31        is playable or not.
32
33        @param policy_value: bool or None, the setting of the Dinosaur Policy
34
35        """
36        tab = self.navigate_to_url('chrome://dino')
37        _BLOCKED_JS = '* /deep/ #main-frame-error div.snackbar'
38        content = tab.EvaluateJavaScript("document.querySelector('{}')"
39                                         .format(_BLOCKED_JS))
40
41        if policy_value:
42            if content is not None:
43                raise error.TestError('Dino game was not playable,'
44                                      ' but should be allowed by policy.')
45        else:
46            if content is None:
47                raise error.TestError('Dino game was playable,'
48                                      ' but should not be allowed by policy.')
49
50    def run_once(self, case):
51        """
52        Setup and run the test configured for the specified test case.
53
54        @param case: Name of the test case to run.
55
56        """
57        self.setup_case(user_policies={self.POLICY_NAME: case})
58        self._dino_check(case)
59