Commit ed1bba31 authored by lazyboy's avatar lazyboy Committed by Commit bot

<webview>: Add test coverage for deferred newwindow attachment.

We can trigger this case by adding a webview that is not in DOM through
newwindow API.

Fix so that deferred attachment would not throw error, this is done by
returning true in attachWindow() method in this case.

BUG=None
Test=Load a <webview> in a chrome app. Make a newwindow request from
that webview. When the newwindow event fires, call e.window.attach
with a <webview> that is not on DOM, this should work as intended,
when the later <webview> is attached to DOM, it should load properly.

Review URL: https://codereview.chromium.org/497833003

Cr-Commit-Position: refs/heads/master@{#291594}
parent 07be9b39
......@@ -763,6 +763,12 @@ IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Close) {
NEEDS_TEST_SERVER);
}
IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_DeferredAttachment) {
TestHelper("testNewWindowDeferredAttachment",
"web_view/newwindow",
NEEDS_TEST_SERVER);
}
IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_ExecuteScript) {
TestHelper("testNewWindowExecuteScript",
"web_view/newwindow",
......
......@@ -866,7 +866,7 @@ WebViewInternal.prototype.attachWindow = function(guestInstanceId,
if (!this.isPluginInRenderTree()) {
this.deferredAttachState = {isNewWindow: isNewWindow};
return false;
return true;
}
this.deferredAttachState = null;
......
......@@ -258,6 +258,41 @@ function testNewWindowClose() {
embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
}
// Checks that calling event.window.attach() with a <webview> that is not
// in the DOM works properly.
// This tests the deferred attachment code path in web_view.js.
function testNewWindowDeferredAttachment() {
var testName = 'testNewWindowDeferredAttachment';
var webview = embedder.setUpGuest_('foobar');
var onNewWindow = function(e) {
chrome.test.log('Embedder notified on newwindow');
embedder.assertCorrectEvent_(e, '');
var newwebview = document.createElement('webview');
newwebview.addEventListener('loadstop', function() {
chrome.test.log('Guest in newwindow got loadstop.');
embedder.test.succeed();
});
try {
e.window.attach(newwebview);
} catch (e) {
embedder.test.fail();
}
// Append the <webview> in DOM later.
window.setTimeout(function() {
document.querySelector('#webview-tag-container').appendChild(newwebview);
}, 0);
};
webview.addEventListener('newwindow', onNewWindow);
// Load a new window with the given name.
embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
};
function testNewWindowExecuteScript() {
var testName = 'testNewWindowExecuteScript';
var webview = embedder.setUpGuest_('foobar');
......@@ -461,6 +496,7 @@ embedder.test.testList = {
'testNoName': testNoName,
'testNewWindowRedirect': testNewWindowRedirect,
'testNewWindowClose': testNewWindowClose,
'testNewWindowDeferredAttachment': testNewWindowDeferredAttachment,
'testNewWindowExecuteScript': testNewWindowExecuteScript,
'testNewWindowOpenInNewTab': testNewWindowOpenInNewTab,
'testNewWindowDeclarativeWebRequest': testNewWindowDeclarativeWebRequest,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment