Home | History | Annotate | Download | only in media
      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
      3 // found in the LICENSE file.
      4 
      5 var QueryString = function() {
      6   // Allows access to query parameters on the URL; e.g., given a URL like:
      7   //    http://<server>/my.html?test=123&bob=123
      8   // Parameters can then be accessed via QueryString.test or QueryString.bob.
      9   var params = {};
     10   // RegEx to split out values by &.
     11   var r = /([^&=]+)=?([^&]*)/g;
     12   // Lambda function for decoding extracted match values. Replaces '+' with
     13   // space so decodeURIComponent functions properly.
     14   function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); }
     15   var match;
     16   while (match = r.exec(window.location.search.substring(1)))
     17     params[d(match[1])] = d(match[2]);
     18   return params;
     19 }();
     20 
     21 function failTest(msg) {
     22   var failMessage = msg;
     23   if (msg instanceof Event)
     24     failMessage = msg.target + '.' + msg.type;
     25   console.log("FAILED TEST: " + msg);
     26   setResultInTitle('FAILED');
     27 }
     28 
     29 var titleChanged = false;
     30 function setResultInTitle(title) {
     31   // If document title is 'ENDED', then update it with new title to possibly
     32   // mark a test as failure.  Otherwise, keep the first title change in place.
     33   if (!titleChanged || document.title.toUpperCase() == 'ENDED')
     34     document.title = title.toUpperCase();
     35   console.log('Set document title to: ' + title + ', updated title: ' +
     36               document.title);
     37   titleChanged = true;
     38 }
     39 
     40 function installTitleEventHandler(element, event) {
     41   element.addEventListener(event, function(e) {
     42     setResultInTitle(event.toString());
     43   }, false);
     44 }
     45 
     46 function convertToArray(input) {
     47   if (Array.isArray(input))
     48     return input;
     49   return [input];
     50 }
     51