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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/playback-persistent-license-events.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 + ', playback, check events';
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 _receivedTimeupdateEvent = false,
20 _startedReleaseSequence = false,
21 _events = [ ];
22
23 function recordEventFunc( eventType ) {
24 return function() { _events.push( eventType ); };
25 }
26
27 function onFailure(error) {
28 forceTestFailureFromPromise(test, error);
29 }
30
31 function onMessage(event) {
32 assert_equals( event.target, _mediaKeySession );
33 assert_true( event instanceof window.MediaKeyMessageEvent );
34 assert_equals( event.type, 'message');
35
36 if (!_startedReleaseSequence) {
37 assert_in_array(event.messageType, ['license-request', 'individu alization-request']);
38 } else {
39 assert_equals(event.messageType, 'license-release');
40 }
41
42 if (event.messageType !== 'individualization-request') {
43 _events.push(event.messageType);
44 }
45
46 config.messagehandler(event.messageType, event.message ).then(functi on(response) {
47 _events.push(event.messageType + '-response');
48 return _mediaKeySession.update(response);
49 }).then(test.step_func(function() {
50 _events.push('update-resolved');
51 if (event.messageType === 'license-release') {
52 checkEventSequence( _events,
53 ['generaterequest',
54 ['license-request', 'license-request-res ponse', 'update-resolved'], // potentially repeating
55 'keystatuseschange',
56 'playing',
57 'remove-resolved',
58 'keystatuseschange',
59 'license-release',
60 'license-release-response',
61 'closed-attribute-resolved',
62 'update-resolved' ]);
63 test.done();
64 }
65 })).catch(onFailure);
66 }
67
68 function onKeyStatusesChange(event) {
69 assert_equals(event.target, _mediaKeySession);
70 assert_true(event instanceof window.Event);
71 assert_equals(event.type, 'keystatuseschange');
72 _events.push('keystatuseschange');
73 }
74
75 function onEncrypted(event) {
76 assert_equals(event.target, _video);
77 assert_true(event instanceof window.MediaEncryptedEvent);
78 assert_equals(event.type, 'encrypted');
79
80 _mediaKeySession.generateRequest( config.initData ? config.initDat aType : event.initDataType,
81 config.initData || event.initDat a ).then(recordEventFunc('generaterequest')
82 ).catch(onFailure);
83 }
84
85 function onTimeupdate(event) {
86 if ( _video.currentTime > ( config.duration || 1 ) && !_receivedTime updateEvent ) {
87 _receivedTimeupdateEvent = true;
88 _video.pause();
89 _video.removeAttribute('src');
90 _video.load();
91
92 _startedReleaseSequence = true;
93 _mediaKeySession.remove().then(recordEventFunc('remove-resolved' )).catch(onFailure);
94 }
95 }
96
97 function onPlaying(event) {
98 _events.push( 'playing' );
99 }
100
101 navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
102 return access.createMediaKeys();
103 }).then(function(mediaKeys) {
104 _mediaKeys = mediaKeys;
105 return _video.setMediaKeys(_mediaKeys);
106 }).then(function() {
107 waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
108 waitForEventAndRunStep('playing', _video, onPlaying, test);
109 // Not using waitForEventAndRunStep() to avoid too many
110 // EVENT(onTimeUpdate) logs.
111 _video.addEventListener('timeupdate', onTimeupdate, true);
112 _mediaKeySession = _mediaKeys.createSession( 'persistent-license' );
113 waitForEventAndRunStep('keystatuseschange', _mediaKeySession, onKeyS tatusesChange, test);
114 waitForEventAndRunStep('message', _mediaKeySession, onMessage, test) ;
115 _mediaKeySession.closed.then( recordEventFunc( 'closed-attribute-res olved' ) );
116 return testmediasource(config);
117 }).then(function(source) {
118 _mediaSource = source;
119 _video.src = URL.createObjectURL(_mediaSource);
120 return source.done;
121 }).then(function(){
122 _video.play();
123 }).catch(onFailure);
124 }, testname);
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698