Bug 1486572 - [wdspec] Create tests for "Is Element Enabled" command.
authorHenrik Skupin <mail@hskupin.info>
Tue, 28 Aug 2018 08:58:53 +0200
changeset 482179 3eb891993d3e0802ae958cb8256d4e44c3b0817e
parent 482178 aaab9dff4a225f3097a5b480a51d2bdc1926ac26
child 482180 bd6fb6ab62f4c6ae57923c1ae987fb32c1387563
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
bugs1486572
milestone63.0a1
Bug 1486572 - [wdspec] Create tests for "Is Element Enabled" command.
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webdriver/tests/is_element_enabled/__init__.py
testing/web-platform/tests/webdriver/tests/is_element_enabled/enabled.py
testing/web-platform/tests/webdriver/tests/is_element_enabled/user_prompts.py
testing/web-platform/tests/webdriver/tests/support/inline.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -310920,16 +310920,21 @@
      {}
     ]
    ],
    "webdriver/tests/get_window_rect/__init__.py": [
     [
      {}
     ]
    ],
+   "webdriver/tests/is_element_enabled/__init__.py": [
+    [
+     {}
+    ]
+   ],
    "webdriver/tests/is_element_selected/__init__.py": [
     [
      {}
     ]
    ],
    "webdriver/tests/maximize_window/__init__.py": [
     [
      {}
@@ -423989,16 +423994,30 @@
    "webdriver/tests/get_window_rect/user_prompts.py": [
     [
      "/webdriver/tests/get_window_rect/user_prompts.py",
      {
       "timeout": "long"
      }
     ]
    ],
+   "webdriver/tests/is_element_enabled/enabled.py": [
+    [
+     "/webdriver/tests/is_element_enabled/enabled.py",
+     {}
+    ]
+   ],
+   "webdriver/tests/is_element_enabled/user_prompts.py": [
+    [
+     "/webdriver/tests/is_element_enabled/user_prompts.py",
+     {
+      "timeout": "long"
+     }
+    ]
+   ],
    "webdriver/tests/is_element_selected/selected.py": [
     [
      "/webdriver/tests/is_element_selected/selected.py",
      {}
     ]
    ],
    "webdriver/tests/is_element_selected/user_prompts.py": [
     [
@@ -524171,21 +524190,21 @@
    "af56147f52291a8b4515c67f843505703875c594",
    "support"
   ],
   "css/css-filter/META.yml": [
    "8d0683319b0fbbd1262cbdd12cdbcb727b2aa9a0",
    "support"
   ],
   "css/css-filter/blur-clip-stacking-context-001.html": [
-   "48c1bae3042b6912ba5edd7ae74c190e5bd8f2d2",
+   "a96994a8afe126e474f9ee015338749f0015dc1f",
    "reftest"
   ],
   "css/css-filter/blur-clip-stacking-context-002.html": [
-   "f4df453b17b86a6da67c4cf5f71261e9315eab95",
+   "0473f12949446da04849386ffea69e7436703010",
    "reftest"
   ],
   "css/css-filter/blur-clip-stacking-context-ref.html": [
    "82b907334fd71791cd2f6530e2e85169e29afa41",
    "support"
   ],
   "css/css-filter/filtered-block-is-container-ref.html": [
    "fc9467f8717dfc722dcb6dbbbb31bfd8c2baee3b",
@@ -649667,25 +649686,25 @@
    "fde0f2a0cd6dd89b59287510f7049ceabac8d371",
    "wdspec"
   ],
   "webdriver/tests/get_element_property/user_prompts.py": [
    "16a098536fde814b5ac8bcb35dac01ac38649d2e",
    "wdspec"
   ],
   "webdriver/tests/get_element_rect/__init__.py": [
-   "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
+   "abf1a91367517107b3b690466a4b570c0a3b7cab",
    "support"
   ],
   "webdriver/tests/get_element_rect/get.py": [
-   "6e0db2c68e0e1a468d0791a2c710b80b0b8ab515",
+   "433e2f6bf8b428136a36b81138386e62eb257daf",
    "wdspec"
   ],
   "webdriver/tests/get_element_rect/user_prompts.py": [
-   "16a098536fde814b5ac8bcb35dac01ac38649d2e",
+   "ec1047bd3893d51f4b2be9597d87ba4a63b6a353",
    "wdspec"
   ],
   "webdriver/tests/get_element_tag_name/__init__.py": [
    "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
    "support"
   ],
   "webdriver/tests/get_element_tag_name/get.py": [
    "d705ae1118f13c2472b6fa4b1c2fc44bb4967ec2",
@@ -649766,16 +649785,28 @@
   "webdriver/tests/get_window_rect/user_prompts.py": [
    "37c8da6bd3838422441fc089d8191930dd2b3da6",
    "wdspec"
   ],
   "webdriver/tests/interface.html": [
    "d049d835f2fc60df7296da08a013793ae7e398ca",
    "testharness"
   ],
+  "webdriver/tests/is_element_enabled/__init__.py": [
+   "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
+   "support"
+  ],
+  "webdriver/tests/is_element_enabled/enabled.py": [
+   "dd56084d8d0eca15b7b6d46491bbd9f0a64cef40",
+   "wdspec"
+  ],
+  "webdriver/tests/is_element_enabled/user_prompts.py": [
+   "bd8bc81bdfcce13e5cdbfec336749cd668bd68ef",
+   "wdspec"
+  ],
   "webdriver/tests/is_element_selected/__init__.py": [
    "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
    "support"
   ],
   "webdriver/tests/is_element_selected/selected.py": [
    "76361e50563d1589d867d7b7ddd45a287ea1eb6c",
    "wdspec"
   ],
@@ -649939,17 +649970,17 @@
    "64427b4670f72c9ea069d0f008d93ad63a9781c0",
    "support"
   ],
   "webdriver/tests/support/http_request.py": [
    "5e46d97017e14ba009d4d1ed6d62bb5012f48d15",
    "support"
   ],
   "webdriver/tests/support/inline.py": [
-   "2f8fe9b79e3bacf1fb3bd9bcd981c8d8389fcd08",
+   "8b4f1657cffb193511da346bc4c236aac1d70308",
    "support"
   ],
   "webdriver/tests/support/merge_dictionaries.py": [
    "cf06c9b433cee167c5c98e06d64cc7a2e68faff3",
    "support"
   ],
   "webdriver/tests/support/wait.py": [
    "6f439ec61a372bc1202f226a3b4e3f41509d5f60",
@@ -656751,17 +656782,17 @@
    "471697a43bfb8844e9fb4ed9a85790ca73c3b0ff",
    "support"
   ],
   "worklets/resources/throwing-worklet-script.js": [
    "6417d6c5f7fe754b3d3b08b009977b4a08667477",
    "support"
   ],
   "worklets/resources/worklet-test-utils.js": [
-   "9dd1b856cc8d29ccd5a7c59df6b4d3920affadb4",
+   "797edc9e563a7e089379d6bb0947da06f205ddc7",
    "support"
   ],
   "wpt": [
    "a24bc83a9197a1561ddf28c8116c0cb10bcde70e",
    "support"
   ],
   "wpt.py": [
    "0736186c5d813f04a83fdd117974a9e1513dbff1",
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/is_element_enabled/enabled.py
@@ -0,0 +1,109 @@
+import pytest
+
+from tests.support.asserts import assert_error, assert_success
+from tests.support.inline import inline
+
+
+def is_element_enabled(session, element_id):
+    return session.transport.send(
+        "GET",
+        "session/{session_id}/element/{element_id}/enabled".format(
+            session_id=session.session_id,
+            element_id=element_id
+        )
+    )
+
+
+def test_no_browsing_context(session, closed_window):
+    response = is_element_enabled(session, "foo")
+    assert_error(response, "no such window")
+
+
+def test_element_stale(session):
+    session.url = inline("<input>")
+    element = session.find.css("input", all=False)
+    session.refresh()
+
+    result = is_element_enabled(session, element.id)
+    assert_error(result, "stale element reference")
+
+
+@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
+def test_form_control_disabled(session, element):
+    session.url = inline("<{} disabled/>".format(element))
+    element = session.find.css(element, all=False)
+
+    result = is_element_enabled(session, element.id)
+    assert_success(result, False)
+
+
+@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
+def test_form_control_enabled(session, element):
+    session.url = inline("<{}/>".format(element))
+    element = session.find.css(element, all=False)
+
+    result = is_element_enabled(session, element.id)
+    assert_success(result, True)
+
+
+@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
+def test_fieldset_disabled_descendant(session, element):
+    session.url = inline("<fieldset disabled><{}/></fieldset>".format(element))
+    element = session.find.css(element, all=False)
+
+    result = is_element_enabled(session, element.id)
+    assert_success(result, False)
+
+
+@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
+def test_fieldset_enabled_descendant(session, element):
+    session.url = inline("<fieldset><{}/></fieldset>".format(element))
+    element = session.find.css(element, all=False)
+
+    result = is_element_enabled(session, element.id)
+    assert_success(result, True)
+
+
+@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
+def test_fieldset_disabled_descendant_legend(session, element):
+    session.url = inline("<fieldset disabled><legend><{}/></legend></fieldset>".format(element))
+    element = session.find.css(element, all=False)
+
+    result = is_element_enabled(session, element.id)
+    assert_success(result, True)
+
+
+@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
+def test_fieldset_enabled_descendant_legend(session, element):
+    session.url = inline("<fieldset><legend><{}/></legend></fieldset>".format(element))
+    element = session.find.css(element, all=False)
+
+    result = is_element_enabled(session, element.id)
+    assert_success(result, True)
+
+
+@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
+def test_xhtml_form_control_disabled(session, element):
+    session.url = inline("""<{} disabled="disabled"/>""".format(element),
+                         doctype="xhtml")
+    element = session.find.css(element, all=False)
+
+    result = is_element_enabled(session, element.id)
+    assert_success(result, False)
+
+
+@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
+def test_xhtml_form_control_enabled(session, element):
+    session.url = inline("""<{}/>""".format(element), doctype="xhtml")
+    element = session.find.css(element, all=False)
+
+    result = is_element_enabled(session, element.id)
+    assert_success(result, True)
+
+
+def test_xml_always_not_enabled(session):
+    session.url = inline("""<note></note>""", doctype="xml")
+    element = session.find.css("note", all=False)
+
+    result = is_element_enabled(session, element.id)
+    assert_success(result, False)
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/is_element_enabled/user_prompts.py
@@ -0,0 +1,120 @@
+# META: timeout=long
+
+import pytest
+
+from tests.support.asserts import assert_error, assert_dialog_handled, assert_success
+from tests.support.inline import inline
+
+
+def is_element_enabled(session, element_id):
+    return session.transport.send(
+        "GET",
+        "session/{session_id}/element/{element_id}/enabled".format(
+            session_id=session.session_id,
+            element_id=element_id
+        )
+    )
+
+
+@pytest.fixture
+def check_user_prompt_closed_without_exception(session, create_dialog):
+    def check_user_prompt_closed_without_exception(dialog_type, retval):
+        session.url = inline("<input id=foo disabled>")
+        element = session.find.css("#foo", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = is_element_enabled(session, element.id)
+        assert_success(response, False)
+
+        assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
+
+    return check_user_prompt_closed_without_exception
+
+
+@pytest.fixture
+def check_user_prompt_closed_with_exception(session, create_dialog):
+    def check_user_prompt_closed_with_exception(dialog_type, retval):
+        session.url = inline("<input id=foo disabled>")
+        element = session.find.css("#foo", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = is_element_enabled(session, element.id)
+        assert_error(response, "unexpected alert open")
+
+        assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
+
+    return check_user_prompt_closed_with_exception
+
+
+@pytest.fixture
+def check_user_prompt_not_closed_but_exception(session, create_dialog):
+    def check_user_prompt_not_closed_but_exception(dialog_type):
+        session.url = inline("<input id=foo disabled>")
+        element = session.find.css("#foo", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = is_element_enabled(session, element.id)
+        assert_error(response, "unexpected alert open")
+
+        assert session.alert.text == dialog_type
+        session.alert.dismiss()
+
+    return check_user_prompt_not_closed_but_exception
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", True),
+    ("prompt", ""),
+])
+def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
+    check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", True),
+    ("prompt", ""),
+])
+def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
+    check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
+    check_user_prompt_not_closed_but_exception(dialog_type)
+
+
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
--- a/testing/web-platform/tests/webdriver/tests/support/inline.py
+++ b/testing/web-platform/tests/webdriver/tests/support/inline.py
@@ -4,27 +4,30 @@ import urllib
 def inline(doc, doctype="html", mime="text/html;charset=utf-8", protocol="http"):
     from .fixtures import server_config, url
     build_url = url(server_config())
 
     if doctype == "html":
         mime = "text/html;charset=utf-8"
     elif doctype == "xhtml":
         mime = "application/xhtml+xml"
-        doc = r"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+        doc = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   <head>
     <title>XHTML might be the future</title>
   </head>
 
   <body>
     {}
   </body>
 </html>""".format(doc)
+    elif doctype == "xml":
+        mime = "text/xml"
+        doc = """<?xml version="1.0" encoding="UTF-8"?>{}""".format(doc)
 
     query = {"doc": doc}
     if mime != "text/html;charset=utf8":
         query["content-type"] = mime
 
     return build_url("/webdriver/tests/support/inline.py",
                      query=urllib.urlencode(query),
                      protocol=protocol)
@@ -36,13 +39,13 @@ def iframe(doc):
 
 def main(request, response):
     doc = request.GET.first("doc", None)
     content_type = request.GET.first("content-type", "text/html;charset=utf8")
     if doc is None:
         rv = 404, [("Content-Type", "text/plain")], "Missing doc parameter in query"
     else:
         response.headers.update([
-          ("Content-Type", content_type),
-          ("X-XSS-Protection", "0")
+            ("Content-Type", content_type),
+            ("X-XSS-Protection", "0")
         ])
         rv = doc
     return rv