| Index: chrome/test/data/webui/webview_execute_script_test.js
|
| diff --git a/chrome/test/data/webui/webview_execute_script_test.js b/chrome/test/data/webui/webview_execute_script_test.js
|
| deleted file mode 100644
|
| index b59666e6444d37230d3aeb6f7ca375ebd9907379..0000000000000000000000000000000000000000
|
| --- a/chrome/test/data/webui/webview_execute_script_test.js
|
| +++ /dev/null
|
| @@ -1,381 +0,0 @@
|
| -// Copyright 2015 The Chromium Authors. All rights reserved.
|
| -// Use of this source code is governed by a BSD-style license that can be
|
| -// found in the LICENSE file.
|
| -
|
| -function createWebview() {
|
| - var webview = document.createElement('webview');
|
| - document.body.appendChild(webview);
|
| - return webview;
|
| -}
|
| -
|
| -function onGetBackgroundExecuted(results) {
|
| - chrome.send('testResult', [results.length == 1 && results[0] == 'red']);
|
| -};
|
| -
|
| -function testExecuteScriptCode(url) {
|
| - var webview = createWebview();
|
| -
|
| - var onSetBackgroundExecuted = function() {
|
| - webview.executeScript({
|
| - code: 'document.body.style.backgroundColor;'
|
| - }, onGetBackgroundExecuted);
|
| - };
|
| -
|
| - var onLoadStop = function() {
|
| - webview.executeScript({
|
| - code: 'document.body.style.backgroundColor = \'red\';'
|
| - }, onSetBackgroundExecuted);
|
| - };
|
| -
|
| - webview.addEventListener('loadstop', onLoadStop);
|
| - webview.src = url;
|
| -}
|
| -
|
| -function testExecuteScriptCodeFromFile(url) {
|
| - var webview = createWebview();
|
| -
|
| - var onSetBackgroundExecuted = function() {
|
| - webview.executeScript({
|
| - code: 'document.body.style.backgroundColor;'
|
| - }, onGetBackgroundExecuted);
|
| - };
|
| -
|
| - var onLoadStop = function() {
|
| - webview.executeScript({
|
| - file: 'test/webview_execute_script.js'
|
| - }, onSetBackgroundExecuted);
|
| - };
|
| -
|
| - webview.addEventListener('loadstop', onLoadStop);
|
| - webview.src = url;
|
| -}
|
| -
|
| -function testAddContentScript(url) {
|
| - var webview = document.createElement('webview');
|
| -
|
| - console.log("Step 1: call <webview>.addContentScripts.");
|
| - webview.addContentScripts(
|
| - [{"name": 'myrule',
|
| - "matches": ["http://*/empty*"],
|
| - "js": ["test/inject_comm_channel.js", "test/inject_comm_channel_2.js"],
|
| - "run_at": "document_start"}]);
|
| -
|
| - webview.addEventListener('loadstop', function() {
|
| - console.log("Step 2: postMessage to build connection.");
|
| - var msg = ['connect'];
|
| - webview.contentWindow.postMessage(JSON.stringify(msg), '*');
|
| - });
|
| -
|
| - window.addEventListener('message', function(e) {
|
| - var data = JSON.parse(e.data);
|
| - if (data == 'connected') {
|
| - console.log(
|
| - 'Step 3: A communication channel has been established with webview.');
|
| - chrome.send('testResult', [true]);
|
| - return;
|
| - }
|
| - console.log('Unexpected message: \'' + data[0] + '\'');
|
| - chrome.send('testResult', [false]);
|
| - });
|
| -
|
| - webview.src = url;
|
| - document.body.appendChild(webview);
|
| -}
|
| -
|
| -function testAddMultiContentScripts(url) {
|
| - var webview = document.createElement('webview');
|
| -
|
| - console.log("Step 1: call <webview>.addContentScripts(myrule1 & myrule2)");
|
| - webview.addContentScripts(
|
| - [{"name": 'myrule1',
|
| - "matches": ["http://*/empty*"],
|
| - "js": ["test/inject_comm_channel.js"],
|
| - "run_at": "document_start"},
|
| - {"name": 'myrule2',
|
| - "matches": ["http://*/empty*"],
|
| - "js": ["test/inject_comm_channel_2.js"],
|
| - "run_at": "document_start"}]);
|
| -
|
| - webview.addEventListener('loadstop', function() {
|
| - console.log("Step 2: postMessage to build connection.");
|
| - var msg1 = ['connect'];
|
| - webview.contentWindow.postMessage(JSON.stringify(msg1), '*');
|
| - console.log("Step 3: postMessage to build connection to the other script.");
|
| - var msg2 = ['connect_request'];
|
| - webview.contentWindow.postMessage(JSON.stringify(msg2), '*');
|
| - });
|
| -
|
| - var response_1 = false;
|
| - var response_2 = false;
|
| - window.addEventListener('message', function(e) {
|
| - var data = JSON.parse(e.data);
|
| - if (data == 'connected') {
|
| - console.log(
|
| - 'Step 4: A communication channel has been established with webview.');
|
| - response_1 = true;
|
| - if (response_1 && response_2)
|
| - chrome.send('testResult', [true]);
|
| - return;
|
| - } else if (data == 'connected_response') {
|
| - console.log(
|
| - 'Step 5: A communication channel has been established with webview.');
|
| - response_2 = true;
|
| - if (response_1 && response_2)
|
| - chrome.send('testResult', [true]);
|
| - return;
|
| - }
|
| - console.log('!!!!!Unexpected message: \'' + data[0] + '\'');
|
| - chrome.send('testResult', [false]);
|
| - });
|
| -
|
| - webview.src = url;
|
| - document.body.appendChild(webview);
|
| -}
|
| -
|
| -function testAddContentScriptWithSameNameShouldOverwriteTheExistingOne(url) {
|
| - var webview = document.createElement('webview');
|
| -
|
| - console.log("Step 1: call <webview>.addContentScripts(myrule1)");
|
| - webview.addContentScripts(
|
| - [{"name": 'myrule1',
|
| - "matches": ["http://*/empty*"],
|
| - "js": ["test/inject_comm_channel.js"],
|
| - "run_at": "document_start"}]);
|
| - var connect_script_1 = true;
|
| - var connect_script_2 = false;
|
| -
|
| - webview.addEventListener('loadstop', function() {
|
| - if (connect_script_1) {
|
| - var msg1 = ['connect'];
|
| - webview.contentWindow.postMessage(JSON.stringify(msg1), '*');
|
| - connect_script_1 = false;
|
| - }
|
| - if (connect_script_2) {
|
| - var msg2 = ['connect_request'];
|
| - webview.contentWindow.postMessage(JSON.stringify(msg2), '*');
|
| - connect_script_2 = false;
|
| - }
|
| - });
|
| -
|
| - var should_get_response_from_script_1 = true;
|
| - window.addEventListener('message', function(e) {
|
| - var data = JSON.parse(e.data);
|
| - if (data == 'connected') {
|
| - if (should_get_response_from_script_1) {
|
| - console.log(
|
| - 'Step 2: A communication channel has been established with webview.'
|
| - );
|
| - webview.addContentScripts(
|
| - [{"name": 'myrule1',
|
| - "matches": ["http://*/empty*"],
|
| - "js": ["test/inject_comm_channel_2.js"],
|
| - "run_at": "document_start"}]);
|
| - connect_script_2 = true;
|
| - should_get_response_from_script_1 = false;
|
| - webview.src = url;
|
| - } else {
|
| - chrome.send('testResult', [false]);
|
| - }
|
| - return;
|
| - } else if (data == 'connected_response') {
|
| - console.log(
|
| - 'Step 3: Another communication channel has been established ' +
|
| - 'with webview.');
|
| - setTimeout(function() {
|
| - chrome.send('testResult', [true]);
|
| - }, 1000);
|
| - return;
|
| - }
|
| - console.log('Unexpected message: \'' + data[0] + '\'');
|
| - chrome.send('testResult', [false]);
|
| - });
|
| -
|
| - webview.src = url;
|
| - document.body.appendChild(webview);
|
| -}
|
| -
|
| -function testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView(url) {
|
| - var webview1 = document.createElement('webview');
|
| - var webview2 = document.createElement('webview');
|
| -
|
| - console.log("Step 1: call <webview1>.addContentScripts.");
|
| - webview1.addContentScripts(
|
| - [{"name": 'myrule',
|
| - "matches": ["http://*/empty*"],
|
| - "js": ["test/inject_comm_channel.js"],
|
| - "run_at": "document_start"}]);
|
| -
|
| - webview2.addEventListener('loadstop', function() {
|
| - console.log("Step 2: webview2 requests to build communication channel.");
|
| - var msg = ['connect'];
|
| - webview2.contentWindow.postMessage(JSON.stringify(msg), '*');
|
| - setTimeout(function() {
|
| - chrome.send('testResult', [true]);
|
| - }, 2000);
|
| - });
|
| -
|
| - window.addEventListener('message', function(e) {
|
| - var data = JSON.parse(e.data);
|
| - if (data == 'connected') {
|
| - chrome.send('testResult', [false]);
|
| - return;
|
| - }
|
| - console.log('Unexpected message: \'' + data[0] + '\'');
|
| - chrome.send('testResult', [false]);
|
| - });
|
| -
|
| - webview1.src = url;
|
| - webview2.src = url;
|
| - document.body.appendChild(webview1);
|
| - document.body.appendChild(webview2);
|
| -}
|
| -
|
| -function testAddAndRemoveContentScripts(url) {
|
| - var webview = document.createElement('webview');
|
| -
|
| - console.log("Step 1: call <webview>.addContentScripts.");
|
| - webview.addContentScripts(
|
| - [{"name": 'myrule',
|
| - "matches": ["http://*/empty*"],
|
| - "js": ["test/inject_comm_channel.js"],
|
| - "run_at": "document_start"}]);
|
| -
|
| - var count = 0;
|
| - webview.addEventListener('loadstop', function() {
|
| - if (count == 0) {
|
| - console.log('Step 2: post message to build connect.');
|
| - var msg = ['connect'];
|
| - webview.contentWindow.postMessage(JSON.stringify(msg), '*');
|
| - count++;
|
| - } else if (count == 1) {
|
| - console.log(
|
| - 'Step 4: call <webview>.removeContentScripts and navigate.');
|
| - webview.removeContentScripts();
|
| - webview.src = url;
|
| - count++;
|
| - } else if (count == 2) {
|
| - console.log('Step 5: post message to build connect again.');
|
| - var msg = ['connect'];
|
| - webview.contentWindow.postMessage(JSON.stringify(msg), '*');
|
| - setTimeout(function() {
|
| - chrome.send('testResult', [true]);
|
| - }, 2000);
|
| - }
|
| - });
|
| -
|
| - var replyCount = 0;
|
| - window.addEventListener('message', function(e) {
|
| - var data = JSON.parse(e.data);
|
| - if (data[0] == 'connected') {
|
| - console.log(
|
| - 'Step 3: A communication channel has been established with webview.');
|
| - if (replyCount == 0) {
|
| - webview.setAttribute('src', 'about:blank');
|
| - replyCount++;
|
| - return;
|
| - } else if (replyCount == 1) {
|
| - chrome.send('testResult', [false]);
|
| - return;
|
| - }
|
| - }
|
| - console.log('Unexpected message: \'' + data[0] + '\'');
|
| - chrome.send('testResult', [false]);
|
| - });
|
| -
|
| - webview.src = url;
|
| - document.body.appendChild(webview);
|
| -}
|
| -
|
| -function testAddContentScriptsWithNewWindowAPI(url) {
|
| - var webview = document.createElement('webview');
|
| -
|
| - var newwebview;
|
| - webview.addEventListener('newwindow', function(e) {
|
| - e.preventDefault();
|
| - newwebview = document.createElement('webview');
|
| -
|
| - console.log('Step 2: call newwebview.addContentScripts.');
|
| - newwebview.addContentScripts(
|
| - [{"name": 'myrule',
|
| - "matches": ["http://*/guest_from_opener*"],
|
| - "js": ["test/inject_comm_channel.js"],
|
| - "run_at": "document_start"}]);
|
| -
|
| - newwebview.addEventListener('loadstop', function(evt) {
|
| - var msg = ['connect'];
|
| - console.log('Step 4: new webview postmessage to build communication ' +
|
| - 'channel.');
|
| - newwebview.contentWindow.postMessage(JSON.stringify(msg), '*');
|
| - });
|
| -
|
| - document.body.appendChild(newwebview);
|
| - // attach the new window to the new <webview>.
|
| - console.log("Step 3: attaches the new webview.");
|
| - e.window.attach(newwebview);
|
| - });
|
| -
|
| - window.addEventListener('message', function(e) {
|
| - var data = JSON.parse(e.data);
|
| - if (data == 'connected' && e.source == newwebview.contentWindow) {
|
| - console.log('Step 5: a communication channel has been established ' +
|
| - 'with the new webview.');
|
| - chrome.send('testResult', [true]);
|
| - return;
|
| - } else {
|
| - chrome.send('testResult', [false]);
|
| - return;
|
| - }
|
| - console.log('unexpected message: \'' + data[0] + '\'');
|
| - chrome.send('testResult', [false]);
|
| - });
|
| -
|
| - console.log('Step 1: navigates the webview to window open guest URL.');
|
| - webview.setAttribute('src', url);
|
| - document.body.appendChild(webview);
|
| -}
|
| -
|
| -function testContentScriptIsInjectedAfterTerminateAndReloadWebView(url) {
|
| - var webview = document.createElement('webview');
|
| -
|
| - console.log('Step 1: call <webview>.addContentScripts.');
|
| - webview.addContentScripts(
|
| - [{"name": 'myrule',
|
| - "matches": ["http://*/empty*"],
|
| - "js": ["test/inject_comm_channel.js"],
|
| - "run_at": "document_start"}]);
|
| -
|
| - var count = 0;
|
| - webview.addEventListener('loadstop', function() {
|
| - if (count == 0) {
|
| - console.log('Step 2: call webview.terminate().');
|
| - webview.terminate();
|
| - ++count;
|
| - return;
|
| - } else if (count == 1) {
|
| - console.log('Step 4: postMessage to build communication.');
|
| - var msg = ['connect'];
|
| - webview.contentWindow.postMessage(JSON.stringify(msg), '*');
|
| - ++count;
|
| - }
|
| - });
|
| -
|
| - webview.addEventListener('exit', function() {
|
| - console.log('Step 3: call webview.reload().');
|
| - webview.reload();
|
| - });
|
| -
|
| - window.addEventListener('message', function(e) {
|
| - var data = JSON.parse(e.data);
|
| - if (data == 'connected') {
|
| - console.log(
|
| - 'Step 5: A communication channel has been established with webview.');
|
| - chrome.send('testResult', [true]);
|
| - return;
|
| - }
|
| - console.log('Unexpected message: \'' + data[0] + '\'');
|
| - chrome.send('testResult', [false]);
|
| - });
|
| -
|
| - webview.src = url;
|
| - document.body.appendChild(webview);
|
| -}
|
|
|