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

Side by Side Diff: LayoutTests/media/encrypted-media/encrypted-media-keystatuses-multiple-sessions.html

Issue 880313003: Add additional layout tests for MediaKeySession.keyStatuses (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: js Created 5 years, 10 months 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 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Verify MediaKeySession.keyStatuses 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 <div id="log"></div>
11 <script>
12 var mediaKeySession1;
13 var mediaKeySession2;
14
15 // Even though key ids are uint8, using printable values so that
16 // they can be verified easily.
17 var key1 = stringToUint8Array('123');
18 var key2 = stringToUint8Array('4567890');
19 var rawKey1 = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0x d2, 0x7b,
20 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0x ae, 0x3c]);
21 var rawKey2 = new Uint8Array([0x3c, 0xae, 0xe4, 0xfc, 0x2a, 0x12, 0x ef, 0x68,
22 0x7b, 0xd2, 0x14, 0x68, 0xf1, 0x62, 0x dd, 0xeb]);
23
24 async_test(function(test)
25 {
26 function processMessage1(event)
27 {
28 // This should only be called for session1.
29 assert_equals(event.target, mediaKeySession1);
30
31 // No keys added yet.
32 verifyKeyStatuses(mediaKeySession1.keyStatuses, { expected: [], unexpected: [key1, key2] });
33
34 // Add key1 to session1.
35 var jwkSet = stringToUint8Array(createJWKSet(createJWK(key1, rawKey1)));
36 mediaKeySession1.update(jwkSet).catch(function(error) {
37 forceTestFailureFromPromise(test, error);
38 });
39 }
40
41 function processKeyStatusesChange1(event)
42 {
43 // This should only be called for session1.
44 assert_equals(event.target, mediaKeySession1);
45
46 // Check that keyStatuses contains the expected key1 only.
47 dumpKeyStatuses(mediaKeySession1.keyStatuses);
48 verifyKeyStatuses(mediaKeySession1.keyStatuses, { expected: [key1], unexpected: [key2] });
49
50 // Now trigger a message event on session2.
51 var initDataType = getInitDataType();
52 mediaKeySession2.generateRequest(initDataType, getInitData(i nitDataType)).catch(function(error) {
53 forceTestFailureFromPromise(test, error);
54 });
55 }
56
57 function processMessage2(event)
58 {
59 // This should only be called for session2.
60 assert_equals(event.target, mediaKeySession2);
61
62 // session2 has no keys added yet.
63 verifyKeyStatuses(mediaKeySession2.keyStatuses, { expected: [], unexpected: [key1, key2] });
64
65 // session1 should still have 1 key.
66 verifyKeyStatuses(mediaKeySession1.keyStatuses, { expected: [key1], unexpected: [key2] });
67
68 // Add key2 to session2.
69 var jwkSet = stringToUint8Array(createJWKSet(createJWK(key2, rawKey2)));
70 mediaKeySession2.update(jwkSet).catch(function(error) {
71 forceTestFailureFromPromise(test, error);
72 });
73 }
74
75 function processKeyStatusesChange2(event)
76 {
77 // This should only be called for session2.
78 assert_equals(event.target, mediaKeySession2);
79
80 // Check that keyStatuses contains the expected key2 only.
81 dumpKeyStatuses(mediaKeySession2.keyStatuses);
82 verifyKeyStatuses(mediaKeySession2.keyStatuses, { expected: [key2], unexpected: [key1] });
83
84 // session1 should still have 1 key.
85 verifyKeyStatuses(mediaKeySession1.keyStatuses, { expected: [key1], unexpected: [key2] });
86
87 test.done();
88 }
89
90 navigator.requestMediaKeySystemAccess('org.w3.clearkey').then(fu nction(access) {
91 return access.createMediaKeys();
92 }).then(function(mediaKeys) {
93 var initDataType = getInitDataType();
94 mediaKeySession1 = mediaKeys.createSession();
95 mediaKeySession2 = mediaKeys.createSession();
96
97 // There should be no keys defined on either session.
98 verifyKeyStatuses(mediaKeySession1.keyStatuses, { expected: [], unexpected: [key1, key2] });
99 verifyKeyStatuses(mediaKeySession2.keyStatuses, { expected: [], unexpected: [key1, key2] });
100
101 // Bind all the event handlers now.
102 waitForEventAndRunStep('message', mediaKeySession1, processM essage1, test);
103 waitForEventAndRunStep('message', mediaKeySession2, processM essage2, test);
104 waitForEventAndRunStep('keystatuseschange', mediaKeySession1 , processKeyStatusesChange1, test);
105 waitForEventAndRunStep('keystatuseschange', mediaKeySession2 , processKeyStatusesChange2, test);
106
107 // Generate a request on session1.
108 return mediaKeySession1.generateRequest(initDataType, getIni tData(initDataType));
109 }).catch(function(error) {
110 forceTestFailureFromPromise(test, error);
111 });
112 }, 'Verify MediaKeySession.keyStatuses with multiple sessions.');
113 </script>
114 </body>
115 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698