summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2020-05-21 16:28:02 +0200
committerPeter Varga <pvarga@inf.u-szeged.hu>2020-05-25 10:58:37 +0200
commit17cac776b2ec30af8f928d648f4708f8e1a25b5e (patch)
tree96b49c7542443d9de158f5187437628c4a2e1dc6 /tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
parent7b6d15cdf271772695d28bf48f1f41a29dc29e28 (diff)
Fix crash on WebContentsDelegateQt::CloseContents()
CloseContents() triggers a windowCloseRequested() signal. The handler of the signal might close the QWebEngineView and it would result the destruction of the WebContentsDelegateQt. Thus, any operation on WebContentsDelegateQt is not safe after a WebContentsAdapterClient::close() call. For example, calling QWebEngineView::close() on QWebEnginePage::windowCloseRequested() would result crash because it sets life cycle state to discarded which destructs web contents. Fixes: QTBUG-84355 Change-Id: I5da404bc9b1923cc19085ee899b550da49d1416b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp')
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 515aa4ebb..e4e451a55 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -231,6 +231,7 @@ private Q_SLOTS:
void renderProcessPid();
void backgroundColor();
void audioMuted();
+ void closeContents();
private:
static QPoint elementCenter(QWebEnginePage *page, const QString &id);
@@ -4641,6 +4642,27 @@ void tst_QWebEnginePage::audioMuted()
QCOMPARE(spy[1][0], QVariant(false));
}
+void tst_QWebEnginePage::closeContents()
+{
+ TestPage page;
+ QSignalSpy windowCreatedSpy(&page, &TestPage::windowCreated);
+ page.runJavaScript("var dialog = window.open('', '', 'width=100, height=100');");
+ QTRY_COMPARE(windowCreatedSpy.count(), 1);
+
+ QWebEngineView *dialogView = new QWebEngineView;
+ QWebEnginePage *dialogPage = page.createdWindows[0];
+ dialogPage->setView(dialogView);
+ QCOMPARE(dialogPage->lifecycleState(), QWebEnginePage::LifecycleState::Active);
+
+ // This should not crash.
+ connect(dialogPage, &QWebEnginePage::windowCloseRequested, dialogView, &QWebEngineView::close);
+ page.runJavaScript("dialog.close();");
+
+ // QWebEngineView::closeEvent() sets the life cycle state to discarded.
+ QTRY_COMPARE(dialogPage->lifecycleState(), QWebEnginePage::LifecycleState::Discarded);
+ delete dialogView;
+}
+
static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")};
W_QTEST_MAIN(tst_QWebEnginePage, params)