1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 04:34:58 +00:00
serenity/Userland/Libraries/LibWeb/Internals/Internals.cpp
Timothy Flynn e52c30cbd5 LibWeb: Allow bypassing transient activation checks for tests
We have a 5 second timeout between a user-activated event occurring and
an activation-gated API being invoked in order for that API to succeed.
This is quite fine in normal circumstances, but the machines used in CI
often exceed that limit (we see upwards of 10 seconds passing between
generating the user-activated event and the API call running).

So instead of generating a user-activated event, add a hook to allow
tests to bypass the very next activation check.
2024-02-20 18:53:59 -05:00

92 lines
2.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/VM.h>
#include <LibWeb/Bindings/InternalsPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Internals/Internals.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Painting/ViewportPaintable.h>
namespace Web::Internals {
JS_DEFINE_ALLOCATOR(Internals);
Internals::Internals(JS::Realm& realm)
: Bindings::PlatformObject(realm)
{
}
Internals::~Internals() = default;
void Internals::initialize(JS::Realm& realm)
{
Base::initialize(realm);
Object::set_prototype(&Bindings::ensure_web_prototype<Bindings::InternalsPrototype>(realm, "Internals"_fly_string));
}
void Internals::signal_text_test_is_done()
{
global_object().browsing_context()->page().client().page_did_finish_text_test();
}
void Internals::gc()
{
vm().heap().collect_garbage();
}
JS::Object* Internals::hit_test(double x, double y)
{
auto* active_document = global_object().browsing_context()->top_level_browsing_context()->active_document();
// NOTE: Force a layout update just before hit testing. This is because the current layout tree, which is required
// for stacking context traversal, might not exist if this call occurs between the tear_down_layout_tree()
// and update_layout() calls
active_document->update_layout();
auto result = active_document->paintable_box()->hit_test({ x, y }, Painting::HitTestType::Exact);
if (result.has_value()) {
auto hit_tеsting_result = JS::Object::create(realm(), nullptr);
hit_tеsting_result->define_direct_property("node", result->dom_node(), JS::default_attributes);
hit_tеsting_result->define_direct_property("indexInNode", JS::Value(result->index_in_node), JS::default_attributes);
return hit_tеsting_result;
}
return nullptr;
}
void Internals::send_text(HTML::HTMLElement& target, String const& text)
{
auto& page = global_object().browsing_context()->page();
target.focus();
for (auto code_point : text.code_points())
page.handle_keydown(code_point_to_key_code(code_point), 0, code_point);
}
void Internals::commit_text()
{
global_object().browsing_context()->page().handle_keydown(Key_Return, 0, 0);
}
void Internals::click(double x, double y)
{
auto& page = global_object().browsing_context()->page();
page.handle_mousedown({ x, y }, { x, y }, 1, 0, 0);
page.handle_mouseup({ x, y }, { x, y }, 1, 0, 0);
}
void Internals::wheel(double x, double y, double delta_x, double delta_y)
{
auto& page = global_object().browsing_context()->page();
page.handle_mousewheel({ x, y }, { x, y }, 0, 0, 0, delta_x, delta_y);
}
}