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
5from contextlib import closing
6import logging
7import os
8
9from autotest_lib.client.bin import test
10from autotest_lib.client.common_lib import file_utils
11from autotest_lib.client.common_lib.cros import chrome
12from autotest_lib.client.cros.video import histogram_verifier
13
14
15# Chrome flags to use fake camera and skip camera permission.
16EXTRA_BROWSER_ARGS = ['--use-fake-device-for-media-stream',
17                      '--use-fake-ui-for-media-stream']
18FAKE_FILE_ARG = '--use-file-for-fake-video-capture="%s"'
19DOWNLOAD_BASE = 'http://commondatastorage.googleapis.com/chromiumos-test-assets-public/crowd/'
20
21HISTOGRAMS_URL = 'chrome://histograms/'
22
23
24class video_ChromeRTCHWDecodeUsed(test.test):
25    """The test verifies HW Encoding for WebRTC video."""
26    version = 1
27
28
29    def start_loopback(self, cr):
30        """
31        Opens WebRTC loopback page.
32
33        @param cr: Autotest Chrome instance.
34        """
35        tab = cr.browser.tabs[0]
36        tab.Navigate(cr.browser.platform.http_server.UrlOf(
37            os.path.join(self.bindir, 'loopback.html')))
38        tab.WaitForDocumentReadyStateToBeComplete()
39
40
41    def run_once(self, video_name, histogram_name, histogram_bucket_val):
42        # Download test video.
43        url = DOWNLOAD_BASE + video_name
44        local_path = os.path.join(self.bindir, video_name)
45        file_utils.download_file(url, local_path)
46
47        # Start chrome with test flags.
48        EXTRA_BROWSER_ARGS.append(FAKE_FILE_ARG % local_path)
49        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS) as cr:
50            # Open WebRTC loopback page.
51            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
52            self.start_loopback(cr)
53
54            # Make sure decode is hardware accelerated.
55            histogram_verifier.verify(cr, histogram_name, histogram_bucket_val)
56