Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for serialization with internal ids forscript.evaluate and script.callFunction. #36041

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions webdriver/tests/bidi/script/call_function/internal_id.py
@@ -0,0 +1,42 @@
import pytest

from ... import recursive_compare, any_string


@pytest.mark.asyncio
@pytest.mark.parametrize(
"return_structure, result_type",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result_type can be removed from here now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[
("[data, data]", "array"),
("new Map([['foo', data],['bar', data]])", "map"),
("({ 'foo': data, 'bar': data })", "object"),
],
)
@pytest.mark.parametrize(
"expression, type",
[
("[1]", "array"),
("new Map([[true, false]])", "map"),
("new Set(['baz'])", "set"),
("{ baz: 'qux' }", "object"),
],
)
async def test_remote_values_with_internal_id(
call_function, return_structure, result_type, expression, type
):
result = await call_function(
f"() => {{ const data = {expression}; return {return_structure}; }}"
)

if result_type == "array":
value = [
{"type": type, "internalId": any_string},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to check one of the items actually have the value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value is actually not present here, since we serialize only with maxDepth=1 now

{"type": type, "internalId": any_string},
]
else:
value = [
["foo", {"type": type, "internalId": any_string}],
["bar", {"type": type, "internalId": any_string}],
]

recursive_compare({"type": result_type, "value": value}, result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to check the return type here? It looks like comparing the value will enough. Can simplify the test, and check only the internal IDs, without data types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, the result_type is not really important here, I've removed it, but I think it is still good to check that the type is present in the value with internalId

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be removed from the parameters as well them

39 changes: 0 additions & 39 deletions webdriver/tests/bidi/script/call_function/result.py
@@ -1,7 +1,6 @@
import pytest

from webdriver.bidi.modules.script import ContextTarget
from ... import recursive_compare, any_string

pytestmark = pytest.mark.asyncio

Expand Down Expand Up @@ -174,41 +173,3 @@ async def test_remote_value_promise_no_await(bidi_session, top_context):
)

assert result == {"type": "promise"}


@pytest.mark.parametrize(
"return_structure, result_type",
[
("[data, data]", "array"),
("new Map([['foo', data],['bar', data]])", "map"),
("({ 'foo': data, 'bar': data })", "object"),
],
)
@pytest.mark.parametrize(
"expression, type",
[
("[1]", "array"),
("new Map([[true, false]])", "map"),
("new Set(['baz'])", "set"),
("{ baz: 'qux' }", "object"),
],
)
async def test_remote_values_with_internal_id(
call_function, return_structure, result_type, expression, type
):
result = await call_function(
f"() => {{ const data = {expression}; return {return_structure}; }}"
)

if result_type == "array":
value = [
{"type": type, "internalId": any_string},
{"type": type, "internalId": any_string},
]
else:
value = [
["foo", {"type": type, "internalId": any_string}],
["bar", {"type": type, "internalId": any_string}],
]

recursive_compare({"type": result_type, "value": value}, result)
40 changes: 40 additions & 0 deletions webdriver/tests/bidi/script/evaluate/internal_id.py
@@ -0,0 +1,40 @@
import pytest

from ... import recursive_compare, any_string


@pytest.mark.asyncio
@pytest.mark.parametrize(
"return_structure, result_type",
[
("[data, data]", "array"),
("new Map([['foo', data],['bar', data]])", "map"),
("({ 'foo': data, 'bar': data })", "object"),
],
)
@pytest.mark.parametrize(
"expression, type",
[
("[1]", "array"),
("new Map([[true, false]])", "map"),
("new Set(['baz'])", "set"),
("{ baz: 'qux' }", "object"),
],
)
async def test_remote_values_with_internal_id(
evaluate, return_structure, result_type, expression, type
):
result = await evaluate(f"{{const data = {expression}; {return_structure}}}")

if result_type == "array":
value = [
{"type": type, "internalId": any_string},
{"type": type, "internalId": any_string},
]
else:
value = [
["foo", {"type": type, "internalId": any_string}],
["bar", {"type": type, "internalId": any_string}],
]

recursive_compare({"type": result_type, "value": value}, result)
39 changes: 0 additions & 39 deletions webdriver/tests/bidi/script/evaluate/result.py
@@ -1,7 +1,5 @@
import pytest

from webdriver.bidi.modules.script import ContextTarget
from ... import recursive_compare, any_string


@pytest.mark.asyncio
Expand Down Expand Up @@ -155,40 +153,3 @@ async def test_remote_values(bidi_session, top_context, expression, expected):
)

assert result == expected


@pytest.mark.asyncio
@pytest.mark.parametrize(
"return_structure, result_type",
[
("[data, data]", "array"),
("new Map([['foo', data],['bar', data]])", "map"),
("({ 'foo': data, 'bar': data })", "object"),
],
)
@pytest.mark.parametrize(
"expression, type",
[
("[1]", "array"),
("new Map([[true, false]])", "map"),
("new Set(['baz'])", "set"),
("{ baz: 'qux' }", "object"),
],
)
async def test_remote_values_with_internal_id(
evaluate, return_structure, result_type, expression, type
):
result = await evaluate(f"{{const data = {expression}; {return_structure}}}")

if result_type == "array":
value = [
{"type": type, "internalId": any_string},
{"type": type, "internalId": any_string},
]
else:
value = [
["foo", {"type": type, "internalId": any_string}],
["bar", {"type": type, "internalId": any_string}],
]

recursive_compare({"type": result_type, "value": value}, result)