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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/onencrypted.js
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/onencrypted.js b/third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/onencrypted.js
new file mode 100644
index 0000000000000000000000000000000000000000..dbeb99d5d44cd4a02c76912489b82f92701bee3d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/imported/wpt/encrypted-media/scripts/onencrypted.js
@@ -0,0 +1,48 @@
+function runTest(config) {
+ var expectedInitData = [];
+ expectedInitData.push(stringToUint8Array(atob(config.keys[0].initData)));
+ expectedInitData.push(stringToUint8Array(atob(config.keys[1].initData)));
+
+ // Will get 2 identical events, one for audio, one for video.
+ var expectedEvents = 2;
+ var currentData;
+
+ async_test(function (test) {
+ var video = config.video,
+ mediaSource,
+ onEncrypted = function (event) {
+ currentData = new Uint8Array(event.initData);
+ assert_equals(event.target, config.video);
+ assert_true(event instanceof window.MediaEncryptedEvent);
+ assert_equals(event.type, 'encrypted');
+ assert_equals(event.initDataType, 'cenc');
+ // At this point we do not know if the event is related to audio or video. So check for both expected init data
+ assert_true(checkInitData(currentData, expectedInitData[0]) || checkInitData(currentData, expectedInitData[1]));
+
+ if (--expectedEvents === 0) {
+ test.done();
+ }
+ };
+
+ waitForEventAndRunStep('encrypted', video, onEncrypted, test);
+ return testmediasource(config).then(function (source) {
+ mediaSource = source;
+ config.video.src = URL.createObjectURL(mediaSource);
+ return source.done;
+ }).then(function(){
+ video.play();
+ });
+ }, 'encrypted fired on encrypted media file.');
+}
+
+function checkInitData(data, expectedData) {
+ if (data.length !== expectedData.length) {
+ return false;
+ }
+ for (var i = 0; i < data.length; i++) {
+ if (data[i] !== expectedData[i]) {
+ return false;
+ }
+ }
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698