Bug 1398095 - [wdspec] Add promise tests for Execute Async Script command. r=ato
authorHenrik Skupin <mail@hskupin.info>
Thu, 14 Feb 2019 13:39:55 +0000
changeset 459128 b8393b9641e543cd482526dfbaa81cb673d39d6f
parent 459127 c69465c47848e9f6a4ee91f9a51893ef74e9a644
child 459129 826603df29563cd5811992f310d94f41b237ac2c
push id35556
push userdvarga@mozilla.com
push dateFri, 15 Feb 2019 01:38:24 +0000
treeherdermozilla-central@b29c87add05f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1398095
milestone67.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 1398095 - [wdspec] Add promise tests for Execute Async Script command. r=ato Depends on D19755 Differential Revision: https://phabricator.services.mozilla.com/D19757
testing/web-platform/meta/webdriver/tests/execute_async_script/promise.py.ini
testing/web-platform/tests/webdriver/tests/execute_async_script/promise.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/webdriver/tests/execute_async_script/promise.py.ini
@@ -0,0 +1,3 @@
+[promise.py]
+  [test_await_promise_resolve]
+    expected: FAIL
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/execute_async_script/promise.py
@@ -0,0 +1,127 @@
+from tests.support.asserts import assert_error, assert_success
+
+
+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_promise_resolve(session):
+    response = execute_async_script(session, """
+        let resolve = arguments[0];
+        resolve(Promise.resolve('foobar'));
+        """)
+    assert_success(response, "foobar")
+
+
+def test_promise_resolve_delayed(session):
+    response = execute_async_script(session, """
+        let resolve = arguments[0];
+        let promise = new Promise(
+            (resolve) => setTimeout(
+                () => resolve('foobar'),
+                50
+            )
+        );
+        resolve(promise);
+        """)
+    assert_success(response, "foobar")
+
+
+def test_promise_all_resolve(session):
+    response = execute_async_script(session, """
+        let resolve = arguments[0];
+        let promise = Promise.all([
+            Promise.resolve(1),
+            Promise.resolve(2)
+        ]);
+        resolve(promise);
+        """)
+    assert_success(response, [1, 2])
+
+
+def test_await_promise_resolve(session):
+    response = execute_async_script(session, """
+        let resolve = arguments[0];
+        let res = await Promise.resolve('foobar');
+        resolve(res);
+        """)
+    assert_success(response, "foobar")
+
+
+def test_promise_resolve_timeout(session):
+    session.timeouts.script = .1
+    response = execute_async_script(session, """
+        let resolve = arguments[0];
+        let promise = new Promise(
+            (resolve) => setTimeout(
+                () => resolve(),
+                1000
+            )
+        );
+        resolve(promise);
+        """)
+    assert_error(response, "script timeout")
+
+
+def test_promise_reject(session):
+    response = execute_async_script(session, """
+        let resolve = arguments[0];
+        resolve(Promise.reject(new Error('my error')));
+        """)
+    assert_error(response, "javascript error")
+
+
+def test_promise_reject_delayed(session):
+    response = execute_async_script(session, """
+        let resolve = arguments[0];
+        let promise = new Promise(
+            (resolve, reject) => setTimeout(
+                () => reject(new Error('my error')),
+                50
+            )
+        );
+        resolve(promise);
+        """)
+    assert_error(response, "javascript error")
+
+
+def test_promise_all_reject(session):
+    response = execute_async_script(session, """
+        let resolve = arguments[0];
+        let promise = Promise.all([
+            Promise.resolve(1),
+            Promise.reject(new Error('error'))
+        ]);
+        resolve(promise);
+        """)
+    assert_error(response, "javascript error")
+
+
+def test_await_promise_reject(session):
+    response = execute_async_script(session, """
+        let resolve = arguments[0];
+        await Promise.reject(new Error('my error'));
+        resolve('foo');
+        """)
+    assert_error(response, "javascript error")
+
+
+def test_promise_reject_timeout(session):
+    session.timeouts.script = .1
+    response = execute_async_script(session, """
+        let resolve = arguments[0];
+        let promise = new Promise(
+            (resolve, reject) => setTimeout(
+                () => reject(new Error('my error')),
+                1000
+            )
+        );
+        resolve(promise);
+        """)
+    assert_error(response, "script timeout")