constellation: Only return focused browsing contexts that exist. (#36330)

The webdriver server relies on the constellation to report which
browsing context is focused, and assumes that a focused context is ready
for interaction. However, new browsing contexts exist in a weird state
where they are not tracked by the constellation until the initial load
is complete, which leads to the constellation rejecting attempts to
navigate a browsing context right after it's created. These changes
ensure the constellation does not report a browsing context as focused
until it's actually created and ready for interaction.

Testing: Run `./mach test-wpt --product servodriver
tests/wpt/mozilla/tests/mozilla/DOMParser.html`, which now runs to
completion.
Fixes: #34551
Fixes: #36328

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-04-04 17:41:14 -04:00 committed by GitHub
parent ad95a602f8
commit 944e795606
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 3 deletions

View file

@ -1253,7 +1253,15 @@ where
self.handle_exit();
},
EmbedderToConstellationMessage::GetFocusTopLevelBrowsingContext(resp_chan) => {
let _ = resp_chan.send(self.webviews.focused_webview().map(|(id, _)| id));
let focused_context = self
.webviews
.focused_webview()
.filter(|(_, webview)| {
self.browsing_contexts
.contains_key(&webview.focused_browsing_context_id)
})
.map(|(id, _)| id);
let _ = resp_chan.send(focused_context);
},
// Perform a navigation previously requested by script, if approved by the embedder.
// If there is already a pending page (self.pending_changes), it will not be overridden;