1# Lint as: python2, python3 2# Copyright 2016 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_TouchscreenZoom(touch_playback_test_base.touch_playback_test_base): 14 """Plays back touchscreen zoom and checks for correct page movement. 15 16 Test zooms in and then out, checking that direction is correct. 17 18 """ 19 version = 1 20 21 _DIRECTIONS = ['in', 'out'] 22 _FILENAME_FMT_STR = 'zoom-%s' 23 24 25 def _check_zoom_in_one_direction(self, direction): 26 logging.info('Starting to zoom %s', direction) 27 start_level = self._events.get_page_zoom() 28 self._events.clear_previous_events() 29 30 self._playback(self._filepaths[direction], 'touchscreen') 31 32 self._events.wait_for_events_to_complete() 33 end_level = self._events.get_page_zoom() 34 delta = end_level - start_level 35 36 if delta == 0: 37 self._events.log_events() 38 raise error.TestFail('No page zoom occurred!') 39 40 if ((delta < 0 and direction == 'in') or 41 (delta > 0 and direction == 'out')): 42 self._events.log_events() 43 raise error.TestFail('Zoom was in the wrong direction!') 44 45 46 def _is_testable(self): 47 """Return True if test can run on this device, else False. 48 49 @raises: TestError if host has no touchscreen when it should. 50 51 """ 52 # Raise error if no touchscreen detected. 53 if not self._has_touchscreen: 54 raise error.TestError('No touchscreen found on this device!') 55 56 # Check if playback files are available on DUT to run test. 57 self._filepaths = self._find_test_files_from_directions( 58 'touchscreen', self._FILENAME_FMT_STR, self._DIRECTIONS) 59 if not self._filepaths: 60 logging.info('Missing gesture files, Aborting test.') 61 return False 62 63 return True 64 65 66 def run_once(self): 67 """Entry point of this test.""" 68 if not self._is_testable(): 69 raise error.TestNAError('Missing input data for this board name.') 70 71 # Log in and start test. 72 with chrome.Chrome(init_network_controller=True) as cr: 73 self._open_events_page(cr) 74 self._events.set_prevent_defaults(False) 75 76 # Zoom in and out on test page. 77 for direction in self._DIRECTIONS: 78 self._check_zoom_in_one_direction(direction) 79