mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
WebDriver+WebContent: Add /session/🆔/window/consume-user-activation
This extension to the WebDriver spec is defined in the HTML spec, how fun.
This commit is contained in:
parent
9bc1318a78
commit
ca806a3e18
|
@ -69,6 +69,7 @@ static constexpr auto s_webdriver_endpoints = Array {
|
|||
ROUTE(POST, "/session/:session_id/window/maximize"sv, maximize_window),
|
||||
ROUTE(POST, "/session/:session_id/window/minimize"sv, minimize_window),
|
||||
ROUTE(POST, "/session/:session_id/window/fullscreen"sv, fullscreen_window),
|
||||
ROUTE(POST, "/session/:session_id/window/consume-user-activation"sv, consume_user_activation),
|
||||
ROUTE(POST, "/session/:session_id/element"sv, find_element),
|
||||
ROUTE(POST, "/session/:session_id/elements"sv, find_elements),
|
||||
ROUTE(POST, "/session/:session_id/element/:element_id/element"sv, find_element_from_element),
|
||||
|
|
|
@ -59,6 +59,9 @@ public:
|
|||
virtual Response minimize_window(Parameters parameters, JsonValue payload) = 0;
|
||||
virtual Response fullscreen_window(Parameters parameters, JsonValue payload) = 0;
|
||||
|
||||
// Extension: https://html.spec.whatwg.org/multipage/interaction.html#user-activation-user-agent-automation
|
||||
virtual Response consume_user_activation(Parameters parameters, JsonValue payload) = 0;
|
||||
|
||||
// 12. Elements, https://w3c.github.io/webdriver/#elements
|
||||
virtual Response find_element(Parameters parameters, JsonValue payload) = 0;
|
||||
virtual Response find_elements(Parameters parameters, JsonValue payload) = 0;
|
||||
|
|
|
@ -24,6 +24,7 @@ endpoint WebDriverClient {
|
|||
maximize_window() => (Web::WebDriver::Response response)
|
||||
minimize_window() => (Web::WebDriver::Response response)
|
||||
fullscreen_window() => (Web::WebDriver::Response response)
|
||||
consume_user_activation() => (Web::WebDriver::Response response)
|
||||
find_element(JsonValue payload) => (Web::WebDriver::Response response)
|
||||
find_elements(JsonValue payload) => (Web::WebDriver::Response response)
|
||||
find_element_from_element(JsonValue payload, String element_id) => (Web::WebDriver::Response response)
|
||||
|
|
|
@ -754,6 +754,27 @@ Messages::WebDriverClient::FullscreenWindowResponse WebDriverConnection::fullscr
|
|||
return serialize_rect(rect);
|
||||
}
|
||||
|
||||
// Extension Consume User Activation, https://html.spec.whatwg.org/multipage/interaction.html#user-activation-user-agent-automation
|
||||
Messages::WebDriverClient::ConsumeUserActivationResponse WebDriverConnection::consume_user_activation()
|
||||
{
|
||||
// FIXME: This should probably be in the spec steps
|
||||
// If the current top-level browsing context is no longer open, return error with error code no such window.
|
||||
TRY(ensure_open_top_level_browsing_context());
|
||||
|
||||
// 1. Let window be current browsing context's active window.
|
||||
auto* window = m_page_client->page().top_level_browsing_context().active_window();
|
||||
|
||||
// 2. Let consume be true if window has transient activation; otherwise false.
|
||||
bool consume = window->has_transient_activation();
|
||||
|
||||
// 3. If consume is true, then consume user activation of window.
|
||||
if (consume)
|
||||
window->consume_user_activation();
|
||||
|
||||
// 4. Return success with data consume.
|
||||
return consume;
|
||||
}
|
||||
|
||||
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
|
||||
Messages::WebDriverClient::FindElementResponse WebDriverConnection::find_element(JsonValue const& payload)
|
||||
{
|
||||
|
|
|
@ -61,6 +61,7 @@ private:
|
|||
virtual Messages::WebDriverClient::MaximizeWindowResponse maximize_window() override;
|
||||
virtual Messages::WebDriverClient::MinimizeWindowResponse minimize_window() override;
|
||||
virtual Messages::WebDriverClient::FullscreenWindowResponse fullscreen_window() override;
|
||||
virtual Messages::WebDriverClient::ConsumeUserActivationResponse consume_user_activation() override;
|
||||
virtual Messages::WebDriverClient::FindElementResponse find_element(JsonValue const& payload) override;
|
||||
virtual Messages::WebDriverClient::FindElementsResponse find_elements(JsonValue const& payload) override;
|
||||
virtual Messages::WebDriverClient::FindElementFromElementResponse find_element_from_element(JsonValue const& payload, String const& element_id) override;
|
||||
|
|
|
@ -389,6 +389,15 @@ Web::WebDriver::Response Client::fullscreen_window(Web::WebDriver::Parameters pa
|
|||
return session->web_content_connection().fullscreen_window();
|
||||
}
|
||||
|
||||
// Extension: Consume User Activation, https://html.spec.whatwg.org/multipage/interaction.html#user-activation-user-agent-automation
|
||||
// POST /session/{session id}/window/consume-user-activation
|
||||
Web::WebDriver::Response Client::consume_user_activation(Web::WebDriver::Parameters parameters, JsonValue)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/consume-user-activation");
|
||||
auto session = TRY(find_session_with_id(parameters[0]));
|
||||
return session->web_content_connection().consume_user_activation();
|
||||
}
|
||||
|
||||
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
|
||||
// POST /session/{session id}/element
|
||||
Web::WebDriver::Response Client::find_element(Web::WebDriver::Parameters parameters, JsonValue payload)
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
virtual Web::WebDriver::Response maximize_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response minimize_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response fullscreen_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response consume_user_activation(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response find_element(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response find_elements(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
virtual Web::WebDriver::Response find_element_from_element(Web::WebDriver::Parameters parameters, JsonValue payload) override;
|
||||
|
|
Loading…
Reference in a new issue