Closed Bug 2086724 Opened 1 month ago Closed 29 days ago

[wpt-sync] Sync PR 63996 - WebKit export of https://bugs.webkit.org/show_bug.cgi?id=326453

Categories

(Testing :: web-platform-tests, task, P4)

task

Tracking

(firefox162 fixed)

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Sync web-platform-tests PR 63996 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/63996
Details from upstream follow.

Basuke Suzuki <basuke@apple.com> wrote:

WebKit export of https://bugs.webkit.org/show_bug.cgi?id=326453

WebKit export from bug: [<!---->Navigation API]<!----> navigation.<!---->traverseTo(<!---->)<!----> from a navigate event can apply before the current traversal'<!---->s hashchange under Site Isolation

<pre>
[Navigation API] navigation.traverseTo() from a navigate event can apply before the current traversal's hashchange under Site Isolation

With UseUIProcessForBackForwardItemLoading, which Site Isolation turns on, a page's history
traversals were not ordered against each other, so a navigation.traverseTo() called from the
navigate event of a history.back() was applied before that back traversal's hashchange event.
This change sends all of a page's traversals through the UI process's
SessionHistoryTraversalQueue, and the queue now waits until every frame has handled the current
traversal before it starts the next one. That matches the HTML spec's session history traversal
queue, which applies the traversals of a traversable one after another.

Before this change, traversals took three paths:

  • A main-frame history.back(), history.forward() or history.go(n) was applied by the UI process
    at once.
  • The same call from a frame whose top is in another process went through
    SessionHistoryTraversalQueue.
  • A Navigation API traversal was applied in the web process by NavigationScheduler, after
    synchronous messages to the UI process for the current back/forward item and, from an iframe,
    for every item.

Now:

  • A Navigation API traversal sends the frame item identifier of its entry to the UI process
    (EnqueueHistoryTraversalToItem), instead of those synchronous messages. A back/forward item
    identifier would not do: for the initial entry of a cross-process iframe, the UI process re-keys
    the frame item under the parent's current item, and the iframe's process keeps the identifier it
    generated. When the traversal's turn comes, the queue finds the entry in the page's back/forward
    list and resolves the target to a delta: the nearest back/forward item, behind and then ahead of
    the current one, that contains the entry. The web process still uses the same rule for iframes
    when the preference is off. If the entry has left the list, or a traversal queued earlier has
    already made it current, nothing moves and the traversal is rejected; the rejection does nothing
    when the earlier traversal's navigate event has settled the promises. Otherwise the queue applies
    the delta like any other, so the traversal also has a direction for
    the stale BackForwardGoToItem check (<a href="https://bugs.webkit.org/show_bug.cgi?id=318728).">https://bugs.webkit.org/show_bug.cgi?id=318728).</a> The web
    process receives an ordinary GoToBackForwardItem, and the navigate event attaches the upcoming
    traverse method tracker as before. NavigationScheduler::isSameDocumentNavigation() also answers
    from the entry.
  • A main-frame history.back(), history.forward() or history.go(n) is enqueued too. Every scripted
    main-frame traversal under Site Isolation now waits for the queue's 0-delay timer, and deltas
    from different frames that arrive before it fires are coalesced.
  • The queue keeps item traversals and deltas in order and coalesces only adjacent deltas. When
    coalescing two deltas overflows, both are dropped, instead of canceling the whole queue.

To tell when a traversal is finished, GoToBackForwardItem now has a reply.
HistoryController::goToItem takes a completion handler that runs once the history policy decision
has been applied, on every path. The web process replies from it with a FrameTraversalResult: the
frame did not take the traversal, took it (applied it or deferred it for a precommit handler), or
started a load for it. The queue waits for a reply from every frame the traversal was sent to.
IPC calls the reply handler even when a web process exits, so a crashed frame process does not
hold the queue. Previously the queue settled only on a main-frame commit, same-document
navigation or provisional load failure. None of these happens for a traversal that changes only
a subframe or one canceled by the navigate event, so such a traversal held every later one.

When a traversal changes the main frame within its document, the UI process now sends it to the
other frames only after the main frame replies that it took it, because canceling the navigate
event there cancels the traversal for all frames. A Navigation API traversal is answered once
every frame has replied. If no frame took it, for example because the main frame canceled it
before it reached the frame that asked for it, the answer rejects the traversal's promises. That
can reject a tracker that has already settled, so Navigation::MethodTrackerRegistry::unregister()
now removes an upcoming traversal only when it belongs to the tracker being unregistered.

When the main frame starts a cross-document load, the queue also waits for that load to commit or
fail, as before, or to be destroyed, because a delta resolved earlier could see a stale current
index (<a href="https://bugs.webkit.org/show_bug.cgi?id=317229).">https://bugs.webkit.org/show_bug.cgi?id=317229).</a> This wait accepts any main-frame commit or
failure: a navigation whose provisional page is replaced never reports its own identifier again,
and waiting for it would hold the queue. The wait also ends when a provisional process terminates
before it commits, since that load then reports neither a commit nor a failure. The queue is
canceled when the main frame's process terminates.

Traversals that the UI process starts itself, such as goBack() from the API or a swipe, still do
not go through the queue, but they take the main-frame-first dispatch above too.

navigate-history-traversal-during-onnavigate.html failed with Site Isolation enabled, in 188 of
the last 200 runs on the mac site-isolation bot, and now passes.
precommitHandler-back-and-forth.html now passes with Site Isolation too, so it gets a
mac-site-isolation result. The four new WPTs, which will be exported, cover a traversal after one
that the navigate event canceled, a traversal to an entry that a traversal queued before it made
current, and traversals from a cross-site iframe, which runs in another process with Site
Isolation. With Site Isolation, the traversal to the entry made current took an iframe back before
this change. The cross-site ones give the iframe user activation with
test_driver.bless(), because WebKit blocks a cross-site iframe without user interaction from
navigating the top-level traversable. The two new WKBackForwardList API tests call history.back()
and, in a later task, history.back() or history.forward() from the main frame, and fail without
this change: the later traversal resolved its delta against the item the first one was leaving.
HistoryTraversalAfterProvisionalProcessTerminatesBeforeCommit kills the provisional process of a
main-frame traversal before it commits; every later traversal used to wait for it. It checks only
that a later traversal applies, because the back/forward list's current item stays on the dropped
entry, so that traversal fires no navigate event and its promises do not settle.

WebKit-Bug: <a href="https://bugs.webkit.org/show_bug.cgi?id=326453">https://bugs.webkit.org/show_bug.cgi?id=326453</a>
WebKit-Canonical-Link: <a href="https://commits.webkit.org/324250@main">https://commits.webkit.org/324250@main</a>
</pre>

Whiteboard: [wptsync downstream] → [wptsync downstream error]
Whiteboard: [wptsync downstream error] → [wptsync downstream]
Whiteboard: [wptsync downstream] → [wptsync downstream error]
Whiteboard: [wptsync downstream error] → [wptsync downstream]

CI Results

Ran 11 Firefox configurations based on mozilla-central, and Firefox, Chrome, and Safari on GitHub CI

Total 260 tests and 1 subtests

Status Summary

Firefox

OK : 2[GitHub] 242[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
PASS : 2[Gecko-linux2204-64-wayland-debug, Gecko-linux2204-64-wayland-opt, GitHub] 262[Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt] 263[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-opt-geckoview]
FAIL : 6
TIMEOUT: 2[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt] 4[GitHub]
ERROR : 1

Chrome

OK : 4
PASS : 3
FAIL : 1

Safari

OK : 4
PASS : 4

Links

Gecko CI (Treeherder)
GitHub PR Head
GitHub PR Base

Details

Firefox-only Failures

New Tests That Don't Pass

Tests Disabled in Gecko Infrastructure

Status: NEW → RESOLVED
Closed: 29 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
You need to log in before you can comment on or make changes to this bug.