| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 function createWebview() { | 5 function createWebview() { |
| 6 var webview = document.createElement('webview'); | 6 var webview = document.createElement('webview'); |
| 7 document.body.appendChild(webview); | 7 document.body.appendChild(webview); |
| 8 return webview; | 8 return webview; |
| 9 } | 9 } |
| 10 | 10 |
| 11 function onGetBackgroundExecuted(results) { |
| 12 chrome.send('testResult', [results.length == 1 && results[0] == 'red']); |
| 13 }; |
| 14 |
| 11 function testExecuteScriptCode(url) { | 15 function testExecuteScriptCode(url) { |
| 12 var webview = createWebview(); | 16 var webview = createWebview(); |
| 13 | 17 |
| 14 var onGetBackgroundExecuted = function(results) { | 18 var onSetBackgroundExecuted = function() { |
| 15 chrome.send('testResult', [results.length == 1 && results[0] == 'red']); | 19 webview.executeScript({ |
| 20 code: 'document.body.style.backgroundColor;' |
| 21 }, onGetBackgroundExecuted); |
| 16 }; | 22 }; |
| 17 | 23 |
| 24 var onLoadStop = function() { |
| 25 webview.executeScript({ |
| 26 code: 'document.body.style.backgroundColor = \'red\';' |
| 27 }, onSetBackgroundExecuted); |
| 28 }; |
| 29 |
| 30 webview.addEventListener('loadstop', onLoadStop); |
| 31 webview.src = url; |
| 32 } |
| 33 |
| 34 function testExecuteScriptCodeFromFile(url) { |
| 35 var webview = createWebview(); |
| 36 |
| 18 var onSetBackgroundExecuted = function() { | 37 var onSetBackgroundExecuted = function() { |
| 19 webview.executeScript({ | 38 webview.executeScript({ |
| 20 code: 'document.body.style.backgroundColor;' | 39 code: 'document.body.style.backgroundColor;' |
| 21 }, onGetBackgroundExecuted); | 40 }, onGetBackgroundExecuted); |
| 22 }; | 41 }; |
| 23 | 42 |
| 24 var onLoadStop = function() { | 43 var onLoadStop = function() { |
| 25 webview.executeScript({ | 44 webview.executeScript({ |
| 26 code: 'document.body.style.backgroundColor = \'red\';' | 45 file: 'test/webview_execute_script.js' |
| 27 }, onSetBackgroundExecuted); | 46 }, onSetBackgroundExecuted); |
| 28 }; | 47 }; |
| 29 | 48 |
| 30 webview.addEventListener('loadstop', onLoadStop); | 49 webview.addEventListener('loadstop', onLoadStop); |
| 31 webview.src = url; | 50 webview.src = url; |
| 32 } | 51 } |
| OLD | NEW |