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