Skip to content

Commit

Permalink
[wdspec] change test_..._closes_browsing_context (#49759)
Browse files Browse the repository at this point in the history
Open context with `window.open` to allow it to be closed by script.
  • Loading branch information
sadym-chromium authored Dec 18, 2024
1 parent 7d9676e commit 16e6fbc
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 27 deletions.
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

0 comments on commit 16e6fbc

Please sign in to comment.