1# Copyright (c) 2013 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
6import time
7import shutil
8
9from autotest_lib.client.bin import test
10from autotest_lib.client.common_lib.cros import chrome
11from autotest_lib.client.cros.video import histogram_verifier
12from autotest_lib.client.cros.video import constants
13from autotest_lib.client.cros.video import native_html5_player
14
15
16class video_ChromeHWDecodeUsed(test.test):
17    """This test verifies VDA works in Chrome."""
18    version = 1
19
20
21    def run_once(self, is_mse, video_file):
22        """
23        Tests whether VDA works by verifying histogram for the loaded video.
24
25        @param is_mse: bool, True if the content uses MSE, False otherwise.
26        @param video_file: Sample video file to be loaded in Chrome.
27
28        """
29        with chrome.Chrome() as cr:
30            # This will execute for MSE video by accesing shaka player
31            if is_mse:
32                 tab1 = cr.browser.tabs[0]
33                 tab1.Navigate(video_file)
34                 tab1.WaitForDocumentReadyStateToBeComplete()
35                 # Running the test longer to check errors and longer playback
36                 # for MSE videos.
37                 time.sleep(30)
38            else:
39            #This execute for normal video for downloading html file
40                 shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
41                 cr.browser.platform.SetHTTPServerDirectories(self.bindir)
42                 tab = cr.browser.tabs[0]
43                 html_fullpath = os.path.join(self.bindir, 'video.html')
44                 url = cr.browser.platform.http_server.UrlOf(html_fullpath)
45                 player = native_html5_player.NativeHtml5Player(
46                         tab,
47                         full_url = url,
48                         video_id = 'video',
49                         video_src_path = video_file,
50                         event_timeout = 120)
51                 player.load_video()
52                 player.play()
53
54            # Waits for histogram updated for the test video.
55            histogram_verifier.verify(
56                    cr,
57                    constants.MEDIA_GVD_INIT_STATUS,
58                    constants.MEDIA_GVD_BUCKET)
59