Home | History | Annotate | Download | only in touch_TouchscreenTaps
      1 # Copyright 2015 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_TouchscreenTaps(touch_playback_test_base.touch_playback_test_base):
     13     """Checks that touchscreen presses are translated into clicks."""
     14     version = 1
     15 
     16     _CLICK_NAME = 'tap'
     17 
     18 
     19     def _check_for_click(self):
     20         """Playback and check whether click occurred.  Fail if not.
     21 
     22         @raises: TestFail if no click occurred.
     23 
     24         """
     25         self._events.clear_previous_events()
     26         self._blocking_playback(filepath=self._filepaths[self._CLICK_NAME],
     27                                 touch_type='touchscreen')
     28         self._events.wait_for_events_to_complete()
     29 
     30         actual_count = self._events.get_click_count()
     31         if actual_count is not 1:
     32             self._events.log_events()
     33             raise error.TestFail('Saw %d clicks!' % actual_count)
     34 
     35 
     36     def _is_testable(self):
     37         """Return True if test can run on this device, else False.
     38 
     39         @raises: TestError if host has no touchscreen.
     40 
     41         """
     42         # Raise error if no touchscreen detected.
     43         if not self._has_touchscreen:
     44             raise error.TestError('No touchscreen found on this device!')
     45 
     46         # Check if playback files are available on DUT to run test.
     47         self._filepaths = self._find_test_files(
     48                 'touchscreen', [self._CLICK_NAME])
     49         if not self._filepaths:
     50             logging.info('Missing gesture files, Aborting test.')
     51             return False
     52 
     53         return True
     54 
     55 
     56     def run_once(self):
     57         """Entry point of this test."""
     58         if not self._is_testable():
     59             return
     60 
     61         # Log in and start test.
     62         with chrome.Chrome(init_network_controller=True) as cr:
     63             self._open_events_page(cr)
     64             self._events.set_prevent_defaults(False)
     65             self._check_for_click()
     66