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

Unified Diff: chrome/test/data/extensions/platform_apps/web_view/newwindow/embedder.js

Issue 558813002: <webview>: Fix an issue with destroying an opener that has unattached guests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tests for attach/discard call after opener destruction Created 6 years, 3 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 | « chrome/renderer/resources/extensions/web_view_events.js ('k') | no next file » | 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/newwindow/embedder.js
diff --git a/chrome/test/data/extensions/platform_apps/web_view/newwindow/embedder.js b/chrome/test/data/extensions/platform_apps/web_view/newwindow/embedder.js
index bded587295d7389ff7126b0adfc952c8f4a3dfbd..d29a43570b7a078d289d6ae082681509e6de4fb4 100644
--- a/chrome/test/data/extensions/platform_apps/web_view/newwindow/embedder.js
+++ b/chrome/test/data/extensions/platform_apps/web_view/newwindow/embedder.js
@@ -200,21 +200,21 @@ function testNewWindowNameTakesPrecedence() {
webViewName, guestName, partitionName, expectedName);
}
-function testWebViewNameTakesPrecedence() {
+function testNewWindowWebViewNameTakesPrecedence() {
var webViewName = 'foo';
var guestName = '';
var partitionName = 'persist:foobar';
var expectedName = webViewName;
- testNewWindowName('testWebViewNameTakesPrecedence',
+ testNewWindowName('testNewWindowWebViewNameTakesPrecedence',
webViewName, guestName, partitionName, expectedName);
}
-function testNoName() {
+function testNewWindowNoName() {
var webViewName = '';
var guestName = '';
var partitionName = '';
var expectedName = '';
- testNewWindowName('testNoName',
+ testNewWindowName('testNewWindowNoName',
webViewName, guestName, partitionName, expectedName);
}
@@ -235,6 +235,35 @@ function testNewWindowRedirect() {
webViewName, guestName, partitionName, expectedName);
}
+// Tests that we fail gracefully if we try to attach() a <webview> on a
+// newwindow event after the opener has been destroyed.
+function testNewWindowAttachAfterOpenerDestroyed() {
+ var testName = 'testNewWindowAttachAfterOpenerDestroyed';
+ var webview = embedder.setUpGuest_('foobar');
+
+ var onNewWindow = function(e) {
+ embedder.assertCorrectEvent_(e, '');
+
+ // Remove the opener.
+ webview.parentNode.removeChild(webview);
+ // Pass in a timeout so we ensure the newwindow disposal codepath
+ // works properly.
+ //window.setTimeout(function() { embedder.test.succeed(); }, 0);
Fady Samuel 2014/09/09 23:01:34 Delete this line?
lazyboy 2014/09/09 23:18:36 Done.
+ window.setTimeout(function() {
+ // At this point the opener <webview> is gone.
+ // Trying to discard() will fail silencly.
Fady Samuel 2014/09/09 23:01:33 s/discard/attach s/silencly/silently.
lazyboy 2014/09/09 23:18:36 Done.
+ e.window.attach(document.createElement('webview'));
+ window.setTimeout(function() { embedder.test.succeed(); });
+ }, 0);
+
+ e.preventDefault();
+ };
+ webview.addEventListener('newwindow', onNewWindow);
+
+ // Load a new window with the given name.
+ embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
+}
+
function testNewWindowClose() {
var testName = 'testNewWindowClose';
var webview = embedder.setUpGuest_('foobar');
@@ -291,7 +320,36 @@ function testNewWindowDeferredAttachment() {
// Load a new window with the given name.
embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
-};
+}
+
+// Tests that we fail gracefully if we try to discard() a <webview> on a
+// newwindow event after the opener has been destroyed.
+function testNewWindowDiscardAfterOpenerDestroyed() {
+ var testName = 'testNewWindowDiscardAfterOpenerDestroyed';
+ var webview = embedder.setUpGuest_('foobar');
+
+ var onNewWindow = function(e) {
+ embedder.assertCorrectEvent_(e, '');
+
+ // Remove the opener.
+ webview.parentNode.removeChild(webview);
+ // Pass in a timeout so we ensure the newwindow disposal codepath
+ // works properly.
+ //window.setTimeout(function() { embedder.test.succeed(); }, 0);
Fady Samuel 2014/09/09 23:01:33 Remove this line?
lazyboy 2014/09/09 23:18:36 Done.
+ window.setTimeout(function() {
+ // At this point the opener <webview> is gone.
+ // Trying to discard() will fail silencly.
Fady Samuel 2014/09/09 23:01:34 s/silency/silently
+ e.window.discard();
+ window.setTimeout(function() { embedder.test.succeed(); });
+ }, 0);
+
+ e.preventDefault();
+ };
+ webview.addEventListener('newwindow', onNewWindow);
+
+ // Load a new window with the given name.
+ embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
+}
function testNewWindowExecuteScript() {
var testName = 'testNewWindowExecuteScript';
@@ -333,6 +391,30 @@ function testNewWindowOpenInNewTab() {
webview.src = embedder.guestWithLinkURL;
}
+// Tests that if opener <webview> is gone with unattached guest, we
+// don't see any error.
+// This test also makes sure we destroy the unattached guests properly.
+function testNewWindowOpenerDestroyedWhileUnattached() {
+ var testName = 'testNewWindowOpenerDestroyedBeforeAttach';
+ var webview = embedder.setUpGuest_('foobar');
+
+ var onNewWindow = function(e) {
+ embedder.assertCorrectEvent_(e, '');
+
+ // Remove the opener.
+ webview.parentNode.removeChild(webview);
+ // Pass in a timeout so we ensure the newwindow disposal codepath
+ // works properly.
+ window.setTimeout(function() { embedder.test.succeed(); }, 0);
+
+ e.preventDefault();
+ };
+ webview.addEventListener('newwindow', onNewWindow);
+
+ // Load a new window with the given name.
+ embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
+}
+
function testNewWindowWebRequest() {
var testName = 'testNewWindowWebRequest';
var webview = embedder.setUpGuest_('foobar');
@@ -491,18 +573,25 @@ function testNewWindowWebRequestRemoveElement() {
}
embedder.test.testList = {
- 'testNewWindowNameTakesPrecedence': testNewWindowNameTakesPrecedence,
- 'testWebViewNameTakesPrecedence': testWebViewNameTakesPrecedence,
- 'testNoName': testNoName,
- 'testNewWindowRedirect': testNewWindowRedirect,
+ 'testNewWindowAttachAfterOpenerDestroyed':
+ testNewWindowAttachAfterOpenerDestroyed,
'testNewWindowClose': testNewWindowClose,
+ 'testNewWindowDeclarativeWebRequest': testNewWindowDeclarativeWebRequest,
'testNewWindowDeferredAttachment': testNewWindowDeferredAttachment,
+ 'testNewWindowDiscardAfterOpenerDestroyed':
+ testNewWindowDiscardAfterOpenerDestroyed,
'testNewWindowExecuteScript': testNewWindowExecuteScript,
+ 'testNewWindowNameTakesPrecedence': testNewWindowNameTakesPrecedence,
+ 'testNewWindowNoName': testNewWindowNoName,
'testNewWindowOpenInNewTab': testNewWindowOpenInNewTab,
- 'testNewWindowDeclarativeWebRequest': testNewWindowDeclarativeWebRequest,
+ 'testNewWindowOpenerDestroyedWhileUnattached':
+ testNewWindowOpenerDestroyedWhileUnattached,
+ 'testNewWindowRedirect': testNewWindowRedirect,
'testNewWindowWebRequest': testNewWindowWebRequest,
'testNewWindowWebRequestCloseWindow': testNewWindowWebRequestCloseWindow,
- 'testNewWindowWebRequestRemoveElement': testNewWindowWebRequestRemoveElement
+ 'testNewWindowWebRequestRemoveElement': testNewWindowWebRequestRemoveElement,
+ 'testNewWindowWebViewNameTakesPrecedence':
+ testNewWindowWebViewNameTakesPrecedence
};
onload = function() {
« no previous file with comments | « chrome/renderer/resources/extensions/web_view_events.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698