mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:47:46 +00:00
Browser+WebContent+WebDriver: Move [Max,Min]imize Window to WebContent
This also lets us more fully implement the "iconify the window" method, which requires we block until the document reaches the "hidden" state.
This commit is contained in:
parent
1c398b32ce
commit
03d0c7a5b6
9 changed files with 75 additions and 86 deletions
|
@ -58,37 +58,6 @@ void WebDriverConnection::forward()
|
|||
browser_window->active_tab().go_forward();
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::GetWindowRectResponse WebDriverConnection::get_window_rect()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_window_rect");
|
||||
if (auto browser_window = m_browser_window.strong_ref())
|
||||
return { browser_window->rect() };
|
||||
return { {} };
|
||||
}
|
||||
|
||||
void WebDriverConnection::restore_window()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: restore_window");
|
||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||
browser_window->show();
|
||||
browser_window->move_to_front();
|
||||
}
|
||||
}
|
||||
|
||||
void WebDriverConnection::maximize_window()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: maximize_window");
|
||||
if (auto browser_window = m_browser_window.strong_ref())
|
||||
browser_window->set_maximized(true);
|
||||
}
|
||||
|
||||
void WebDriverConnection::minimize_window()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: minimize_window");
|
||||
if (auto browser_window = m_browser_window.strong_ref())
|
||||
browser_window->set_minimized(true);
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::SerializeSourceResponse WebDriverConnection::serialize_source()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: serialize_source");
|
||||
|
|
|
@ -42,10 +42,6 @@ public:
|
|||
virtual void refresh() override;
|
||||
virtual void back() override;
|
||||
virtual void forward() override;
|
||||
virtual Messages::WebDriverSessionClient::GetWindowRectResponse get_window_rect() override;
|
||||
virtual void restore_window() override;
|
||||
virtual void maximize_window() override;
|
||||
virtual void minimize_window() override;
|
||||
virtual Messages::WebDriverSessionClient::SerializeSourceResponse serialize_source() override;
|
||||
virtual Messages::WebDriverSessionClient::ExecuteScriptResponse execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async) override;
|
||||
virtual Messages::WebDriverSessionClient::GetAllCookiesResponse get_all_cookies() override;
|
||||
|
|
|
@ -18,10 +18,6 @@ endpoint WebDriverSessionClient {
|
|||
refresh() =|
|
||||
back() =|
|
||||
forward() =|
|
||||
get_window_rect() => (Gfx::IntRect rect)
|
||||
restore_window() =|
|
||||
maximize_window() =|
|
||||
minimize_window() =|
|
||||
serialize_source() => (String source)
|
||||
execute_script(String body, Vector<String> json_arguments, Optional<u64> timeout, bool async) => (Web::WebDriver::ExecuteScriptResultType result_type, String json_result)
|
||||
get_all_cookies() => (Vector<Web::Cookie::Cookie> cookies)
|
||||
|
|
|
@ -7,4 +7,6 @@ endpoint WebDriverClient {
|
|||
get_current_url() => (Web::WebDriver::Response response)
|
||||
get_window_rect() => (Web::WebDriver::Response response)
|
||||
set_window_rect(JsonValue payload) => (Web::WebDriver::Response response)
|
||||
maximize_window() => (Web::WebDriver::Response response)
|
||||
minimize_window() => (Web::WebDriver::Response response)
|
||||
}
|
||||
|
|
|
@ -222,6 +222,45 @@ Messages::WebDriverClient::SetWindowRectResponse WebDriverConnection::set_window
|
|||
return serialize_rect(window_rect);
|
||||
}
|
||||
|
||||
// 11.8.3 Maximize Window, https://w3c.github.io/webdriver/#dfn-maximize-window
|
||||
Messages::WebDriverClient::MaximizeWindowResponse WebDriverConnection::maximize_window()
|
||||
{
|
||||
// 1. If the remote end does not support the Maximize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation.
|
||||
|
||||
// 2. 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());
|
||||
|
||||
// FIXME: 3. Handle any user prompts and return its value if it is an error.
|
||||
// FIXME: 4. Fully exit fullscreen.
|
||||
|
||||
// 5. Restore the window.
|
||||
restore_the_window();
|
||||
|
||||
// 6. Maximize the window of the current top-level browsing context.
|
||||
auto window_rect = maximize_the_window();
|
||||
|
||||
// 7. Return success with data set to the WindowRect object for the current top-level browsing context.
|
||||
return serialize_rect(window_rect);
|
||||
}
|
||||
|
||||
// 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window
|
||||
Messages::WebDriverClient::MinimizeWindowResponse WebDriverConnection::minimize_window()
|
||||
{
|
||||
// 1. If the remote end does not support the Minimize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation.
|
||||
|
||||
// 2. 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());
|
||||
|
||||
// FIXME: 3. Handle any user prompts and return its value if it is an error.
|
||||
// FIXME: 4. Fully exit fullscreen.
|
||||
|
||||
// 5. Iconify the window.
|
||||
auto window_rect = iconify_the_window();
|
||||
|
||||
// 6. Return success with data set to the WindowRect object for the current top-level browsing context.
|
||||
return serialize_rect(window_rect);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-no-longer-open
|
||||
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
|
||||
{
|
||||
|
@ -240,9 +279,35 @@ void WebDriverConnection::restore_the_window()
|
|||
// Do not return from this operation until the visibility state of the top-level browsing context’s active document has reached the visible state, or until the operation times out.
|
||||
// FIXME: Implement timeouts.
|
||||
Web::Platform::EventLoopPlugin::the().spin_until([this]() {
|
||||
auto state = m_page_host.page().top_level_browsing_context().active_document()->visibility_state();
|
||||
return state == "visible"sv;
|
||||
auto state = m_page_host.page().top_level_browsing_context().system_visibility_state();
|
||||
return state == Web::HTML::VisibilityState::Visible;
|
||||
});
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-maximize-the-window
|
||||
Gfx::IntRect WebDriverConnection::maximize_the_window()
|
||||
{
|
||||
// To maximize the window, given an operating system level window with an associated top-level browsing context, run the implementation-specific steps to transition the operating system level window into the maximized window state.
|
||||
auto rect = m_web_content_client.did_request_maximize_window();
|
||||
|
||||
// Return when the window has completed the transition, or within an implementation-defined timeout.
|
||||
return rect;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-iconify-the-window
|
||||
Gfx::IntRect WebDriverConnection::iconify_the_window()
|
||||
{
|
||||
// To iconify the window, given an operating system level window with an associated top-level browsing context, run implementation-specific steps to iconify, minimize, or hide the window from the visible screen.
|
||||
auto rect = m_web_content_client.did_request_minimize_window();
|
||||
|
||||
// Do not return from this operation until the visibility state of the top-level browsing context’s active document has reached the hidden state, or until the operation times out.
|
||||
// FIXME: Implement timeouts.
|
||||
Web::Platform::EventLoopPlugin::the().spin_until([this]() {
|
||||
auto state = m_page_host.page().top_level_browsing_context().system_visibility_state();
|
||||
return state == Web::HTML::VisibilityState::Hidden;
|
||||
});
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,9 +35,13 @@ private:
|
|||
virtual Messages::WebDriverClient::GetCurrentUrlResponse get_current_url() override;
|
||||
virtual Messages::WebDriverClient::GetWindowRectResponse get_window_rect() override;
|
||||
virtual Messages::WebDriverClient::SetWindowRectResponse set_window_rect(JsonValue const& payload) override;
|
||||
virtual Messages::WebDriverClient::MaximizeWindowResponse maximize_window() override;
|
||||
virtual Messages::WebDriverClient::MinimizeWindowResponse minimize_window() override;
|
||||
|
||||
ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
|
||||
void restore_the_window();
|
||||
Gfx::IntRect maximize_the_window();
|
||||
Gfx::IntRect iconify_the_window();
|
||||
|
||||
ConnectionFromClient& m_web_content_client;
|
||||
PageHost& m_page_host;
|
||||
|
|
|
@ -600,8 +600,7 @@ Web::WebDriver::Response Client::handle_maximize_window(Vector<StringView> const
|
|||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/maximize");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
auto result = TRY(session->maximize_window());
|
||||
return make_json_value(result);
|
||||
return session->web_content_connection().maximize_window();
|
||||
}
|
||||
|
||||
// 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window
|
||||
|
@ -610,8 +609,7 @@ Web::WebDriver::Response Client::handle_minimize_window(Vector<StringView> const
|
|||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window/minimize");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
auto result = TRY(session->minimize_window());
|
||||
return make_json_value(result);
|
||||
return session->web_content_connection().minimize_window();
|
||||
}
|
||||
|
||||
// 12.3.2 Find Element, https://w3c.github.io/webdriver/#dfn-find-element
|
||||
|
|
|
@ -311,45 +311,6 @@ static JsonValue serialize_rect(Gfx::IntRect const& rect)
|
|||
return serialized_rect;
|
||||
}
|
||||
|
||||
// 11.8.3 Maximize Window, https://w3c.github.io/webdriver/#dfn-maximize-window
|
||||
Web::WebDriver::Response Session::maximize_window()
|
||||
{
|
||||
// 1. If the remote end does not support the Maximize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation.
|
||||
|
||||
// 2. If the current top-level browsing context is no longer open, return error with error code no such window.
|
||||
TRY(check_for_open_top_level_browsing_context_or_return_error());
|
||||
|
||||
// FIXME: 3. Handle any user prompts and return its value if it is an error.
|
||||
// FIXME: 4. Fully exit fullscreen.
|
||||
|
||||
// 5. Restore the window.
|
||||
m_browser_connection->async_restore_window();
|
||||
|
||||
// 6. Maximize the window of the current top-level browsing context.
|
||||
m_browser_connection->async_maximize_window();
|
||||
|
||||
// 7. Return success with data set to the WindowRect object for the current top-level browsing context.
|
||||
return serialize_rect(m_browser_connection->get_window_rect());
|
||||
}
|
||||
|
||||
// 11.8.4 Minimize Window, https://w3c.github.io/webdriver/#minimize-window
|
||||
Web::WebDriver::Response Session::minimize_window()
|
||||
{
|
||||
// 1. If the remote end does not support the Minimize Window command for the current top-level browsing context for any reason, return error with error code unsupported operation.
|
||||
|
||||
// 2. If the current top-level browsing context is no longer open, return error with error code no such window.
|
||||
TRY(check_for_open_top_level_browsing_context_or_return_error());
|
||||
|
||||
// FIXME: 3. Handle any user prompts and return its value if it is an error.
|
||||
// FIXME: 4. Fully exit fullscreen.
|
||||
|
||||
// 5. Iconify the window.
|
||||
m_browser_connection->async_minimize_window();
|
||||
|
||||
// 6. Return success with data set to the WindowRect object for the current top-level browsing context.
|
||||
return serialize_rect(m_browser_connection->get_window_rect());
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-get-or-create-a-web-element-reference
|
||||
static String get_or_create_a_web_element_reference(Session::LocalElement const& element)
|
||||
{
|
||||
|
|
|
@ -58,8 +58,6 @@ public:
|
|||
Web::WebDriver::Response get_window_handle();
|
||||
ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window();
|
||||
Web::WebDriver::Response get_window_handles() const;
|
||||
Web::WebDriver::Response maximize_window();
|
||||
Web::WebDriver::Response minimize_window();
|
||||
Web::WebDriver::Response find_element(JsonValue const& payload);
|
||||
Web::WebDriver::Response find_elements(JsonValue const& payload);
|
||||
Web::WebDriver::Response find_element_from_element(JsonValue const& payload, StringView parameter_element_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue