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

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: 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 |expectedKeys|
137 // and none of the keys in |otherKeys|. All keys should have status 'usable'.
138 function verifyKeyStatuses(keyStatuses, expectedKeys, otherKeys)
sandersd (OOO until July 31) 2015/01/30 20:40:00 Consider taking the expected/other keys parameters
jrummell 2015/01/30 22:33:56 Done.
139 {
140 assert_true(Array.isArray(expectedKeys) && Array.isArray(otherKeys),
141 'Incorrect usage of verifyKeyStatuses()');
142
143 // |keyStatuses| should have same size as number of |expectedKeys|.
144 assert_equals(keyStatuses.size, expectedKeys.length);
145
146 // All |expectedKeys| should be found.
147 expectedKeys.map(function(key) {
148 assert_true(keyStatuses.has(key));
149 assert_equals(keyStatuses.get(key), 'usable');
150 });
151
152 // All |otherKeys| should not be found.
153 otherKeys.map(function(key) {
154 assert_false(keyStatuses.has(key));
155 assert_equals(keyStatuses.get(key), undefined);
156 });
157 }
158
112 // Encodes data into base64 string without trailing '='. 159 // Encodes data into base64 string without trailing '='.
113 function base64Encode(data) 160 function base64Encode(data)
114 { 161 {
115 var result = btoa(String.fromCharCode.apply(null, data)); 162 var result = btoa(String.fromCharCode.apply(null, data));
116 return result.replace(/=+$/g, ''); 163 return result.replace(/=+$/g, '');
117 } 164 }
118 165
119 // For Clear Key, the License Format is a JSON Web Key (JWK) Set, which contains 166 // 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 167 // a set of cryptographic keys represented by JSON. These helper functions help
121 // wrap raw keys into a JWK set. 168 // wrap raw keys into a JWK set.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 return stringToUint8Array(decoded_key); 223 return stringToUint8Array(decoded_key);
177 } 224 }
178 catch (o) { 225 catch (o) {
179 // Not valid JSON, so return message untouched as Uint8Array. 226 // Not valid JSON, so return message untouched as Uint8Array.
180 // This is for backwards compatibility. 227 // This is for backwards compatibility.
181 // FIXME: Remove this once the code is switched to return JSON all 228 // FIXME: Remove this once the code is switched to return JSON all
182 // the time. 229 // the time.
183 return new Uint8Array(message); 230 return new Uint8Array(message);
184 } 231 }
185 } 232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698