1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:37:37 +00:00

Browser+WebContent+WebDriver: Move Is Element Enabled to WebContent

This commit is contained in:
Timothy Flynn 2022-11-10 10:39:09 -05:00 committed by Linus Groh
parent 30d6a73d0e
commit 93e14799c5
16 changed files with 29 additions and 70 deletions

View file

@ -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_is_element_enabled = [this](i32 element_id) {
return active_tab().view().is_element_enabled(element_id);
};
new_tab.webdriver_endpoints().on_serialize_source = [this]() {
return active_tab().view().serialize_source();
};

View file

@ -146,17 +146,6 @@ void WebDriverConnection::scroll_element_into_view(i32 element_id)
}
}
Messages::WebDriverSessionClient::IsElementEnabledResponse WebDriverConnection::is_element_enabled(i32 element_id)
{
dbgln("WebDriverConnection: is_element_enabled {}", element_id);
if (auto browser_window = m_browser_window.strong_ref()) {
auto& tab = browser_window->active_tab();
if (tab.webdriver_endpoints().on_is_element_enabled)
return { tab.webdriver_endpoints().on_is_element_enabled(element_id) };
}
return { false };
}
Messages::WebDriverSessionClient::TakeScreenshotResponse WebDriverConnection::take_screenshot()
{
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: take_screenshot");

View file

@ -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::IsElementEnabledResponse is_element_enabled(i32 element_id) override;
virtual Messages::WebDriverSessionClient::TakeScreenshotResponse take_screenshot() override;
virtual Messages::WebDriverSessionClient::TakeElementScreenshotResponse take_element_screenshot(i32 element_id) override;

View file

@ -24,7 +24,6 @@ public:
~WebDriverEndpoints() = default;
Function<void(i32 element_id)> on_scroll_element_into_view;
Function<bool(i32 element_id)> on_is_element_enabled;
Function<Gfx::ShareableBitmap(i32 element_id)> on_take_element_screenshot;
Function<String()> on_serialize_source;
Function<Messages::WebContentServer::WebdriverExecuteScriptResponse(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)> on_execute_script;

View file

@ -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) => ()
is_element_enabled(i32 element_id) => (bool enabled)
take_screenshot() => (Gfx::ShareableBitmap data)
take_element_screenshot(i32 element_id) => (Gfx::ShareableBitmap data)
}

View file

@ -559,11 +559,6 @@ void OutOfProcessWebView::scroll_element_into_view(i32 element_id)
return client().scroll_element_into_view(element_id);
}
bool OutOfProcessWebView::is_element_enabled(i32 element_id)
{
return client().is_element_enabled(element_id);
}
void OutOfProcessWebView::set_content_filters(Vector<String> filters)
{
client().async_set_content_filters(filters);

View file

@ -64,7 +64,6 @@ public:
OrderedHashMap<String, String> get_session_storage_entries();
void scroll_element_into_view(i32 element_id);
bool is_element_enabled(i32 element_id);
void set_content_filters(Vector<String>);
void set_proxy_mappings(Vector<String> proxies, HashMap<String, size_t> mappings);

View file

@ -26,7 +26,6 @@
#include <LibWeb/Dump.h>
#include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
#include <LibWeb/HTML/Storage.h>
#include <LibWeb/HTML/Window.h>
@ -525,26 +524,6 @@ static Gfx::IntRect calculate_absolute_rect_of_element(Web::Page const& page, We
};
}
Messages::WebContentServer::IsElementEnabledResponse ConnectionFromClient::is_element_enabled(i32 element_id)
{
auto element = find_element_by_id(element_id);
if (!element.has_value())
return { false };
auto* document = page().top_level_browsing_context().active_document();
if (!document)
return { false };
bool enabled = !document->is_xml_document();
if (enabled && is<Web::HTML::FormAssociatedElement>(*element)) {
auto& form_associated_element = dynamic_cast<Web::HTML::FormAssociatedElement&>(*element);
enabled = form_associated_element.enabled();
}
return { enabled };
}
Messages::WebContentServer::TakeElementScreenshotResponse ConnectionFromClient::take_element_screenshot(i32 element_id)
{
auto element = find_element_by_id(element_id);

View file

@ -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::IsElementEnabledResponse is_element_enabled(i32 element_id) override;
virtual Messages::WebContentServer::TakeElementScreenshotResponse take_element_screenshot(i32 element_id) override;
virtual Messages::WebContentServer::TakeDocumentScreenshotResponse take_document_screenshot() override;

View file

@ -43,7 +43,6 @@ endpoint WebContentServer
js_console_request_messages(i32 start_index) =|
scroll_element_into_view(i32 element_id) => ()
is_element_enabled(i32 element_id) => (bool enabled)
take_element_screenshot(i32 element_id) => (Gfx::ShareableBitmap data)
take_document_screenshot() => (Gfx::ShareableBitmap data)

View file

@ -20,4 +20,5 @@ endpoint WebDriverClient {
get_element_text(String element_id) => (Web::WebDriver::Response response)
get_element_tag_name(String element_id) => (Web::WebDriver::Response response)
get_element_rect(String element_id) => (Web::WebDriver::Response response)
is_element_enabled(String element_id) => (Web::WebDriver::Response response)
}

View file

@ -20,6 +20,7 @@
#include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/HTML/AttributeNames.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/HTML/HTMLOptionElement.h>
#include <LibWeb/Page/Page.h>
@ -688,6 +689,31 @@ Messages::WebDriverClient::GetElementRectResponse WebDriverConnection::get_eleme
return body;
}
// 12.4.8 Is Element Enabled, https://w3c.github.io/webdriver/#dfn-is-element-enabled
Messages::WebDriverClient::IsElementEnabledResponse WebDriverConnection::is_element_enabled(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 enabled be a boolean initially set to true if the current browsing contexts active documents type is not "xml".
// 5. Otherwise, let enabled to false and jump to the last step of this algorithm.
bool enabled = !m_page_host.page().top_level_browsing_context().active_document()->is_xml_document();
// 6. Set enabled to false if a form control is disabled.
if (enabled && is<Web::HTML::FormAssociatedElement>(*element)) {
auto& form_associated_element = dynamic_cast<Web::HTML::FormAssociatedElement&>(*element);
enabled = form_associated_element.enabled();
}
// 7. Return success with data enabled.
return make_success_response(enabled);
}
// https://w3c.github.io/webdriver/#dfn-no-longer-open
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
{

View file

@ -50,6 +50,7 @@ private:
virtual Messages::WebDriverClient::GetElementTextResponse get_element_text(String const& element_id) override;
virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(String const& element_id) override;
virtual Messages::WebDriverClient::GetElementRectResponse get_element_rect(String const& element_id) override;
virtual Messages::WebDriverClient::IsElementEnabledResponse is_element_enabled(String const& element_id) override;
ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
void restore_the_window();

View file

@ -717,8 +717,7 @@ Web::WebDriver::Response Client::handle_is_element_enabled(Vector<StringView> co
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/element/<element_id>/enabled");
auto* session = TRY(find_session_with_id(parameters[0]));
auto result = TRY(session->is_element_enabled(parameters[1]));
return make_json_value(result);
return session->web_content_connection().is_element_enabled(parameters[1]);
}
// 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source

View file

@ -312,26 +312,6 @@ static ErrorOr<i32, Web::WebDriver::Error> get_known_connected_element(StringVie
return maybe_element_id.release_value();
}
// 12.4.8 Is Element Enabled, https://w3c.github.io/webdriver/#dfn-is-element-enabled
Web::WebDriver::Response Session::is_element_enabled(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.
// 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 enabled be a boolean initially set to true if the current browsing contexts active documents type is not "xml".
// 5. Otherwise, let enabled to false and jump to the last step of this algorithm.
// 6. Set enabled to false if a form control is disabled.
auto enabled = m_browser_connection->is_element_enabled(element_id);
// 7. Return success with data enabled.
return JsonValue { enabled };
}
// 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source
Web::WebDriver::Response Session::get_source()
{

View file

@ -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 is_element_enabled(StringView element_id);
Web::WebDriver::Response get_source();
Web::WebDriver::Response execute_script(JsonValue const& payload);
Web::WebDriver::Response execute_async_script(JsonValue const& payload);