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': |