mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
WebDriver: Implement POST /session/{id}/back endpoint
This commit is contained in:
parent
443ffab9dc
commit
9132656856
Notes:
sideshowbarker
2024-07-17 08:42:05 +09:00
Author: https://github.com/moustafaraafat Commit: https://github.com/SerenityOS/serenity/commit/9132656856 Pull-request: https://github.com/SerenityOS/serenity/pull/15623 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/TobyAsE ✅
7 changed files with 46 additions and 0 deletions
|
@ -53,4 +53,11 @@ void WebDriverConnection::refresh()
|
|||
browser_window->active_tab().reload();
|
||||
}
|
||||
|
||||
void WebDriverConnection::back()
|
||||
{
|
||||
dbgln("WebDriverConnection: back");
|
||||
if (auto browser_window = m_browser_window.strong_ref())
|
||||
browser_window->active_tab().go_back();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
virtual void set_url(AK::URL const& url) override;
|
||||
virtual Messages::WebDriverSessionClient::GetTitleResponse get_title() override;
|
||||
virtual void refresh() override;
|
||||
virtual void back() override;
|
||||
|
||||
private:
|
||||
WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window);
|
||||
|
|
|
@ -7,4 +7,5 @@ endpoint WebDriverSessionClient {
|
|||
set_url(URL url) =|
|
||||
get_title() => (String title)
|
||||
refresh() =|
|
||||
back() =|
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ Vector<Client::Route> Client::s_routes = {
|
|||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "title" }, &Client::handle_get_title },
|
||||
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "window" }, &Client::handle_delete_window },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "refresh" }, &Client::handle_refresh },
|
||||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "back" }, &Client::handle_back },
|
||||
};
|
||||
|
||||
Client::Client(NonnullOwnPtr<Core::Stream::BufferedTCPSocket> socket, Core::Object* parent)
|
||||
|
@ -463,4 +464,15 @@ ErrorOr<JsonValue, HttpError> Client::handle_refresh(Vector<StringView> paramete
|
|||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// POST /session/{session id}/back https://w3c.github.io/webdriver/#dfn-back
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_back(Vector<StringView> parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/back");
|
||||
Session* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
// NOTE: Spec steps handled in Session::back().
|
||||
auto result = TRY(session->back());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ private:
|
|||
ErrorOr<JsonValue, HttpError> handle_get_title(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_delete_window(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_refresh(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_back(Vector<StringView>, JsonValue const& payload);
|
||||
|
||||
ErrorOr<Session*, HttpError> find_session_with_id(StringView session_id);
|
||||
JsonValue make_json_value(JsonValue const&);
|
||||
|
|
|
@ -183,4 +183,27 @@ ErrorOr<JsonValue, HttpError> Session::refresh()
|
|||
return JsonValue();
|
||||
}
|
||||
|
||||
// POST /session/{session id}/back https://w3c.github.io/webdriver/#dfn-back
|
||||
ErrorOr<JsonValue, HttpError> Session::back()
|
||||
{
|
||||
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
|
||||
auto current_window = get_window_object();
|
||||
if (!current_window.has_value())
|
||||
return HttpError { 404, "no such window", "Window not found" };
|
||||
|
||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||
|
||||
// 3. Traverse the history by a delta –1 for the current browsing context.
|
||||
m_browser_connection->async_back();
|
||||
|
||||
// FIXME: 4. If the previous step completed results in a pageHide event firing, wait until pageShow event
|
||||
// fires or for the session page load timeout milliseconds to pass, whichever occurs sooner.
|
||||
|
||||
// FIXME: 5. If the previous step completed by the session page load timeout being reached, and user
|
||||
// prompts have been handled, return error with error code timeout.
|
||||
|
||||
// 6. Return success with data null.
|
||||
return JsonValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
ErrorOr<JsonValue, HttpError> get_url();
|
||||
ErrorOr<JsonValue, HttpError> get_title();
|
||||
ErrorOr<JsonValue, HttpError> refresh();
|
||||
ErrorOr<JsonValue, HttpError> back();
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Client> m_client;
|
||||
|
|
Loading…
Reference in a new issue