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

[WebDriver BiDi] missing unhandledPromptBehavior #46895

Merged
merged 3 commits into from
Jun 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import webdriver.bidi.error as error
from webdriver.bidi.modules.script import ContextTarget
from webdriver.error import TimeoutException


pytestmark = pytest.mark.asyncio
Expand All @@ -12,6 +11,7 @@
USER_PROMPT_OPENED_EVENT = "browsingContext.userPromptOpened"


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
async def test_alert(
bidi_session, wait_for_event, wait_for_future_safe, new_tab, subscribe_events
):
Expand All @@ -38,6 +38,7 @@ async def test_alert(
assert result == {"type": "undefined"}


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
@pytest.mark.parametrize("accept", [True, False])
async def test_confirm(
bidi_session,
Expand Down Expand Up @@ -72,6 +73,7 @@ async def test_confirm(
assert result == {"type": "boolean", "value": accept}


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
@pytest.mark.parametrize("accept", [True, False])
async def test_prompt(
bidi_session,
Expand Down Expand Up @@ -110,7 +112,9 @@ async def test_prompt(
assert result == {"type": "null"}


@pytest.mark.parametrize("accept", [True, False])
@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
@pytest.mark.parametrize("accept", [False])
# @pytest.mark.parametrize("accept", [True, False])
whimboo marked this conversation as resolved.
Show resolved Hide resolved
async def test_beforeunload(
bidi_session,
subscribe_events,
Expand Down Expand Up @@ -138,7 +142,7 @@ async def test_beforeunload(
)

# Wait for the prompt to open.
event = await wait_for_future_safe(on_entry)
await wait_for_future_safe(on_entry)

on_prompt_closed = wait_for_event(USER_PROMPT_CLOSED_EVENT)

Expand All @@ -147,23 +151,26 @@ async def test_beforeunload(
)

# Wait for the prompt to be closed.
event = await wait_for_future_safe(on_prompt_closed)
await wait_for_future_safe(on_prompt_closed)

if accept:
# Check navigation to the target page.
navigated = await wait_for_future_safe(navigated_future)
assert navigated["url"] == page_target
else:
# If the beforeunload prompt was dismissed no navigation takes place.
with pytest.raises(TimeoutException):
await wait_for_future_safe(navigated_future, timeout=0.5)
# If the beforeunload prompt was dismissed, the navigation is canceled.
# Step 22.2 of the html spec 7.4.2.2 Beginning navigation.
# https://html.spec.whatwg.org/multipage/browsing-the-web.html#beginning-navigation
with pytest.raises(error.UnknownErrorException):
await wait_for_future_safe(navigated_future)

contexts = await bidi_session.browsing_context.get_tree(
root=new_tab["context"], max_depth=0
)
assert contexts[0]["url"] != page_target


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
@pytest.mark.parametrize("type_hint", ["tab", "window"])
async def test_two_top_level_contexts(
bidi_session,
Expand Down Expand Up @@ -201,6 +208,7 @@ async def test_two_top_level_contexts(
await bidi_session.browsing_context.close(context=new_context["context"])


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
async def test_multiple_frames(
bidi_session,
new_tab,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
USER_PROMPT_OPENED_EVENT = "browsingContext.userPromptOpened"


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
@pytest.mark.parametrize("accept", [False, True])
async def test_beforeunload(
bidi_session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
USER_PROMPT_OPENED_EVENT = "browsingContext.userPromptOpened"


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
async def test_unsubscribe(
bidi_session, inline, new_tab, wait_for_event, wait_for_future_safe
):
Expand Down Expand Up @@ -45,6 +46,7 @@ async def on_event(method, data):
remove_listener()


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
async def test_prompt_type_alert(
bidi_session,
subscribe_events,
Expand Down Expand Up @@ -78,6 +80,7 @@ async def test_prompt_type_alert(
}


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
@pytest.mark.parametrize("accept", [True, False])
async def test_prompt_type_confirm(
bidi_session,
Expand Down Expand Up @@ -115,6 +118,7 @@ async def test_prompt_type_confirm(
}


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
@pytest.mark.parametrize("accept", [True, False])
async def test_prompt_type_prompt(
bidi_session,
Expand Down Expand Up @@ -161,6 +165,7 @@ async def test_prompt_type_prompt(
}


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
async def test_prompt_with_defaults(
bidi_session,
subscribe_events,
Expand Down Expand Up @@ -194,6 +199,7 @@ async def test_prompt_with_defaults(
}


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
@pytest.mark.parametrize("type_hint", ["tab", "window"])
async def test_subscribe_to_one_context(
bidi_session,
Expand Down Expand Up @@ -273,6 +279,7 @@ async def on_event(method, data):
await bidi_session.browsing_context.close(context=another_new_context["context"])


@pytest.mark.capabilities({"unhandledPromptBehavior": {'default': 'ignore'}})
async def test_iframe(
bidi_session,
new_tab,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async def test_prompt_type(
"context": new_tab["context"],
"type": prompt_type,
"message": text,
"handler": "dismiss",
**({"defaultValue": ""} if prompt_type == "prompt" else {}),
}

Expand Down Expand Up @@ -95,19 +96,14 @@ async def test_prompt_default_value(

event = await wait_for_future_safe(on_entry)

expected_event = {
assert event == {
"context": new_tab["context"],
"type": "prompt",
"message": text,
"handler": "dismiss",
"defaultValue": default if default is not None else ""
}

if default is None:
expected_event["defaultValue"] = ""
else:
expected_event["defaultValue"] = default

assert event == expected_event


@pytest.mark.parametrize("type_hint", ["tab", "window"])
async def test_subscribe_to_one_context(
Expand Down Expand Up @@ -160,6 +156,7 @@ async def on_event(method, data):
assert event == {
"context": new_context["context"],
"type": "alert",
"handler": "dismiss",
"message": "first tab",
}

Expand Down Expand Up @@ -202,5 +199,6 @@ async def test_iframe(
assert event == {
"context": new_tab["context"],
"type": "alert",
"handler": "dismiss",
"message": "in iframe",
}