Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1029)

Unified Diff: content/test/data/media/player.html

Issue 10647007: Add http based media browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/common/content_switches.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/data/media/player.html
diff --git a/content/test/data/media/player.html b/content/test/data/media/player.html
index bceccd3d9c1e8d05d2d7b8840d4ade610a40d4b3..e954cf8e938d53707a9df3b71a9db74433f010a9 100644
--- a/content/test/data/media/player.html
+++ b/content/test/data/media/player.html
@@ -1,45 +1,77 @@
<html>
-<body>
+<body onload="RunTest();">
<div id="player_container"></div>
-<script>
-var player = null;
-function InstallEventHandler(event, action) {
- player.addEventListener(event, function(e) {
- eval(action);
+</body>
+
+<script type="text/javascript">
+// <audio> or <video> player element.
+var player;
+
+// Listen for |event| from |element|, set document.title = |event| upon event.
+function InstallTitleEventHandler(element, event) {
+ element.addEventListener(event, function(e) {
+ document.title = event.toUpperCase();
}, false);
}
-// Parse the location and load the media file accordingly.
-var url = window.location.href;
-var url_parts = url.split('?');
-
-// Make sure the URL is of the form "player.html?query".
-var ok = false;
-if (url_parts.length > 1) {
- var query = url_parts[1];
- var query_parts = query.split('=');
- if (query_parts.length == 2) {
- var tag = query_parts[0];
- var media_url = query_parts[1];
- if (tag == 'audio' || tag == 'video') {
- ok = true;
- var container = document.getElementById('player_container');
- container.innerHTML = '<' + tag + ' controls id="player"></' + tag + '>';
- player = document.getElementById('player');
-
- // Install event handlers.
- InstallEventHandler('error', 'document.title = "ERROR"');
- InstallEventHandler('playing', 'document.title = "PLAYING"');
-
- // Starts the player.
- player.src = media_url;
- player.play();
- }
- }
-}
-if (!ok) {
+function Failed() {
document.title = 'FAILED';
+ return false;
+}
+
+function SeekTestStep(e) {
+ player.removeEventListener('ended', SeekTestStep, false);
+
+ // Test completes on the next ended event.
+ InstallTitleEventHandler(player, 'ended');
+
+ player.currentTime = 0.9 * player.duration;
+ player.play();
+}
+
+function SeekTestTimeoutSetup() {
+ if (player.currentTime < 2)
+ return;
+
+ player.removeEventListener('timeupdate', SeekTestTimeoutSetup, false);
+ SeekTestStep();
+}
+
+// Uses URL query parameters to create an audio or video element using a given
+// source. URL must be of the form "player.html?[tag]=[media_url]". Plays the
+// media and waits for X seconds of playback or the ended event, at which point
+// the test seeks near the end of the file and resumes playback. Test completes
+// when the second ended event occurs or an error event occurs at any time.
+function RunTest() {
+ var url_parts = window.location.href.split('?');
+ if (url_parts.length != 2)
+ return Failed();
+
+ var query_parts = url_parts[1].split('=');
+ if (query_parts.length != 2)
+ return Failed();
+
+ var tag = query_parts[0];
+ var media_url = query_parts[1];
+ if (tag != 'audio' && tag != 'video')
+ return Failed();
+
+ // Create player and insert into DOM.
+ player = document.createElement(tag);
+ player.controls = true;
+ document.getElementById('player_container').appendChild(player);
+
+ // Transition to the seek test after X seconds of playback or when the ended
+ // event occurs, whichever happens first.
+ player.addEventListener('ended', SeekTestStep, false);
+ player.addEventListener('timeupdate', SeekTestTimeoutSetup, false);
+
+ // Ensure we percolate up any error events.
+ InstallTitleEventHandler(player, 'error');
+
+ // Starts the player.
+ player.src = media_url;
+ player.play();
}
</script>
-</body>
</html>
« no previous file with comments | « content/public/common/content_switches.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698