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 1752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1763 return; | 1763 return; |
1764 } | 1764 } |
1765 window.console.log('Unexpected message: \'' + data[0] + '\''); | 1765 window.console.log('Unexpected message: \'' + data[0] + '\''); |
1766 embedder.test.fail(); | 1766 embedder.test.fail(); |
1767 }); | 1767 }); |
1768 document.body.appendChild(webview); | 1768 document.body.appendChild(webview); |
1769 } | 1769 } |
1770 | 1770 |
1771 function testPostMessageCommChannel() { | 1771 function testPostMessageCommChannel() { |
1772 var webview = new WebView(); | 1772 var webview = new WebView(); |
| 1773 // Run this test with display:none to verify that postMessage works correctly. |
| 1774 webview.style.display = 'none'; |
1773 webview.src = 'about:blank'; | 1775 webview.src = 'about:blank'; |
1774 webview.addEventListener('loadstop', function(e) { | 1776 webview.addEventListener('loadstop', function(e) { |
| 1777 window.console.log('loadstop'); |
1775 webview.executeScript( | 1778 webview.executeScript( |
1776 {file: 'inject_comm_channel.js'}, | 1779 {file: 'inject_comm_channel.js'}, |
1777 function(results) { | 1780 function(results) { |
1778 window.console.log('The guest script for a two-way comm channel has ' + | 1781 window.console.log('The guest script for a two-way comm channel has ' + |
1779 'been injected into webview.'); | 1782 'been injected into webview.'); |
1780 // Establish a communication channel with the guest. | 1783 // Establish a communication channel with the guest. |
1781 var msg = ['connect']; | 1784 var msg = ['connect']; |
1782 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 1785 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
1783 } | 1786 } |
1784 ); | 1787 ); |
1785 }); | 1788 }); |
| 1789 webview.addEventListener('consolemessage', function(e) { |
| 1790 window.console.log('Guest: "' + e.message + '"'); |
| 1791 }); |
1786 window.addEventListener('message', function(e) { | 1792 window.addEventListener('message', function(e) { |
1787 var data = JSON.parse(e.data); | 1793 var data = JSON.parse(e.data); |
1788 if (data[0] == 'connected') { | 1794 if (data[0] == 'connected') { |
1789 console.log('A communication channel has been established with webview.'); | 1795 console.log('A communication channel has been established with webview.'); |
1790 embedder.test.succeed(); | 1796 embedder.test.succeed(); |
1791 return; | 1797 return; |
1792 } | 1798 } |
1793 console.log('Unexpected message: \'' + data[0] + '\''); | 1799 console.log('Unexpected message: \'' + data[0] + '\''); |
1794 embedder.test.fail(); | 1800 embedder.test.fail(); |
1795 }); | 1801 }); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2143 'testFindAPI_findupdate': testFindAPI, | 2149 'testFindAPI_findupdate': testFindAPI, |
2144 'testLoadDataAPI': testLoadDataAPI | 2150 'testLoadDataAPI': testLoadDataAPI |
2145 }; | 2151 }; |
2146 | 2152 |
2147 onload = function() { | 2153 onload = function() { |
2148 chrome.test.getConfig(function(config) { | 2154 chrome.test.getConfig(function(config) { |
2149 embedder.setUp_(config); | 2155 embedder.setUp_(config); |
2150 chrome.test.sendMessage("Launched"); | 2156 chrome.test.sendMessage("Launched"); |
2151 }); | 2157 }); |
2152 }; | 2158 }; |
OLD | NEW |