|
| 1 | +# META: timeout=long |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from tests.support.asserts import assert_dialog_handled, assert_error, assert_png, assert_success |
| 6 | +from tests.support.inline import inline |
| 7 | + |
| 8 | +from . import take_full_page_screenshot |
| 9 | + |
| 10 | +@pytest.fixture |
| 11 | +def check_user_prompt_closed_without_exception(session, create_dialog): |
| 12 | + def check_user_prompt_closed_without_exception(dialog_type, retval): |
| 13 | + session.url = inline("<input/>") |
| 14 | + |
| 15 | + create_dialog(dialog_type, text=dialog_type) |
| 16 | + |
| 17 | + response = take_full_page_screenshot(session) |
| 18 | + value = assert_success(response) |
| 19 | + |
| 20 | + assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval) |
| 21 | + |
| 22 | + assert_png(value) |
| 23 | + |
| 24 | + return check_user_prompt_closed_without_exception |
| 25 | + |
| 26 | + |
| 27 | +@pytest.fixture |
| 28 | +def check_user_prompt_closed_with_exception(session, create_dialog): |
| 29 | + def check_user_prompt_closed_with_exception(dialog_type, retval): |
| 30 | + session.url = inline("<input/>") |
| 31 | + |
| 32 | + create_dialog(dialog_type, text=dialog_type) |
| 33 | + |
| 34 | + response = take_full_page_screenshot(session) |
| 35 | + assert_error(response, "unexpected alert open") |
| 36 | + |
| 37 | + assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval) |
| 38 | + |
| 39 | + return check_user_prompt_closed_with_exception |
| 40 | + |
| 41 | + |
| 42 | +@pytest.fixture |
| 43 | +def check_user_prompt_not_closed_but_exception(session, create_dialog): |
| 44 | + def check_user_prompt_not_closed_but_exception(dialog_type): |
| 45 | + session.url = inline("<input/>") |
| 46 | + |
| 47 | + create_dialog(dialog_type, text=dialog_type) |
| 48 | + |
| 49 | + response = take_full_page_screenshot(session) |
| 50 | + assert_error(response, "unexpected alert open") |
| 51 | + |
| 52 | + assert session.alert.text == dialog_type |
| 53 | + session.alert.dismiss() |
| 54 | + |
| 55 | + return check_user_prompt_not_closed_but_exception |
| 56 | + |
| 57 | + |
| 58 | +@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"}) |
| 59 | +@pytest.mark.parametrize("dialog_type, retval", [ |
| 60 | + ("alert", None), |
| 61 | + ("confirm", True), |
| 62 | + ("prompt", ""), |
| 63 | +]) |
| 64 | +def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval): |
| 65 | + check_user_prompt_closed_without_exception(dialog_type, retval) |
| 66 | + |
| 67 | + |
| 68 | +@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"}) |
| 69 | +@pytest.mark.parametrize("dialog_type, retval", [ |
| 70 | + ("alert", None), |
| 71 | + ("confirm", True), |
| 72 | + ("prompt", ""), |
| 73 | +]) |
| 74 | +def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval): |
| 75 | + check_user_prompt_closed_with_exception(dialog_type, retval) |
| 76 | + |
| 77 | + |
| 78 | +@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"}) |
| 79 | +@pytest.mark.parametrize("dialog_type, retval", [ |
| 80 | + ("alert", None), |
| 81 | + ("confirm", False), |
| 82 | + ("prompt", None), |
| 83 | +]) |
| 84 | +def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval): |
| 85 | + check_user_prompt_closed_without_exception(dialog_type, retval) |
| 86 | + |
| 87 | + |
| 88 | +@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"}) |
| 89 | +@pytest.mark.parametrize("dialog_type, retval", [ |
| 90 | + ("alert", None), |
| 91 | + ("confirm", False), |
| 92 | + ("prompt", None), |
| 93 | +]) |
| 94 | +def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval): |
| 95 | + check_user_prompt_closed_with_exception(dialog_type, retval) |
| 96 | + |
| 97 | + |
| 98 | +@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"}) |
| 99 | +@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"]) |
| 100 | +def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type): |
| 101 | + check_user_prompt_not_closed_but_exception(dialog_type) |
| 102 | + |
| 103 | + |
| 104 | +@pytest.mark.parametrize("dialog_type, retval", [ |
| 105 | + ("alert", None), |
| 106 | + ("confirm", False), |
| 107 | + ("prompt", None), |
| 108 | +]) |
| 109 | +def test_default(check_user_prompt_closed_with_exception, dialog_type, retval): |
| 110 | + check_user_prompt_closed_with_exception(dialog_type, retval) |
0 commit comments