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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/onencrypted.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) {
2 var expectedInitData = [];
3 expectedInitData.push(stringToUint8Array(atob(config.keys[0].initData)));
4 expectedInitData.push(stringToUint8Array(atob(config.keys[1].initData)));
5
6 // Will get 2 identical events, one for audio, one for video.
7 var expectedEvents = 2;
8 var currentData;
9
10 async_test(function (test) {
11 var video = config.video,
12 mediaSource,
13 onEncrypted = function (event) {
14 currentData = new Uint8Array(event.initData);
15 assert_equals(event.target, config.video);
16 assert_true(event instanceof window.MediaEncryptedEvent);
17 assert_equals(event.type, 'encrypted');
18 assert_equals(event.initDataType, 'cenc');
19 // At this point we do not know if the event is related to audio or video. So check for both expected init data
20 assert_true(checkInitData(currentData, expectedInitData[0]) || c heckInitData(currentData, expectedInitData[1]));
21
22 if (--expectedEvents === 0) {
23 test.done();
24 }
25 };
26
27 waitForEventAndRunStep('encrypted', video, onEncrypted, test);
28 return testmediasource(config).then(function (source) {
29 mediaSource = source;
30 config.video.src = URL.createObjectURL(mediaSource);
31 return source.done;
32 }).then(function(){
33 video.play();
34 });
35 }, 'encrypted fired on encrypted media file.');
36 }
37
38 function checkInitData(data, expectedData) {
39 if (data.length !== expectedData.length) {
40 return false;
41 }
42 for (var i = 0; i < data.length; i++) {
43 if (data[i] !== expectedData[i]) {
44 return false;
45 }
46 }
47 return true;
48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698