Web Inspector: InspectorTest.evaluateInPage should return a rejection if an error...
authorbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Dec 2017 01:29:57 +0000 (01:29 +0000)
committerbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Dec 2017 01:29:57 +0000 (01:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180956

Reviewed by Joseph Pecoraro.

Source/WebInspectorUI:

* UserInterface/Test/FrontendTestHarness.js:
(FrontendTestHarness.prototype.evaluateInPage.translateResult): Renamed.
(FrontendTestHarness.prototype.evaluateInPage):
If the result was thrown, then reject with the error.
Rename the helper method to match the same one in RemoteObject.prototype.fetchProperties.

LayoutTests:

* inspector/unit-tests/test-harness-evaluate-in-page-expected.txt:
* inspector/unit-tests/test-harness-evaluate-in-page.html:
Update test case to expect an exception when an error was thrown in our evaluation.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226163 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/unit-tests/test-harness-evaluate-in-page-expected.txt
LayoutTests/inspector/unit-tests/test-harness-evaluate-in-page.html
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Test/FrontendTestHarness.js

index fe99619..77582a5 100644 (file)
@@ -1,3 +1,14 @@
+2017-12-19  Brian Burg  <bburg@apple.com>
+
+        Web Inspector: InspectorTest.evaluateInPage should return a rejection if an error was thrown
+        https://bugs.webkit.org/show_bug.cgi?id=180956
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/unit-tests/test-harness-evaluate-in-page-expected.txt:
+        * inspector/unit-tests/test-harness-evaluate-in-page.html:
+        Update test case to expect an exception when an error was thrown in our evaluation.
+
 2017-12-19  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream] Clean up RealtimeMediaSource interfaces
index df2a192..93a2fdf 100644 (file)
@@ -142,9 +142,7 @@ PASS: Type of evaluation result should be 'object'.
 PASS: Subtype of evaluation result should be 'error'.
 
 Checking result of evaluating string: throw new Error(42)
-PASS: Returned result should be a WI.RemoteObject.
-PASS: Non-primitive evaluation results should not have a marshalled value.
-PASS: Type of evaluation result should be 'object'.
-PASS: Subtype of evaluation result should be 'error'.
+PASS: Should produce an exception.
+Error: Error: 42
 
 
index 7ebe82a..57522da 100644 (file)
@@ -104,6 +104,7 @@ function test()
             input: `throw new Error(42)`,
             type: "object",
             subtype: "error",
+            thrown: true,
         },
     ];
 
@@ -139,12 +140,20 @@ function test()
         name: "evaluateInPage.RemoteObjects",
         async test() {
             for (let {input, type, subtype, thrown} of complexCases) {
-                let result = await InspectorTest.evaluateInPage(input);
                 InspectorTest.log(`Checking result of evaluating string: ${input}`);
-                InspectorTest.expectThat(result instanceof WI.RemoteObject, "Returned result should be a WI.RemoteObject.");
-                InspectorTest.expectFalse(result.hasValue(), "Non-primitive evaluation results should not have a marshalled value.");
-                InspectorTest.expectEqual(result.type, type, `Type of evaluation result should be '${type}'.`);
-                InspectorTest.expectEqual(result.subtype, subtype, `Subtype of evaluation result should be '${subtype}'.`);
+
+                if (thrown) {
+                    await InspectorTest.expectException(async () => {
+                        await InspectorTest.evaluateInPage(input);
+                    });
+                } else {
+                    let result = await InspectorTest.evaluateInPage(input);
+                    InspectorTest.expectThat(result instanceof WI.RemoteObject, "Returned result should be a WI.RemoteObject.");
+                    InspectorTest.expectFalse(result.hasValue(), "Non-primitive evaluation results should not have a marshalled value.");
+                    InspectorTest.expectEqual(result.type, type, `Type of evaluation result should be '${type}'.`);
+                    InspectorTest.expectEqual(result.subtype, subtype, `Subtype of evaluation result should be '${subtype}'.`);
+                }
+
                 InspectorTest.log("");
             }
         }
index 8e8949a..c10b45b 100644 (file)
@@ -1,3 +1,16 @@
+2017-12-19  Brian Burg  <bburg@apple.com>
+
+        Web Inspector: InspectorTest.evaluateInPage should return a rejection if an error was thrown
+        https://bugs.webkit.org/show_bug.cgi?id=180956
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Test/FrontendTestHarness.js:
+        (FrontendTestHarness.prototype.evaluateInPage.translateResult):┬áRenamed.
+        (FrontendTestHarness.prototype.evaluateInPage):
+        If the result was thrown, then reject with the error.
+        Rename the helper method to match the same one in RemoteObject.prototype.fetchProperties.
+
 2017-12-19  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Network Table - Redesign the waterfall popover showing timing data
index ea9b980..023195f 100644 (file)
@@ -89,17 +89,24 @@ FrontendTestHarness = class FrontendTestHarness extends TestHarness
         }
 
         // Return primitive values directly, otherwise return a WI.RemoteObject instance.
-        function resultObjectToReturn(result) {
+        function translateResult(result) {
             let remoteObject = WI.RemoteObject.fromPayload(result);
             return (!remoteObjectOnly && remoteObject.hasValue()) ? remoteObject.value : remoteObject;
         }
 
         let response = RuntimeAgent.evaluate.invoke({expression, objectGroup: "test", includeCommandLineAPI: false})
         if (callback && typeof callback === "function") {
-            response = response.then(({result, wasThrown}) => callback(null, resultObjectToReturn(result), wasThrown));
+            response = response.then(({result, wasThrown}) => callback(null, translateResult(result), wasThrown));
             response = response.catch((error) => callback(error, null, false));
-        } else
-            return response.then(({result}) => resultObjectToReturn(result));
+        } else {
+            // Turn a thrown Error result into a promise rejection.
+            return response.then(({result, wasThrown}) => {
+                result = translateResult(result);
+                if (result && wasThrown)
+                    return Promise.reject(new Error(result.description));
+                return Promise.resolve(result);
+            });
+        }
     }
 
     debug()