1# Copyright (c) 2014 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 os, time 6 7 8from autotest_lib.client.bin import test, utils 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.common_lib.cros import chrome 11from autotest_lib.client.cros.video import youtube_helper 12 13 14FLASH_PROCESS_NAME = 'chrome/chrome --type=ppapi' 15PLAYER_PLAYING_STATE = 'Playing' 16PLAYBACK_TEST_TIME_S = 10 17 18 19class video_MultiplePlayback(test.test): 20 """This test verify simultaneous video playback. 21 We are testing using Youtube html5, flash and a local video. 22 23 """ 24 version = 1 25 26 27 def verify_localvideo_playback(self, tab1): 28 """To verify local video playback 29 30 @param tab1: browser tab. 31 """ 32 33 playback = 0 # seconds 34 prev_playback = 0 35 while (int(tab1.EvaluateJavaScript('testvideo.currentTime')) 36 < int(tab1.EvaluateJavaScript('testvideo.duration')) 37 and playback < PLAYBACK_TEST_TIME_S): 38 if (int(tab1.EvaluateJavaScript('testvideo.currentTime')) 39 <= prev_playback): 40 raise error.TestError('Video is not playing.') 41 prev_playback = int(tab1.EvaluateJavaScript( 42 'testvideo.currentTime')) 43 time.sleep(1) 44 playback = playback + 1 45 46 47 def run_video_tests(self, browser): 48 """Play youtube html5, flash and a loca video, and verify the playback. 49 50 @param browser: The Browser object to run the test with. 51 52 """ 53 browser.platform.SetHTTPServerDirectories(self.bindir) 54 tab1 = browser.tabs.New() 55 # Verifying <video> support. 56 tab1.Navigate(browser.platform.http_server.UrlOf( 57 os.path.join(self.bindir, 'video.html'))) 58 59 # Waiting for test video to load. 60 tab1.WaitForJavaScriptExpression('testvideo.currentTime < 1.0', 5) 61 62 tab2 = browser.tabs.New() 63 tab2.Navigate(browser.platform.http_server.UrlOf( 64 os.path.join(self.bindir, 'youtube5.html'))) 65 yh = youtube_helper.YouTubeHelper(tab2) 66 # Waiting for test video to load. 67 yh.wait_for_player_state(PLAYER_PLAYING_STATE) 68 yh.set_video_duration() 69 # Verify that YouTube is running in html5 mode. 70 prc = utils.get_process_list('chrome', '--type=ppapi') 71 if prc: 72 raise error.TestFail('Tab2: Running YouTube in Flash mode.') 73 74 tab3 = browser.tabs.New() 75 tab3.Navigate(browser.platform.http_server.UrlOf( 76 os.path.join(self.bindir, 'youtube.html'))) 77 yh1 = youtube_helper.YouTubeHelper(tab3) 78 # Waiting for test video to load. 79 yh1.wait_for_player_state(PLAYER_PLAYING_STATE) 80 yh1.set_video_duration() 81 # Verify that YouTube is running in html5 mode. 82 prc1 = utils.get_process_list('chrome', '--type=ppapi') 83 if not prc1: 84 raise error.TestFail('Tab3: No flash process is Running .') 85 86 # Verifying video playback. 87 self.verify_localvideo_playback(tab1) 88 yh.verify_video_playback() 89 yh1.verify_video_playback() 90 91 92 def run_once(self): 93 # TODO(scottz): Remove this when crbug.com/220147 is fixed. 94 dut_board = utils.get_current_board() 95 if dut_board == 'x86-mario': 96 raise error.TestNAError('This test is not available on %s' % 97 dut_board) 98 with chrome.Chrome() as cr: 99 self.run_video_tests(cr.browser) 100