diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json
index 6aea24aecaa1..eb9884000246 100644
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -298090,6 +298090,11 @@
{}
]
],
+ "webdriver/tests/back/conftest.py": [
+ [
+ {}
+ ]
+ ],
"webdriver/tests/close_window/__init__.py": [
[
{}
@@ -408620,6 +408625,14 @@
{}
]
],
+ "webdriver/tests/back/user_prompts.py": [
+ [
+ "/webdriver/tests/back/user_prompts.py",
+ {
+ "timeout": "long"
+ }
+ ]
+ ],
"webdriver/tests/close_window/close.py": [
[
"/webdriver/tests/close_window/close.py",
@@ -624138,7 +624151,15 @@
"support"
],
"webdriver/tests/back/back.py": [
- "0df671f059b0b9064a6a8608163b46042524f7e7",
+ "ae4209c3f47af5e13c0851f73ad3d1f788b7ed56",
+ "wdspec"
+ ],
+ "webdriver/tests/back/conftest.py": [
+ "a15c7372ba9d459ddcc4b5cf4030eb32406b60cf",
+ "support"
+ ],
+ "webdriver/tests/back/user_prompts.py": [
+ "53944b4a302d2e1c5cde4e48ff451452d699f7f6",
"wdspec"
],
"webdriver/tests/close_window/__init__.py": [
diff --git a/testing/web-platform/tests/webdriver/tests/back/back.py b/testing/web-platform/tests/webdriver/tests/back/back.py
index bbb353697a45..0ecfccc193c6 100644
--- a/testing/web-platform/tests/webdriver/tests/back/back.py
+++ b/testing/web-platform/tests/webdriver/tests/back/back.py
@@ -1,5 +1,5 @@
from tests.support.inline import inline
-from tests.support.asserts import assert_success
+from tests.support.asserts import assert_error, assert_success
def back(session):
@@ -14,3 +14,99 @@ def test_null_response_value(session):
response = back(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
+
+ response = back(session)
+ assert_error(response, "no such window")
+
+
+def test_no_browsing_history(session):
+ response = back(session)
+ assert_success(response)
+
+
+def test_data_urls(session):
+ test_pages = [
+ inline("
"),
+ inline("
"),
+ ]
+
+ for page in test_pages:
+ session.url = page
+ assert session.url == test_pages[1]
+
+ response = back(session)
+ assert_success(response)
+ assert session.url == test_pages[0]
+
+
+def test_dismissed_beforeunload(session):
+ url_beforeunload = inline("""
+
+
+ """)
+
+ session.url = inline("
")
+ session.url = url_beforeunload
+
+ element = session.find.css("input", all=False)
+ element.send_keys("bar")
+
+ response = back(session)
+ assert_success(response)
+
+ assert session.url != url_beforeunload
+
+
+def test_fragments(session, url):
+ test_pages = [
+ url("/common/blank.html"),
+ url("/common/blank.html#1234"),
+ url("/common/blank.html#5678"),
+ ]
+
+ for page in test_pages:
+ session.url = page
+ assert session.url == test_pages[2]
+
+ response = back(session)
+ assert_success(response)
+ assert session.url == test_pages[1]
+
+ response = back(session)
+ assert_success(response)
+ assert session.url == test_pages[0]
+
+
+def test_history_pushstate(session, url):
+ pushstate_page = inline("""
+
+
click
+ """)
+
+ 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"}
+
+ response = back(session)
+ assert_success(response)
+
+ assert session.url == pushstate_page
+ assert session.execute_script("return history.state;") is None
diff --git a/testing/web-platform/tests/webdriver/tests/back/conftest.py b/testing/web-platform/tests/webdriver/tests/back/conftest.py
new file mode 100644
index 000000000000..d5fd320a696a
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/back/conftest.py
@@ -0,0 +1,19 @@
+import pytest
+
+from webdriver.error import NoSuchWindowException
+
+
+@pytest.fixture(name="session")
+def fixture_session(capabilities, session, create_window):
+ """Prevent re-using existent history by running the test in a new window."""
+ original_handle = session.window_handle
+ session.window_handle = create_window()
+
+ yield session
+
+ try:
+ session.close()
+ except NoSuchWindowException:
+ pass
+
+ session.window_handle = original_handle
diff --git a/testing/web-platform/tests/webdriver/tests/back/user_prompts.py b/testing/web-platform/tests/webdriver/tests/back/user_prompts.py
new file mode 100644
index 000000000000..0aefe46284f2
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/back/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 back(session):
+ return session.transport.send(
+ "POST", "session/{session_id}/back".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 = back(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 = back(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 = back(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 = back(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 = back(session)
+ assert_error(response, "unexpected alert open")
+
+ assert_dialog_handled(session, expected_text="dialog")