mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
WebDriver: Implement Close Window closer to the spec
We are expected to return the list of open handles after closing the current handle. Also just return a WebDriver::Response instead of a wrapped Error variant.
This commit is contained in:
parent
9dc622475e
commit
47493b5734
Notes:
sideshowbarker
2024-07-17 04:32:08 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/47493b5734 Pull-request: https://github.com/SerenityOS/serenity/pull/16045 Reviewed-by: https://github.com/linusg ✅
|
@ -559,8 +559,8 @@ Web::WebDriver::Response Client::handle_close_window(Vector<StringView> const& p
|
|||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/window");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
TRY(unwrap_result(session->close_window()));
|
||||
return make_json_value(JsonValue());
|
||||
auto result = TRY(session->close_window());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
|
||||
|
|
|
@ -95,29 +95,6 @@ private:
|
|||
ErrorOr<NonnullOwnPtr<Session>, Web::WebDriver::Error> take_session_with_id(StringView session_id);
|
||||
JsonValue make_json_value(JsonValue const&);
|
||||
|
||||
template<typename T>
|
||||
static ErrorOr<T, Web::WebDriver::Error> unwrap_result(ErrorOr<T, Variant<Web::WebDriver::Error, Error>> result)
|
||||
{
|
||||
if (result.is_error()) {
|
||||
Variant<Web::WebDriver::Error, Error> error = result.release_error();
|
||||
if (error.has<Web::WebDriver::Error>())
|
||||
return error.get<Web::WebDriver::Error>();
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, error.get<Error>().string_literal());
|
||||
}
|
||||
|
||||
return result.release_value();
|
||||
}
|
||||
static ErrorOr<void, Web::WebDriver::Error> unwrap_result(ErrorOr<void, Variant<Web::WebDriver::Error, Error>> result)
|
||||
{
|
||||
if (result.is_error()) {
|
||||
Variant<Web::WebDriver::Error, Error> error = result.release_error();
|
||||
if (error.has<Web::WebDriver::Error>())
|
||||
return error.get<Web::WebDriver::Error>();
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, error.get<Error>().string_literal());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
NonnullOwnPtr<Core::Stream::BufferedTCPSocket> m_socket;
|
||||
static Vector<Route> s_routes;
|
||||
String m_prefix = "/";
|
||||
|
|
|
@ -142,23 +142,22 @@ Web::WebDriver::Response Session::get_window_handle()
|
|||
}
|
||||
|
||||
// 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
|
||||
ErrorOr<void, Variant<Web::WebDriver::Error, Error>> Session::close_window()
|
||||
Web::WebDriver::Response Session::close_window()
|
||||
{
|
||||
// 1. 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());
|
||||
|
||||
// 2. Close the current top-level browsing context.
|
||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||
|
||||
// 3. Close the current top-level browsing context.
|
||||
m_windows.remove(m_current_window_handle);
|
||||
|
||||
// 3. If there are no more open top-level browsing contexts, then close the session.
|
||||
if (m_windows.is_empty()) {
|
||||
auto result = stop();
|
||||
if (result.is_error()) {
|
||||
return Variant<Web::WebDriver::Error, Error>(result.release_error());
|
||||
}
|
||||
}
|
||||
// 4. If there are no more open top-level browsing contexts, then close the session.
|
||||
if (m_windows.is_empty())
|
||||
TRY(stop());
|
||||
|
||||
return {};
|
||||
// 5. Return the result of running the remote end steps for the Get Window Handles command.
|
||||
return get_window_handles();
|
||||
}
|
||||
|
||||
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
ErrorOr<void> start();
|
||||
Web::WebDriver::Response stop();
|
||||
Web::WebDriver::Response get_window_handle();
|
||||
ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window();
|
||||
Web::WebDriver::Response close_window();
|
||||
Web::WebDriver::Response get_window_handles() const;
|
||||
Web::WebDriver::Response take_element_screenshot(StringView element_id);
|
||||
|
||||
|
|
Loading…
Reference in a new issue