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