Skip to content

Commit

Permalink
[wdspec] Add more tests for "userContext" argument in "permissions.se…
Browse files Browse the repository at this point in the history
…tPermission" command.

Differential Revision: https://phabricator.services.mozilla.com/D210293

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1894217
gecko-commit: 9532fe565037be6bb0808b1488f185a1f74b93d1
gecko-reviewers: webdriver-reviewers, whimboo
  • Loading branch information
lutien authored and moz-wptsync-bot committed May 15, 2024
1 parent dd39fe6 commit 1051a73
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,41 +100,3 @@ async def test_set_permission_origin_unknown(bidi_session, new_tab, origin, url)
origin=origin,
)
assert await get_permission_state(bidi_session, new_tab, "geolocation") == "prompt"


@pytest.mark.asyncio
async def test_set_permission_user_context(bidi_session, new_tab, url, create_user_context):
test_url = url("/common/blank.html", protocol="https")

user_context = await create_user_context()
# new_tab is in the default user context. new_tab2 is in the non-default user context.
new_tab2 = await bidi_session.browsing_context.create(type_hint="tab", user_context=user_context)

# Navigate a context in the default user context.
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=test_url,
wait="complete",
)

# Navigate a context in the non-default user context.
await bidi_session.browsing_context.navigate(
context=new_tab2["context"],
url=test_url,
wait="complete",
)

origin = await get_context_origin(bidi_session, new_tab)

assert await get_permission_state(bidi_session, new_tab, "geolocation") == "prompt"
assert await get_permission_state(bidi_session, new_tab2, "geolocation") == "prompt"

await bidi_session.permissions.set_permission(
descriptor={"name": "geolocation"},
state="granted",
origin=origin,
user_context=user_context,
)

assert await get_permission_state(bidi_session, new_tab, "geolocation") == "prompt"
assert await get_permission_state(bidi_session, new_tab2, "geolocation") == "granted"
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import pytest

from . import get_context_origin, get_permission_state

pytestmark = pytest.mark.asyncio


async def test_set_permission_user_context(
bidi_session, new_tab, url, create_user_context
):
test_url = url("/common/blank.html", protocol="https", domain="alt")

user_context = await create_user_context()
# new_tab is in the default user context. new_tab2 is in the non-default user context.
new_tab2 = await bidi_session.browsing_context.create(
type_hint="tab", user_context=user_context
)

# Navigate a context in the default user context.
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=test_url,
wait="complete",
)

# Navigate a context in the non-default user context.
await bidi_session.browsing_context.navigate(
context=new_tab2["context"],
url=test_url,
wait="complete",
)

origin = await get_context_origin(bidi_session, new_tab)

assert await get_permission_state(bidi_session, new_tab, "geolocation") == "prompt"
assert await get_permission_state(bidi_session, new_tab2, "geolocation") == "prompt"

await bidi_session.permissions.set_permission(
descriptor={"name": "geolocation"},
state="granted",
origin=origin,
user_context=user_context,
)

assert await get_permission_state(bidi_session, new_tab, "geolocation") == "prompt"
assert (
await get_permission_state(bidi_session, new_tab2, "geolocation") == "granted"
)

# Create another tab in the non-default user context
new_tab3 = await bidi_session.browsing_context.create(
type_hint="tab", user_context=user_context
)
await bidi_session.browsing_context.navigate(
context=new_tab3["context"],
url=test_url,
wait="complete",
)

# Make sure that the permission state is still present.
assert (
await get_permission_state(bidi_session, new_tab3, "geolocation") == "granted"
)


async def test_set_permission_with_reload(bidi_session, url, create_user_context):
user_context = await create_user_context()
new_tab = await bidi_session.browsing_context.create(
type_hint="tab", user_context=user_context
)

test_url = url("/common/blank.html", protocol="https")
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=test_url,
wait="complete",
)

origin = await get_context_origin(bidi_session, new_tab)

await bidi_session.permissions.set_permission(
descriptor={"name": "geolocation"},
state="granted",
origin=origin,
user_context=user_context,
)

assert await get_permission_state(bidi_session, new_tab, "geolocation") == "granted"

await bidi_session.browsing_context.reload(
context=new_tab["context"],
wait="complete",
)

# Make sure that permission state is still set.
assert await get_permission_state(bidi_session, new_tab, "geolocation") == "granted"


async def test_reset_permission(bidi_session, url, create_user_context):
test_url = url("/common/blank.html", protocol="https")

user_context = await create_user_context()
new_tab = await bidi_session.browsing_context.create(
type_hint="tab", user_context=user_context
)

await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=test_url,
wait="complete",
)

origin = await get_context_origin(bidi_session, new_tab)

await bidi_session.permissions.set_permission(
descriptor={"name": "geolocation"},
state="granted",
origin=origin,
user_context=user_context,
)

assert await get_permission_state(bidi_session, new_tab, "geolocation") == "granted"

# Reset the permission state
await bidi_session.permissions.set_permission(
descriptor={"name": "geolocation"},
state="prompt",
origin=origin,
user_context=user_context,
)
assert await get_permission_state(bidi_session, new_tab, "geolocation") == "prompt"

0 comments on commit 1051a73

Please sign in to comment.