Title: [226163] trunk
Revision
226163
Author
[email protected]
Date
2017-12-19 17:29:57 -0800 (Tue, 19 Dec 2017)

Log Message

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.

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.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (226162 => 226163)


--- trunk/LayoutTests/ChangeLog	2017-12-20 01:15:58 UTC (rev 226162)
+++ trunk/LayoutTests/ChangeLog	2017-12-20 01:29:57 UTC (rev 226163)
@@ -1,3 +1,14 @@
+2017-12-19  Brian Burg  <[email protected]>
+
+        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  <[email protected]>
 
         [MediaStream] Clean up RealtimeMediaSource interfaces

Modified: trunk/LayoutTests/inspector/unit-tests/test-harness-evaluate-in-page-expected.txt (226162 => 226163)


--- trunk/LayoutTests/inspector/unit-tests/test-harness-evaluate-in-page-expected.txt	2017-12-20 01:15:58 UTC (rev 226162)
+++ trunk/LayoutTests/inspector/unit-tests/test-harness-evaluate-in-page-expected.txt	2017-12-20 01:29:57 UTC (rev 226163)
@@ -142,9 +142,7 @@
 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
 
 

Modified: trunk/LayoutTests/inspector/unit-tests/test-harness-evaluate-in-page.html (226162 => 226163)


--- trunk/LayoutTests/inspector/unit-tests/test-harness-evaluate-in-page.html	2017-12-20 01:15:58 UTC (rev 226162)
+++ trunk/LayoutTests/inspector/unit-tests/test-harness-evaluate-in-page.html	2017-12-20 01:29:57 UTC (rev 226163)
@@ -104,6 +104,7 @@
             input: `throw new Error(42)`,
             type: "object",
             subtype: "error",
+            thrown: true,
         },
     ];
 
@@ -139,12 +140,20 @@
         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("");
             }
         }

Modified: trunk/Source/WebInspectorUI/ChangeLog (226162 => 226163)


--- trunk/Source/WebInspectorUI/ChangeLog	2017-12-20 01:15:58 UTC (rev 226162)
+++ trunk/Source/WebInspectorUI/ChangeLog	2017-12-20 01:29:57 UTC (rev 226163)
@@ -1,3 +1,16 @@
+2017-12-19  Brian Burg  <[email protected]>
+
+        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  <[email protected]>
 
         Web Inspector: Network Table - Redesign the waterfall popover showing timing data

Modified: trunk/Source/WebInspectorUI/UserInterface/Test/FrontendTestHarness.js (226162 => 226163)


--- trunk/Source/WebInspectorUI/UserInterface/Test/FrontendTestHarness.js	2017-12-20 01:15:58 UTC (rev 226162)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/FrontendTestHarness.js	2017-12-20 01:29:57 UTC (rev 226163)
@@ -89,7 +89,7 @@
         }
 
         // 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;
         }
@@ -96,10 +96,17 @@
 
         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()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to