1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:37:37 +00:00

WebDriver: Remove active sessions from the close-the-session AO

These steps now have more than one caller; specifically, they may be
called from the Delete Session and Close Window endpoints. The session
was only removed from the active session map for the former endpoint.

Instead, let's more accurately handle removing the session where the
spec tells us to, so that all callers properly perform this step.
This commit is contained in:
Timothy Flynn 2023-03-07 10:46:14 -05:00 committed by Linus Groh
parent a0992c7731
commit 12015a4db6
3 changed files with 2 additions and 15 deletions

View file

@ -49,18 +49,6 @@ ErrorOr<NonnullRefPtr<Session>, Web::WebDriver::Error> Client::find_session_with
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidSessionId, "Invalid session id");
}
ErrorOr<NonnullRefPtr<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");
if (auto session = s_sessions.take(*session_id_or_error); session.has_value())
return session.release_value();
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidSessionId, "Invalid session id");
}
void Client::close_session(unsigned session_id)
{
if (s_sessions.remove(session_id))
@ -196,7 +184,7 @@ Web::WebDriver::Response Client::delete_session(Web::WebDriver::Parameters param
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(take_session_with_id(parameters[0]));
auto session = TRY(find_session_with_id(parameters[0]));
TRY(session->stop());
// 2. Return success with data null.