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 647c3b7762a453e71069aa7327a6917c02828a7e..e8c61661cb3169d79ecdd32eeaa395e5bec98242 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 |
@@ -601,6 +601,38 @@ function testExecuteScript() { |
document.body.appendChild(webview); |
} |
+// This test verifies that the call of executeScript will fail and return null |
+// if the webview has been navigated to another source. |
+function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() { |
+ var webview = document.createElement('webview'); |
+ var step = 1; |
+ var navigationOccur = false; |
+ var newSrc = 'data:text/html,trigger navigation'; |
+ webview.addEventListener('loadstart', function() { |
+ if (step == 1) { |
+ webview.setAttribute('src', newSrc); |
+ navigationOccur = true; |
+ } |
+ ++step; |
+ }); |
+ webview.addEventListener('loadstop', function() { |
+ webview.executeScript( |
+ {code:'document.body.style.backgroundColor = "red";'}, |
+ function(results) { |
+ if (navigationOccur) { |
+ // Expect a null results because the executeScript failed; |
+ // return "red", otherwise. |
+ embedder.test.assertEq(null, results); |
+ embedder.test.succeed(); |
+ } |
+ navigationOccur = false; |
+ } |
+ ); |
+ }); |
+ webview.setAttribute('src', "about:blank"); |
+ document.body.appendChild(webview); |
+} |
+ |
// This test calls terminate() on guest after it has already been |
// terminated. This makes sure we ignore the call gracefully. |
function testTerminateAfterExit() { |
@@ -1480,6 +1512,8 @@ embedder.test.testList = { |
'testPartitionRaisesException': testPartitionRaisesException, |
'testExecuteScriptFail': testExecuteScriptFail, |
'testExecuteScript': testExecuteScript, |
+ 'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged': |
+ testExecuteScriptIsAbortedWhenWebViewSourceIsChanged, |
'testTerminateAfterExit': testTerminateAfterExit, |
'testAssignSrcAfterCrash': testAssignSrcAfterCrash, |
'testNavOnConsecutiveSrcAttributeChanges': |