Title: [273821] trunk
Revision
273821
Author
pan...@apple.com
Date
2021-03-03 09:59:27 -0800 (Wed, 03 Mar 2021)

Log Message

REGRESSION (r266288): Web Inspector: ::marker shows on every element now
https://bugs.webkit.org/show_bug.cgi?id=222384

Reviewed by Devin Rousso.

Source/WebCore:

Test: inspector/css/getMatchedStylesForNodeMarkerPseudoId.html

Add filtering of the `::marker` CSS rule for elements that are not list items, as they do no apply to the
element.

* inspector/agents/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::getMatchedStylesForNode):
- Added filtering for `*::marker` rules on non-`display:list-item` elements.
(WebCore::InspectorCSSAgent::buildObjectForRule):
- Drive-by refactoring to reduce code duplication.

LayoutTests:

Added test for the filtering of `*::marker` selector from the rule results of `CSS.getMatchedStyleForNode` on
elements that don't support `::marker`.

* inspector/css/getMatchedStylesForNode-expected.txt:
- Updated expectations to account for the abscence of the `::marker` rule on non-list elements.
* inspector/css/getMatchedStylesForNodeMarkerPseudoId-expected.txt: Added.
* inspector/css/getMatchedStylesForNodeMarkerPseudoId.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (273820 => 273821)


--- trunk/LayoutTests/ChangeLog	2021-03-03 17:51:55 UTC (rev 273820)
+++ trunk/LayoutTests/ChangeLog	2021-03-03 17:59:27 UTC (rev 273821)
@@ -1,3 +1,18 @@
+2021-03-03  Patrick Angle  <pan...@apple.com>
+
+        REGRESSION (r266288): Web Inspector: ::marker shows on every element now
+        https://bugs.webkit.org/show_bug.cgi?id=222384
+
+        Reviewed by Devin Rousso.
+
+        Added test for the filtering of `*::marker` selector from the rule results of `CSS.getMatchedStyleForNode` on
+        elements that don't support `::marker`.
+
+        * inspector/css/getMatchedStylesForNode-expected.txt:
+        - Updated expectations to account for the abscence of the `::marker` rule on non-list elements.
+        * inspector/css/getMatchedStylesForNodeMarkerPseudoId-expected.txt: Added.
+        * inspector/css/getMatchedStylesForNodeMarkerPseudoId.html: Added.
+
 2021-03-03  Kate Cheney  <katherine_che...@apple.com>
 
         Report the correct document uri in the case of a ContentSecurityPolicyClient

Modified: trunk/LayoutTests/inspector/css/getMatchedStylesForNode-expected.txt (273820 => 273821)


--- trunk/LayoutTests/inspector/css/getMatchedStylesForNode-expected.txt	2021-03-03 17:51:55 UTC (rev 273820)
+++ trunk/LayoutTests/inspector/css/getMatchedStylesForNode-expected.txt	2021-03-03 17:59:27 UTC (rev 273821)
@@ -379,54 +379,6 @@
     ]
   },
   {
-    "pseudoId": "marker",
-    "matches": [
-      {
-        "rule": {
-          "selectorList": {
-            "selectors": [
-              {
-                "text": "div::marker",
-                "specificity": [
-                  0,
-                  0,
-                  2
-                ]
-              }
-            ],
-            "text": "div::marker",
-            "range": "<filtered>"
-          },
-          "sourceLine": "<filtered>",
-          "origin": "author",
-          "style": {
-            "cssProperties": [
-              {
-                "name": "z-index",
-                "value": "3",
-                "text": "z-index: 3;",
-                "range": "<filtered>",
-                "implicit": false,
-                "status": "active"
-              }
-            ],
-            "shorthandEntries": [],
-            "styleId": "<filtered>",
-            "width": "",
-            "height": "",
-            "range": "<filtered>",
-            "cssText": " z-index: 3; "
-          },
-          "sourceURL": "<filtered>",
-          "ruleId": "<filtered>"
-        },
-        "matchingSelectors": [
-          0
-        ]
-      }
-    ]
-  },
-  {
     "pseudoId": "before",
     "matches": [
       {

Added: trunk/LayoutTests/inspector/css/getMatchedStylesForNodeMarkerPseudoId-expected.txt (0 => 273821)


--- trunk/LayoutTests/inspector/css/getMatchedStylesForNodeMarkerPseudoId-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/css/getMatchedStylesForNodeMarkerPseudoId-expected.txt	2021-03-03 17:59:27 UTC (rev 273821)
@@ -0,0 +1,14 @@
+Tests for the CSS.getMatchedStyleForNode command and the `::marker` CSS rule selector.
+
+
+== Running test suite: CSS.getMatchedStyleForNode.MarkerPseudoId
+-- Running test case: CSS.getMatchedStyleForNode.MarkerPseudoId.ListItem
+PASS: Expected exactly 2 rules for selector `*::marker`.
+
+-- Running test case: CSS.getMatchedStyleForNode.MarkerPseudoId.NonListItem
+PASS: Expected no rules entry for selector `*::marker`.
+
+-- Running test case: CSS.getMatchedStyleForNode.MarkerPseudoId.NonListItemWithMarkerSpecified
+PASS: Expected no rules entry for selector `*::marker`.
+PASS: Expected 3 rules for selector `*::marker`.
+

Added: trunk/LayoutTests/inspector/css/getMatchedStylesForNodeMarkerPseudoId.html (0 => 273821)


--- trunk/LayoutTests/inspector/css/getMatchedStylesForNodeMarkerPseudoId.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/css/getMatchedStylesForNodeMarkerPseudoId.html	2021-03-03 17:59:27 UTC (rev 273821)
@@ -0,0 +1,90 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+function changeElementDisplayValue(id, value)
+{
+    document.getElementById(id).style.display = value;
+}
+
+function test()
+{
+    let suite = InspectorTest.createAsyncSuite("CSS.getMatchedStyleForNode.MarkerPseudoId");
+
+    function addTestCase({name, description, selector, domNodeStylesHandler})
+    {
+        suite.addTestCase({
+            name,
+            description,
+            async test() {
+                let documentNode = await WI.domManager.requestDocument();
+                let nodeId = await documentNode.querySelector(selector);
+                let domNode = WI.domManager.nodeForId(nodeId);
+                InspectorTest.assert(domNode, `Should find DOM Node for selector '${selector}'.`);
+
+                let domNodeStyles = WI.cssManager.stylesForNode(domNode);
+                InspectorTest.assert(domNodeStyles, `Should find CSS Styles for DOM Node.`);
+                await domNodeStyles.refreshIfNeeded();
+
+                await domNodeStylesHandler(domNodeStyles);
+            },
+        });
+    }
+
+    async function changeElementDisplayValue(id, value)
+    {
+        await InspectorTest.evaluateInPage(`changeElementDisplayValue("${id}", "${value}")`);
+    }
+
+    addTestCase({
+        name: "CSS.getMatchedStyleForNode.MarkerPseudoId.ListItem",
+        description: "A list item should have both the User Agent and authored `::marker` rules.",
+        selector: "#listItem",
+        async domNodeStylesHandler(styles) {
+            InspectorTest.expectEqual(styles.pseudoElements.get(WI.CSSManager.PseudoSelectorNames.Marker).matchedRules.length, 2, "Expected exactly 2 rules for selector `*::marker`.");
+        }
+    });
+
+    addTestCase({
+        name: "CSS.getMatchedStyleForNode.MarkerPseudoId.NonListItem",
+        description: "A non-list item should have no `::marker` rules.",
+        selector: "#nonListItem",
+        async domNodeStylesHandler(styles) {
+            InspectorTest.expectEqual(styles.pseudoElements.get(WI.CSSManager.PseudoSelectorNames.Marker), undefined, "Expected no rules entry for selector `*::marker`.");
+        }
+    });
+
+    addTestCase({
+        name: "CSS.getMatchedStyleForNode.MarkerPseudoId.NonListItemWithMarkerSpecified",
+        description: "A non-list item with a `base-selector::marker` specified should not show the specified rule unless it becomes a list item.",
+        selector: "#nonListItemWithMarkerSpecified",
+        async domNodeStylesHandler(styles) {
+            InspectorTest.expectEqual(styles.pseudoElements.get(WI.CSSManager.PseudoSelectorNames.Marker), undefined, "Expected no rules entry for selector `*::marker`.");
+            await changeElementDisplayValue("nonListItemWithMarkerSpecified", "list-item");
+            await styles.refresh();
+            InspectorTest.expectEqual(styles.pseudoElements.get(WI.CSSManager.PseudoSelectorNames.Marker).matchedRules.length, 3, "Expected 3 rules for selector `*::marker`.");
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+<style>
+    ::marker {
+        color: red;
+    }
+    #nonListItemWithMarkerSpecified::marker {
+        color: green;
+    }
+</style>
+</head>
+<body _onload_="runTest()">
+    <p>Tests for the CSS.getMatchedStyleForNode command and the `::marker` CSS rule selector.</p>
+    <ul>
+        <li id="listItem"></li>
+    </ul>
+    <div id="nonListItem"></div>
+    <div id="nonListItemWithMarkerSpecified"></div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (273820 => 273821)


--- trunk/Source/WebCore/ChangeLog	2021-03-03 17:51:55 UTC (rev 273820)
+++ trunk/Source/WebCore/ChangeLog	2021-03-03 17:59:27 UTC (rev 273821)
@@ -1,3 +1,21 @@
+2021-03-03  Patrick Angle  <pan...@apple.com>
+
+        REGRESSION (r266288): Web Inspector: ::marker shows on every element now
+        https://bugs.webkit.org/show_bug.cgi?id=222384
+
+        Reviewed by Devin Rousso.
+
+        Test: inspector/css/getMatchedStylesForNodeMarkerPseudoId.html
+
+        Add filtering of the `::marker` CSS rule for elements that are not list items, as they do no apply to the
+        element.
+
+        * inspector/agents/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::getMatchedStylesForNode):
+        - Added filtering for `*::marker` rules on non-`display:list-item` elements.
+        (WebCore::InspectorCSSAgent::buildObjectForRule):
+        - Drive-by refactoring to reduce code duplication.
+
 2021-03-03  Kate Cheney  <katherine_che...@apple.com>
 
         Report the correct document uri in the case of a ContentSecurityPolicyClient

Modified: trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp (273820 => 273821)


--- trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp	2021-03-03 17:51:55 UTC (rev 273820)
+++ trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp	2021-03-03 17:59:27 UTC (rev 273821)
@@ -502,6 +502,9 @@
         if (!includePseudo || *includePseudo) {
             pseudoElements = JSON::ArrayOf<Protocol::CSS::PseudoIdMatches>::create();
             for (PseudoId pseudoId = PseudoId::FirstPublicPseudoId; pseudoId < PseudoId::AfterLastInternalPseudoId; pseudoId = static_cast<PseudoId>(static_cast<unsigned>(pseudoId) + 1)) {
+                // `*::marker` selectors are only applicable to elements with `display: list-item`.
+                if (pseudoId == PseudoId::Marker && element->computedStyle()->display() != DisplayType::ListItem)
+                    continue;
                 if (auto protocolPseudoId = protocolValueForPseudoId(pseudoId)) {
                     auto matchedRules = styleResolver.pseudoStyleRulesForElement(element, pseudoId, Style::Resolver::AllCSSRules);
                     if (!matchedRules.isEmpty()) {
@@ -1089,11 +1092,7 @@
         styleResolver.inspectorCSSOMWrappers().collectScopeWrappers(shadowRoot->styleScope());
 
     CSSStyleRule* cssomWrapper = styleResolver.inspectorCSSOMWrappers().getWrapperForRuleInSheets(styleRule);
-    if (!cssomWrapper)
-        return nullptr;
-
-    InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(cssomWrapper->parentStyleSheet());
-    return inspectorStyleSheet ? inspectorStyleSheet->buildObjectForRule(cssomWrapper) : nullptr;
+    return buildObjectForRule(cssomWrapper);
 }
 
 RefPtr<Protocol::CSS::CSSRule> InspectorCSSAgent::buildObjectForRule(CSSStyleRule* rule)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to