Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / media / encrypted-media / encrypted-media-playback-encrypted-and-clear-sources.html
blobc4686b2c5edc927f0a96c86739b66fe4a9f50abb
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Multiple playbacks alternating between encrypted and clear sources.</title>
5 <script src="encrypted-media-utils.js"></script>
6 <script src="../../resources/testharness.js"></script>
7 <script src="../../resources/testharnessreport.js"></script>
8 </head>
9 <body>
10 <video id="testVideo"></video>
11 <div id="log"></div>
12 <script>
13 async_test(function(test)
15 var video = document.getElementById('testVideo');
16 var isUpdatePromiseResolved = false;
17 var encryptedEventCount = 0;
18 var playbackCount = 0;
20 var rawKey = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
21 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);
23 function onEncrypted(event)
25 assert_equals(event.target, video);
26 assert_true(event instanceof window.MediaEncryptedEvent);
27 assert_equals(event.type, 'encrypted');
29 // The same decryption key is used by both the audio and
30 // the video streams so only create a session once. To
31 // avoid issues when comparing the expected.txt file
32 // (which logs the events in the order they occur), create
33 // the session on the second event. This also ensures we
34 // see both events.
35 if (++encryptedEventCount != 2)
36 return;
38 assert_false(video.mediaKeys === null, "video.mediaKeys is null.");
39 var mediaKeySession = video.mediaKeys.createSession();
40 waitForEventAndRunStep('message', mediaKeySession, onMessage, test);
41 mediaKeySession.generateRequest(event.initDataType, event.initData).catch(function(error) {
42 forceTestFailureFromPromise(test, error);
43 });
46 function onMessage(event)
48 assert_true(event instanceof window.MediaKeyMessageEvent);
49 assert_equals(event.type, 'message');
50 assert_equals(event.messageType, 'license-request');
52 var keyId = extractSingleKeyIdFromMessage(event.message);
53 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, rawKey)));
54 event.target.update(jwkSet).then(function(result) {
55 isUpdatePromiseResolved = true;
56 }).catch(function(error) {
57 forceTestFailureFromPromise(test, error);
58 });
61 function onPlaying(event)
63 // Not using waitForEventAndRunStep() to avoid too many
64 // EVENT(onTimeUpdate) logs.
65 video.addEventListener('timeupdate', onTimeUpdate, true);
68 function onTimeUpdate(event)
70 if (event.target.currentTime < 0.2 || !isUpdatePromiseResolved)
71 return;
73 video.removeEventListener('timeupdate', onTimeUpdate, true);
75 if (playbackCount > 2) {
76 test.done();
77 return;
80 playbackCount++;
82 resetSrc().then(function(){
83 startPlayback();
84 });
87 function resetSrc() {
88 encryptedEventCount = 0;
89 video.removeAttribute('src');
90 video.load();
91 return video.setMediaKeys(null);
94 function startPlayback() {
95 if (playbackCount % 2) {
96 video.src = '../content/test-vp8-vorbis-webvtt.webm';
97 video.play();
98 return;
101 navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
102 return access.createMediaKeys();
103 }).then(function(mediaKeys) {
104 return video.setMediaKeys(mediaKeys);
105 }).then(function(result) {
106 video.src = '../content/test-encrypted.webm';
107 assert_false(video.mediaKeys === null, "video.mediaKeys is null.");
108 video.play();
109 }).catch(function(error) {
110 forceTestFailureFromPromise(test, error);
114 waitForEventAndRunStep('playing', video, onPlaying, test);
115 waitForEventAndRunStep('encrypted', video, onEncrypted, test);
116 startPlayback();
117 }, 'Multiple playbacks alternating between encrypted and clear sources.');
118 </script>
119 </body>
120 </html>