• 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 logging
6import os
7import os.path
8import time
9
10from autotest_lib.client.bin import test, utils
11from autotest_lib.client.common_lib import error
12from autotest_lib.client.common_lib.cros import chrome
13from autotest_lib.client.cros.video import helper_logger
14
15
16class video_VimeoVideo(test.test):
17    """This test verifies Vimeo video.
18
19    - verify video playback.
20    - verify player states.
21
22    """
23    version = 1
24    _PLAYER_PLAY_STATE = 'play'
25    _PLAYER_PAUSE_STATE = 'pause'
26    _PLAYBACK_TEST_TIME_S = 10
27    _WAIT_TIMEOUT_S = 10
28    _WPR_ARCHIVE = '/usr/local/insight.wpr'
29
30
31    def _get_player_status(self):
32        """Returns the player status."""
33        return self._tab.EvaluateJavaScript('vimeo_player.status')
34
35
36    def _wait_for_player(self):
37        """Wait for the player to load."""
38        self._tab.WaitForJavaScriptCondition(
39                'typeof vimeo_player !== \'undefined\'',
40                timeout=self._WAIT_TIMEOUT_S)
41
42    def _wait_for_player_status(self, expected_status):
43        """"Wait for expected player status.
44
45        @param expected_status: expected player status to wait for.
46        """
47        utils.poll_for_condition(
48                lambda: self._get_player_status() == expected_status,
49                exception=error.TestError(
50                        'Vimeo player failed to obtain %s status. '
51                        'Current player status is %s.' %
52                        (expected_status, self._get_player_status())),
53                timeout=self._WAIT_TIMEOUT_S,
54                sleep_interval=1)
55
56
57    def _video_current_time(self):
58        "Returns current video time."""
59        self._tab.WaitForJavaScriptCondition(
60                'typeof vimeo_player.duration == \'number\'',
61                timeout=self._WAIT_TIMEOUT_S)
62        return float(self._tab.EvaluateJavaScript('vimeo_player.duration'))
63
64
65    def run_vimeo_tests(self, browser):
66        """Run Vimeo video sanity tests.
67
68        @param browser: The Browser object to run the test with.
69
70        """
71        self._tab = browser.tabs[0]
72        self._tab.Navigate(browser.platform.http_server.UrlOf(
73                os.path.join(self.bindir, 'vimeo.html')))
74        self._wait_for_player()
75        self._wait_for_player_status(self._PLAYER_PLAY_STATE)
76        # Abort the test if video is not playing.
77        utils.poll_for_condition(
78                lambda: self._video_current_time() > 5.0,
79                exception=error.TestError(
80                        'Init: video isn\'t playing.'),
81                timeout=self._WAIT_TIMEOUT_S,
82                sleep_interval=1)
83
84        #TODO: mussa crbug/445636 Get pausing and playing again to work
85        """ Pausing and Playing again under WPR currently causes vimeo to throw
86        an error and will stop the playback and fail the test.
87        Need to understand if we can make this work with WPR.
88        """
89
90        playback = 0 # seconds
91        prev_playback = 0
92        logging.info('video current time before loop: %s',
93                     self._video_current_time())
94        while (playback < self._PLAYBACK_TEST_TIME_S):
95            if self._video_current_time() <= prev_playback:
96                utils.poll_for_condition(
97                        lambda: self._video_current_time() > prev_playback,
98                        exception=error.TestError(
99                                'Long Wait: Video is not playing.'),
100                        timeout=self._WAIT_TIMEOUT_S,
101                        sleep_interval=1)
102            prev_playback = self._video_current_time()
103            logging.info('video curr time before sleep n prev playback: %s %s',
104                         self._video_current_time(), prev_playback)
105            time.sleep(1)
106            logging.info('video current time after sleep: %s',
107                         self._video_current_time())
108            playback = playback + 1
109
110
111    @helper_logger.video_log_wrapper
112    def run_once(self):
113        with chrome.Chrome(
114                extra_browser_args=helper_logger.chrome_vmodule_flag(),
115                init_network_controller=True) as cr:
116            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
117            self.run_vimeo_tests(cr.browser)
118