1<!doctype html> 2<!-- 3@license 4Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 5This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 6The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 7The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 8Code distributed by Google as part of the polymer project is also 9subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 10--> 11<html> 12<head> 13 <title>iron-location</title> 14 15 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> 16 <script src="../../web-component-tester/browser.js"></script> 17 18 <link rel="import" href="../../polymer/polymer.html"> 19 <link rel="import" href="../../promise-polyfill/promise-polyfill.html"> 20 <link rel="import" href="../iron-query-params.html"> 21</head> 22<body> 23 24 <test-fixture id="BasicQueryParams"> 25 <template> 26 <iron-query-params></iron-query-params> 27 </template> 28 </test-fixture> 29 30 <script> 31 'use strict'; 32 33 suite('<iron-query-params>', function () { 34 35 var paramsElem; 36 setup(function() { 37 paramsElem = fixture('BasicQueryParams'); 38 }); 39 40 test('basic functionality with ?key=value params', function() { 41 // Check initialization 42 expect(paramsElem.paramsString).to.be.eq(''); 43 expect(paramsElem.paramsObject).to.deep.eq({}); 44 45 // Check the mapping from paramsString to paramsObject. 46 paramsElem.paramsString = 'greeting=hello&target=world'; 47 expect(paramsElem.paramsObject).to.deep.equal( 48 {greeting: 'hello', target: 'world'}); 49 50 // Check the mapping from paramsObject back to paramsString. 51 paramsElem.set('paramsObject.another', 'key'); 52 expect(paramsElem.paramsString).to.be.equal( 53 'greeting=hello&target=world&another=key'); 54 }); 55 test('encoding of params', function() { 56 var mappings = [ 57 { 58 string: 'a=b', 59 object: {'a': 'b'} 60 }, 61 { 62 string: 'debug&ok', 63 object: {'debug': '', 'ok': ''} 64 }, 65 { 66 string: 'monster%20kid%3A=%F0%9F%98%BF"es=%27%27', 67 object: {'monster kid:': '', 'quotes': '\'\''} 68 }, 69 { 70 string: 'yes%2C%20ok?%20what%20is%20up%20with%20%CB%9Athiiis%CB%9A=%E2%98%83', 71 object: {'yes, ok? what is up with ˚thiiis˚': '☃'} 72 }, 73 ]; 74 75 mappings.forEach(function(mapping) { 76 // Clear 77 paramsElem.paramsObject = {}; 78 expect(paramsElem.paramsString).to.be.equal(''); 79 80 // Test going from string to object 81 paramsElem.paramsString = mapping.string; 82 expect(paramsElem.paramsObject).to.deep.equal(mapping.object); 83 84 // Clear again. 85 paramsElem.paramsObject = {}; 86 expect(paramsElem.paramsString).to.be.equal(''); 87 88 // Test going from object to string 89 paramsElem.paramsObject = mapping.object; 90 expect(paramsElem.paramsString).to.be.equal(mapping.string); 91 }); 92 }); 93 test('query strings with alternative encodings', function() { 94 // Check the mapping for querystrings with + instead of %20. 95 paramsElem.paramsString = 'key=value+with+spaces'; 96 expect(paramsElem.paramsObject).to.deep.equal( 97 {key: 'value with spaces'}); 98 }); 99 }); 100 101 </script> 102</body> 103