Web Inspector: Audit: attempt to re-link DOM nodes for imported results
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 22:00:34 +0000 (22:00 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 22:00:34 +0000 (22:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191044
<rdar://problem/45687364>

Reviewed by Brian Burg.

Source/WebInspectorUI:

When importing a `WI.AuditTestCaseResult`, attempt to `querySelector` for each item in
`data.domNodes`. If a node is found, replace it with that node and show a tree instead.

* UserInterface/Models/AuditTestCase.js:
(WI.AuditTestCase.async fromPayload): Added.
(WI.AuditTestCase.fromPayload): Deleted.

* UserInterface/Models/AuditTestGroup.js:
(WI.AuditTestGroup.async fromPayload): Added.
(WI.AuditTestGroup.fromPayload): Deleted.

* UserInterface/Models/AuditTestCaseResult.js:
(WI.AuditTestCaseResult.async fromPayload): Added.
(WI.AuditTestCaseResult.fromPayload): Deleted.

* UserInterface/Models/AuditTestGroupResult.js:
(WI.AuditTestGroupResult.async fromPayload): Added.
(WI.AuditTestGroupResult.fromPayload): Deleted.

* UserInterface/Controllers/AuditManager.js:
(WI.AuditManager.prototype.import):

LayoutTests:

* inspector/model/auditTestCase.html:
* inspector/model/auditTestCaseResult.html:
* inspector/model/auditTestGroup.html:
* inspector/model/auditTestGroupResult.html:

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

LayoutTests/ChangeLog
LayoutTests/inspector/model/auditTestCase.html
LayoutTests/inspector/model/auditTestCaseResult.html
LayoutTests/inspector/model/auditTestGroup.html
LayoutTests/inspector/model/auditTestGroupResult.html
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/AuditManager.js
Source/WebInspectorUI/UserInterface/Models/AuditTestCase.js
Source/WebInspectorUI/UserInterface/Models/AuditTestCaseResult.js
Source/WebInspectorUI/UserInterface/Models/AuditTestGroup.js
Source/WebInspectorUI/UserInterface/Models/AuditTestGroupResult.js

index 42a3632..413737a 100644 (file)
@@ -1,3 +1,16 @@
+2018-10-31  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Audit: attempt to re-link DOM nodes for imported results
+        https://bugs.webkit.org/show_bug.cgi?id=191044
+        <rdar://problem/45687364>
+
+        Reviewed by Brian Burg.
+
+        * inspector/model/auditTestCase.html:
+        * inspector/model/auditTestCaseResult.html:
+        * inspector/model/auditTestGroup.html:
+        * inspector/model/auditTestGroupResult.html:
+
 2018-10-31  Jer Noble  <jer.noble@apple.com>
 
         MediaSource.isTypeSupported('video/mp4; codecs="hvc1.1.6.L60.B0') is inproperly rejected
index 3dfc1ad..829d01d 100644 (file)
@@ -11,7 +11,7 @@ function test()
         suite.addTestCase({
             name,
             async test() {
-                let object = WI.AuditTestCase.fromPayload(payload);
+                let object = await WI.AuditTestCase.fromPayload(payload);
                 InspectorTest.log(object ? JSON.stringify(object, null, 2) : object);
             },
         });
index fb87f91..fd44fc7 100644 (file)
@@ -11,7 +11,7 @@ function test()
         suite.addTestCase({
             name,
             async test() {
-                let object = WI.AuditTestCaseResult.fromPayload(payload);
+                let object = await WI.AuditTestCaseResult.fromPayload(payload);
                 InspectorTest.log(object ? JSON.stringify(object, null, 2) : object);
             },
         });
index ff0cd5e..bdfa290 100644 (file)
@@ -11,7 +11,7 @@ function test()
         suite.addTestCase({
             name,
             async test() {
-                let object = WI.AuditTestGroup.fromPayload(payload);
+                let object = await WI.AuditTestGroup.fromPayload(payload);
                 InspectorTest.log(object ? JSON.stringify(object, null, 2) : object);
             },
         });
index 0eba2df..9767049 100644 (file)
@@ -11,7 +11,7 @@ function test()
         suite.addTestCase({
             name,
             async test() {
-                let object = WI.AuditTestGroupResult.fromPayload(payload);
+                let object = await WI.AuditTestGroupResult.fromPayload(payload);
                 InspectorTest.log(object ? JSON.stringify(object, null, 2) : object);
             },
         });
index 14325b1..8646653 100644 (file)
@@ -1,3 +1,33 @@
+2018-10-31  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Audit: attempt to re-link DOM nodes for imported results
+        https://bugs.webkit.org/show_bug.cgi?id=191044
+        <rdar://problem/45687364>
+
+        Reviewed by Brian Burg.
+
+        When importing a `WI.AuditTestCaseResult`, attempt to `querySelector` for each item in
+        `data.domNodes`. If a node is found, replace it with that node and show a tree instead.
+
+        * UserInterface/Models/AuditTestCase.js:
+        (WI.AuditTestCase.async fromPayload): Added.
+        (WI.AuditTestCase.fromPayload): Deleted.
+
+        * UserInterface/Models/AuditTestGroup.js:
+        (WI.AuditTestGroup.async fromPayload): Added.
+        (WI.AuditTestGroup.fromPayload): Deleted.
+
+        * UserInterface/Models/AuditTestCaseResult.js:
+        (WI.AuditTestCaseResult.async fromPayload): Added.
+        (WI.AuditTestCaseResult.fromPayload): Deleted.
+
+        * UserInterface/Models/AuditTestGroupResult.js:
+        (WI.AuditTestGroupResult.async fromPayload): Added.
+        (WI.AuditTestGroupResult.fromPayload): Deleted.
+
+        * UserInterface/Controllers/AuditManager.js:
+        (WI.AuditManager.prototype.import):
+
 2018-10-31  Joseph Pecoraro  <pecoraro@apple.com>
 
         Follow-up review comment to r237652.
index e0defa0..7dd19cb 100644 (file)
@@ -95,7 +95,7 @@ WI.AuditManager = class AuditManager extends WI.Object
 
     import()
     {
-        WI.loadDataFromFile((data, filename) => {
+        WI.loadDataFromFile(async (data, filename) => {
             if (!data)
                 return;
 
@@ -107,9 +107,9 @@ WI.AuditManager = class AuditManager extends WI.Object
                 return;
             }
 
-            let object = WI.AuditTestGroup.fromPayload(payload) || WI.AuditTestCase.fromPayload(payload);
+            let object = await WI.AuditTestGroup.fromPayload(payload) || await WI.AuditTestCase.fromPayload(payload);
             if (!object) {
-                object = WI.AuditTestGroupResult.fromPayload(payload) || WI.AuditTestCaseResult.fromPayload(payload);
+                object = await WI.AuditTestGroupResult.fromPayload(payload) || await WI.AuditTestCaseResult.fromPayload(payload);
                 if (!object) {
                     WI.AuditManager.synthesizeError(WI.UIString("invalid JSON."));
                     return;
index 90bc1e0..4f09fdf 100644 (file)
@@ -36,7 +36,7 @@ WI.AuditTestCase = class AuditTestCase extends WI.AuditTestBase
 
     // Static
 
-    static fromPayload(payload)
+    static async fromPayload(payload)
     {
         if (typeof payload !== "object" || payload === null)
             return null;
index 8652a85..5c8bd53 100644 (file)
@@ -40,7 +40,7 @@ WI.AuditTestCaseResult = class AuditTestCaseResult extends WI.AuditTestResultBas
 
     // Static
 
-    static fromPayload(payload)
+    static async fromPayload(payload)
     {
         if (typeof payload !== "object" || payload === null)
             return null;
@@ -86,8 +86,20 @@ WI.AuditTestCaseResult = class AuditTestCaseResult extends WI.AuditTestResultBas
             options.description = description;
         if (!isEmptyObject(data)) {
             options.data = {};
-            if (data.domNodes && data.domNodes.length)
+            if (data.domNodes && data.domNodes.length) {
+                if (window.DOMAgent) {
+                    let documentNode = await new Promise((resolve) => WI.domManager.requestDocument(resolve));
+                    data.domNodes = await Promise.all(data.domNodes.map(async (domNodeString) => {
+                        let nodeId = 0;
+                        try {
+                            nodeId = await WI.domManager.querySelector(documentNode, domNodeString);
+                        } catch { }
+                        return WI.domManager.nodeForId(nodeId) || domNodeString;
+                    }));
+                }
+
                 options.data.domNodes = data.domNodes;
+            }
             if (data.domAttributes && data.domAttributes.length)
                 options.data.domAttributes = data.domAttributes;
             if (data.errors && data.errors.length)
@@ -102,6 +114,7 @@ WI.AuditTestCaseResult = class AuditTestCaseResult extends WI.AuditTestResultBas
             if (metadata.url)
                 options.metadata.url = metadata.url;
         }
+
         return new WI.AuditTestCaseResult(name, level, options);
     }
 
index 784e974..e37ca63 100644 (file)
@@ -41,7 +41,7 @@ WI.AuditTestGroup = class AuditTestGroup extends WI.AuditTestBase
 
     // Static
 
-    static fromPayload(payload)
+    static async fromPayload(payload)
     {
         if (typeof payload !== "object" || payload === null)
             return null;
@@ -57,7 +57,17 @@ WI.AuditTestGroup = class AuditTestGroup extends WI.AuditTestBase
         if (!Array.isArray(tests))
             return null;
 
-        tests = tests.map((test) => WI.AuditTestCase.fromPayload(test) || WI.AuditTestGroup.fromPayload(test));
+        tests = await Promise.all(tests.map(async (test) => {
+            let testCase = await WI.AuditTestCase.fromPayload(test);
+            if (testCase)
+                return testCase;
+
+            let testGroup = await WI.AuditTestGroup.fromPayload(test);
+            if (testGroup)
+                return testGroup;
+
+            return null;
+        }));
         tests = tests.filter((test) => !!test);
         if (!tests.length)
             return null;
index 012b463..d03cd1c 100644 (file)
@@ -36,7 +36,7 @@ WI.AuditTestGroupResult = class AuditTestGroupResult extends WI.AuditTestResultB
 
     // Static
 
-    static fromPayload(payload)
+    static async fromPayload(payload)
     {
         if (typeof payload !== "object" || payload === null)
             return null;
@@ -52,7 +52,17 @@ WI.AuditTestGroupResult = class AuditTestGroupResult extends WI.AuditTestResultB
         if (!Array.isArray(results))
             return null;
 
-        results = results.map((result) => WI.AuditTestGroupResult.fromPayload(result) || WI.AuditTestCaseResult.fromPayload(result));
+        results = await Promise.all(results.map(async (test) => {
+            let testCaseResult = await WI.AuditTestCaseResult.fromPayload(test);
+            if (testCaseResult)
+                return testCaseResult;
+
+            let testGroupResult = await WI.AuditTestGroupResult.fromPayload(test);
+            if (testGroupResult)
+                return testGroupResult;
+
+            return null;
+        }));
         results = results.filter((result) => !!result);
         if (!results.length)
             return null;