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

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

Issue 959413003: Implement <webview>.addContentScript/removeContentScript API [1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a test. Created 5 years, 9 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 fbb4623855ec8b6c8c70fad26808dd71161f15d3..6980f512834036984ffedc64ae4a223e3e5d5593 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
@@ -749,6 +749,55 @@ function testPartitionRemovalAfterNavigationFails() {
webview.setAttribute('src', 'data:text/html,<html><body>guest</body></html>');
}
+function testAddAndRemoveContentScripts() {
+ var webview = document.createElement('webview');
+
+ var count = 0;
+ webview.addEventListener('loadstop', function() {
+ if (count == 0) {
+ webview.addContentScripts(
+ [{"name": 'myrule',
+ "matches": ["http://*/extensions/*"],
+ "js": ["simple_script.js"]}],
+ function() {
+ window.console.log("Step 1: addContentScripts is called.");
+ webview.src = embedder.emptyGuestURL;
+ ++count;
+ });
+ } else if (count == 1) {
+ webview.executeScript(
+ {code: 'document.body.style.backgroundColor;'},
+ function(results) {
+ embedder.test.assertEq(1, results.length);
+ embedder.test.assertEq('red', results[0]);
+ window.console.log(
+ "Step 2: content scripts are injected during navigation.");
+ webview.src = "about:blank";
+ ++count;
+ });
+ } else if (count == 2) {
+ webview.removeContentScripts(
+ function() {
+ window.console.log("Step 3: removeContentScripts is called.");
+ webview.src = embedder.emptyGuestURL;
+ ++count;
+ });
+ } else if (count == 3) {
+ webview.executeScript(
+ {code: 'document.body.style.backgroundColor;'},
+ function(results) {
+ embedder.test.assertEq(1, results.length);
+ embedder.test.assertEq('', results[0]);
+ window.console.log(
+ "Step 4: content scripts are successfully removed.");
+ embedder.test.succeed();
+ });
+ }
+ });
+ webview.setAttribute('src', 'about:blank');
+ document.body.appendChild(webview);
+}
+
function testExecuteScriptFail() {
var webview = document.createElement('webview');
document.body.appendChild(webview);
@@ -2056,6 +2105,7 @@ embedder.test.testList = {
'testPartitionChangeAfterNavigation': testPartitionChangeAfterNavigation,
'testPartitionRemovalAfterNavigationFails':
testPartitionRemovalAfterNavigationFails,
+ 'testAddAndRemoveContentScripts': testAddAndRemoveContentScripts,
'testExecuteScriptFail': testExecuteScriptFail,
'testExecuteScript': testExecuteScript,
'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged':

Powered by Google App Engine
This is Rietveld 408576698