• 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.
4import time
5
6from autotest_lib.client.common_lib import error
7from autotest_lib.client.common_lib import utils
8
9from autotest_lib.client.cros.enterprise import enterprise_policy_base
10from autotest_lib.client.cros.input_playback import keyboard
11
12
13class policy_PrintingEnabled(
14        enterprise_policy_base.EnterprisePolicyTest):
15    """
16    Test effect of PrintingEnabled policy on Chrome OS.
17
18    The test will open a page, and attempt to 'print' the page as a local
19    PDF. If PDF is present after the print, printing is Enabled. If not,
20    printing is disabled.
21
22    """
23    version = 1
24
25    POLICY_NAME = 'PrintingEnabled'
26
27    def _input_key(self, key):
28        """
29        Press the key specified, wait a short time for the page to respond.
30
31        There is a 2 second wait for each button push to allow the dialog to
32        open, and load before proceeding. Because this dialog is not part of
33        the controllable telemetry view, there is not an easier/better way to
34        know if the dialog is fully loaded or not.
35
36        @key: string of the key(s) to press"""
37
38        self.keyboard.press_key(key)
39        time.sleep(2)
40
41    def _print_check(self, case):
42        """
43        Navigates to the chrome://policy page, and will check to see if the
44        print button is enabled/blocked.
45
46        @param case: bool or None, the setting of the PrintingEnabled Policy
47
48        """
49        self.navigate_to_url('chrome://policy')
50
51        # Open the print page, and hit enter to print, and save (as local pdf).
52        self._input_key('ctrl+p')
53        self._input_key('enter')
54        self._input_key('enter')
55
56        download_dur = utils.system_output('ls /home/chronos/user/Downloads/')
57
58        if case or case is None:
59            if 'Policies' not in download_dur:
60                raise error.TestError('Printing not enabled when it should be')
61        else:
62            if 'Policies' in download_dur:
63                raise error.TestError('Printing enabled when it should not be')
64
65    def run_once(self, case):
66        """
67        Entry point of the test.
68
69        @param case: Name of the test case to run.
70
71        """
72        self.keyboard = keyboard.Keyboard()
73        self.setup_case(user_policies={'PrintingEnabled': case},
74                        disable_default_apps=False)
75
76        self._print_check(case)
77        self.keyboard.close()
78