OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Utils provide logging functions and other JS functions commonly used by the | 5 // Utils provide logging functions and other JS functions commonly used by the |
6 // app and media players. | 6 // app and media players. |
7 var Utils = new function() { | 7 var Utils = new function() { |
8 this.titleChanged = false; | 8 this.titleChanged = false; |
9 }; | 9 }; |
10 | 10 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 for (var i = 0; i < uintArray.length; i++) { | 168 for (var i = 0; i < uintArray.length; i++) { |
169 var hex = uintArray[i].toString(16); | 169 var hex = uintArray[i].toString(16); |
170 if (hex.length == 1) | 170 if (hex.length == 1) |
171 hex = '0' + hex; | 171 hex = '0' + hex; |
172 hex_str += hex; | 172 hex_str += hex; |
173 } | 173 } |
174 return hex_str; | 174 return hex_str; |
175 }; | 175 }; |
176 | 176 |
177 Utils.hasPrefix = function(msg, prefix) { | 177 Utils.hasPrefix = function(msg, prefix) { |
178 var message = String.fromCharCode.apply(null, msg); | 178 var message = String.fromCharCode.apply(null, Utils.convertToUint8Array(msg)); |
ddorwin
2016/02/20 00:09:10
Since there is no way to assert that a Uint8Array
| |
179 return message.substring(0, prefix.length) == prefix; | 179 return message.substring(0, prefix.length) == prefix; |
180 }; | 180 }; |
181 | 181 |
182 Utils.installTitleEventHandler = function(element, event) { | 182 Utils.installTitleEventHandler = function(element, event) { |
183 element.addEventListener(event, function(e) { | 183 element.addEventListener(event, function(e) { |
184 Utils.setResultInTitle(e.type); | 184 Utils.setResultInTitle(e.type); |
185 }, false); | 185 }, false); |
186 }; | 186 }; |
187 | 187 |
188 Utils.isRenewalMessage = function(message) { | 188 Utils.isRenewalMessage = function(message) { |
189 if (message.messageType != 'license-renewal') | 189 if (message.messageType != 'license-renewal') |
190 return false; | 190 return false; |
191 | 191 |
192 if (!Utils.isRenewalMessagePrefixed(message.message)) { | 192 if (!Utils.isRenewalMessagePrefixed(message.message)) { |
193 Utils.failTest('license-renewal message doesn\'t contain expected header', | 193 Utils.failTest('license-renewal message doesn\'t contain expected header', |
194 PREFIXED_EME_RENEWAL_MISSING_HEADER); | 194 PREFIXED_EME_RENEWAL_MISSING_HEADER); |
195 } | 195 } |
196 return true; | 196 return true; |
197 }; | 197 }; |
198 | 198 |
199 // For the prefixed API renewal messages are determined by looking at the | 199 // For the prefixed API renewal messages are determined by looking at the |
200 // message and finding a known string. | 200 // message and finding a known string. |
201 Utils.isRenewalMessagePrefixed = function(msg) { | 201 Utils.isRenewalMessagePrefixed = function(msg) { |
202 return Utils.hasPrefix(Utils.convertToUint8Array(msg), | 202 return Utils.hasPrefix(msg, PREFIXED_EME_RENEWAL_MESSAGE_HEADER); |
203 PREFIXED_EME_RENEWAL_MESSAGE_HEADER); | |
204 }; | 203 }; |
205 | 204 |
206 Utils.resetTitleChange = function() { | 205 Utils.resetTitleChange = function() { |
207 this.titleChanged = false; | 206 this.titleChanged = false; |
208 document.title = ''; | 207 document.title = ''; |
209 }; | 208 }; |
210 | 209 |
211 Utils.sendRequest = function( | 210 Utils.sendRequest = function( |
212 requestType, responseType, message, serverURL, onResponseCallbackFn, | 211 requestType, responseType, message, serverURL, onResponseCallbackFn, |
213 forceInvalidResponse) { | 212 forceInvalidResponse) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 var time = Utils.getCurrentTimeString(); | 275 var time = Utils.getCurrentTimeString(); |
277 // Log to document. | 276 // Log to document. |
278 Utils.documentLog(arguments[0], time); | 277 Utils.documentLog(arguments[0], time); |
279 // Log to JS console. | 278 // Log to JS console. |
280 var logString = time + ' - '; | 279 var logString = time + ' - '; |
281 for (var i = 0; i < arguments.length; i++) { | 280 for (var i = 0; i < arguments.length; i++) { |
282 logString += ' ' + arguments[i]; | 281 logString += ' ' + arguments[i]; |
283 } | 282 } |
284 console.log(logString); | 283 console.log(logString); |
285 }; | 284 }; |
OLD | NEW |