diff options
author | Jüri Valdmann <juri.valdmann@qt.io> | 2018-07-09 14:18:11 +0200 |
---|---|---|
committer | Jüri Valdmann <juri.valdmann@qt.io> | 2018-07-16 08:56:50 +0000 |
commit | a6f9de61cc3a51c776d35fe40f3489c097c91908 (patch) | |
tree | 103535216f51ab1436f7221e256c2b9cd35f30d2 | |
parent | 5fbe7fe2f9fef3f9430c468e3e0dd3898d3012c1 (diff) |
Create WebContents with initially_hidden = true
Task-number: QTBUG-69360
Change-Id: Ia17ce79a8221aa339c72763a984bf1958935ef96
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | src/core/web_contents_adapter.cpp | 2 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview.cpp | 3 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_geopermission.qml | 1 | ||||
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 5 | ||||
-rw-r--r-- | tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | 14 |
5 files changed, 25 insertions, 0 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index fc4dc9b2a..ec1416010 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -223,6 +223,7 @@ static content::WebContents *createBlankWebContents(WebContentsAdapterClient *ad create_params.routing_id = MSG_ROUTING_NONE; create_params.initial_size = gfx::Size(kTestWindowWidth, kTestWindowHeight); create_params.context = reinterpret_cast<gfx::NativeView>(adapterClient); + create_params.initially_hidden = true; return content::WebContents::Create(create_params); } @@ -430,6 +431,7 @@ void WebContentsAdapter::initialize(content::SiteInstance *site) content::WebContents::CreateParams create_params(m_profileAdapter->profile(), site); create_params.initial_size = gfx::Size(kTestWindowWidth, kTestWindowHeight); create_params.context = reinterpret_cast<gfx::NativeView>(m_adapterClient); + create_params.initially_hidden = true; m_webContents.reset(content::WebContents::Create(create_params)); } diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 83ee19f03..9c999e290 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -776,6 +776,9 @@ void QQuickWebEngineViewPrivate::initializationFinished() for (QQuickWebEngineScript *script : qAsConst(m_userScripts)) script->d_func()->bind(profileAdapter()->userResourceController(), adapter.data()); + if (q->window() && q->isVisible()) + adapter->wasShown(); + if (!m_isBeingAdopted) return; diff --git a/tests/auto/quick/qmltests/data/tst_geopermission.qml b/tests/auto/quick/qmltests/data/tst_geopermission.qml index 642cf2016..c935ac0b4 100644 --- a/tests/auto/quick/qmltests/data/tst_geopermission.qml +++ b/tests/auto/quick/qmltests/data/tst_geopermission.qml @@ -70,6 +70,7 @@ TestWebEngineView { TestCase { name: "WebViewGeopermission" + when: windowShown function init() { deniedGeolocation = false diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 014319340..a5eb575b9 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -398,6 +398,11 @@ void tst_QWebEnginePage::geolocationRequestJS() QSignalSpy spyLoadFinished(newPage, SIGNAL(loadFinished(bool))); newPage->setHtml(QString("<html><body>test</body></html>"), QUrl("qrc://secure/origin")); QTRY_COMPARE(spyLoadFinished.count(), 1); + + // Geolocation is only enabled for visible WebContents. + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + if (evaluateJavaScriptSync(newPage, QLatin1String("!navigator.geolocation")).toBool()) W_QSKIP("Geolocation is not supported.", SkipSingle); diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index fa816172a..286efca56 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -186,6 +186,7 @@ private Q_SLOTS: void contextMenu(); void webUIURLs_data(); void webUIURLs(); + void visibilityState(); }; // This will be called before the first test function is executed. @@ -2753,5 +2754,18 @@ void tst_QWebEngineView::webUIURLs() QCOMPARE(loadFinishedSpy.takeFirst().at(0).toBool(), supported); } +void tst_QWebEngineView::visibilityState() +{ + QWebEngineView view; + QSignalSpy spy(&view, &QWebEngineView::loadFinished); + view.load(QStringLiteral("about:blank")); + QVERIFY(spy.count() || spy.wait()); + QVERIFY(spy.takeFirst().takeFirst().toBool()); + QCOMPARE(evaluateJavaScriptSync(view.page(), "document.visibilityState").toString(), QStringLiteral("hidden")); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QCOMPARE(evaluateJavaScriptSync(view.page(), "document.visibilityState").toString(), QStringLiteral("visible")); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" |