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.
5 function createWebview() {
6 var webview
= document
.createElement('webview');
7 document
.body
.appendChild(webview
);
11 function onGetBackgroundExecuted(results
) {
12 chrome
.send('testResult', [results
.length
== 1 && results
[0] == 'red']);
15 function testExecuteScriptCode(url
) {
16 var webview
= createWebview();
18 var onSetBackgroundExecuted = function() {
19 webview
.executeScript({
20 code
: 'document.body.style.backgroundColor;'
21 }, onGetBackgroundExecuted
);
24 var onLoadStop = function() {
25 webview
.executeScript({
26 code
: 'document.body.style.backgroundColor = \'red\';'
27 }, onSetBackgroundExecuted
);
30 webview
.addEventListener('loadstop', onLoadStop
);
34 function testExecuteScriptCodeFromFile(url
) {
35 var webview
= createWebview();
37 var onSetBackgroundExecuted = function() {
38 webview
.executeScript({
39 code
: 'document.body.style.backgroundColor;'
40 }, onGetBackgroundExecuted
);
43 var onLoadStop = function() {
44 webview
.executeScript({
45 file
: 'test/webview_execute_script.js'
46 }, onSetBackgroundExecuted
);
49 webview
.addEventListener('loadstop', onLoadStop
);