-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Any, Optional, Mapping, MutableMapping | ||
|
||
from ._module import BidiModule, command | ||
|
||
|
||
class Permissions(BidiModule): | ||
@command | ||
def end(self) -> Mapping[str, Any]: | ||
return {} | ||
|
||
@end.result | ||
async def _end(self, result: Mapping[str, Any]) -> Any: | ||
if self.session.transport: | ||
await self.session.transport.wait_closed() | ||
|
||
return result | ||
|
||
@command | ||
def set_permission(self, | ||
descriptor: Optional[Mapping[str, Any]] = None, | ||
state: Optional[str] = None, | ||
origin: Optional[str] = None) -> Mapping[str, Any]: | ||
params: MutableMapping[str, Any] = { | ||
"descriptor": descriptor, | ||
"state": state, | ||
"origin": origin | ||
} | ||
return params |
Empty file.
23 changes: 23 additions & 0 deletions
23
webdriver/tests/bidi/permissions/set_permission/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from typing import Any, Mapping | ||
|
||
from webdriver.bidi.modules.script import ContextTarget | ||
|
||
async def get_permission_state(bidi_session, context: Mapping[str, Any], name: str) -> str: | ||
result = await bidi_session.script.call_function( | ||
function_declaration="""() => { | ||
return navigator.permissions.query({ name: '%s' }) | ||
.then(val => val.state, err => err.message) | ||
}""" % name, | ||
target=ContextTarget(context["context"]), | ||
await_promise=True) | ||
return result["value"] | ||
|
||
|
||
async def get_context_origin(bidi_session, context: Mapping[str, Any]) -> str: | ||
result = await bidi_session.script.call_function( | ||
function_declaration="""() => { | ||
return window.location.origin; | ||
}""", | ||
target=ContextTarget(context["context"]), | ||
await_promise=False) | ||
return result["value"] |
53 changes: 53 additions & 0 deletions
53
webdriver/tests/bidi/permissions/set_permission/invalid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import pytest | ||
import webdriver.bidi.error as error | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
@pytest.mark.parametrize("descriptor", [False, "SOME_STRING", 42, {}, [], {"name": 23}, None]) | ||
async def test_params_descriptor_invalid_type(bidi_session, descriptor): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.permissions.set_permission( | ||
descriptor=descriptor, | ||
state="granted", | ||
origin="https://example.com", | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("descriptor", [{"name": "unknown"}]) | ||
async def test_params_descriptor_invalid_value(bidi_session, descriptor): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.permissions.set_permission( | ||
descriptor=descriptor, | ||
state="granted", | ||
origin="https://example.com", | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("state", [False, 42, {}, [], None]) | ||
async def test_params_state_invalid_type(bidi_session, state): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.permissions.set_permission( | ||
descriptor={"name": "geolocation"}, | ||
state=state, | ||
origin="https://example.com", | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("state", ["UNKOWN", "Granted"]) | ||
async def test_params_state_invalid_value(bidi_session, state): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.permissions.set_permission( | ||
descriptor={"name": "geolocation"}, | ||
state=state, | ||
origin="https://example.com", | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("origin", [False, 42, {}, [], None]) | ||
async def test_params_origin_invalid_type(bidi_session, origin): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.permissions.set_permission( | ||
descriptor={"name": "geolocation"}, | ||
state="granted", | ||
origin=origin, | ||
) |
42 changes: 42 additions & 0 deletions
42
webdriver/tests/bidi/permissions/set_permission/set_permission.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
|
||
from . import get_context_origin, get_permission_state | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
@pytest.mark.asyncio | ||
async def test_set_permission(bidi_session, new_tab, url): | ||
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) | ||
|
||
assert await get_permission_state(bidi_session, new_tab, "geolocation") == "prompt" | ||
|
||
await bidi_session.permissions.set_permission( | ||
descriptor={"name": "geolocation"}, | ||
state="granted", | ||
origin=origin, | ||
) | ||
|
||
assert await get_permission_state(bidi_session, new_tab, "geolocation") == "granted" | ||
|
||
await bidi_session.permissions.set_permission( | ||
descriptor={"name": "geolocation"}, | ||
state="denied", | ||
origin=origin, | ||
) | ||
|
||
assert await get_permission_state(bidi_session, new_tab, "geolocation") == "denied" | ||
|
||
await bidi_session.permissions.set_permission( | ||
descriptor={"name": "geolocation"}, | ||
state="prompt", | ||
origin=origin, | ||
) | ||
|
||
assert await get_permission_state(bidi_session, new_tab, "geolocation") == "prompt" |