1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 14:37:45 +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

@ -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();