فهرست منبع

WebDriver: Implement POST /session/{id}/forward endpoint

Moustafa Raafat 2 سال پیش
والد
کامیت
a4fa604bde

+ 7 - 0
Userland/Applications/Browser/WebDriverConnection.cpp

@@ -60,4 +60,11 @@ void WebDriverConnection::back()
         browser_window->active_tab().go_back();
 }
 
+void WebDriverConnection::forward()
+{
+    dbgln("WebDriverConnection: forward");
+    if (auto browser_window = m_browser_window.strong_ref())
+        browser_window->active_tab().go_forward();
+}
+
 }

+ 1 - 0
Userland/Applications/Browser/WebDriverConnection.h

@@ -41,6 +41,7 @@ public:
     virtual Messages::WebDriverSessionClient::GetTitleResponse get_title() override;
     virtual void refresh() override;
     virtual void back() override;
+    virtual void forward() override;
 
 private:
     WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window);

+ 1 - 0
Userland/Applications/Browser/WebDriverSessionClient.ipc

@@ -8,4 +8,5 @@ endpoint WebDriverSessionClient {
     get_title() => (String title)
     refresh() =|
     back() =|
+    forward() =|
 }

+ 12 - 0
Userland/Services/WebDriver/Client.cpp

@@ -28,6 +28,7 @@ Vector<Client::Route> Client::s_routes = {
     { 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 },
+    { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "forward" }, &Client::handle_forward },
 };
 
 Client::Client(NonnullOwnPtr<Core::Stream::BufferedTCPSocket> socket, Core::Object* parent)
@@ -475,4 +476,15 @@ ErrorOr<JsonValue, HttpError> Client::handle_back(Vector<StringView> parameters,
     return make_json_value(result);
 }
 
+// POST /session/{session id}/forward https://w3c.github.io/webdriver/#dfn-forward
+ErrorOr<JsonValue, HttpError> Client::handle_forward(Vector<StringView> parameters, JsonValue const&)
+{
+    dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/forward");
+    Session* session = TRY(find_session_with_id(parameters[0]));
+
+    // NOTE: Spec steps handled in Session::forward().
+    auto result = TRY(session->forward());
+    return make_json_value(result);
+}
+
 }

+ 1 - 0
Userland/Services/WebDriver/Client.h

@@ -55,6 +55,7 @@ private:
     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<JsonValue, HttpError> handle_forward(Vector<StringView>, JsonValue const& payload);
 
     ErrorOr<Session*, HttpError> find_session_with_id(StringView session_id);
     JsonValue make_json_value(JsonValue const&);

+ 23 - 0
Userland/Services/WebDriver/Session.cpp

@@ -206,4 +206,27 @@ ErrorOr<JsonValue, HttpError> Session::back()
     return JsonValue();
 }
 
+// POST /session/{session id}/forward https://w3c.github.io/webdriver/#dfn-forward
+ErrorOr<JsonValue, HttpError> Session::forward()
+{
+    // 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_forward();
+
+    // 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();
+}
+
 }

+ 1 - 0
Userland/Services/WebDriver/Session.h

@@ -39,6 +39,7 @@ public:
     ErrorOr<JsonValue, HttpError> get_title();
     ErrorOr<JsonValue, HttpError> refresh();
     ErrorOr<JsonValue, HttpError> back();
+    ErrorOr<JsonValue, HttpError> forward();
 
 private:
     NonnullRefPtr<Client> m_client;