Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / media / encrypted-media / encrypted-media-playback-multiple-sessions.html
blob8277b7b0b2a15d4fcb008ada1db47eace0ab6762
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Clear Key Playback with Multiple Sessions</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 audioMediaKeySession = null;
17 var videoMediaKeySession = null;
18 var audioInitDataType = null;
19 var videoInitDataType = null;
20 var audioInitData = null;
21 var videoInitData = null;
22 var audioKeyProvided = false;
23 var videoKeyProvided = false;
25 // The 2 streams use different key ids and different keys.
26 var audioKeyId = '1234567890123456';
27 var audioKey = new Uint8Array([0x30, 0x30, 0x62, 0xF1, 0x68, 0x14, 0xD2, 0x7B,
28 0x68, 0xEF, 0x12, 0x2A, 0xFC, 0xE4, 0xAE, 0x0A]);
29 var videoKeyId = '0123456789012345';
30 var videoKey = new Uint8Array([0x7A, 0x7A, 0x62, 0xF1, 0x68, 0x14, 0xD2, 0x7B,
31 0x68, 0xEF, 0x12, 0x2A, 0xFC, 0xE4, 0xAE, 0x0A]);
33 function onEncrypted(event)
35 var keyId = String.fromCharCode.apply(null, new Uint8Array(event.initData));
37 // To avoid issues when comparing the expected.txt file
38 // (which logs the events in the order they occur), save
39 // the initData and make the calls to generateRequest()
40 // only after both "onencrypted" events are received.
41 // This prevents a "message" event from occurring before
42 // both "onencrypted" events are received.
43 var mediaKeySession = video.mediaKeys.createSession();
44 if (keyId == videoKeyId) {
45 assert_equals(videoMediaKeySession, null);
46 videoMediaKeySession = mediaKeySession;
47 videoInitDataType = event.initDataType;
48 videoInitData = event.initData;
49 // Return if audio "onencrypted" event not yet received.
50 if (audioMediaKeySession == null)
51 return;
52 } else {
53 assert_equals(keyId, audioKeyId);
54 assert_equals(audioMediaKeySession, null);
55 audioMediaKeySession = mediaKeySession;
56 audioInitDataType = event.initDataType;
57 audioInitData = event.initData;
58 // Return if video "onencrypted" event not yet received.
59 if (videoMediaKeySession == null)
60 return;
63 // Both sessions have been created.
64 assert_not_equals(videoMediaKeySession, null);
65 assert_not_equals(audioMediaKeySession, null);
67 var promises = [];
68 waitForEventAndRunStep('message', videoMediaKeySession, onMessage, test);
69 promises.push(videoMediaKeySession.generateRequest(videoInitDataType, videoInitData));
71 waitForEventAndRunStep('message', audioMediaKeySession, onMessage, test);
72 promises.push(audioMediaKeySession.generateRequest(audioInitDataType, audioInitData));
74 Promise.all(promises).catch(function(error) {
75 forceTestFailureFromPromise(test, error);
76 });
79 function onMessage(event)
81 assert_equals(event.messageType, 'license-request');
82 var keyId = extractSingleKeyIdFromMessage(event.message);
83 if (event.target == videoMediaKeySession) {
84 assert_equals(String.fromCharCode.apply(null, keyId), videoKeyId);
85 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, videoKey)));
86 videoMediaKeySession.update(jwkSet).then(function(result) {
87 videoKeyProvided = true;
88 }).catch(function(error) {
89 forceTestFailureFromPromise(test, error);
90 });
91 } else {
92 assert_equals(event.target, audioMediaKeySession);
93 assert_equals(String.fromCharCode.apply(null, keyId), audioKeyId);
94 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, audioKey)));
95 audioMediaKeySession.update(jwkSet).then(function(result) {
96 audioKeyProvided = true;
97 }).catch(function(error) {
98 forceTestFailureFromPromise(test, error);
99 });
103 function onPlaying(event)
105 // Video should not start playing until both keys have been
106 // provided.
107 assert_true(videoKeyProvided);
108 assert_true(audioKeyProvided);
110 // Not using waitForEventAndRunStep() to avoid too many
111 // EVENT(onTimeUpdate) logs.
112 video.addEventListener('timeupdate', onTimeUpdate, true);
115 function onTimeUpdate(event)
117 if (event.target.currentTime < 0.2)
118 return;
120 test.done();
123 navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
124 return access.createMediaKeys();
125 }).then(function(mediaKeys) {
126 waitForEventAndRunStep('encrypted', video, onEncrypted, test);
127 waitForEventAndRunStep('playing', video, onPlaying, test);
128 video.src = '../content/test-encrypted-different-av-keys.webm';
129 return video.setMediaKeys(mediaKeys);
130 }).then(function(result) {
131 video.play();
132 }).catch(function(error) {
133 forceTestFailureFromPromise(test, error);
135 }, 'Playback using Clear Key key system with multiple sessions.');
136 </script>
137 </body>
138 </html>