commit c4e2355a77c385e3408bf5452fd9f65d519fd577
parent 2dbbdcb739ba5931472982f818d517113be90f49
Author: Euclid <yezhizhenjiakang@gmail.com>
Date: Mon, 27 Oct 2025 10:02:21 +0000
Bug 1995183 [wpt PR 55534] - wdspec tests: Check correct node type instead of asserting error for script execution, a=testonly
Automatic update from web-platform-tests
Update outdated test to align spec
Signed-off-by: Euclid <yezhizhenjiakang@gmail.com>
--
1. Test node type instead of removing all
2. Remove test unrelated to node
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
--
Fix test that never selected anything correctly
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
--
Cdata test
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
--
Update async test symetrically
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
--
Remove unused test and reduce duplication
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
--
dummy commit to check https://github.com/web-platform-tests/wpt/pull/55534#discussion_r2447338379
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
--
Revert some changes and check enumerable serialization
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
--
Reordeing assertions
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
--
minor adjustment
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
--
wpt-commits: a3f865d9fc1ecec0c167fe9d321f8ba0f7fe4508, 8c0c67d078f571dd58d9e230be2324d109efed67, 2db0d3c2dcb52cb8b3f6771120072d6212748833, 65a4074ad4b31ebca34c8dc55a4534799e5d9735, 191c2d8c3dc0f391d150da6fd6f1216e58d95fa6, 05a87ac6c74f0ddbe70db117cda572c4b06b3e02, bdbfb04cb441026fef5bf033c82c50fc9b3246cd, 8c6c3835d5864fce20fa04bd7569151963f572eb, 1cd8a8b225fbdeaa53d858b2e4c727bcaf7abc66, 41f1c2edcddb318eadef475b8a2a20688c7f163f
wpt-pr: 55534
Diffstat:
2 files changed, 82 insertions(+), 31 deletions(-)
diff --git a/testing/web-platform/tests/webdriver/tests/classic/execute_async_script/node.py b/testing/web-platform/tests/webdriver/tests/classic/execute_async_script/node.py
@@ -18,6 +18,17 @@ PAGE_DATA = """
</script>
"""
+# https://dom.spec.whatwg.org/#ref-for-dom-node-nodetype%E2%91%A0
+NODE_TYPE = {
+ "element": 1,
+ "attribute": 2,
+ "text": 3,
+ "cdata": 4,
+ "processing_instruction": 7,
+ "comment": 8,
+ "document": 9,
+ "doctype": 10,
+}
@pytest.mark.parametrize("as_frame", [False, True], ids=["top_context", "child_context"])
def test_detached_shadow_root(session, get_test_page, as_frame):
@@ -59,6 +70,39 @@ def test_stale_element(session, get_test_page, as_frame):
@pytest.mark.parametrize("expression, expected_type", [
+ (""" document.querySelector("svg").attributes[0] """, "attribute"),
+ (""" document.querySelector("div#text-node").childNodes[1] """, "text"),
+ (""" document.implementation.createDocument("", "root", null).createCDATASection("foo") """, "cdata"),
+ (""" document.createProcessingInstruction("xml-stylesheet", "href='foo.css'") """, "processing_instruction"),
+ (""" document.querySelector("div#comment").childNodes[0] """, "comment"),
+ (""" document""", "document"),
+ (""" document.doctype""", "doctype"),
+], ids=["attribute", "text", "cdata", "processing_instruction", "comment", "document", "doctype"])
+def test_node_type(session, inline, expression, expected_type):
+ session.url = inline(PAGE_DATA)
+
+ response = execute_async_script(
+ session,
+ f"""
+ const [resolve] = arguments;
+ const result = {expression};
+ resolve({{
+ 'result': result,
+ 'type': result.nodeType
+ }});""",
+ )
+ result = assert_success(response)
+
+ assert result["type"] == NODE_TYPE[expected_type]
+
+ if expected_type == "document":
+ assert 'location' in result['result']
+ else:
+ assert result['result'] == {}
+
+
+
+@pytest.mark.parametrize("expression, expected_type", [
("document.querySelector('div')", WebElement),
("document.querySelector('custom-element').shadowRoot", ShadowRoot),
], ids=["element", "shadow-root"])
@@ -69,18 +113,3 @@ def test_element_reference(session, get_test_page, expression, expected_type):
reference = assert_success(result)
assert isinstance(reference, expected_type)
-
-@pytest.mark.parametrize("expression", [
- (""" document.querySelector("svg").attributes[0] """),
- (""" document.querySelector("div#text-node").childNodes[1] """),
- (""" document.querySelector("foo").childNodes[1] """),
- (""" document.createProcessingInstruction("xml-stylesheet", "href='foo.css'") """),
- (""" document.querySelector("div#comment").childNodes[0] """),
- (""" document"""),
- (""" document.doctype"""),
-], ids=["attribute", "text", "cdata", "processing_instruction", "comment", "document", "doctype"])
-def test_not_supported_nodes(session, inline, expression):
- session.url = inline(PAGE_DATA)
-
- result = execute_async_script(session, f"arguments[0]({expression})")
- assert_error(result, "javascript error")
diff --git a/testing/web-platform/tests/webdriver/tests/classic/execute_script/node.py b/testing/web-platform/tests/webdriver/tests/classic/execute_script/node.py
@@ -17,6 +17,17 @@ PAGE_DATA = """
</script>
"""
+# https://dom.spec.whatwg.org/#ref-for-dom-node-nodetype%E2%91%A0
+NODE_TYPE = {
+ "element": 1,
+ "attribute": 2,
+ "text": 3,
+ "cdata": 4,
+ "processing_instruction": 7,
+ "comment": 8,
+ "document": 9,
+ "doctype": 10,
+}
@pytest.mark.parametrize("as_frame", [False, True], ids=["top_context", "child_context"])
def test_detached_shadow_root(session, get_test_page, as_frame):
@@ -58,6 +69,33 @@ def test_stale_element(session, get_test_page, as_frame):
@pytest.mark.parametrize("expression, expected_type", [
+ (""" document.querySelector("svg").attributes[0] """, "attribute"),
+ (""" document.querySelector("div#text-node").childNodes[1] """, "text"),
+ (""" document.implementation.createDocument("", "root", null).createCDATASection("foo") """, "cdata"),
+ (""" document.createProcessingInstruction("xml-stylesheet", "href='foo.css'") """, "processing_instruction"),
+ (""" document.querySelector("div#comment").childNodes[0] """, "comment"),
+ (""" document""", "document"),
+ (""" document.doctype""", "doctype"),
+], ids=["attribute", "text", "cdata", "processing_instruction", "comment", "document", "doctype"])
+def test_node_type(session, inline, expression, expected_type):
+ session.url = inline(PAGE_DATA)
+
+ response = execute_script(
+ session,
+ f"const result = {expression}; return {{'result': result, 'type': result.nodeType}}",
+ )
+ result = assert_success(response)
+
+ assert result["type"] == NODE_TYPE[expected_type]
+
+ if expected_type == "document":
+ assert 'location' in result['result']
+ else:
+ assert result['result'] == {}
+
+
+
+@pytest.mark.parametrize("expression, expected_type", [
("document.querySelector('div')", WebElement),
("document.querySelector('custom-element').shadowRoot", ShadowRoot),
], ids=["element", "shadow-root"])
@@ -67,19 +105,3 @@ def test_web_reference(session, get_test_page, expression, expected_type):
result = execute_script(session, f"return {expression}")
reference = assert_success(result)
assert isinstance(reference, expected_type)
-
-
-@pytest.mark.parametrize("expression", [
- (""" document.querySelector("svg").attributes[0] """),
- (""" document.querySelector("div#text-node").childNodes[1] """),
- (""" document.querySelector("foo").childNodes[1] """),
- (""" document.createProcessingInstruction("xml-stylesheet", "href='foo.css'") """),
- (""" document.querySelector("div#comment").childNodes[0] """),
- (""" document"""),
- (""" document.doctype"""),
-], ids=["attribute", "text", "cdata", "processing_instruction", "comment", "document", "doctype"])
-def test_not_supported_nodes(session, inline, expression):
- session.url = inline(PAGE_DATA)
-
- result = execute_script(session, f"return {expression}")
- assert_error(result, "javascript error")