Chromium Code Reviews| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, Utils.convertToUint8Array(msg)); | 178 var message = String.fromCharCode.apply(null, Utils.convertToUint8Array(msg)); |
| 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.toUpperCase()); |
|
ddorwin
2016/03/04 19:00:16
There is an "ended" event that would conflict with
sandersd (OOO until July 31)
2016/03/04 19:26:00
Indeed there is, but tests are explicitly relying
ddorwin
2016/03/04 20:14:06
Hmm. Maybe all the expected strings should have sp
sandersd (OOO until July 31)
2016/03/04 20:40:17
Acknowledged.
| |
| 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.hasPrefix(message.message, EME_RENEWAL_MESSAGE_HEADER)) { | 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 EME_RENEWAL_MISSING_HEADER); | 194 EME_RENEWAL_MISSING_HEADER); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 if (forceInvalidResponse) { | 249 if (forceInvalidResponse) { |
| 250 Utils.timeLog('Not sending request - forcing an invalid response.'); | 250 Utils.timeLog('Not sending request - forcing an invalid response.'); |
| 251 return onResponseCallbackFn(Utils.convertToUint8Array("Invalid response.")); | 251 return onResponseCallbackFn(Utils.convertToUint8Array("Invalid response.")); |
| 252 } | 252 } |
| 253 sendRequestAttempt(); | 253 sendRequestAttempt(); |
| 254 }; | 254 }; |
| 255 | 255 |
| 256 Utils.setResultInTitle = function(title) { | 256 Utils.setResultInTitle = function(title) { |
| 257 // If document title is 'ENDED', then update it with new title to possibly | 257 // If document title is 'ENDED', then update it with new title to possibly |
| 258 // mark a test as failure. Otherwise, keep the first title change in place. | 258 // mark a test as failure. Otherwise, keep the first title change in place. |
| 259 if (!this.titleChanged || document.title.toUpperCase() == 'ENDED') | 259 if (!this.titleChanged || document.title == 'ENDED') |
| 260 document.title = title.toUpperCase(); | 260 document.title = title; |
| 261 Utils.timeLog('Set document title to: ' + title + ', updated title: ' + | 261 Utils.timeLog('Set document title to: ' + title + ', updated title: ' + |
| 262 document.title); | 262 document.title); |
| 263 this.titleChanged = true; | 263 this.titleChanged = true; |
| 264 }; | 264 }; |
| 265 | 265 |
| 266 Utils.timeLog = function(/**/) { | 266 Utils.timeLog = function(/**/) { |
| 267 if (arguments.length == 0) | 267 if (arguments.length == 0) |
| 268 return; | 268 return; |
| 269 var time = Utils.getCurrentTimeString(); | 269 var time = Utils.getCurrentTimeString(); |
| 270 // Log to document. | 270 // Log to document. |
| 271 Utils.documentLog(arguments[0], time); | 271 Utils.documentLog(arguments[0], time); |
| 272 // Log to JS console. | 272 // Log to JS console. |
| 273 var logString = time + ' - '; | 273 var logString = time + ' - '; |
| 274 for (var i = 0; i < arguments.length; i++) { | 274 for (var i = 0; i < arguments.length; i++) { |
| 275 logString += ' ' + arguments[i]; | 275 logString += ' ' + arguments[i]; |
| 276 } | 276 } |
| 277 console.log(logString); | 277 console.log(logString); |
| 278 }; | 278 }; |
| OLD | NEW |