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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 var message = String.fromCharCode.apply(null, msg); | 195 var message = String.fromCharCode.apply(null, msg); |
196 return message.substring(0, prefix.length) == prefix; | 196 return message.substring(0, prefix.length) == prefix; |
197 }; | 197 }; |
198 | 198 |
199 Utils.installTitleEventHandler = function(element, event) { | 199 Utils.installTitleEventHandler = function(element, event) { |
200 element.addEventListener(event, function(e) { | 200 element.addEventListener(event, function(e) { |
201 Utils.setResultInTitle(e.type); | 201 Utils.setResultInTitle(e.type); |
202 }, false); | 202 }, false); |
203 }; | 203 }; |
204 | 204 |
205 Utils.isHeartBeatMessage = function(msg) { | 205 Utils.isRenewalMessage = function(message) { |
206 return Utils.hasPrefix(Utils.convertToUint8Array(msg), HEART_BEAT_HEADER); | 206 if (message.messageType != 'license-renewal') |
| 207 return false; |
| 208 |
| 209 if (!Utils.isRenewalMessagePrefixed(message.message)) { |
| 210 Utils.failTest('license-renewal message doesn\'t contain expected header', |
| 211 KEY_ERROR); |
| 212 } |
| 213 return true; |
| 214 }; |
| 215 |
| 216 // For the prefixed API renewal messages are determined by looking at the |
| 217 // message and finding a known string. |
| 218 Utils.isRenewalMessagePrefixed = function(msg) { |
| 219 return Utils.hasPrefix(Utils.convertToUint8Array(msg), |
| 220 RENEWAL_MESSAGE_HEADER); |
207 }; | 221 }; |
208 | 222 |
209 Utils.resetTitleChange = function() { | 223 Utils.resetTitleChange = function() { |
210 this.titleChanged = false; | 224 this.titleChanged = false; |
211 document.title = ''; | 225 document.title = ''; |
212 }; | 226 }; |
213 | 227 |
214 Utils.sendRequest = function(requestType, responseType, message, serverURL, | 228 Utils.sendRequest = function(requestType, responseType, message, serverURL, |
215 onSuccessCallbackFn, forceInvalidResponse) { | 229 onSuccessCallbackFn, forceInvalidResponse) { |
216 var requestAttemptCount = 0; | 230 var requestAttemptCount = 0; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 var time = Utils.getCurrentTimeString(); | 289 var time = Utils.getCurrentTimeString(); |
276 // Log to document. | 290 // Log to document. |
277 Utils.documentLog(arguments[0], time); | 291 Utils.documentLog(arguments[0], time); |
278 // Log to JS console. | 292 // Log to JS console. |
279 var logString = time + ' - '; | 293 var logString = time + ' - '; |
280 for (var i = 0; i < arguments.length; i++) { | 294 for (var i = 0; i < arguments.length; i++) { |
281 logString += ' ' + arguments[i]; | 295 logString += ' ' + arguments[i]; |
282 } | 296 } |
283 console.log(logString); | 297 console.log(logString); |
284 }; | 298 }; |
OLD | NEW |