Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tools/webdriver/webdriver/bidi/modules/emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
3 changes: 3 additions & 0 deletions webdriver/tests/bidi/emulation/set_touch_override/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MAX_TOUCHES_PER_CONTEXT = 4
MAX_TOUCHES_PER_USER_CONTEXT = 5
MAX_TOUCHES_GLOBAL = 6
43 changes: 43 additions & 0 deletions webdriver/tests/bidi/emulation/set_touch_override/conftest.py
Original file line number Diff line number Diff line change
@@ -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()
110 changes: 110 additions & 0 deletions webdriver/tests/bidi/emulation/set_touch_override/contexts.py
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions webdriver/tests/bidi/emulation/set_touch_override/global.py
Original file line number Diff line number Diff line change
@@ -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
110 changes: 110 additions & 0 deletions webdriver/tests/bidi/emulation/set_touch_override/invalid.py
Original file line number Diff line number Diff line change
@@ -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"]],
)
Loading