1# Copyright 2019 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.
4from autotest_lib.client.cros.power import power_videotest
5
6import py_utils
7
8class power_VideoDRMPlayback(power_videotest.power_VideoTest):
9    """class for power_VideoDRMPlayback test."""
10    version = 1
11
12    _BASE_URL='https://ats.sandbox.google.com/videostack/media_test_page.html?file='
13
14    # list of video name and url.
15    _VIDEOS = [
16        ('h264_720_30fps_cenc',
17         _BASE_URL + 'EME_720p30fpsH264_foodmarket_sync_L3_video_clear_audio.mp4.mpd'
18        ),
19        ('h264_1080_30fps_cenc',
20         _BASE_URL + 'EME_1080p30fpsH264_foodmarket_sync_L3_video_clear_audio.mp4.mpd'
21        ),
22        ('vp9_720_30fps_cenc',
23         _BASE_URL + 'EME_720p30fpsVP9_foodmarket_sync_L3_video_clear_audio.webm.mpd'
24        ),
25        ('vp9_1080_30fps_cenc',
26         _BASE_URL + 'EME_1080p30fpsVP9_foodmarket_sync_L3_video_clear_audio.webm.mpd'
27        ),
28        ('av1_720_30fps_cenc',
29         _BASE_URL + 'EME_720p30fpsAV1_foodmarket_sync_L3_video_clear_audio.mp4.mpd'
30        ),
31        ('av1_1080_30fps_cenc',
32         _BASE_URL + 'EME_1080p30fpsAV1_foodmarket_sync_L3_video_clear_audio.mp4.mpd'
33        ),
34        ('h264_720_30fps_cbcs',
35         _BASE_URL + 'EME_720p30fpsH264_foodmarket_sync_cbcs_video_clear_audio.mp4.mpd'
36        ),
37        ('h264_1080_30fps_cbcs',
38         _BASE_URL + 'EME_1080p30fpsH264_foodmarket_sync_cbcs_video_clear_audio.mp4.mpd'
39        ),
40        ('av1_720_30fps_cbcs',
41         _BASE_URL + 'EME_720p30fpsAV1_foodmarket_sync_cbcs_video_clear_audio.mp4.mpd'
42        ),
43        ('av1_1080_30fps_cbcs',
44         _BASE_URL + 'EME_1080p30fpsAV1_foodmarket_sync_cbcs_video_clear_audio.mp4.mpd'
45        ),
46    ]
47
48    # Time in seconds to measure power per video file.
49    _MEASUREMENT_DURATION = 120
50
51    def _prepare_video(self, cr, url):
52        """Prepare browser session before playing video.
53
54        @param cr: Autotest Chrome instance.
55        @param url: url of video file to play.
56        """
57        tab = cr.browser.tabs[0]
58        tab.Navigate(url)
59        tab.WaitForDocumentReadyStateToBeComplete()
60
61    def _start_video(self, cr, url):
62        """Start playing video.
63
64        @param cr: Autotest Chrome instance.
65        @param url: url of video file to play.
66        """
67        tab = cr.browser.tabs[0]
68
69        # Chrome prevents making an element fullscreen if the request doesn't
70        # initiated by user gesture. https://CrOSPower.page.link/noFullScreen
71        # Fake the user gesture by evaluate javascript from URL bar.
72        try:
73            tab.Navigate("javascript:TestFrameworkApp.FullScreen()", timeout=0)
74            tab.WaitForDocumentReadyStateToBeComplete()
75        except py_utils.TimeoutException:
76            # tab.Navigate always raise TimeoutException because we used it to
77            # execute javascript and didn't navigate to anywhere.
78            pass
79
80        tab.EvaluateJavaScript("TestFrameworkApp.getInstance().startTest()")
81
82    def _teardown_video(self, cr, url):
83        """Teardown browser session after playing video.
84
85        @param cr: Autotest Chrome instance.
86        @param url: url of video file to play.
87        """
88        pass
89
90    def run_once(self, videos=None, secs_per_video=_MEASUREMENT_DURATION,
91                 use_hw_decode=True):
92        """run_once method.
93
94        @param videos: list of tuple of tagname and video url to test.
95        @param secs_per_video: time in seconds to play video and measure power.
96        @param use_hw_decode: if False, disable hw video decoding.
97        """
98        if not videos:
99            videos = self._VIDEOS
100
101        super(power_VideoDRMPlayback, self).run_once(
102            videos, secs_per_video, use_hw_decode)
103
104