Refactoring using new native HTML5 API's
This test is refactored using new native HTML5 API's
BUG=chromium:566122
TEST=manual
Change-Id: Ic3f80605e4ae6d8dde0bc7dcbcef419fefb90716
Reviewed-on: https://chromium-review.googlesource.com/320394
Commit-Ready: Avinash Kodipelli <avkodipelli@chromium.org>
Tested-by: Avinash Kodipelli <avkodipelli@chromium.org>
Reviewed-by: Avinash Kodipelli <avkodipelli@chromium.org>
diff --git a/client/cros/video/native_html5_player.py b/client/cros/video/native_html5_player.py
index dd839f7..0ccc5d2 100644
--- a/client/cros/video/native_html5_player.py
+++ b/client/cros/video/native_html5_player.py
@@ -49,6 +49,24 @@
self.tab.ExecuteJavaScript('pause()')
+ def paused(self):
+ """
+ Checks whether video paused.
+
+ """
+ cmd = "%s.paused" % self.video_id
+ return self.tab.EvaluateJavaScript(cmd)
+
+
+ def ended(self):
+ """
+ Checks whether video paused.
+
+ """
+ cmd = "%s.ended" % self.video_id
+ return self.tab.EvaluateJavaScript(cmd)
+
+
def currentTime(self):
"""
Returns the current time of the video element.
@@ -73,4 +91,4 @@
Determines if a vimeo video has finished seeking.
"""
- return self.tab.EvaluateJavaScript('finishedSeeking()')
\ No newline at end of file
+ return self.tab.EvaluateJavaScript('finishedSeeking()')
diff --git a/client/cros/video/vda_constants.py b/client/cros/video/vda_constants.py
index d78fb97..c620e69 100644
--- a/client/cros/video/vda_constants.py
+++ b/client/cros/video/vda_constants.py
@@ -8,3 +8,4 @@
RTC_INIT_HISTOGRAM = 'Media.RTCVideoDecoderInitDecodeSuccess'
MEDIA_GVD_BUCKET = 0
RTC_VIDEO_INIT_BUCKET = 1
+VIDEO_HTML_FILEPATH = '/usr/local/autotest/cros/video/video.html'
diff --git a/client/cros/video/video.html b/client/cros/video/video.html
new file mode 100644
index 0000000..dffee18
--- /dev/null
+++ b/client/cros/video/video.html
@@ -0,0 +1,64 @@
+<html>
+<body>
+ <video id='video' name='media' height="480" width="854" controls>
+ <source src='' type='video'>
+ </video>
+ <br>
+Current time (seconds): <span id='videoCurTime'>0</span>
+</body>
+
+<script type="text/javascript">
+var can_play = false;
+var finished_seeking = false;
+
+(function() {
+ var timeEle = document.getElementById('videoCurTime');
+ video.addEventListener('timeupdate', function(event) {
+ timeEle.innerHTML = video.currentTime;
+ }, false);
+})();
+
+(function() {
+ video.addEventListener('canplaythrough', function(event) {
+ can_play = true;
+ }, false);
+})();
+
+(function() {
+ video.addEventListener('seeked', function(event) {
+ finished_seeking = true;
+ }, false);
+})();
+
+(function() {
+ video.addEventListener('seeking', function(event) {
+ finished_seeking = false;
+ }, false);
+})();
+
+function loadVideoSource(video_source_path) {
+ video.src = video_source_path;
+ return true;
+}
+
+function canplay() {
+ return can_play;
+}
+
+function finishedSeeking() {
+ return finished_seeking;
+}
+
+function play() {
+ video.play();
+}
+
+function pause() {
+ video.pause();
+}
+
+function currentTime() {
+ return video.currentTime;
+}
+</script>
+</html>
diff --git a/client/site_tests/video_ChromeVidResChangeHWDecode/video.html b/client/site_tests/video_ChromeVidResChangeHWDecode/video.html
deleted file mode 100644
index a44d651..0000000
--- a/client/site_tests/video_ChromeVidResChangeHWDecode/video.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<!-- This is a test html file for video test. -->
-<html>
-<body>
- <video id='testvideo' controls autoplay muted name='media'>
- </video>
-</body>
-
-<script type="text/javascript">
-var testvideo = document.getElementById('testvideo');
-
-function loadVideo(video) {
- testvideo.src = video;
- testvideo.play();
-}
-</script>
-</html>
diff --git a/client/site_tests/video_ChromeVidResChangeHWDecode/video_ChromeVidResChangeHWDecode.py b/client/site_tests/video_ChromeVidResChangeHWDecode/video_ChromeVidResChangeHWDecode.py
index ee90f94..ef641a9 100755
--- a/client/site_tests/video_ChromeVidResChangeHWDecode/video_ChromeVidResChangeHWDecode.py
+++ b/client/site_tests/video_ChromeVidResChangeHWDecode/video_ChromeVidResChangeHWDecode.py
@@ -3,13 +3,14 @@
# found in the LICENSE file.
import os
-import time
+import time, logging, shutil
from autotest_lib.client.bin import test, utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.common_lib.cros import chrome
from autotest_lib.client.cros.video import histogram_verifier
from autotest_lib.client.cros.video import vda_constants
+from autotest_lib.client.cros.video import native_html5_player
class video_ChromeVidResChangeHWDecode(test.test):
@@ -21,16 +22,23 @@
"""Verify VDA and playback for the video_file.
@param video_file: test video file.
+ @param video_len : test video file length.
"""
+
with chrome.Chrome() as cr:
+ shutil.copy2(vda_constants.VIDEO_HTML_FILEPATH, self.bindir)
cr.browser.platform.SetHTTPServerDirectories(self.bindir)
tab1 = cr.browser.tabs[0]
- tab1.Navigate(cr.browser.platform.http_server.UrlOf(
- os.path.join(self.bindir, 'video.html')))
- tab1.WaitForDocumentReadyStateToBeComplete()
- tab1.EvaluateJavaScript(
- 'loadVideo("%s")' % (video_file))
-
+ html_fullpath = os.path.join(self.bindir, 'video.html')
+ url = cr.browser.platform.http_server.UrlOf(html_fullpath)
+ logging.info("full url is %s", url)
+ player = native_html5_player.NativeHtml5Player(tab1,
+ full_url = url,
+ video_id = 'video',
+ video_src_path = video_file,
+ event_timeout = 120)
+ player.load_video()
+ player.play()
# Waits for histogram updated for the test video.
histogram_verifier.verify(
cr,
@@ -39,14 +47,13 @@
# Verify the video playback.
for i in range(1, video_len/2):
- if tab1.EvaluateJavaScript(
- 'testvideo.ended || testvideo.paused'):
+ if (player.paused() or player.ended()):
raise error.TestError('Video either stopped or ended.')
time.sleep(1)
# Verify that video ends successfully.
utils.poll_for_condition(
- lambda: tab1.EvaluateJavaScript('testvideo.ended'),
+ lambda: player.ended(),
timeout=video_len,
exception=error.TestError('Video did not end successfully'),
sleep_interval=1)