1 # Copyright 2018 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 functools 6 import logging 7 import numpy 8 import os 9 import time 10 11 from autotest_lib.client.bin import fps_meter 12 from autotest_lib.client.common_lib.cros import chrome 13 from autotest_lib.client.cros import touch_playback_test_base 14 15 import py_utils 16 17 """ The tracing file that contains the desired mouse scrolling events. """ 18 _PLAYBACK_FILE = 'mouse_event' 19 20 """ Description of the fake mouse we add to the system. """ 21 _MOUSE_DESCRIPTION = 'mouse.prop' 22 23 """ List of URLs that will be used to test users gestures on. """ 24 _LIST_OF_URLS = ['https://www.youtube.com', 'https://www.cnn.com', 25 'https://slashdot.org/'] 26 27 """ Separator used in fps_meter for each VSync """ 28 _SEPARATOR = ' ' 29 30 class platform_MouseScrollTest( 31 touch_playback_test_base.touch_playback_test_base): 32 """Fast scroll up and down with mouse pressure test.""" 33 version = 1 34 35 def _play_events(self, event_filename): 36 """ 37 Simulate mouse events for user scrolling. 38 39 @param event_filename string string file name containing the events 40 to play pack. 41 """ 42 file_path = os.path.join(self.bindir, event_filename) 43 self._blocking_playback(str(file_path), touch_type='mouse') 44 45 def run_once(self): 46 """ Runs the test once. """ 47 mouse_file = os.path.join(self.bindir, _MOUSE_DESCRIPTION) 48 self._emulate_mouse(property_file=mouse_file) 49 50 def record_fps_info(fps_data, fps_info): 51 """ record the fps info from |fps_meter| """ 52 frame_info, frame_times = fps_info 53 frame_info_str = ''.join(frame_info) 54 fps_count = sum( 55 map(int, frame_info_str.replace(_SEPARATOR, ""))) 56 fps_data.append(fps_count) 57 58 fps_data = [] 59 fps = fps_meter.FPSMeter(functools.partial(record_fps_info, fps_data)) 60 with chrome.Chrome(init_network_controller=True) as cr: 61 for url in _LIST_OF_URLS: 62 tab = cr.browser.tabs.New() 63 tab.Navigate(url) 64 try: 65 tab.WaitForDocumentReadyStateToBeComplete(timeout=15) 66 except py_utils.TimeoutException: 67 logging.warning('Time out during loading url ' + url) 68 69 tab.Activate() 70 cr.browser.platform.SetHTTPServerDirectories(self.bindir) 71 fps.start() 72 self._play_events(_PLAYBACK_FILE) 73 fps.stop() 74 time.sleep(1) 75 76 value = getattr(numpy, 'mean')(fps_data) 77 78 self.output_perf_value(description='fps average', 79 value=value, 80 units='frames per second', 81 higher_is_better=True) 82