Title: [225820] trunk
Revision
225820
Author
bb...@apple.com
Date
2017-12-12 16:31:15 -0800 (Tue, 12 Dec 2017)

Log Message

Web Inspector: support async setup() and async teardown() in AsyncTestSuite
https://bugs.webkit.org/show_bug.cgi?id=180626

Reviewed by Timothy Hatcher.

Source/WebInspectorUI:

This can make some code simpler by removing Promise-related boilerplate. I'm splitting
this patch from the new use-site in the interest of making it easier to review.

* UserInterface/Test/TestSuite.js:
(AsyncTestSuite.prototype.runTestCases):
(AsyncTestSuite):

LayoutTests:

Update tests to cover async setup() and async teardown() in the case
of success, runtime failure, and explicit failure.

* inspector/unit-tests/async-test-suite-expected.txt:
* inspector/unit-tests/async-test-suite.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225819 => 225820)


--- trunk/LayoutTests/ChangeLog	2017-12-13 00:11:45 UTC (rev 225819)
+++ trunk/LayoutTests/ChangeLog	2017-12-13 00:31:15 UTC (rev 225820)
@@ -1,5 +1,18 @@
 2017-12-12  Brian Burg  <bb...@apple.com>
 
+        Web Inspector: support async setup() and async teardown() in AsyncTestSuite
+        https://bugs.webkit.org/show_bug.cgi?id=180626
+
+        Reviewed by Timothy Hatcher.
+
+        Update tests to cover async setup() and async teardown() in the case
+        of success, runtime failure, and explicit failure.
+
+        * inspector/unit-tests/async-test-suite-expected.txt:
+        * inspector/unit-tests/async-test-suite.html:
+
+2017-12-12  Brian Burg  <bb...@apple.com>
+
         Web Inspector: SyncTestSuite should complain if passed an async setup/test/teardown function
         https://bugs.webkit.org/show_bug.cgi?id=180717
 

Modified: trunk/LayoutTests/inspector/unit-tests/async-test-suite-expected.txt (225819 => 225820)


--- trunk/LayoutTests/inspector/unit-tests/async-test-suite-expected.txt	2017-12-13 00:11:45 UTC (rev 225819)
+++ trunk/LayoutTests/inspector/unit-tests/async-test-suite-expected.txt	2017-12-13 00:31:15 UTC (rev 225820)
@@ -105,3 +105,48 @@
 PASS: Promise did evaluate the async test function.
 PASS: Rejected value should be a runtime exception.
 
+== Running test suite: AsyncTestSuite.AsyncSetupAndAsyncTeardown
+-- Running test setup.
+-- Running test case: TestWithSetupAndTeardown
+PASS: Test should see side effects of running setup() action.
+-- Running test teardown.
+PASS: Teardown should see side effects of running setup() action.
+
+-- Running test case: TestRunningAfterTeardown
+PASS: Test should see side effects of previous test's teardown() action.
+PASS: Promise from asyncSetupAndAsyncTeardownTestSuite.runTestCases() should resolve.
+
+== Running test suite: AsyncTestSuite.AsyncSetupExplicitFailure
+-- Running test case: AsyncFunctionFailure
+!! EXCEPTION: AsyncFunctionFailure Exception Message
+Stack Trace: (suppressed)
+PASS: Promise from asyncSetupExplicitFailureTestSuite.runTestCases() should reject.
+PASS: Promise did evaluate the async setup function.
+PASS: Rejected value should be thrown exception.
+
+== Running test suite: AsyncTestSuite.AsyncSetupRuntimeFailure
+-- Running test setup.
+!! EXCEPTION: undefined is not an object (evaluating '({}).x.x')
+Stack Trace: (suppressed)
+PASS: Promise from asyncSetupRuntimeFailureTestSuite.runTestCases() should reject.
+PASS: Promise did evaluate the async setup function.
+PASS: Rejected value should be a runtime exception.
+
+== Running test suite: AsyncTestSuite.AsyncTeardownExplicitFailure
+-- Running test case: AsyncFunctionFailure
+-- Running test teardown.
+!! EXCEPTION: AsyncFunctionFailure Exception Message
+Stack Trace: (suppressed)
+PASS: Promise from asyncTeardownExplicitFailureTestSuite.runTestCases() should reject.
+PASS: Promise did evaluate the async teardown function.
+PASS: Rejected value should be thrown exception.
+
+== Running test suite: AsyncTestSuite.AsyncTeardownRuntimeFailure
+-- Running test case: AsyncFunctionFailure
+-- Running test teardown.
+!! EXCEPTION: undefined is not an object (evaluating '({}).x.x')
+Stack Trace: (suppressed)
+PASS: Promise from asyncTeardownRuntimeFailureTestSuite.runTestCases() should reject.
+PASS: Promise did evaluate the async teardown function.
+PASS: Rejected value should be a runtime exception.
+

Modified: trunk/LayoutTests/inspector/unit-tests/async-test-suite.html (225819 => 225820)


--- trunk/LayoutTests/inspector/unit-tests/async-test-suite.html	2017-12-13 00:11:45 UTC (rev 225819)
+++ trunk/LayoutTests/inspector/unit-tests/async-test-suite.html	2017-12-13 00:31:15 UTC (rev 225820)
@@ -290,7 +290,7 @@
         },
         teardown: (resolve, reject) => {
             ProtocolTest.assert(false, "Teardown action should not execute if its setup action threw an exception.");
-            reject();           
+            reject();
         }
     });
 
@@ -389,7 +389,7 @@
         return Promise.resolve(); // Continue this test.
     });
 
-
+    // Async test functions.
     let asyncFunctionSuccessTestSuiteDidEvaluate = false;
     let asyncFunctionSuccessTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncFunctionSuccess");
     asyncFunctionSuccessTestSuite.addTestCase({
@@ -413,7 +413,6 @@
         return Promise.resolve(); // Continue this test.
     });
 
-
     let asyncFunctionExplicitFailureTestSuiteDidEvaluate = false;
     let asyncFunctionExplicitFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncFunctionExplicitFailure");
     asyncFunctionExplicitFailureTestSuite.addTestCase({
@@ -437,7 +436,6 @@
         return Promise.resolve(); // Continue this test.
     });
 
-
     let asyncFunctionRuntimeFailureTestSuiteDidEvaluate = false;
     let asyncFunctionRuntimeFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncFunctionRuntimeFailure");
     asyncFunctionRuntimeFailureTestSuite.addTestCase({
@@ -461,6 +459,142 @@
         return Promise.resolve(); // Continue this test.
     });
 
+    // Async setup() and teardown() success test cases.
+    const asyncSetupAndTeardownSymbol = Symbol("async-suite-async-setup-and-teardown-token");
+    window[asyncSetupAndTeardownSymbol] = 0;
+
+    let asyncSetupAndAsyncTeardownTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncSetupAndAsyncTeardown");
+    asyncSetupAndAsyncTeardownTestSuite.addTestCase({
+        name: "TestWithSetupAndTeardown",
+        description: "Check execution order for setup and teardown actions.",
+        async setup() {
+            window[asyncSetupAndTeardownSymbol] = 1;
+        },
+        async test() {
+            ProtocolTest.expectThat(window[asyncSetupAndTeardownSymbol] === 1, "Test should see side effects of running setup() action.");
+            window[asyncSetupAndTeardownSymbol] = 2;
+        },
+        async teardown() {
+            ProtocolTest.expectThat(window[asyncSetupAndTeardownSymbol] === 2, "Teardown should see side effects of running setup() action.");
+            window[asyncSetupAndTeardownSymbol] = 3;
+        }
+    });
+    asyncSetupAndAsyncTeardownTestSuite.addTestCase({
+        name: "TestRunningAfterTeardown",
+        description: "Check execution order for test after a teardown action.",
+        test(resolve, reject) {
+            ProtocolTest.expectThat(window[asyncSetupAndTeardownSymbol] === 3, "Test should see side effects of previous test's teardown() action.");
+            resolve();
+        },
+    });
+
+    result = result.then(() => {
+        return asyncSetupAndAsyncTeardownTestSuite.runTestCases();
+    }).then(function resolved() {
+        ProtocolTest.pass("Promise from asyncSetupAndAsyncTeardownTestSuite.runTestCases() should resolve.");
+        return Promise.resolve(); // Continue this test.
+    }, function rejected(e) {
+        ProtocolTest.fail("Promise from asyncSetupAndAsyncTeardownTestSuite.runTestCases() should resolve.");
+        return Promise.resolve(); // Continue this test.
+    });
+
+    // Async setup() failure test cases.
+    let asyncSetupExplicitFailureTestSuiteDidEvaluate = false;
+    let asyncSetupExplicitFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncSetupExplicitFailure");
+    asyncSetupExplicitFailureTestSuite.addTestCase({
+        name: "AsyncFunctionFailure",
+        description: "Check that an async suite with async test functions that throws will reject",
+        async test() {
+            asyncSetupExplicitFailureTestSuiteDidEvaluate = true;
+            throw "AsyncFunctionFailure Exception Message";
+        }
+    });
+
+    result = result.then(() => {
+        return asyncSetupExplicitFailureTestSuite.runTestCases();
+    }).then(function resolve() {
+        ProtocolTest.fail("Promise from asyncSetupExplicitFailureTestSuite.runTestCases() should reject.");
+        return Promise.resolve(); // Continue this test.
+    }, function rejected(e) {
+        ProtocolTest.pass("Promise from asyncSetupExplicitFailureTestSuite.runTestCases() should reject.");
+        ProtocolTest.expectThat(asyncSetupExplicitFailureTestSuiteDidEvaluate, "Promise did evaluate the async setup function.");
+        ProtocolTest.expectEqual(e, "AsyncFunctionFailure Exception Message", "Rejected value should be thrown exception.");
+        return Promise.resolve(); // Continue this test.
+    });
+
+    let asyncSetupRuntimeFailureTestSuiteDidEvaluate = false;
+    let asyncSetupRuntimeFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncSetupRuntimeFailure");
+    asyncSetupRuntimeFailureTestSuite.addTestCase({
+        name: "AsyncFunctionFailure",
+        description: "Check that an async suite with an async setup function that throws with a runtime error will reject",
+        async setup() {
+            asyncSetupRuntimeFailureTestSuiteDidEvaluate = true;
+            ({}).x.x.x;
+        },
+        async test() { return true; },
+    });
+
+    result = result.then(() => {
+        return asyncSetupRuntimeFailureTestSuite.runTestCases();
+    }).then(function resolve() {
+        ProtocolTest.fail("Promise from asyncSetupRuntimeFailureTestSuite.runTestCases() should reject.");
+        return Promise.resolve(); // Continue this test.
+    }, function rejected(e) {
+        ProtocolTest.pass("Promise from asyncSetupRuntimeFailureTestSuite.runTestCases() should reject.");
+        ProtocolTest.expectThat(asyncSetupRuntimeFailureTestSuiteDidEvaluate, "Promise did evaluate the async setup function.");
+        ProtocolTest.expectThat(e instanceof TypeError, "Rejected value should be a runtime exception.");
+        return Promise.resolve(); // Continue this test.
+    });
+
+    // Async teardown() failure test cases.
+    let asyncTeardownExplicitFailureTestSuiteDidEvaluate = false;
+    let asyncTeardownExplicitFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncTeardownExplicitFailure");
+    asyncTeardownExplicitFailureTestSuite.addTestCase({
+        name: "AsyncFunctionFailure",
+        description: "Check that an async suite with async test functions that throws will reject",
+        async test() { return true; },
+        async teardown() {
+            asyncTeardownExplicitFailureTestSuiteDidEvaluate = true;
+            throw "AsyncFunctionFailure Exception Message";
+        },
+    });
+
+    result = result.then(() => {
+        return asyncTeardownExplicitFailureTestSuite.runTestCases();
+    }).then(function resolve() {
+        ProtocolTest.fail("Promise from asyncTeardownExplicitFailureTestSuite.runTestCases() should reject.");
+        return Promise.resolve(); // Continue this test.
+    }, function rejected(e) {
+        ProtocolTest.pass("Promise from asyncTeardownExplicitFailureTestSuite.runTestCases() should reject.");
+        ProtocolTest.expectThat(asyncTeardownExplicitFailureTestSuiteDidEvaluate, "Promise did evaluate the async teardown function.");
+        ProtocolTest.expectEqual(e, "AsyncFunctionFailure Exception Message", "Rejected value should be thrown exception.");
+        return Promise.resolve(); // Continue this test.
+    });
+
+    let asyncTeardownRuntimeFailureTestSuiteDidEvaluate = false;
+    let asyncTeardownRuntimeFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncTeardownRuntimeFailure");
+    asyncTeardownRuntimeFailureTestSuite.addTestCase({
+        name: "AsyncFunctionFailure",
+        description: "Check that an async suite with an async teardown function that throws with a runtime error will reject",
+        async test() { return true; },
+        async teardown() {
+            asyncTeardownRuntimeFailureTestSuiteDidEvaluate = true;
+            ({}).x.x.x;
+        },
+    });
+
+    result = result.then(() => {
+        return asyncTeardownRuntimeFailureTestSuite.runTestCases();
+    }).then(function resolve() {
+        ProtocolTest.fail("Promise from asyncTeardownRuntimeFailureTestSuite.runTestCases() should reject.");
+        return Promise.resolve(); // Continue this test.
+    }, function rejected(e) {
+        ProtocolTest.pass("Promise from asyncTeardownRuntimeFailureTestSuite.runTestCases() should reject.");
+        ProtocolTest.expectThat(asyncTeardownRuntimeFailureTestSuiteDidEvaluate, "Promise did evaluate the async teardown function.");
+        ProtocolTest.expectThat(e instanceof TypeError, "Rejected value should be a runtime exception.");
+        return Promise.resolve(); // Continue this test.
+    });
+
     // This will finish the test whether the chain was resolved or rejected.
     result = result.then(() => { ProtocolTest.completeTest(); });
 }

Modified: trunk/Source/WebInspectorUI/ChangeLog (225819 => 225820)


--- trunk/Source/WebInspectorUI/ChangeLog	2017-12-13 00:11:45 UTC (rev 225819)
+++ trunk/Source/WebInspectorUI/ChangeLog	2017-12-13 00:31:15 UTC (rev 225820)
@@ -1,5 +1,19 @@
 2017-12-12  Brian Burg  <bb...@apple.com>
 
+        Web Inspector: support async setup() and async teardown() in AsyncTestSuite
+        https://bugs.webkit.org/show_bug.cgi?id=180626
+
+        Reviewed by Timothy Hatcher.
+
+        This can make some code simpler by removing Promise-related boilerplate. I'm splitting
+        this patch from the new use-site in the interest of making it easier to review.
+
+        * UserInterface/Test/TestSuite.js:
+        (AsyncTestSuite.prototype.runTestCases):
+        (AsyncTestSuite):
+
+2017-12-12  Brian Burg  <bb...@apple.com>
+
         Web Inspector: SyncTestSuite should complain if passed an async setup/test/teardown function
         https://bugs.webkit.org/show_bug.cgi?id=180717
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Test/TestSuite.js (225819 => 225820)


--- trunk/Source/WebInspectorUI/UserInterface/Test/TestSuite.js	2017-12-13 00:11:45 UTC (rev 225819)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/TestSuite.js	2017-12-13 00:31:15 UTC (rev 225820)
@@ -139,6 +139,8 @@
             if (testcase.setup) {
                 chain = chain.then(() => {
                     this._harness.log("-- Running test setup.");
+                    if (testcase.setup[Symbol.toStringTag] === "AsyncFunction")
+                        return testcase.setup();
                     return new Promise(testcase.setup);
                 });
             }
@@ -158,6 +160,8 @@
             if (testcase.teardown) {
                 chain = chain.then(() => {
                     this._harness.log("-- Running test teardown.");
+                    if (testcase.teardown[Symbol.toStringTag] === "AsyncFunction")
+                        return testcase.teardown();
                     return new Promise(testcase.teardown);
                 });
             }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to