Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5125)

Unified Diff: chrome/test/data/extensions/platform_apps/web_view/shim/main.js

Issue 1058113002: Implement <webview>.addContentScript/removeContentScript API [3] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webui_api_1
Patch Set: Rebase and replace \" by \'. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/platform_apps/web_view/shim/main.js
diff --git a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
index 9f86a2bbff6a422a666b40a7cf94a9fcd2b575fa..60a7250aa4970e19c855de252578d3dba2824b39 100644
--- a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
+++ b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
@@ -762,12 +762,12 @@ function testPartitionRemovalAfterNavigationFails() {
function testAddContentScript() {
var webview = document.createElement('webview');
- console.log("Step 1: call <webview>.addContentScripts.");
+ console.log('Step 1: call <webview>.addContentScripts.');
webview.addContentScripts(
[{"name": 'myrule',
- "matches": ["http://*/extensions/*"],
- "js": ["inject_comm_channel.js"],
- "run_at": "document_start"}]);
+ "matches": ['http://*/extensions/*'],
+ "js": ['inject_comm_channel.js'],
+ "run_at": 'document_start'}]);
webview.addEventListener('loadstop', function() {
var msg = [request_to_comm_channel_1];
@@ -796,16 +796,16 @@ function testAddContentScript() {
function testAddMultipleContentScripts() {
var webview = document.createElement('webview');
- console.log("Step 1: call <webview>.addContentScripts(myrule1 & myrule2)");
+ console.log('Step 1: call <webview>.addContentScripts(myrule1 & myrule2)');
webview.addContentScripts(
[{"name": 'myrule1',
- "matches": ["http://*/extensions/*"],
- "js": ["inject_comm_channel.js"],
- "run_at": "document_start"},
+ "matches": ['http://*/extensions/*'],
+ "js": ['inject_comm_channel.js'],
+ "run_at": 'document_start'},
{"name": 'myrule2',
- "matches": ["http://*/extensions/*"],
- "js": ["inject_comm_channel_2.js"],
- "run_at": "document_start"}]);
+ "matches": ['http://*/extensions/*'],
+ "js": ['inject_comm_channel_2.js'],
+ "run_at": 'document_start'}]);
webview.addEventListener('loadstop', function() {
var msg1 = [request_to_comm_channel_1];
@@ -849,12 +849,12 @@ function testAddMultipleContentScripts() {
function testAddContentScriptWithSameNameShouldOverwriteTheExistingOne() {
var webview = document.createElement('webview');
- console.log("Step 1: call <webview>.addContentScripts(myrule1)");
+ console.log('Step 1: call <webview>.addContentScripts(myrule1)');
webview.addContentScripts(
[{"name": 'myrule1',
- "matches": ["http://*/extensions/*"],
- "js": ["inject_comm_channel.js"],
- "run_at": "document_start"}]);
+ "matches": ['http://*/extensions/*'],
+ "js": ['inject_comm_channel.js'],
+ "run_at": 'document_start'}]);
var connect_script_1 = true;
var connect_script_2 = false;
@@ -881,9 +881,9 @@ function testAddContentScriptWithSameNameShouldOverwriteTheExistingOne() {
);
webview.addContentScripts(
[{"name": 'myrule1',
- "matches": ["http://*/extensions/*"],
- "js": ["inject_comm_channel_2.js"],
- "run_at": "document_start"}]);
+ "matches": ['http://*/extensions/*'],
+ "js": ['inject_comm_channel_2.js'],
+ "run_at": 'document_start'}]);
connect_script_2 = true;
should_get_response_from_script_1 = false;
webview.src = embedder.emptyGuestURL;
@@ -915,15 +915,15 @@ function testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView() {
var webview1 = document.createElement('webview');
var webview2 = document.createElement('webview');
- console.log("Step 1: call <webview1>.addContentScripts.");
+ console.log('Step 1: call <webview1>.addContentScripts.');
webview1.addContentScripts(
[{"name": 'myrule',
- "matches": ["http://*/extensions/*"],
- "js": ["inject_comm_channel.js"],
- "run_at": "document_start"}]);
+ "matches": ['http://*/extensions/*'],
+ "js": ['inject_comm_channel.js'],
+ "run_at": 'document_start'}]);
webview2.addEventListener('loadstop', function() {
- console.log("Step 2: webview2 requests to build communication channel.");
+ console.log('Step 2: webview2 requests to build communication channel.');
var msg = [request_to_comm_channel_1];
webview2.contentWindow.postMessage(JSON.stringify(msg), '*');
setTimeout(function() {
@@ -956,12 +956,12 @@ function testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView() {
function testAddAndRemoveContentScripts() {
var webview = document.createElement('webview');
- console.log("Step 1: call <webview>.addContentScripts.");
+ console.log('Step 1: call <webview>.addContentScripts.');
webview.addContentScripts(
[{"name": 'myrule',
- "matches": ["http://*/extensions/*"],
- "js": ["inject_comm_channel.js"],
- "run_at": "document_start"}]);
+ "matches": ['http://*/extensions/*'],
+ "js": ['inject_comm_channel.js'],
+ "run_at": 'document_start'}]);
var count = 0;
webview.addEventListener('loadstop', function() {
@@ -1022,9 +1022,9 @@ function testAddContentScriptsWithNewWindowAPI() {
console.log('Step 2: call newwebview.addContentScripts.');
newwebview.addContentScripts(
[{"name": 'myrule',
- "matches": ["http://*/extensions/*"],
- "js": ["inject_comm_channel.js"],
- "run_at": "document_start"}]);
+ "matches": ['http://*/extensions/*'],
+ "js": ['inject_comm_channel.js'],
+ "run_at": 'document_start'}]);
newwebview.addEventListener('loadstop', function(evt) {
var msg = [request_to_comm_channel_1];
@@ -1035,7 +1035,7 @@ function testAddContentScriptsWithNewWindowAPI() {
document.body.appendChild(newwebview);
// attach the new window to the new <webview>.
- console.log("Step 3: attaches the new webview.");
+ console.log('Step 3: attaches the new webview.');
e.window.attach(newwebview);
});
@@ -1068,9 +1068,9 @@ function testContentScriptIsInjectedAfterTerminateAndReloadWebView() {
console.log('Step 1: call <webview>.addContentScripts.');
webview.addContentScripts(
[{"name": 'myrule',
- "matches": ["http://*/extensions/*"],
- "js": ["inject_comm_channel.js"],
- "run_at": "document_start"}]);
+ "matches": ['http://*/extensions/*'],
+ "js": ['inject_comm_channel.js'],
+ "run_at": 'document_start'}]);
var count = 0;
webview.addEventListener('loadstop', function() {
@@ -1116,9 +1116,9 @@ function testContentScriptExistsAsLongAsWebViewTagExists() {
console.log('Step 1: call <webview>.addContentScripts.');
webview.addContentScripts(
[{"name": 'myrule',
- "matches": ["http://*/extensions/*"],
- "js": ["simple_script.js"],
- "run_at": "document_end"}]);
+ "matches": ['http://*/extensions/*'],
+ "js": ['simple_script.js'],
+ "run_at": 'document_end'}]);
var count = 0;
webview.addEventListener('loadstop', function() {
@@ -1154,6 +1154,31 @@ function testContentScriptExistsAsLongAsWebViewTagExists() {
document.body.appendChild(webview);
}
+function testAddContentScriptWithCode() {
+ var webview = document.createElement('webview');
+
+ console.log('Step 1: call <webview>.addContentScripts.');
+ webview.addContentScripts(
+ [{"name": 'myrule',
+ "matches": ['http://*/extensions/*'],
+ "code": 'document.body.style.backgroundColor = \'red\';',
+ "run_at": 'document_end'}]);
+
+ webview.addEventListener('loadstop', function() {
+ console.log('Step 2: call webview.executeScript() to check result.')
+ webview.executeScript({
+ code: 'document.body.style.backgroundColor;'},
+ function(results) {
+ embedder.test.assertEq(1, results.length);
+ embedder.test.assertEq('red', results[0]);
+ embedder.test.succeed();
+ });
+ });
+
+ webview.src = embedder.emptyGuestURL;
+ document.body.appendChild(webview);
+}
+
function testExecuteScriptFail() {
var webview = document.createElement('webview');
document.body.appendChild(webview);
@@ -2647,6 +2672,7 @@ embedder.test.testList = {
testContentScriptIsInjectedAfterTerminateAndReloadWebView,
'testContentScriptExistsAsLongAsWebViewTagExists':
testContentScriptExistsAsLongAsWebViewTagExists,
+ 'testAddContentScriptWithCode': testAddContentScriptWithCode,
'testExecuteScriptFail': testExecuteScriptFail,
'testExecuteScript': testExecuteScript,
'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged':

Powered by Google App Engine
This is Rietveld 408576698