mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:27:45 +00:00
WebDriver: Introduce a WebDriverEndpoints
class
This holds the Functions used by the WebDriver to not clutter up the `Tab.h` file.
This commit is contained in:
parent
354a845d65
commit
c11462f40e
4 changed files with 51 additions and 24 deletions
|
@ -582,27 +582,27 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
|
||||||
return active_tab().view().get_session_storage_entries();
|
return active_tab().view().get_session_storage_entries();
|
||||||
};
|
};
|
||||||
|
|
||||||
new_tab.on_get_document_element = [this]() {
|
new_tab.webdriver_endpoints().on_get_document_element = [this]() {
|
||||||
return active_tab().view().get_document_element();
|
return active_tab().view().get_document_element();
|
||||||
};
|
};
|
||||||
|
|
||||||
new_tab.on_query_selector_all = [this](i32 start_node_id, String const& selector) {
|
new_tab.webdriver_endpoints().on_query_selector_all = [this](i32 start_node_id, String const& selector) {
|
||||||
return active_tab().view().query_selector_all(start_node_id, selector);
|
return active_tab().view().query_selector_all(start_node_id, selector);
|
||||||
};
|
};
|
||||||
|
|
||||||
new_tab.on_get_element_attribute = [this](i32 element_id, String const& name) {
|
new_tab.webdriver_endpoints().on_get_element_attribute = [this](i32 element_id, String const& name) {
|
||||||
return active_tab().view().get_element_attribute(element_id, name);
|
return active_tab().view().get_element_attribute(element_id, name);
|
||||||
};
|
};
|
||||||
|
|
||||||
new_tab.on_get_element_property = [this](i32 element_id, String const& name) {
|
new_tab.webdriver_endpoints().on_get_element_property = [this](i32 element_id, String const& name) {
|
||||||
return active_tab().view().get_element_property(element_id, name);
|
return active_tab().view().get_element_property(element_id, name);
|
||||||
};
|
};
|
||||||
|
|
||||||
new_tab.on_get_active_documents_type = [this]() {
|
new_tab.webdriver_endpoints().on_get_active_documents_type = [this]() {
|
||||||
return active_tab().view().get_active_documents_type();
|
return active_tab().view().get_active_documents_type();
|
||||||
};
|
};
|
||||||
|
|
||||||
new_tab.on_get_computed_value_for_element = [this](i32 element_id, String const& property_name) {
|
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);
|
return active_tab().view().get_computed_value_for_element(element_id, property_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "History.h"
|
#include "History.h"
|
||||||
|
#include "WebDriverEndpoints.h"
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <LibGUI/ActionGroup.h>
|
#include <LibGUI/ActionGroup.h>
|
||||||
|
@ -68,12 +69,8 @@ public:
|
||||||
Function<Vector<Web::Cookie::Cookie>()> on_get_cookies_entries;
|
Function<Vector<Web::Cookie::Cookie>()> on_get_cookies_entries;
|
||||||
Function<OrderedHashMap<String, String>()> on_get_local_storage_entries;
|
Function<OrderedHashMap<String, String>()> on_get_local_storage_entries;
|
||||||
Function<OrderedHashMap<String, String>()> on_get_session_storage_entries;
|
Function<OrderedHashMap<String, String>()> on_get_session_storage_entries;
|
||||||
Function<Optional<i32>()> on_get_document_element;
|
|
||||||
Function<Optional<Vector<i32>>(i32 start_node_id, String const&)> on_query_selector_all;
|
WebDriverEndpoints& webdriver_endpoints() { return m_webdriver_endpoints; }
|
||||||
Function<Optional<String>(i32 element_id, String const&)> on_get_element_attribute;
|
|
||||||
Function<Optional<String>(i32 element_id, String const&)> on_get_element_property;
|
|
||||||
Function<String()> on_get_active_documents_type;
|
|
||||||
Function<String(i32 element_id, String const&)> on_get_computed_value_for_element;
|
|
||||||
|
|
||||||
enum class InspectorTarget {
|
enum class InspectorTarget {
|
||||||
Document,
|
Document,
|
||||||
|
@ -141,6 +138,8 @@ private:
|
||||||
|
|
||||||
Optional<URL> m_navigating_url;
|
Optional<URL> m_navigating_url;
|
||||||
|
|
||||||
|
WebDriverEndpoints m_webdriver_endpoints {};
|
||||||
|
|
||||||
bool m_loaded { false };
|
bool m_loaded { false };
|
||||||
bool m_is_history_navigation { false };
|
bool m_is_history_navigation { false };
|
||||||
};
|
};
|
||||||
|
|
|
@ -127,8 +127,8 @@ Messages::WebDriverSessionClient::GetDocumentElementResponse WebDriverConnection
|
||||||
dbgln("WebDriverConnection: get_document_element");
|
dbgln("WebDriverConnection: get_document_element");
|
||||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||||
auto& tab = browser_window->active_tab();
|
auto& tab = browser_window->active_tab();
|
||||||
if (tab.on_get_document_element)
|
if (tab.webdriver_endpoints().on_get_document_element)
|
||||||
return { tab.on_get_document_element() };
|
return { tab.webdriver_endpoints().on_get_document_element() };
|
||||||
}
|
}
|
||||||
return { {} };
|
return { {} };
|
||||||
}
|
}
|
||||||
|
@ -138,8 +138,8 @@ Messages::WebDriverSessionClient::QuerySelectorAllResponse WebDriverConnection::
|
||||||
dbgln("WebDriverConnection: query_selector_all");
|
dbgln("WebDriverConnection: query_selector_all");
|
||||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||||
auto& tab = browser_window->active_tab();
|
auto& tab = browser_window->active_tab();
|
||||||
if (tab.on_query_selector_all)
|
if (tab.webdriver_endpoints().on_query_selector_all)
|
||||||
return { tab.on_query_selector_all(start_node_id, selector) };
|
return { tab.webdriver_endpoints().on_query_selector_all(start_node_id, selector) };
|
||||||
}
|
}
|
||||||
return { {} };
|
return { {} };
|
||||||
}
|
}
|
||||||
|
@ -149,8 +149,8 @@ Messages::WebDriverSessionClient::GetElementAttributeResponse WebDriverConnectio
|
||||||
dbgln("WebDriverConnection: get_element_attribute");
|
dbgln("WebDriverConnection: get_element_attribute");
|
||||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||||
auto& tab = browser_window->active_tab();
|
auto& tab = browser_window->active_tab();
|
||||||
if (tab.on_get_element_attribute)
|
if (tab.webdriver_endpoints().on_get_element_attribute)
|
||||||
return { tab.on_get_element_attribute(element_id, name) };
|
return { tab.webdriver_endpoints().on_get_element_attribute(element_id, name) };
|
||||||
}
|
}
|
||||||
return { {} };
|
return { {} };
|
||||||
}
|
}
|
||||||
|
@ -160,8 +160,8 @@ Messages::WebDriverSessionClient::GetElementPropertyResponse WebDriverConnection
|
||||||
dbgln("WebDriverConnection: get_element_property");
|
dbgln("WebDriverConnection: get_element_property");
|
||||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||||
auto& tab = browser_window->active_tab();
|
auto& tab = browser_window->active_tab();
|
||||||
if (tab.on_get_element_property)
|
if (tab.webdriver_endpoints().on_get_element_property)
|
||||||
return { tab.on_get_element_property(element_id, name) };
|
return { tab.webdriver_endpoints().on_get_element_property(element_id, name) };
|
||||||
}
|
}
|
||||||
return { {} };
|
return { {} };
|
||||||
}
|
}
|
||||||
|
@ -171,8 +171,8 @@ Messages::WebDriverSessionClient::GetActiveDocumentsTypeResponse WebDriverConnec
|
||||||
dbgln("WebDriverConnection: get_active_documents_type");
|
dbgln("WebDriverConnection: get_active_documents_type");
|
||||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||||
auto& tab = browser_window->active_tab();
|
auto& tab = browser_window->active_tab();
|
||||||
if (tab.on_get_active_documents_type)
|
if (tab.webdriver_endpoints().on_get_active_documents_type)
|
||||||
return { tab.on_get_active_documents_type() };
|
return { tab.webdriver_endpoints().on_get_active_documents_type() };
|
||||||
}
|
}
|
||||||
return { "" };
|
return { "" };
|
||||||
}
|
}
|
||||||
|
@ -182,8 +182,8 @@ Messages::WebDriverSessionClient::GetComputedValueForElementResponse WebDriverCo
|
||||||
dbgln("WebDriverConnection: get_computed_value_for_element");
|
dbgln("WebDriverConnection: get_computed_value_for_element");
|
||||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||||
auto& tab = browser_window->active_tab();
|
auto& tab = browser_window->active_tab();
|
||||||
if (tab.on_get_computed_value_for_element)
|
if (tab.webdriver_endpoints().on_get_computed_value_for_element)
|
||||||
return { tab.on_get_computed_value_for_element(element_id, property_name) };
|
return { tab.webdriver_endpoints().on_get_computed_value_for_element(element_id, property_name) };
|
||||||
}
|
}
|
||||||
return { "" };
|
return { "" };
|
||||||
}
|
}
|
||||||
|
|
28
Userland/Applications/Browser/WebDriverEndpoints.h
Normal file
28
Userland/Applications/Browser/WebDriverEndpoints.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Forward.h>
|
||||||
|
#include <AK/Function.h>
|
||||||
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
|
namespace Browser {
|
||||||
|
|
||||||
|
class WebDriverEndpoints {
|
||||||
|
public:
|
||||||
|
WebDriverEndpoints() = default;
|
||||||
|
~WebDriverEndpoints() = default;
|
||||||
|
|
||||||
|
Function<Optional<i32>()> on_get_document_element;
|
||||||
|
Function<Optional<Vector<i32>>(i32 start_node_id, String const&)> on_query_selector_all;
|
||||||
|
Function<Optional<String>(i32 element_id, String const&)> on_get_element_attribute;
|
||||||
|
Function<Optional<String>(i32 element_id, String const&)> on_get_element_property;
|
||||||
|
Function<String()> on_get_active_documents_type;
|
||||||
|
Function<String(i32 element_id, String const&)> on_get_computed_value_for_element;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue