Truly independent web browser
LibWeb: Don’t indicate script focus after a click moved focus
sideshowbarkerb70575d19bbf
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex e41415ab6b5..8a3cd31567f 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -979,6 +979,7 @@ void Document::visit_edges(Cell::Visitor& visitor)visitor.visit(m_focused_area);visitor.visit(m_sequential_focus_navigation_starting_point);visitor.visit(m_active_element);+ visitor.visit(m_focus_visibility_request_target);visitor.visit(m_target_element);visitor.visit(m_autofocus_candidates);visitor.visit(m_accessibility_focus_target);@@ -4200,6 +4201,37 @@ void Document::set_focused_area(GC::Ptr<Node> node, InvalidateFocusPseudoClassesm_writing_suggestion_controller->did_focus(m_focused_area);}+void Document::note_keyboard_interaction()+{+ if (!m_last_user_focus_was_by_pointer)+ return;+ auto indicated_focus = focused_element_indicates_focus();+ m_last_user_focus_was_by_pointer = false;+ publish_focus_visibility_change(indicated_focus);+}++void Document::request_focus_visibility_for_focused_element(bool focus_visible)+{+ auto indicated_focus = focused_element_indicates_focus();+ set_requested_focus_visibility(m_focused_area, focus_visible);+ publish_focus_visibility_change(indicated_focus);+}++bool Document::focused_element_indicates_focus() const+{+ auto const* focused_element = as_if<Element>(m_focused_area.ptr());+ return focused_element && focused_element->should_indicate_focus();+}++// The focused element's :focus-visible can change without focus moving, so the style engine has to hear the new state+// from the element rather than from a focus move.+void Document::publish_focus_visibility_change(bool indicated_focus_before)+{+ auto* focused_element = as_if<Element>(m_focused_area.ptr());+ if (focused_element && focused_element->should_indicate_focus() != indicated_focus_before)+ CSS::record_element_state_changed(*focused_element, CSS::PseudoClass::FocusVisible, !indicated_focus_before);+}+Element const* Document::active_element() const{return m_active_element ? m_active_element.ptr() : body();diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.hindex 7153d3e6e0c..64fd49943f8 100644--- a/Libraries/LibWeb/DOM/Document.h+++ b/Libraries/LibWeb/DOM/Document.h@@ -781,6 +781,32 @@ public:HTML::FocusTrigger last_focus_trigger() const { return m_last_focus_trigger; }void set_last_focus_trigger(HTML::FocusTrigger trigger) { m_last_focus_trigger = trigger; }+ // Whether the user last moved focus with a pointing device and hasn't used the keyboard since. Focus that a script+ // moves leaves this alone, since this decides whether that focus is indicated.+ bool last_user_focus_was_by_pointer() const { return m_last_user_focus_was_by_pointer; }+ void set_last_user_focus_was_by_pointer(bool value) { m_last_user_focus_was_by_pointer = value; }++ // Using the keyboard clears last_user_focus_was_by_pointer(), which can change whether the focused element matches+ // :focus-visible without focus moving.+ void note_keyboard_interaction();++ // The focusVisible option of the focus() call that last moved focus here, if it had one, for the element it focused.+ // Any other focus move here clears it, and it never applies to another element this document's focus moves to.+ Optional<bool> requested_focus_visibility_for(Node const& node) const+ {+ if (m_focus_visibility_request_target.ptr() != &node)+ return {};+ return m_requested_focus_visibility;+ }+ void set_requested_focus_visibility(GC::Ptr<Node> target, Optional<bool> value)+ {+ m_focus_visibility_request_target = value.has_value() ? target : nullptr;+ m_requested_focus_visibility = value.value_or(false);+ }++ // A focus() call with a focusVisible option on the element that already has focus applies the option to it.+ void request_focus_visibility_for_focused_element(bool focus_visible);+Element const* active_element() const;void set_active_element(GC::Ptr<Element>);@@ -1960,6 +1986,12 @@ private:GC::Ptr<Node> m_sequential_focus_navigation_starting_point;HTML::FocusTrigger m_last_focus_trigger { HTML::FocusTrigger::Other };+ bool m_last_user_focus_was_by_pointer { false };+ GC::Ptr<Node> m_focus_visibility_request_target;+ bool m_requested_focus_visibility { false };++ bool focused_element_indicates_focus() const;+ void publish_focus_visibility_change(bool indicated_focus_before);GC::Ptr<Element> m_active_element;GC::Ptr<Element> m_target_element;diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cppindex 975550e2245..3810d412f8d 100644--- a/Libraries/LibWeb/DOM/Element.cpp+++ b/Libraries/LibWeb/DOM/Element.cpp@@ -7259,6 +7259,11 @@ void Element::play_or_cancel_animations_after_display_property_change()// https://drafts.csswg.org/selectors/#indicate-focusbool Element::should_indicate_focus() const{+ // NB: When focus() moved focus with a focusVisible option, that option decides, ahead of every heuristic below.+ // https://html.spec.whatwg.org/multipage/interaction.html#dom-focus+ if (auto requested_focus_visibility = document().requested_focus_visibility_for(*this); requested_focus_visibility.has_value())+ return *requested_focus_visibility;+// User agents can choose their own heuristics for when to indicate focus; however, the following (non-normative)// suggestions can be used as a starting point for when to indicate focus on the currently focused element:@@ -7278,16 +7283,22 @@ bool Element::should_indicate_focus() constif (document().last_focus_trigger() == HTML::FocusTrigger::Key)return true;- // FIXME: * If the user interacts with the page via a pointing device (mouse, touchscreen, etc.) and the focused element+ // * If the user interacts with the page via a pointing device (mouse, touchscreen, etc.) and the focused element// does not support keyboard input, don’t indicate focus.+ // NB: Keyboard use while the element stays focused brings the indication back, per the suggestion above.+ if (document().last_focus_trigger() == HTML::FocusTrigger::Click)+ return !document().last_user_focus_was_by_pointer();// * If the previously-focused element indicated focus, and a script causes focus to move elsewhere, indicate focus// on the newly focused element.// Conversely, if the previously-focused element did not indicate focus, and a script causes focus to move// elsewhere, don’t indicate focus on the newly focused element.- // AD-HOC: Other browsers seem to always indicate focus on programmatically focused elements.+ // AD-HOC: Focus that a script moves follows how the user last moved focus, rather than whether the previously-+ // focused element indicated it: It isn't indicated if the user last moved focus with a pointing device and+ // hasn't used the keyboard since, even when the element clicked was a text control that indicated focus.+ // But focus that a script moves before the user has moved focus at all (while a page loads) is indicated.if (document().last_focus_trigger() == HTML::FocusTrigger::Script)- return true;+ return !document().last_user_focus_was_by_pointer();// FIXME: * If a newly-displayed element automatically gains focus (such as an action button in a freshly opened dialog),// that element should indicate focus.diff --git a/Libraries/LibWeb/HTML/Focus.cpp b/Libraries/LibWeb/HTML/Focus.cppindex 685b2e6f682..f37c0392d6e 100644--- a/Libraries/LibWeb/HTML/Focus.cpp+++ b/Libraries/LibWeb/HTML/Focus.cpp@@ -616,7 +616,7 @@ static GC::Ptr<DOM::Node> get_focusable_area(DOM::Node& focus_target, FocusTrigg// https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps// FIXME: This should accept more types.-void run_focusing_steps(GC::Ptr<DOM::Node> new_focus_target, GC::Ptr<DOM::Node> fallback_target, FocusTrigger focus_trigger, ScrollIntoView scroll_into_view)+void run_focusing_steps(GC::Ptr<DOM::Node> new_focus_target, GC::Ptr<DOM::Node> fallback_target, FocusTrigger focus_trigger, ScrollIntoView scroll_into_view, Optional<bool> focus_visible){// 1. If new focus target is not a focusable area, then set new focus target to the result of getting the focusable// area for new focus target, given focus trigger if it was passed.@@ -667,8 +667,13 @@ void run_focusing_steps(GC::Ptr<DOM::Node> new_focus_target, GC::Ptr<DOM::Node>auto root = focus_root(new_focus_target->document());if (!root)return;- if (new_focus_target.ptr() == root->currently_focused_area().ptr())+ if (new_focus_target.ptr() == root->currently_focused_area().ptr()) {+ // NB: focus()'s focusVisible option still applies to the element that already has focus, e.g. the delegate a+ // shadow host resolved to.+ if (focus_visible.has_value())+ new_focus_target->document().request_focus_visibility_for_focused_element(*focus_visible);return;+ }// 6. Let old chain be the current focus chain of the top-level browsing context in which// new focus target finds itself.@@ -679,6 +684,9 @@ void run_focusing_steps(GC::Ptr<DOM::Node> new_focus_target, GC::Ptr<DOM::Node>// AD-HOC: Remember last focus trigger for :focus-visible / focus indication.new_focus_target->document().set_last_focus_trigger(focus_trigger);+ new_focus_target->document().set_requested_focus_visibility(new_focus_target, focus_visible);+ if (focus_trigger == FocusTrigger::Click || focus_trigger == FocusTrigger::Key)+ new_focus_target->document().set_last_user_focus_was_by_pointer(focus_trigger == FocusTrigger::Click);// NB: The tab's focused navigable shows the walk below a top-level traversable another process hosts, and the other// pages of the tab follow it, so it moves to the navigable of new focus target before any focus event fires.diff --git a/Libraries/LibWeb/HTML/Focus.h b/Libraries/LibWeb/HTML/Focus.hindex 642d08b1742..b32645659e3 100644--- a/Libraries/LibWeb/HTML/Focus.h+++ b/Libraries/LibWeb/HTML/Focus.h@@ -23,7 +23,7 @@ enum class ScrollIntoView : u8 {WEB_API Vector<GC::Root<DOM::Node>> focus_chain(GC::Ptr<DOM::Node> subject);WEB_API void run_focus_update_steps(Vector<GC::Root<DOM::Node>> old_chain, Vector<GC::Root<DOM::Node>> new_chain, GC::Ptr<DOM::Node> new_focus_target);-WEB_API void run_focusing_steps(GC::Ptr<DOM::Node> new_focus_target, GC::Ptr<DOM::Node> fallback_target = nullptr, FocusTrigger focus_trigger = FocusTrigger::Other, ScrollIntoView = ScrollIntoView::Yes);+WEB_API void run_focusing_steps(GC::Ptr<DOM::Node> new_focus_target, GC::Ptr<DOM::Node> fallback_target = nullptr, FocusTrigger focus_trigger = FocusTrigger::Other, ScrollIntoView = ScrollIntoView::Yes, Optional<bool> focus_visible = {});WEB_API void run_unfocusing_steps(GC::Ptr<DOM::Node> old_focus_target);GC::Ptr<DOM::Node> focus_delegate(DOM::Node& focus_target, FocusTrigger = FocusTrigger::Other);void run_popover_focusing_steps(HTMLElement& subject);diff --git a/Libraries/LibWeb/HTML/HTMLOrSVGOrMathMLElement.cpp b/Libraries/LibWeb/HTML/HTMLOrSVGOrMathMLElement.cppindex 4c5d4ad069d..ab095003aad 100644--- a/Libraries/LibWeb/HTML/HTMLOrSVGOrMathMLElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLOrSVGOrMathMLElement.cpp@@ -89,8 +89,13 @@ void HTMLOrSVGOrMathMLElement<ElementBase>::focus(Bindings::FocusOptions const&// OPTIMIZATION: Checking whether an element is focusable may update its style. WebKit and Blink// also return before that check when focus() is called on the already-focused element.if (auto navigable = element.document().navigable()) {- if (navigable->top_level_traversable()->currently_focused_area() == GC::Ptr<DOM::Node> { element })+ if (navigable->top_level_traversable()->currently_focused_area() == GC::Ptr<DOM::Node> { element }) {+ // NB: Step 3 still applies to an element that already has focus, since it doesn't depend on the focusing+ // steps having moved focus.+ if (options.focus_visible.has_value())+ element.document().request_focus_visibility_for_focused_element(*options.focus_visible);return;+ }}// 2. Run the focusing steps for this.@@ -98,9 +103,11 @@ void HTMLOrSVGOrMathMLElement<ElementBase>::focus(Bindings::FocusOptions const&// "center".// NB: The scroll into view of step 4 is performed by the focus update steps, which scroll the newly focused// element into view for every way of focusing it.- run_focusing_steps(&element, nullptr, FocusTrigger::Script, options.prevent_scroll ? ScrollIntoView::No : ScrollIntoView::Yes);-- // FIXME: 3. If options["focusVisible"] is true, or does not exist but in an implementation-defined way the user agent determines it would be best to do so, then indicate focus.+ // 3. If options["focusVisible"] is true, or does not exist but in an implementation-defined way the user agent+ // determines it would be best to do so, then indicate focus.+ // NB: The focusing steps record the option, and Element::should_indicate_focus() answers with it while the element+ // stays focused.+ run_focusing_steps(&element, nullptr, FocusTrigger::Script, options.prevent_scroll ? ScrollIntoView::No : ScrollIntoView::Yes, options.focus_visible);}// https://html.spec.whatwg.org/multipage/interaction.html#dom-blurdiff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex b8be2a94a33..a550eef591c 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -1901,6 +1901,11 @@ EventResult EventHandler::handle_keydown(UIEvents::KeyCode key, u32 modifiers, uif (!m_navigable->active_document()->is_fully_active())return EventResult::Dropped;+ // Using the keyboard means focus is indicated again, even if a click moved it last. A shortcut, with Ctrl, Alt, or+ // Super held, doesn't count.+ if (!(modifiers & (UIEvents::KeyModifier::Mod_Alt | UIEvents::KeyModifier::Mod_Ctrl | UIEvents::KeyModifier::Mod_Super)))+ m_navigable->active_document()->note_keyboard_interaction();+if (should_ignore_device_input_event() && m_mousedown_target_is_drag_candidate && key == UIEvents::KeyCode::Key_Escape)return cancel_drag_and_drop_event(m_last_known_mouse_visual_viewport_position.value_or({}), m_last_known_mouse_screen_position, UIEvents::MouseButton::Primary, m_last_known_mouse_buttons, modifiers);diff --git a/Tests/LibWeb/Text/expected/focus-visible-after-keyboard-use-on-script-focused-element.txt b/Tests/LibWeb/Text/expected/focus-visible-after-keyboard-use-on-script-focused-element.txtnew file mode 100644index 00000000000..3df7c64ac4a--- /dev/null+++ b/Tests/LibWeb/Text/expected/focus-visible-after-keyboard-use-on-script-focused-element.txt@@ -0,0 +1,7 @@+After a click moved focus by script: focused=true, matches=false, outline=rgb(255, 0, 0)+After a Ctrl shortcut: focused=true, matches=false, outline=rgb(255, 0, 0)+After a key press: focused=true, matches=true, outline=rgb(0, 128, 0)+After another click moved focus by script: focused=true, matches=false, outline=rgb(255, 0, 0)+After focus({ focusVisible: true }) on the focused target: focused=true, matches=true, outline=rgb(0, 128, 0)+After focus({ focusVisible: false }) on the focused target: focused=true, matches=false, outline=rgb(255, 0, 0)+After a key press, with focusVisible: false still in effect: focused=true, matches=false, outline=rgb(255, 0, 0)diff --git a/Tests/LibWeb/Text/expected/focus-visible-request-applies-to-its-target.txt b/Tests/LibWeb/Text/expected/focus-visible-request-applies-to-its-target.txtnew file mode 100644index 00000000000..eab2cac234a--- /dev/null+++ b/Tests/LibWeb/Text/expected/focus-visible-request-applies-to-its-target.txt@@ -0,0 +1,4 @@+Button after focus({ focusVisible: false }): matches=false+Iframe after focus moved into it: focused=true, matches=true+Delegate after a click: focused=true, matches=false+Delegate after host.focus({ focusVisible: true }): matches=truediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-007.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-007.txtnew file mode 100644index 00000000000..86f22f471eb--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-007.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Using keyboard while element is focused should trigger :focus-visible; using mouse without moving focus should not cancel it; moving focus using mouse should cancel it.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-012.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-012.txtnew file mode 100644index 00000000000..f074b069249--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-012.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Keyboard focus should match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-021.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-021.txtnew file mode 100644index 00000000000..471aa6eb079--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-021.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Ctrl key doesn't make an element to stop matching :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-028.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-028.txtnew file mode 100644index 00000000000..e611134f5a4--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-028.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Programmatic focus after click and keyboard interaction should match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-004.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-004.txtnew file mode 100644index 00000000000..05eccfe5bc4--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-004.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after keyboard event does match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-005.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-005.txtnew file mode 100644index 00000000000..7162d88f96a--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-005.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after blur after keyboard event does match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-008-b.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-008-b.txtnew file mode 100644index 00000000000..a1fc06a022f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-008-b.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after mouse click on a button that does not match :focus-visible, does NOT match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-008.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-008.txtnew file mode 100644index 00000000000..5aac64dab5d--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-008.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-009.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-009.txtnew file mode 100644index 00000000000..fa8d83ca83f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-009.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after blur after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-010.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-010.txtnew file mode 100644index 00000000000..9cf64ed178f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-010.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after mouse click on a focusable element that matches :focus-visible, does NOT match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-011.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-011.txtnew file mode 100644index 00000000000..54b3a69c5d5--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-011.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after blur after mouse click on a focusable element that matches :focus-visible, does NOT match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-012.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-012.txtnew file mode 100644index 00000000000..efc6150f667--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-012.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after keyboard focus does match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-013.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-013.txtnew file mode 100644index 00000000000..5b6790b2984--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-013.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after blur after keyboard focus does match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-014.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-014.txtnew file mode 100644index 00000000000..f6a2f64ff15--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-014.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after keyboard input does match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-015.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-015.txtnew file mode 100644index 00000000000..2a4f74e2744--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-015.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after blur after keyboard input does match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-018.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-018.txtnew file mode 100644index 00000000000..94ec7aa7f4e--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-018.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after mouse click on a focusable element after editing an input does NOT match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-019.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-019.txtnew file mode 100644index 00000000000..0ed4d1d3d5e--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-019.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Script focus after blur after mouse click on a focusable element after editing an input does NOT match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-020.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-020.txtnew file mode 100644index 00000000000..555cb882dd0--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-visible-script-focus-020.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass ":focus-visible" should be a valid selector+Pass Double script focus after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/interaction/focus/processing-model/focusVisible.txt b/Tests/LibWeb/Text/expected/wpt-import/html/interaction/focus/processing-model/focusVisible.txtnew file mode 100644index 00000000000..ced20e16e9b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/interaction/focus/processing-model/focusVisible.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 5 tests++5 Pass+Pass FocusOptions.focusVisible: button+Pass FocusOptions.focusVisible: input+Pass FocusOptions.focusVisible: #contenteditable+Pass FocusOptions.focusVisible: #tabindex+Pass FocusOptions.focusVisible: #not_focusable\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/focus-visible-after-keyboard-use-on-script-focused-element.html b/Tests/LibWeb/Text/input/focus-visible-after-keyboard-use-on-script-focused-element.htmlnew file mode 100644index 00000000000..a5d6fb3597f--- /dev/null+++ b/Tests/LibWeb/Text/input/focus-visible-after-keyboard-use-on-script-focused-element.html@@ -0,0 +1,42 @@+<!DOCTYPE html>+<style>+ body { margin: 0; }+ button { display: block; width: 100px; height: 50px; }+ :focus-visible { outline: 3px solid rgb(0, 128, 0); }+ :focus:not(:focus-visible) { outline: 3px solid rgb(255, 0, 0); }+</style>+<button id="opener">Opener</button>+<button id="target">Target</button>+<script src="include.js"></script>+<script>+ test(() => {+ const opener = document.getElementById("opener");+ const target = document.getElementById("target");+ opener.addEventListener("click", () => target.focus());++ const report = label => {+ println(`${label}: focused=${document.activeElement === target}, matches=${target.matches(":focus-visible")}, outline=${getComputedStyle(target).outlineColor}`);+ };++ internals.click(50, 25);+ report("After a click moved focus by script");++ internals.sendKey(target, "A", internals.MOD_CTRL);+ report("After a Ctrl shortcut");++ internals.sendKey(target, "LeftShift");+ report("After a key press");++ internals.click(50, 25);+ report("After another click moved focus by script");++ target.focus({ focusVisible: true });+ report("After focus({ focusVisible: true }) on the focused target");++ target.focus({ focusVisible: false });+ report("After focus({ focusVisible: false }) on the focused target");++ internals.sendKey(target, "LeftShift");+ report("After a key press, with focusVisible: false still in effect");+ });+</script>diff --git a/Tests/LibWeb/Text/input/focus-visible-request-applies-to-its-target.html b/Tests/LibWeb/Text/input/focus-visible-request-applies-to-its-target.htmlnew file mode 100644index 00000000000..7a30bf65b62--- /dev/null+++ b/Tests/LibWeb/Text/input/focus-visible-request-applies-to-its-target.html@@ -0,0 +1,34 @@+<!DOCTYPE html>+<style>+ body { margin: 0; }+ button, iframe, #host { display: block; width: 100px; height: 50px; border: 0; }+</style>+<button id="button">Button</button>+<iframe id="frame" srcdoc="<button id=inner>Inner</button>"></iframe>+<div id="host"></div>+<script src="include.js"></script>+<script>+ asyncTest(done => {+ const button = document.getElementById("button");+ const frame = document.getElementById("frame");+ const host = document.getElementById("host");+ const shadow = host.attachShadow({ mode: "open", delegatesFocus: true });+ shadow.innerHTML = "<button style='width: 100px; height: 50px'>Delegate</button>";+ const delegate = shadow.querySelector("button");++ window.addEventListener("load", () => {+ button.focus({ focusVisible: false });+ println(`Button after focus({ focusVisible: false }): matches=${button.matches(":focus-visible")}`);++ frame.contentDocument.getElementById("inner").focus();+ println(`Iframe after focus moved into it: focused=${document.activeElement === frame}, matches=${frame.matches(":focus-visible")}`);++ internals.click(50, 125);+ println(`Delegate after a click: focused=${shadow.activeElement === delegate}, matches=${delegate.matches(":focus-visible")}`);++ host.focus({ focusVisible: true });+ println(`Delegate after host.focus({ focusVisible: true }): matches=${delegate.matches(":focus-visible")}`);+ done();+ });+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-007.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-007.htmlnew file mode 100644index 00000000000..97b4f0178d9--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-007.html@@ -0,0 +1,85 @@+<!DOCTYPE html>+<html>+<head>+ <meta charset="utf-8" />+ <title>CSS Test (Selectors): Keyboard use triggers :focus-visible</title>+ <link rel="author" title="Alice Boxhall" href="[email protected]" />+ <link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+ <script src="../../resources/testharness.js"></script>+ <script src="../../resources/testharnessreport.js"></script>+ <script src="../../resources/testdriver.js"></script>+ <script src="../../resources/testdriver-vendor.js"></script>+ <style>+ [data-hadkeydown] :focus-visible {+ outline: green solid 5px;+ }++ [data-hadmousedown] :focus-visible {+ outline: red solid 5px;+ }++ [data-hadkeydown] :focus:not(:focus-visible) {+ outline: 0;+ background-color: red;+ }++ [data-hadmousedown] :focus:not(:focus-visible) {+ outline: 0;+ background-color: lime;+ }++ </style>+</head>+<body>+ This test checks that using the keyboard in a way that does not move focus still causes <code>:focus-visible</code> matching to trigger.+ <ol id="instructions">+ <li>If the user-agent does not claim to support the <code>:focus-visible</code> pseudo-class then SKIP this test.</li>+ <li>Use the mouse to focus the element below that says "Click me."</li>+ <li>If the element has a red outline, then the test result is FAILURE.</li>+ <li>Press the ENTER key.</li>+ <li>If the element now has a green outline and not red background, then the test result is SUCCESS.</li>+ </ol>++ <div id="one" tabindex="0">Click me.</div>+ <script>+ setup({ explicit_done: true });++ document.body.addEventListener("keydown", (e) => {+ delete document.body.dataset.hadmousedown;+ document.body.dataset.hadkeydown = "";+ }, true);++ document.body.addEventListener("mousedown", (e) => {+ delete document.body.dataset.hadkeydown;+ document.body.dataset.hadmousedown = "";+ }, true);++ async_test(function(t) {+ let tested_initial_focus = false;++ const handle_initial_focus = t.step_func(() => {+ tested_initial_focus = true;+ assert_equals(getComputedStyle(one).backgroundColor, "rgb(0, 255, 0)");+ assert_not_equals(getComputedStyle(one).outlineColor, "rgb(255, 0, 0)");++ one.addEventListener("keyup", t.step_func(test_modality_change));+ one.removeEventListener("focus", handle_initial_focus);++ const enter = "\uE007";+ test_driver.send_keys(one, enter);+ });++ const test_modality_change = t.step_func(() => {+ assert_true(tested_initial_focus);+ one.removeEventListener("keyup", test_modality_change);+ assert_equals(getComputedStyle(one).outlineColor, "rgb(0, 128, 0)");+ assert_not_equals(getComputedStyle(one).backgroundColor, "rgb(255, 0, 0)");+ t.done();+ });++ one.addEventListener("focus", handle_initial_focus);+ test_driver.click(one).then(() => done());+ }, "Using keyboard while element is focused should trigger :focus-visible; using mouse without moving focus should not cancel it; moving focus using mouse should cancel it.");+ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-012.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-012.htmlnew file mode 100644index 00000000000..e34b32dfa0c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-012.html@@ -0,0 +1,69 @@+<!DOCTYPE html>+<html>+<head>+ <meta charset="utf-8" />+ <title>CSS Test (Selectors): Keyboard shortcut combinations do not trigger :focus-visible</title>+ <link rel="author" title="Alice Boxhall" href="[email protected]" />+ <link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+ <script src="../../resources/testharness.js"></script>+ <script src="../../resources/testharnessreport.js"></script>+ <script src="../../resources/testdriver.js"></script>+ <script src="../../resources/testdriver-actions.js"></script>+ <script src="../../resources/testdriver-vendor.js"></script>+ <style>+ @supports not selector(:focus-visible) {+ :focus {+ outline: red solid 5px;+ background-color: red;+ }+ }++ :focus-visible {+ outline: 0;+ outline-color: red;+ background-color: red;+ }++ :focus:not(:focus-visible) {+ outline: green solid 5px;+ }+ </style>+</head>+<body>+ This test checks that using keyboard combinations with [Ctrl], [Alt] or [Cmd]+ do not trigger <code>:focus-visible</code> matching.+ <ol id="instructions">+ <li>If the user-agent does not claim to support the <code>:focus-visible</code> pseudo-class then SKIP this test.</li>+ <li>Click the element below that says "Click me, then use a keyboard shortcut."</li>+ <li>Press a keyboard combination including [Ctrl], [Alt] or [Cmd], such as <code>Ctrl</code> + <code>y</code></li>+ <li>If the element has a red background, then the test result is FAILURE. If the element has a green outline, then the test result is SUCCESS.</li>+ </ol>+ <br>+ <div id="el" tabindex="0">Click me, then use a keyboard shortcut.</div>+ <script>+ var t = async_test( "Keyboard focus should match :focus-visible");++ el.addEventListener("click", t.step_func(function(e) {+ assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${el.tagName}#${el.id} should be green`);+ assert_not_equals(getComputedStyle(el).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${el.tagName}#${el.id} should NOT be red`);+ }), true);++ el.addEventListener("keydown", t.step_func(function(e) {+ if (e.altKey || e.ctrlKey || e.metaKey) {+ assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${el.tagName}#${el.id} should be green`);+ assert_not_equals(getComputedStyle(el).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${el.tagName}#${el.id} should NOT be red`);+ t.done();+ return;+ }+ assert_true(false, "No modifier key");+ t.done();+ }));++ const ctrl_key = '\uE009';+ test_driver.click(el).then(() => {+ return test_driver.send_keys(el, ctrl_key);+ });++ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-021.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-021.htmlnew file mode 100644index 00000000000..f66fb49d1f5--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-021.html@@ -0,0 +1,67 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Modifier key doesn't make element to stop matching :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick green;+ }++ :focus:not(:focus-visible) {+ outline: none;+ background-color: red;+ }+</style>++This test checks that using a modifier key does not make the element to stop matching <code>:focus-visible</code>.+<ol id="instructions">+ <li>If the element that says "Focused" has a red background, then the test result is a FAILURE.</li>+ <li>Press the Ctrl key.</li>+ <li>If the element keeps the green outline and has not a red background, then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<div id="target" tabindex="0">Focused</div>+<script>+ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ async_test(function(t) {+ target.addEventListener("focus", t.step_func(() => {+ assert_equals(getComputedStyle(target).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${target.tagName}#${target.id} should be green`);+ assert_not_equals(getComputedStyle(target).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${target.tagName}#${target.id} should NOT be red`);++ const ctrl_key = '\uE009';+ test_driver.send_keys(target, ctrl_key);+ }));++ target.addEventListener("keyup", t.step_func_done(() => {+ assert_equals(getComputedStyle(target).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${target.tagName}#${target.id} should be green`);+ assert_not_equals(getComputedStyle(target).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ }, "Ctrl key doesn't make an element to stop matching :focus-visible");++ target.focus();+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-028.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-028.htmlnew file mode 100644index 00000000000..24c53ed63d2--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-028.html@@ -0,0 +1,84 @@+<!DOCTYPE html>+<html>+<head>+ <meta charset="utf-8" />+ <title>CSS Test (Selectors): Programmatic focus causes :focus-visible to match after keyboard usage when preventDefault() is used</title>+ <link rel="author" title="Tyler Jones" href="[email protected]" />+ <link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+ <script src="../../resources/testharness.js"></script>+ <script src="../../resources/testharnessreport.js"></script>+ <script src="../../resources/testdriver.js"></script>+ <script src="../../resources/testdriver-vendor.js"></script>+ <style>+ @supports not selector(:focus-visible) {+ :focus {+ outline: red solid 5px;+ background-color: red;+ }+ }++ :focus-visible {+ outline: blue solid 5px;+ }++ :focus:not(:focus-visible) {+ outline: 0;+ background-color: lime;+ }+ </style>+</head>+<body>+ This test checks that programmatically focusing an element after a click and using keyboard afterwards triggers <code>:focus-visible</code> matching.+ <ol id="instructions">+ <li>If the user-agent does not claim to support the <code>:focus-visible</code> pseudo-class then SKIP this test.</li>+ <li>Click the button below that says "Click me".</li>+ <li>Once focused on the button that says "I will be focused programmatically", use "Left" or "Right" arrow keys to navigate through the button group</li>+ <li>If any button within the group has a blue outline after using either arrow key, then the test result is SUCCESS. If the element has a green background after using either arrow key, then the test result is FAILURE.</li>+ </ol>+ <br />+ <button id="button">Click me</button>+ <div id="container">+ <button id="btn1">I will be focused programmatically.</button>+ <button id="btn2">Button 2</button>+ <button id="btn3">Button 3</button>+ </div>+ <script>+ button.addEventListener("click", () => {+ btn1.focus();+ });++ focusTrap(document.querySelector('#container'));++ function focusTrap(container) {+ container.addEventListener('keydown', (e) => {+ if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft') return;+ e.preventDefault();++ const btns = container.querySelectorAll('button');+ const currentIndex = Array.from(btns).indexOf(document.activeElement);+ let nextIndex;++ if (e.key === 'ArrowRight') {+ nextIndex = (currentIndex + 1) % btns.length;+ } else if (e.key === 'ArrowLeft') {+ nextIndex = (currentIndex - 1 + btns.length) % btns.length;+ }++ btns[nextIndex].focus();+ });+ }++ promise_test(async t => {+ const arrow_right = "\uE014";+ btn2.addEventListener("focus", t.step_func_done((e) => {+ assert_equals(getComputedStyle(btn2).outlineColor, "rgb(0, 0, 255)", `outlineColor for ${btn2.tagName}#${btn2.id} is blue`);+ assert_not_equals(getComputedStyle(btn2).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${btn2.tagName}#${btn2.id} is NOT lime`);+ }));++ await test_driver.click(button);+ assert_equals(document.activeElement, btn1);+ await test_driver.send_keys(btn1, arrow_right);+ }, "Programmatic focus after click and keyboard interaction should match :focus-visible");+ </script>+</body>+</html>\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-004.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-004.htmlnew file mode 100644index 00000000000..f985a413edc--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-004.html@@ -0,0 +1,62 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after keyboard input does match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick green;+ }++ :focus:not(:focus-visible) {+ background-color: red;+ }+</style>++<p>This test checks that a script focus after a keyboard input does match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Type some letter with the keyboard without having done anything before.</li>+ <li>If the element that says "Focused" has a red background then the test result is FAILURE, if it has a green outline then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<div id="target" tabindex="0">Focused</div>++<script>+ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ document.addEventListener("keypress", () => {+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${target.tagName}#${target.id} should be green`);+ assert_not_equals(getComputedStyle(target).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ test_driver.send_keys(document.body, "a");+ }, "Script focus after keyboard event does match :focus-visible");+</script>+diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-005.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-005.htmlnew file mode 100644index 00000000000..4d2f209027e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-005.html@@ -0,0 +1,63 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after blur after keyboard input does match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick green;+ }++ :focus:not(:focus-visible) {+ background-color: red;+ }+</style>++<p>This test checks that a script focus after blur after a keyboard input does match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Type some letter with the keyboard without having done anything before.</li>+ <li>If the element that says "Focused" has a red background then the test result is FAILURE, if it has a green outline then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<div id="target" tabindex="0">Focused</div>++<script>+ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ document.addEventListener("keypress", () => {+ document.activeElement.blur();+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${target.tagName}#${target.id} should be green`);+ assert_not_equals(getComputedStyle(target).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ test_driver.send_keys(document.body, "a");+ }, "Script focus after blur after keyboard event does match :focus-visible");+</script>+diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-008-b.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-008-b.htmlnew file mode 100644index 00000000000..cdd0597f779--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-008-b.html@@ -0,0 +1,64 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after mouse click on a button that does not match :focus-visible, does NOT match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick red;+ }++ :focus:not(:focus-visible) {+ background-color: lime;+ }+</style>++<p>This test checks that a script focus after a mouse click on a button that does not match <code>:focus visible</code>, does NOT match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Click on the button that says "Click me".</li>+ <li>If the element that says "Focused" has a red outline then the test result is FAILURE, if it has a green background then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<button id="initial">Click me</button>+<div id="target" tabindex="0">Focused</div>++<script>+ setup({ explicit_done: true });++ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ initial.addEventListener("click", () => {+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`);+ assert_not_equals(getComputedStyle(target).outlineColor, "rgb(255, 0, 0)", `outlineColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ test_driver.click(initial).then(() => done());+ }, "Script focus after mouse click on a button that does not match :focus-visible, does NOT match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-008.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-008.htmlnew file mode 100644index 00000000000..76540b05430--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-008.html@@ -0,0 +1,64 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick red;+ }++ :focus:not(:focus-visible) {+ background-color: lime;+ }+</style>++<p>This test checks that a script focus after a mouse click on a focusable element that does not match <code>:focus visible</code>, does NOT match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Click on the element that says "Click me".</li>+ <li>If the element that says "Focused" has a red outline then the test result is FAILURE, if it has a green background then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<div id="initial" tabindex="0">Click me</div>+<div id="target" tabindex="0">Focused</div>++<script>+ setup({ explicit_done: true });++ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ initial.addEventListener("click", () => {+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`);+ assert_not_equals(getComputedStyle(target).outlineColor, "rgb(255, 0, 0)", `outlineColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ test_driver.click(initial).then(() => done());+ }, "Script focus after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-009.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-009.htmlnew file mode 100644index 00000000000..f00e38723fb--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-009.html@@ -0,0 +1,65 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after blur after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick red;+ }++ :focus:not(:focus-visible) {+ background-color: lime;+ }+</style>++<p>This test checks that a script focus after blur after a mouse click on a focusable element that does not match <code>:focus visible</code>, does NOT match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Click on the element that says "Click me".</li>+ <li>If the element that says "Focused" has a red outline then the test result is FAILURE, if it has a green background then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<div id="initial" tabindex="0">Click me</div>+<div id="target" tabindex="0">Focused</div>++<script>+ setup({ explicit_done: true });++ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ initial.addEventListener("click", () => {+ document.activeElement.blur();+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`);+ assert_not_equals(getComputedStyle(target).outlineColor, "rgb(255, 0, 0)", `outlineColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ test_driver.click(initial).then(() => done());+ }, "Script focus after blur after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-010.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-010.htmlnew file mode 100644index 00000000000..6cc38de04a4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-010.html@@ -0,0 +1,64 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after mouse click on a focusable element that matches :focus-visible, does NOT match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick red;+ }++ :focus:not(:focus-visible) {+ background-color: lime;+ }+</style>++<p>This test checks that a script focus after a mouse click on a focusable element that matches <code>:focus visible</code>, does NOT match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Click on the element that says "Click me".</li>+ <li>If the element that says "Focused" has a red outline then the test result is FAILURE, if it has a green background then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<input id="initial" value="Click me">+<div id="target" tabindex="0">Focused</div>++<script>+ setup({ explicit_done: true });++ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ initial.addEventListener("click", () => {+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`);+ assert_not_equals(getComputedStyle(target).outlineColor, "rgb(255, 0, 0)", `outlineColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ test_driver.click(initial).then(() => done());+ }, "Script focus after mouse click on a focusable element that matches :focus-visible, does NOT match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-011.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-011.htmlnew file mode 100644index 00000000000..7ea71dc5ab6--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-011.html@@ -0,0 +1,65 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after blur after mouse click on a focusable element that matches :focus-visible, does NOT match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick red;+ }++ :focus:not(:focus-visible) {+ background-color: lime;+ }+</style>++<p>This test checks that a script focus after blur after a mouse click on a focusable element that matches <code>:focus visible</code>, does NOT match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Click on the element that says "Click me".</li>+ <li>If the element that says "Focused" has a red outline then the test result is FAILURE, if it has a green background then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<input id="initial" value="Click me">+<div id="target" tabindex="0">Focused</div>++<script>+ setup({ explicit_done: true });++ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ initial.addEventListener("click", () => {+ document.activeElement.blur();+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`);+ assert_not_equals(getComputedStyle(target).outlineColor, "rgb(255, 0, 0)", `outlineColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ test_driver.click(initial).then(() => done());+ }, "Script focus after blur after mouse click on a focusable element that matches :focus-visible, does NOT match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-012.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-012.htmlnew file mode 100644index 00000000000..99ac6db1e7b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-012.html@@ -0,0 +1,63 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after keyboard focus does match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick green;+ }++ :focus:not(:focus-visible) {+ background-color: red;+ }+</style>++<p>This test checks that a script focus after a keyboard focus does match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Type TAB key.</li>+ <li>If the element that says "Focused" has a red background then the test result is FAILURE, if it has a green outline then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<div id="initial" tabindex="0">Focus me</div>+<div id="target" tabindex="0">Focused</div>++<script>+ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ initial.addEventListener("focus", () => {+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${target.tagName}#${target.id} should be green`);+ assert_not_equals(getComputedStyle(target).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ const tab_key = "\ue004";+ test_driver.send_keys(document.body, tab_key);+ }, "Script focus after keyboard focus does match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-013.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-013.htmlnew file mode 100644index 00000000000..12f4aa0466a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-013.html@@ -0,0 +1,64 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after blur after keyboard focus does match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick green;+ }++ :focus:not(:focus-visible) {+ background-color: red;+ }+</style>++<p>This test checks that a script focus after blur after a keyboard focus does match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Type TAB key.</li>+ <li>If the element that says "Focused" has a red background then the test result is FAILURE, if it has a green outline then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<div id="initial" tabindex="0">Focus me</div>+<div id="target" tabindex="0">Focused</div>++<script>+ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ initial.addEventListener("focus", () => {+ document.activeElement.blur();+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${target.tagName}#${target.id} should be green`);+ assert_not_equals(getComputedStyle(target).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ const tab_key = "\ue004";+ test_driver.send_keys(document.body, tab_key);+ }, "Script focus after blur after keyboard focus does match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-014.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-014.htmlnew file mode 100644index 00000000000..f88cff4e37e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-014.html@@ -0,0 +1,63 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after keyboard input does match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick green;+ }++ :focus:not(:focus-visible) {+ background-color: red;+ }+</style>++<p>This test checks that a script focus after a keyboard input does match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Click on the input below and type some letter.</li>+ <li>If the element that says "Focused" has a red background then the test result is FAILURE, if it has a green outline then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<input id="initial">+<div id="target" tabindex="0">Focused</div>++<script>+ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ initial.addEventListener("keypress", () => {+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${target.tagName}#${target.id} should be green`);+ assert_not_equals(getComputedStyle(target).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ initial.focus();+ test_driver.send_keys(initial, "a");+ }, "Script focus after keyboard input does match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-015.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-015.htmlnew file mode 100644index 00000000000..9ca95783843--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-015.html@@ -0,0 +1,64 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after blur after keyboard input does match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick green;+ }++ :focus:not(:focus-visible) {+ background-color: red;+ }+</style>++<p>This test checks that a script focus after blur after a keyboard input does match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Click on the input below and type some letter.</li>+ <li>If the element that says "Focused" has a red background then the test result is FAILURE, if it has a green outline then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<input id="initial">+<div id="target" tabindex="0">Focused</div>++<script>+ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ initial.addEventListener("keypress", () => {+ document.activeElement.blur();+ target.focus();+ });++ async_test(function(t) {+ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${target.tagName}#${target.id} should be green`);+ assert_not_equals(getComputedStyle(target).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ initial.focus();+ test_driver.send_keys(initial, "a");+ }, "Script focus after blur after keyboard input does match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-018.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-018.htmlnew file mode 100644index 00000000000..b98da94c895--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-018.html@@ -0,0 +1,71 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after mouse click on a focusable element after editing an input does NOT match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick red;+ }++ :focus:not(:focus-visible) {+ background-color: lime;+ }+</style>++<p>This test checks that a script focus after a mouse click on a focusable element after editing an input does NOT match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Click on the input below and type some letter.</li>+ <li>Then click on the element that says "Click me".</li>+ <li>If the element that says "Focused" has a red outline then the test result is FAILURE, if it has a green background then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<input id="initial">+<div id="trigger" tabindex="0">Click me</div>+<div id="target" tabindex="0">Focused</div>++<script>+ setup({ explicit_done: true });++ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ trigger.addEventListener("click", () => {+ target.focus();+ });++ async_test(function(t) {+ initial.addEventListener("keypress", () => {+ test_driver.click(trigger).then(() => done());+ });++ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`);+ assert_not_equals(getComputedStyle(target).outlineColor, "rgb(255, 0, 0)", `outlineColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ initial.focus();+ test_driver.send_keys(initial, "a");+ }, "Script focus after mouse click on a focusable element after editing an input does NOT match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-019.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-019.htmlnew file mode 100644index 00000000000..2b5a5c9e43a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-019.html@@ -0,0 +1,72 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Script focus after blur after mouse click on a focusable element after editing an input does NOT match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick red;+ }++ :focus:not(:focus-visible) {+ background-color: lime;+ }+</style>++<p>This test checks that a script focus after blur after a mouse click on a focusable element after editing an input does NOT match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Click on the input below and type some letter.</li>+ <li>Then click on the element that says "Click me".</li>+ <li>If the element that says "Focused" has a red outline then the test result is FAILURE, if it has a green background then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<input id="initial">+<div id="trigger" tabindex="0">Click me</div>+<div id="target" tabindex="0">Focused</div>++<script>+ setup({ explicit_done: true });++ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ trigger.addEventListener("click", () => {+ document.activeElement.blur();+ target.focus();+ });++ async_test(function(t) {+ initial.addEventListener("keypress", () => {+ test_driver.click(trigger).then(() => done());+ });++ target.addEventListener("focus", t.step_func_done(function() {+ assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`);+ assert_not_equals(getComputedStyle(target).outlineColor, "rgb(255, 0, 0)", `outlineColor for ${target.tagName}#${target.id} should NOT be red`);+ }));++ initial.focus();+ test_driver.send_keys(initial, "a");+ }, "Script focus after blur after mouse click on a focusable element after editing an input does NOT match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-020.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-020.htmlnew file mode 100644index 00000000000..1ebc5faaa18--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-script-focus-020.html@@ -0,0 +1,70 @@+<!DOCTYPE html>+<meta charset="utf-8" />+<title>CSS Test (Selectors): Double script focus after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible</title>+<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/testdriver.js"></script>+<script src="../../resources/testdriver-vendor.js"></script>+<script src="../../css/support/parsing-testcommon.js"></script>+<style>+ #warning {+ display: none;+ background: red;+ }++ @supports not selector(:focus-visible) {+ #instructions {+ display: none;+ }++ #warning {+ display: block;+ }+ }++ :focus-visible {+ outline: solid thick red;+ }++ :focus:not(:focus-visible) {+ background-color: lime;+ }+</style>++<p>This test checks that a double script focus after a mouse click on a focusable element that does not match <code>:focus visible</code>, does NOT match <code>:focus-visible</code>.</p>+<ol id="instructions">+ <li>Click on the element that says "Click me".</li>+ <li>If the element that says "Focused" has a red outline then the test result is FAILURE, if it has a green background then the test result is SUCCESS.</li>+</ol>+<p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>++<div id="initial" tabindex="0">Click me</div>+<div id="target" tabindex="0">Focused</div>++<script>+ setup({ explicit_done: true });++ // Check that :focus-visible is supported.+ test_valid_selector(':focus-visible');++ initial.addEventListener("click", () => {+ target.focus();+ target.blur();+ target.focus();+ });++ async_test(function(t) {+ let count = 0;+ target.addEventListener("focus", t.step_func(function() {+ assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`);+ assert_not_equals(getComputedStyle(target).outlineColor, "rgb(255, 0, 0)", `outlineColor for ${target.tagName}#${target.id} should NOT be red`);+ if (count > 0)+ t.done();+ count++;+ }));++ test_driver.click(initial).then(() => done());+ }, "Double script focus after mouse click on a focusable element that does not match :focus-visible, does NOT match :focus-visible");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/interaction/focus/processing-model/focusVisible.html b/Tests/LibWeb/Text/input/wpt-import/html/interaction/focus/processing-model/focusVisible.htmlnew file mode 100644index 00000000000..533e7603a53--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/interaction/focus/processing-model/focusVisible.html@@ -0,0 +1,65 @@+<!doctype html>++<title>focus(options) - focusVisible</title>+<script src=../../../../resources/testharness.js></script>+<script src=../../../../resources/testharnessreport.js></script>+<script src="../../../../resources/testdriver.js"></script>+<script src="../../../../resources/testdriver-actions.js"></script>+<script src="../../../../resources/testdriver-vendor.js"></script>++<style>+ div {+ height: 10px;+ border: 1px solid black;+ }+</style>++<button>ABC</button>+<input>+<div id="contenteditable" contenteditable></div>+<div id="tabindex" tabindex=0></div>+<div id="not_focusable"></div>++<div id="reset_focus" tabindex=0></div>++<script>+const reset_focus = document.getElementById("reset_focus");++async function check_focus_visible(element, options, { shouldBeVisible, shouldBeFocused }) {+ // Reset focus by clicking on a div, which should not show focus rings.+ await test_driver.click(reset_focus);++ assert_equals(document.activeElement, reset_focus, "Reset should be focused");+ assert_true(reset_focus.matches(":focus"), "Clicking focusable div should match :focus");+ assert_false(reset_focus.matches(":focus-visible"), "Clicking focusable div shouldn't match :focus-visible");++ element.focus(options);++ assert_equals(document.activeElement, shouldBeFocused ? element : reset_focus, "activeElement");+ assert_equals(element.matches(":focus"), shouldBeFocused, ":focus");+ assert_equals(element.matches(":focus-visible"), shouldBeVisible, ":focus-visible");+}++for (let selector of ["button", "input", "#contenteditable", "#tabindex", "#not_focusable"]) {+ promise_test(async function() {+ const takesKeyboardInput = selector == "#contenteditable" || selector == "input";+ const shouldBeFocused = selector != "#not_focusable";++ const element = document.querySelector(selector);++ await check_focus_visible(element, {}, {+ shouldBeVisible: takesKeyboardInput,+ shouldBeFocused,+ });++ await check_focus_visible(element, { focusVisible: true }, {+ shouldBeVisible: shouldBeFocused,+ shouldBeFocused,+ });+ await check_focus_visible(element, { focusVisible: false }, {+ shouldBeVisible: false,+ shouldBeFocused,+ });+ }, "FocusOptions.focusVisible: " + selector);+}+</script>