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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/util/testmediasource.js

Issue 2546853003: Add W3C encrypted-media tests (Closed)
Patch Set: rebase now that content files landed Created 4 years 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
OLDNEW
(Empty)
1 function testmediasource(config) {
2
3 return new Promise(function(resolve, reject) {
4 // Fetch the media resources
5 var fetches = [config.audioPath, config.videoPath].map(function(path) {
6 return fetch(path).then(function(response) {
7 if (!response.ok) throw new Error('Resource fetch failed');
8 return response.arrayBuffer();
9 });
10 });
11
12 Promise.all(fetches).then(function(resources) {
13 config.audioMedia = resources[0];
14 config.videoMedia = resources[1];
15
16 // Create media source
17 var source = new MediaSource();
18 source.done = new Promise(function(resolvesource,rejectsource){
19
20 // Create and fill source buffers when the media source is opene d
21 source.addEventListener('sourceopen', onSourceOpen);
22 resolve(source);
23
24 function onSourceOpen(event) {
25 var audioSourceBuffer = source.addSourceBuffer(config.audioT ype),
26 videoSourceBuffer = source.addSourceBuffer(config.videoT ype);
27
28 audioSourceBuffer.addEventListener('updateend',onUpdateEnd);
29 videoSourceBuffer.addEventListener('updateend',onUpdateEnd);
30
31 audioSourceBuffer.appendBuffer(config.audioMedia);
32 videoSourceBuffer.appendBuffer(config.videoMedia);
33
34 function onUpdateEnd(event){
35 event.target.removeEventListener('updateend', onUpdateEn d);
36 if (!audioSourceBuffer.updating && !videoSourceBuffer.up dating) {
37 if (source.readyState !== 'open') {
38 rejectsource(new Error("Media source error"));
39 } else {
40 source.endOfStream();
41 resolvesource();
42 }
43 }
44 }
45 }
46 });
47 });
48 });
49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698