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 import time
      7 
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.client.common_lib.cros import chrome
     10 from autotest_lib.client.cros import touch_playback_test_base
     11 
     12 
     13 class touch_TouchscreenTaps(touch_playback_test_base.touch_playback_test_base):
     14     """Checks that touchscreen presses are translated into clicks."""
     15     version = 1
     16 
     17     _TEST_TIMEOUT = 1  # Number of seconds the test will wait for a click.
     18     _CLICK_NAME = 'tap'
     19 
     20 
     21     def _check_for_click(self):
     22         """Playback and check whether click occurred.  Fail if not.
     23 
     24         @raises: TestFail if no click occurred.
     25 
     26         """
     27         self._reload_page()
     28         self._blocking_playback(filepath=self._filepaths[self._CLICK_NAME],
     29                                 touch_type='touchscreen')
     30         time.sleep(self._TEST_TIMEOUT)
     31         actual_count = int(self._tab.EvaluateJavaScript('clickCount'))
     32         if actual_count is not 1:
     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() as cr:
     63             self._open_test_page(cr)
     64             self._check_for_click()
     65