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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/public/common/content_switches.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <html> 1 <html>
2 <body> 2 <body onload="RunTest();">
3 <div id="player_container"></div> 3 <div id="player_container"></div>
4 <script> 4 </body>
5 var player = null; 5
6 function InstallEventHandler(event, action) { 6 <script type="text/javascript">
7 player.addEventListener(event, function(e) { 7 // <audio> or <video> player element.
8 eval(action); 8 var player;
9
10 // Listen for |event| from |element|, set document.title = |event| upon event.
11 function InstallTitleEventHandler(element, event) {
12 element.addEventListener(event, function(e) {
13 document.title = event.toUpperCase();
9 }, false); 14 }, false);
10 } 15 }
11 16
12 // Parse the location and load the media file accordingly. 17 function Failed() {
13 var url = window.location.href; 18 document.title = 'FAILED';
14 var url_parts = url.split('?'); 19 return false;
20 }
15 21
16 // Make sure the URL is of the form "player.html?query". 22 function SeekTestStep(e) {
17 var ok = false; 23 player.removeEventListener('ended', SeekTestStep, false);
18 if (url_parts.length > 1) {
19 var query = url_parts[1];
20 var query_parts = query.split('=');
21 if (query_parts.length == 2) {
22 var tag = query_parts[0];
23 var media_url = query_parts[1];
24 if (tag == 'audio' || tag == 'video') {
25 ok = true;
26 var container = document.getElementById('player_container');
27 container.innerHTML = '<' + tag + ' controls id="player"></' + tag + '>';
28 player = document.getElementById('player');
29 24
30 // Install event handlers. 25 // Test completes on the next ended event.
31 InstallEventHandler('error', 'document.title = "ERROR"'); 26 InstallTitleEventHandler(player, 'ended');
32 InstallEventHandler('playing', 'document.title = "PLAYING"');
33 27
34 // Starts the player. 28 player.currentTime = 0.9 * player.duration;
35 player.src = media_url; 29 player.play();
36 player.play();
37 }
38 }
39 } 30 }
40 if (!ok) { 31
41 document.title = 'FAILED'; 32 function SeekTestTimeoutSetup() {
33 if (player.currentTime < 2)
34 return;
35
36 player.removeEventListener('timeupdate', SeekTestTimeoutSetup, false);
37 SeekTestStep();
38 }
39
40 // Uses URL query parameters to create an audio or video element using a given
41 // source. URL must be of the form "player.html?[tag]=[media_url]". Plays the
42 // media and waits for X seconds of playback or the ended event, at which point
43 // the test seeks near the end of the file and resumes playback. Test completes
44 // when the second ended event occurs or an error event occurs at any time.
45 function RunTest() {
46 var url_parts = window.location.href.split('?');
47 if (url_parts.length != 2)
48 return Failed();
49
50 var query_parts = url_parts[1].split('=');
51 if (query_parts.length != 2)
52 return Failed();
53
54 var tag = query_parts[0];
55 var media_url = query_parts[1];
56 if (tag != 'audio' && tag != 'video')
57 return Failed();
58
59 // Create player and insert into DOM.
60 player = document.createElement(tag);
61 player.controls = true;
62 document.getElementById('player_container').appendChild(player);
63
64 // Transition to the seek test after X seconds of playback or when the ended
65 // event occurs, whichever happens first.
66 player.addEventListener('ended', SeekTestStep, false);
67 player.addEventListener('timeupdate', SeekTestTimeoutSetup, false);
68
69 // Ensure we percolate up any error events.
70 InstallTitleEventHandler(player, 'error');
71
72 // Starts the player.
73 player.src = media_url;
74 player.play();
42 } 75 }
43 </script> 76 </script>
44 </body>
45 </html> 77 </html>
OLDNEW
« 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