Skip to content

Commit

Permalink
[wdspec] Update script invalid tests to properly check invalid option…
Browse files Browse the repository at this point in the history
…al arguments

Depends on D216811

In most cases, the calls would fail early because of a missing channel argument.
Ideally for invalid tests, all the payload should be correct except for the invalid argument we are testing.

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

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1908621
gecko-commit: f0952d56d427b2f8bd8e03576403aef0a650f8d2
gecko-reviewers: webdriver-reviewers, whimboo
  • Loading branch information
juliandescottes authored and moz-wptsync-bot committed Jul 19, 2024
1 parent f4f0bf7 commit 27c8d23
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 84 deletions.
62 changes: 40 additions & 22 deletions webdriver/tests/bidi/script/add_preload_script/invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,22 @@ async def test_params_arguments_channel_ownership_invalid_type(bidi_session, own
with pytest.raises(error.InvalidArgumentException):
await bidi_session.script.add_preload_script(
function_declaration="() => {}",
arguments=[{"type": "channel", "value": {"ownership": ownership}}],
arguments=[
{"type": "channel", "value": {"channel": "foo", "ownership": ownership}}
],
)


async def test_params_arguments_channel_ownership_invalid_value(bidi_session):
with pytest.raises(error.InvalidArgumentException):
await bidi_session.script.add_preload_script(
function_declaration="() => {}",
arguments=[{"type": "channel", "value": {
"ownership": "_UNKNOWN_"}}],
arguments=[
{
"type": "channel",
"value": {"channel": "foo", "ownership": "_UNKNOWN_"},
}
],
)


Expand All @@ -86,7 +92,10 @@ async def test_params_arguments_channel_serialization_options_invalid_type(
arguments=[
{
"type": "channel",
"value": {"serializationOptions": serialization_options},
"value": {
"channel": "foo",
"serializationOptions": serialization_options,
},
}
],
)
Expand All @@ -102,7 +111,10 @@ async def test_params_arguments_channel_max_dom_depth_invalid_type(
arguments=[
{
"type": "channel",
"value": {"serializationOptions": {"maxDomDepth": max_dom_depth}},
"value": {
"channel": "foo",
"serializationOptions": {"maxDomDepth": max_dom_depth},
},
}
],
)
Expand All @@ -115,7 +127,10 @@ async def test_params_arguments_channel_max_dom_depth_invalid_value(bidi_session
arguments=[
{
"type": "channel",
"value": {"serializationOptions": {"maxDomDepth": -1}},
"value": {
"channel": "foo",
"serializationOptions": {"maxDomDepth": -1},
},
}
],
)
Expand All @@ -132,7 +147,8 @@ async def test_params_arguments_channel_max_object_depth_invalid_type(
{
"type": "channel",
"value": {
"serializationOptions": {"maxObjectDepth": max_object_depth}
"channel": "foo",
"serializationOptions": {"maxObjectDepth": max_object_depth},
},
}
],
Expand All @@ -146,7 +162,10 @@ async def test_params_arguments_channel_max_object_depth_invalid_value(bidi_sess
arguments=[
{
"type": "channel",
"value": {"serializationOptions": {"maxObjectDepth": -1}},
"value": {
"channel": "foo",
"serializationOptions": {"maxObjectDepth": -1},
},
}
],
)
Expand All @@ -163,9 +182,10 @@ async def test_params_arguments_channel_include_shadow_tree_invalid_type(
{
"type": "channel",
"value": {
"channel": "foo",
"serializationOptions": {
"includeShadowTree": include_shadow_tree
}
},
},
}
],
Expand All @@ -180,49 +200,48 @@ async def test_params_arguments_channel_include_shadow_tree_invalid_value(bidi_s
{
"type": "channel",
"value": {
"serializationOptions": {"includeShadowTree": "_UNKNOWN_"}
"channel": "foo",
"serializationOptions": {"includeShadowTree": "_UNKNOWN_"},
},
}
],
)


@pytest.mark.parametrize("contexts", [False, 42, '_UNKNOWN_', {}])
@pytest.mark.parametrize("contexts", [False, 42, "_UNKNOWN_", {}])
async def test_params_contexts_invalid_type(bidi_session, contexts):
with pytest.raises(error.InvalidArgumentException):
await bidi_session.script.add_preload_script(
function_declaration="() => {}",
contexts=contexts
function_declaration="() => {}", contexts=contexts
),


async def test_params_contexts_empty_list(bidi_session):
with pytest.raises(error.InvalidArgumentException):
await bidi_session.script.add_preload_script(
function_declaration="() => {}",
contexts=[]
function_declaration="() => {}", contexts=[]
),


@pytest.mark.parametrize("value", [None, False, 42, {}, []])
async def test_params_contexts_context_invalid_type(bidi_session, value):
with pytest.raises(error.InvalidArgumentException):
await bidi_session.script.add_preload_script(
function_declaration="() => {}",
contexts=[value]
function_declaration="() => {}", contexts=[value]
),


@pytest.mark.parametrize("value", ["", "somestring"])
async def test_params_contexts_context_invalid_value(bidi_session, value):
with pytest.raises(error.NoSuchFrameException):
await bidi_session.script.add_preload_script(
function_declaration="() => {}",
contexts=[value]
function_declaration="() => {}", contexts=[value]
),


async def test_params_contexts_context_non_top_level(bidi_session, new_tab, test_page_same_origin_frame):
async def test_params_contexts_context_non_top_level(
bidi_session, new_tab, test_page_same_origin_frame
):
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=test_page_same_origin_frame,
Expand All @@ -237,8 +256,7 @@ async def test_params_contexts_context_non_top_level(bidi_session, new_tab, test

with pytest.raises(error.InvalidArgumentException):
await bidi_session.script.add_preload_script(
function_declaration="() => {}",
contexts=[child_info['context']]
function_declaration="() => {}", contexts=[child_info["context"]]
),


Expand Down
Loading

0 comments on commit 27c8d23

Please sign in to comment.