1<!-- 2@license 3Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 4This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 5The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 6The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 7Code distributed by Google as part of the polymer project is also 8subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 9--> 10 11<!DOCTYPE html> 12<html> 13 <head> 14 <meta charset="utf-8"> 15 <title>Base source for injecting into an iframe for tests</title> 16 <script src="../../webcomponentsjs/webcomponents.js"></script> 17 <link rel='import' href='./initialization-cases.html'> 18 </head> 19 <body> 20 <script> 21 window.addEventListener("message", messageReceived, false); 22 23 window.addEventListener('WebComponentsReady', function() { 24 window.parent.postMessage({ 25 'type': 'ready' 26 }, '*'); 27 }); 28 29 var appendBodyReceived = false; 30 function messageReceived(msg) { 31 if (!msg.data) { 32 console.error('got invalid msg?'); 33 } 34 // the parent can (at any time) ask for our URL. 35 if (msg.data.type === 'urlQuery') { 36 msg.source.postMessage({ 37 'type': 'urlQueryResponse', 38 'href': window.location.href, 39 'pathname': window.location.pathname, 40 'hash': window.location.hash, 41 'search': window.location.search 42 }, '*'); 43 } else if (msg.data.type === 'appendBody') { 44 if (appendBodyReceived) { 45 throw new Error('should only receive at most one appendBody call'); 46 } 47 var element = document.createElement(msg.data.tagName); 48 document.body.appendChild(element); 49 appendBodyReceived = true; 50 } 51 } 52 53 window.addEventListener('error', function(e) { 54 window.parent.postMessage({ 55 'type': 'error', 56 'error': e.message 57 }, '*'); 58 }); 59 </script> 60 </body> 61</html> 62