summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2022-05-31 13:08:05 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-06-07 19:29:26 +0000
commitc5de1b21232c7114b27e42fa8c15cb323d256e47 (patch)
treed495d46c1ac63a8447e290d785ded071c05b0019 /tests/auto
parent10b4b06d28dbeb0de67edcb94eb85df4d70e4f55 (diff)
Do not reset favicon for same document navigations
Fixes: QTBUG-103735 Pick-to: 6.3 6.4 Change-Id: Iee0c09cde16a825097b7c1c014655476989922c0 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/quick/qmltests/data/tst_favicon.qml32
-rw-r--r--tests/auto/widgets/favicon/tst_favicon.cpp37
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/auto/quick/qmltests/data/tst_favicon.qml b/tests/auto/quick/qmltests/data/tst_favicon.qml
index 79c835c70..ce4a2aa3c 100644
--- a/tests/auto/quick/qmltests/data/tst_favicon.qml
+++ b/tests/auto/quick/qmltests/data/tst_favicon.qml
@@ -165,6 +165,38 @@ TestWebEngineView {
compare(iconUrl, Qt.resolvedUrl("icons/qt32.ico"))
}
+ function test_faviconLoadPushState_data() {
+ return [
+ { tag: "OTR", profile: defaultProfile },
+ { tag: "non-OTR", profile: nonOTRProfile },
+ ];
+ }
+
+ function test_faviconLoadPushState(row) {
+ webEngineView.profile = row.profile;
+ compare(iconChangedSpy.count, 0);
+
+ var iconUrl;
+
+ webEngineView.url = Qt.resolvedUrl("favicon.html");
+ verify(webEngineView.waitForLoadSucceeded());
+ tryCompare(iconChangedSpy, "count", 1);
+ iconUrl = removeFaviconProviderPrefix(webEngineView.icon);
+ compare(iconUrl, Qt.resolvedUrl("icons/favicon.png"));
+
+ iconChangedSpy.clear();
+
+ // pushState() is a same document navigation and should not reset or
+ // update favicon.
+ compare(webEngineView.history.items.rowCount(), 1);
+ runJavaScript("history.pushState('', '')");
+ tryVerify(function() { return webEngineView.history.items.rowCount() === 2; });
+
+ // Favicon change is not expected.
+ compare(iconChangedSpy.count, 0);
+ iconUrl = removeFaviconProviderPrefix(webEngineView.icon);
+ compare(iconUrl, Qt.resolvedUrl("icons/favicon.png"));
+ }
function test_noFavicon_data() {
return [
diff --git a/tests/auto/widgets/favicon/tst_favicon.cpp b/tests/auto/widgets/favicon/tst_favicon.cpp
index d8b4803c0..6b5ae3c02 100644
--- a/tests/auto/widgets/favicon/tst_favicon.cpp
+++ b/tests/auto/widgets/favicon/tst_favicon.cpp
@@ -29,6 +29,7 @@
#include <QtTest/QtTest>
#include <util.h>
+#include <QWebEngineHistory>
#include <QWebEnginePage>
#include <QWebEngineProfile>
#include <QWebEngineSettings>
@@ -49,6 +50,7 @@ private Q_SLOTS:
void faviconLoadFromResources();
void faviconLoadEncodedUrl();
void faviconLoadAfterHistoryNavigation();
+ void faviconLoadPushState();
void noFavicon();
void aboutBlank();
void unavailableFavicon();
@@ -222,6 +224,41 @@ void tst_Favicon::faviconLoadAfterHistoryNavigation()
QCOMPARE(m_page->iconUrl(), QUrl("qrc:/resources/icons/qtmulti.ico"));
}
+void tst_Favicon::faviconLoadPushState()
+{
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+ QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon)));
+
+ QUrl url("qrc:/resources/favicon-single.html");
+ m_page->load(url);
+
+ QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+ QTRY_COMPARE(iconChangedSpy.count(), 1);
+
+ QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QCOMPARE(iconUrl, m_page->iconUrl());
+ QCOMPARE(iconUrl, QUrl("qrc:/resources/icons/qt32.ico"));
+
+ const QIcon &icon = m_page->icon();
+ QVERIFY(!icon.isNull());
+
+ iconUrlChangedSpy.clear();
+ iconChangedSpy.clear();
+
+ // pushState() is a same document navigation and should not reset or
+ // update favicon.
+ QCOMPARE(m_page->history()->count(), 1);
+ evaluateJavaScriptSync(m_page, "history.pushState('', '')");
+ QTRY_COMPARE(m_page->history()->count(), 2);
+
+ // Favicon change is not expected.
+ QCOMPARE(iconUrlChangedSpy.count(), 0);
+ QCOMPARE(iconChangedSpy.count(), 0);
+ QCOMPARE(m_page->iconUrl(), QUrl("qrc:/resources/icons/qt32.ico"));
+}
+
void tst_Favicon::noFavicon()
{
if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists())