1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-19 10:16:34 +01:00

Fix failing tests after removing loadfinished hack

This commit is contained in:
Juraj Oravec 2024-09-06 06:30:21 +00:00
parent c8953b63d8
commit f064713296
3 changed files with 20 additions and 25 deletions

View File

@ -41,21 +41,17 @@ void SiteSettingsTest::webAttributeTest()
SiteSettingsManager *siteSettings = mApp->siteSettingsManager();
siteSettings->setOption(QWebEngineSettings::AutoLoadImages, QUrl(QSL("https://www.falkon.org/")), SiteSettingsManager::Deny);
siteSettings->setOption(QWebEngineSettings::JavascriptEnabled, QUrl(QSL("https://kde.org/")), SiteSettingsManager::Deny);
siteSettings->setOption(QWebEngineSettings::LocalStorageEnabled, QUrl(QSL("https://store.falkon.org/")), SiteSettingsManager::Deny);
siteSettings->setOption(QWebEngineSettings::PlaybackRequiresUserGesture, QUrl(QSL("https://planet.kde.org/")), SiteSettingsManager::Allow);
WebTab tab;
checkInternalPage(QUrl(QSL("falkon:start")));
checkInternalPage(&tab, QUrl(QSL("falkon:start")));
checkExternalPage(QUrl(QSL("https://www.falkon.org/")));
checkExternalPage(QUrl(QSL("https://kde.org/")));
checkExternalPage(&tab, QUrl(QSL("https://www.falkon.org/")));
checkExternalPage(&tab, QUrl(QSL("https://kde.org/")));
checkExternalPage(&tab, QUrl(QSL("https://store.falkon.org/")));
checkInternalPage(QUrl(QSL("falkon:about")));
checkInternalPage(&tab, QUrl(QSL("falkon:about")));
checkExternalPage(&tab, QUrl(QSL("https://planet.kde.org/")));
checkExternalPage(QUrl(QSL("https://planet.kde.org/")));
}
bool SiteSettingsTest::checkWebAttributes(WebPage *page, QHash<QWebEngineSettings::WebAttribute, bool> webAttributes)
@ -69,8 +65,9 @@ bool SiteSettingsTest::checkWebAttributes(WebPage *page, QHash<QWebEngineSetting
return true;
}
void SiteSettingsTest::checkInternalPage(WebTab *tab, QUrl url)
void SiteSettingsTest::checkInternalPage(QUrl url)
{
WebTab tab;
QMap<QWebEngineSettings::WebAttribute, bool> internalWebAttributes = {
{QWebEngineSettings::AutoLoadImages, true}
,{QWebEngineSettings::JavascriptEnabled, true}
@ -86,25 +83,26 @@ void SiteSettingsTest::checkInternalPage(WebTab *tab, QUrl url)
,{QWebEngineSettings::WebRTCPublicInterfacesOnly, false}
};
QSignalSpy spy(tab, SIGNAL(loadingChanged(bool)));
tab->load(url);
QTRY_COMPARE(spy.count(), 3);
QSignalSpy spy(tab.webView(), &WebView::loadFinished);
tab.load(url);
QTRY_COMPARE(spy.count(), 1);
auto *page = tab->webView()->page();
auto *page = tab.webView()->page();
for (auto it = internalWebAttributes.begin(); it != internalWebAttributes.end(); ++it) {
QCOMPARE(page->settings()->testAttribute(it.key()), it.value());
}
}
void SiteSettingsTest::checkExternalPage(WebTab *tab, QUrl url)
void SiteSettingsTest::checkExternalPage(QUrl url)
{
WebTab tab;
SiteSettingsManager *siteSettings = mApp->siteSettingsManager();
QSignalSpy spy(tab, SIGNAL(loadingChanged(bool)));
tab->load(url);
QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 3, 20000);
QSignalSpy spy(tab.webView(), &WebView::loadFinished);
tab.load(url);
QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
auto *page = tab->webView()->page();
auto *page = tab.webView()->page();
QCOMPARE(checkWebAttributes(page, siteSettings->getWebAttributes(url)), true);
}

View File

@ -39,8 +39,8 @@ private Q_SLOTS:
private:
bool checkWebAttributes(WebPage *page, QHash<QWebEngineSettings::WebAttribute, bool> webAttributes);
void checkInternalPage(WebTab *tab, QUrl url);
void checkExternalPage(WebTab *tab, QUrl url);
void checkInternalPage(QUrl url);
void checkExternalPage(QUrl url);
};
#endif // SITESETTINGSTEST_H

View File

@ -81,10 +81,7 @@ void WebViewTest::loadSignalsChangePageTest()
auto *page2 = new WebPage;
view.setPage(page2);
// WebPage: Workaround for broken load started/finished signals in QtWebEngine 5.10
const int loadFinishedEmitCount = qstrncmp(qVersion(), "5.11.", 5) == 0 ? 1 : 2;
QTRY_COMPARE(loadFinishedSpy.count(), loadFinishedEmitCount);
QTRY_COMPARE(loadFinishedSpy.count(), 1);
QCOMPARE(loadStartedSpy.count(), 0);
loadFinishedSpy.clear();