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

fix: support default for BeforeUnload prompt #2412

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/bidiMapper/modules/context/BrowsingContextImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ export class BrowsingContextImpl {
case BrowsingContext.UserPromptType.Beforeunload:
return (
this.#unhandledPromptBehavior?.beforeUnload ??
this.#unhandledPromptBehavior?.default ??
// In WebDriver Classic spec, `beforeUnload` prompt should be accepted by
sadym-chromium marked this conversation as resolved.
Show resolved Hide resolved
// default. Step 4 of "Get the prompt handler" algorithm
// (https://w3c.github.io/webdriver/#dfn-get-the-prompt-handler):
Expand Down
91 changes: 51 additions & 40 deletions tests/browsing_context/test_user_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
'default': 'accept'
}
}],
indirect=True)
indirect=True)
async def test_browsingContext_userPromptOpened_capabilityRespected(
websocket, context_id, prompt_type, capabilities):
await subscribe(websocket, [
Expand Down Expand Up @@ -165,45 +165,47 @@ async def test_browsingContext_userPromptOpened_capabilityRespected(


@pytest.mark.asyncio
@pytest.mark.parametrize('capabilities', [{}, {
'unhandledPromptBehavior': 'dismiss'
}, {
'unhandledPromptBehavior': 'dismiss and notify'
}, {
'unhandledPromptBehavior': {
'default': 'dismiss'
}
}, {
'unhandledPromptBehavior': {
'beforeUnload': 'dismiss',
'default': 'ignore'
}
}, {
'unhandledPromptBehavior': 'accept'
}, {
'unhandledPromptBehavior': 'accept and notify'
}, {
'unhandledPromptBehavior': {
'default': 'accept'
}
}, {
'unhandledPromptBehavior': {
'beforeUnload': 'accept',
'default': 'ignore'
}
}, {
'unhandledPromptBehavior': 'ignore'
}, {
'unhandledPromptBehavior': {
'default': 'ignore'
}
}, {
'unhandledPromptBehavior': {
'beforeUnload': 'ignore',
'default': 'accept'
}
}],
indirect=True)
@pytest.mark.parametrize('capabilities', [
{},
{
'unhandledPromptBehavior': 'dismiss'
}, {
'unhandledPromptBehavior': 'dismiss and notify'
}, {
'unhandledPromptBehavior': {
'default': 'dismiss'
}
}, {
'unhandledPromptBehavior': {
'beforeUnload': 'dismiss',
'default': 'ignore'
}
}, {
'unhandledPromptBehavior': 'accept'
}, {
'unhandledPromptBehavior': 'accept and notify'
}, {
'unhandledPromptBehavior': {
'default': 'accept'
}
}, {
'unhandledPromptBehavior': {
'beforeUnload': 'accept',
'default': 'ignore'
}
}, {
'unhandledPromptBehavior': 'ignore'
}, {
'unhandledPromptBehavior': {
'default': 'ignore'
}
}, {
'unhandledPromptBehavior': {
'beforeUnload': 'ignore',
'default': 'accept'
}
}],
indirect=True)
async def test_browsingContext_beforeUnloadPromptOpened_capabilityRespected(
websocket, context_id, html, capabilities):
await subscribe(websocket, ["browsingContext.userPromptOpened"])
Expand Down Expand Up @@ -249,6 +251,15 @@ async def test_browsingContext_beforeUnloadPromptOpened_capabilityRespected(
if 'beforeUnload' in capabilities['unhandledPromptBehavior']:
expected_handler = capabilities['unhandledPromptBehavior'][
'beforeUnload']
elif 'default' in capabilities['unhandledPromptBehavior']:
expected_handler = capabilities['unhandledPromptBehavior'][
'default']
if isinstance(capabilities['unhandledPromptBehavior'], str):
match capabilities['unhandledPromptBehavior']:
case 'dismiss' | 'dismiss and notify':
expected_handler = 'dismiss'
case 'ignore':
expected_handler = 'ignore'

resp = await read_JSON_message(websocket)
assert resp == {
Expand Down
Loading