| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // Miscellaneous utility functions for HTML media tests. Loading this script | 5 // Miscellaneous utility functions for HTML media tests. Loading this script |
| 6 // should not modify the page in any way. | 6 // should not modify the page in any way. |
| 7 // | |
| 8 | 7 |
| 9 var QueryString = function () { | 8 var QueryString = function() { |
| 10 // Allows access to query parameters on the URL; e.g., given a URL like: | 9 // Allows access to query parameters on the URL; e.g., given a URL like: |
| 11 // | |
| 12 // http://<url>/my.html?test=123&bob=123 | 10 // http://<url>/my.html?test=123&bob=123 |
| 13 // | |
| 14 // parameters can now be accessed via QueryString.test or QueryString.bob. | 11 // parameters can now be accessed via QueryString.test or QueryString.bob. |
| 15 var params = {}; | 12 var params = {}; |
| 16 | |
| 17 // RegEx to split out values by &. | 13 // RegEx to split out values by &. |
| 18 var r = /([^&=]+)=?([^&]*)/g; | 14 var r = /([^&=]+)=?([^&]*)/g; |
| 19 | |
| 20 // Lambda function for decoding extracted match values. Replaces '+' with | 15 // Lambda function for decoding extracted match values. Replaces '+' with |
| 21 // space so decodeURIComponent functions properly. | 16 // space so decodeURIComponent functions properly. |
| 22 function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); } | 17 function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); } |
| 23 | |
| 24 var match; | 18 var match; |
| 25 while (match = r.exec(window.location.search.substring(1))) | 19 while (match = r.exec(window.location.search.substring(1))) |
| 26 params[d(match[1])] = d(match[2]); | 20 params[d(match[1])] = d(match[2]); |
| 27 | |
| 28 return params; | 21 return params; |
| 29 } (); | 22 }(); |
| 30 | |
| 31 function getCurrentTime() { | |
| 32 if (window.performance.now) | |
| 33 return window.performance.now(); | |
| 34 else | |
| 35 return new Date().getTime(); | |
| 36 } | |
| 37 | |
| 38 function Timer() { | |
| 39 this.start_ = 0; | |
| 40 this.times_ = []; | |
| 41 } | |
| 42 | |
| 43 Timer.prototype = { | |
| 44 start: function() { | |
| 45 this.start_ = getCurrentTime(); | |
| 46 }, | |
| 47 | |
| 48 stop: function() { | |
| 49 var delta = getCurrentTime() - this.start_; | |
| 50 this.times_.push(delta); | |
| 51 return delta; | |
| 52 }, | |
| 53 | |
| 54 reset: function() { | |
| 55 this.start_ = 0; | |
| 56 this.times_ = []; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 function GenerateUniqueURL(src) { | |
| 61 var ch = src.indexOf('?') >= 0 ? '&' : '?'; | |
| 62 return src + ch + 't=' + (new Date()).getTime(); | |
| 63 } | |
| OLD | NEW |