Bug 1392274 - [wdspec] Add tests for Refresh navigation command.
MozReview-Commit-ID: 4AOSJNvMPkG
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -408483,16 +408483,24 @@
]
],
"webdriver/tests/refresh/refresh.py": [
[
"/webdriver/tests/refresh/refresh.py",
{}
]
],
+ "webdriver/tests/refresh/user_prompts.py": [
+ [
+ "/webdriver/tests/refresh/user_prompts.py",
+ {
+ "timeout": "long"
+ }
+ ]
+ ],
"webdriver/tests/send_alert_text/send.py": [
[
"/webdriver/tests/send_alert_text/send.py",
{}
]
],
"webdriver/tests/set_timeouts/set.py": [
[
@@ -623749,17 +623757,21 @@
"f5e96dee33de36e3626c3e9bbfdd0014b27c305c",
"wdspec"
],
"webdriver/tests/refresh/__init__.py": [
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"support"
],
"webdriver/tests/refresh/refresh.py": [
- "15f800f47dcc793325dbd920b8253648072503cd",
+ "0a4ce17f3e167e0d45413c383a954923f6c8ce05",
+ "wdspec"
+ ],
+ "webdriver/tests/refresh/user_prompts.py": [
+ "ac2edca6cf7abe32e028c4ef101d3953768560ae",
"wdspec"
],
"webdriver/tests/send_alert_text/__init__.py": [
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"support"
],
"webdriver/tests/send_alert_text/send.py": [
"97c85c87bad0a09ec0ac97fb978e049e1b320283",
--- a/testing/web-platform/tests/webdriver/tests/refresh/refresh.py
+++ b/testing/web-platform/tests/webdriver/tests/refresh/refresh.py
@@ -1,15 +1,115 @@
+import pytest
+
+from webdriver.error import NoSuchElementException, StaleElementReferenceException
+
from tests.support.inline import inline
-from tests.support.asserts import assert_success
+from tests.support.asserts import assert_error, assert_success
def refresh(session):
return session.transport.send(
"POST", "session/{session_id}/refresh".format(**vars(session)))
def test_null_response_value(session):
session.url = inline("<div>")
response = refresh(session)
value = assert_success(response)
assert value is None
+
+
+def test_no_browsing_context(session, create_window):
+ new_handle = create_window()
+
+ session.window_handle = new_handle
+ session.close()
+ assert new_handle not in session.handles
+
+ result = refresh(session)
+
+ assert_error(result, "no such window")
+
+
+def test_basic(session):
+ url = inline("<div id=foo>")
+
+ session.url = url
+ element = session.find.css("#foo", all=False)
+
+ response = refresh(session)
+ assert_success(response)
+
+ with pytest.raises(StaleElementReferenceException):
+ element.property("id")
+
+ assert session.url == url
+ assert session.find.css("#foo", all=False)
+
+
+def test_dismissed_beforeunload(session):
+ url_beforeunload = inline("""
+ <input type="text">
+ <script>
+ window.addEventListener("beforeunload", function (event) {
+ event.preventDefault();
+ });
+ </script>
+ """)
+
+ session.url = url_beforeunload
+ element = session.find.css("input", all=False)
+ element.send_keys("bar")
+
+ response = refresh(session)
+ assert_success(response)
+
+ with pytest.raises(StaleElementReferenceException):
+ element.property("id")
+
+ session.find.css("input", all=False)
+
+
+def test_history_pushstate(session, url):
+ pushstate_page = inline("""
+ <script>
+ function pushState() {
+ history.pushState({foo: "bar"}, "", "#pushstate");
+ }
+ </script>
+ <a onclick="javascript:pushState();">click</a>
+ """)
+
+ session.url = pushstate_page
+
+ session.find.css("a", all=False).click()
+ assert session.url == "{}#pushstate".format(pushstate_page)
+ assert session.execute_script("return history.state;") == {"foo": "bar"}
+
+ session.execute_script("""
+ let elem = window.document.createElement('div');
+ window.document.body.appendChild(elem);
+ """)
+ element = session.find.css("div", all=False)
+
+ response = refresh(session)
+ assert_success(response)
+
+ assert session.url == "{}#pushstate".format(pushstate_page)
+ assert session.execute_script("return history.state;") == {"foo": "bar"}
+
+ with pytest.raises(StaleElementReferenceException):
+ element.property("id")
+
+
+def test_refresh_switches_to_parent_browsing_context(session, create_frame):
+ session.url = inline("<div id=foo>")
+
+ session.switch_frame(create_frame())
+ with pytest.raises(NoSuchElementException):
+ session.find.css("#foo", all=False)
+
+ response = refresh(session)
+ assert_success(response)
+
+ session.find.css("#foo", all=False)
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/refresh/user_prompts.py
@@ -0,0 +1,68 @@
+# META: timeout=long
+
+import pytest
+
+from tests.support.asserts import assert_dialog_handled, assert_error, assert_success
+
+
+def refresh(session):
+ return session.transport.send(
+ "POST", "session/{session_id}/refresh".format(**vars(session)))
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_handle_prompt_accept(session, create_dialog, dialog_type):
+ create_dialog(dialog_type, text="dialog")
+
+ response = refresh(session)
+ assert_success(response)
+
+ assert_dialog_handled(session, expected_text="dialog")
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_handle_prompt_accept_and_notify(session, create_dialog, dialog_type):
+ create_dialog(dialog_type, text="dialog")
+
+ response = refresh(session)
+ assert_error(response, "unexpected alert open")
+
+ assert_dialog_handled(session, expected_text="dialog")
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_handle_prompt_dismiss(session, create_dialog, dialog_type):
+ create_dialog(dialog_type, text="dialog")
+
+ response = refresh(session)
+ assert_success(response)
+
+ assert_dialog_handled(session, expected_text="dialog")
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_handle_prompt_dissmiss_and_notify(session, create_dialog, dialog_type):
+ create_dialog(dialog_type, text="dialog")
+
+ response = refresh(session)
+ assert_error(response, "unexpected alert open")
+
+ assert_dialog_handled(session, expected_text="dialog")
+
+
+def test_handle_prompt_ignore():
+ """TODO"""
+
+
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_handle_prompt_default(session, create_dialog, dialog_type):
+ create_dialog(dialog_type, text="dialog")
+
+ response = refresh(session)
+ assert_error(response, "unexpected alert open")
+
+ assert_dialog_handled(session, expected_text="dialog")