summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorTobias Christiansen <tobyase@serenityos.org>2022-10-14 18:09:33 +0200
committerSam Atkins <atkinssj@gmail.com>2022-10-15 15:43:42 +0100
commit1179d951f6ea518b88da129f5ff269a9139ec9c8 (patch)
tree0be8cd90ef85a0a750fdb29fcbff597f8f520034 /Userland/Services
parent8653903beec8e166765c587e2f50c9beb1add456 (diff)
downloadserenity-1179d951f6ea518b88da129f5ff269a9139ec9c8.zip
WebDriver: Implement `POST /session/{id}/refresh` endpoint
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/WebDriver/Client.cpp12
-rw-r--r--Userland/Services/WebDriver/Client.h1
-rw-r--r--Userland/Services/WebDriver/Session.cpp25
-rw-r--r--Userland/Services/WebDriver/Session.h1
4 files changed, 39 insertions, 0 deletions
diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp
index 8daaa507c4..25ea87bba4 100644
--- a/Userland/Services/WebDriver/Client.cpp
+++ b/Userland/Services/WebDriver/Client.cpp
@@ -26,6 +26,7 @@ Vector<Client::Route> Client::s_routes = {
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "url" }, &Client::handle_get_url },
{ 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 },
};
Client::Client(NonnullOwnPtr<Core::Stream::BufferedTCPSocket> socket, Core::Object* parent)
@@ -451,4 +452,15 @@ ErrorOr<JsonValue, HttpError> Client::handle_delete_window(Vector<StringView> pa
return make_json_value(JsonValue());
}
+// POST /session/{session id}/refresh https://w3c.github.io/webdriver/#dfn-refresh
+ErrorOr<JsonValue, HttpError> Client::handle_refresh(Vector<StringView> parameters, JsonValue const&)
+{
+ dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/refresh");
+ Session* session = TRY(find_session_with_id(parameters[0]));
+
+ // NOTE: Spec steps handled in Session::refresh().
+ auto result = TRY(session->refresh());
+ return make_json_value(result);
+}
+
}
diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h
index 5360fdd5e8..a5b5d8bcde 100644
--- a/Userland/Services/WebDriver/Client.h
+++ b/Userland/Services/WebDriver/Client.h
@@ -53,6 +53,7 @@ private:
ErrorOr<JsonValue, HttpError> handle_get_url(Vector<StringView>, JsonValue const& payload);
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<Session*, HttpError> find_session_with_id(StringView session_id);
JsonValue make_json_value(JsonValue const&);
diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp
index f12716e220..36fd0110a1 100644
--- a/Userland/Services/WebDriver/Session.cpp
+++ b/Userland/Services/WebDriver/Session.cpp
@@ -158,4 +158,29 @@ ErrorOr<JsonValue, HttpError> Session::get_title()
return JsonValue(m_browser_connection->get_title());
}
+// POST /session/{session id}/refresh https://w3c.github.io/webdriver/#dfn-refresh
+ErrorOr<JsonValue, HttpError> Session::refresh()
+{
+ // 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. Initiate an overridden reload of the current top-level browsing context’s active document.
+ m_browser_connection->async_refresh();
+
+ // FIXME: 4. If url is special except for file:
+
+ // FIXME: 1. Try to wait for navigation to complete.
+
+ // FIXME: 2. Try to run the post-navigation checks.
+
+ // FIXME: 5. Set the current browsing context with current top-level browsing context.
+
+ // 6. Return success with data null.
+ return JsonValue();
+}
+
}
diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h
index 407702d988..a334322958 100644
--- a/Userland/Services/WebDriver/Session.h
+++ b/Userland/Services/WebDriver/Session.h
@@ -37,6 +37,7 @@ public:
ErrorOr<JsonValue, HttpError> post_url(JsonValue const& url);
ErrorOr<JsonValue, HttpError> get_url();
ErrorOr<JsonValue, HttpError> get_title();
+ ErrorOr<JsonValue, HttpError> refresh();
private:
NonnullRefPtr<Client> m_client;