mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:27:44 +00:00
Browser+WebContent+WebDriver: Move Get Element CSS Value to WebContent
This commit is contained in:
parent
3c00d0e92b
commit
06f1b8825c
16 changed files with 39 additions and 121 deletions
|
@ -611,14 +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_active_documents_type = [this]() {
|
||||
return active_tab().view().get_active_documents_type();
|
||||
};
|
||||
|
||||
new_tab.webdriver_endpoints().on_get_computed_value_for_element = [this](i32 element_id, String const& property_name) {
|
||||
return active_tab().view().get_computed_value_for_element(element_id, property_name);
|
||||
};
|
||||
|
||||
new_tab.webdriver_endpoints().on_get_element_text = [this](i32 element_id) {
|
||||
return active_tab().view().get_element_text(element_id);
|
||||
};
|
||||
|
|
|
@ -146,28 +146,6 @@ void WebDriverConnection::scroll_element_into_view(i32 element_id)
|
|||
}
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::GetActiveDocumentsTypeResponse WebDriverConnection::get_active_documents_type()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_active_documents_type");
|
||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||
auto& tab = browser_window->active_tab();
|
||||
if (tab.webdriver_endpoints().on_get_active_documents_type)
|
||||
return { tab.webdriver_endpoints().on_get_active_documents_type() };
|
||||
}
|
||||
return { "" };
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::GetComputedValueForElementResponse WebDriverConnection::get_computed_value_for_element(i32 element_id, String const& property_name)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_computed_value_for_element");
|
||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||
auto& tab = browser_window->active_tab();
|
||||
if (tab.webdriver_endpoints().on_get_computed_value_for_element)
|
||||
return { tab.webdriver_endpoints().on_get_computed_value_for_element(element_id, property_name) };
|
||||
}
|
||||
return { "" };
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::GetElementTextResponse WebDriverConnection::get_element_text(i32 element_id)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_element_text");
|
||||
|
|
|
@ -49,8 +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::GetActiveDocumentsTypeResponse get_active_documents_type() override;
|
||||
virtual Messages::WebDriverSessionClient::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) 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;
|
||||
|
|
|
@ -24,8 +24,6 @@ public:
|
|||
~WebDriverEndpoints() = default;
|
||||
|
||||
Function<void(i32 element_id)> on_scroll_element_into_view;
|
||||
Function<String()> on_get_active_documents_type;
|
||||
Function<String(i32 element_id, String const&)> on_get_computed_value_for_element;
|
||||
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;
|
||||
|
|
|
@ -25,8 +25,6 @@ endpoint WebDriverSessionClient {
|
|||
add_cookie(Web::Cookie::ParsedCookie cookie) =|
|
||||
update_cookie(Web::Cookie::Cookie cookie) =|
|
||||
scroll_element_into_view(i32 element_id) => ()
|
||||
get_active_documents_type() => (String type)
|
||||
get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value)
|
||||
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)
|
||||
|
|
|
@ -559,16 +559,6 @@ void OutOfProcessWebView::scroll_element_into_view(i32 element_id)
|
|||
return client().scroll_element_into_view(element_id);
|
||||
}
|
||||
|
||||
String OutOfProcessWebView::get_active_documents_type()
|
||||
{
|
||||
return client().get_active_documents_type();
|
||||
}
|
||||
|
||||
String OutOfProcessWebView::get_computed_value_for_element(i32 element_id, String const& property_name)
|
||||
{
|
||||
return client().get_computed_value_for_element(element_id, property_name);
|
||||
}
|
||||
|
||||
String OutOfProcessWebView::get_element_text(i32 element_id)
|
||||
{
|
||||
return client().get_element_text(element_id);
|
||||
|
|
|
@ -64,8 +64,6 @@ public:
|
|||
OrderedHashMap<String, String> get_session_storage_entries();
|
||||
|
||||
void scroll_element_into_view(i32 element_id);
|
||||
String get_active_documents_type();
|
||||
String get_computed_value_for_element(i32 element_id, String const& property_name);
|
||||
String get_element_text(i32 element_id);
|
||||
String get_element_tag_name(i32 element_id);
|
||||
Gfx::IntRect get_element_rect(i32 element_id);
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include <LibJS/Runtime/ConsoleObject.h>
|
||||
#include <LibJS/Runtime/JSONObject.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/NodeList.h>
|
||||
|
@ -495,44 +494,6 @@ void ConnectionFromClient::scroll_element_into_view(i32 element_id)
|
|||
element->scroll_into_view(options);
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetActiveDocumentsTypeResponse ConnectionFromClient::get_active_documents_type()
|
||||
{
|
||||
auto* active_document = page().top_level_browsing_context().active_document();
|
||||
|
||||
if (!active_document)
|
||||
return { "" };
|
||||
|
||||
auto type = active_document->document_type();
|
||||
|
||||
switch (type) {
|
||||
case Web::DOM::Document::Type::HTML:
|
||||
return { "html" };
|
||||
break;
|
||||
case Web::DOM::Document::Type::XML:
|
||||
return { "xml" };
|
||||
break;
|
||||
}
|
||||
|
||||
return { "" };
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetComputedValueForElementResponse ConnectionFromClient::get_computed_value_for_element(i32 element_id, String const& property_name)
|
||||
{
|
||||
auto element = find_element_by_id(element_id);
|
||||
if (!element.has_value())
|
||||
return { "" };
|
||||
|
||||
auto property_id = Web::CSS::property_id_from_string(property_name);
|
||||
|
||||
auto computed_values = element->computed_css_values();
|
||||
if (!computed_values)
|
||||
return { "" };
|
||||
|
||||
auto style_value = computed_values->property(property_id);
|
||||
|
||||
return { style_value->to_string() };
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetElementTextResponse ConnectionFromClient::get_element_text(i32 element_id)
|
||||
{
|
||||
auto element = find_element_by_id(element_id);
|
||||
|
|
|
@ -84,8 +84,6 @@ private:
|
|||
virtual void js_console_request_messages(i32) override;
|
||||
|
||||
virtual void scroll_element_into_view(i32 element_id) override;
|
||||
virtual Messages::WebContentServer::GetActiveDocumentsTypeResponse get_active_documents_type() override;
|
||||
virtual Messages::WebContentServer::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) 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;
|
||||
|
|
|
@ -43,8 +43,6 @@ endpoint WebContentServer
|
|||
js_console_request_messages(i32 start_index) =|
|
||||
|
||||
scroll_element_into_view(i32 element_id) => ()
|
||||
get_active_documents_type() => (String type)
|
||||
get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value)
|
||||
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)
|
||||
|
|
|
@ -16,4 +16,5 @@ endpoint WebDriverClient {
|
|||
is_element_selected(String element_id) => (Web::WebDriver::Response response)
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
#include <AK/JsonValue.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/StyleProperties.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/HTML/AttributeNames.h>
|
||||
|
@ -555,6 +558,38 @@ Messages::WebDriverClient::GetElementPropertyResponse WebDriverConnection::get_e
|
|||
return make_success_response({});
|
||||
}
|
||||
|
||||
// 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value
|
||||
Messages::WebDriverClient::GetElementCssValueResponse WebDriverConnection::get_element_css_value(String const& element_id, String const& name)
|
||||
{
|
||||
// 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 computed value be the result of the first matching condition:
|
||||
String computed_value;
|
||||
|
||||
// -> current browsing context’s active document’s type is not "xml"
|
||||
if (!m_page_host.page().top_level_browsing_context().active_document()->is_xml_document()) {
|
||||
// computed value of parameter property name from element’s style declarations. property name is obtained from url variables.
|
||||
auto property = Web::CSS::property_id_from_string(name);
|
||||
|
||||
if (auto* computed_values = element->computed_css_values())
|
||||
computed_value = computed_values->property(property)->to_string();
|
||||
}
|
||||
// -> Otherwise
|
||||
else {
|
||||
// "" (empty string)
|
||||
computed_value = String::empty();
|
||||
}
|
||||
|
||||
// 5. Return success with data computed value.
|
||||
return make_success_response(move(computed_value));
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-no-longer-open
|
||||
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
|
||||
{
|
||||
|
|
|
@ -46,6 +46,7 @@ private:
|
|||
virtual Messages::WebDriverClient::IsElementSelectedResponse is_element_selected(String const& element_id) override;
|
||||
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;
|
||||
|
||||
ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
|
||||
void restore_the_window();
|
||||
|
|
|
@ -677,12 +677,11 @@ Web::WebDriver::Response Client::handle_get_element_property(Vector<StringView>
|
|||
|
||||
// 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value
|
||||
// GET /session/{session id}/element/{element id}/css/{property name}
|
||||
Web::WebDriver::Response Client::handle_get_element_css_value(Vector<StringView> const& parameters, JsonValue const& payload)
|
||||
Web::WebDriver::Response Client::handle_get_element_css_value(Vector<StringView> const& parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/css/<property_name>");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
auto result = TRY(session->get_element_css_value(payload, parameters[1], parameters[2]));
|
||||
return make_json_value(result);
|
||||
return session->web_content_connection().get_element_css_value(parameters[1], parameters[2]);
|
||||
}
|
||||
|
||||
// 12.4.5 Get Element Text, https://w3c.github.io/webdriver/#dfn-get-element-text
|
||||
|
|
|
@ -323,32 +323,6 @@ static ErrorOr<i32, Web::WebDriver::Error> get_known_connected_element(StringVie
|
|||
return maybe_element_id.release_value();
|
||||
}
|
||||
|
||||
// 12.4.4 Get Element CSS Value, https://w3c.github.io/webdriver/#dfn-get-element-css-value
|
||||
Web::WebDriver::Response Session::get_element_css_value(JsonValue const&, StringView parameter_element_id, StringView property_name)
|
||||
{
|
||||
// 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.
|
||||
|
||||
// 3. Let element be the result of trying to get a known connected element with url variable element id.
|
||||
auto element_id = TRY(get_known_connected_element(parameter_element_id));
|
||||
|
||||
// 4. Let computed value be the result of the first matching condition:
|
||||
// -> current browsing context’s active document’s type is not "xml"
|
||||
// computed value of parameter property name from element’s style declarations. property name is obtained from url variables.
|
||||
// -> Otherwise
|
||||
// "" (empty string)
|
||||
auto active_documents_type = m_browser_connection->get_active_documents_type();
|
||||
if (active_documents_type == "xml")
|
||||
return JsonValue("");
|
||||
|
||||
auto computed_value = m_browser_connection->get_computed_value_for_element(element_id, property_name);
|
||||
|
||||
// 5. Return success with data computed value.
|
||||
return JsonValue(computed_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)
|
||||
{
|
||||
|
|
|
@ -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_css_value(JsonValue const& payload, StringView element_id, StringView property_name);
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue