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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/playback-retrieve-persistent-license.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 + ', persistent-license, '
5 + /video\/([^;]*)/.exec(config.videoType)[1]
6 + ', ' + config.testcase;
7
8 var configuration = { initDataTypes: [ config.initDataType ],
9 audioCapabilities: [ { contentType: config.audioType } ],
10 videoCapabilities: [ { contentType: config.videoType } ],
11 sessionTypes: [ 'persistent-license' ] };
12
13
14 async_test( function(test) {
15 var _video = config.video,
16 _mediaKeys,
17 _mediaKeySession,
18 _mediaSource,
19 _sessionId;
20
21 function onFailure(error) {
22 forceTestFailureFromPromise(test, error);
23 }
24
25 function onEncrypted(event) {
26 assert_equals(event.target, _video);
27 assert_true(event instanceof window.MediaEncryptedEvent);
28 assert_equals(event.type, 'encrypted');
29
30 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test) ;
31 _mediaKeySession.generateRequest( config.initData ? config.initDat aType : event.initDataType,
32 config.initData || event.initDat a ).then( function() {
33 _sessionId = _mediaKeySession.sessionId;
34 }).catch(onFailure);
35 }
36
37 function onMessage(event) {
38 assert_equals(event.target, _mediaKeySession);
39 assert_true(event instanceof window.MediaKeyMessageEvent);
40 assert_equals(event.type, 'message');
41
42 assert_in_array(event.messageType, ['license-request', 'individualiz ation-request']);
43
44 config.messagehandler(event.messageType, event.message).then(functio n(response) {
45 return _mediaKeySession.update(response);
46 }).catch(onFailure);
47 }
48
49 function onPlaying(event) {
50 // Not using waitForEventAndRunStep() to avoid too many
51 // EVENT(onTimeUpdate) logs.
52 _video.addEventListener('timeupdate', onTimeupdate, true);
53 }
54
55 function onTimeupdate(event) {
56 if (_video.currentTime > (config.duration || 1)) {
57 _video.removeEventListener('timeupdate', onTimeupdate);
58 _video.pause();
59 _video.removeAttribute('src');
60 _video.load()
61
62 _mediaKeySession.closed.then(test.step_func(onClosed));
63 _mediaKeySession.close();
64 }
65 }
66
67 function onClosed() {
68 // Open a new window in which we will attempt to play with the persi sted license
69 var win = window.open(config.windowscript);
70
71 // Lisen for an event from the new window containing its test assert ions
72 window.addEventListener('message', test.step_func(function(messageEv ent) {
73 messageEvent.data.forEach(test.step_func(function(assertion) {
74 assert_equals(assertion.actual, assertion.expected, assertio n.message);
75 }));
76
77 win.close();
78 test.done();
79 }));
80
81 // Delete things which can't be cloned and posted over to the new wi ndow
82 delete config.video;
83 delete config.messagehandler;
84
85 // Post the config and session id to the new window when it is ready
86 win.onload = function() {
87 win.postMessage({config: config, sessionId: _sessionId}, '*');
88 }
89 }
90
91 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]) .then(function(access) {
92 return access.createMediaKeys();
93 }).then(function(mediaKeys) {
94 _mediaKeys = mediaKeys;
95 _video.setMediaKeys( mediaKeys );
96 _mediaKeySession = _mediaKeys.createSession('persistent-license');
97 waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
98 waitForEventAndRunStep('playing', _video, onPlaying, test);
99 return testmediasource(config);
100 }).then(function(source) {
101 _mediaSource = source;
102 _video.src = URL.createObjectURL(_mediaSource);
103 return source.done;
104 }).then(function(){
105 _video.play();
106 }).catch(onFailure);
107 }, testname);
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698