def display(filepath): """Display chart with filepath on device by using telemetry.""" assert os.path.isfile(filepath), 'filepath %r not found.' % filepath filepath = os.path.abspath(filepath) logging.info('Setup SIGINT listener for stop displaying.') displaying = [True] def handler(signum, frame): """Wait signal to clear running flag.""" if signum == signal.SIGINT: displaying.pop() signal.signal(signal.SIGINT, handler) with chrome.Chrome(init_network_controller=True ) as cr, set_display_brightness(DISPLAY_LEVEL): logging.info('Display chart file of path %r.', filepath) cr.browser.platform.SetHTTPServerDirectories(os.path.dirname(filepath)) tab = cr.browser.tabs[0] tab.Navigate(cr.browser.platform.http_server.UrlOf(filepath)) logging.info('Set chart tab fullscreen.') kb = keyboard.Keyboard() kb.press_key('f4') kb.close() logging.info('Chart is ready.') while displaying: time.sleep(1)
def run_once(self, test_url=JELLYFISH_URL, duration=2.5 * HOUR): """run_once method. @param test_url: url of webgl heavy page. @param duration: time in seconds to display url and measure power. """ with chrome.Chrome(init_network_controller=True) as self.cr: tab = self.cr.browser.tabs.New() tab.Activate() # Just measure power in full-screen. fullscreen = tab.EvaluateJavaScript('document.webkitIsFullScreen') if not fullscreen: with keyboard.Keyboard() as keys: keys.press_key('f4') self.backlight.set_percent(100) logging.info('Navigating to url: %s', test_url) tab.Navigate(test_url) tab.WaitForDocumentReadyStateToBeComplete() if test_url == self.JELLYFISH_URL: # Change param to 100 fast moving jellyfish. tab.EvaluateJavaScript('$("#jCount").val(100);') tab.EvaluateJavaScript('$("#jSpeed").val(0.1);') # Jellyfish is added one by one. Wait until we have 100. while tab.EvaluateJavaScript('jellyfish.count') < 100: time.sleep(0.1) self.start_measurements() time.sleep(duration)
def display(filepath): """Display chart with filepath on device by using telemetry.""" assert os.path.isfile(filepath), 'filepath %r not found.' % filepath filepath = os.path.abspath(filepath) logging.info('Setup SIGINT listener for stop displaying.') displaying = [True] def handler(signum, frame): """Wait signal to clear running flag.""" if signum == signal.SIGINT: displaying.pop() signal.signal(signal.SIGINT, handler) with chrome.Chrome() as cr, set_display_brightness(DISPLAY_LEVEL): logging.info('Display chart file of path %r.', filepath) tab = cr.browser.tabs[0] tab.Navigate('file://' + filepath) logging.info('Set chart tab fullscreen.') kb = keyboard.Keyboard() kb.press_key('f4') kb.close() while displaying: time.sleep(1)
def initialize(self, **kwargs): super(policy_IncognitoModeAvailability, self).initialize(**kwargs) self.keyboard = keyboard.Keyboard() self.POLICY_NAME = 'IncognitoModeAvailability' self.POLICIES = {} self.TEST_CASES = { 'Available': 0, 'Disabled': 1}
def log_out_via_keyboard(self): """ Logs out of the device using the keyboard shortcut """ _keyboard = keyboard.Keyboard() _keyboard.press_key('ctrl+shift+q') _keyboard.press_key('ctrl+shift+q') _keyboard.close()
def initialize(self, **kwargs): super(policy_DeveloperToolsAvailability, self).initialize(**kwargs) self.keyboard = keyboard.Keyboard() self.POLICY_NAME = 'DeveloperToolsAvailability' self.POLICIES = {} self.TEST_CASES = { 'NotSet': None, 'DisabledOnExtensions': 0, 'Available': 1, 'Disabled': 2 }
def run_once(self, videos=None, secs_per_video=_MEASUREMENT_DURATION, use_hw_decode=True): """run_once method. @param videos: list of tuple of tagname and video url to test. @param secs_per_video: time in seconds to play video and measure power. @param use_hw_decode: if False, disable hw video decoding. """ videos_local = [] loop = 0 if not videos: videos = self._VIDEOS # Download video to ramdisk for name, url in videos: local_path = os.path.join(self._RAMDISK, os.path.basename(url)) logging.info('Downloading %s to %s', url, local_path) file_utils.download_file(url, local_path) videos_local.append((name, local_path)) extra_browser_args = [] if not use_hw_decode: extra_browser_args.append(self._DISABLE_HW_VIDEO_DECODE_ARGS) with chrome.Chrome(extra_browser_args=extra_browser_args, init_network_controller=True) as self.cr: self.cr.browser.platform.SetHTTPServerDirectories(self._RAMDISK) tab = self.cr.browser.tabs.New() tab.Activate() # Just measure power in full-screen. fullscreen = tab.EvaluateJavaScript('document.webkitIsFullScreen') if not fullscreen: with keyboard.Keyboard() as keys: keys.press_key('f4') time.sleep(self._WAIT_FOR_IDLE) self.start_measurements() for name, url in videos_local: logging.info('Playing video: %s', name) self._play_video(self.cr, url) tagname = '%s_%s' % (self.tagged_testname, name) loop_start = time.time() self.loop_sleep(loop, secs_per_video) self.keyvals[name + '_dropped_frame_percent'] = \ self._calculate_dropped_frame_percent(tab) self.checkpoint_measurements(tagname, loop_start) loop += 1
def run_once(self, case): """ Setup and run the test configured for the specified test case. @param case: Name of the test case to run. """ self.keyboard = keyboard.Keyboard() TEST_CASES = {'Set': 'chrome://policy', 'NotSet': None} case_value = TEST_CASES[case] policy_setting = {'NewTabPageLocation': case_value} self.setup_case(user_policies=policy_setting) self._homepage_check(case_value)
def initialize(self): self.keyboard = keyboard.Keyboard() self.username, password = arc_util.get_test_account_info() # Login a user session. if utils.is_arc_available(): super(platform_LogoutPerf, self).initialize(gaia_login=True, disable_arc_opt_in=False) self.cr = self._chrome else: with tempfile.NamedTemporaryFile() as cap: file_utils.download_file(arc_util._ARCP_URL, cap.name) password = cap.read().rstrip() self.cr = chrome.Chrome(gaia_login=True, username=self.username, password=password)
def _test_lock_status(self, case): """ Verify the screen lock status. @param case: bool or None, setting of AllowScreenLock policy. """ _keyboard = keyboard.Keyboard() lock_state = self.cr.login_status['isScreenLocked'] if lock_state: raise error.TestFail('Screen was locked prior to test') # Lock the screen with the screenlock hotkey _keyboard.press_key('search+L') is_locked = self.cr.login_status['isScreenLocked'] # Policy is None or True if case is not False and not is_locked: raise error.TestFail('Screen was NOT locked when should be')
def initialize(self): """Setup the test environment.""" # Create a virtual keyboard device for key event playback. self.keyboard = keyboard.Keyboard() # Create a virtual stylus self.stylus = stylus.Stylus() # Instantiate Chrome browser. username, password = arc_util.get_test_account_info() self.browser = chrome.Chrome(gaia_login=True, username=username, password=password) self.tab = self.browser.browser.tabs[0] # Setup Chrome Tracing. config = tracing_config.TracingConfig() category_filter = config.chrome_trace_config.category_filter category_filter.AddFilterString(_TARGET_TRACING_CATEGORIES) config.enable_chrome_trace = True self.target_tracing_config = config
def run_once(self, url=URL, duration=180): """run_once method. @param url: url of webgl heavy page. @param duration: time in seconds to display url and measure power. """ with chrome.Chrome(init_network_controller=True) as self.cr: tab = self.cr.browser.tabs.New() tab.Activate() # Just measure power in full-screen. fullscreen = tab.EvaluateJavaScript('document.webkitIsFullScreen') if not fullscreen: with keyboard.Keyboard() as keys: keys.press_key('f4') logging.info('Navigating to url: %s', url) tab.Navigate(url) tab.WaitForDocumentReadyStateToBeComplete() self.start_measurements() time.sleep(duration)
def initialize_test(self, chrome, player_page): """Initializes the test. @param chrome: An Autotest Chrome instance. @param player_page: The URL (string) of the YouTube player page to test. """ self.tab = chrome.browser.tabs[0] self.tab.Navigate(player_page) self.tab.WaitForDocumentReadyStateToBeComplete() time.sleep(2) self.keys = keyboard.Keyboard() with open( os.path.join(os.path.dirname(__file__), 'files/video_YouTubePageCommon.js')) as f: js = f.read() if not self.tab.EvaluateJavaScript(js): raise error.TestFail('YouTube page failed to load.') logging.info('Loaded accompanying .js script.')
def run_once(self, pages=None, secs_per_page=60, brightness=''): """run_once method. @param pages: list of pages names that must be in <testdir>/html/<name>.html @param secs_per_page: time in seconds to display page and measure power. @param brightness: flag for brightness setting to use for testing. possible value are 'max' (100%) and 'all' (all manual brightness steps in Chrome OS) """ if pages is None: pages = self.PAGES with chrome.Chrome(init_network_controller=True) as self.cr: http_path = os.path.join(self.job.testdir, 'power_Display', 'html') self.cr.browser.platform.SetHTTPServerDirectories(http_path) tab = self.cr.browser.tabs.New() tab.Activate() # Just measure power in full-screen. fullscreen = tab.EvaluateJavaScript('document.webkitIsFullScreen') if not fullscreen: with keyboard.Keyboard() as keys: keys.press_key('f4') if brightness not in ['', 'all', 'max']: raise error.TestFail( 'Invalid brightness flag: %s' % (brightness)) if brightness == 'max': self.backlight.set_percent(100) brightnesses = [] if brightness == 'all': self.backlight.set_percent(100) for step in range(16, 0, -1): nonlinear = step * 6.25 linear = self.backlight.nonlinear_to_linear(nonlinear) brightnesses.append((nonlinear, linear)) else: linear = self.backlight.get_percent() nonlinear = self.backlight.linear_to_nonlinear(linear) brightnesses.append((nonlinear, linear)) self.start_measurements() loop = 0 for name in pages: url = os.path.join(http_path, name + '.html') logging.info('Navigating to url: %s', url) tab.Navigate(self.cr.browser.platform.http_server.UrlOf(url)) tab.WaitForDocumentReadyStateToBeComplete() for nonlinear, linear in brightnesses: self.backlight.set_percent(linear) tagname = '%s_%s' % (self.tagged_testname, name) if len(brightnesses) > 1: tagname += '_%.2f' % (nonlinear) loop_start = time.time() self.loop_sleep(loop, secs_per_page) self.checkpoint_measurements(tagname, loop_start) loop += 1
def initialize(self, **kwargs): super(policy_HomepageLocation, self).initialize(**kwargs) self.keyboard = keyboard.Keyboard() self.POLICY_NAME = 'HomepageLocation' self.SUPPORTING_POLICIES = {'HomepageIsNewTabPage': False} self.TEST_CASES = {'Set': 'chrome://version/', 'NotSet': None}