This test caused some flakiness due to the about:blank load it triggers.
It causes headless-browser to receive a load event for about:blank. If
we have moved onto the next test before that event arrived, that test
would ultimately time out, as its own load will have been dropped while
the about:blank load is still ongoing.
This patch makes us wait for that iframe load event before completing
the test.
We may want to consider never sending subframe load events to the UI
process as well. We really only care about top-level page loads in the
receivers of that event.
(cherry picked from commit be9071834eb0c836ccd821adaa0134820e3f6297)
If we end up in a situation where the navigable no longer has an active
window, we can't perform navigation or many other navigable operations.
These are all ad-hoc, since the navigables spec is basically all written
as if there's always an active window. Unfortunately, the active window
comes from the active document's browsing context, which is a nullable
concept even in the spec, so we do need to deal with null here.
This removes all the locally reproducible crashes when running WPT over
the legacy Japanese encoding directory on my computer.
Yes, this is a bit of a monkey patch, but it should be harmless since
we're (as I understand it) dealing with navigables that are still
hanging around with related tasks queued on them. Once all these tasks
have been completed, the navigables will go away anyway.
(cherry picked from commit aae191aa33c88edba97f872707a5d0f9705cb0aa)
Invoking exec() entirely blocks the UI application's main thread. Qt
explicitly recommends against this. In practice, it seems prevents some
IPC messages from being handled by the UI until the dialog is closed by
the user.
Instead, use open() (which is non-blocking) and set up a signal handler
to deal with the result.
(cherry picked from commit ea9abe26e1c40c0d2e96007bf7d69afb49a7052a)
There was a timing issue here where WebDriver would dismiss a dialog,
and then invoke another endpoint before the dialog was actually closed.
This is because the dismissal first has to hop over to the UI process to
close the graphical dialog, which then asynchronously informs WebContent
of the result. It's not until WebContent receives that result that the
dialog is considered closed, thus those subsequent endpoints would abort
due a dialog being "open".
We now wait for dialogs to be fully closed before returning from the
dismissal endpoints.
(cherry picked from commit 0722a3b1c091adbafc056686ebedbf5c2db84207)
Similar to commit c2cf65adac78912883996153fb608dafe389b6e0, we should
avoid spinning the event loop from the WebContent-side of the WebDriver
connection. This can result in deadlocks if another component in LibWeb
also spins the event loop.
The AO to await navigations has two event loop spinners - waiting for
the navigation to complete and for the document to reach the target
readiness state. We now use NavigationObserver and DocumentObserver to
be notified when these conditions are met. And we use the same async IPC
mechanism as script execution to notify the WebDriver process when all
conditions are met (or timed out).
(cherry picked from commit bf0bc62654803565a6f39ade63d9172cc48c085a)
This contains a hook to be notified when a navigable navigation is
complete, to be used by WebDriver.
(cherry picked from commit 74ef9dc3936d678fdf811bb3c1b39a6ffba2b106)
Some callers (namely WebDriver) will want to stop receiving updates from
the DocumentObserver.
(cherry picked from commit 247307a2a28e92b20a57d127eed73a093dd4e3d3)
Contradictory to the spec, the Set Timeouts endpoint should update the
existing timeouts configuration in-place, rather than replacing it. WPT
expects this, and other browsers already implement this endpoint this
way.
(cherry picked from commit dae6200c1dab586258a8a970ba308c6b2f1cad9c)
Namely, all fields in the timeouts object may now be null. There are a
few calling AOs that we will want to bring up to date as well.
(cherry picked from commit 8396afeb76b5229c385525d307a8d91efa45d6ff)
We've added a few JS::Handle members to this class over time. Let's
avoid creating a new GC root for each of these, and explicitly add a
visitation method.
(cherry picked from commit 048b51eb54d003af5dc202af1b16bb690b1348f9)
The underlying concept is the same, but this method was renamed in the
spec to drop the word "connected".
(cherry picked from commit 022e2b8a94497c01138840478f76af07ddcf51da)
Some of this code is older than widespread use of GCPtr. These functions
returning raw pointers has been a point of confusion at times, so lets
just indicate that they are non-null.
(cherry picked from commit a96a762305423965a9697c2b7038a229d96ac734)
This is a method defined in the WebDriver spec, but requires access to a
bunch of private fields in these classes, so this is implemented in the
same manner as the reset algorithm.
(cherry picked from commit 516f5f70081526ddef2d4a88fc5a1ae916e12fab)
Instead of having N functions all implement the same practice of looping
until an async event has arrived, this templatizes the bulk of the work.
(cherry picked from commit 922837f31b4cc66f6a3acd875962b54c6d547f65)
These aren't required to comply with the UIEvents spec, but they are
required by WebDriver.
(cherry picked from commit 5b2633d90f81d0098d5d7cea1274b98c91851fae;
amended to change `MOD_KEYPAD` to 32 to match serenity's `Mod_Keypad`
in Kernel/API/KeyCode.h)
Multi-byte code point presses do not have a UIEvents::KeyCode value, so
we would previously set the event's key field to "Unidentified".
(cherry picked from commit a11e5055c7f225da3b96571e892042868fd2af18)
We have support for using (shift+)tab to move focus to the next/previous
element on the page. However, there were several ways for this to crash
as written. This updates our implementation to check if we did not find
a node to move focus to, and to reset focus to the first/last node in
the document.
This doesn't seem to work when wrapping around from the first to the
last node. A FIXME has been added for that, as this would already not
work before this patch (the main focus here is not crashing).
(cherry picked from commit 96b5646fc116a98dac80559b9a4be2c149f2e157)
The spec says we don't need to await navigations if we navigate to the
same URL that we are already on, but at least in our implementation, we
should still await the page load. Otherwise, we will invoke WebDriver
endpoints on the wrong page.
(cherry picked from commit 13fe3477ab8ac253bd7346d50b3224baf891872e)
Our handling of left vs. right modifiers keys (shift, ctrl, etc.) was
largely not to spec. This patch adds explicit UIEvents::KeyCode values
for these keys, and updates the UI to match native key events to these
keys (as best as we are able).
(cherry picked from commit 4fcaeabe1a6acd9f4d5fd811a36f2e86748b2a72;
amended to make the rest of the system build and to keep `Mod_AltGr`
around in addition to adding it as a key)
Co-authored-by: Nico Weber <thakis@chromium.org>
For example, pressing just the shift key should not producde a keypress
event.
(cherry picked from commit 448754d95dc797b44d9b066c1e37dabec79d79e6;
amended to not use ICU in CharacterTypes.cpp)
Fire the events before handling any close requests or selection changes.
Pages must have an opportunity to cancel the events.
(cherry picked from commit 3925317c118e23a9b87b65ca792c5d94a92c98a7)
If the user only presses the shift key, for example, we are required to
still send that event to WebContent and generate the corresponding JS
events. Unfortunately, NSApp does not inform us of these events via the
keyDown/keyUp methods. We have to implement the flagsChanged interface,
and track for ourselves what modifier keys were pressed or released.
(cherry picked from commit eabd5b0f2271e7a89727daf80dd28623711f3416)
We only set the grapheme segmenter's text once after creating a new
segmenter, so we also need to clear it whenever we invalidate the text.
(cherry picked from commit 25516e351e46104ff445216e7835aaab9f9b9535)
The expensive part of creating a segmenter is doing the locale and UCD
data lookups at creation time. Instead of doing this once per text node,
cache the segmenters on the document, and clone them as needed (cloning
is much, much cheaper).
On a profile loading Ladybird's GitHub repo, the following hot methods
changed as follows:
ChunkIterator ctor: 6.08% -> 0.21%
Segmenter factory: 5.86% -> 0%
Segmenter clone: N/A -> 0.09%
(cherry picked from commit 5d7175874258f00763adcced230149dd1379e4a6;
mended as usual for Unicode::Segmenter -> Locale::Segmenter, and also
to resolve minor conflicts due to serenity not yet having
LadybirdBrowser/ladybird#1106. Also, due to serenity not using ICU,
this doesn't have a big performance effect over here, but it still
makes future cherry-picks easier)
Our current text iterator is not aware of multi-code point graphemes.
Instead of simply incrementing an iterator one code point at a time, use
our Unicode grapheme segmenter to break text into fragments.
(cherry picked from commit f0105b473b9cc3446ec36359b559db9a8e78446d;
amended as usual for Unicode::Segmenter -> Locale::Segmenter, and to
tweak expected/multi-code-point-graphemes.txt for serenity's superior
emoji glyphs)
Instead of recomputing boundaries on every iteration, this now
computes boundaries once and then searches that vector.
This is still O(n^2) for now, but already much faster (at the expense
of using O(n) memory): `BenchmarkSegmenter.for_each_boundary` stays
at around 3ms, but `forward` and `backward` go from ~13s to ~60ms
on my system.