From 78a35ada36c27188026c8dd576cdb94ac120e52f Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Tue, 16 Dec 2025 17:30:42 +0100 Subject: [PATCH 1/3] [wdspec] `emulation.setTouchOverride` --- .../webdriver/bidi/modules/emulation.py | 13 +++ .../emulation/set_touch_override/__init__.py | 3 + .../emulation/set_touch_override/conftest.py | 42 +++++++ .../emulation/set_touch_override/contexts.py | 90 ++++++++++++++ .../emulation/set_touch_override/global.py | 38 ++++++ .../emulation/set_touch_override/invalid.py | 110 ++++++++++++++++++ .../set_touch_override/user_contexts.py | 82 +++++++++++++ 7 files changed, 378 insertions(+) create mode 100644 webdriver/tests/bidi/emulation/set_touch_override/__init__.py create mode 100644 webdriver/tests/bidi/emulation/set_touch_override/conftest.py create mode 100644 webdriver/tests/bidi/emulation/set_touch_override/contexts.py create mode 100644 webdriver/tests/bidi/emulation/set_touch_override/global.py create mode 100644 webdriver/tests/bidi/emulation/set_touch_override/invalid.py create mode 100644 webdriver/tests/bidi/emulation/set_touch_override/user_contexts.py diff --git a/tools/webdriver/webdriver/bidi/modules/emulation.py b/tools/webdriver/webdriver/bidi/modules/emulation.py index e6aca041e3d496..e7b067f62c73f9 100644 --- a/tools/webdriver/webdriver/bidi/modules/emulation.py +++ b/tools/webdriver/webdriver/bidi/modules/emulation.py @@ -130,3 +130,16 @@ def set_network_conditions( "contexts": contexts, "userContexts": user_contexts, } + + @command + def set_touch_override( + self, + max_touch_points: Nullable[int], + contexts: Maybe[List[str]] = UNDEFINED, + user_contexts: Maybe[List[str]] = UNDEFINED, + ) -> Mapping[str, Any]: + return { + "maxTouchPoints": max_touch_points, + "contexts": contexts, + "userContexts": user_contexts, + } diff --git a/webdriver/tests/bidi/emulation/set_touch_override/__init__.py b/webdriver/tests/bidi/emulation/set_touch_override/__init__.py new file mode 100644 index 00000000000000..49e272bf398e79 --- /dev/null +++ b/webdriver/tests/bidi/emulation/set_touch_override/__init__.py @@ -0,0 +1,3 @@ +MAX_TOUCHES_PER_CONTEXT = 4 +MAX_TOUCHES_PER_USER_CONTEXT = 5 +MAX_TOUCHES_GLOBAL = 6 diff --git a/webdriver/tests/bidi/emulation/set_touch_override/conftest.py b/webdriver/tests/bidi/emulation/set_touch_override/conftest.py new file mode 100644 index 00000000000000..d00ba940ddc72c --- /dev/null +++ b/webdriver/tests/bidi/emulation/set_touch_override/conftest.py @@ -0,0 +1,42 @@ +import pytest_asyncio +from webdriver.bidi.modules.script import ContextTarget + +@pytest_asyncio.fixture +async def get_max_touch_points(bidi_session): + async def get_max_touch_points(context): + result = await bidi_session.script.evaluate( + expression="navigator.maxTouchPoints", + target=ContextTarget(context["context"]), + await_promise=True, + ) + return result["value"] + + return get_max_touch_points + + +@pytest_asyncio.fixture +async def initial_max_touch_points(bidi_session, top_context, get_max_touch_points): + """Return the initial value of maxTouchPoints.""" + return await get_max_touch_points(top_context) + + +@pytest_asyncio.fixture(params=['default', 'new'], + ids=["Default user context", "Custom user context"]) +async def target_user_context(request, create_user_context): + return request.param + + +@pytest_asyncio.fixture +async def affected_user_context(target_user_context, create_user_context): + """ Returns either a new or default user context. """ + if target_user_context == 'default': + return 'default' + return await create_user_context() + + +@pytest_asyncio.fixture +async def not_affected_user_context(target_user_context, create_user_context): + """ Returns opposite to `affected_user_context user context. """ + if target_user_context == 'new': + return 'default' + return await create_user_context() diff --git a/webdriver/tests/bidi/emulation/set_touch_override/contexts.py b/webdriver/tests/bidi/emulation/set_touch_override/contexts.py new file mode 100644 index 00000000000000..5857925397bb34 --- /dev/null +++ b/webdriver/tests/bidi/emulation/set_touch_override/contexts.py @@ -0,0 +1,90 @@ +import pytest +from . import MAX_TOUCHES_PER_CONTEXT, MAX_TOUCHES_PER_USER_CONTEXT, MAX_TOUCHES_PER_GLOBAL + + +pytestmark = pytest.mark.asyncio + + +async def test_contexts_isolation(bidi_session, top_context, + get_max_touch_points, initial_max_touch_points): + another_context = await bidi_session.browsing_context.create( + type_hint="tab") + + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_PER_CONTEXT, + contexts=[top_context["context"]]) + assert await get_max_touch_points(top_context) == MAX_TOUCHES_PER_CONTEXT + assert await get_max_touch_points(another_context) == initial_max_touch_points + + yet_another_context = await bidi_session.browsing_context.create( + type_hint="tab") + assert await get_max_touch_points(yet_another_context) == initial_max_touch_points + + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + contexts=[top_context["context"]]) + assert await get_max_touch_points(top_context) == initial_max_touch_points + assert await get_max_touch_points(another_context) == initial_max_touch_points + assert await get_max_touch_points(yet_another_context) == initial_max_touch_points + + +@pytest.mark.parametrize("domain", ["", "alt"], + ids=["same_origin", "cross_origin"]) +async def test_frame(bidi_session, url, get_max_touch_points, + top_context, create_iframe, domain, initial_max_touch_points): + iframe_id = await create_iframe(top_context, url('/', domain=domain)) + + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_PER_CONTEXT, + contexts=[top_context["context"]]) + assert await get_max_touch_points(iframe_id) == MAX_TOUCHES_PER_CONTEXT + + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + contexts=[top_context["context"]]) + assert await get_max_touch_points(iframe_id) == initial_max_touch_points + + +async def test_overrides_user_contexts(bidi_session, get_max_touch_points, + affected_user_context, initial_max_touch_points): + affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=affected_user_context) + + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_PER_CONTEXT, + contexts=[affected_context["context"]]) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_CONTEXT + + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_PER_USER_CONTEXT, + user_contexts=[affected_user_context]) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_CONTEXT + + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + contexts=[affected_context["context"]]) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_USER_CONTEXT + + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + user_contexts=[affected_user_context]) + assert await get_max_touch_points(affected_context) == initial_max_touch_points + + +async def test_overrides_global(bidi_session, get_max_touch_points, + affected_user_context, initial_max_touch_points): + affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=affected_user_context) + + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_PER_CONTEXT, + contexts=[affected_context["context"]]) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_CONTEXT + + await bidi_session.emulation.set_touch_override(max_touch_points=MAX_TOUCHES_PER_GLOBAL) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_CONTEXT + + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + contexts=[affected_context["context"]]) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_GLOBAL diff --git a/webdriver/tests/bidi/emulation/set_touch_override/global.py b/webdriver/tests/bidi/emulation/set_touch_override/global.py new file mode 100644 index 00000000000000..a8f244e547d912 --- /dev/null +++ b/webdriver/tests/bidi/emulation/set_touch_override/global.py @@ -0,0 +1,38 @@ +import pytest +from . import MAX_TOUCHES_GLOBAL + + + +pytestmark = pytest.mark.asyncio + + +async def test_top_level(bidi_session, create_user_context, + get_max_touch_points, affected_user_context, initial_max_touch_points): + affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=affected_user_context) + + await bidi_session.emulation.set_touch_override(max_touch_points=MAX_TOUCHES_GLOBAL) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_GLOBAL + + another_affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=affected_user_context) + assert await get_max_touch_points(another_affected_context) == MAX_TOUCHES_GLOBAL + + await bidi_session.emulation.set_touch_override(max_touch_points=None) + assert await get_max_touch_points(affected_context) == initial_max_touch_points + assert await get_max_touch_points(another_affected_context) == initial_max_touch_points + + +@pytest.mark.parametrize("domain", ["", "alt"], + ids=["same_origin", "cross_origin"]) +async def test_iframe(bidi_session, url, get_max_touch_points, + top_context, create_iframe, domain, affected_user_context, initial_max_touch_points): + affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=affected_user_context) + iframe_id = await create_iframe(affected_context, url('/', domain=domain)) + + await bidi_session.emulation.set_touch_override(max_touch_points=MAX_TOUCHES_GLOBAL) + assert await get_max_touch_points(iframe_id) == MAX_TOUCHES_GLOBAL + + await bidi_session.emulation.set_touch_override(max_touch_points=None) + assert await get_max_touch_points(iframe_id) == initial_max_touch_points diff --git a/webdriver/tests/bidi/emulation/set_touch_override/invalid.py b/webdriver/tests/bidi/emulation/set_touch_override/invalid.py new file mode 100644 index 00000000000000..7b963d23ecc4ea --- /dev/null +++ b/webdriver/tests/bidi/emulation/set_touch_override/invalid.py @@ -0,0 +1,110 @@ +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 + + +@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.emulation.set_touch_override( + max_touch_points=None, + contexts=value + ) + + +async def test_params_contexts_empty_list(bidi_session): + with pytest.raises(error.InvalidArgumentException): + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + 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.emulation.set_touch_override( + max_touch_points=None, + contexts=[value]) + + +async def test_params_contexts_entry_invalid_value(bidi_session): + with pytest.raises(error.NoSuchFrameException): + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + contexts=["_invalid_"], + ) + + +@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.emulation.set_touch_override( + max_touch_points=None, + user_contexts=value, + ) + + +async def test_params_user_contexts_empty_list(bidi_session): + with pytest.raises(error.InvalidArgumentException): + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + 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.emulation.set_touch_override( + max_touch_points=None, + 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.emulation.set_touch_override( + max_touch_points=None, + user_contexts=[value], + ) + + +async def test_params_contexts_and_user_contexts(bidi_session, top_context): + with pytest.raises(error.InvalidArgumentException): + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + contexts=[top_context["context"]], + user_contexts=["default"], + ) + + +async def test_params_touch_override_missing(bidi_session, top_context): + with pytest.raises(error.InvalidArgumentException): + await bidi_session.emulation.set_touch_override( + max_touch_points=UNDEFINED, + contexts=[top_context["context"]], + ) + + +@pytest.mark.parametrize("value", get_invalid_cases("number", nullable=True)) +async def test_params_touch_override_invalid_type(bidi_session, top_context, + value): + with pytest.raises(error.InvalidArgumentException): + await bidi_session.emulation.set_touch_override( + max_touch_points=value, + contexts=[top_context["context"]], + ) + + +async def test_params_touch_override_invalid_value(bidi_session, + top_context): + with pytest.raises(error.InvalidArgumentException): + await bidi_session.emulation.set_touch_override( + max_touch_points=-1, + contexts=[top_context["context"]], + ) diff --git a/webdriver/tests/bidi/emulation/set_touch_override/user_contexts.py b/webdriver/tests/bidi/emulation/set_touch_override/user_contexts.py new file mode 100644 index 00000000000000..d9d7a64d83110b --- /dev/null +++ b/webdriver/tests/bidi/emulation/set_touch_override/user_contexts.py @@ -0,0 +1,82 @@ +import pytest +from . import MAX_TOUCHES_PER_USER_CONTEXT, MAX_TOUCHES_GLOBAL + + + +pytestmark = pytest.mark.asyncio + + +async def test_isolation(bidi_session, create_user_context, + get_max_touch_points, affected_user_context, not_affected_user_context, initial_max_touch_points): + affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=affected_user_context) + not_affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=not_affected_user_context) + + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_PER_USER_CONTEXT, + user_contexts=[affected_user_context]) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_USER_CONTEXT + assert await get_max_touch_points(not_affected_context) == initial_max_touch_points + + another_affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=affected_user_context) + another_not_affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=not_affected_user_context) + assert await get_max_touch_points(another_affected_context) == MAX_TOUCHES_PER_USER_CONTEXT + assert await get_max_touch_points(another_not_affected_context) == initial_max_touch_points + + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + user_contexts=[affected_user_context]) + + assert await get_max_touch_points(affected_context) == initial_max_touch_points + assert await get_max_touch_points(not_affected_context) == initial_max_touch_points + assert await get_max_touch_points(another_affected_context) == initial_max_touch_points + assert await get_max_touch_points(another_not_affected_context) == initial_max_touch_points + + +@pytest.mark.parametrize("domain", ["", "alt"], + ids=["same_origin", "cross_origin"]) +async def test_frame(bidi_session, url, get_max_touch_points, + top_context, create_iframe, domain, affected_user_context, initial_max_touch_points): + affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=affected_user_context) + + iframe_id = await create_iframe(affected_context, url('/', domain=domain)) + + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_PER_USER_CONTEXT, + user_contexts=[affected_user_context]) + + assert await get_max_touch_points(iframe_id) == MAX_TOUCHES_PER_USER_CONTEXT + + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + user_contexts=[affected_user_context]) + + assert await get_max_touch_points(iframe_id) == initial_max_touch_points + + +async def test_overrides_global(bidi_session, get_max_touch_points, + affected_user_context, initial_max_touch_points): + affected_context = await bidi_session.browsing_context.create( + type_hint="tab", user_context=affected_user_context) + + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_PER_USER_CONTEXT, + user_contexts=[affected_user_context]) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_USER_CONTEXT + + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_GLOBAL) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_USER_CONTEXT + + await bidi_session.emulation.set_touch_override( + max_touch_points=None, + user_contexts=[affected_user_context]) + assert await get_max_touch_points(affected_context) == MAX_TOUCHES_GLOBAL + + await bidi_session.emulation.set_touch_override( + max_touch_points=None) + assert await get_max_touch_points(affected_context) == initial_max_touch_points From e7c28d7f7443e02fc1efde2c1f0ea1170dea939e Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Tue, 16 Dec 2025 17:51:59 +0100 Subject: [PATCH 2/3] format --- .../emulation/set_touch_override/__init__.py | 2 +- .../emulation/set_touch_override/conftest.py | 5 +- .../emulation/set_touch_override/contexts.py | 52 ++++++++++++------- .../emulation/set_touch_override/global.py | 26 ++++++---- .../emulation/set_touch_override/invalid.py | 4 +- .../set_touch_override/user_contexts.py | 47 ++++++++++------- 6 files changed, 83 insertions(+), 53 deletions(-) diff --git a/webdriver/tests/bidi/emulation/set_touch_override/__init__.py b/webdriver/tests/bidi/emulation/set_touch_override/__init__.py index 49e272bf398e79..c383898198e79b 100644 --- a/webdriver/tests/bidi/emulation/set_touch_override/__init__.py +++ b/webdriver/tests/bidi/emulation/set_touch_override/__init__.py @@ -1,3 +1,3 @@ MAX_TOUCHES_PER_CONTEXT = 4 MAX_TOUCHES_PER_USER_CONTEXT = 5 -MAX_TOUCHES_GLOBAL = 6 +MAX_TOUCHES_GLOBAL = 6 diff --git a/webdriver/tests/bidi/emulation/set_touch_override/conftest.py b/webdriver/tests/bidi/emulation/set_touch_override/conftest.py index d00ba940ddc72c..f47549a94aa5ce 100644 --- a/webdriver/tests/bidi/emulation/set_touch_override/conftest.py +++ b/webdriver/tests/bidi/emulation/set_touch_override/conftest.py @@ -1,6 +1,7 @@ import pytest_asyncio from webdriver.bidi.modules.script import ContextTarget + @pytest_asyncio.fixture async def get_max_touch_points(bidi_session): async def get_max_touch_points(context): @@ -15,14 +16,14 @@ async def get_max_touch_points(context): @pytest_asyncio.fixture -async def initial_max_touch_points(bidi_session, top_context, get_max_touch_points): +async def initial_max_touch_points(top_context, get_max_touch_points): """Return the initial value of maxTouchPoints.""" return await get_max_touch_points(top_context) @pytest_asyncio.fixture(params=['default', 'new'], ids=["Default user context", "Custom user context"]) -async def target_user_context(request, create_user_context): +async def target_user_context(request): return request.param diff --git a/webdriver/tests/bidi/emulation/set_touch_override/contexts.py b/webdriver/tests/bidi/emulation/set_touch_override/contexts.py index 5857925397bb34..3854a23c5a59a1 100644 --- a/webdriver/tests/bidi/emulation/set_touch_override/contexts.py +++ b/webdriver/tests/bidi/emulation/set_touch_override/contexts.py @@ -1,12 +1,13 @@ import pytest -from . import MAX_TOUCHES_PER_CONTEXT, MAX_TOUCHES_PER_USER_CONTEXT, MAX_TOUCHES_PER_GLOBAL - +from . import MAX_TOUCHES_PER_CONTEXT, MAX_TOUCHES_PER_USER_CONTEXT, \ + MAX_TOUCHES_GLOBAL pytestmark = pytest.mark.asyncio async def test_contexts_isolation(bidi_session, top_context, - get_max_touch_points, initial_max_touch_points): + get_max_touch_points, + initial_max_touch_points): another_context = await bidi_session.browsing_context.create( type_hint="tab") @@ -14,24 +15,28 @@ async def test_contexts_isolation(bidi_session, top_context, max_touch_points=MAX_TOUCHES_PER_CONTEXT, contexts=[top_context["context"]]) assert await get_max_touch_points(top_context) == MAX_TOUCHES_PER_CONTEXT - assert await get_max_touch_points(another_context) == initial_max_touch_points + assert await get_max_touch_points( + another_context) == initial_max_touch_points yet_another_context = await bidi_session.browsing_context.create( type_hint="tab") - assert await get_max_touch_points(yet_another_context) == initial_max_touch_points + assert await get_max_touch_points( + yet_another_context) == initial_max_touch_points await bidi_session.emulation.set_touch_override( max_touch_points=None, contexts=[top_context["context"]]) assert await get_max_touch_points(top_context) == initial_max_touch_points - assert await get_max_touch_points(another_context) == initial_max_touch_points - assert await get_max_touch_points(yet_another_context) == initial_max_touch_points + assert await get_max_touch_points( + another_context) == initial_max_touch_points + assert await get_max_touch_points( + yet_another_context) == initial_max_touch_points @pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"]) -async def test_frame(bidi_session, url, get_max_touch_points, - top_context, create_iframe, domain, initial_max_touch_points): +async def test_frame(bidi_session, url, get_max_touch_points, top_context, + create_iframe, domain, initial_max_touch_points): iframe_id = await create_iframe(top_context, url('/', domain=domain)) await bidi_session.emulation.set_touch_override( @@ -46,45 +51,54 @@ async def test_frame(bidi_session, url, get_max_touch_points, async def test_overrides_user_contexts(bidi_session, get_max_touch_points, - affected_user_context, initial_max_touch_points): + affected_user_context, + initial_max_touch_points): affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=affected_user_context) await bidi_session.emulation.set_touch_override( max_touch_points=MAX_TOUCHES_PER_CONTEXT, contexts=[affected_context["context"]]) - assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_CONTEXT + assert await get_max_touch_points( + affected_context) == MAX_TOUCHES_PER_CONTEXT await bidi_session.emulation.set_touch_override( max_touch_points=MAX_TOUCHES_PER_USER_CONTEXT, user_contexts=[affected_user_context]) - assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_CONTEXT + assert await get_max_touch_points( + affected_context) == MAX_TOUCHES_PER_CONTEXT await bidi_session.emulation.set_touch_override( max_touch_points=None, contexts=[affected_context["context"]]) - assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_USER_CONTEXT + assert await get_max_touch_points( + affected_context) == MAX_TOUCHES_PER_USER_CONTEXT await bidi_session.emulation.set_touch_override( max_touch_points=None, user_contexts=[affected_user_context]) - assert await get_max_touch_points(affected_context) == initial_max_touch_points + assert await get_max_touch_points( + affected_context) == initial_max_touch_points async def test_overrides_global(bidi_session, get_max_touch_points, - affected_user_context, initial_max_touch_points): + affected_user_context): affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=affected_user_context) await bidi_session.emulation.set_touch_override( max_touch_points=MAX_TOUCHES_PER_CONTEXT, contexts=[affected_context["context"]]) - assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_CONTEXT + assert await get_max_touch_points( + affected_context) == MAX_TOUCHES_PER_CONTEXT - await bidi_session.emulation.set_touch_override(max_touch_points=MAX_TOUCHES_PER_GLOBAL) - assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_CONTEXT + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_GLOBAL) + assert await get_max_touch_points( + affected_context) == MAX_TOUCHES_PER_CONTEXT await bidi_session.emulation.set_touch_override( max_touch_points=None, contexts=[affected_context["context"]]) - assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_GLOBAL + assert await get_max_touch_points( + affected_context) == MAX_TOUCHES_GLOBAL diff --git a/webdriver/tests/bidi/emulation/set_touch_override/global.py b/webdriver/tests/bidi/emulation/set_touch_override/global.py index a8f244e547d912..074de223d574a6 100644 --- a/webdriver/tests/bidi/emulation/set_touch_override/global.py +++ b/webdriver/tests/bidi/emulation/set_touch_override/global.py @@ -1,37 +1,41 @@ import pytest from . import MAX_TOUCHES_GLOBAL - - pytestmark = pytest.mark.asyncio -async def test_top_level(bidi_session, create_user_context, - get_max_touch_points, affected_user_context, initial_max_touch_points): +async def test_top_level(bidi_session, get_max_touch_points, + affected_user_context, initial_max_touch_points): affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=affected_user_context) - await bidi_session.emulation.set_touch_override(max_touch_points=MAX_TOUCHES_GLOBAL) + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_GLOBAL) assert await get_max_touch_points(affected_context) == MAX_TOUCHES_GLOBAL another_affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=affected_user_context) - assert await get_max_touch_points(another_affected_context) == MAX_TOUCHES_GLOBAL + assert await get_max_touch_points( + another_affected_context) == MAX_TOUCHES_GLOBAL await bidi_session.emulation.set_touch_override(max_touch_points=None) - assert await get_max_touch_points(affected_context) == initial_max_touch_points - assert await get_max_touch_points(another_affected_context) == initial_max_touch_points + assert await get_max_touch_points( + affected_context) == initial_max_touch_points + assert await get_max_touch_points( + another_affected_context) == initial_max_touch_points @pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"]) -async def test_iframe(bidi_session, url, get_max_touch_points, - top_context, create_iframe, domain, affected_user_context, initial_max_touch_points): +async def test_iframe(bidi_session, url, get_max_touch_points, create_iframe, + domain, affected_user_context, + initial_max_touch_points): affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=affected_user_context) iframe_id = await create_iframe(affected_context, url('/', domain=domain)) - await bidi_session.emulation.set_touch_override(max_touch_points=MAX_TOUCHES_GLOBAL) + await bidi_session.emulation.set_touch_override( + max_touch_points=MAX_TOUCHES_GLOBAL) assert await get_max_touch_points(iframe_id) == MAX_TOUCHES_GLOBAL await bidi_session.emulation.set_touch_override(max_touch_points=None) diff --git a/webdriver/tests/bidi/emulation/set_touch_override/invalid.py b/webdriver/tests/bidi/emulation/set_touch_override/invalid.py index 7b963d23ecc4ea..8ff0a96d4157d4 100644 --- a/webdriver/tests/bidi/emulation/set_touch_override/invalid.py +++ b/webdriver/tests/bidi/emulation/set_touch_override/invalid.py @@ -93,7 +93,7 @@ async def test_params_touch_override_missing(bidi_session, top_context): @pytest.mark.parametrize("value", get_invalid_cases("number", nullable=True)) async def test_params_touch_override_invalid_type(bidi_session, top_context, - value): + value): with pytest.raises(error.InvalidArgumentException): await bidi_session.emulation.set_touch_override( max_touch_points=value, @@ -102,7 +102,7 @@ async def test_params_touch_override_invalid_type(bidi_session, top_context, async def test_params_touch_override_invalid_value(bidi_session, - top_context): + top_context): with pytest.raises(error.InvalidArgumentException): await bidi_session.emulation.set_touch_override( max_touch_points=-1, diff --git a/webdriver/tests/bidi/emulation/set_touch_override/user_contexts.py b/webdriver/tests/bidi/emulation/set_touch_override/user_contexts.py index d9d7a64d83110b..877f179a66d04c 100644 --- a/webdriver/tests/bidi/emulation/set_touch_override/user_contexts.py +++ b/webdriver/tests/bidi/emulation/set_touch_override/user_contexts.py @@ -1,13 +1,12 @@ import pytest from . import MAX_TOUCHES_PER_USER_CONTEXT, MAX_TOUCHES_GLOBAL - - pytestmark = pytest.mark.asyncio -async def test_isolation(bidi_session, create_user_context, - get_max_touch_points, affected_user_context, not_affected_user_context, initial_max_touch_points): +async def test_isolation(bidi_session, get_max_touch_points, + affected_user_context, not_affected_user_context, + initial_max_touch_points): affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=affected_user_context) not_affected_context = await bidi_session.browsing_context.create( @@ -16,30 +15,38 @@ async def test_isolation(bidi_session, create_user_context, await bidi_session.emulation.set_touch_override( max_touch_points=MAX_TOUCHES_PER_USER_CONTEXT, user_contexts=[affected_user_context]) - assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_USER_CONTEXT - assert await get_max_touch_points(not_affected_context) == initial_max_touch_points + assert await get_max_touch_points( + affected_context) == MAX_TOUCHES_PER_USER_CONTEXT + assert await get_max_touch_points( + not_affected_context) == initial_max_touch_points another_affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=affected_user_context) another_not_affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=not_affected_user_context) - assert await get_max_touch_points(another_affected_context) == MAX_TOUCHES_PER_USER_CONTEXT - assert await get_max_touch_points(another_not_affected_context) == initial_max_touch_points + assert await get_max_touch_points( + another_affected_context) == MAX_TOUCHES_PER_USER_CONTEXT + assert await get_max_touch_points( + another_not_affected_context) == initial_max_touch_points await bidi_session.emulation.set_touch_override( max_touch_points=None, user_contexts=[affected_user_context]) - assert await get_max_touch_points(affected_context) == initial_max_touch_points - assert await get_max_touch_points(not_affected_context) == initial_max_touch_points - assert await get_max_touch_points(another_affected_context) == initial_max_touch_points - assert await get_max_touch_points(another_not_affected_context) == initial_max_touch_points + assert await get_max_touch_points( + affected_context) == initial_max_touch_points + assert await get_max_touch_points( + not_affected_context) == initial_max_touch_points + assert await get_max_touch_points( + another_affected_context) == initial_max_touch_points + assert await get_max_touch_points( + another_not_affected_context) == initial_max_touch_points @pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"]) -async def test_frame(bidi_session, url, get_max_touch_points, - top_context, create_iframe, domain, affected_user_context, initial_max_touch_points): +async def test_frame(bidi_session, url, get_max_touch_points, create_iframe, + domain, affected_user_context, initial_max_touch_points): affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=affected_user_context) @@ -59,18 +66,21 @@ async def test_frame(bidi_session, url, get_max_touch_points, async def test_overrides_global(bidi_session, get_max_touch_points, - affected_user_context, initial_max_touch_points): + affected_user_context, + initial_max_touch_points): affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=affected_user_context) await bidi_session.emulation.set_touch_override( max_touch_points=MAX_TOUCHES_PER_USER_CONTEXT, user_contexts=[affected_user_context]) - assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_USER_CONTEXT + assert await get_max_touch_points( + affected_context) == MAX_TOUCHES_PER_USER_CONTEXT await bidi_session.emulation.set_touch_override( max_touch_points=MAX_TOUCHES_GLOBAL) - assert await get_max_touch_points(affected_context) == MAX_TOUCHES_PER_USER_CONTEXT + assert await get_max_touch_points( + affected_context) == MAX_TOUCHES_PER_USER_CONTEXT await bidi_session.emulation.set_touch_override( max_touch_points=None, @@ -79,4 +89,5 @@ async def test_overrides_global(bidi_session, get_max_touch_points, await bidi_session.emulation.set_touch_override( max_touch_points=None) - assert await get_max_touch_points(affected_context) == initial_max_touch_points + assert await get_max_touch_points( + affected_context) == initial_max_touch_points From f73c3049813df30d9f90869b1195af0e2062c9cf Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Wed, 17 Dec 2025 08:54:08 +0100 Subject: [PATCH 3/3] prevent state leak --- .../tests/bidi/emulation/set_touch_override/contexts.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/webdriver/tests/bidi/emulation/set_touch_override/contexts.py b/webdriver/tests/bidi/emulation/set_touch_override/contexts.py index 3854a23c5a59a1..7712cf1e6dbee7 100644 --- a/webdriver/tests/bidi/emulation/set_touch_override/contexts.py +++ b/webdriver/tests/bidi/emulation/set_touch_override/contexts.py @@ -82,7 +82,8 @@ async def test_overrides_user_contexts(bidi_session, get_max_touch_points, async def test_overrides_global(bidi_session, get_max_touch_points, - affected_user_context): + affected_user_context, + initial_max_touch_points): affected_context = await bidi_session.browsing_context.create( type_hint="tab", user_context=affected_user_context) @@ -102,3 +103,8 @@ async def test_overrides_global(bidi_session, get_max_touch_points, contexts=[affected_context["context"]]) assert await get_max_touch_points( affected_context) == MAX_TOUCHES_GLOBAL + + await bidi_session.emulation.set_touch_override( + max_touch_points=None) + assert await get_max_touch_points( + affected_context) == initial_max_touch_points