2022-11-08 10:03:07 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
|
|
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
2024-09-29 09:40:17 -04:00
|
|
|
* Copyright (c) 2022-2024, Tim Flynn <trflynn89@ladybird.org>
|
2022-11-08 10:03:07 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-12-16 09:19:34 -05:00
|
|
|
#include <AK/ByteString.h>
|
2022-11-21 09:51:46 -05:00
|
|
|
#include <AK/Function.h>
|
2022-11-14 11:55:10 -05:00
|
|
|
#include <AK/HashMap.h>
|
2023-03-05 15:31:49 -05:00
|
|
|
#include <AK/String.h>
|
2023-02-25 12:43:09 -05:00
|
|
|
#include <LibGfx/Rect.h>
|
2022-11-08 10:03:07 -05:00
|
|
|
#include <LibIPC/ConnectionToServer.h>
|
2022-11-10 20:55:17 -05:00
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
#include <LibJS/Heap/MarkedVector.h>
|
2022-11-09 15:02:38 -05:00
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
#include <LibWeb/WebDriver/ElementLocationStrategies.h>
|
2022-11-08 10:03:07 -05:00
|
|
|
#include <LibWeb/WebDriver/Response.h>
|
2022-11-11 14:28:57 -05:00
|
|
|
#include <LibWeb/WebDriver/TimeoutsConfiguration.h>
|
2022-11-08 10:03:07 -05:00
|
|
|
#include <WebContent/Forward.h>
|
|
|
|
#include <WebContent/WebDriverClientEndpoint.h>
|
|
|
|
#include <WebContent/WebDriverServerEndpoint.h>
|
|
|
|
|
|
|
|
namespace WebContent {
|
|
|
|
|
|
|
|
class WebDriverConnection final
|
|
|
|
: public IPC::ConnectionToServer<WebDriverClientEndpoint, WebDriverServerEndpoint> {
|
2022-12-15 08:44:10 -05:00
|
|
|
C_OBJECT_ABSTRACT(WebDriverConnection)
|
2022-11-08 10:03:07 -05:00
|
|
|
|
|
|
|
public:
|
2023-12-16 09:19:34 -05:00
|
|
|
static ErrorOr<NonnullRefPtr<WebDriverConnection>> connect(Web::PageClient& page_client, ByteString const& webdriver_ipc_path);
|
2022-11-08 10:03:07 -05:00
|
|
|
virtual ~WebDriverConnection() = default;
|
|
|
|
|
2024-10-17 18:50:36 -04:00
|
|
|
void visit_edges(JS::Cell::Visitor&);
|
|
|
|
|
2024-10-25 10:28:29 -04:00
|
|
|
void page_did_open_dialog(Badge<PageClient>);
|
|
|
|
|
2022-11-08 10:03:07 -05:00
|
|
|
private:
|
2023-02-08 17:05:44 -05:00
|
|
|
WebDriverConnection(NonnullOwnPtr<Core::LocalSocket> socket, Web::PageClient& page_client);
|
2022-11-08 10:03:07 -05:00
|
|
|
|
|
|
|
virtual void die() override { }
|
2022-11-08 14:14:29 -05:00
|
|
|
|
|
|
|
virtual void close_session() override;
|
2022-11-17 16:27:32 -05:00
|
|
|
virtual void set_page_load_strategy(Web::WebDriver::PageLoadStrategy const& page_load_strategy) override;
|
|
|
|
virtual void set_unhandled_prompt_behavior(Web::WebDriver::UnhandledPromptBehavior const& unhandled_prompt_behavior) override;
|
|
|
|
virtual void set_strict_file_interactability(bool strict_file_interactability) override;
|
2022-11-08 10:42:12 -05:00
|
|
|
virtual void set_is_webdriver_active(bool) override;
|
2022-11-11 14:28:57 -05:00
|
|
|
virtual Messages::WebDriverClient::GetTimeoutsResponse get_timeouts() override;
|
|
|
|
virtual Messages::WebDriverClient::SetTimeoutsResponse set_timeouts(JsonValue const& payload) override;
|
2022-11-08 12:58:24 -05:00
|
|
|
virtual Messages::WebDriverClient::NavigateToResponse navigate_to(JsonValue const& payload) override;
|
2022-11-08 13:06:22 -05:00
|
|
|
virtual Messages::WebDriverClient::GetCurrentUrlResponse get_current_url() override;
|
2022-11-11 13:46:22 -05:00
|
|
|
virtual Messages::WebDriverClient::BackResponse back() override;
|
|
|
|
virtual Messages::WebDriverClient::ForwardResponse forward() override;
|
|
|
|
virtual Messages::WebDriverClient::RefreshResponse refresh() override;
|
2022-11-11 13:50:43 -05:00
|
|
|
virtual Messages::WebDriverClient::GetTitleResponse get_title() override;
|
2023-03-13 10:45:34 -04:00
|
|
|
virtual Messages::WebDriverClient::GetWindowHandleResponse get_window_handle() override;
|
2022-11-14 11:55:10 -05:00
|
|
|
virtual Messages::WebDriverClient::CloseWindowResponse close_window() override;
|
2024-09-14 13:02:44 -04:00
|
|
|
virtual Messages::WebDriverClient::SwitchToWindowResponse switch_to_window(String const& handle) override;
|
2023-03-14 07:09:50 -04:00
|
|
|
virtual Messages::WebDriverClient::NewWindowResponse new_window(JsonValue const& payload) override;
|
2024-09-08 08:14:52 -04:00
|
|
|
virtual Messages::WebDriverClient::SwitchToFrameResponse switch_to_frame(JsonValue const& payload) override;
|
|
|
|
virtual Messages::WebDriverClient::SwitchToParentFrameResponse switch_to_parent_frame(JsonValue const& payload) override;
|
2022-11-09 09:56:20 -05:00
|
|
|
virtual Messages::WebDriverClient::GetWindowRectResponse get_window_rect() override;
|
|
|
|
virtual Messages::WebDriverClient::SetWindowRectResponse set_window_rect(JsonValue const& payload) override;
|
2022-11-09 11:00:53 -05:00
|
|
|
virtual Messages::WebDriverClient::MaximizeWindowResponse maximize_window() override;
|
|
|
|
virtual Messages::WebDriverClient::MinimizeWindowResponse minimize_window() override;
|
2022-11-09 13:09:17 -05:00
|
|
|
virtual Messages::WebDriverClient::FullscreenWindowResponse fullscreen_window() override;
|
2024-05-29 13:14:42 -04:00
|
|
|
virtual Messages::WebDriverClient::ConsumeUserActivationResponse consume_user_activation() override;
|
2022-11-09 15:02:38 -05:00
|
|
|
virtual Messages::WebDriverClient::FindElementResponse find_element(JsonValue const& payload) override;
|
2022-11-09 15:08:49 -05:00
|
|
|
virtual Messages::WebDriverClient::FindElementsResponse find_elements(JsonValue const& payload) override;
|
2023-03-05 15:31:49 -05:00
|
|
|
virtual Messages::WebDriverClient::FindElementFromElementResponse find_element_from_element(JsonValue const& payload, String const& element_id) override;
|
|
|
|
virtual Messages::WebDriverClient::FindElementsFromElementResponse find_elements_from_element(JsonValue const& payload, String const& element_id) override;
|
|
|
|
virtual Messages::WebDriverClient::FindElementFromShadowRootResponse find_element_from_shadow_root(JsonValue const& payload, String const& shadow_id) override;
|
|
|
|
virtual Messages::WebDriverClient::FindElementsFromShadowRootResponse find_elements_from_shadow_root(JsonValue const& payload, String const& shadow_id) override;
|
2022-11-14 19:02:23 -05:00
|
|
|
virtual Messages::WebDriverClient::GetActiveElementResponse get_active_element() override;
|
2023-03-05 15:31:49 -05:00
|
|
|
virtual Messages::WebDriverClient::GetElementShadowRootResponse get_element_shadow_root(String const& element_id) override;
|
|
|
|
virtual Messages::WebDriverClient::IsElementSelectedResponse is_element_selected(String const& element_id) override;
|
|
|
|
virtual Messages::WebDriverClient::GetElementAttributeResponse get_element_attribute(String const& element_id, String const& name) override;
|
|
|
|
virtual Messages::WebDriverClient::GetElementPropertyResponse get_element_property(String const& element_id, String const& name) override;
|
|
|
|
virtual Messages::WebDriverClient::GetElementCssValueResponse get_element_css_value(String const& element_id, String const& name) override;
|
|
|
|
virtual Messages::WebDriverClient::GetElementTextResponse get_element_text(String const& element_id) override;
|
|
|
|
virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(String const& element_id) override;
|
|
|
|
virtual Messages::WebDriverClient::GetElementRectResponse get_element_rect(String const& element_id) override;
|
|
|
|
virtual Messages::WebDriverClient::IsElementEnabledResponse is_element_enabled(String const& element_id) override;
|
|
|
|
virtual Messages::WebDriverClient::GetComputedRoleResponse get_computed_role(String const& element_id) override;
|
|
|
|
virtual Messages::WebDriverClient::GetComputedLabelResponse get_computed_label(String const& element_id) override;
|
|
|
|
virtual Messages::WebDriverClient::ElementClickResponse element_click(String const& element_id) override;
|
2024-09-08 08:14:52 -04:00
|
|
|
virtual Messages::WebDriverClient::ElementClearResponse element_clear(String const& element_id) override;
|
2024-09-25 11:26:46 -04:00
|
|
|
virtual Messages::WebDriverClient::ElementSendKeysResponse element_send_keys(String const& element_id, JsonValue const& payload) override;
|
2022-11-10 18:00:01 -05:00
|
|
|
virtual Messages::WebDriverClient::GetSourceResponse get_source() override;
|
2022-11-10 20:55:17 -05:00
|
|
|
virtual Messages::WebDriverClient::ExecuteScriptResponse execute_script(JsonValue const& payload) override;
|
2022-11-10 21:00:27 -05:00
|
|
|
virtual Messages::WebDriverClient::ExecuteAsyncScriptResponse execute_async_script(JsonValue const& payload) override;
|
2022-11-11 09:24:07 -05:00
|
|
|
virtual Messages::WebDriverClient::GetAllCookiesResponse get_all_cookies() override;
|
2023-03-05 15:31:49 -05:00
|
|
|
virtual Messages::WebDriverClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
|
2022-11-11 11:00:45 -05:00
|
|
|
virtual Messages::WebDriverClient::AddCookieResponse add_cookie(JsonValue const& payload) override;
|
2023-03-05 15:31:49 -05:00
|
|
|
virtual Messages::WebDriverClient::DeleteCookieResponse delete_cookie(String const& name) override;
|
2022-11-11 11:27:08 -05:00
|
|
|
virtual Messages::WebDriverClient::DeleteAllCookiesResponse delete_all_cookies() override;
|
2024-09-25 11:26:46 -04:00
|
|
|
virtual Messages::WebDriverClient::PerformActionsResponse perform_actions(JsonValue const& payload) override;
|
2023-06-17 11:36:00 -04:00
|
|
|
virtual Messages::WebDriverClient::ReleaseActionsResponse release_actions() override;
|
2022-11-16 07:15:57 -05:00
|
|
|
virtual Messages::WebDriverClient::DismissAlertResponse dismiss_alert() override;
|
2022-11-16 07:24:22 -05:00
|
|
|
virtual Messages::WebDriverClient::AcceptAlertResponse accept_alert() override;
|
2022-11-16 08:26:48 -05:00
|
|
|
virtual Messages::WebDriverClient::GetAlertTextResponse get_alert_text() override;
|
2022-11-16 08:57:05 -05:00
|
|
|
virtual Messages::WebDriverClient::SendAlertTextResponse send_alert_text(JsonValue const& payload) override;
|
2022-11-10 13:20:44 -05:00
|
|
|
virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override;
|
2023-03-05 15:31:49 -05:00
|
|
|
virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;
|
2024-09-25 11:26:46 -04:00
|
|
|
virtual Messages::WebDriverClient::PrintPageResponse print_page(JsonValue const& payload) override;
|
2023-03-07 11:29:14 -05:00
|
|
|
virtual Messages::WebDriverClient::EnsureTopLevelBrowsingContextIsOpenResponse ensure_top_level_browsing_context_is_open() override;
|
2024-09-13 17:18:23 -04:00
|
|
|
|
2024-10-01 13:04:37 -04:00
|
|
|
void set_current_browsing_context(Web::HTML::BrowsingContext&);
|
2024-09-13 17:18:23 -04:00
|
|
|
Web::HTML::BrowsingContext& current_browsing_context() { return *m_current_browsing_context; }
|
2024-10-17 18:50:36 -04:00
|
|
|
JS::GCPtr<Web::HTML::BrowsingContext> current_parent_browsing_context() { return m_current_parent_browsing_context; }
|
2024-10-01 13:04:37 -04:00
|
|
|
|
|
|
|
void set_current_top_level_browsing_context(Web::HTML::BrowsingContext&);
|
2024-10-17 18:50:36 -04:00
|
|
|
JS::GCPtr<Web::HTML::BrowsingContext> current_top_level_browsing_context() { return m_current_top_level_browsing_context; }
|
2024-09-13 17:18:23 -04:00
|
|
|
|
|
|
|
ErrorOr<void, Web::WebDriver::Error> ensure_current_browsing_context_is_open();
|
|
|
|
ErrorOr<void, Web::WebDriver::Error> ensure_current_top_level_browsing_context_is_open();
|
2023-03-07 11:29:14 -05:00
|
|
|
|
2022-11-16 06:58:14 -05:00
|
|
|
ErrorOr<void, Web::WebDriver::Error> handle_any_user_prompts();
|
2022-11-09 09:56:20 -05:00
|
|
|
void restore_the_window();
|
2022-11-09 11:00:53 -05:00
|
|
|
Gfx::IntRect maximize_the_window();
|
|
|
|
Gfx::IntRect iconify_the_window();
|
2022-11-21 09:51:46 -05:00
|
|
|
|
2024-10-25 10:28:29 -04:00
|
|
|
using OnNavigationComplete = JS::NonnullGCPtr<JS::HeapFunction<void(Web::WebDriver::Response)>>;
|
|
|
|
void wait_for_navigation_to_complete(OnNavigationComplete);
|
2023-03-07 18:04:17 -05:00
|
|
|
|
2024-09-13 17:18:23 -04:00
|
|
|
Gfx::IntPoint calculate_absolute_position_of_element(JS::NonnullGCPtr<Web::Geometry::DOMRect> rect);
|
|
|
|
Gfx::IntRect calculate_absolute_rect_of_element(Web::DOM::Element const& element);
|
|
|
|
|
2024-10-17 17:38:34 -04:00
|
|
|
using StartNodeGetter = Function<ErrorOr<JS::NonnullGCPtr<Web::DOM::ParentNode>, Web::WebDriver::Error>()>;
|
2022-11-21 09:51:46 -05:00
|
|
|
ErrorOr<JsonArray, Web::WebDriver::Error> find(StartNodeGetter&& start_node_getter, Web::WebDriver::LocationStrategy using_, StringView value);
|
2022-11-08 10:03:07 -05:00
|
|
|
|
2022-11-10 20:55:17 -05:00
|
|
|
struct ScriptArguments {
|
2023-12-16 09:19:34 -05:00
|
|
|
ByteString script;
|
2022-11-10 20:55:17 -05:00
|
|
|
JS::MarkedVector<JS::Value> arguments;
|
|
|
|
};
|
2024-09-27 17:42:07 -04:00
|
|
|
ErrorOr<ScriptArguments, Web::WebDriver::Error> extract_the_script_arguments_from_a_request(JS::VM&, JsonValue const& payload);
|
2022-11-11 11:21:00 -05:00
|
|
|
void delete_cookies(Optional<StringView> const& name = {});
|
2022-11-10 20:55:17 -05:00
|
|
|
|
2022-11-17 16:27:32 -05:00
|
|
|
// https://w3c.github.io/webdriver/#dfn-page-load-strategy
|
|
|
|
Web::WebDriver::PageLoadStrategy m_page_load_strategy { Web::WebDriver::PageLoadStrategy::Normal };
|
|
|
|
|
|
|
|
// https://w3c.github.io/webdriver/#dfn-unhandled-prompt-behavior
|
|
|
|
Web::WebDriver::UnhandledPromptBehavior m_unhandled_prompt_behavior { Web::WebDriver::UnhandledPromptBehavior::DismissAndNotify };
|
|
|
|
|
|
|
|
// https://w3c.github.io/webdriver/#dfn-strict-file-interactability
|
|
|
|
bool m_strict_file_interactability { false };
|
|
|
|
|
2022-11-11 14:28:57 -05:00
|
|
|
// https://w3c.github.io/webdriver/#dfn-session-script-timeout
|
|
|
|
Web::WebDriver::TimeoutsConfiguration m_timeouts_configuration;
|
2024-09-13 17:18:23 -04:00
|
|
|
|
|
|
|
// https://w3c.github.io/webdriver/#dfn-current-browsing-context
|
2024-10-17 18:50:36 -04:00
|
|
|
JS::GCPtr<Web::HTML::BrowsingContext> m_current_browsing_context;
|
2024-09-29 09:40:17 -04:00
|
|
|
|
2024-10-01 13:04:37 -04:00
|
|
|
// https://w3c.github.io/webdriver/#dfn-current-parent-browsing-context
|
2024-10-17 18:50:36 -04:00
|
|
|
JS::GCPtr<Web::HTML::BrowsingContext> m_current_parent_browsing_context;
|
2024-10-01 13:04:37 -04:00
|
|
|
|
|
|
|
// https://w3c.github.io/webdriver/#dfn-current-top-level-browsing-context
|
2024-10-17 18:50:36 -04:00
|
|
|
JS::GCPtr<Web::HTML::BrowsingContext> m_current_top_level_browsing_context;
|
2024-10-01 13:04:37 -04:00
|
|
|
|
2024-10-17 18:50:36 -04:00
|
|
|
JS::GCPtr<JS::Cell> m_action_executor;
|
2024-10-25 10:28:29 -04:00
|
|
|
|
|
|
|
JS::GCPtr<Web::DOM::DocumentObserver> m_document_observer;
|
|
|
|
JS::GCPtr<Web::HTML::NavigationObserver> m_navigation_observer;
|
|
|
|
JS::GCPtr<Web::WebDriver::HeapTimer> m_navigation_timer;
|
2022-11-08 10:03:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|