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

[wdspec] change test_..._closes_browsing_context #49759

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions webdriver/tests/bidi/input/perform_actions/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

pytestmark = pytest.mark.asyncio

CONTEXT_LOAD_EVENT = "browsingContext.load"


async def test_invalid_browsing_context(bidi_session):
actions = Actions()
Expand All @@ -20,18 +22,26 @@ async def test_invalid_browsing_context(bidi_session):


async def test_key_down_closes_browsing_context(
bidi_session, configuration, new_tab, inline
bidi_session, configuration, new_tab, inline, subscribe_events,
wait_for_event
):
url = inline("""
<input onkeydown="window.close()">close</input>
<script>document.querySelector("input").focus();</script>
""")

await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=url,
wait="complete",
# Opening a new context via `window.open` is required for script to be able
# to close it.
await subscribe_events(events=[CONTEXT_LOAD_EVENT])
on_load = wait_for_event(CONTEXT_LOAD_EVENT)

await bidi_session.script.evaluate(
expression=f"window.open('{url}')",
target=ContextTarget(new_tab["context"]),
await_promise=True
)
# Wait for the new context to be created and get it.
new_context = await on_load

actions = Actions()
(
Expand All @@ -43,7 +53,7 @@ async def test_key_down_closes_browsing_context(

with pytest.raises(NoSuchFrameException):
await bidi_session.input.perform_actions(
actions=actions, context=new_tab["context"]
actions=actions, context=new_context["context"]
)


Expand Down
26 changes: 19 additions & 7 deletions webdriver/tests/bidi/input/perform_actions/pointer_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from webdriver.bidi.error import MoveTargetOutOfBoundsException, NoSuchFrameException
from webdriver.bidi.modules.input import Actions, get_element_origin
from webdriver.bidi.modules.script import ContextTarget

from tests.support.asserts import assert_move_to_coordinates
from tests.support.helpers import filter_dict
Expand All @@ -16,18 +17,29 @@

pytestmark = pytest.mark.asyncio

CONTEXT_LOAD_EVENT = "browsingContext.load"


async def test_pointer_down_closes_browsing_context(
bidi_session, configuration, get_element, new_tab, inline
bidi_session, configuration, get_element, new_tab, inline, subscribe_events,
wait_for_event
):
url = inline("""<input onpointerdown="window.close()">close</input>""")
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=url,
wait="complete",

# Opening a new context via `window.open` is required for script to be able
# to close it.
await subscribe_events(events=[CONTEXT_LOAD_EVENT])
on_load = wait_for_event(CONTEXT_LOAD_EVENT)

await bidi_session.script.evaluate(
expression=f"window.open('{url}')",
target=ContextTarget(new_tab["context"]),
await_promise=True
)
# Wait for the new context to be created and get it.
new_context = await on_load

element = await get_element("input", context=new_tab)
element = await get_element("input", context=new_context)
origin = get_element_origin(element)

actions = Actions()
Expand All @@ -41,7 +53,7 @@ async def test_pointer_down_closes_browsing_context(

with pytest.raises(NoSuchFrameException):
await bidi_session.input.perform_actions(
actions=actions, context=new_tab["context"]
actions=actions, context=new_context["context"]
)


Expand Down
26 changes: 19 additions & 7 deletions webdriver/tests/bidi/input/perform_actions/pointer_pen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from webdriver.bidi.error import MoveTargetOutOfBoundsException, NoSuchFrameException
from webdriver.bidi.modules.input import Actions, get_element_origin
from webdriver.bidi.modules.script import ContextTarget

from .. import get_events
from . import (
Expand All @@ -13,18 +14,29 @@

pytestmark = pytest.mark.asyncio

CONTEXT_LOAD_EVENT = "browsingContext.load"


async def test_pointer_down_closes_browsing_context(
bidi_session, configuration, get_element, new_tab, inline
bidi_session, configuration, get_element, new_tab, inline, subscribe_events,
wait_for_event
):
url = inline("""<input onpointerdown="window.close()">close</input>""")
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=url,
wait="complete",

# Opening a new context via `window.open` is required for script to be able
# to close it.
await subscribe_events(events=[CONTEXT_LOAD_EVENT])
on_load = wait_for_event(CONTEXT_LOAD_EVENT)

await bidi_session.script.evaluate(
expression=f"window.open('{url}')",
target=ContextTarget(new_tab["context"]),
await_promise=True
)
# Wait for the new context to be created and get it.
new_context = await on_load

element = await get_element("input", context=new_tab)
element = await get_element("input", context=new_context)
origin = get_element_origin(element)

actions = Actions()
Expand All @@ -38,7 +50,7 @@ async def test_pointer_down_closes_browsing_context(

with pytest.raises(NoSuchFrameException):
await bidi_session.input.perform_actions(
actions=actions, context=new_tab["context"]
actions=actions, context=new_context["context"]
)


Expand Down
26 changes: 19 additions & 7 deletions webdriver/tests/bidi/input/perform_actions/pointer_touch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from webdriver.bidi.error import MoveTargetOutOfBoundsException, NoSuchFrameException
from webdriver.bidi.modules.input import Actions, get_element_origin
from webdriver.bidi.modules.script import ContextTarget

from .. import get_events
from . import (
Expand All @@ -13,18 +14,29 @@

pytestmark = pytest.mark.asyncio

CONTEXT_LOAD_EVENT = "browsingContext.load"


async def test_pointer_down_closes_browsing_context(
bidi_session, configuration, get_element, new_tab, inline
bidi_session, configuration, get_element, new_tab, inline, subscribe_events,
wait_for_event
):
url = inline("""<input onpointerdown="window.close()">close</input>""")
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=url,
wait="complete",

# Opening a new context via `window.open` is required for script to be able
# to close it.
await subscribe_events(events=[CONTEXT_LOAD_EVENT])
on_load = wait_for_event(CONTEXT_LOAD_EVENT)

await bidi_session.script.evaluate(
expression=f"window.open('{url}')",
target=ContextTarget(new_tab["context"]),
await_promise=True
)
# Wait for the new context to be created and get it.
new_context = await on_load

element = await get_element("input", context=new_tab)
element = await get_element("input", context=new_context)
origin = get_element_origin(element)

actions = Actions()
Expand All @@ -38,7 +50,7 @@ async def test_pointer_down_closes_browsing_context(

with pytest.raises(NoSuchFrameException):
await bidi_session.input.perform_actions(
actions=actions, context=new_tab["context"]
actions=actions, context=new_context["context"]
)


Expand Down