diff options
author | Viktor Engelmann <Viktor.Engelmann@qt.io> | 2017-03-13 14:30:02 +0100 |
---|---|---|
committer | Viktor Engelmann <viktor.engelmann@qt.io> | 2017-05-30 10:30:06 +0000 |
commit | 93f9eed62db271ae4b8896f48df72a956f3ce7be (patch) | |
tree | dbaf7ddd410874f63e2d3e4fbaf6ef2632bd0bf7 /tests | |
parent | 95ca17c45aea718cade487640edc63e08bc23820 (diff) |
Store Target URL in WebContentsDelegateQt::WebContentsCreated
When opening a new window, for example by using the JavaScript
method window.open('...'), the requested url is not stored
in the content::WebContents object we get in
WebContentsDelegateQt::createWindow (at this point, it should
at least be stored as pending request in the WebContents'
NavigationController, but it is not).
Because of this, the QQuickWebEngineNewViewRequest object
in QQuickWebEngineViewPrivate::adoptNewWindow never contained
the url. We have access to the target url in
WebContentsDelegateQt::WebContentsCreated, so now we store
it there in a new property m_initialTargetUrl, from where
WebContentsDelegateQt::createWindow takes it and passes it
to WebContentsAdapter::adoptNewWindow as a new parameter.
[ChangeLog][WebEngine] Fix WebEngineNewViewRequest::requestedUrl being empty when opening window from JavaScript
Task-number: QTBUG-57675
Change-Id: I7e2c7866899baade17ce2517e6be8b2b2709699e
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_newViewRequest.qml | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml index 7a04d5f5b..4becbb620 100644 --- a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml +++ b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml @@ -28,7 +28,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtWebEngine 1.2 +import QtWebEngine 1.5 TestWebEngineView { id: webEngineView @@ -47,7 +47,8 @@ TestWebEngineView { onNewViewRequested: { newViewRequest = { "destination": request.destination, - "userInitiated": request.userInitiated + "userInitiated": request.userInitiated, + "requestedUrl": request.requestedUrl }; dialog = Qt.createQmlObject( @@ -81,6 +82,8 @@ TestWebEngineView { } function test_jsWindowOpen() { + var url = 'data:text/html,%3Chtml%3E%3Cbody%3ETest+Page%3C%2Fbody%3E%3C%2Fhtml%3E'; + // Open an empty page in a new tab webEngineView.loadHtml( "<html><head><script>" + @@ -95,28 +98,30 @@ TestWebEngineView { verify(dialog.webEngineView.waitForLoadSucceeded()); compare(dialog.webEngineView.url, ""); + compare(newViewRequest.requestedUrl, 'about:blank'); newViewRequestedSpy.clear(); dialog.destroy(); - // Open an empty page in a new dialog + // Open a page in a new dialog webEngineView.loadHtml( "<html><head><script>" + - " function popup() { window.open('', '_blank', 'width=200,height=100'); }" + + " function popup() { window.open('" + url + "', '_blank', 'width=200,height=100'); }" + "</script></head>" + "<body onload='popup()'></body></html>"); verify(webEngineView.waitForLoadSucceeded()); tryCompare(newViewRequestedSpy, "count", 1); compare(newViewRequest.destination, WebEngineView.NewViewInDialog); + compare(newViewRequest.requestedUrl, url); verify(!newViewRequest.userInitiated); verify(dialog.webEngineView.waitForLoadSucceeded()); newViewRequestedSpy.clear(); dialog.destroy(); - // Open an empty page in a new dialog by user + // Open a page in a new dialog by user webEngineView.loadHtml( "<html><head><script>" + - " function popup() { window.open('', '_blank', 'width=200,height=100'); }" + + " function popup() { window.open('" + url + "', '_blank', 'width=200,height=100'); }" + "</script></head>" + "<body onload=\"document.getElementById('popupButton').focus();\">" + " <button id='popupButton' onclick='popup()'>Pop Up!</button>" + @@ -124,6 +129,7 @@ TestWebEngineView { verify(webEngineView.waitForLoadSucceeded()); verifyElementHasFocus("popupButton"); keyPress(Qt.Key_Enter); + compare(newViewRequest.requestedUrl, url); tryCompare(newViewRequestedSpy, "count", 1); compare(newViewRequest.destination, WebEngineView.NewViewInDialog); |