OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // | 7 // |
8 | 8 |
9 var QueryString = function () { | 9 var QueryString = function () { |
10 // Allows access to query parameters on the URL; e.g., given a URL like: | 10 // Allows access to query parameters on the URL; e.g., given a URL like: |
11 // | 11 // |
12 // http://<url>/my.html?test=123&bob=123 | 12 // http://<url>/my.html?test=123&bob=123 |
13 // | 13 // |
14 // parameters can now be accessed via QueryString.test or QueryString.bob. | 14 // parameters can now be accessed via QueryString.test or QueryString.bob. |
15 var params = {}; | 15 var params = {}; |
16 | 16 |
17 // RegEx to split out values by &. | 17 // RegEx to split out values by &. |
18 var r = /([^&=]+)=?([^&]*)/g; | 18 var r = /([^&=]+)=?([^&]*)/g; |
19 | 19 |
20 // Lambda function for decoding extracted match values. Replaces '+' with | 20 // Lambda function for decoding extracted match values. Replaces '+' with |
21 // space so decodeURIComponent functions properly. | 21 // space so decodeURIComponent functions properly. |
22 function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); } | 22 function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); } |
23 | 23 |
24 var match; | 24 var match; |
25 while (match = r.exec(window.location.search.substring(1))) | 25 while (match = r.exec(window.location.search.substring(1))) |
26 params[d(match[1])] = d(match[2]); | 26 params[d(match[1])] = d(match[2]); |
27 | 27 |
28 return params; | 28 return params; |
29 } (); | 29 } (); |
30 | |
31 function Timer() { | |
32 this.start_ = 0; | |
DaleCurtis
2012/04/18 18:57:53
Can this just be this.reset()?
shadi
2012/04/19 04:16:59
No, since reset is not defined at this point.
DaleCurtis
2012/04/19 19:42:10
Said no, but code shows you changed it?
shadi
2012/04/20 00:17:46
Actually I don't know how this got uploaded. This
| |
33 this.times_ = []; | |
34 } | |
35 | |
36 Timer.prototype = { | |
37 start: function() { | |
38 this.start_ = new Date().getTime(); | |
39 }, | |
40 | |
41 stop: function() { | |
42 var delta = new Date().getTime() - this.start_; | |
43 this.times_.push(delta); | |
44 return delta; | |
45 }, | |
46 | |
47 reset: function() { | |
48 this.start_ = 0; | |
49 this.times_ = []; | |
50 } | |
51 } | |
52 | |
53 // The purpose of generateSrc() is to return a unique URL based on original src. | |
54 function generateSrc(src) { | |
DaleCurtis
2012/04/18 18:57:53
Better name? GenerateUniqueURL?
shadi
2012/04/19 04:16:59
Done.
| |
55 var ch = src.indexOf('?') >= 0 ? '&' : '?'; | |
56 return src + ch + 't=' + (new Date()).getTime(); | |
57 } | |
OLD | NEW |