xref: /aosp_15_r20/external/autotest/client/site_tests/touch_StylusTaps/touch_StylusTaps.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
2# Copyright 2017 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import logging
7
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.common_lib.cros import chrome
10from autotest_lib.client.cros import touch_playback_test_base
11
12
13class touch_StylusTaps(touch_playback_test_base.touch_playback_test_base):
14    """Checks that stylus touches are translated into clicks."""
15    version = 1
16
17    _CLICK_NAME = 'tap'
18
19    def _check_for_click(self):
20        """Playback and check whether click occurred.  Fail if not.
21
22        @raises: TestFail if no click or hover occurred.
23
24        """
25        cases = [(self._CLICK_NAME, 1)]
26        for (filename, expected_count) in cases:
27            self._events.clear_previous_events()
28            self._blocking_playback(filepath=self._filepaths[filename],
29                                    touch_type='stylus')
30            self._events.wait_for_events_to_complete()
31
32            actual_count = self._events.get_click_count()
33            if actual_count is not expected_count:
34                self._events.log_events()
35                raise error.TestFail('Saw %d clicks when %s were expected!' % (
36                        actual_count, expected_count))
37
38    def run_once(self):
39        """Entry point of this test."""
40        self._filepaths = self._find_test_files('stylus', [self._CLICK_NAME])
41        if not self._filepaths:
42            logging.info('Missing gesture files, Aborting test.')
43            raise error.TestNAError('Missing input data for this board name.')
44
45        # Log in and start test.
46        with chrome.Chrome(init_network_controller=True) as cr:
47            self._open_events_page(cr)
48            self._events.set_prevent_defaults(False)
49            self._check_for_click()
50