Ver Fonte

WebDriver: Move `GET /session/{session id}/window` impl into Session

Linus Groh há 2 anos atrás
pai
commit
24ee5a2202

+ 3 - 7
Userland/Services/WebDriver/Client.cpp

@@ -533,13 +533,9 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_window_handle(Vector<StringView
     dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window");
     auto* session = TRY(find_session_with_id(parameters[0]));
 
-    // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
-    auto current_window = session->get_window_object();
-    if (!current_window.has_value())
-        return HttpError { 404, "no such window", "Window not found" };
-
-    // 2. Return success with data being the window handle associated with the current top-level browsing context.
-    return make_json_value(session->current_window_handle());
+    // NOTE: Spec steps handled in Session::get_title().
+    auto result = TRY(session->get_window_handle());
+    return make_json_value(result);
 }
 
 // 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window

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

@@ -235,6 +235,18 @@ ErrorOr<JsonValue, HttpError> Session::get_title()
     return JsonValue(m_browser_connection->get_title());
 }
 
+// 11.1 Get Window Handle, https://w3c.github.io/webdriver/#get-window-handle
+ErrorOr<JsonValue, HttpError> Session::get_window_handle()
+{
+    // 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" };
+
+    // 2. Return success with data being the window handle associated with the current top-level browsing context.
+    return m_current_window_handle;
+}
+
 // 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
 ErrorOr<void, Variant<HttpError, Error>> Session::close_window()
 {

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

@@ -47,6 +47,7 @@ public:
     ErrorOr<JsonValue, HttpError> forward();
     ErrorOr<JsonValue, HttpError> refresh();
     ErrorOr<JsonValue, HttpError> get_title();
+    ErrorOr<JsonValue, HttpError> get_window_handle();
     ErrorOr<JsonValue, HttpError> find_element(JsonValue const& payload);
     ErrorOr<JsonValue, HttpError> find_elements(JsonValue const& payload);
     ErrorOr<JsonValue, HttpError> find_element_from_element(JsonValue const& payload, StringView parameter_element_id);