bug 1546319: webdriver: add Get Element Property tests for mutated web content; r=automatedtester
authorAndreas Tolfsen <ato@sny.no>
Tue, 23 Apr 2019 13:38:53 +0000
changeset 470500 728a88d6113294c05c8b8af2eb635faa3200b937
parent 470499 f811995954013dae14ed21659a24a33ce1dbe174
child 470501 4a753a263c3835e7e52f0c3419a3b7c43e12ab54
push id35906
push useraciure@mozilla.com
push dateTue, 23 Apr 2019 22:14:56 +0000
treeherdermozilla-central@0ce3633f8b80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester
bugs1546319
milestone68.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 1546319: webdriver: add Get Element Property tests for mutated web content; r=automatedtester There are approximately zero coverage for properties modified or set by web content and through script evaluation. The only succcess path test for Get Element Property is test_element, but it checks an attribute already present in the prototype of the HTMLInputElement. This patch adds tests where the property is defined through web content. This uncovers a defect in Firefox, where Get Element Property seemingly operates on the initial value of the attribute. Differential Revision: https://phabricator.services.mozilla.com/D28463
testing/web-platform/meta/webdriver/tests/get_element_property/get.py.ini
testing/web-platform/tests/webdriver/tests/get_element_property/get.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/webdriver/tests/get_element_property/get.py.ini
@@ -0,0 +1,24 @@
+[get.py]
+  [test_primitives\["foobar"-foobar\]]
+    expected: FAIL
+
+  [test_primitives\[42-42\]]
+    expected: FAIL
+
+  [test_primitives\[js_primitive2-py_primitive2\]]
+    expected: FAIL
+
+  [test_primitives\[js_primitive3-py_primitive3\]]
+    expected: FAIL
+
+  [test_primitives_set_by_execute_script\["foobar"-foobar\]]
+    expected: FAIL
+
+  [test_primitives_set_by_execute_script\[42-42\]]
+    expected: FAIL
+
+  [test_primitives_set_by_execute_script\[js_primitive2-py_primitive2\]]
+    expected: FAIL
+
+  [test_primitives_set_by_execute_script\[js_primitive3-py_primitive3\]]
+    expected: FAIL
--- a/testing/web-platform/tests/webdriver/tests/get_element_property/get.py
+++ b/testing/web-platform/tests/webdriver/tests/get_element_property/get.py
@@ -1,8 +1,10 @@
+import pytest
+
 from tests.support.asserts import assert_error, assert_success
 from tests.support.inline import inline
 
 
 def get_element_property(session, element_id, prop):
     return session.transport.send(
         "GET", "session/{session_id}/element/{element_id}/property/{prop}".format(
             session_id=session.session_id,
@@ -33,16 +35,73 @@ def test_property_non_existent(session):
     session.url = inline("<input>")
     element = session.find.css("input", all=False)
 
     response = get_element_property(session, element.id, "foo")
     assert_success(response, None)
     assert session.execute_script("return arguments[0].foo", args=(element,)) is None
 
 
+def test_content_attribute(session):
+    session.url = inline("<input value=foobar>")
+    element = session.find.css("input", all=False)
+
+    response = get_element_property(session, element.id, "value")
+    assert_success(response, "foobar")
+
+
+def test_idl_attribute(session):
+    session.url = inline("<input value=foo>")
+    element = session.find.css("input", all=False)
+    session.execute_script("""arguments[0].value = "bar";""", args=(element,))
+
+    response = get_element_property(session, element.id, "value")
+    assert_success(response, "bar")
+
+
+@pytest.mark.parametrize("js_primitive,py_primitive", [
+    ("\"foobar\"", "foobar"),
+    (42, 42),
+    ([], []),
+    ({}, {}),
+    ("null", None),
+    ("undefined", None),
+])
+def test_primitives(session, js_primitive, py_primitive):
+    session.url = inline("""
+        <input>
+
+        <script>
+        const input = document.querySelector("input");
+        input.foobar = {js_primitive};
+        </script>
+        """.format(js_primitive=js_primitive))
+    element = session.find.css("input", all=False)
+
+    response = get_element_property(session, element.id, "foobar")
+    assert_success(response, py_primitive)
+
+
+@pytest.mark.parametrize("js_primitive,py_primitive", [
+    ("\"foobar\"", "foobar"),
+    (42, 42),
+    ([], []),
+    ({}, {}),
+    ("null", None),
+    ("undefined", None),
+])
+def test_primitives_set_by_execute_script(session, js_primitive, py_primitive):
+    session.url = inline("<input>")
+    element = session.find.css("input", all=False)
+    session.execute_script("arguments[0].foobar = {}".format(js_primitive), args=(element,))
+
+    response = get_element_property(session, element.id, "foobar")
+    assert_success(response, py_primitive)
+
+
 def test_mutated_element(session):
     session.url = inline("<input type=checkbox>")
     element = session.find.css("input", all=False)
     element.click()
     assert session.execute_script("return arguments[0].hasAttribute('checked')", args=(element,)) is False
 
     response = get_element_property(session, element.id, "checked")
     assert_success(response, True)