Home | History | Annotate | Download | only in video_MultiplePlayback
      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 
      5 import os, time
      6 
      7 
      8 from autotest_lib.client.bin import test, utils
      9 from autotest_lib.client.common_lib import error
     10 from autotest_lib.client.common_lib.cros import chrome
     11 from autotest_lib.client.cros.video import youtube_helper
     12 
     13 
     14 FLASH_PROCESS_NAME = 'chrome/chrome --type=ppapi'
     15 PLAYER_PLAYING_STATE = 'Playing'
     16 PLAYBACK_TEST_TIME_S = 10
     17 
     18 
     19 class 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.WaitForJavaScriptCondition('testvideo.currentTime < 1.0',
     61                                         timeout=5)
     62 
     63         tab2 = browser.tabs.New()
     64         tab2.Navigate(browser.platform.http_server.UrlOf(
     65                 os.path.join(self.bindir, 'youtube5.html')))
     66         yh = youtube_helper.YouTubeHelper(tab2)
     67         # Waiting for test video to load.
     68         yh.wait_for_player_state(PLAYER_PLAYING_STATE)
     69         yh.set_video_duration()
     70         # Verify that YouTube is running in html5 mode.
     71         prc = utils.get_process_list('chrome', '--type=ppapi')
     72         if prc:
     73             raise error.TestFail('Tab2: Running YouTube in Flash mode.')
     74 
     75         tab3 = browser.tabs.New()
     76         tab3.Navigate(browser.platform.http_server.UrlOf(
     77                 os.path.join(self.bindir, 'youtube.html')))
     78         yh1 = youtube_helper.YouTubeHelper(tab3)
     79         # Waiting for test video to load.
     80         yh1.wait_for_player_state(PLAYER_PLAYING_STATE)
     81         yh1.set_video_duration()
     82         # Verify that YouTube is running in html5 mode.
     83         prc1 = utils.get_process_list('chrome', '--type=ppapi')
     84         if not prc1:
     85             raise error.TestFail('Tab3: No flash process is Running .')
     86 
     87         # Verifying video playback.
     88         self.verify_localvideo_playback(tab1)
     89         yh.verify_video_playback()
     90         yh1.verify_video_playback()
     91 
     92 
     93     def run_once(self):
     94         # TODO(scottz): Remove this when crbug.com/220147 is fixed.
     95         dut_board = utils.get_current_board()
     96         if dut_board == 'x86-mario':
     97            raise error.TestNAError('This test is not available on %s' %
     98                                     dut_board)
     99         with chrome.Chrome(init_network_controller=True) as cr:
    100             self.run_video_tests(cr.browser)
    101