Title: [211289] trunk
Revision
211289
Author
[email protected]
Date
2017-01-27 10:58:13 -0800 (Fri, 27 Jan 2017)

Log Message

Styles should not show background-repeat-x/y, or -webkit-mask-repeat-x/y
https://bugs.webkit.org/show_bug.cgi?id=167255

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

Source/WebCore:

Test: inspector/css/css-property.html

* css/makeprop.pl:
(addProperty):
Add a generated function `isInternalCSSProperty` that checks the given CSSPropertyID against
a derived list of properties from CSSProperties.json with "internal-only".

* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::getSupportedCSSProperties):
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyle::styleWithProperties):
Only pass CSS property payloads to the frontend if they are not internal.

LayoutTests:

Checks that internal-only CSS properties are marked as invalid when passed to WebInspector.

* inspector/css/css-property-expected.txt: Added.
* inspector/css/css-property.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (211288 => 211289)


--- trunk/LayoutTests/ChangeLog	2017-01-27 18:44:18 UTC (rev 211288)
+++ trunk/LayoutTests/ChangeLog	2017-01-27 18:58:13 UTC (rev 211289)
@@ -1,3 +1,15 @@
+2017-01-27  Devin Rousso  <[email protected]>
+
+        Styles should not show background-repeat-x/y, or -webkit-mask-repeat-x/y
+        https://bugs.webkit.org/show_bug.cgi?id=167255
+
+        Reviewed by Joseph Pecoraro.
+
+        Checks that internal-only CSS properties are marked as invalid when passed to WebInspector.
+
+        * inspector/css/css-property-expected.txt: Added.
+        * inspector/css/css-property.html: Added.
+
 2017-01-27  Antti Koivisto  <[email protected]>
 
         Implement Cache-control: immutable

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


--- trunk/LayoutTests/inspector/css/css-property-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/css/css-property-expected.txt	2017-01-27 18:58:13 UTC (rev 211289)
@@ -0,0 +1,38 @@
+Testing methods of CSSProperty.
+
+
+== Running test suite: CSSProperty
+-- Running test case: CSSProperty.prototype.get valid
+PASS: "background-repeat" is a valid property.
+PASS: "background-repeat-x" is an invalid property.
+PASS: "background-repeat-invalid" is an invalid property.
+PASS: "background-repeat-y" is an invalid property.
+
+-- Running test case: CSSProperty.prototype.get anonymous
+PASS: "background-repeat" is not an anonymous CSS property.
+PASS: "background-repeat-x" is not an anonymous CSS property.
+PASS: "background-repeat-invalid" is not an anonymous CSS property.
+PASS: "background-repeat-y" is an anonymous CSS property.
+
+-- Running test case: CSSProperty.prototype.get implicit
+PASS: "background-repeat" is not an implicit CSS property.
+PASS: "background-repeat-x" is not an implicit CSS property.
+PASS: "background-repeat-invalid" is not an implicit CSS property.
+PASS: "background-repeat-y" is an implicit CSS property.
+
+-- Running test case: CSSProperty.prototype.get value
+PASS: "background-repeat" has the value "repeat".
+PASS: "background-repeat-x" has the value "repeat".
+PASS: "background-repeat-invalid" has the value "repeat".
+PASS: "background-repeat-y" has the value "repeat".
+
+-- Running test case: CSSProperty.prototype.get text
+PASS: "background-repeat" has the text "background-repeat: repeat;".
+PASS: "background-repeat" has the _text (private) "background-repeat: repeat;".
+PASS: "background-repeat-x" has the text "background-repeat-x: repeat;".
+PASS: "background-repeat-x" has the _text (private) "background-repeat-x: repeat;".
+PASS: "background-repeat-invalid" has the text "background-repeat-invalid: repeat;".
+PASS: "background-repeat-invalid" has the _text (private) "background-repeat-invalid: repeat;".
+PASS: "background-repeat-y" has the text "background-repeat-y: repeat;".
+PASS: "background-repeat-y" has the _text (private) "".
+

Added: trunk/LayoutTests/inspector/css/css-property.html (0 => 211289)


--- trunk/LayoutTests/inspector/css/css-property.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/css/css-property.html	2017-01-27 18:58:13 UTC (rev 211289)
@@ -0,0 +1,184 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+function test() {
+    let nodeStyles = null;
+
+    let suite = InspectorTest.createAsyncSuite("CSSProperty");
+
+    suite.addTestCase({
+        name: "CSSProperty.prototype.get valid",
+        description: "Ensure valid, invalid, and internal-only have correct valid state.",
+        test(resolve, reject) {
+            for (let rule of nodeStyles.matchedRules) {
+                if (rule.selectorText !== "div#x")
+                    continue;
+
+                for (let property of rule.style.properties) {
+                    switch (property.name) {
+                    case "background-repeat":
+                        InspectorTest.expectThat(property.valid, `"${property.name}" is a valid property.`);
+                        break;
+                    case "background-repeat-x":
+                    case "background-repeat-y":
+                    case "background-repeat-invalid":
+                        InspectorTest.expectFalse(property.valid, `"${property.name}" is an invalid property.`);
+                        break;
+                    }
+                }
+            }
+
+            resolve();
+        }
+    });
+
+    suite.addTestCase({
+        name: "CSSProperty.prototype.get anonymous",
+        description: "Ensure valid, invalid, and internal-only have correct anonymous state.",
+        test(resolve, reject) {
+            for (let rule of nodeStyles.matchedRules) {
+                if (rule.selectorText !== "div#x")
+                    continue;
+
+                for (let property of rule.style.properties) {
+                    switch (property.name) {
+                    case "background-repeat":
+                    case "background-repeat-x":
+                    case "background-repeat-invalid":
+                        InspectorTest.expectFalse(property.anonymous, `"${property.name}" is not an anonymous CSS property.`);
+                        break;
+                    case "background-repeat-y":
+                        InspectorTest.expectThat(property.anonymous, `"${property.name}" is an anonymous CSS property.`);
+                        break;
+                    }
+                }
+            }
+
+            resolve();
+        }
+    });
+
+    suite.addTestCase({
+        name: "CSSProperty.prototype.get implicit",
+        description: "Ensure valid, invalid, and internal-only have correct implicit state.",
+        test(resolve, reject) {
+            for (let rule of nodeStyles.matchedRules) {
+                if (rule.selectorText !== "div#x")
+                    continue;
+
+                for (let property of rule.style.properties) {
+                    switch (property.name) {
+                    case "background-repeat":
+                    case "background-repeat-x":
+                    case "background-repeat-invalid":
+                        InspectorTest.expectFalse(property.implicit, `"${property.name}" is not an implicit CSS property.`);
+                        break;
+                    case "background-repeat-y":
+                        InspectorTest.expectThat(property.implicit, `"${property.name}" is an implicit CSS property.`);
+                        break;
+                    }
+                }
+            }
+
+            resolve();
+        }
+    });
+
+    suite.addTestCase({
+        name: "CSSProperty.prototype.get value",
+        description: "Ensure valid, invalid, and internal-only have correct value.",
+        test(resolve, reject) {
+            for (let rule of nodeStyles.matchedRules) {
+                if (rule.selectorText !== "div#x")
+                    continue;
+
+                for (let property of rule.style.properties) {
+                    switch (property.name) {
+                    case "background-repeat":
+                    case "background-repeat-x":
+                    case "background-repeat-y":
+                    case "background-repeat-invalid":
+                        InspectorTest.expectEqual(property.value, "repeat", `"${property.name}" has the value "repeat".`);
+                        break;
+                    }
+                }
+            }
+
+            resolve();
+        }
+    });
+
+    suite.addTestCase({
+        name: "CSSProperty.prototype.get text",
+        description: "Ensure valid, invalid, and internal-only have correct text.",
+        test(resolve, reject) {
+            for (let rule of nodeStyles.matchedRules) {
+                if (rule.selectorText !== "div#x")
+                    continue;
+
+                // It is necessary to use "_text" because the public "text" getter will attempt to
+                // synthesize a value for the CSSProperty if it is falsy.  This is used for cases
+                // where a shorthand property is written in the style, since the longhand properties
+                // (with corresponding values) are still sent to the frontend.
+                for (let property of rule.style.properties) {
+                    switch (property.name) {
+                    case "background-repeat":
+                        InspectorTest.expectEqual(property.text, "background-repeat: repeat;", `"${property.name}" has the text "background-repeat: repeat;".`);
+                        InspectorTest.expectEqual(property._text, "background-repeat: repeat;", `"${property.name}" has the _text (private) "background-repeat: repeat;".`);
+                        break;
+                    case "background-repeat-x":
+                        InspectorTest.expectEqual(property.text, "background-repeat-x: repeat;", `"${property.name}" has the text "background-repeat-x: repeat;".`);
+                        InspectorTest.expectEqual(property._text, "background-repeat-x: repeat;", `"${property.name}" has the _text (private) "background-repeat-x: repeat;".`);
+                        break;
+                    case "background-repeat-y":
+                        InspectorTest.expectEqual(property.text, "background-repeat-y: repeat;", `"${property.name}" has the text "background-repeat-y: repeat;".`);
+                        InspectorTest.expectEqual(property._text, "", `"${property.name}" has the _text (private) "".`);
+                        break;
+                    case "background-repeat-invalid":
+                        InspectorTest.expectEqual(property.text, "background-repeat-invalid: repeat;", `"${property.name}" has the text "background-repeat-invalid: repeat;".`);
+                        InspectorTest.expectEqual(property._text, "background-repeat-invalid: repeat;", `"${property.name}" has the _text (private) "background-repeat-invalid: repeat;".`);
+                        break;
+                    }
+                }
+            }
+
+            resolve();
+        }
+    });
+
+    WebInspector.domTreeManager.requestDocument((documentNode) => {
+        WebInspector.domTreeManager.querySelector(documentNode.id, "div#x", (contentNodeId) => {
+            if (contentNodeId) {
+                let domNode = WebInspector.domTreeManager.nodeForId(contentNodeId);
+                nodeStyles = WebInspector.cssStyleManager.stylesForNode(domNode);
+
+                if (nodeStyles.needsRefresh) {
+                    nodeStyles.singleFireEventListener(WebInspector.DOMNodeStyles.Event.Refreshed, (event) => {
+                        suite.runTestCasesAndFinish()
+                    });
+                } else
+                    suite.runTestCasesAndFinish();
+            } else {
+                InspectorTest.fail("DOM node not found.");
+                InspectorTest.completeTest();
+            }
+        });
+    });
+}
+</script>
+</head>
+<body _onload_="runTest()">
+    <p>Testing methods of CSSProperty.</p>
+
+    <style>
+    div#x {
+        background-repeat: repeat;
+        background-repeat-x: repeat;
+        background-repeat-invalid: repeat;
+    }
+    </style>
+    <div id="x"></div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (211288 => 211289)


--- trunk/Source/WebCore/ChangeLog	2017-01-27 18:44:18 UTC (rev 211288)
+++ trunk/Source/WebCore/ChangeLog	2017-01-27 18:58:13 UTC (rev 211289)
@@ -1,3 +1,23 @@
+2017-01-27  Devin Rousso  <[email protected]>
+
+        Styles should not show background-repeat-x/y, or -webkit-mask-repeat-x/y
+        https://bugs.webkit.org/show_bug.cgi?id=167255
+
+        Reviewed by Joseph Pecoraro.
+
+        Test: inspector/css/css-property.html
+
+        * css/makeprop.pl:
+        (addProperty):
+        Add a generated function `isInternalCSSProperty` that checks the given CSSPropertyID against
+        a derived list of properties from CSSProperties.json with "internal-only".
+
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::getSupportedCSSProperties):
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::InspectorStyle::styleWithProperties):
+        Only pass CSS property payloads to the frontend if they are not internal.
+
 2017-01-27  Antti Koivisto  <[email protected]>
 
         Implement Cache-control: immutable

Modified: trunk/Source/WebCore/css/makeprop.pl (211288 => 211289)


--- trunk/Source/WebCore/css/makeprop.pl	2017-01-27 18:44:18 UTC (rev 211288)
+++ trunk/Source/WebCore/css/makeprop.pl	2017-01-27 18:58:13 UTC (rev 211289)
@@ -58,6 +58,7 @@
 my %defines = map { $_ => 1 } split(/ /, $defines);
 
 my @names;
+my @internalProprerties;
 my $numPredefinedProperties = 2;
 my %nameIsInherited;
 my %nameIsHighPriority;
@@ -140,7 +141,8 @@
                 } elsif ($styleBuilderOptions{$codegenOptionName}) {
                     $propertiesWithStyleBuilderOptions{$name}{$codegenOptionName} = $codegenProperties->{$codegenOptionName};
                 } elsif ($codegenOptionName eq "internal-only") {
-                    # internal-only properties exist to make it easier to parse compound properties (e.g. background-repeat) as if they were shorthands. This doesn't currently affect codegen.
+                    # internal-only properties exist to make it easier to parse compound properties (e.g. background-repeat) as if they were shorthands.
+                    push @internalProprerties, $name
                 } else {
                     die "Unrecognized codegen property \"$optionName\" for $name property.";
                 }
@@ -242,7 +244,7 @@
     }
 }
 
-print GPERF<< "EOF";
+print GPERF << "EOF";
 %%
 const Property* findProperty(const char* str, unsigned int len)
 {
@@ -249,6 +251,22 @@
     return CSSPropertyNamesHash::findPropertyImpl(str, len);
 }
 
+bool isInternalCSSProperty(const CSSPropertyID id)
+{
+    switch (id) {
+EOF
+
+foreach my $name (@internalProprerties) {
+  print GPERF "    case CSSPropertyID::CSSProperty" . $nameToId{$name} . ":\n";
+}
+
+print GPERF << "EOF";
+        return true;
+    default:
+        return false;
+    }
+}
+
 const char* getPropertyName(CSSPropertyID id)
 {
     if (id < firstCSSProperty)
@@ -380,6 +398,7 @@
 
 print HEADER << "EOF";
 
+bool isInternalCSSProperty(const CSSPropertyID);
 const char* getPropertyName(CSSPropertyID);
 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID id);
 WTF::String getPropertyNameString(CSSPropertyID id);

Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (211288 => 211289)


--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp	2017-01-27 18:44:18 UTC (rev 211288)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp	2017-01-27 18:58:13 UTC (rev 211289)
@@ -845,6 +845,9 @@
     auto properties = Inspector::Protocol::Array<Inspector::Protocol::CSS::CSSPropertyInfo>::create();
     for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) {
         CSSPropertyID id = convertToCSSPropertyID(i);
+        if (isInternalCSSProperty(id))
+            continue;
+
         auto property = Inspector::Protocol::CSS::CSSPropertyInfo::create()
             .setName(getPropertyNameString(id))
             .release();

Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (211288 => 211289)


--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2017-01-27 18:44:18 UTC (rev 211288)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2017-01-27 18:58:13 UTC (rev 211289)
@@ -654,8 +654,10 @@
 
         propertiesObject->addItem(property.copyRef());
 
+        CSSPropertyID propertyId = cssPropertyID(name);
+
         // Default "parsedOk" == true.
-        if (!propertyEntry.parsedOk)
+        if (!propertyEntry.parsedOk || isInternalCSSProperty(propertyId))
             property->setParsedOk(false);
         if (it->hasRawText())
             property->setText(it->rawText);
@@ -678,7 +680,7 @@
                 // Parsed property overrides any property with the same name. Non-parsed property overrides
                 // previous non-parsed property with the same name (if any).
                 bool shouldInactivate = false;
-                CSSPropertyID propertyId = cssPropertyID(name);
+
                 // Canonicalize property names to treat non-prefixed and vendor-prefixed property names the same (opacity vs. -webkit-opacity).
                 String canonicalPropertyName = propertyId ? getPropertyNameString(propertyId) : name;
                 HashMap<String, RefPtr<Inspector::Protocol::CSS::CSSProperty>>::iterator activeIt = propertyNameToPreviousActiveProperty.find(canonicalPropertyName);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to