• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 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
7
8from autotest_lib.client.bin import test
9from autotest_lib.client.bin import utils
10from autotest_lib.client.common_lib import error
11from autotest_lib.client.common_lib.cros import chrome
12
13EXTRA_BROWSER_ARGS = ['--use-fake-ui-for-media-stream',
14                      '--use-fake-device-for-media-stream']
15
16# Polling timeout.
17SHORT_TIMEOUT_IN_SECS = 45
18
19
20class video_WebRtcSanity(test.test):
21    """Local getUserMedia test with fake webcam at VGA and 720p."""
22    version = 1
23
24    def start_getusermedia(self, cr):
25        """Opens the test page.
26
27        @param cr: Autotest Chrome instance.
28        """
29        cr.browser.platform.SetHTTPServerDirectories(self.bindir)
30
31        self.tab = cr.browser.tabs[0]
32        self.tab.Navigate(cr.browser.platform.http_server.UrlOf(
33                os.path.join(self.bindir, 'getusermedia.html')))
34        self.tab.WaitForDocumentReadyStateToBeComplete()
35
36    def wait_test_completed(self, timeout_secs):
37        """Waits until the test is done.
38
39        @param timeout_secs Max time to wait in seconds.
40
41        @returns True if test completed, False otherwise.
42
43        """
44        def _test_done():
45            status = self.tab.EvaluateJavaScript('getStatus()')
46            logging.debug(status);
47            return status != 'running'
48
49        utils.poll_for_condition(
50            _test_done, timeout=timeout_secs, sleep_interval=1,
51            desc = 'getusermedia.html reports itself as finished')
52
53    def run_once(self):
54        """Runs the test."""
55        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS,
56                           init_network_controller=True) as cr:
57            self.start_getusermedia(cr)
58            self.wait_test_completed(SHORT_TIMEOUT_IN_SECS)
59            self.verify_successful()
60
61
62    def verify_successful(self):
63        """Checks the results of the test.
64
65        @raises TestError if an error occurred.
66        """
67        status = self.tab.EvaluateJavaScript('getStatus()')
68        logging.info('Status: %s', status)
69        if status != 'ok-video-playing':
70            raise error.TestFail('Failed: %s' % status)
71