Bug 1392274 - [wdspec] Add tests for Refresh navigation command. draft
authorHenrik Skupin <mail@hskupin.info>
Fri, 06 Jul 2018 13:55:39 +0200
changeset 822935 138cd9ce0ef93d84819cc5c15f5dc02d007901a4
parent 822934 a05459402e6a3a5c1742a3691186c9f896b5037d
push id117536
push userbmo:hskupin@gmail.com
push dateThu, 26 Jul 2018 12:36:51 +0000
bugs1392274
milestone63.0a1
Bug 1392274 - [wdspec] Add tests for Refresh navigation command. MozReview-Commit-ID: 4AOSJNvMPkG
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webdriver/tests/refresh/refresh.py
testing/web-platform/tests/webdriver/tests/refresh/user_prompts.py
--- 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")