1<!doctype html> 2<!-- 3@license 4Copyright (c) 2016 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.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 <link rel="import" href="../iron-location.html"> 22</head> 23<body> 24 <dom-module id="integration-element"> 25 <template> 26 <iron-location 27 id="location" 28 path="{{path}}" 29 query="{{query}}" 30 hash="{{hash}}"> 31 </iron-location> 32 <iron-query-params 33 id="queryParams" 34 params-string="{{query}}" 35 params-object="{{queryParams}}"> 36 </iron-query-params> 37 </template> 38 <script> 39 HTMLImports.whenReady(function() { 40 Polymer({ 41 is: 'integration-element' 42 }); 43 }); 44 </script> 45 </dom-module> 46 47 <test-fixture id="Integration"> 48 <template> 49 <integration-element></integration-element> 50 </template> 51 </test-fixture> 52 53 <script> 54 'use strict'; 55 56 suite('Integration tests', function () { 57 58 var integration; 59 var ironLocation; 60 var ironQueryParams; 61 62 setup(function() { 63 integration = fixture('Integration'); 64 ironLocation = integration.$.location; 65 ironQueryParams = integration.$.queryParams; 66 }); 67 68 test('propagations from location to iqp', function() { 69 var queryEncodingExamples = { 70 'foo': '?foo', 71 '': '', 72 'foo bar': '?foo%20bar', 73 'foo#bar': '?foo%23bar', 74 'foo?bar': '?foo?bar', 75 '/foo\'bar\'baz': ['?/foo%27bar%27baz', '?/foo\'bar\'baz'], 76 'foo/bar/baz': '?foo/bar/baz' 77 }; 78 for (var plainTextQuery in queryEncodingExamples) { 79 var encodedQueries = queryEncodingExamples[plainTextQuery]; 80 var ironLocationQuery = encodedQueries; 81 if (typeof encodedQueries === 'string') { 82 encodedQueries = [encodedQueries]; 83 ironLocationQuery = [ironLocationQuery.substring(1)]; 84 } else { 85 ironLocationQuery = ironLocationQuery.map(function(value) { 86 return value.substring(1); 87 }); 88 } 89 90 ironLocation.query = plainTextQuery; 91 expect(encodedQueries).to.contain(window.location.search); 92 expect(ironLocationQuery).to.contain(ironLocation.query); 93 expect(ironLocationQuery).to.contain(ironQueryParams.paramsString); 94 if (plainTextQuery) { 95 expect('').to.be.equal(ironQueryParams.paramsObject[plainTextQuery]) 96 } else { 97 expect(ironQueryParams.paramsObject[plainTextQuery]).to.be.undefined; 98 } 99 } 100 }); 101 102 test('propagations from iqp to location', function() { 103 var queryEncodingExamples = { 104 'foo': '?foo', 105 '': '', 106 'foo bar': '?foo%20bar', 107 'foo#bar': '?foo%23bar', 108 'foo?bar': '?foo?bar', 109 '/foo\'bar\'baz': ['?/foo%27bar%27baz', '?/foo\'bar\'baz'], 110 'foo/bar/baz': '?foo/bar/baz' 111 }; 112 for (var plainTextQuery in queryEncodingExamples) { 113 var encodedQueries = queryEncodingExamples[plainTextQuery]; 114 var ironLocationQuery = encodedQueries; 115 if (typeof encodedQueries === 'string') { 116 encodedQueries = [encodedQueries]; 117 ironLocationQuery = [ironLocationQuery.substring(1)]; 118 } else { 119 ironLocationQuery = ironLocationQuery.map(function(value) { 120 return value.substring(1); 121 }); 122 } 123 124 var newParamsObject = {}; 125 newParamsObject[plainTextQuery] = ''; 126 127 ironQueryParams.paramsObject = newParamsObject; 128 expect(encodedQueries).to.contain(window.location.search); 129 expect(ironLocationQuery).to.contain(ironLocation.query); 130 } 131 }); 132 }); 133 134 </script> 135</body> 136