Bug 1486456 - [wdspec] Add basic tests for "Get Element rect". r=ato
authorHenrik Skupin <mail@hskupin.info>
Mon, 27 Aug 2018 16:26:11 +0200
changeset 488733 4c623a756c06017d341d956ce5a8633baf3f7fc8
parent 488732 514f97264e6c75713ff3828931c5415a69697ca7
child 488734 8efef28be72c1ab7e433248924b9459beb2e1b33
push id9734
push usershindli@mozilla.com
push dateThu, 30 Aug 2018 12:18:07 +0000
treeherdermozilla-beta@71c71ab3afae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1486456
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1486456 - [wdspec] Add basic tests for "Get Element rect". r=ato
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webdriver/tests/get_element_rect/__init__.py
testing/web-platform/tests/webdriver/tests/get_element_rect/get.py
testing/web-platform/tests/webdriver/tests/get_element_rect/user_prompts.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -310648,16 +310648,21 @@
      {}
     ]
    ],
    "webdriver/tests/get_element_property/__init__.py": [
     [
      {}
     ]
    ],
+   "webdriver/tests/get_element_rect/__init__.py": [
+    [
+     {}
+    ]
+   ],
    "webdriver/tests/get_element_tag_name/__init__.py": [
     [
      {}
     ]
    ],
    "webdriver/tests/get_element_text/__init__.py": [
     [
      {}
@@ -422898,16 +422903,30 @@
    "webdriver/tests/get_element_property/user_prompts.py": [
     [
      "/webdriver/tests/get_element_property/user_prompts.py",
      {
       "timeout": "long"
      }
     ]
    ],
+   "webdriver/tests/get_element_rect/get.py": [
+    [
+     "/webdriver/tests/get_element_rect/get.py",
+     {}
+    ]
+   ],
+   "webdriver/tests/get_element_rect/user_prompts.py": [
+    [
+     "/webdriver/tests/get_element_rect/user_prompts.py",
+     {
+      "timeout": "long"
+     }
+    ]
+   ],
    "webdriver/tests/get_element_tag_name/get.py": [
     [
      "/webdriver/tests/get_element_tag_name/get.py",
      {}
     ]
    ],
    "webdriver/tests/get_element_tag_name/user_prompts.py": [
     [
@@ -648475,16 +648494,28 @@
   "webdriver/tests/get_element_property/get.py": [
    "fde0f2a0cd6dd89b59287510f7049ceabac8d371",
    "wdspec"
   ],
   "webdriver/tests/get_element_property/user_prompts.py": [
    "16a098536fde814b5ac8bcb35dac01ac38649d2e",
    "wdspec"
   ],
+  "webdriver/tests/get_element_rect/__init__.py": [
+   "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
+   "support"
+  ],
+  "webdriver/tests/get_element_rect/get.py": [
+   "6e0db2c68e0e1a468d0791a2c710b80b0b8ab515",
+   "wdspec"
+  ],
+  "webdriver/tests/get_element_rect/user_prompts.py": [
+   "16a098536fde814b5ac8bcb35dac01ac38649d2e",
+   "wdspec"
+  ],
   "webdriver/tests/get_element_tag_name/__init__.py": [
    "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
    "support"
   ],
   "webdriver/tests/get_element_tag_name/get.py": [
    "d705ae1118f13c2472b6fa4b1c2fc44bb4967ec2",
    "wdspec"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/get_element_rect/__init__.py
@@ -0,0 +1,10 @@
+def retrieve_element_rect(session, element):
+    return session.execute_script("""
+        let rect = arguments[0].getBoundingClientRect();
+        return {
+            x: rect.left + window.pageXOffset,
+            y: rect.top + window.pageYOffset,
+            width: rect.width,
+            height: rect.height,
+        };
+        """, args=(element,))
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/get_element_rect/get.py
@@ -0,0 +1,41 @@
+from tests.support.asserts import assert_error, assert_success
+from tests.support.inline import inline
+
+from . import retrieve_element_rect
+
+
+def get_element_rect(session, element_id):
+    return session.transport.send(
+        "GET",
+        "session/{session_id}/element/{element_id}/rect".format(
+            session_id=session.session_id,
+            element_id=element_id,
+        )
+    )
+
+
+def test_no_browsing_context(session, closed_window):
+    response = get_element_rect(session, "foo")
+    assert_error(response, "no such window")
+
+
+def test_element_not_found(session):
+    result = get_element_rect(session, "foo")
+    assert_error(result, "no such element")
+
+
+def test_element_stale(session):
+    session.url = inline("<input>")
+    element = session.find.css("input", all=False)
+    session.refresh()
+
+    result = get_element_rect(session, element.id)
+    assert_error(result, "stale element reference")
+
+
+def test_basic(session):
+    session.url = inline("<input>")
+    element = session.find.css("input", all=False)
+
+    result = get_element_rect(session, element.id)
+    assert_success(result, retrieve_element_rect(session, element))
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/get_element_rect/user_prompts.py
@@ -0,0 +1,122 @@
+# META: timeout=long
+
+import pytest
+
+from tests.support.asserts import assert_error, assert_success, assert_dialog_handled
+from tests.support.inline import inline
+
+from . import retrieve_element_rect
+
+
+def get_element_rect(session, element_id):
+    return session.transport.send(
+        "GET",
+        "session/{session_id}/element/{element_id}/rect".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>")
+        element = session.find.css("input", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = get_element_rect(session, element.id)
+        assert_success(response, retrieve_element_rect(session, element))
+
+        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>")
+        element = session.find.css("input", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = get_element_rect(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>")
+        element = session.find.css("input", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = get_element_rect(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)