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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/playback-temporary.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 runTest(config,qualifier) {
2
3 var testname = testnamePrefix(qualifier, config.keysystem)
4 + ', temporary, '
5 + /video\/([^;]*)/.exec(config.videoType)[1]
6 + ', playback, ' + config.testcase;
7
8 var configuration = { initDataTypes: [ config.initDataType ],
9 audioCapabilities: [ { contentType: config.audioType } ],
10 videoCapabilities: [ { contentType: config.videoType } ],
11 sessionTypes: [ 'temporary' ] };
12
13 async_test(function(test) {
14
15 var _video = config.video,
16 _mediaKeys,
17 _mediaKeySession,
18 _mediaSource;
19
20 function onFailure(error) {
21 forceTestFailureFromPromise(test, error);
22 }
23
24 function onEncrypted(event) {
25 assert_equals(event.target, _video);
26 assert_true(event instanceof window.MediaEncryptedEvent);
27 assert_equals(event.type, 'encrypted');
28
29 // Only create the session for the firs encrypted event
30 if (_mediaKeySession !== undefined) return;
31
32 var initDataType = config.initData ? config.initDataType : event.ini tDataType;
33 var initData = config.initData || event.initData;
34
35 _mediaKeySession = _mediaKeys.createSession('temporary');
36 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test) ;
37 _mediaKeySession.generateRequest( initDataType, initData ).catch(onF ailure);
38 }
39
40 function onMessage(event) {
41 assert_equals(event.target, _mediaKeySession);
42 assert_true(event instanceof window.MediaKeyMessageEvent);
43 assert_equals(event.type, 'message');
44
45 assert_in_array(event.messageType, ['license-request', 'individualiz ation-request']);
46
47 config.messagehandler(event.messageType, event.message).then(functio n(response) {
48 return event.target.update(response);
49 }).catch(onFailure);
50 }
51
52 function onPlaying(event) {
53 // Not using waitForEventAndRunStep() to avoid too many
54 // EVENT(onTimeUpdate) logs.
55 _video.addEventListener('timeupdate', onTimeupdate, true);
56 }
57
58 function onTimeupdate(event) {
59 if ( _video.currentTime > (config.duration || 1)) {
60 _video.pause();
61 test.done();
62 }
63 }
64
65 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]) .then(function(access) {
66 return access.createMediaKeys();
67 }).then(function(mediaKeys) {
68 _mediaKeys = mediaKeys;
69 return _video.setMediaKeys(_mediaKeys);
70 }).then(function(){
71 waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
72 waitForEventAndRunStep('playing', _video, onPlaying, test);
73 return testmediasource(config);
74 }).then(function(source) {
75 _mediaSource = source;
76 _video.src = URL.createObjectURL(_mediaSource);
77 return source.done;
78 }).then(function(){
79 _video.play();
80 }).catch(onFailure);
81 }, testname);
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698