| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.hasPrefix(message.message, EME_RENEWAL_MESSAGE_HEADER)) { |
| 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 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 | |
| 200 // message and finding a known string. | |
| 201 Utils.isRenewalMessagePrefixed = function(msg) { | |
| 202 return Utils.hasPrefix(msg, PREFIXED_EME_RENEWAL_MESSAGE_HEADER); | |
| 203 }; | |
| 204 | |
| 205 Utils.resetTitleChange = function() { | 199 Utils.resetTitleChange = function() { |
| 206 this.titleChanged = false; | 200 this.titleChanged = false; |
| 207 document.title = ''; | 201 document.title = ''; |
| 208 }; | 202 }; |
| 209 | 203 |
| 210 Utils.sendRequest = function( | 204 Utils.sendRequest = function( |
| 211 requestType, responseType, message, serverURL, onResponseCallbackFn, | 205 requestType, responseType, message, serverURL, onResponseCallbackFn, |
| 212 forceInvalidResponse) { | 206 forceInvalidResponse) { |
| 213 var requestAttemptCount = 0; | 207 var requestAttemptCount = 0; |
| 214 var REQUEST_RETRY_DELAY_MS = 3000; | 208 var REQUEST_RETRY_DELAY_MS = 3000; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 var time = Utils.getCurrentTimeString(); | 269 var time = Utils.getCurrentTimeString(); |
| 276 // Log to document. | 270 // Log to document. |
| 277 Utils.documentLog(arguments[0], time); | 271 Utils.documentLog(arguments[0], time); |
| 278 // Log to JS console. | 272 // Log to JS console. |
| 279 var logString = time + ' - '; | 273 var logString = time + ' - '; |
| 280 for (var i = 0; i < arguments.length; i++) { | 274 for (var i = 0; i < arguments.length; i++) { |
| 281 logString += ' ' + arguments[i]; | 275 logString += ' ' + arguments[i]; |
| 282 } | 276 } |
| 283 console.log(logString); | 277 console.log(logString); |
| 284 }; | 278 }; |
| OLD | NEW |