Skip to content

Commit

Permalink
Update script result_ownership tests to check that handle id is only …
Browse files Browse the repository at this point in the history
…set on root
  • Loading branch information
juliandescottes authored and jgraham committed Mar 15, 2023
1 parent 2c5ee97 commit 4662f28
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions webdriver/tests/bidi/script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ def assert_handle(obj: Mapping[str, Any], should_contain_handle: bool) -> None:
if should_contain_handle:
assert "handle" in obj, f"Result should contain `handle`. Actual: {obj}"
assert isinstance(obj["handle"], str), f"`handle` should be a string, but was {type(obj['handle'])}"

# Recursively check that handle is not found in any of the nested values.
if "value" in obj:
value = obj["value"]
if type(value) is list:
for v in value:
assert_handle(v, False)

if type(value) is dict:
for v in value.values():
assert_handle(v, False)

else:
assert "handle" not in obj, f"Result should not contain `handle`. Actual: {obj}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def test_rejected_promise(bidi_session, top_context, result_ownership, sho
[("root", True), ("none", False), (None, False)])
async def test_return_value(bidi_session, top_context, await_promise, result_ownership, should_contain_handle):
result = await bidi_session.script.call_function(
function_declaration="async function(){return {a:1}}",
function_declaration="async function(){return {a: {b:1}}}",
await_promise=await_promise,
result_ownership=result_ownership,
target=ContextTarget(top_context["context"]))
Expand Down
2 changes: 1 addition & 1 deletion webdriver/tests/bidi/script/evaluate/result_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def test_rejected_promise(bidi_session, top_context, result_ownership, sho
[("root", True), ("none", False), (None, False)])
async def test_return_value(bidi_session, top_context, await_promise, result_ownership, should_contain_handle):
result = await bidi_session.script.evaluate(
expression="Promise.resolve({a:1})",
expression="Promise.resolve({a: {b:1}})",
await_promise=await_promise,
result_ownership=result_ownership,
target=ContextTarget(top_context["context"]))
Expand Down

0 comments on commit 4662f28

Please sign in to comment.