commit 1b12cfa0bd91240f370fde7049f73250c7a43218 parent 906f88665f1a33dfcb10375506e8b28f82d7af5b Author: Adam Vandolder <avandolder@mozilla.com> Date: Sun, 26 Oct 2025 20:35:51 +0000 Bug 1996445 - Have CanonicalBrowsingContext::NavigationTraverse calculate the top-level entry offset. r=dom-core,smaug Differential Revision: https://phabricator.services.mozilla.com/D270081 Diffstat:
4 files changed, 17 insertions(+), 26 deletions(-)
diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp @@ -1653,25 +1653,14 @@ void CanonicalBrowsingContext::NavigationTraverse( RefPtr<SessionHistoryEntry> targetEntry; // 12.1 Let navigableSHEs be the result of getting session history entries // given navigable. - Maybe<int32_t> activeIndex; - Maybe<int32_t> targetIndex; - uint32_t index = 0; nsSHistory::WalkContiguousEntriesInOrder( - mActiveEntry, [&targetEntry, aKey, activeEntry = mActiveEntry, - &activeIndex, &targetIndex, &index](auto* aEntry) { - if (nsCOMPtr<SessionHistoryEntry> entry = do_QueryObject(aEntry)) { - if (entry->Info().NavigationKey() == aKey) { - targetEntry = entry; - targetIndex = Some(index); - } - - if (entry == activeEntry) { - activeIndex = Some(index); - } + mActiveEntry, [&targetEntry, aKey](auto* aEntry) { + auto* entry = static_cast<SessionHistoryEntry*>(aEntry); + if (entry->Info().NavigationKey() == aKey) { + targetEntry = entry; + return false; } - - index++; - return !targetIndex || !activeIndex; + return true; }); if (!targetEntry) { @@ -1682,11 +1671,18 @@ void CanonicalBrowsingContext::NavigationTraverse( return aResolver(NS_OK); } - if (!activeIndex || !targetIndex) { + nsCOMPtr targetRoot = nsSHistory::GetRootSHEntry(targetEntry); + nsCOMPtr activeRoot = nsSHistory::GetRootSHEntry(mActiveEntry); + if (!targetRoot || !activeRoot) { + return aResolver(NS_ERROR_DOM_INVALID_STATE_ERR); + } + int32_t targetIndex = shistory->GetIndexOfEntry(targetRoot); + int32_t activeIndex = shistory->GetIndexOfEntry(activeRoot); + if (targetIndex == -1 || activeIndex == -1) { return aResolver(NS_ERROR_DOM_INVALID_STATE_ERR); } - int32_t offset = *targetIndex - *activeIndex; + int32_t offset = targetIndex - activeIndex; MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Debug, "Performing traversal by {}", offset); diff --git a/testing/web-platform/meta/navigation-api/navigate-event/navigation-traverseTo-same-document-preventDefault-multiple-windows.html.ini b/testing/web-platform/meta/navigation-api/navigate-event/navigation-traverseTo-same-document-preventDefault-multiple-windows.html.ini @@ -1,3 +0,0 @@ -[navigation-traverseTo-same-document-preventDefault-multiple-windows.html] - [navigation.traverseTo() - if a top window cancels the traversal, any iframes should not fire navigate] - expected: FAIL diff --git a/testing/web-platform/meta/navigation-api/navigate-event/navigation-traverseTo-top-cancels-cross-document-child.html.ini b/testing/web-platform/meta/navigation-api/navigate-event/navigation-traverseTo-top-cancels-cross-document-child.html.ini @@ -1,3 +0,0 @@ -[navigation-traverseTo-top-cancels-cross-document-child.html] - [navigate.traverseTo() cancelled by top frame cancels cross-document iframe] - expected: FAIL diff --git a/testing/web-platform/meta/navigation-api/navigation-methods/back-forward-multiple-frames.html.ini b/testing/web-platform/meta/navigation-api/navigation-methods/back-forward-multiple-frames.html.ini @@ -1,3 +1,4 @@ [back-forward-multiple-frames.html] + expected: TIMEOUT [navigation.back() and navigation.forward() can navigate multiple frames] - expected: FAIL + expected: TIMEOUT