OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 * Copyright 2013 The Chromium Authors. All rights reserved. Use of this |
| 3 * source code is governed by a BSD-style license that can be found in the |
| 4 * LICENSE file. |
| 5 --> |
| 6 <html> |
| 7 <head> |
| 8 <script type="text/javascript"> |
| 9 // A guest that has an <iframe>. |
| 10 // The <iframe> initially requests geolocation. The embedder keeps the |
| 11 // geolocation permission request hanging (by calling e.preventDefault()), |
| 12 // and the guest unloads to iframe (by setting a new src). The unload |
| 13 // will trigger cancelPermissionRequest. |
| 14 |
| 15 // The window reference of the embedder to send post message reply. |
| 16 var embedderWindowChannel = null; |
| 17 |
| 18 // Url of the iframe's initial src. |
| 19 var g_testName = 'uninitialized'; |
| 20 |
| 21 var notifyEmbedder = function(msg_array) { |
| 22 embedderWindowChannel.postMessage(JSON.stringify(msg_array), '*'); |
| 23 }; |
| 24 |
| 25 var iframeElement; |
| 26 var iframeLoadCount; |
| 27 var iframeOnLoad = function() { |
| 28 console.log('iframeOnLoad'); |
| 29 ++iframeLoadCount; |
| 30 if (iframeLoadCount == 1) { |
| 31 iframeElement.src = |
| 32 'data:text/html,<html><body>' + |
| 33 'Second iframe, this clears first iframe\'s documentElement' + |
| 34 '</body></html>'; |
| 35 } else if (iframeLoadCount == 2) { |
| 36 notifyEmbedder([g_testName, 'PASSED']); |
| 37 } else { |
| 38 notifyEmbedder([g_testName, 'FAILED']); |
| 39 } |
| 40 }; |
| 41 |
| 42 var startTest = function(iframeURL) { |
| 43 iframeElement = document.createElement('iframe'); |
| 44 document.querySelector('#iframe-container').appendChild(iframeElement); |
| 45 iframeLoadCount = 0; |
| 46 iframeElement.onload = iframeOnLoad; |
| 47 iframeElement.src = iframeURL; |
| 48 }; |
| 49 |
| 50 var onPostMessageReceived = function(e) { |
| 51 var data = JSON.parse(e.data); |
| 52 if (data[0] == 'test-cancel-geolocation') { |
| 53 window.console.log('guest: test-cancel-geolocation'); |
| 54 g_testName = data[1]; |
| 55 var iframeURL = data[2]; |
| 56 embedderWindowChannel = e.source; |
| 57 // Start the test once we have |embedderWindowChannel|. |
| 58 startTest(iframeURL); |
| 59 } |
| 60 }; |
| 61 window.addEventListener('message', onPostMessageReceived, false); |
| 62 </script> |
| 63 </head> |
| 64 <body> |
| 65 <div> |
| 66 This is a guest that has an iframe. Iframe requests geolocation. While the |
| 67 permission is being decide, the iframe is unloaded. |
| 68 </div> |
| 69 <div id="iframe-container"></div> |
| 70 <script> |
| 71 console.log('Guest loaded'); |
| 72 </script> |
| 73 </body> |
| 74 </html> |
OLD | NEW |