Skip to content

Commit

Permalink
[wdspec] fix browsingContext.navigationFailed test
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed Dec 16, 2024
1 parent 3408919 commit f96eee1
Showing 1 changed file with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

pytestmark = pytest.mark.asyncio

NAVIGATION_ABORTED_EVENT = "browsingContext.navigationAborted"
NAVIGATION_FAILED_EVENT = "browsingContext.navigationFailed"
NAVIGATION_STARTED_EVENT = "browsingContext.navigationStarted"
USER_PROMPT_OPENED_EVENT = "browsingContext.userPromptOpened"
Expand Down Expand Up @@ -233,31 +234,51 @@ async def test_with_new_navigation(
slow_page_url = url(
"/webdriver/tests/bidi/browsing_context/support/empty.html?pipe=trickle(d10)"
)
await subscribe_events(events=[NAVIGATION_FAILED_EVENT])

result = await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=slow_page_url, wait="none"
)
on_navigation_failed = wait_for_event(NAVIGATION_FAILED_EVENT)

# Depending on implementation, the `trickle(d10)` page can or can not yet
# create a new document. Depending on this, `aborted` or `failed` event
# should be emitted.
await subscribe_events(
events=[NAVIGATION_ABORTED_EVENT, NAVIGATION_FAILED_EVENT])

events = []

async def on_event(method, data):
events.append(data)

remove_listener_1 = bidi_session.add_event_listener(
NAVIGATION_ABORTED_EVENT, on_event)
remove_listener_2 = bidi_session.add_event_listener(NAVIGATION_FAILED_EVENT,
on_event)

second_url = inline("<div>foo</div>")

# Trigger the second navigation which should fail the first one.
await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=second_url, wait="none"
)

event = await wait_for_future_safe(on_navigation_failed)
wait = AsyncPoll(bidi_session, timeout=1)
await wait.until(lambda _: len(events) > 0)
assert len(events) == 1

# Make sure that the first navigation failed.
# Make sure that the first navigation failed or aborted.
assert_navigation_info(
event,
events[0],
{
"context": new_tab["context"],
"navigation": result["navigation"],
"url": slow_page_url,
},
)

remove_listener_1()
remove_listener_2()


async def test_with_new_navigation_inside_page(
bidi_session,
Expand All @@ -282,25 +303,44 @@ async def test_with_new_navigation_inside_page(
</html>
"""
)
await subscribe_events(events=[NAVIGATION_FAILED_EVENT])
on_navigation_failed = wait_for_event(NAVIGATION_FAILED_EVENT)

# Depending on implementation, the `trickle(d10)` page can or can not yet
# create a new document. Depending on this, `aborted` or `failed` event
# should be emitted.
await subscribe_events(
events=[NAVIGATION_ABORTED_EVENT, NAVIGATION_FAILED_EVENT])

events = []

async def on_event(method, data):
events.append(data)

remove_listener_1 = bidi_session.add_event_listener(
NAVIGATION_ABORTED_EVENT, on_event)
remove_listener_2 = bidi_session.add_event_listener(NAVIGATION_FAILED_EVENT,
on_event)

result = await bidi_session.browsing_context.navigate(
context=new_tab["context"], url=slow_page_url, wait="none"
)

event = await wait_for_future_safe(on_navigation_failed)
wait = AsyncPoll(bidi_session, timeout=1)
await wait.until(lambda _: len(events) > 0)
assert len(events) == 1

# Make sure that the first navigation failed.
assert_navigation_info(
event,
events[0],
{
"context": new_tab["context"],
"navigation": result["navigation"],
"url": slow_page_url,
},
)

remove_listener_1()
remove_listener_2()


@pytest.mark.parametrize("type_hint", ["tab", "window"])
async def test_close_context(
Expand Down

0 comments on commit f96eee1

Please sign in to comment.