• 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
5import logging
6import re
7
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.common_lib.cros import chrome
10from autotest_lib.client.cros.enterprise import enterprise_policy_base
11from autotest_lib.client.cros.input_playback import input_playback
12from autotest_lib.client.cros.touch_playback_test_base import EventsPage
13
14
15class policy_KeyboardDefaultToFunctionKeys(
16        enterprise_policy_base.EnterprisePolicyTest):
17    version = 1
18
19    POLICY_NAME = 'KeyboardDefaultToFunctionKeys'
20    TEST_CASES = {
21        'True': True,
22        'False': False,
23        'NotSet': None
24    }
25
26
27    def initialize(self, **kwargs):
28        """
29        Emulate a keyboard and initialize enterprise policy base.
30
31        """
32        super(policy_KeyboardDefaultToFunctionKeys, self).initialize(**kwargs)
33        self.player = input_playback.InputPlayback()
34        self.player.emulate(input_type='keyboard')
35        self.player.find_connected_inputs()
36
37
38    def cleanup(self):
39        """
40        Close playback and policy base class.
41
42        """
43        self.player.close()
44        super(policy_KeyboardDefaultToFunctionKeys, self).cleanup()
45
46
47    def _test_function_keys_default(self, policy_value):
48        """
49        Test default function keys action.
50
51        Search+function keys should perform the alternate action.
52
53        @param policy_value: policy value for this case.
54        @raises error.TestFail if keypress differs from expected value.
55
56        """
57        # Get focus of the page
58        self.player.blocking_playback_of_default_file(
59            input_type='keyboard', filename='keyboard_enter')
60
61        key_actions = ['BrowserForward', 'F2']
62
63        if policy_value:
64            key_actions = reversed(key_actions)
65
66        for action, keys in zip(key_actions, ['f2', 'search+f2']):
67            self._events.clear_previous_events()
68
69            self.player.blocking_playback_of_default_file(
70                input_type='keyboard', filename='keyboard_' + keys)
71
72            events_log = self._events.get_events_log()
73            logging.info('Events log: ' + events_log)
74
75            if not re.search('key=' + action, events_log):
76                raise error.TestFail(('policy_value: %s - typed: %s, '
77                                     'expected: %s') %
78                                     (policy_value, keys, action))
79
80
81    def run_once(self, case):
82        """
83        Setup and run the test configured for the specified test case.
84
85        @param case: Name of the test case to run.
86
87        """
88        case_value = self.TEST_CASES[case]
89        self.setup_case(user_policies={self.POLICY_NAME: case_value},
90                        init_network_controller=True)
91
92        self._events = EventsPage(self.cr, self.bindir)
93        self._test_function_keys_default(case_value)
94