Bug 1405325 - Align WebDriver:DeleteCookie with specification. r=maja_zf, a=test-only
authorAndreas Tolfsen <ato@sny.no>
Tue, 03 Oct 2017 16:25:57 +0100
changeset 432425 9a1314063088
parent 432424 bd809f9f27e0
child 432426 fdcd4aa54eae
push id7953
push userryanvm@gmail.com
push date2017-10-12 14:05 +0000
treeherdermozilla-beta@f4ba99b41183 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
bugs1405325
milestone57.0
Bug 1405325 - Align WebDriver:DeleteCookie with specification. r=maja_zf, a=test-only The Delete Cookie command should not return an error if the cookie does not exist. The variable names "toDelete" and "candidateName" was also juxtapositioned and wrong. Here I am using the approximate names used in the specification prose for clarity. Fixes: https://github.com/mozilla/geckodriver/issues/989 MozReview-Commit-ID: 6IIGGpB1JWn
testing/marionette/driver.js
testing/web-platform/meta/MANIFEST.json
testing/web-platform/meta/webdriver/tests/cookies/delete_cookie.py.ini
testing/web-platform/tests/webdriver/tests/cookies/delete_cookie.py
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -2693,24 +2693,22 @@ GeckoDriver.prototype.deleteAllCookies =
  *     A modal dialog is open, blocking this operation.
  */
 GeckoDriver.prototype.deleteCookie = function(cmd, resp) {
   assert.content(this.context);
   assert.window(this.getCurrentWindow());
   assert.noUserPrompt(this.dialog);
 
   let {hostname, pathname} = this.currentURL;
-  let candidateName = assert.string(cmd.parameters.name);
-  for (let toDelete of cookie.iter(hostname, pathname)) {
-    if (toDelete.name === candidateName) {
-      return cookie.remove(toDelete);
+  let name = assert.string(cmd.parameters.name);
+  for (let c of cookie.iter(hostname, pathname)) {
+    if (c.name === name) {
+      cookie.remove(c);
     }
   }
-
-  throw new UnknownError("Unable to find cookie");
 };
 
 /**
  * Close the currently selected tab/window.
  *
  * With multiple open tabs present the currently selected tab will
  * be closed.  Otherwise the window itself will be closed. If it is the
  * last window currently open, the window will not be closed to prevent
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -407199,16 +407199,22 @@
     ]
    ],
    "webdriver/tests/contexts/resizing_and_positioning.py": [
     [
      "/webdriver/tests/contexts/resizing_and_positioning.py",
      {}
     ]
    ],
+   "webdriver/tests/cookies/delete_cookie.py": [
+    [
+     "/webdriver/tests/cookies/delete_cookie.py",
+     {}
+    ]
+   ],
    "webdriver/tests/cookies/get_named_cookie.py": [
     [
      "/webdriver/tests/cookies/get_named_cookie.py",
      {}
     ]
    ],
    "webdriver/tests/element_click/select.py": [
     [
@@ -628452,16 +628458,20 @@
   "webdriver/tests/contexts/maximize_window.py": [
    "904dd1db0e9731148a1793065b1d38acf0ac094b",
    "wdspec"
   ],
   "webdriver/tests/contexts/resizing_and_positioning.py": [
    "479379109115668183643e8a050396219332887d",
    "wdspec"
   ],
+  "webdriver/tests/cookies/delete_cookie.py": [
+   "4e846b0f0538bbfc88e7dc6b637f19260a8d3c3e",
+   "wdspec"
+  ],
   "webdriver/tests/cookies/get_named_cookie.py": [
    "afa7bcffd838c939aa6483c26a49d43c4b2dc94b",
    "wdspec"
   ],
   "webdriver/tests/element_click/__init__.py": [
    "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "support"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/webdriver/tests/cookies/delete_cookie.py.ini
@@ -0,0 +1,7 @@
+[delete_cookie.py]
+  type: wdspec
+  [delete_cookie.py::test_handle_prompt_accept]
+    expected: FAIL
+
+  [delete_cookie.py::test_handle_prompt_missing_value]
+    expected: FAIL
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/cookies/delete_cookie.py
@@ -0,0 +1,123 @@
+from tests.support.asserts import assert_error, assert_dialog_handled, assert_success
+from tests.support.fixtures import create_dialog
+from tests.support.inline import inline
+
+
+def delete_cookie(session, name):
+    return session.transport.send("DELETE", "/session/%s/cookie/%s" % (session.session_id, name))
+
+
+# 16.4 Delete Cookie
+
+
+def test_no_browsing_context(session, create_window):
+    """
+    1. If the current top-level browsing context is no longer open,
+    return error with error code no such window.
+
+    """
+    session.window_handle = create_window()
+    session.close()
+    response = delete_cookie(session, "foo")
+    assert_error(response, "no such window")
+
+
+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):
+    """
+    2. 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({"alwaysMatch": {"unhandledPromptBehavior": "accept"}})
+    session.url = inline("<title>WD doc title</title>")
+
+    create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1")
+    response = delete_cookie(session, "foo")
+    assert response.status == 200
+    assert_dialog_handled(session, "dismiss #1")
+
+    create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2")
+    response = delete_cookie(session, "foo")
+    assert response.status == 200
+    assert_dialog_handled(session, "dismiss #2")
+
+    create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3")
+    response = delete_cookie(session, "foo")
+    assert response.status == 200
+    assert_dialog_handled(session, "dismiss #3")
+
+
+def test_handle_prompt_missing_value(session, create_dialog):
+    """
+    2. 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.url = inline("<title>WD doc title</title>")
+    create_dialog("alert", text="dismiss #1", result_var="dismiss1")
+
+    response = delete_cookie(session, "foo")
+
+    assert_error(response, "unexpected alert open")
+    assert_dialog_handled(session, "dismiss #1")
+
+    create_dialog("confirm", text="dismiss #2", result_var="dismiss2")
+
+    response = delete_cookie(session, "foo")
+    assert_error(response, "unexpected alert open")
+    assert_dialog_handled(session, "dismiss #2")
+
+    create_dialog("prompt", text="dismiss #3", result_var="dismiss3")
+
+    response = delete_cookie(session, "foo")
+    assert_error(response, "unexpected alert open")
+    assert_dialog_handled(session, "dismiss #3")
+
+
+def test_unknown_cookie(session):
+    response = delete_cookie(session, "stilton")
+    assert response.status == 200
+    assert "value" in response.body
+    assert isinstance(response.body["value"], dict)
+    assert response.body["value"] == {}