summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-11-10 10:21:03 -0500
committerLinus Groh <mail@linusgroh.de>2022-11-10 17:02:11 +0000
commit5d32fd7026c43c72ed3b96634a2d0d66cf2caa37 (patch)
tree175179a6484ee2408927bad37d544392c514cad0
parent06f1b8825c51e26a8732687a30d80c26769458a1 (diff)
downloadserenity-5d32fd7026c43c72ed3b96634a2d0d66cf2caa37.zip
Browser+WebContent+WebDriver: Move Get Element Text to WebContent
-rw-r--r--Userland/Applications/Browser/BrowserWindow.cpp4
-rw-r--r--Userland/Applications/Browser/WebDriverConnection.cpp11
-rw-r--r--Userland/Applications/Browser/WebDriverConnection.h1
-rw-r--r--Userland/Applications/Browser/WebDriverEndpoints.h1
-rw-r--r--Userland/Applications/Browser/WebDriverSessionClient.ipc1
-rw-r--r--Userland/Libraries/LibWebView/OutOfProcessWebView.cpp5
-rw-r--r--Userland/Libraries/LibWebView/OutOfProcessWebView.h1
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.cpp9
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.h1
-rw-r--r--Userland/Services/WebContent/WebContentServer.ipc1
-rw-r--r--Userland/Services/WebContent/WebDriverClient.ipc1
-rw-r--r--Userland/Services/WebContent/WebDriverConnection.cpp18
-rw-r--r--Userland/Services/WebContent/WebDriverConnection.h1
-rw-r--r--Userland/Services/WebDriver/Client.cpp5
-rw-r--r--Userland/Services/WebDriver/Session.cpp23
-rw-r--r--Userland/Services/WebDriver/Session.h1
16 files changed, 22 insertions, 62 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp
index e6d4c12fab..6e855e8c0e 100644
--- a/Userland/Applications/Browser/BrowserWindow.cpp
+++ b/Userland/Applications/Browser/BrowserWindow.cpp
@@ -611,10 +611,6 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
active_tab().view().scroll_element_into_view(element_id);
};
- new_tab.webdriver_endpoints().on_get_element_text = [this](i32 element_id) {
- return active_tab().view().get_element_text(element_id);
- };
-
new_tab.webdriver_endpoints().on_get_element_tag_name = [this](i32 element_id) {
return active_tab().view().get_element_tag_name(element_id);
};
diff --git a/Userland/Applications/Browser/WebDriverConnection.cpp b/Userland/Applications/Browser/WebDriverConnection.cpp
index 0b5da0dd3f..8bb5cfcb8d 100644
--- a/Userland/Applications/Browser/WebDriverConnection.cpp
+++ b/Userland/Applications/Browser/WebDriverConnection.cpp
@@ -146,17 +146,6 @@ void WebDriverConnection::scroll_element_into_view(i32 element_id)
}
}
-Messages::WebDriverSessionClient::GetElementTextResponse WebDriverConnection::get_element_text(i32 element_id)
-{
- dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_element_text");
- if (auto browser_window = m_browser_window.strong_ref()) {
- auto& tab = browser_window->active_tab();
- if (tab.webdriver_endpoints().on_get_element_text)
- return { tab.webdriver_endpoints().on_get_element_text(element_id) };
- }
- return { "" };
-}
-
Messages::WebDriverSessionClient::GetElementTagNameResponse WebDriverConnection::get_element_tag_name(i32 element_id)
{
dbgln("WebDriverConnection: get_computed_value_for_element");
diff --git a/Userland/Applications/Browser/WebDriverConnection.h b/Userland/Applications/Browser/WebDriverConnection.h
index 7bb71ea999..994eb5aa7d 100644
--- a/Userland/Applications/Browser/WebDriverConnection.h
+++ b/Userland/Applications/Browser/WebDriverConnection.h
@@ -49,7 +49,6 @@ public:
virtual void add_cookie(Web::Cookie::ParsedCookie const&) override;
virtual void update_cookie(Web::Cookie::Cookie const&) override;
virtual void scroll_element_into_view(i32 element_id) override;
- virtual Messages::WebDriverSessionClient::GetElementTextResponse get_element_text(i32 element_id) override;
virtual Messages::WebDriverSessionClient::GetElementTagNameResponse get_element_tag_name(i32 element_id) override;
virtual Messages::WebDriverSessionClient::GetElementRectResponse get_element_rect(i32 element_id) override;
virtual Messages::WebDriverSessionClient::IsElementEnabledResponse is_element_enabled(i32 element_id) override;
diff --git a/Userland/Applications/Browser/WebDriverEndpoints.h b/Userland/Applications/Browser/WebDriverEndpoints.h
index 9b89dca8b4..c4f739ef61 100644
--- a/Userland/Applications/Browser/WebDriverEndpoints.h
+++ b/Userland/Applications/Browser/WebDriverEndpoints.h
@@ -24,7 +24,6 @@ public:
~WebDriverEndpoints() = default;
Function<void(i32 element_id)> on_scroll_element_into_view;
- Function<String(i32 element_id)> on_get_element_text;
Function<String(i32 element_id)> on_get_element_tag_name;
Function<Gfx::IntRect(i32 element_id)> on_get_element_rect;
Function<bool(i32 element_id)> on_is_element_enabled;
diff --git a/Userland/Applications/Browser/WebDriverSessionClient.ipc b/Userland/Applications/Browser/WebDriverSessionClient.ipc
index 16989327a8..ac23d01ea6 100644
--- a/Userland/Applications/Browser/WebDriverSessionClient.ipc
+++ b/Userland/Applications/Browser/WebDriverSessionClient.ipc
@@ -25,7 +25,6 @@ endpoint WebDriverSessionClient {
add_cookie(Web::Cookie::ParsedCookie cookie) =|
update_cookie(Web::Cookie::Cookie cookie) =|
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/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp
index 1a47b173fc..64ef065410 100644
--- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp
+++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp
@@ -559,11 +559,6 @@ void OutOfProcessWebView::scroll_element_into_view(i32 element_id)
return client().scroll_element_into_view(element_id);
}
-String OutOfProcessWebView::get_element_text(i32 element_id)
-{
- return client().get_element_text(element_id);
-}
-
String OutOfProcessWebView::get_element_tag_name(i32 element_id)
{
return client().get_element_tag_name(element_id);
diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h
index 68ed2afee0..05a3907144 100644
--- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h
+++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h
@@ -64,7 +64,6 @@ public:
OrderedHashMap<String, String> get_session_storage_entries();
void scroll_element_into_view(i32 element_id);
- String get_element_text(i32 element_id);
String get_element_tag_name(i32 element_id);
Gfx::IntRect get_element_rect(i32 element_id);
bool is_element_enabled(i32 element_id);
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);