commit 2e0a449ea4cae18dca6cd8780c541bc1952a4b78
parent 839bcbe622469506c6d2fc1205e320de4c484d08
Author: Maksim Sadym <69349599+sadym-chromium@users.noreply.github.com>
Date: Wed, 15 Oct 2025 08:43:04 +0000
Bug 1993922 [wpt PR 55358] - [wdspec] `network.setExtraHeaders` invalid cases, a=testonly
Automatic update from web-platform-tests
[wdspec] `network.setExtraHeaders` invalid cases (#55358)
--
wpt-commits: 371355452f197c56f16a9c97e6be032b0b3b8cc3
wpt-pr: 55358
Diffstat:
3 files changed, 195 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/tools/webdriver/webdriver/bidi/modules/network.py b/testing/web-platform/tests/tools/webdriver/webdriver/bidi/modules/network.py
@@ -2,6 +2,7 @@ from enum import Enum
from typing import Any, Dict, List, Mapping, MutableMapping, Optional, Union
from ._module import BidiModule, command
+from ..undefined import UNDEFINED, Maybe
class AuthCredentials(Dict[str, Any]):
@@ -331,3 +332,16 @@ class Network(BidiModule):
def _get_data(self, result: Mapping[str, Any]) -> Any:
assert result["bytes"] is not None
return result["bytes"]
+
+ @command
+ def set_extra_headers(
+ self,
+ headers: List[Dict[str, Any]],
+ contexts: Maybe[List[str]] = UNDEFINED,
+ user_contexts: Maybe[List[str]] = UNDEFINED,
+ ) -> Mapping[str, Any]:
+ return {
+ "headers": headers,
+ "contexts": contexts,
+ "userContexts": user_contexts,
+ }
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/network/set_extra_headers/__init__.py b/testing/web-platform/tests/webdriver/tests/bidi/network/set_extra_headers/__init__.py
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/network/set_extra_headers/invalid.py b/testing/web-platform/tests/webdriver/tests/bidi/network/set_extra_headers/invalid.py
@@ -0,0 +1,181 @@
+import pytest
+
+import webdriver.bidi.error as error
+from tests.bidi import get_invalid_cases
+from webdriver.bidi.undefined import UNDEFINED
+
+pytestmark = pytest.mark.asyncio
+
+VALID_HEADERS = [{
+ "name": "some_name",
+ "value": {
+ "type": "string",
+ "value": "come_value"
+ }}]
+
+
+@pytest.mark.parametrize("value", get_invalid_cases("list"))
+async def test_params_contexts_invalid_type(bidi_session, value):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=VALID_HEADERS,
+ contexts=value
+ )
+
+
+async def test_params_contexts_empty_list(bidi_session):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=VALID_HEADERS,
+ contexts=[])
+
+
+@pytest.mark.parametrize("value", get_invalid_cases("string"))
+async def test_params_contexts_entry_invalid_type(bidi_session, value):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=VALID_HEADERS,
+ contexts=[value])
+
+
+async def test_params_contexts_entry_invalid_value(bidi_session):
+ with pytest.raises(error.NoSuchFrameException):
+ await bidi_session.network.set_extra_headers(
+ headers=VALID_HEADERS,
+ contexts=["_invalid_"],
+ )
+
+
+async def test_params_contexts_iframe(bidi_session, new_tab, get_test_page):
+ url = get_test_page(as_frame=True)
+ await bidi_session.browsing_context.navigate(
+ context=new_tab["context"], url=url, wait="complete"
+ )
+
+ contexts = await bidi_session.browsing_context.get_tree(
+ root=new_tab["context"])
+ assert len(contexts) == 1
+ frames = contexts[0]["children"]
+ assert len(frames) == 1
+
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=VALID_HEADERS,
+ contexts=[frames[0]["context"]],
+ )
+
+
+@pytest.mark.parametrize("value", get_invalid_cases("list"))
+async def test_params_user_contexts_invalid_type(bidi_session, value):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=VALID_HEADERS,
+ user_contexts=value,
+ )
+
+
+async def test_params_user_contexts_empty_list(bidi_session):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=VALID_HEADERS,
+ user_contexts=[],
+ )
+
+
+@pytest.mark.parametrize("value", get_invalid_cases("string"))
+async def test_params_user_contexts_entry_invalid_type(bidi_session, value):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=VALID_HEADERS,
+ user_contexts=[value],
+ )
+
+
+@pytest.mark.parametrize("value", ["", "somestring"])
+async def test_params_user_contexts_entry_invalid_value(bidi_session, value):
+ with pytest.raises(error.NoSuchUserContextException):
+ await bidi_session.network.set_extra_headers(
+ headers=VALID_HEADERS,
+ user_contexts=[value],
+ )
+
+
+async def test_params_contexts_and_user_contexts(bidi_session, top_context):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=VALID_HEADERS,
+ contexts=[top_context["context"]],
+ user_contexts=["default"],
+ )
+
+
+async def test_params_headers_missing(bidi_session, top_context):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(headers=UNDEFINED)
+
+
+@pytest.mark.parametrize("value", get_invalid_cases("list", nullable=False))
+async def test_params_headers_invalid_type(bidi_session, top_context,
+ value):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(headers=value)
+
+
+@pytest.mark.parametrize("value", get_invalid_cases("dict", nullable=False))
+async def test_params_headers_header_invalid_type(bidi_session, top_context,
+ value):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(headers=[value])
+
+
+@pytest.mark.parametrize("value", get_invalid_cases("string", nullable=False))
+async def test_params_headers_header_name_invalid_type(bidi_session,
+ top_context,
+ value):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=[{"name": value, "value": "some_value"}],
+ )
+
+
+# https://fetch.spec.whatwg.org/#header-name
+@pytest.mark.parametrize("value",
+ ["", " ", "\t", "\n", '"', '(', ')', ',', '/', ':',
+ ';', '<', '=', '>', '?', '@', '[', '\\', ']', '{',
+ '}'])
+async def test_params_headers_header_name_invalid_value(bidi_session,
+ top_context, value):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=[{"name": value, "value": "some_value"}],
+ )
+
+
+@pytest.mark.parametrize("value", get_invalid_cases("string", nullable=False))
+async def test_params_headers_header_value_invalid_type(bidi_session,
+ top_context,
+ value):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=[{"name": "some_name", "value": value}],
+ contexts=[top_context["context"]],
+ )
+
+
+# https://fetch.spec.whatwg.org/#header-value
+@pytest.mark.parametrize("value", [" value", # leading space
+ "value ", # trailing space
+ "\tvalue", # leading tab
+ "value\t", # trailing tab
+ "va\0lue", # NUL
+ "va\nlue", # LF
+ "va\rlue", # CR
+ ])
+async def test_params_headers_header_value_invalid_value(bidi_session,
+ top_context,
+ value):
+ with pytest.raises(error.InvalidArgumentException):
+ await bidi_session.network.set_extra_headers(
+ headers=[{"name": "some_name", "value": value}],
+ contexts=[top_context["context"]],
+ )