OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var webview = null; |
| 6 |
| 7 var LOG = function(msg) { |
| 8 window.console.log(msg); |
| 9 }; |
| 10 |
| 11 var startTest = function(guestURL) { |
| 12 window.onmessage = onMessge; |
| 13 chrome.test.sendMessage('guest-loaded'); |
| 14 webview = document.getElementById('webview'); |
| 15 webview.onloadstop = onWebviewLoaded; |
| 16 webview.onconsolemessage = function(e) { LOG('[Guest]: ' + e.message); }; |
| 17 |
| 18 webview.setAttribute('src', guestURL); |
| 19 }; |
| 20 |
| 21 var onWebviewLoaded = function(event) { |
| 22 window.console.log('onWebviewLoaded'); |
| 23 webview.contentWindow.postMessage(JSON.stringify(['ping']), '*'); |
| 24 }; |
| 25 |
| 26 var onMessge = function(e) { |
| 27 var data = JSON.parse(e.data); |
| 28 if (data.length != 1 && data[0] !== 'pong') { |
| 29 chrome.test.fail(); |
| 30 } else { |
| 31 chrome.test.succeed(); |
| 32 } |
| 33 }; |
| 34 |
| 35 chrome.test.getConfig(function(config) { |
| 36 chrome.test.runTests([ |
| 37 function postMessage() { |
| 38 var guestURL = 'http://localhost:' + config.testServer.port + |
| 39 '/extensions/platform_apps/web_view/post_message/guest.html'; |
| 40 LOG('guestURL: ' + guestURL); |
| 41 document.querySelector('#webview-tag-container').innerHTML = |
| 42 '<webview id="webview"></webview>'; |
| 43 startTest(guestURL); |
| 44 }]); |
| 45 }); |
OLD | NEW |