Home | History | Annotate | Download | only in static
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright 2015 The Chromium Authors. All rights reserved.
      4 Use of this source code is governed by a BSD-style license that can be
      5 found in the LICENSE file.
      6 -->
      7 
      8 <link rel="import" href="/tracing/core/test_utils.html">
      9 
     10 <link rel="import" href="/dashboard/static/uri.html">
     11 
     12 <script>
     13 'use strict';
     14 
     15 tr.b.unittest.testSuite(function() {
     16 
     17   var testOptions = {
     18     setUp: function() {
     19       window.originalGetQueryString_ = uri.getQueryString;
     20     },
     21 
     22     tearDown: function() {
     23       uri.getQueryString = window.originalGetQueryString_;
     24     }
     25   };
     26 
     27   test('getCurrentPathWithParams encodes value', function() {
     28     assert.equal(
     29         window.location.pathname + '?key=some%20value',
     30         uri.getCurrentPathWithParams({'key': 'some value'}));
     31   }, testOptions);
     32 
     33   test('getParameter at start', function() {
     34     uri.getQueryString = function() {
     35       return '?foo=bar&x=y';
     36     };
     37     assert.equal('bar', uri.getParameter('foo'));
     38   }, testOptions);
     39 
     40   test('getParameter not at start', function() {
     41     uri.getQueryString = function() {
     42       return '?foo=bar&x=y';
     43     };
     44     assert.equal('y', uri.getParameter('x'));
     45   }, testOptions);
     46 
     47   test('getParameter decodes hex sequences and plus signs', function() {
     48     uri.getQueryString = function() {
     49       return '?foo=bar%2C+baz';
     50     };
     51     assert.equal('bar, baz', uri.getParameter('foo'));
     52   }, testOptions);
     53 
     54   test('getAllParameters basic', function() {
     55     uri.getQueryString = function() {
     56       return '?a=1&b=2';
     57     };
     58     assert.deepEqual({'a': '1', 'b': '2'}, uri.getAllParameters());
     59   }, testOptions);
     60 
     61   test('getAllParameters decodes hex sequences and plus signs', function() {
     62     uri.getQueryString = function() {
     63       return '?a=%3A%3A&b=x+y';
     64     };
     65     assert.deepEqual({'a': '::', 'b': 'x y'}, uri.getAllParameters());
     66   }, testOptions);
     67 
     68 });
     69 </script>
     70