mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 07:37:35 +00:00
WebContent+WebDriver: Fully implement closing a session
There were a couple steps missing to close the remote end. Further, we were not removing the session from the list of active sessions.
This commit is contained in:
parent
3ba6b5a7cb
commit
cc78a74c51
7 changed files with 47 additions and 8 deletions
|
@ -331,6 +331,21 @@ ErrorOr<Session*, Web::WebDriver::Error> Client::find_session_with_id(StringView
|
|||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidSessionId, "Invalid session id");
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<Session>, Web::WebDriver::Error> Client::take_session_with_id(StringView session_id)
|
||||
{
|
||||
auto session_id_or_error = session_id.to_uint<>();
|
||||
if (!session_id_or_error.has_value())
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidSessionId, "Invalid session id");
|
||||
|
||||
for (size_t i = 0; i < Client::s_sessions.size(); ++i) {
|
||||
if (Client::s_sessions[i].session_id() == session_id_or_error.value()) {
|
||||
return Client::s_sessions.take(i);
|
||||
}
|
||||
}
|
||||
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidSessionId, "Invalid session id");
|
||||
}
|
||||
|
||||
void Client::close_session(unsigned session_id)
|
||||
{
|
||||
bool found = Client::s_sessions.remove_first_matching([&](auto const& it) {
|
||||
|
@ -426,11 +441,8 @@ Web::WebDriver::Response Client::handle_delete_session(Vector<StringView> const&
|
|||
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>");
|
||||
|
||||
// 1. If the current session is an active session, try to close the session.
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
auto stop_result = session->stop();
|
||||
if (stop_result.is_error())
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, stop_result.error().string_literal());
|
||||
auto session = TRY(take_session_with_id(parameters[0]));
|
||||
TRY(session->stop());
|
||||
|
||||
// 2. Return success with data null.
|
||||
return make_json_value(JsonValue());
|
||||
|
|
|
@ -91,6 +91,7 @@ private:
|
|||
Web::WebDriver::Response handle_take_element_screenshot(Vector<StringView> const&, JsonValue const& payload);
|
||||
|
||||
ErrorOr<Session*, Web::WebDriver::Error> find_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&);
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -136,10 +136,23 @@ ErrorOr<void> Session::start()
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> Session::stop()
|
||||
// https://w3c.github.io/webdriver/#dfn-close-the-session
|
||||
Web::WebDriver::Response Session::stop()
|
||||
{
|
||||
// 1. Perform the following substeps based on the remote end’s type:
|
||||
// NOTE: We perform the "Remote end is an endpoint node" steps in the WebContent process.
|
||||
m_web_content_connection->close_session();
|
||||
m_web_content_connection = nullptr;
|
||||
|
||||
// 2. Remove the current session from active sessions.
|
||||
// NOTE: Handled by WebDriver::Client.
|
||||
|
||||
// 3. Perform any implementation-specific cleanup steps.
|
||||
m_browser_connection->async_quit();
|
||||
return {};
|
||||
m_started = false;
|
||||
|
||||
// 4. If an error has occurred in any of the steps above, return the error, otherwise return success with data null.
|
||||
return JsonValue {};
|
||||
}
|
||||
|
||||
// 9.1 Get Timeouts, https://w3c.github.io/webdriver/#dfn-get-timeouts
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
}
|
||||
|
||||
ErrorOr<void> start();
|
||||
ErrorOr<void> stop();
|
||||
Web::WebDriver::Response stop();
|
||||
JsonObject get_timeouts();
|
||||
Web::WebDriver::Response set_timeouts(JsonValue const& payload);
|
||||
Web::WebDriver::Response back();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue