1# Lint as: python2, python3 2# Copyright 2018 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.bin import utils 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.common_lib.cros import chrome 11from autotest_lib.client.cros import touch_playback_test_base 12 13 14class touch_GestureNav(touch_playback_test_base.touch_playback_test_base): 15 """Test to verify the three finger tab switching touchpad gesture.""" 16 version = 1 17 18 _WAIT_FOR_COMPLETE_NAV = 5 19 20 def _is_testable(self): 21 """Returns True if the test can run on this device, else False.""" 22 if not self._has_touchpad: 23 raise error.TestError('No touchpad found on this device!') 24 25 # Check if playback files are available on DUT to run test. 26 self._filepaths = self._find_test_files_from_directions('touchpad', 27 'two-finger-longswipe-%s', ['back', 'fwd']) 28 if not self._filepaths: 29 logging.info('Missing gesture files. Aborting test.') 30 return False 31 32 return True 33 34 35 def _check_tab_navigate(self, to_url, direction=''): 36 """ 37 Verify tab navigation behavior. Moving two fingers one or 38 another direction will navigate back or forward in the tab. 39 40 @param direction: the swipe direction and the input file suffix. 41 @param to_url: url to verify the swipe navigated to. 42 43 """ 44 self.tab.WaitForDocumentReadyStateToBeComplete() 45 fail_msg = 'Incorrect tab navigating %s to %s' % (direction, to_url) 46 utils.poll_for_condition( 47 lambda: self.tab.url.encode('utf8').rstrip('/') == to_url, 48 exception=error.TestFail(fail_msg), 49 timeout=self._WAIT_FOR_COMPLETE_NAV) 50 51 52 def run_once(self): 53 """Entry point of this test.""" 54 if not self._is_testable(): 55 raise error.TestNAError('Missing input data for this board name.') 56 57 # Log in and start test. 58 with chrome.Chrome(autotest_ext=True, 59 init_network_controller=True) as cr: 60 self.tab = cr.browser.tabs[0] 61 62 url_back = 'https://www.youtube.com' 63 url_fwd = 'https://www.google.com' 64 65 # Navigate to two urls in the same tab 66 self.tab.Navigate(url_back) 67 self._check_tab_navigate(url_back) 68 self.tab.Navigate(url_fwd) 69 self._check_tab_navigate(url_fwd) 70 71 # Swipe to navigate back 72 self._blocking_playback(touch_type='touchpad', 73 filepath=self._filepaths['back']) 74 self._check_tab_navigate(url_back, 'back') 75 76 # Swipe to navigate forward 77 self._blocking_playback(touch_type='touchpad', 78 filepath=self._filepaths['fwd']) 79 self._check_tab_navigate(url_fwd, 'fwd') 80