• 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
6
7from autotest_lib.client.bin import test, utils
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.common_lib.cros import chrome
10
11WAIT_TIMEOUT_S = 30
12
13class video_VideoReload(test.test):
14    """This test verifies reloading video works in Chrome."""
15    version = 1
16
17    def run_once(self, html):
18        """Tests whether Chrome reloads video after reloading the tab.
19
20        @param html: Sample html file to be loaded and reloaded in Chrome.
21        """
22        with chrome.Chrome() as cr:
23            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
24            tab = cr.browser.tabs[0]
25            tab.Navigate(cr.browser.platform.http_server.UrlOf(
26                    os.path.join(self.bindir, html)))
27
28            def is_video_at_start():
29                """Checks if video is at the start position."""
30                return tab.EvaluateJavaScript(
31                        '(typeof videoAtStart != "undefined") && videoAtStart')
32
33            # Expect video being loaded and started for the first time.
34            utils.poll_for_condition(
35                    is_video_at_start,
36                    exception=error.TestError('Video is not started'),
37                    timeout=WAIT_TIMEOUT_S,
38                    sleep_interval=1)
39
40            # Reload the tab after playing video for a while.
41            tab.EvaluateJavaScript('playAndReload()')
42
43            # Expect video being restarted after reloading the tab.
44            utils.poll_for_condition(
45                    is_video_at_start,
46                    exception=error.TestError('Video is not restarted'),
47                    timeout=WAIT_TIMEOUT_S,
48                    sleep_interval=1)
49