diff options
author | batu_hoang <55729155+longvatrong111@users.noreply.github.com> | 2025-06-08 04:54:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-07 20:54:36 +0000 |
commit | aeca81c09110eae49c1a0acd965decacc06b78d4 (patch) | |
tree | 6e454f5b9a3b3dfe9d5ec83946707321d7d8ac83 /components/script | |
parent | c808ff76662ce059093dcc36c2d516fc770b29b6 (diff) | |
download | servo-aeca81c09110eae49c1a0acd965decacc06b78d4.tar.gz servo-aeca81c09110eae49c1a0acd965decacc06b78d4.zip |
[webdriver] Implement get shadow root (#37280)
Implement Get Element Shadow Root
https://www.w3.org/TR/webdriver2/#dfn-get-element-shadow-root
cc: @xiaochengh, @yezhizhen, @PotatoCP
Testing:
`\tests\wpt\tests\webdriver\tests\classic\get_element_shadow_root\get.py`
is blocked by `no_browsing_context` and `closed_window`
pass for other sub-tests.
Signed-off-by: batu_hoang <longvatrong111@gmail.com>
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/script_thread.rs | 8 | ||||
-rw-r--r-- | components/script/webdriver_handlers.rs | 21 |
2 files changed, 29 insertions, 0 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index e7f60e23772..1260fa9867a 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -2280,6 +2280,14 @@ impl ScriptThread { can_gc, ) }, + WebDriverScriptCommand::GetElementShadowRoot(element_id, reply) => { + webdriver_handlers::handle_get_element_shadow_root( + &documents, + pipeline_id, + element_id, + reply, + ) + }, WebDriverScriptCommand::ElementClick(element_id, reply) => { webdriver_handlers::handle_element_click( &documents, diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index c81dcbd85fd..322839aa078 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -843,6 +843,27 @@ pub(crate) fn handle_find_element_elements_tag_name( .unwrap(); } +/// <https://www.w3.org/TR/webdriver2/#dfn-get-element-shadow-root> +pub(crate) fn handle_get_element_shadow_root( + documents: &DocumentCollection, + pipeline: PipelineId, + element_id: String, + reply: IpcSender<Result<Option<String>, ErrorStatus>>, +) { + reply + .send( + find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| match node + .downcast::<Element>( + ) { + Some(element) => Ok(element + .GetShadowRoot() + .map(|x| x.upcast::<Node>().unique_id(pipeline))), + None => Err(ErrorStatus::NoSuchElement), + }), + ) + .unwrap(); +} + pub(crate) fn handle_will_send_keys( documents: &DocumentCollection, pipeline: PipelineId, |