From 7cb9b85c25b005efdeeda8d35e06d6e19a059a67 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 19 Oct 2022 19:47:47 +0200 Subject: [PATCH] WebDriver: Rename Session::{get_window_object => current_window}() - It's not a "window object" (in the JS sense), it's a simple struct storing a handle and is_open property - We usually omit 'get' for getters - The new name makes it more clear that this is looked up using the m_current_window_handle as a key --- Userland/Services/WebDriver/Session.cpp | 37 ++++++++++++------------- Userland/Services/WebDriver/Session.h | 2 +- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index ad059426ed..f953177dfb 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -100,7 +100,7 @@ ErrorOr Session::set_timeouts(JsonValue const& payload) ErrorOr Session::navigate_to(JsonValue const& payload) { // 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(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -136,7 +136,7 @@ ErrorOr Session::navigate_to(JsonValue const& payload) ErrorOr Session::get_current_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(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -153,7 +153,7 @@ ErrorOr Session::get_current_url() ErrorOr 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(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -176,7 +176,7 @@ ErrorOr Session::back() ErrorOr 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(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -199,7 +199,7 @@ ErrorOr Session::forward() ErrorOr 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(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -224,7 +224,7 @@ ErrorOr Session::refresh() ErrorOr Session::get_title() { // 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(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -239,7 +239,7 @@ ErrorOr Session::get_title() ErrorOr 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(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -251,7 +251,7 @@ ErrorOr Session::get_window_handle() ErrorOr> Session::close_window() { // 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(); + auto current_window = this->current_window(); if (!current_window.has_value()) return Variant(HttpError { 404, "no such window", "Window not found" }); @@ -424,7 +424,7 @@ ErrorOr Session::find_element(JsonValue const& payload) auto selector = maybe_selector.to_string(); // 5. If the current browsing context is no longer open, return error with error code no such window. - auto current_window = get_window_object(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -481,7 +481,7 @@ ErrorOr Session::find_elements(JsonValue const& payload) auto selector = maybe_selector.to_string(); // 5. If the current browsing context is no longer open, return error with error code no such window. - auto current_window = get_window_object(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -533,7 +533,7 @@ ErrorOr Session::find_element_from_element(JsonValue const auto selector = maybe_selector.to_string(); // 5. If the current browsing context is no longer open, return error with error code no such window. - auto current_window = get_window_object(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -591,7 +591,7 @@ ErrorOr Session::find_elements_from_element(JsonValue cons auto selector = maybe_selector.to_string(); // 5. If the current browsing context is no longer open, return error with error code no such window. - auto current_window = get_window_object(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -617,7 +617,7 @@ ErrorOr Session::find_elements_from_element(JsonValue cons ErrorOr Session::get_element_attribute(JsonValue const&, StringView parameter_element_id, StringView name) { // 1. If the current browsing context is no longer open, return error with error code no such window. - auto current_window = get_window_object(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -669,7 +669,7 @@ static JsonObject serialize_cookie(Web::Cookie::Cookie const& cookie) ErrorOr Session::get_all_cookies() { // 1. If the current browsing context is no longer open, return error with error code no such window. - auto current_window = get_window_object(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -694,9 +694,8 @@ ErrorOr Session::get_all_cookies() // 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie ErrorOr Session::get_named_cookie(String const& name) { - // 1. If the current browsing context is no longer open, return error with error code no such window. - auto current_window = get_window_object(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -736,7 +735,7 @@ ErrorOr Session::add_cookie(JsonValue const& payload) return HttpError { 400, "invalid argument", "Cookie-Object doesn't contain all required keys" }; // 3. If the current browsing context is no longer open, return error with error code no such window. - auto current_window = get_window_object(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -857,7 +856,7 @@ void Session::delete_cookies(Optional const& name) ErrorOr Session::delete_cookie(StringView const& name) { // 1. If the current browsing context is no longer open, return error with error code no such window. - auto current_window = get_window_object(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; @@ -874,7 +873,7 @@ ErrorOr Session::delete_cookie(StringView const& name) ErrorOr Session::delete_all_cookies() { // 1. If the current browsing context is no longer open, return error with error code no such window. - auto current_window = get_window_object(); + auto current_window = this->current_window(); if (!current_window.has_value()) return HttpError { 404, "no such window", "Window not found" }; diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index be8c669243..002fb7ef41 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -33,7 +33,7 @@ public: i32 id; }; - Optional get_window_object() { return m_windows.get(m_current_window_handle); } + Optional current_window() { return m_windows.get(m_current_window_handle); } String const& current_window_handle() { return m_current_window_handle; } ErrorOr start();