Home | History | Annotate | Download | only in touch_StylusTaps
      1 # Copyright 2017 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 import logging
      6 
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.client.common_lib.cros import chrome
      9 from autotest_lib.client.cros import touch_playback_test_base
     10 
     11 
     12 class touch_StylusTaps(touch_playback_test_base.touch_playback_test_base):
     13     """Checks that stylus touches are translated into clicks."""
     14     version = 1
     15 
     16     _CLICK_NAME = 'tap'
     17 
     18     def _check_for_click(self):
     19         """Playback and check whether click occurred.  Fail if not.
     20 
     21         @raises: TestFail if no click or hover occurred.
     22 
     23         """
     24         cases = [(self._CLICK_NAME, 1)]
     25         for (filename, expected_count) in cases:
     26             self._events.clear_previous_events()
     27             self._blocking_playback(filepath=self._filepaths[filename],
     28                                     touch_type='stylus')
     29             self._events.wait_for_events_to_complete()
     30 
     31             actual_count = self._events.get_click_count()
     32             if actual_count is not expected_count:
     33                 self._events.log_events()
     34                 raise error.TestFail('Saw %d clicks when %s were expected!' % (
     35                         actual_count, expected_count))
     36 
     37     def run_once(self):
     38         """Entry point of this test."""
     39         self._filepaths = self._find_test_files('stylus', [self._CLICK_NAME])
     40         if not self._filepaths:
     41             logging.info('Missing gesture files, Aborting test.')
     42             return
     43 
     44         # Log in and start test.
     45         with chrome.Chrome(init_network_controller=True) as cr:
     46             self._open_events_page(cr)
     47             self._events.set_prevent_defaults(False)
     48             self._check_for_click()
     49