From bbf7226ace4d9bbcff4d68c063dc598c2d3f2ff0 Mon Sep 17 00:00:00 2001 From: Tamas Zakor Date: Wed, 14 Oct 2020 14:56:47 +0200 Subject: Fix new view request handling Ignore url loading if the request is not from a data url and the Q(Quick)WebEngineNewViewRequest.openIn() is not called on newViewRequested(). Set the missing Q(Quick)WebEngineNewViewRequest::requestedUrl property. Fixes: QTBUG-87378 Change-Id: Idddc9cf075db68dcf5825b3e746d16419d02cfa0 Reviewed-by: Tamas Zakor Reviewed-by: Peter Varga Reviewed-by: Allan Sandfeld Jensen --- .../auto/quick/qmltests/data/TestWebEngineView.qml | 6 ++++-- tests/auto/quick/qmltests/data/test2.html | 2 +- .../quick/qmltests/data/tst_newViewRequest.qml | 25 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) (limited to 'tests/auto/quick/qmltests/data') diff --git a/tests/auto/quick/qmltests/data/TestWebEngineView.qml b/tests/auto/quick/qmltests/data/TestWebEngineView.qml index 6db076ae8..f2bc09e4b 100644 --- a/tests/auto/quick/qmltests/data/TestWebEngineView.qml +++ b/tests/auto/quick/qmltests/data/TestWebEngineView.qml @@ -85,12 +85,14 @@ WebEngineView { function getElementCenter(element) { var center; - runJavaScript("(function() {" + + testCase.tryVerify(function() { + runJavaScript("(function() {" + " var elem = document.getElementById('" + element + "');" + " var rect = elem.getBoundingClientRect();" + " return { 'x': (rect.left + rect.right) / 2, 'y': (rect.top + rect.bottom) / 2 };" + "})();", function(result) { center = result } ); - testCase.tryVerify(function() { return center !== undefined; }); + return center !== undefined; + }); return center; } diff --git a/tests/auto/quick/qmltests/data/test2.html b/tests/auto/quick/qmltests/data/test2.html index 629c2a063..7a02bf1f2 100644 --- a/tests/auto/quick/qmltests/data/test2.html +++ b/tests/auto/quick/qmltests/data/test2.html @@ -1,6 +1,6 @@ Test page with huge link area - + diff --git a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml index 80389e9f8..08d63d956 100644 --- a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml +++ b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml @@ -38,6 +38,13 @@ TestWebEngineView { property var newViewRequest: null property var dialog: null property string viewType: "" + property var loadRequestArray: [] + + onLoadingChanged: { + loadRequestArray.push({ + "status": loadRequest.status, + }); + } SignalSpy { id: newViewRequestedSpy @@ -81,6 +88,7 @@ TestWebEngineView { newViewRequestedSpy.clear(); newViewRequest = null; viewType = ""; + loadRequestArray = []; } function cleanup() { @@ -163,6 +171,23 @@ TestWebEngineView { } newViewRequestedSpy.clear(); } + + loadRequestArray = []; + compare(loadRequestArray.length, 0); + webEngineView.url = Qt.resolvedUrl("test2.html"); + verify(webEngineView.waitForLoadSucceeded()); + var center = getElementCenter("link"); + mouseClick(webEngineView, center.x, center.y, Qt.LeftButton, Qt.ControlModifier); + tryCompare(newViewRequestedSpy, "count", 1); + compare(newViewRequest.requestedUrl, Qt.resolvedUrl("test1.html")); + compare(newViewRequest.destination, WebEngineView.NewViewInBackgroundTab); + verify(newViewRequest.userInitiated); + if (viewType === "" || viewType === "null") { + compare(loadRequestArray[0].status, WebEngineView.LoadStartedStatus); + compare(loadRequestArray[1].status, WebEngineView.LoadSucceededStatus); + compare(loadRequestArray.length, 2); + } + newViewRequestedSpy.clear(); } } } -- cgit v1.2.3