diff options
author | Martin Negyokru <negyokru@inf.u-szeged.hu> | 2023-09-26 14:45:15 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-09-29 10:31:21 +0000 |
commit | ea1cb36bdad1a26e98f5909b5b13572114c48b52 (patch) | |
tree | 4697d4fe65e7bf0d9c106a47bffc36c28cd739f6 | |
parent | a87695c8413890e06ea27abff84b15cd2a994754 (diff) |
Handle initial NavigationEntries
Chromium introduced the Initial NavigationEntry that meant to
represent the initial empty document at FrameTree creation time.
It is just a placeholder entry put in the list of NavigationEntries
that gets replaced on the next navigation.
A side effect of this is that we have an extra entry in the list before
we load any page.
This change also reverts the history related tests modified by
106 Adaptations that introduced this behavior.
Fixes: QTBUG-117489
Pick-to: 6.5
Change-Id: I2738591b681082792544bd884f8ecec54ce9d72d
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
(cherry picked from commit f19aa5e343db66e5baacacd3c360c4cb00a01c7c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/core/web_contents_adapter.cpp | 26 | ||||
-rw-r--r-- | tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp | 4 | ||||
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 12 |
3 files changed, 30 insertions, 12 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 7e13064b3..fecafd411 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -210,10 +210,28 @@ static std::unique_ptr<content::WebContents> createBlankWebContents(WebContentsA return webContents; } +static int navigationListSize(content::NavigationController &controller) { + // If we're currently on the initial NavigationEntry, no navigation has + // committed, so the initial NavigationEntry should not be part of the + // "Navigation List", and we should return 0 as the navigation list size. + if (controller.GetLastCommittedEntry()->IsInitialEntry()) + return 0; + return controller.GetEntryCount(); +} + +static int navigationListCurrentIndex(content::NavigationController &controller) { + // If we're currently on the initial NavigationEntry, no navigation has + // committed, so the initial NavigationEntry should not be part of the + // "Navigation List", and we should return -1 as the current index. + if (controller.GetLastCommittedEntry()->IsInitialEntry()) + return -1; + return controller.GetCurrentEntryIndex(); +} + static void serializeNavigationHistory(content::NavigationController &controller, QDataStream &output) { - const int currentIndex = controller.GetCurrentEntryIndex(); - const int count = controller.GetEntryCount(); + const int currentIndex = navigationListCurrentIndex(controller); + const int count = navigationListSize(controller); const int pendingIndex = controller.GetPendingEntryIndex(); output << kHistoryStreamVersion; @@ -910,13 +928,13 @@ void WebContentsAdapter::navigateToOffset(int offset) int WebContentsAdapter::navigationEntryCount() { CHECK_INITIALIZED(0); - return m_webContents->GetController().GetEntryCount(); + return navigationListSize(m_webContents->GetController()); } int WebContentsAdapter::currentNavigationEntryIndex() { CHECK_INITIALIZED(0); - return m_webContents->GetController().GetCurrentEntryIndex(); + return navigationListCurrentIndex(m_webContents->GetController()); } QUrl WebContentsAdapter::getNavigationEntryOriginalUrl(int index) diff --git a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp index 6ddc031d5..ad66e972c 100644 --- a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp +++ b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp @@ -487,9 +487,9 @@ void tst_QWebEngineHistory::clear() QWebEnginePage page2(this); QWebEngineHistory* hist2 = page2.history(); - QCOMPARE(hist2->count(), 1); + QCOMPARE(hist2->count(), 0); hist2->clear(); - QCOMPARE(hist2->count(), 1); // Do not change anything. + QCOMPARE(hist2->count(), 0); // Do not change anything. } void tst_QWebEngineHistory::historyItemFromDeletedPage() diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index c9bcb11bd..0c1fa5ae0 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -2077,14 +2077,14 @@ void tst_QWebEnginePage::symmetricUrl() QVERIFY(view.url().isEmpty()); - QCOMPARE(view.history()->count(), 1); + QCOMPARE(view.history()->count(), 0); QUrl dataUrl("data:text/html,<h1>Test"); view.setUrl(dataUrl); view.show(); QCOMPARE(view.url(), dataUrl); - QCOMPARE(view.history()->count(), 1); + QCOMPARE(view.history()->count(), 0); // loading is _not_ immediate, so the text isn't set just yet. QVERIFY(toPlainTextSync(view.page()).isEmpty()); @@ -2397,7 +2397,7 @@ void tst_QWebEnginePage::setHtmlWithBaseURL() QCOMPARE(evaluateJavaScriptSync(&page, "document.images[0].height").toInt(), 128); // no history item has to be added. - QCOMPARE(m_view->page()->history()->count(), 1); + QCOMPARE(m_view->page()->history()->count(), 0); } class MyPage : public QWebEnginePage @@ -2828,7 +2828,7 @@ void tst_QWebEnginePage::setUrlHistory() int expectedLoadFinishedCount = 0; QSignalSpy spy(m_page, SIGNAL(loadFinished(bool))); - QCOMPARE(m_page->history()->count(), 1); + QCOMPARE(m_page->history()->count(), 0); m_page->setUrl(QUrl()); expectedLoadFinishedCount++; @@ -2902,7 +2902,7 @@ void tst_QWebEnginePage::setUrlUsingStateObject() QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); int expectedUrlChangeCount = 0; - QCOMPARE(m_page->history()->count(), 1); + QCOMPARE(m_page->history()->count(), 0); url = QUrl("qrc:/resources/test1.html"); m_page->setUrl(url); @@ -3712,7 +3712,7 @@ void tst_QWebEnginePage::openLinkInNewPage() QCOMPARE(page1.history()->count(), 1); else QCOMPARE(page1.history()->count(), 2); - QCOMPARE(page2.history()->count(), 1); + QCOMPARE(page2.history()->count(), 0); break; case Effect::LoadInOther: QTRY_COMPARE(page2.spy.size(), 1); |