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