Title: [223809] trunk
Revision
223809
Author
[email protected]
Date
2017-10-20 23:52:47 -0700 (Fri, 20 Oct 2017)

Log Message

Web Inspector: Support `async test() { ... }` in Inspector Test Suites
https://bugs.webkit.org/show_bug.cgi?id=178614

Patch by Joseph Pecoraro <[email protected]> on 2017-10-20
Reviewed by Devin Rousso.

Add the ability to have test functions be async functions. A successful
async test function just needs to complete evaluation. To indicate
failure it should throw an exception.

    suite.addTestCase({
        name: "ExceptionOfNormal",
        async test() {
            InspectorTest.expectThat(...);
        }
    });

    suite.addTestCase({
        name: "ExampleOfRejection",
        async test() {
            let value = await SomeAgent.method();
            if (value.error)
                throw "Exception";
            ...
        }
    });

Using async test functions has the added benefit that a runtime exception
inside of asynchronous test code will reject the current test case instead
of timing out. For example...

    suite.addTestCase({
        name: "ExampleOfRejectionThroughRuntimeException",
        async test() {
            let arr = [];
            arr.this.does.not.exist;
        }
    });

... should will lead to a failure instead of a timeout.

This should allow us to structure some common tests more naturally, like so:

    suite.addTestCase({
        name: "ExampleOfNormalAsyncTest",
        async test() {
            InspectorTest.evaluateInPage(`...`);
            let event = await WI.Manager.awaitEvent(...);
            let resource = event.data.resource;
            InspectorTest.expectEqual(...);
            InspectorTest.expectEqual(...);
            InspectorTest.expectEqual(...);
        }
    });

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

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (223808 => 223809)


--- trunk/LayoutTests/ChangeLog	2017-10-21 06:16:54 UTC (rev 223808)
+++ trunk/LayoutTests/ChangeLog	2017-10-21 06:52:47 UTC (rev 223809)
@@ -1,3 +1,63 @@
+2017-10-20  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: Support `async test() { ... }` in Inspector Test Suites
+        https://bugs.webkit.org/show_bug.cgi?id=178614
+
+        Reviewed by Devin Rousso.
+
+        Add the ability to have test functions be async functions. A successful
+        async test function just needs to complete evaluation. To indicate
+        failure it should throw an exception.
+
+            suite.addTestCase({
+                name: "ExceptionOfNormal",
+                async test() {
+                    InspectorTest.expectThat(...);
+                }
+            });
+
+            suite.addTestCase({
+                name: "ExampleOfRejection",
+                async test() {
+                    let value = await SomeAgent.method();
+                    if (value.error)
+                        throw "Exception";
+                    ...
+                }
+            });
+
+        Using async test functions has the added benefit that a runtime exception
+        inside of asynchronous test code will reject the current test case instead
+        of timing out. For example...
+        
+            suite.addTestCase({
+                name: "ExampleOfRejectionThroughRuntimeException",
+                async test() {
+                    let arr = [];
+                    arr.this.does.not.exist;
+                }
+            });
+        
+        ... should will lead to a failure instead of a timeout.
+        
+        This should allow us to structure some common tests more naturally, like so:
+
+            suite.addTestCase({
+                name: "ExampleOfNormalAsyncTest",
+                async test() {
+                    InspectorTest.evaluateInPage(`...`);
+                    let event = await WI.Manager.awaitEvent(...);
+                    let resource = event.data.resource;
+                    InspectorTest.expectEqual(...);
+                    InspectorTest.expectEqual(...);
+                    InspectorTest.expectEqual(...);
+                }
+            });
+
+        * inspector/unit-tests/async-test-suite-expected.txt:
+        * inspector/unit-tests/async-test-suite.html:
+        * inspector/unit-tests/target-manager.html:
+
 2017-10-20  Ryosuke Niwa  <[email protected]>
 
         http/tests/security/clipboard/drag-drop-html-cross-origin-iframe-in-same-origin.html is flaky

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


--- trunk/LayoutTests/inspector/unit-tests/async-test-suite-expected.txt	2017-10-21 06:16:54 UTC (rev 223808)
+++ trunk/LayoutTests/inspector/unit-tests/async-test-suite-expected.txt	2017-10-21 06:52:47 UTC (rev 223809)
@@ -83,3 +83,25 @@
 Stack Trace: (suppressed)
 PASS: Promise from teardownFailureTestSuite.runTestCases() should reject.
 
+== Running test suite: AsyncTestSuite.AsyncFunctionSuccess
+-- Running test case: AsyncFunctionSuccess
+PASS: Promise from asyncFunctionSuccessTestSuite.runTestCases() should succeed.
+PASS: Promise did evaluate the async test function.
+PASS: Resolved value should be 42.
+
+== Running test suite: AsyncTestSuite.AsyncFunctionExplicitFailure
+-- Running test case: AsyncFunctionFailure
+!! EXCEPTION: AsyncFunctionFailure Exception Message
+Stack Trace: (suppressed)
+PASS: Promise from asyncFunctionExplicitFailureTestSuite.runTestCases() should reject.
+PASS: Promise did evaluate the async test function.
+PASS: Rejected value should be thrown exception.
+
+== Running test suite: AsyncTestSuite.AsyncFunctionRuntimeFailure
+-- Running test case: AsyncFunctionFailure
+!! EXCEPTION: undefined is not an object (evaluating '({}).x.x')
+Stack Trace: (suppressed)
+PASS: Promise from asyncFunctionRuntimeFailureTestSuite.runTestCases() should reject.
+PASS: Promise did evaluate the async test function.
+PASS: Rejected value should be a runtime exception.
+

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


--- trunk/LayoutTests/inspector/unit-tests/async-test-suite.html	2017-10-21 06:16:54 UTC (rev 223808)
+++ trunk/LayoutTests/inspector/unit-tests/async-test-suite.html	2017-10-21 06:52:47 UTC (rev 223809)
@@ -9,44 +9,44 @@
 
     try {
         let result = new AsyncTestSuite(this);
-        ProtocolTest.log("FAIL: instantiating AsyncTestSuite requires name argument.");
+        ProtocolTest.fail("instantiating AsyncTestSuite requires name argument.");
     } catch (e) {
-        ProtocolTest.log("PASS: instantiating AsyncTestSuite requires name argument.");
+        ProtocolTest.pass("instantiating AsyncTestSuite requires name argument.");
     }
 
     try {
         let result = new AsyncTestSuite(this, {});
-        ProtocolTest.log("FAIL: instantiating AsyncTestSuite requires string name argument.");
+        ProtocolTest.fail("instantiating AsyncTestSuite requires string name argument.");
     } catch (e) {
-        ProtocolTest.log("PASS: instantiating AsyncTestSuite requires string name argument.");
+        ProtocolTest.pass("instantiating AsyncTestSuite requires string name argument.");
     }
 
     try {
         let result = new AsyncTestSuite(this, "      ");
-        ProtocolTest.log("FAIL: instantiating AsyncTestSuite requires non-whitespace name argument.");
+        ProtocolTest.fail("instantiating AsyncTestSuite requires non-whitespace name argument.");
     } catch (e) {
-        ProtocolTest.log("PASS: instantiating AsyncTestSuite requires non-whitespace name argument.");
+        ProtocolTest.pass("instantiating AsyncTestSuite requires non-whitespace name argument.");
     }
 
     try {
         let result = new AsyncTestSuite("something", {});
-        ProtocolTest.log("FAIL: instantiating AsyncTestSuite requires test harness argument.");
+        ProtocolTest.fail("instantiating AsyncTestSuite requires test harness argument.");
     } catch (e) {
-        ProtocolTest.log("PASS: instantiating AsyncTestSuite requires test harness argument.");
+        ProtocolTest.pass("instantiating AsyncTestSuite requires test harness argument.");
     }
 
     let badArgsSuite = ProtocolTest.createAsyncSuite("dummy");
     try {
         badArgsSuite.addTestCase();
-        ProtocolTest.log("FAIL: should not be able to add empty test case.");
+        ProtocolTest.fail("should not be able to add empty test case.");
     } catch (e) {
-        ProtocolTest.log("PASS: should not be able to add empty test case.");
+        ProtocolTest.pass("should not be able to add empty test case.");
     }
     try {
         badArgsSuite.addTestCase("string");
-        ProtocolTest.log("FAIL: should not be able to add non-object test case.");
+        ProtocolTest.fail("should not be able to add non-object test case.");
     } catch (e) {
-        ProtocolTest.log("PASS: should not be able to add non-object test case.");
+        ProtocolTest.pass("should not be able to add non-object test case.");
     }
     try {
         badArgsSuite.addTestCase({
@@ -53,9 +53,9 @@
             name: {},
             test() {},
         });
-        ProtocolTest.log("FAIL: test case should require string name.");
+        ProtocolTest.fail("test case should require string name.");
     } catch (e) {
-        ProtocolTest.log("PASS: test case should require string name.");
+        ProtocolTest.pass("test case should require string name.");
     }
     try {
         badArgsSuite.addTestCase({
@@ -62,9 +62,9 @@
             name: "        ",
             test() {},
         });
-        ProtocolTest.log("FAIL: test case should require non-whitespace name.");
+        ProtocolTest.fail("test case should require non-whitespace name.");
     } catch (e) {
-        ProtocolTest.log("PASS: test case should require non-whitespace name.");
+        ProtocolTest.pass("test case should require non-whitespace name.");
     }
     try {
         badArgsSuite.addTestCase({
@@ -71,9 +71,9 @@
             name: "foo",
             test: null,
         });
-        ProtocolTest.log("FAIL: test case should require test function.");
+        ProtocolTest.fail("test case should require test function.");
     } catch (e) {
-        ProtocolTest.log("PASS: test case should require test function.");
+        ProtocolTest.pass("test case should require test function.");
     }
     try {
         badArgsSuite.addTestCase({
@@ -81,9 +81,9 @@
             test() {},
             setup: "astd"
         });
-        ProtocolTest.log("FAIL: should not be able to specify non-Function `setup` parameter.");
+        ProtocolTest.fail("should not be able to specify non-Function `setup` parameter.");
     } catch (e) {
-        ProtocolTest.log("PASS: should not be able to specify non-Function `setup` parameter.");
+        ProtocolTest.pass("should not be able to specify non-Function `setup` parameter.");
     }
     try {
         badArgsSuite.addTestCase({
@@ -91,9 +91,9 @@
             test() {},
             setup: 123
         });
-        ProtocolTest.log("FAIL: should not be able to specify non-Function `setup` parameter.");
+        ProtocolTest.fail("should not be able to specify non-Function `setup` parameter.");
     } catch (e) {
-        ProtocolTest.log("PASS: should not be able to specify non-Function `setup` parameter.");
+        ProtocolTest.pass("should not be able to specify non-Function `setup` parameter.");
     }
     try {
         badArgsSuite.addTestCase({
@@ -101,9 +101,9 @@
             test() {},
             setup: {}
         });
-        ProtocolTest.log("FAIL: should not be able to specify non-Function `setup` parameter.");
+        ProtocolTest.fail("should not be able to specify non-Function `setup` parameter.");
     } catch (e) {
-        ProtocolTest.log("PASS: should not be able to specify non-Function `setup` parameter.");
+        ProtocolTest.pass("should not be able to specify non-Function `setup` parameter.");
     }
     try {
         badArgsSuite.addTestCase({
@@ -111,9 +111,9 @@
             test() {},
             teardown: "astd"
         });
-        ProtocolTest.log("FAIL: should not be able to specify non-Function `teardown` parameter.");
+        ProtocolTest.fail("should not be able to specify non-Function `teardown` parameter.");
     } catch (e) {
-        ProtocolTest.log("PASS: should not be able to specify non-Function `teardown` parameter.");
+        ProtocolTest.pass("should not be able to specify non-Function `teardown` parameter.");
     }
     try {
         badArgsSuite.addTestCase({
@@ -121,9 +121,9 @@
             test() {},
             teardown: 123
         });
-        ProtocolTest.log("FAIL: should not be able to specify non-Function `teardown` parameter.");
+        ProtocolTest.fail("should not be able to specify non-Function `teardown` parameter.");
     } catch (e) {
-        ProtocolTest.log("PASS: should not be able to specify non-Function `teardown` parameter.");
+        ProtocolTest.pass("should not be able to specify non-Function `teardown` parameter.");
     }
     try {
         badArgsSuite.addTestCase({
@@ -131,17 +131,17 @@
             test() {},
             teardown: {}
         });
-        ProtocolTest.log("FAIL: should not be able to specify non-Function `teardown` parameter.");
+        ProtocolTest.fail("should not be able to specify non-Function `teardown` parameter.");
     } catch (e) {
-        ProtocolTest.log("PASS: should not be able to specify non-Function `teardown` parameter.");
+        ProtocolTest.pass("should not be able to specify non-Function `teardown` parameter.");
     }
 
     let runEmptySuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.RunEmptySuite");
     try {
         runEmptySuite.runTestCases();
-        ProtocolTest.log("FAIL: should not be able to run empty test suite.");
+        ProtocolTest.fail("should not be able to run empty test suite.");
     } catch (e) {
-        ProtocolTest.log("PASS: should not be able to run empty test suite.");
+        ProtocolTest.pass("should not be able to run empty test suite.");
     }
 
     let runTwiceSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.RunTwiceSuite");
@@ -156,9 +156,9 @@
         // Test cases won't run in this event loop; this call should still throw.
         // Later tests are chained to this suite to avoid nondeterminism.
         runTwiceSuite.runTestCases();
-        ProtocolTest.log("FAIL: should not be able to run a test suite twice.");
+        ProtocolTest.fail("should not be able to run a test suite twice.");
     } catch (e) {
-        ProtocolTest.log("PASS: should not be able to run a test suite twice.");
+        ProtocolTest.pass("should not be able to run a test suite twice.");
     }
 
     let rejectToken = {"token": 666};
@@ -209,10 +209,10 @@
         return promise;
     });
     result = result.then(function resolved() {
-        ProtocolTest.log("FAIL: Promise from sequentialExecutionSuite.runTestCases() should reject when a test case fails.");
+        ProtocolTest.fail("Promise from sequentialExecutionSuite.runTestCases() should reject when a test case fails.");
         return Promise.resolve(); // Continue this test.
     }, function rejected(e) {
-        ProtocolTest.log("PASS: Promise from sequentialExecutionSuite.runTestCases() should reject when a test case fails.");
+        ProtocolTest.pass("Promise from sequentialExecutionSuite.runTestCases() should reject when a test case fails.");
         ProtocolTest.expectThat(e === thrownError, "Promise from sequentialExecutionSuite.runTestCases() should reject without altering its result value.");
 
         ProtocolTest.expectThat(sequentialExecutionSuite.runCount === 4, "sequentialExecutionSuite should have executed four tests.");
@@ -225,10 +225,10 @@
     result = result.then(() => {
         return abortOnFailureSuite.runTestCases();
     }).then(function resolved() {
-        ProtocolTest.log("FAIL: Promise from abortOnFailureSuite.runTestCases() should reject when a test case fails.");
+        ProtocolTest.fail("Promise from abortOnFailureSuite.runTestCases() should reject when a test case fails.");
         return Promise.resolve(); // Continue this test.
     }, function rejected(e) {
-        ProtocolTest.log("PASS: Promise from abortOnFailureSuite.runTestCases() should reject when a test case fails.");
+        ProtocolTest.pass("Promise from abortOnFailureSuite.runTestCases() should reject when a test case fails.");
         ProtocolTest.expectThat(e === rejectToken, "Promise from abortOnFailureSuite.runTestCases() should reject without altering its result value.");
         ProtocolTest.expectThat(abortOnFailureSuite.runCount === 2, "abortOnFailureSuite should have executed two tests.");
         ProtocolTest.expectThat(abortOnFailureSuite.passCount === 1, "abortOnFailureSuite should have passed one test.");
@@ -272,10 +272,10 @@
     result = result.then(() => {
         return setupAndTeardownTestSuite.runTestCases();
     }).then(function resolved() {
-        ProtocolTest.log("PASS: Promise from setupAndTeardownTestSuite.runTestCases() should resolve.");
+        ProtocolTest.pass("Promise from setupAndTeardownTestSuite.runTestCases() should resolve.");
         return Promise.resolve(); // Continue this test.
     }, function rejected(e) {
-        ProtocolTest.log("FAIL: Promise from setupAndTeardownTestSuite.runTestCases() should resolve.");
+        ProtocolTest.fail("Promise from setupAndTeardownTestSuite.runTestCases() should resolve.");
         return Promise.resolve(); // Continue this test.
     });
 
@@ -297,10 +297,10 @@
     result = result.then(() => {
         return setupExceptionTestSuite.runTestCases();
     }).then(function resolved() {
-        ProtocolTest.log("FAIL: Promise from setupExceptionTestSuite.runTestCases() should reject.");
+        ProtocolTest.fail("Promise from setupExceptionTestSuite.runTestCases() should reject.");
         return Promise.resolve(); // Continue this test.
     }, function rejected(e) {
-        ProtocolTest.log("PASS: Promise from setupExceptionTestSuite.runTestCases() should reject.");
+        ProtocolTest.pass("Promise from setupExceptionTestSuite.runTestCases() should reject.");
         return Promise.resolve(); // Continue this test.
     });
 
@@ -322,10 +322,10 @@
     result = result.then(() => {
         return setupFailureTestSuite.runTestCases();
     }).then(function resolved() {
-        ProtocolTest.log("FAIL: Promise from setupFailureTestSuite.runTestCases() should reject.");
+        ProtocolTest.fail("Promise from setupFailureTestSuite.runTestCases() should reject.");
         return Promise.resolve(); // Continue this test.
     }, function rejected(e) {
-        ProtocolTest.log("PASS: Promise from setupFailureTestSuite.runTestCases() should reject.");
+        ProtocolTest.pass("Promise from setupFailureTestSuite.runTestCases() should reject.");
         return Promise.resolve(); // Continue this test.
     });
 
@@ -352,10 +352,10 @@
     result = result.then(() => {
         return teardownExceptionTestSuite.runTestCases();
     }).then(function resolved() {
-        ProtocolTest.log("FAIL: Promise from teardownExceptionTestSuite.runTestCases() should reject.");
+        ProtocolTest.fail("Promise from teardownExceptionTestSuite.runTestCases() should reject.");
         return Promise.resolve(); // Continue this test.
     }, function rejected(e) {
-        ProtocolTest.log("PASS: Promise from teardownExceptionTestSuite.runTestCases() should reject.");
+        ProtocolTest.pass("Promise from teardownExceptionTestSuite.runTestCases() should reject.");
         return Promise.resolve(); // Continue this test.
     });
 
@@ -382,13 +382,85 @@
     result = result.then(() => {
         return teardownFailureTestSuite.runTestCases();
     }).then(function resolved() {
-        ProtocolTest.log("FAIL: Promise from teardownFailureTestSuite.runTestCases() should reject.");
+        ProtocolTest.fail("Promise from teardownFailureTestSuite.runTestCases() should reject.");
         return Promise.resolve(); // Continue this test.
     }, function rejected(e) {
-        ProtocolTest.log("PASS: Promise from teardownFailureTestSuite.runTestCases() should reject.");
+        ProtocolTest.pass("Promise from teardownFailureTestSuite.runTestCases() should reject.");
         return Promise.resolve(); // Continue this test.
     });
 
+
+    let asyncFunctionSuccessTestSuiteDidEvaluate = false;
+    let asyncFunctionSuccessTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncFunctionSuccess");
+    asyncFunctionSuccessTestSuite.addTestCase({
+        name: "AsyncFunctionSuccess",
+        description: "Check that an async suite with async test functions can succeed",
+        async test() {
+            asyncFunctionSuccessTestSuiteDidEvaluate = true;
+            return 42;
+        }
+    });
+
+    result = result.then(() => {
+        return asyncFunctionSuccessTestSuite.runTestCases();
+    }).then(function resolve(x) {
+        ProtocolTest.pass("Promise from asyncFunctionSuccessTestSuite.runTestCases() should succeed.");
+        ProtocolTest.expectThat(asyncFunctionSuccessTestSuiteDidEvaluate, "Promise did evaluate the async test function.");
+        ProtocolTest.expectEqual(x, 42, "Resolved value should be 42.");
+        return Promise.resolve(); // Continue this test.
+    }, function rejected(e) {
+        ProtocolTest.fail("Promise from asyncFunctionSuccessTestSuite.runTestCases() should succeed.");
+        return Promise.resolve(); // Continue this test.
+    });
+
+
+    let asyncFunctionExplicitFailureTestSuiteDidEvaluate = false;
+    let asyncFunctionExplicitFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncFunctionExplicitFailure");
+    asyncFunctionExplicitFailureTestSuite.addTestCase({
+        name: "AsyncFunctionFailure",
+        description: "Check that an async suite with async test functions that throws will reject",
+        async test() {
+            asyncFunctionExplicitFailureTestSuiteDidEvaluate = true;
+            throw "AsyncFunctionFailure Exception Message";
+        }
+    });
+
+    result = result.then(() => {
+        return asyncFunctionExplicitFailureTestSuite.runTestCases();
+    }).then(function resolve() {
+        ProtocolTest.fail("Promise from asyncFunctionExplicitFailureTestSuite.runTestCases() should reject.");
+        return Promise.resolve(); // Continue this test.
+    }, function rejected(e) {
+        ProtocolTest.pass("Promise from asyncFunctionExplicitFailureTestSuite.runTestCases() should reject.");
+        ProtocolTest.expectThat(asyncFunctionExplicitFailureTestSuiteDidEvaluate, "Promise did evaluate the async test function.");
+        ProtocolTest.expectEqual(e, "AsyncFunctionFailure Exception Message", "Rejected value should be thrown exception.");
+        return Promise.resolve(); // Continue this test.
+    });
+
+
+    let asyncFunctionRuntimeFailureTestSuiteDidEvaluate = false;
+    let asyncFunctionRuntimeFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncFunctionRuntimeFailure");
+    asyncFunctionRuntimeFailureTestSuite.addTestCase({
+        name: "AsyncFunctionFailure",
+        description: "Check that an async suite with async test functions that throws with a runtime error will reject",
+        async test() {
+            asyncFunctionRuntimeFailureTestSuiteDidEvaluate = true;
+            ({}).x.x.x;
+        }
+    });
+
+    result = result.then(() => {
+        return asyncFunctionRuntimeFailureTestSuite.runTestCases();
+    }).then(function resolve() {
+        ProtocolTest.fail("Promise from asyncFunctionRuntimeFailureTestSuite.runTestCases() should reject.");
+        return Promise.resolve(); // Continue this test.
+    }, function rejected(e) {
+        ProtocolTest.pass("Promise from asyncFunctionRuntimeFailureTestSuite.runTestCases() should reject.");
+        ProtocolTest.expectThat(asyncFunctionRuntimeFailureTestSuiteDidEvaluate, "Promise did evaluate the async test 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/LayoutTests/inspector/unit-tests/target-manager.html (223808 => 223809)


--- trunk/LayoutTests/inspector/unit-tests/target-manager.html	2017-10-21 06:16:54 UTC (rev 223808)
+++ trunk/LayoutTests/inspector/unit-tests/target-manager.html	2017-10-21 06:52:47 UTC (rev 223809)
@@ -37,7 +37,7 @@
     suite.addTestCase({
         name: "TargetManager.MainTarget",
         description: "We should always have the main target.",
-        test(resolve, reject) {
+        async test() {
             InspectorTest.assert(WI.targets === WI.targetManager.targets);
             InspectorTest.expectEqual(WI.targets.size, 1, "Targets list should always start out with the main target.");
             InspectorTest.expectEqual([...WI.targets][0], WI.mainTarget, "Target list should always contain the main target.");
@@ -44,7 +44,6 @@
             InspectorTest.expectNotNull(WI.mainTarget.executionContext, "Main target should have an ExecutionContext.");
             InspectorTest.expectEqual(WI.mainTarget.RuntimeAgent, RuntimeAgent, "Main target should have the global RuntimeAgent.");
             dumpTargets();
-            resolve();
         }
     });
 
@@ -51,18 +50,16 @@
     suite.addTestCase({
         name: "TargetManager.WorkerTarget.Create",
         description: "Creating a Worker should create a new Worker Target.",
-        test(resolve, reject) {
+        async test() {
             InspectorTest.evaluateInPage("createWorker()");
-            WI.targetManager.singleFireEventListener(WI.TargetManager.Event.TargetAdded, (event) => {
-                let target = event.data.target;
-                InspectorTest.assert(target instanceof WI.Target);
-                InspectorTest.expectEqual(target.type, WI.Target.Type.Worker, "Added Target should have Worker type.");
-                InspectorTest.expectNotNull(target.executionContext, "Added Target should have an ExecutionContext.");
-                InspectorTest.expectNotNull(target.RuntimeAgent, "Added Target should have a RuntimeAgent.");
-                InspectorTest.expectNotEqual(target.RuntimeAgent, RuntimeAgent, "Added Target RuntimeAgent should not be the global RuntimeAgent.");
-                dumpTargets();
-                resolve();
-            });
+            let event = await WI.targetManager.awaitEvent(WI.TargetManager.Event.TargetAdded);
+            let target = event.data.target;
+            InspectorTest.assert(target instanceof WI.Target);
+            InspectorTest.expectEqual(target.type, WI.Target.Type.Worker, "Added Target should have Worker type.");
+            InspectorTest.expectNotNull(target.executionContext, "Added Target should have an ExecutionContext.");
+            InspectorTest.expectNotNull(target.RuntimeAgent, "Added Target should have a RuntimeAgent.");
+            InspectorTest.expectNotEqual(target.RuntimeAgent, RuntimeAgent, "Added Target RuntimeAgent should not be the global RuntimeAgent.");
+            dumpTargets();
         }
     });
 
@@ -69,15 +66,13 @@
     suite.addTestCase({
         name: "TargetManager.WorkerTarget.Remove",
         description: "Creating a Worker should create a new Worker Target.",
-        test(resolve, reject) {
+        async test() {
             InspectorTest.evaluateInPage("terminateWorker()");
-            WI.targetManager.singleFireEventListener(WI.TargetManager.Event.TargetRemoved, (event) => {
-                let target = event.data.target;
-                InspectorTest.assert(target instanceof WI.Target);
-                InspectorTest.expectEqual(target.type, WI.Target.Type.Worker, "Removed Target should have Worker type.");
-                dumpTargets();
-                resolve();
-            });
+            let event = await WI.targetManager.awaitEvent(WI.TargetManager.Event.TargetRemoved);
+            let target = event.data.target;
+            InspectorTest.assert(target instanceof WI.Target);
+            InspectorTest.expectEqual(target.type, WI.Target.Type.Worker, "Removed Target should have Worker type.");
+            dumpTargets();
         }
     });
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Test/TestSuite.js (223808 => 223809)


--- trunk/Source/WebInspectorUI/UserInterface/Test/TestSuite.js	2017-10-21 06:16:54 UTC (rev 223808)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/TestSuite.js	2017-10-21 06:52:47 UTC (rev 223809)
@@ -150,6 +150,8 @@
                 priorLogCount = this._harness.logCount;
                 this._harness.log(`-- Running test case: ${testcase.name}`);
                 this.runCount++;
+                if (testcase.test[Symbol.toStringTag] === "AsyncFunction")
+                    return testcase.test();
                 return new Promise(testcase.test);
             });
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to