diff options
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/WebContent/ConnectionFromClient.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/WebContent/ConnectionFromClient.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebContentServer.ipc | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverClient.ipc | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.cpp | 18 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.cpp | 5 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Session.cpp | 23 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Session.h | 1 |
9 files changed, 22 insertions, 38 deletions
diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index b122df7edc..89f6690211 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -494,15 +494,6 @@ void ConnectionFromClient::scroll_element_into_view(i32 element_id) element->scroll_into_view(options); } -Messages::WebContentServer::GetElementTextResponse ConnectionFromClient::get_element_text(i32 element_id) -{ - auto element = find_element_by_id(element_id); - if (!element.has_value()) - return { "" }; - - return { element->layout_node()->dom_node()->text_content() }; -} - Messages::WebContentServer::GetElementTagNameResponse ConnectionFromClient::get_element_tag_name(i32 element_id) { auto element = find_element_by_id(element_id); diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index a2dce5887c..07bed678ae 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -84,7 +84,6 @@ private: virtual void js_console_request_messages(i32) override; virtual void scroll_element_into_view(i32 element_id) override; - virtual Messages::WebContentServer::GetElementTextResponse get_element_text(i32 element_id) override; virtual Messages::WebContentServer::GetElementTagNameResponse get_element_tag_name(i32 element_id) override; virtual Messages::WebContentServer::GetElementRectResponse get_element_rect(i32 element_id) override; virtual Messages::WebContentServer::IsElementEnabledResponse is_element_enabled(i32 element_id) override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index dd8352ed78..03d5528f09 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -43,7 +43,6 @@ endpoint WebContentServer js_console_request_messages(i32 start_index) =| scroll_element_into_view(i32 element_id) => () - get_element_text(i32 element_id) => (String text) get_element_tag_name(i32 element_id) => (String tag_name) get_element_rect(i32 element_id) => (Gfx::IntRect rect) is_element_enabled(i32 element_id) => (bool enabled) diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index d4d748a334..f02787e960 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -17,4 +17,5 @@ endpoint WebDriverClient { get_element_attribute(String element_id, String name) => (Web::WebDriver::Response response) get_element_property(String element_id, String name) => (Web::WebDriver::Response response) get_element_css_value(String element_id, String name) => (Web::WebDriver::Response response) + get_element_text(String element_id) => (Web::WebDriver::Response response) } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index f84a98e2f2..79a2d4face 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -590,6 +590,24 @@ Messages::WebDriverClient::GetElementCssValueResponse WebDriverConnection::get_e return make_success_response(move(computed_value)); } +// 12.4.5 Get Element Text, https://w3c.github.io/webdriver/#dfn-get-element-text +Messages::WebDriverClient::GetElementTextResponse WebDriverConnection::get_element_text(String const& element_id) +{ + // 1. If the current browsing context is no longer open, return error with error code no such window. + TRY(ensure_open_top_level_browsing_context()); + + // FIXME: 2. Handle any user prompts and return its value if it is an error. + + // 3. Let element be the result of trying to get a known connected element with url variable element id. + auto* element = TRY(get_known_connected_element(element_id)); + + // 4. Let rendered text be the result of performing implementation-specific steps whose result is exactly the same as the result of a Function.[[Call]](null, element) with bot.dom.getVisibleText as the this value. + auto rendered_text = element->text_content(); + + // 5. Return success with data rendered text. + return make_success_response(move(rendered_text)); +} + // https://w3c.github.io/webdriver/#dfn-no-longer-open ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context() { diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index 6bf3c6f01d..09210038d7 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -47,6 +47,7 @@ private: virtual Messages::WebDriverClient::GetElementAttributeResponse get_element_attribute(String const& element_id, String const& name) override; virtual Messages::WebDriverClient::GetElementPropertyResponse get_element_property(String const& element_id, String const& name) override; virtual Messages::WebDriverClient::GetElementCssValueResponse get_element_css_value(String const& element_id, String const& name) override; + virtual Messages::WebDriverClient::GetElementTextResponse get_element_text(String const& element_id) override; ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context(); void restore_the_window(); diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index e8979e30ed..560ee4ff33 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -686,12 +686,11 @@ Web::WebDriver::Response Client::handle_get_element_css_value(Vector<StringView> // 12.4.5 Get Element Text, https://w3c.github.io/webdriver/#dfn-get-element-text // GET /session/{session id}/element/{element id}/text -Web::WebDriver::Response Client::handle_get_element_text(Vector<StringView> const& parameters, JsonValue const& payload) +Web::WebDriver::Response Client::handle_get_element_text(Vector<StringView> const& parameters, JsonValue const&) { dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/text"); auto* session = TRY(find_session_with_id(parameters[0])); - auto result = TRY(session->get_element_text(payload, parameters[1])); - return make_json_value(result); + return session->web_content_connection().get_element_text(parameters[1]); } // 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index c12204d358..2613d2b943 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -323,29 +323,6 @@ static ErrorOr<i32, Web::WebDriver::Error> get_known_connected_element(StringVie return maybe_element_id.release_value(); } -// 12.4.5 Get Element Text, https://w3c.github.io/webdriver/#dfn-get-element-text -Web::WebDriver::Response Session::get_element_text(JsonValue const&, StringView parameter_element_id) -{ - // 1. If the current browsing context is no longer open, return error with error code no such window. - TRY(check_for_open_top_level_browsing_context_or_return_error()); - - // FIXME: 2. Handle any user prompts and return its value if it is an error. - - // FIXME: 3. Let element be the result of trying to get a known connected element with url variable element id. - auto maybe_element_id = parameter_element_id.to_int(); - if (!maybe_element_id.has_value()) - return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Element ID is not an i32"); - - auto element_id = maybe_element_id.release_value(); - - // 4. Let rendered text be the result of performing implementation-specific steps whose result is exactly the - // same as the result of a Function.[[Call]](null, element) with bot.dom.getVisibleText as the this value. - auto rendered_text = m_browser_connection->get_element_text(element_id); - - // 5. Return success with data rendered text. - return JsonValue(rendered_text); -} - // 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name Web::WebDriver::Response Session::get_element_tag_name(JsonValue const&, StringView parameter_element_id) { diff --git a/Userland/Services/WebDriver/Session.h b/Userland/Services/WebDriver/Session.h index 9b1081f447..c7027ec316 100644 --- a/Userland/Services/WebDriver/Session.h +++ b/Userland/Services/WebDriver/Session.h @@ -58,7 +58,6 @@ public: Web::WebDriver::Response get_window_handle(); ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window(); Web::WebDriver::Response get_window_handles() const; - Web::WebDriver::Response get_element_text(JsonValue const& payload, StringView element_id); Web::WebDriver::Response get_element_tag_name(JsonValue const& payload, StringView element_id); Web::WebDriver::Response get_element_rect(StringView element_id); Web::WebDriver::Response is_element_enabled(StringView element_id); |