mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:27:35 +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
4 changed files with 12 additions and 36 deletions
|
@ -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");
|
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/window");
|
||||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||||
TRY(unwrap_result(session->close_window()));
|
auto result = TRY(session->close_window());
|
||||||
return make_json_value(JsonValue());
|
return make_json_value(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
|
// 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);
|
ErrorOr<NonnullOwnPtr<Session>, Web::WebDriver::Error> take_session_with_id(StringView session_id);
|
||||||
JsonValue make_json_value(JsonValue const&);
|
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;
|
NonnullOwnPtr<Core::Stream::BufferedTCPSocket> m_socket;
|
||||||
static Vector<Route> s_routes;
|
static Vector<Route> s_routes;
|
||||||
String m_prefix = "/";
|
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
|
// 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.
|
// 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());
|
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);
|
m_windows.remove(m_current_window_handle);
|
||||||
|
|
||||||
// 3. If there are no more open top-level browsing contexts, then close the session.
|
// 4. If there are no more open top-level browsing contexts, then close the session.
|
||||||
if (m_windows.is_empty()) {
|
if (m_windows.is_empty())
|
||||||
auto result = stop();
|
TRY(stop());
|
||||||
if (result.is_error()) {
|
|
||||||
return Variant<Web::WebDriver::Error, Error>(result.release_error());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
ErrorOr<void> start();
|
ErrorOr<void> start();
|
||||||
Web::WebDriver::Response stop();
|
Web::WebDriver::Response stop();
|
||||||
Web::WebDriver::Response get_window_handle();
|
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 get_window_handles() const;
|
||||||
Web::WebDriver::Response take_element_screenshot(StringView element_id);
|
Web::WebDriver::Response take_element_screenshot(StringView element_id);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue