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

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

Issue 843953003: Fixed testExecuteScriptIsAbortedWhenWebViewSourceIsChanged raciness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « no previous file | extensions/test/data/web_view/apitest/main.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 58c18745c39ed38d1d2c64979f8a533632381e67..2f0181a2cdaa514afde138930bdc5aaa0c4b28a5 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
@@ -808,35 +808,42 @@ 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.
+// This test verifies that the call to executeScript will fail and return null
+// if the webview has been navigated between the time the call was made and the
+// time it arrives in the guest process.
function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() {
var webview = document.createElement('webview');
- var initial = true;
- var navigationOccur = false;
- var newSrc = 'data:text/html,trigger navigation';
- webview.addEventListener('loadstart', function() {
- if (initial) {
- webview.setAttribute('src', newSrc);
- navigationOccur = true;
- }
- initial = false;
- });
- 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.
+ webview.addEventListener('loadstop', function onLoadStop(e) {
+ window.console.log('2. Inject script to trigger a guest-initiated ' +
+ 'navigation.');
+ var navUrl = 'data:text/html,trigger nav';
+ webview.executeScript({
+ code: 'window.location.href = "' + navUrl + '";'
+ });
+
+ window.console.log('3. Listening for the load that will be started as a ' +
+ 'result of 2.');
+ webview.addEventListener('loadstart', function onLoadStart(e) {
+ embedder.test.assertEq('about:blank', webview.src);
+ window.console.log('4. Attempting to inject script into about:blank. ' +
+ 'This is expected to fail.');
+ webview.executeScript(
+ { code: 'document.body.style.backgroundColor = "red";' },
+ function(results) {
+ window.console.log(
+ '5. Verify that executeScript has, indeed, failed.');
embedder.test.assertEq(null, results);
+ embedder.test.assertEq(navUrl, webview.src);
embedder.test.succeed();
}
- navigationOccur = false;
- }
- );
+ );
+ webview.removeEventListener('loadstart', onLoadStart);
+ });
+ webview.removeEventListener('loadstop', onLoadStop);
});
- webview.setAttribute('src', "about:blank");
+
+ window.console.log('1. Performing initial navigation.');
+ webview.setAttribute('src', 'about:blank');
document.body.appendChild(webview);
}
« no previous file with comments | « no previous file | extensions/test/data/web_view/apitest/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698