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
3 // found in the LICENSE file.
5 // Miscellaneous utility functions for HTML media tests. Loading this script
6 // should not modify the page in any way.
9 var QueryString = function () {
10 // Allows access to query parameters on the URL; e.g., given a URL like:
12 // http://<url>/my.html?test=123&bob=123
14 // parameters can now be accessed via QueryString.test or QueryString.bob.
17 // RegEx to split out values by &.
18 var r = /([^&=]+)=?([^&]*)/g;
20 // Lambda function for decoding extracted match values. Replaces '+' with
21 // space so decodeURIComponent functions properly.
22 function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); }
25 while (match = r.exec(window.location.search.substring(1)))
26 params[d(match[1])] = d(match[2]);
31 function getCurrentTime() {
32 if (window.performance.now)
33 return window.performance.now();
35 return new Date().getTime();
45 this.start_ = getCurrentTime();
49 var delta = getCurrentTime() - this.start_;
50 this.times_.push(delta);
60 function GenerateUniqueURL(src) {
61 var ch = src.indexOf('?') >= 0 ? '&' : '?';
62 return src + ch + 't=' + (new Date()).getTime();