aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenzie Raditya Tirtarahardja <kenzieradityatirtarahardja18@gmail.com>2025-04-16 11:55:15 +0800
committerGitHub <noreply@github.com>2025-04-16 03:55:15 +0000
commit15199ba2efee3fb59661d63238bcd4fc7990ad0c (patch)
treedaf3319b8fccfc32dba436535f66fa6ac31d3185
parentcef7aa58ec3dc6b5e2ee729cc4b2c8a9c85fe681 (diff)
downloadservo-15199ba2efee3fb59661d63238bcd4fc7990ad0c.tar.gz
servo-15199ba2efee3fb59661d63238bcd4fc7990ad0c.zip
Implement GetComputedRole in wd (#36552)
Implement Webdriver Get Computed Role. [spec](https://w3c.github.io/webdriver/#get-computed-role) Signed-off-by: Kenzie Raditya Tirtarahardja <kenzieradityatirtarahardja.18@gmail.com> Co-authored-by: Kenzie Raditya Tirtarahardja <kenzieradityatirtarahardja.18@gmail.com>
-rw-r--r--components/script/script_thread.rs8
-rw-r--r--components/script/webdriver_handlers.rs18
-rw-r--r--components/shared/embedder/webdriver.rs1
-rw-r--r--components/webdriver_server/lib.rs13
4 files changed, 40 insertions, 0 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 336b00233a6..76daf5c87c0 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -2253,6 +2253,14 @@ impl ScriptThread {
WebDriverScriptCommand::GetActiveElement(reply) => {
webdriver_handlers::handle_get_active_element(&documents, pipeline_id, reply)
},
+ WebDriverScriptCommand::GetComputedRole(node_id, reply) => {
+ webdriver_handlers::handle_get_computed_role(
+ &documents,
+ pipeline_id,
+ node_id,
+ reply,
+ )
+ },
WebDriverScriptCommand::GetPageSource(reply) => {
webdriver_handlers::handle_get_page_source(&documents, pipeline_id, reply, can_gc)
},
diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs
index ed9f9d5e0c1..c6303ca89e0 100644
--- a/components/script/webdriver_handlers.rs
+++ b/components/script/webdriver_handlers.rs
@@ -799,6 +799,24 @@ pub(crate) fn handle_get_active_element(
.unwrap();
}
+pub(crate) fn handle_get_computed_role(
+ documents: &DocumentCollection,
+ pipeline: PipelineId,
+ node_id: String,
+ reply: IpcSender<Result<Option<String>, ErrorStatus>>,
+) {
+ reply
+ .send(
+ find_node_by_unique_id(documents, pipeline, node_id).and_then(|node| {
+ match node.downcast::<Element>() {
+ Some(element) => Ok(element.GetRole().map(String::from)),
+ None => Err(ErrorStatus::UnknownError),
+ }
+ }),
+ )
+ .unwrap();
+}
+
pub(crate) fn handle_get_page_source(
documents: &DocumentCollection,
pipeline: PipelineId,
diff --git a/components/shared/embedder/webdriver.rs b/components/shared/embedder/webdriver.rs
index eb9c61dc497..324906c2584 100644
--- a/components/shared/embedder/webdriver.rs
+++ b/components/shared/embedder/webdriver.rs
@@ -114,6 +114,7 @@ pub enum WebDriverScriptCommand {
FocusElement(String, IpcSender<Result<(), ErrorStatus>>),
ElementClick(String, IpcSender<Result<Option<String>, ErrorStatus>>),
GetActiveElement(IpcSender<Option<String>>),
+ GetComputedRole(String, IpcSender<Result<Option<String>, ErrorStatus>>),
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
GetCookies(IpcSender<Vec<Serde<Cookie<'static>>>>),
GetElementAttribute(
diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs
index f9f2ff6e139..e9bec44afaa 100644
--- a/components/webdriver_server/lib.rs
+++ b/components/webdriver_server/lib.rs
@@ -1214,6 +1214,18 @@ impl Handler {
)))
}
+ fn handle_computed_role(&self, element: &WebElement) -> WebDriverResult<WebDriverResponse> {
+ let (sender, receiver) = ipc::channel().unwrap();
+ let cmd = WebDriverScriptCommand::GetComputedRole(element.to_string(), sender);
+ self.browsing_context_script_command(cmd)?;
+ match receiver.recv().unwrap() {
+ Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
+ serde_json::to_value(value)?,
+ ))),
+ Err(error) => Err(WebDriverError::new(error, "")),
+ }
+ }
+
fn handle_element_tag_name(&self, element: &WebElement) -> WebDriverResult<WebDriverResponse> {
let (sender, receiver) = ipc::channel().unwrap();
let cmd = WebDriverScriptCommand::GetElementTagName(element.to_string(), sender);
@@ -1844,6 +1856,7 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
WebDriverCommand::GetNamedCookie(name) => self.handle_get_cookie(name),
WebDriverCommand::GetCookies => self.handle_get_cookies(),
WebDriverCommand::GetActiveElement => self.handle_active_element(),
+ WebDriverCommand::GetComputedRole(ref element) => self.handle_computed_role(element),
WebDriverCommand::GetElementRect(ref element) => self.handle_element_rect(element),
WebDriverCommand::GetElementText(ref element) => self.handle_element_text(element),
WebDriverCommand::GetElementTagName(ref element) => {