Bug 1392274 - [wdspec] Add tests for Forward navigation command. draft
authorHenrik Skupin <mail@hskupin.info>
Fri, 06 Jul 2018 13:54:36 +0200
changeset 822933 7967dad337085697759e2cc4c3ec295f274c2677
parent 821963 1e5fa52a612e8985e12212d1950a732954e00e45
child 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 Forward navigation command. MozReview-Commit-ID: 3GzaN91ihDr
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webdriver/tests/forward/conftest.py
testing/web-platform/tests/webdriver/tests/forward/forward.py
testing/web-platform/tests/webdriver/tests/forward/user_prompts.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -184506,16 +184506,28 @@
       [
        "/svg/linking/reftests/use-descendant-combinator-ref.html",
        "=="
       ]
      ],
      {}
     ]
    ],
+   "svg/linking/reftests/use-descendant-combinator-003.html": [
+    [
+     "/svg/linking/reftests/use-descendant-combinator-003.html",
+     [
+      [
+       "/svg/linking/reftests/use-descendant-combinator-ref.html",
+       "=="
+      ]
+     ],
+     {}
+    ]
+   ],
    "svg/painting/currentColor-override-pserver-fallback.svg": [
     [
      "/svg/painting/currentColor-override-pserver-fallback.svg",
      [
       [
        "/svg/painting/currentColor-override-pserver-fallback-ref.svg",
        "=="
       ]
@@ -184542,28 +184554,16 @@
       [
        "/svg/painting/currentColor-override-pserver-stroke-ref.svg",
        "=="
       ]
      ],
      {}
     ]
    ],
-   "svg/linking/reftests/use-descendant-combinator-003.html": [
-    [
-     "/svg/linking/reftests/use-descendant-combinator-003.html",
-     [
-      [
-       "/svg/linking/reftests/use-descendant-combinator-ref.html",
-       "=="
-      ]
-     ],
-     {}
-    ]
-   ],
    "svg/painting/reftests/paint-context-001.svg": [
     [
      "/svg/painting/reftests/paint-context-001.svg",
      [
       [
        "/svg/painting/reftests/paint-context-001-ref.svg",
        "=="
       ]
@@ -297971,16 +297971,21 @@
      {}
     ]
    ],
    "webdriver/tests/forward/__init__.py": [
     [
      {}
     ]
    ],
+   "webdriver/tests/forward/conftest.py": [
+    [
+     {}
+    ]
+   ],
    "webdriver/tests/fullscreen_window/__init__.py": [
     [
      {}
     ]
    ],
    "webdriver/tests/get_active_element/__init__.py": [
     [
      {}
@@ -408249,16 +408254,24 @@
     ]
    ],
    "webdriver/tests/forward/forward.py": [
     [
      "/webdriver/tests/forward/forward.py",
      {}
     ]
    ],
+   "webdriver/tests/forward/user_prompts.py": [
+    [
+     "/webdriver/tests/forward/user_prompts.py",
+     {
+      "timeout": "long"
+     }
+    ]
+   ],
    "webdriver/tests/fullscreen_window/fullscreen.py": [
     [
      "/webdriver/tests/fullscreen_window/fullscreen.py",
      {}
     ]
    ],
    "webdriver/tests/fullscreen_window/user_prompts.py": [
     [
@@ -439003,17 +439016,17 @@
    "ff8d1c26701d15164bcb549d42937825e1f0edd0",
    "testharness"
   ],
   "content-security-policy/securitypolicyviolation/idl.html": [
    "266180135d8167bc47d6c7a73798e87aa1082bee",
    "testharness"
   ],
   "content-security-policy/securitypolicyviolation/img-src-redirect-upgrade-reporting.https.html": [
-   "e338e94ea726419db64ed5b98c95b862c394409e",
+   "f6623c80b2b4be3fd9dd0f5dc0a6417652f1b797",
    "testharness"
   ],
   "content-security-policy/securitypolicyviolation/img-src-redirect-upgrade-reporting.https.html.headers": [
    "960ee8a9f7ccf33ea435890e2eae0e68399f32ed",
    "support"
   ],
   "content-security-policy/securitypolicyviolation/inside-dedicated-worker.html": [
    "46d18c97d554716b714856c00bdc49388d211868",
@@ -439055,17 +439068,17 @@
    "b2d6d11fc189d78f5ea623c52e1d1f64fe53a772",
    "testharness"
   ],
   "content-security-policy/securitypolicyviolation/style-sample.html": [
    "e570217f560f6e7a8917e79266ac9d2e8ea078f6",
    "testharness"
   ],
   "content-security-policy/securitypolicyviolation/support/inside-worker.sub.js": [
-   "f425a7ae6c167bfe9857f08f460897e16bf6ca95",
+   "d94662579190653a3b3e9d076b79d7b0f01f2dc7",
    "support"
   ],
   "content-security-policy/securitypolicyviolation/support/inside-worker.sub.js.headers": [
    "ac19897e2693ba3228640d03c770cd5a33c51381",
    "support"
   ],
   "content-security-policy/securitypolicyviolation/support/testharness-helper.sub.js": [
    "71244cc74fa8f8ee8082c876264e053348905fbd",
@@ -619078,16 +619091,20 @@
   "svg/linking/reftests/use-descendant-combinator-001.html": [
    "323fde648ee2d065bfd945a2c4d5be86f1c308ff",
    "reftest"
   ],
   "svg/linking/reftests/use-descendant-combinator-002.html": [
    "3d51ca0fc007d52147e7ea03493cac7ee1bb7903",
    "reftest"
   ],
+  "svg/linking/reftests/use-descendant-combinator-003.html": [
+   "d9155d3b92ecf0735f82ed9a0f2a8fd3fc380d55",
+   "reftest"
+  ],
   "svg/linking/reftests/use-descendant-combinator-ref.html": [
    "fb8aec792684b97151d2964b85d1e70829e141ad",
    "support"
   ],
   "svg/linking/scripted/href-animate-element.html": [
    "c224f6b609079f31c256625417e4677b21b5f71a",
    "testharness"
   ],
@@ -622183,17 +622200,17 @@
    "c95130e1f0226d18fcdd9dc9d5795395d6de586f",
    "support"
   ],
   "webaudio/README.md": [
    "230684ec60fd2e408f9b6014417f3eddfe2dc95a",
    "support"
   ],
   "webaudio/historical.html": [
-   "93068df297042344669093ce899f0230c87ebf54",
+   "c6e3c7d6751731c708edfb0f4e32df8a6a3b80b0",
    "testharness"
   ],
   "webaudio/idlharness.https.html": [
    "0403de985b3346240ba1d4b465a8e0838f3860bc",
    "testharness"
   ],
   "webaudio/js/buffer-loader.js": [
    "4d564eae0b3d7d1045626d1f144cd2638dba64e5",
@@ -623482,18 +623499,26 @@
   "webdriver/tests/find_elements_from_element/find.py": [
    "2daef29773c98649b04e3d6e97380ba569ec045d",
    "wdspec"
   ],
   "webdriver/tests/forward/__init__.py": [
    "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "support"
   ],
+  "webdriver/tests/forward/conftest.py": [
+   "a15c7372ba9d459ddcc4b5cf4030eb32406b60cf",
+   "support"
+  ],
   "webdriver/tests/forward/forward.py": [
-   "558f686e715eab83f2979c4ac772472b7eb91432",
+   "ddc7153767994ff6136bfda3d7b5f15265c0310c",
+   "wdspec"
+  ],
+  "webdriver/tests/forward/user_prompts.py": [
+   "df9a47a6fd51cd1e57b676054c9da029cd67178a",
    "wdspec"
   ],
   "webdriver/tests/fullscreen_window/__init__.py": [
    "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "support"
   ],
   "webdriver/tests/fullscreen_window/fullscreen.py": [
    "8a6e06b2fbd2ec80326ab1145e6ddfb35c6995b4",
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/forward/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
--- a/testing/web-platform/tests/webdriver/tests/forward/forward.py
+++ b/testing/web-platform/tests/webdriver/tests/forward/forward.py
@@ -1,17 +1,133 @@
+from tests.support.asserts import assert_error, assert_success
 from tests.support.inline import inline
-from tests.support.asserts import assert_success
 
 
 def forward(session):
     return session.transport.send(
         "POST", "session/{session_id}/forward".format(**vars(session)))
 
 
 def test_null_response_value(session):
     session.url = inline("<div>")
     session.url = inline("<p>")
     session.back()
 
     response = forward(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 = forward(session)
+    assert_error(response, "no such window")
+
+
+def test_no_browsing_history(session):
+    url = inline("<div id=foo>")
+
+    session.url = url
+    element = session.find.css("#foo", all=False)
+
+    response = forward(session)
+    assert_success(response)
+
+    assert session.url == url
+    assert element.property("id") == "foo"
+
+
+def test_data_urls(session):
+    test_pages = [
+        inline("<p id=1>"),
+        inline("<p id=2>"),
+    ]
+
+    for page in test_pages:
+        session.url = page
+
+    session.back()
+    assert session.url == test_pages[0]
+
+    response = forward(session)
+    assert_success(response)
+    assert session.url == test_pages[1]
+
+
+def test_dismissed_beforeunload(session):
+    url_beforeunload = inline("""
+      <input type="text">
+      <script>
+        window.addEventListener("beforeunload", function (event) {
+          event.preventDefault();
+        });
+      </script>
+    """)
+
+    session.url = url_beforeunload
+    session.url = inline("<div id=foo>")
+    session.back()
+
+    element = session.find.css("input", all=False)
+    element.send_keys("bar")
+
+    response = forward(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
+
+    session.back()
+    assert session.url == test_pages[1]
+
+    session.back()
+    assert session.url == test_pages[0]
+
+    response = forward(session)
+    assert_success(response)
+    assert session.url == test_pages[1]
+
+    response = forward(session)
+    assert_success(response)
+    assert session.url == test_pages[2]
+
+
+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.back()
+    assert session.url == pushstate_page
+    assert session.execute_script("return history.state;") is None
+
+    response = forward(session)
+    assert_success(response)
+
+    assert session.url == "{}#pushstate".format(pushstate_page)
+    assert session.execute_script("return history.state;") == {"foo": "bar"}
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/forward/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 forward(session):
+    return session.transport.send(
+        "POST", "session/{session_id}/forward".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 = forward(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 = forward(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 = forward(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 = forward(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 = forward(session)
+    assert_error(response, "unexpected alert open")
+
+    assert_dialog_handled(session, expected_text="dialog")