bug 1546303: webdriver: add WPT tests for properties in evaluated scripts; r=whimboo
authorAndreas Tolfsen <ato@sny.no>
Tue, 23 Apr 2019 14:09:43 +0000
changeset 470501 4a753a263c3835e7e52f0c3419a3b7c43e12ab54
parent 470500 728a88d6113294c05c8b8af2eb635faa3200b937
child 470502 970ef36e6c09e748140ebf96c9ccfec6eb52ab5e
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)
reviewerswhimboo
bugs1546303
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 1546303: webdriver: add WPT tests for properties in evaluated scripts; r=whimboo This adds a basic set of tests for interacting with various kinds of DOM properties from the WebDriver commands Execute Script and Execute Async Script. Differential Revision: https://phabricator.services.mozilla.com/D28453
testing/web-platform/tests/webdriver/tests/execute_async_script/properties.py
testing/web-platform/tests/webdriver/tests/execute_script/properties.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/execute_async_script/properties.py
@@ -0,0 +1,71 @@
+from tests.support.asserts import assert_same_element, assert_success
+from tests.support.inline import inline
+
+
+def execute_async_script(session, script, args=None):
+    if args is None:
+        args = []
+    body = {"script": script, "args": args}
+    return session.transport.send(
+        "POST", "/session/{session_id}/execute/async".format(**vars(session)),
+        body)
+
+
+def test_content_attribute(session):
+    session.url = inline("<input value=foobar>")
+    response = execute_async_script(session, """
+        const [resolve] = arguments;
+        const input = document.querySelector("input");
+        resolve(input.value);
+        """)
+    assert_success(response, "foobar")
+
+
+def test_idl_attribute(session):
+    session.url = inline("""
+        <input>
+        <script>
+        const input = document.querySelector("input");
+        input.value = "foobar";
+        </script>
+        """)
+    response = execute_async_script(session, """
+        const [resolve] = arguments;
+        const input = document.querySelector("input");
+        resolve(input.value);
+        """)
+    assert_success(response, "foobar")
+
+
+def test_idl_attribute_element(session):
+    session.url = inline("""
+        <p>foo
+        <p>bar
+
+        <script>
+        const [foo, bar] = document.querySelectorAll("p");
+        foo.bar = bar;
+        </script>
+        """)
+    _foo, bar = session.find.css("p")
+    response = execute_async_script(session, """
+        const [resolve] = arguments;
+        const foo = document.querySelector("p");
+        resolve(foo.bar);
+        """)
+    value = assert_success(response)
+    assert_same_element(session, bar, value)
+
+
+def test_script_defining_property(session):
+    session.url = inline("<input>")
+    session.execute_script("""
+        const input = document.querySelector("input");
+        input.foobar = "foobar";
+        """)
+    response = execute_async_script(session, """
+        const [resolve] = arguments;
+        const input = document.querySelector("input");
+        resolve(input.foobar);
+        """)
+    assert_success(response, "foobar")
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/execute_script/properties.py
@@ -0,0 +1,67 @@
+from tests.support.asserts import assert_same_element, assert_success
+from tests.support.inline import inline
+
+
+def execute_script(session, script, args=None):
+    if args is None:
+        args = []
+    body = {"script": script, "args": args}
+    return session.transport.send(
+        "POST", "/session/{session_id}/execute/sync".format(**vars(session)),
+        body)
+
+
+def test_content_attribute(session):
+    session.url = inline("<input value=foobar>")
+    response = execute_script(session, """
+        const input = document.querySelector("input");
+        return input.value;
+        """)
+    assert_success(response, "foobar")
+
+
+def test_idl_attribute(session):
+    session.url = inline("""
+        <input>
+        <script>
+        const input = document.querySelector("input");
+        input.value = "foobar";
+        </script>
+        """)
+    response = execute_script(session, """
+        const input = document.querySelector("input");
+        return input.value;
+        """)
+    assert_success(response, "foobar")
+
+
+def test_idl_attribute_element(session):
+    session.url = inline("""
+        <p>foo
+        <p>bar
+
+        <script>
+        const [foo, bar] = document.querySelectorAll("p");
+        foo.bar = bar;
+        </script>
+        """)
+    _foo, bar = session.find.css("p")
+    response = execute_script(session, """
+        const foo = document.querySelector("p");
+        return foo.bar;
+        """)
+    value = assert_success(response)
+    assert_same_element(session, bar, value)
+
+
+def test_script_defining_property(session):
+    session.url = inline("<input>")
+    execute_script(session, """
+        const input = document.querySelector("input");
+        input.foobar = "foobar";
+        """)
+    response = execute_script(session, """
+        const input = document.querySelector("input");
+        return input.foobar;
+        """)
+    assert_success(response, "foobar")