1# Copyright (c) 2013 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 5import fnmatch 6import logging 7import os 8 9from autotest_lib.client.bin import test, utils 10from autotest_lib.client.common_lib import error 11from autotest_lib.client.common_lib.cros import chrome 12from autotest_lib.client.cros.video import helper_logger 13 14WAIT_TIMEOUT_S = 180 15 16class video_VideoSeek(test.test): 17 """This test verifies video seek works in Chrome.""" 18 version = 1 19 20 def is_skipping_test(self, codec, is_switchres): 21 """Determine whether this test should skip. 22 23 @param codec: the codec to be tested, ex. 'vp8', 'vp9', 'h264'. 24 @param is_switchres: bool, True if using switch resolution video. 25 """ 26 blacklist = [ 27 # (board, codec, is_switchres); None if don't care. 28 29 # "board" supports Unix shell-type wildcards 30 31 # Disable vp8 switchres for nyan devices temporarily due to: 32 # crbug/699260 33 ('nyan', 'vp8', True), ('nyan_*', 'vp8', True) 34 ] 35 36 board = utils.get_current_board() 37 38 for entry in blacklist: 39 if ((entry[0] is None or fnmatch.fnmatch(board, entry[0])) and 40 (entry[1] is None or codec == entry[1]) and 41 (entry[2] is None or is_switchres == entry[2])): 42 return True 43 44 return False 45 46 47 @helper_logger.video_log_wrapper 48 def run_once(self, codec, is_switchres, video): 49 """Tests whether video seek works by random seeks forward and backward. 50 51 @param codec: the codec to be tested, ex. 'vp8', 'vp9', 'h264'. 52 @param is_switchres: bool, True if using switch resolution video. 53 @param video: Sample video file to be seeked in Chrome. 54 """ 55 if self.is_skipping_test(codec, is_switchres): 56 logging.info('Skipping test run on this board.') 57 return # return immediately to pass this test 58 59 with chrome.Chrome( 60 extra_browser_args=helper_logger.chrome_vmodule_flag(), 61 init_network_controller=True) as cr: 62 cr.browser.platform.SetHTTPServerDirectories(self.bindir) 63 tab = cr.browser.tabs[0] 64 tab.Navigate(cr.browser.platform.http_server.UrlOf( 65 os.path.join(self.bindir, 'video.html'))) 66 tab.WaitForDocumentReadyStateToBeComplete() 67 68 tab.EvaluateJavaScript('loadSourceAndRunSeekTest("%s")' % video) 69 70 def get_seek_test_status(): 71 seek_test_status = tab.EvaluateJavaScript('getSeekTestStatus()') 72 logging.info('Seeking: %s', seek_test_status) 73 return seek_test_status 74 75 utils.poll_for_condition( 76 lambda: get_seek_test_status() == 'pass', 77 exception=error.TestError('Seek test is stuck and timeout'), 78 timeout=WAIT_TIMEOUT_S, 79 sleep_interval=1) 80