Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / media / encrypted-media / encrypted-media-keystatuses.html
blobd8b96b69d31499a529c4d5b238d6ec89e3fbd962
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Verify MediaKeySession.keyStatuses</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 async_test(function(test)
14 var mediaKeySession;
15 var initDataType;
16 var initData;
18 // Even though key ids are uint8, using printable values so that
19 // they can be verified easily.
20 var key1String = '123';
21 var key2String = '4567890';
22 var key1 = stringToUint8Array(key1String);
23 var key2 = stringToUint8Array(key2String);
24 var rawKey1 = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
25 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);
26 var rawKey2 = new Uint8Array([0x3c, 0xae, 0xe4, 0xfc, 0x2a, 0x12, 0xef, 0x68,
27 0x7b, 0xd2, 0x14, 0x68, 0xf1, 0x62, 0xdd, 0xeb]);
29 function processMessage(event)
31 // No keys added yet.
32 assert_equals(mediaKeySession.keyStatuses.size, 0);
34 waitForEventAndRunStep('keystatuseschange', mediaKeySession, processKeyStatusesChange, test);
36 var jwkSet = stringToUint8Array(createJWKSet(createJWK(key1, rawKey1), createJWK(key2, rawKey2)));
37 mediaKeySession.update(jwkSet).catch(function(error) {
38 forceTestFailureFromPromise(test, error);
39 });
42 function processKeyStatusesChange(event)
44 // Two keys added, so both should show up in |keyStatuses|.
45 assert_equals(mediaKeySession.keyStatuses.size, 2);
46 dumpKeyStatuses(mediaKeySession.keyStatuses);
48 // Check |keyStatuses| for 2 entries.
49 var result = [];
50 for (var entry of mediaKeySession.keyStatuses) {
51 result.push({ key: arrayBufferAsString(entry[0]), value: entry[1] });
53 assert_object_equals(result,
54 [{ key: key1String, value: 'usable'}, { key: key2String, value: 'usable'}],
55 'keyStatuses fails');
57 // |keyStatuses| must contain both keys.
58 result = [];
59 for (var key of mediaKeySession.keyStatuses.keys()) {
60 result.push(arrayBufferAsString(key));
62 assert_array_equals(result,
63 [key1String, key2String],
64 'keyStatuses.keys() fails');
66 // Both values in |mediaKeySession| should be 'usable'.
67 result = [];
68 for (var value of mediaKeySession.keyStatuses.values()) {
69 result.push(value);
71 assert_array_equals(result,
72 ['usable', 'usable'],
73 'keyStatuses.values() fails');
75 // Check |keyStatuses.entries()|.
76 result = [];
77 for (var entry of mediaKeySession.keyStatuses.entries()) {
78 result.push({ key: arrayBufferAsString(entry[0]), value: entry[1] });
80 assert_object_equals(result,
81 [{ key: key1String, value: 'usable'}, { key: key2String, value: 'usable'}],
82 'keyStatuses.entries() fails');
84 // forEach() should return both entries.
85 result = [];
86 mediaKeySession.keyStatuses.forEach(function(value, key, map) {
87 result.push({ key: arrayBufferAsString(key), value: value });
88 });
89 assert_object_equals(result,
90 [{ key: key1String, value: 'usable'}, { key: key2String, value: 'usable'}],
91 'keyStatuses.forEach() fails');
93 assert_true(mediaKeySession.keyStatuses.has(key1));
94 assert_true(mediaKeySession.keyStatuses.has(key2));
95 assert_false(mediaKeySession.keyStatuses.has(stringToUint8Array('123456')));
96 assert_equals(mediaKeySession.keyStatuses.get(key1), 'usable');
97 assert_equals(mediaKeySession.keyStatuses.get(key2), 'usable');
98 assert_equals(mediaKeySession.keyStatuses.get(stringToUint8Array('123456')), undefined);
100 test.done();
103 getSupportedInitDataType().then(function(type) {
104 initDataType = type;
105 initData = getInitData(initDataType);
106 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
107 }).then(function(access) {
108 return access.createMediaKeys();
109 }).then(function(mediaKeys) {
110 mediaKeySession = mediaKeys.createSession();
112 // There should be no keys defined yet.
113 assert_equals(mediaKeySession.keyStatuses.size, 0);
115 waitForEventAndRunStep('message', mediaKeySession, processMessage, test);
116 return mediaKeySession.generateRequest(initDataType, initData);
117 }).catch(function(error) {
118 forceTestFailureFromPromise(test, error);
120 }, 'Verify MediaKeySession.keyStatuses.');
121 </script>
122 </body>
123 </html>