OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var util = {}; | 5 var util = {}; |
6 var embedder = {}; | 6 var embedder = {}; |
7 embedder.baseGuestURL = ''; | 7 embedder.baseGuestURL = ''; |
8 embedder.emptyGuestURL = ''; | 8 embedder.emptyGuestURL = ''; |
9 embedder.windowOpenGuestURL = ''; | 9 embedder.windowOpenGuestURL = ''; |
10 embedder.noReferrerGuestURL = ''; | 10 embedder.noReferrerGuestURL = ''; |
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 return; | 1731 return; |
1732 } | 1732 } |
1733 window.console.log('Unexpected message: \'' + data[0] + '\''); | 1733 window.console.log('Unexpected message: \'' + data[0] + '\''); |
1734 embedder.test.fail(); | 1734 embedder.test.fail(); |
1735 }); | 1735 }); |
1736 document.body.appendChild(webview); | 1736 document.body.appendChild(webview); |
1737 } | 1737 } |
1738 | 1738 |
1739 function testPostMessageCommChannel() { | 1739 function testPostMessageCommChannel() { |
1740 var webview = new WebView(); | 1740 var webview = new WebView(); |
| 1741 // Run this test with display:none to verify that postMessage works correctly. |
| 1742 webview.style.display = 'none'; |
1741 webview.src = 'about:blank'; | 1743 webview.src = 'about:blank'; |
1742 webview.addEventListener('loadstop', function(e) { | 1744 webview.addEventListener('loadstop', function(e) { |
| 1745 window.console.log('loadstop'); |
1743 webview.executeScript( | 1746 webview.executeScript( |
1744 {file: 'inject_comm_channel.js'}, | 1747 {file: 'inject_comm_channel.js'}, |
1745 function(results) { | 1748 function(results) { |
1746 window.console.log('The guest script for a two-way comm channel has ' + | 1749 window.console.log('The guest script for a two-way comm channel has ' + |
1747 'been injected into webview.'); | 1750 'been injected into webview.'); |
1748 // Establish a communication channel with the guest. | 1751 // Establish a communication channel with the guest. |
1749 var msg = ['connect']; | 1752 var msg = ['connect']; |
1750 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 1753 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
1751 } | 1754 } |
1752 ); | 1755 ); |
1753 }); | 1756 }); |
| 1757 webview.addEventListener('consolemessage', function(e) { |
| 1758 window.console.log('Guest: "' + e.message + '"'); |
| 1759 }); |
1754 window.addEventListener('message', function(e) { | 1760 window.addEventListener('message', function(e) { |
1755 var data = JSON.parse(e.data); | 1761 var data = JSON.parse(e.data); |
1756 if (data[0] == 'connected') { | 1762 if (data[0] == 'connected') { |
1757 console.log('A communication channel has been established with webview.'); | 1763 console.log('A communication channel has been established with webview.'); |
1758 embedder.test.succeed(); | 1764 embedder.test.succeed(); |
1759 return; | 1765 return; |
1760 } | 1766 } |
1761 console.log('Unexpected message: \'' + data[0] + '\''); | 1767 console.log('Unexpected message: \'' + data[0] + '\''); |
1762 embedder.test.fail(); | 1768 embedder.test.fail(); |
1763 }); | 1769 }); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2154 'testLoadDataAPI': testLoadDataAPI, | 2160 'testLoadDataAPI': testLoadDataAPI, |
2155 'testResizeEvents': testResizeEvents | 2161 'testResizeEvents': testResizeEvents |
2156 }; | 2162 }; |
2157 | 2163 |
2158 onload = function() { | 2164 onload = function() { |
2159 chrome.test.getConfig(function(config) { | 2165 chrome.test.getConfig(function(config) { |
2160 embedder.setUp_(config); | 2166 embedder.setUp_(config); |
2161 chrome.test.sendMessage("Launched"); | 2167 chrome.test.sendMessage("Launched"); |
2162 }); | 2168 }); |
2163 }; | 2169 }; |
OLD | NEW |