Update broken references to image assets
[chromium-blink-merge.git] / media / test / data / mse_config_change.html
blob9234b65a9072b98fe3ef621a4efb6acb452d8d08
1 <html>
2 <head>
3 <title>Test media source config changes.</title>
4 </head>
5 <body onload="runTest();">
6 <video controls></video>
7 <script src='eme_player_js/app_loader.js' type='text/javascript'></script>
8 <script type="text/javascript">
9 var testConfig;
11 var video = document.querySelector('video');
12 var mediaType = 'video/webm; codecs="vorbis, vp8"';
14 var CLEAR_MEDIA_1 = 'bear-320x240.webm';
15 var CLEAR_MEDIA_2 = 'bear-640x360.webm';
16 var ENCRYPTED_MEDIA_1 = 'bear-320x240-av_enc-av.webm';
17 var ENCRYPTED_MEDIA_2 = 'bear-640x360-av_enc-av.webm';
19 var MEDIA_1_WIDTH = 320;
20 var MEDIA_1_HEIGHT = 240;
22 var MEDIA_2_WIDTH = 640;
23 var MEDIA_2_HEIGHT = 360;
24 var MEDIA_2_LENGTH = 2.75;
26 // The time in secs to append the second media source.
27 var APPEND_TIME = 1;
28 // DELTA is the time after APPEND_TIME where the second video dimensions
29 // are guaranteed to take effect.
30 var DELTA = 0.1;
31 // Append MEDIA_2 source at APPEND_TIME, so expected total duration is:
32 var TOTAL_DURATION = APPEND_TIME + MEDIA_2_LENGTH;
34 function initTestConfig() {
35 testConfig = new TestConfig();
36 testConfig.loadQueryParams();
39 function appendNextSource(mediaSource) {
40 console.log('Appending next media source at ' + APPEND_TIME + 'sec.');
41 var xhr = new XMLHttpRequest();
42 var mediaFile =
43 (testConfig.runEncrypted == 1) ? ENCRYPTED_MEDIA_2 : CLEAR_MEDIA_2;
44 xhr.open("GET", mediaFile);
45 xhr.responseType = 'arraybuffer';
46 xhr.addEventListener('load', function(e) {
47 var onUpdateEnd = function(e) {
48 console.log('Second buffer append ended.');
49 srcBuffer.removeEventListener('updateend', onUpdateEnd);
50 mediaSource.endOfStream();
51 if (!mediaSource.duration ||
52 Math.abs(mediaSource.duration - TOTAL_DURATION) > DELTA) {
53 Utils.failTest('Unexpected mediaSource.duration = ' +
54 mediaSource.duration + ', expected duration = ' +
55 TOTAL_DURATION);
56 return;
58 video.play();
60 console.log('Appending next media source at ' + APPEND_TIME + 'sec.');
61 var srcBuffer = mediaSource.sourceBuffers[0];
62 srcBuffer.addEventListener('updateend', onUpdateEnd);
63 srcBuffer.timestampOffset = APPEND_TIME;
64 srcBuffer.appendBuffer(new Uint8Array(e.target.response));
65 });
66 xhr.send();
69 function onTimeUpdate() {
70 // crbug.com/246308
71 //checkVideoProperties();
73 // Seek to APPEND_TIME because after a seek a timeUpdate event is fired
74 // before video width and height properties get updated.
75 if (video.currentTime < APPEND_TIME - DELTA) {
76 // Seek to save test execution time (about 1 secs) and to test seek
77 // on the first buffer.
78 video.currentTime = APPEND_TIME - DELTA;
79 } else if (video.currentTime > APPEND_TIME + DELTA) {
80 // Check video duration here to guarantee that second segment has been
81 // appended and video total duration is updated.
82 // Video duration is a float value so we check it within a range.
83 if (!video.duration ||
84 Math.abs(video.duration - TOTAL_DURATION) > DELTA) {
85 Utils.failTest('Unexpected video.duration = ' + video.duration +
86 ', expected duration = ' + TOTAL_DURATION);
87 return;
90 video.removeEventListener('timeupdate', onTimeUpdate);
91 video.removeEventListener('ended', Utils.failTest);
92 Utils.installTitleEventHandler(video, 'ended');
93 // Seek to save test execution time and to test seek on second buffer.
94 video.currentTime = APPEND_TIME + MEDIA_2_LENGTH * 0.9;
98 function checkVideoProperties() {
99 if (video.currentTime <= APPEND_TIME) {
100 if (video.videoWidth != MEDIA_1_WIDTH ||
101 video.videoHeight != MEDIA_1_HEIGHT) {
102 logVideoDimensions();
103 Utils.failTest('Unexpected dimensions for first video segment.');
104 return;
106 } else if (video.currentTime >= APPEND_TIME + DELTA) {
107 if (video.videoWidth != MEDIA_2_WIDTH ||
108 video.videoHeight != MEDIA_2_HEIGHT) {
109 logVideoDimensions();
110 Utils.failTest('Unexpected dimensions for second video segment.');
111 return;
116 function logVideoDimensions() {
117 console.log('video.currentTime = ' + video.currentTime +
118 ', video dimensions = ' + video.videoWidth + 'x' +
119 video.videoHeight + '.');
122 function runTest() {
123 initTestConfig();
124 testConfig.mediaFile =
125 (testConfig.runEncrypted == 1) ? ENCRYPTED_MEDIA_1 : CLEAR_MEDIA_1;
126 testConfig.mediaType = mediaType;
127 video.addEventListener('timeupdate', onTimeUpdate);
128 video.addEventListener('ended', Utils.failTest);
129 var mediaSource = MediaSourceUtils.loadMediaSourceFromTestConfig(
130 testConfig, appendNextSource);
131 if (testConfig.runEncrypted == 1) {
132 var emePlayer = PlayerUtils.createPlayer(video, testConfig);
133 emePlayer.registerEventListeners()
134 .then(function(player) {
135 video.src = window.URL.createObjectURL(mediaSource);
137 .catch(function(error) {
138 Utils.failTest('Unable to register event listeners.');
140 } else {
141 video.src = window.URL.createObjectURL(mediaSource);
144 </script>
145 </body>
146 </html>