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..c383898198e79b --- /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..f47549a94aa5ce --- /dev/null +++ b/webdriver/tests/bidi/emulation/set_touch_override/conftest.py @@ -0,0 +1,43 @@ +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(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): + 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..7712cf1e6dbee7 --- /dev/null +++ b/webdriver/tests/bidi/emulation/set_touch_override/contexts.py @@ -0,0 +1,110 @@ +import pytest +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): + 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_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_GLOBAL + + await bidi_session.emulation.set_touch_override( + max_touch_points=None) + assert await get_max_touch_points( + affected_context) == initial_max_touch_points 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..074de223d574a6 --- /dev/null +++ b/webdriver/tests/bidi/emulation/set_touch_override/global.py @@ -0,0 +1,42 @@ +import pytest +from . import MAX_TOUCHES_GLOBAL + +pytestmark = pytest.mark.asyncio + + +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) + 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, 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..8ff0a96d4157d4 --- /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..877f179a66d04c --- /dev/null +++ b/webdriver/tests/bidi/emulation/set_touch_override/user_contexts.py @@ -0,0 +1,93 @@ +import pytest +from . import MAX_TOUCHES_PER_USER_CONTEXT, MAX_TOUCHES_GLOBAL + +pytestmark = pytest.mark.asyncio + + +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( + 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, 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