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