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

Side by Side Diff: LayoutTests/media/encrypted-media/encrypted-media-utils.js

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
1 var console = null; 1 var console = null;
2 2
3 function consoleWrite(text) 3 function consoleWrite(text)
4 { 4 {
5 if (!console && document.body) { 5 if (!console && document.body) {
6 console = document.createElement('div'); 6 console = document.createElement('div');
7 document.body.appendChild(console); 7 document.body.appendChild(console);
8 } 8 }
9 var span = document.createElement('span'); 9 var span = document.createElement('span');
10 span.appendChild(document.createTextNode(text)); 10 span.appendChild(document.createTextNode(text));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return result; 102 return result;
103 } 103 }
104 104
105 function arrayBufferAsString(buffer) 105 function arrayBufferAsString(buffer)
106 { 106 {
107 // MediaKeySession.keyStatuses iterators return an ArrayBuffer, 107 // MediaKeySession.keyStatuses iterators return an ArrayBuffer,
108 // so convert it into a printable string. 108 // so convert it into a printable string.
109 return String.fromCharCode.apply(null, new Uint8Array(buffer)); 109 return String.fromCharCode.apply(null, new Uint8Array(buffer));
110 } 110 }
111 111
112 function dumpKeyStatuses(keyStatuses)
113 {
114 consoleWrite("for (var entry of keyStatuses)");
115 for (var entry of keyStatuses) {
116 consoleWrite(arrayBufferAsString(entry[0]) + ", " + entry[1]);
117 }
118 consoleWrite("for (var key of keyStatuses.keys())");
119 for (var key of keyStatuses.keys()) {
120 consoleWrite(arrayBufferAsString(key));
121 }
122 consoleWrite("for (var value of keyStatuses.values())");
123 for (var value of keyStatuses.values()) {
124 consoleWrite(value);
125 }
126 consoleWrite("for (var entry of keyStatuses.entries())");
127 for (var entry of keyStatuses.entries()) {
128 consoleWrite(arrayBufferAsString(entry[0]) + ", " + entry[1]);
129 }
130 consoleWrite("keyStatuses.forEach()");
131 keyStatuses.forEach(function(value, key, map) {
132 consoleWrite(arrayBufferAsString(key) + ", " + value);
133 });
134 }
135
136 // Verify that |keyStatuses| contains just the keys in |keys.expected|
137 // and none of the keys in |keys.unexpected|. All keys should have status
138 // 'usable'.
sandersd (OOO until July 31) 2015/01/30 22:51:38 Best to provide an example call.
jrummell 2015/01/30 23:18:25 Done.
139 function verifyKeyStatuses(keyStatuses, keys)
140 {
141 assert_true(Array.isArray(keys.expected) && Array.isArray(keys.unexpected),
142 'Incorrect usage of verifyKeyStatuses()');
sandersd (OOO until July 31) 2015/01/30 22:51:38 Alternatively, you can use the more common notatio
jrummell 2015/01/30 23:18:26 Done. I removed unexpected: [], but left in empty
143
144 // |keyStatuses| should have same size as number of |expectedKeys|.
145 assert_equals(keyStatuses.size, keys.expected.length);
146
147 // All |keys.expected| should be found.
148 keys.expected.map(function(key) {
149 assert_true(keyStatuses.has(key));
150 assert_equals(keyStatuses.get(key), 'usable');
151 });
152
153 // All |keys.unexpected| should not be found.
154 keys.unexpected.map(function(key) {
155 assert_false(keyStatuses.has(key));
156 assert_equals(keyStatuses.get(key), undefined);
157 });
158 }
159
112 // Encodes data into base64 string without trailing '='. 160 // Encodes data into base64 string without trailing '='.
113 function base64Encode(data) 161 function base64Encode(data)
114 { 162 {
115 var result = btoa(String.fromCharCode.apply(null, data)); 163 var result = btoa(String.fromCharCode.apply(null, data));
116 return result.replace(/=+$/g, ''); 164 return result.replace(/=+$/g, '');
117 } 165 }
118 166
119 // For Clear Key, the License Format is a JSON Web Key (JWK) Set, which contains 167 // For Clear Key, the License Format is a JSON Web Key (JWK) Set, which contains
120 // a set of cryptographic keys represented by JSON. These helper functions help 168 // a set of cryptographic keys represented by JSON. These helper functions help
121 // wrap raw keys into a JWK set. 169 // wrap raw keys into a JWK set.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 return stringToUint8Array(decoded_key); 224 return stringToUint8Array(decoded_key);
177 } 225 }
178 catch (o) { 226 catch (o) {
179 // Not valid JSON, so return message untouched as Uint8Array. 227 // Not valid JSON, so return message untouched as Uint8Array.
180 // This is for backwards compatibility. 228 // This is for backwards compatibility.
181 // FIXME: Remove this once the code is switched to return JSON all 229 // FIXME: Remove this once the code is switched to return JSON all
182 // the time. 230 // the time.
183 return new Uint8Array(message); 231 return new Uint8Array(message);
184 } 232 }
185 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698