• 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.
4from autotest_lib.client.common_lib import error
5from autotest_lib.client.cros.enterprise import enterprise_policy_base
6from autotest_lib.client.cros.input_playback import keyboard
7
8
9class policy_IncognitoModeAvailability(
10        enterprise_policy_base.EnterprisePolicyTest):
11    """
12    Tests the IncognitoModeAvailable policy in Chrome OS.
13
14    If the policy is set to Available then the user will be able to open
15    a new Incognito window. If the policy is Disabled then the user should not
16    be able to open a new Incognito window. Forced is not being tested.
17
18    """
19    version = 1
20
21    def initialize(self, **kwargs):
22        super(policy_IncognitoModeAvailability, self).initialize(**kwargs)
23        self.keyboard = keyboard.Keyboard()
24        self.POLICY_NAME = 'IncognitoModeAvailability'
25        self.POLICIES = {}
26        self.TEST_CASES = {
27            'Available': 0,
28            'Disabled': 1}
29
30    def _check_incognito_mode_availability(self, case):
31        """
32        Opens a new chrome://user-actions page and then tries to open a new
33        Incognito window. To see if the new window actually opened the test
34        checks the number of tabs opened as well as what was recorded in
35        user actions.
36
37        @param case: policy description.
38
39        """
40        page_scrape_cmd = (
41            'document.getElementById("user-actions-table").innerText;')
42        self.navigate_to_url('chrome://user-actions')
43        current_number_of_chrome_tabs = len(self.cr.browser.tabs)
44        self.keyboard.press_key('ctrl+shift+n')
45        new_tab_count = len(self.cr.browser.tabs)
46
47        recorded_user_actions = (
48            self.cr.browser.tabs[1].EvaluateJavaScript(page_scrape_cmd))
49
50        if case == 'Available':
51            if (new_tab_count <= current_number_of_chrome_tabs or
52                'NewIncognitoWindow' not in recorded_user_actions):
53                    raise error.TestFail('New Incognito window did not open.')
54
55        else:
56            if (new_tab_count != current_number_of_chrome_tabs or
57                'Accel_New_Incognito_Window' not in recorded_user_actions):
58                   raise error.TestFail('New Incognito window did open.')
59
60    def run_once(self, case):
61        """
62        Setup and run the test configured for the specified test case.
63
64        @param case: Name of the test case to run.
65
66        """
67        case_value = self.TEST_CASES[case]
68        self.POLICIES[self.POLICY_NAME] = case_value
69        self.setup_case(user_policies=self.POLICIES)
70        self._check_incognito_mode_availability(case)