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] fix browsingContext.navigationFailed test #49718

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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,50 @@ 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])
# Depending on implementation, the `trickle(d10)` page can or can not yet
OrKoN marked this conversation as resolved.
Show resolved Hide resolved
# create a new document. Depending on this, `aborted` or `failed` event
# should be emitted.
await subscribe_events(
events=[NAVIGATION_ABORTED_EVENT, 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)

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 +302,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 All @@ -315,26 +354,45 @@ async def test_close_context(
slow_page_url = url(
"/webdriver/tests/bidi/browsing_context/support/empty.html?pipe=trickle(d10)"
)
await subscribe_events(events=[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])

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

on_navigation_failed = wait_for_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)

await bidi_session.browsing_context.close(context=new_context["context"])
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 navigation failed.
assert_navigation_info(
event,
events[0],
{
"context": new_context["context"],
"navigation": result["navigation"],
"url": slow_page_url,
},
)

remove_listener_1()
remove_listener_2()


async def test_close_iframe(
bidi_session,
Expand All @@ -348,9 +406,13 @@ async def test_close_iframe(
iframe_url = inline("<div>foo</div>")
page_url = inline(f"<iframe src={iframe_url}></iframe")

await subscribe_events(events=[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])

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

Expand All @@ -365,21 +427,36 @@ async def test_close_iframe(
context=iframe_context, url=slow_page_url, wait="none"
)

on_navigation_failed = wait_for_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)

# Reload the top context to destroy the iframe.
await bidi_session.browsing_context.reload(context=new_tab["context"], 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 iframe navigation failed.
assert_navigation_info(
event,
events[0],
{
"context": iframe_context,
"navigation": result["navigation"],
"url": slow_page_url,
},
)

remove_listener_1()
remove_listener_2()


@pytest.mark.capabilities({"unhandledPromptBehavior": {"beforeUnload": "ignore"}})
async def test_with_beforeunload_prompt(
Expand Down