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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 Utils.resetTitleChange = function() { | 209 Utils.resetTitleChange = function() { |
| 210 this.titleChanged = false; | 210 this.titleChanged = false; |
| 211 document.title = ''; | 211 document.title = ''; |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 Utils.sendRequest = function(requestType, responseType, message, serverURL, | 214 Utils.sendRequest = function(requestType, responseType, message, serverURL, |
| 215 onSuccessCallbackFn, forceInvalidResponse) { | 215 onSuccessCallbackFn, forceInvalidResponse) { |
| 216 var requestAttemptCount = 0; | 216 var requestAttemptCount = 0; |
| 217 var MAXIMUM_REQUEST_ATTEMPTS = 3; | 217 var MAXIMUM_REQUEST_ATTEMPTS = 3; |
| 218 var REQUEST_RETRY_DELAY_MS = 3000; | 218 var REQUEST_RETRY_DELAY_MS = 3000; |
| 219 var REQUEST_TIMEOUT_MS = 1000; | |
| 219 | 220 |
| 220 function sendRequestAttempt() { | 221 function sendRequestAttempt() { |
| 221 requestAttemptCount++; | 222 requestAttemptCount++; |
| 222 if (requestAttemptCount == MAXIMUM_REQUEST_ATTEMPTS) { | 223 if (requestAttemptCount > MAXIMUM_REQUEST_ATTEMPTS) { |
| 223 Utils.failTest('FAILED: Exceeded maximum license request attempts.'); | 224 Utils.failTest('FAILED: Exceeded maximum license request attempts.'); |
| 224 return; | 225 return; |
| 225 } | 226 } |
| 226 var xmlhttp = new XMLHttpRequest(); | 227 var xmlhttp = new XMLHttpRequest(); |
| 227 xmlhttp.responseType = responseType; | 228 xmlhttp.responseType = responseType; |
| 228 xmlhttp.open(requestType, serverURL, true); | 229 xmlhttp.open(requestType, serverURL, true); |
| 229 xmlhttp.onerror = function(e) { | 230 xmlhttp.onerror = function(e) { |
| 230 Utils.timeLog('Request status: ' + this.statusText); | 231 Utils.timeLog('Request error: ' + this.statusText); |
| 231 Utils.failTest('FAILED: License request XHR failed with network error.'); | 232 Utils.timeLog('Retrying request if possible in ' + |
| 233 REQUEST_RETRY_DELAY_MS + 'ms'); | |
|
sandersd (OOO until July 31)
2014/10/01 17:46:12
statusText is typically uninformative (it's probab
jrummell
2014/10/01 20:49:07
Done.
| |
| 234 setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS); | |
| 232 }; | 235 }; |
| 233 xmlhttp.onload = function(e) { | 236 xmlhttp.onload = function(e) { |
| 234 if (this.status == 200) { | 237 if (this.status == 200) { |
| 235 if (onSuccessCallbackFn) | 238 if (onSuccessCallbackFn) |
| 236 onSuccessCallbackFn(this.response); | 239 onSuccessCallbackFn(this.response); |
| 237 } else { | 240 } else { |
| 238 Utils.timeLog('Bad response status: ' + this.status); | 241 Utils.timeLog('Bad response status: ' + this.status); |
| 239 Utils.timeLog('Bad response: ' + this.response); | 242 Utils.timeLog('Bad response: ' + this.response); |
| 240 Utils.timeLog('Retrying request if possible in ' + | 243 Utils.timeLog('Retrying request if possible in ' + |
| 241 REQUEST_RETRY_DELAY_MS + 'ms'); | 244 REQUEST_RETRY_DELAY_MS + 'ms'); |
| 242 setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS); | 245 setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS); |
| 243 } | 246 } |
| 244 }; | 247 }; |
| 248 xmlhttp.timeout = REQUEST_TIMEOUT_MS; | |
| 249 xmlhttp.ontimeout = function(e) { | |
| 250 Utils.timeLog('Attempt (' + requestAttemptCount + ') timeout'); | |
|
sandersd (OOO until July 31)
2014/10/01 17:46:11
It would be good to format the three kinds of fail
jrummell
2014/10/01 20:49:07
Done.
| |
| 251 Utils.timeLog('Retrying request if possible in ' + | |
| 252 REQUEST_RETRY_DELAY_MS + 'ms'); | |
| 253 setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS); | |
| 254 } | |
| 245 Utils.timeLog('Attempt (' + requestAttemptCount + | 255 Utils.timeLog('Attempt (' + requestAttemptCount + |
| 246 '): sending request to server: ' + serverURL); | 256 '): sending request to server: ' + serverURL); |
| 247 xmlhttp.send(message); | 257 xmlhttp.send(message); |
| 248 } | 258 } |
| 249 | 259 |
| 250 if (forceInvalidResponse) { | 260 if (forceInvalidResponse) { |
| 251 Utils.timeLog('Not sending request - forcing an invalid response.'); | 261 Utils.timeLog('Not sending request - forcing an invalid response.'); |
| 252 return onSuccessCallbackFn([0xAA]); | 262 return onSuccessCallbackFn([0xAA]); |
| 253 } | 263 } |
| 254 sendRequestAttempt(); | 264 sendRequestAttempt(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 270 var time = Utils.getCurrentTimeString(); | 280 var time = Utils.getCurrentTimeString(); |
| 271 // Log to document. | 281 // Log to document. |
| 272 Utils.documentLog(arguments[0], time); | 282 Utils.documentLog(arguments[0], time); |
| 273 // Log to JS console. | 283 // Log to JS console. |
| 274 var logString = time + ' - '; | 284 var logString = time + ' - '; |
| 275 for (var i = 0; i < arguments.length; i++) { | 285 for (var i = 0; i < arguments.length; i++) { |
| 276 logString += ' ' + arguments[i]; | 286 logString += ' ' + arguments[i]; |
| 277 } | 287 } |
| 278 console.log(logString); | 288 console.log(logString); |
| 279 }; | 289 }; |
| OLD | NEW |