Bug 1455282 - [wdspec] Add tests for Close Window command. draft
authorHenrik Skupin <mail@hskupin.info>
Fri, 20 Apr 2018 10:50:14 +0200
changeset 785521 1eeb2128a0981b852ddc6e655b5e0d17870306ff
parent 785511 679084c3a88c283a8d5494f3d9e998a9a399b7fc
push id107244
push userbmo:hskupin@gmail.com
push dateFri, 20 Apr 2018 09:17:50 +0000
bugs1455282
milestone61.0a1
Bug 1455282 - [wdspec] Add tests for Close Window command. MozReview-Commit-ID: 13j69lZhr1G
testing/web-platform/meta/MANIFEST.json
testing/web-platform/meta/webdriver/tests/close_window/prompts.py.ini
testing/web-platform/tests/webdriver/tests/close_window/close.py
testing/web-platform/tests/webdriver/tests/close_window/prompts.py
testing/web-platform/tests/webdriver/tests/support/fixtures.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -393324,16 +393324,28 @@
    "webdriver/tests/actions/special_keys.py": [
     [
      "/webdriver/tests/actions/special_keys.py",
      {
       "timeout": "long"
      }
     ]
    ],
+   "webdriver/tests/close_window/close.py": [
+    [
+     "/webdriver/tests/close_window/close.py",
+     {}
+    ]
+   ],
+   "webdriver/tests/close_window/prompts.py": [
+    [
+     "/webdriver/tests/close_window/prompts.py",
+     {}
+    ]
+   ],
    "webdriver/tests/contexts/json_serialize_windowproxy.py": [
     [
      "/webdriver/tests/contexts/json_serialize_windowproxy.py",
      {
       "timeout": "long"
      }
     ]
    ],
@@ -605695,16 +605707,24 @@
   "webdriver/tests/actions/support/refine.py": [
    "0d244bffe67ef57be68aad99f1cbc7440ff80e27",
    "support"
   ],
   "webdriver/tests/actions/support/test_actions_wdspec.html": [
    "95203777fcc012ab64465287737a89a4ba2c31dc",
    "support"
   ],
+  "webdriver/tests/close_window/close.py": [
+   "8142739fffb19e69fb5bb017f7843032a92203c0",
+   "wdspec"
+  ],
+  "webdriver/tests/close_window/prompts.py": [
+   "bbe3f014b668703209d8be4798c72d580b82aeac",
+   "wdspec"
+  ],
   "webdriver/tests/conftest.py": [
    "c812269d034c9ca1b8c4f136dd5d0cea52f4d0f0",
    "support"
   ],
   "webdriver/tests/contexts/json_serialize_windowproxy.py": [
    "d29c82c48b3bd1e2b07c40798a774eb77d6178a5",
    "wdspec"
   ],
@@ -605928,17 +605948,17 @@
    "5a31a3917a5157516c10951a3b3d5ffb43b992d9",
    "support"
   ],
   "webdriver/tests/support/asserts.py": [
    "1b839404daaca1d059cba98377edb91691ef7e82",
    "support"
   ],
   "webdriver/tests/support/fixtures.py": [
-   "e787c0ef06fcdfc86f337be5af61e492be08ec9c",
+   "126e82c42568c9ecb240e735a2b1361882ecd9ba",
    "support"
   ],
   "webdriver/tests/support/http_request.py": [
    "cb40c781fea2280b98135522def5e6a116d7b946",
    "support"
   ],
   "webdriver/tests/support/inline.py": [
    "ffabd6a12d6e7928176fa00702214e0c8e0a25d7",
@@ -606096,17 +606116,17 @@
    "d870e4e7ca81044bd62ddbf79fb666d02bc5b9ee",
    "support"
   ],
   "webmessaging/broadcastchannel/sandbox.html": [
    "9eeb2cbdcf50727280da1de83f665c6041b7741c",
    "testharness"
   ],
   "webmessaging/broadcastchannel/workers.html": [
-   "483e03e9528f1e80fc1b250caee46f7f256d63c1",
+   "2ca289f36c001c15e64b849098e8f28b21178862",
    "testharness"
   ],
   "webmessaging/event.data.sub.htm": [
    "994c26d63d21f6acabc9e5c2af667e1d557040b3",
    "testharness"
   ],
   "webmessaging/event.origin.sub.htm": [
    "591a0bcef635d7158fe9c04fabfeea030dce9c62",
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/webdriver/tests/close_window/prompts.py.ini
@@ -0,0 +1,3 @@
+[prompts.py]
+  [test_handle_prompt_accept]
+    expected: FAIL
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/close_window/close.py
@@ -0,0 +1,39 @@
+from tests.support.asserts import assert_error, assert_success
+
+
+def close(session):
+    return session.transport.send("DELETE", "session/%s/window" % session.session_id)
+
+
+def tst_top_level_browsing_context_no_longer_open(session, create_window):
+    new_handle = create_window()
+
+    session.window_handle = new_handle
+    session.close()
+    assert new_handle not in session.handles
+
+    response = close(session)
+    assert_error(response, "no such window")
+
+
+def tst_close_top_level_browsing_context(session, create_window):
+    handles = session.handles
+
+    new_handle = create_window()
+    session.window_handle = new_handle
+
+    response = close(session)
+    value = assert_success(response)
+    assert new_handle not in value
+    assert session.handles == handles
+
+
+def test_close_last_top_level_browsing_context(session):
+    assert len(session.handles) == 1
+    response = close(session)
+
+    value = assert_success(response)
+    assert value == []
+
+    # With no more open top-level browsing contexts, the session is closed.
+    session.session_id = None
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/close_window/prompts.py
@@ -0,0 +1,105 @@
+from tests.support.asserts import assert_error, assert_dialog_handled
+from tests.support.fixtures import create_dialog, create_window
+from tests.support.inline import inline
+
+
+def close(session):
+    return session.transport.send("DELETE", "session/%s/window" % session.session_id)
+
+
+def test_handle_prompt_dismiss_and_notify():
+    """TODO"""
+
+
+def test_handle_prompt_accept_and_notify():
+    """TODO"""
+
+
+def test_handle_prompt_ignore():
+    """TODO"""
+
+
+def test_handle_prompt_accept(new_session, add_browser_capabilites):
+    """
+    3. Handle any user prompts and return its value if it is an error.
+
+    [...]
+
+    In order to handle any user prompts a remote end must take the
+    following steps:
+
+      [...]
+
+      2. Perform the following substeps based on the current session's
+      user prompt handler:
+
+        [...]
+
+        - accept state
+           Accept the current user prompt.
+
+    """
+    _, session = new_session({"capabilities": {
+        "alwaysMatch": add_browser_capabilites({"unhandledPromptBehavior": "accept"})}})
+    session.window_handle = create_window(session)()
+
+    session.url = inline("<title>WD doc title</title>")
+
+    create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
+    response = close(session)
+    assert response.status == 200
+    assert_dialog_handled(session, "dismiss #1")
+
+    create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
+    response = close(session)
+    assert response.status == 200
+    assert_dialog_handled(session, "dismiss #2")
+
+    create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
+    response = close(session)
+    assert response.status == 200
+    assert_dialog_handled(session, "dismiss #3")
+
+
+def test_handle_prompt_missing_value(session, create_dialog, create_window):
+    """
+    3. Handle any user prompts and return its value if it is an error.
+
+    [...]
+
+    In order to handle any user prompts a remote end must take the
+    following steps:
+
+      [...]
+
+      2. Perform the following substeps based on the current session's
+      user prompt handler:
+
+        [...]
+
+        - missing value default state
+           1. Dismiss the current user prompt.
+           2. Return error with error code unexpected alert open.
+
+    """
+    session.window_handle = create_window()
+
+    session.url = inline("<title>WD doc title</title>")
+    create_dialog("alert", text="dismiss #1", result_var="dismiss1")
+
+    response = close(session)
+
+    assert_error(response, "unexpected alert open")
+    assert_dialog_handled(session, "dismiss #1")
+
+    create_dialog("confirm", text="dismiss #2", result_var="dismiss2")
+
+    response = close(session)
+    assert_error(response, "unexpected alert open")
+    assert_dialog_handled(session, "dismiss #2")
+
+    create_dialog("prompt", text="dismiss #3", result_var="dismiss3")
+
+    response = close(session)
+    assert_error(response, "unexpected alert open")
+    assert_dialog_handled(session, "dismiss #3")
--- a/testing/web-platform/tests/webdriver/tests/support/fixtures.py
+++ b/testing/web-platform/tests/webdriver/tests/support/fixtures.py
@@ -71,16 +71,17 @@ def _restore_windows(session):
     for window in _windows(session, exclude=[current_window]):
         session.window_handle = window
         if len(session.handles) > 1:
             session.close()
 
     session.window_handle = current_window
 
 
+@ignore_exceptions
 def _switch_to_top_level_browsing_context(session):
     """If the current browsing context selected by WebDriver is a
     `<frame>` or an `<iframe>`, switch it back to the top-level
     browsing context.
     """
     session.switch_frame(None)