mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
WebDriver: Implement GET /session/{id}/url
endpoint
This commit is contained in:
parent
a15d32982a
commit
096fe865c6
Notes:
sideshowbarker
2024-07-17 06:00:14 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/096fe865c6 Pull-request: https://github.com/SerenityOS/serenity/pull/15504 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg
3 changed files with 23 additions and 3 deletions
|
@ -417,12 +417,14 @@ ErrorOr<JsonValue, HttpError> Client::handle_post_url(Vector<StringView> paramet
|
|||
}
|
||||
|
||||
// GET /session/{session id}/url https://w3c.github.io/webdriver/#dfn-get-current-url
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_get_url(Vector<StringView>, JsonValue const&)
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_get_url(Vector<StringView> parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/url");
|
||||
Session* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
// FIXME: Implement the spec steps
|
||||
return HttpError { 400, "", "" };
|
||||
// NOTE: Spec steps handled in Session::get_url().
|
||||
auto result = TRY(session->get_url());
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// GET /session/{session id}/title https://w3c.github.io/webdriver/#dfn-get-title
|
||||
|
|
|
@ -126,6 +126,23 @@ ErrorOr<JsonValue, HttpError> Session::post_url(JsonValue const& payload)
|
|||
return JsonValue();
|
||||
}
|
||||
|
||||
// GET /session/{session id}/url https://w3c.github.io/webdriver/#dfn-get-current-url
|
||||
ErrorOr<JsonValue, HttpError> Session::get_url()
|
||||
{
|
||||
// 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 { 400, "no such window", "Window not found" };
|
||||
|
||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||
|
||||
// 3. Let url be the serialization of the current top-level browsing context’s active document’s document URL.
|
||||
auto url = m_browser_connection->get_url().to_string();
|
||||
|
||||
// 4. Return success with data url.
|
||||
return JsonValue(url);
|
||||
}
|
||||
|
||||
// GET /session/{session id}/title https://w3c.github.io/webdriver/#dfn-get-title
|
||||
ErrorOr<JsonValue, HttpError> Session::get_title()
|
||||
{
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
ErrorOr<void> stop();
|
||||
ErrorOr<void, Variant<HttpError, Error>> delete_window();
|
||||
ErrorOr<JsonValue, HttpError> post_url(JsonValue const& url);
|
||||
ErrorOr<JsonValue, HttpError> get_url();
|
||||
ErrorOr<JsonValue, HttpError> get_title();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue