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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/playback-retrieve-persistent-usage-record.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-usage-record, '
5 + /video\/([^;]*)/.exec(config.videoType)[1]
6 + ', playback, retrieve in new window';
7
8 var configuration = { initDataTypes: [ config.initDataType ],
9 audioCapabilities: [ { contentType: config.audioType } ],
10 videoCapabilities: [ { contentType: config.videoType } ],
11 sessionTypes: [ 'persistent-usage-record' ] };
12
13
14 async_test( function( test ) {
15 var _video = config.video,
16 _mediaKeys,
17 _mediaKeySession,
18 _mediaSource,
19 _sessionId,
20 _isClosing = false;
21
22 function onFailure(error) {
23 forceTestFailureFromPromise(test, error);
24 }
25
26 function onEncrypted(event) {
27 assert_equals(event.target, _video);
28 assert_true(event instanceof window.MediaEncryptedEvent);
29 assert_equals(event.type, 'encrypted');
30
31 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test) ;
32 _mediaKeySession.generateRequest( config.initDataType || event.ini tDataType,
33 config.initData || event.initDat a ).then( function() {
34 _sessionId = _mediaKeySession.sessionId;
35 }).catch(onFailure);
36 }
37
38 function onMessage(event) {
39 assert_equals(event.target, _mediaKeySession);
40 assert_true(event instanceof window.MediaKeyMessageEvent);
41 assert_equals(event.type, 'message');
42
43 assert_in_array( event.messageType,['license-request', 'individuali zation-request']);
44
45 config.messagehandler( event.messageType, event.message ).then(funct ion(response) {
46 return _mediaKeySession.update(response);
47 }).then(function() {
48 _video.setMediaKeys(_mediaKeys);
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 (!_isClosing && _video.currentTime > (config.duration || 1)) {
60 _isClosing = true;
61 _video.removeEventListener('timeupdate', onTimeupdate);
62 _video.pause();
63 _mediaKeySession.closed.then( test.step_func(onClosed));
64 _mediaKeySession.close();
65 }
66 }
67
68 function onClosed(event) {
69 _video.src = "";
70 _video.setMediaKeys( null );
71
72 var win = window.open(config.windowscript);
73 window.addEventListener('message', test.step_func(function(event) {
74 event.data.forEach(test.step_func(function(assertion) {
75 assert_equals(assertion.actual, assertion.expected, assertio n.message);
76 }));
77
78 win.close();
79 test.done();
80 }));
81
82 delete config.video;
83 delete config.messagehandler;
84
85 win.onload = function() {
86 win.postMessage({ config: config, sessionId: _sessionId }, '*');
87 }
88 }
89
90 navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]) .then(function(access) {
91 return access.createMediaKeys();
92 }).then(function(mediaKeys) {
93 _mediaKeys = mediaKeys;
94 return _video.setMediaKeys(mediaKeys);
95 }).then(function(){
96 _mediaKeySession = _mediaKeys.createSession( 'persistent-usage-recor d' );
97 waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
98 waitForEventAndRunStep('playing', _video, onPlaying, test);
99 return config.servercertificate ? _mediaKeys.setServerCertificate(co nfig.servercertificate) : true;
100 }).then(function(success) {
101 return testmediasource(config);
102 }).then(function(source) {
103 _mediaSource = source;
104 _video.src = URL.createObjectURL(_mediaSource);
105 return source.done;
106 }).then(function(){
107 _video.play();
108 }).catch(onFailure);
109 }, testname);
110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698