From f06cb10ce5a6d543d97bd05484179f56b60e6e5a Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Fri, 14 Mar 2014 18:28:33 +0100 Subject: Base load signals on Blink loader events This mainly remove the use of the LoadingStateChanged callback, which is tied to DidStartLoading and DidStopLoading. Those signals are handled from the browser process side, also wrapping the time where the render process is initialized. We can't rely on those signals for loadStarted, but afterward rely on the Blink loader for loadFinished. We must use the same source for both. Instead only rely on Blink callbacks ultimately related to network events. This gives us a behavior closer to QtWebKit. The major compromise that this forces us to to accept is that loadStarted is now triggered asynchronously. This will basically break anything expecting loadStarted to be emitted synchronously from the load method. This also adjust autotests to get a few more passing. Initial-patch-by: Pierre Rossi Change-Id: Ib6c0170df891d1b7f8ed4dc1d483985523e267dc Reviewed-by: Pierre Rossi Reviewed-by: Simon Hausmann --- .../qwebengineframe/tst_qwebengineframe.cpp | 6 ++--- .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 29 ++++++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp index 52e422cb9..448f488f6 100644 --- a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp +++ b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp @@ -1516,7 +1516,7 @@ void tst_QWebEngineFrame::setUrlThenLoads() QSignalSpy finishedSpy(m_page, SIGNAL(loadFinished(bool))); m_page->setUrl(url); - QCOMPARE(startedSpy.count(), 1); + QTRY_COMPARE(startedSpy.count(), 1); QTRY_COMPARE(urlChangedSpy.count(), 1); QTRY_COMPARE(finishedSpy.count(), 1); QVERIFY(finishedSpy.at(0).first().toBool()); @@ -1529,12 +1529,12 @@ void tst_QWebEngineFrame::setUrlThenLoads() // Just after first load. URL didn't changed yet. m_page->load(urlToLoad1); - QTRY_COMPARE(startedSpy.count(), 2); QEXPECT_FAIL("", "Slight change: url() will return the loaded URL immediately.", Continue); QCOMPARE(m_page->url(), url); QCOMPARE(m_page->requestedUrl(), urlToLoad1); // baseUrlSync spins an event loop and this sometimes return the next result. // QCOMPARE(baseUrlSync(m_page), baseUrl); + QTRY_COMPARE(startedSpy.count(), 2); // After first URL changed. QTRY_COMPARE(urlChangedSpy.count(), 2); @@ -1546,11 +1546,11 @@ void tst_QWebEngineFrame::setUrlThenLoads() // Just after second load. URL didn't changed yet. m_page->load(urlToLoad2); - QTRY_COMPARE(startedSpy.count(), 3); QEXPECT_FAIL("", "Slight change: url() will return the loaded URL immediately.", Continue); QCOMPARE(m_page->url(), urlToLoad1); QCOMPARE(m_page->requestedUrl(), urlToLoad2); QCOMPARE(baseUrlSync(m_page), extractBaseUrl(urlToLoad1)); + QTRY_COMPARE(startedSpy.count(), 3); // After second URL changed. QTRY_COMPARE(urlChangedSpy.count(), 3); diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index bb07e2e00..7e1d811e8 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -362,21 +362,23 @@ void tst_QWebEnginePage::geolocationRequestJS() void tst_QWebEnginePage::loadFinished() { - qRegisterMetaType("QNetworkRequest*"); - QSignalSpy spyLoadStarted(m_view, SIGNAL(loadStarted())); - QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool))); + QWebEnginePage page; + QSignalSpy spyLoadStarted(&page, SIGNAL(loadStarted())); + QSignalSpy spyLoadFinished(&page, SIGNAL(loadFinished(bool))); - m_view->page()->load(QUrl("data:text/html,foo \">" "")); QTRY_COMPARE(spyLoadFinished.count(), 1); - QTRY_VERIFY(spyLoadStarted.count() > 1); - QTRY_VERIFY(spyLoadFinished.count() > 1); + QEXPECT_FAIL("", "Behavior change: Load signals are emitted only for the main frame in QtWebEngine.", Continue); + QTRY_VERIFY_WITH_TIMEOUT(spyLoadStarted.count() > 1, 100); + QEXPECT_FAIL("", "Behavior change: Load signals are emitted only for the main frame in QtWebEngine.", Continue); + QTRY_VERIFY_WITH_TIMEOUT(spyLoadFinished.count() > 1, 100); spyLoadFinished.clear(); - m_view->page()->load(QUrl("data:text/html,")); QTRY_COMPARE(spyLoadFinished.count(), 1); QCOMPARE(spyLoadFinished.count(), 1); @@ -1604,6 +1606,9 @@ void tst_QWebEnginePage::textEditing() void tst_QWebEnginePage::requestCache() { +#if !defined(ACCEPTNAVIGATIONREQUEST) + QSKIP("ACCEPTNAVIGATIONREQUEST"); +#else TestPage page; QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); @@ -1627,6 +1632,7 @@ void tst_QWebEnginePage::requestCache() (int)QNetworkRequest::PreferNetwork); QCOMPARE(page.navigations.at(2).request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(), (int)QNetworkRequest::PreferCache); +#endif } void tst_QWebEnginePage::loadCachedPage() @@ -1676,7 +1682,8 @@ void tst_QWebEnginePage::backActionUpdate() QTRY_COMPARE(loadSpy.count(), 1); QVERIFY(!action->isEnabled()); QTest::mouseClick(&view, Qt::LeftButton, 0, QPoint(10, 10)); - QTRY_COMPARE(loadSpy.count(), 2); + QEXPECT_FAIL("", "Behavior change: Load signals are emitted only for the main frame in QtWebEngine.", Continue); + QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 2, 100); QVERIFY(action->isEnabled()); } @@ -2723,6 +2730,7 @@ void tst_QWebEnginePage::defaultTextEncoding() #endif } +#if defined(QWEBENGINEPAGE_ERRORPAGEEXTENSION) class ErrorPage : public QWebEnginePage { public: @@ -2745,6 +2753,7 @@ public: return true; } }; +#endif void tst_QWebEnginePage::errorPageExtension() { @@ -2827,6 +2836,9 @@ void tst_QWebEnginePage::errorPageExtensionInFrameset() void tst_QWebEnginePage::errorPageExtensionLoadFinished() { +#if !defined(QWEBENGINEPAGE_ERRORPAGEEXTENSION) + QSKIP("QWEBENGINEPAGE_ERRORPAGEEXTENSION"); +#else ErrorPage page; m_view->setPage(&page); @@ -2852,6 +2864,7 @@ void tst_QWebEnginePage::errorPageExtensionLoadFinished() QVERIFY(nonExistantFrameLoadSucceded); m_view->setPage(0); +#endif } class FriendlyWebPage : public QWebEnginePage -- cgit v1.2.3