Index: third_party/WebKit/Source/core/css/RuleFeatureSetTest.cpp |
diff --git a/third_party/WebKit/Source/core/css/RuleFeatureSetTest.cpp b/third_party/WebKit/Source/core/css/RuleFeatureSetTest.cpp |
index eba129ca4d501a6a39d17cff5d29311ba841a9cc..cc7854ff3115b8881be6cedc6a9a8941730aa00f 100644 |
--- a/third_party/WebKit/Source/core/css/RuleFeatureSetTest.cpp |
+++ b/third_party/WebKit/Source/core/css/RuleFeatureSetTest.cpp |
@@ -85,6 +85,11 @@ public: |
return m_ruleFeatureSet->collectFeaturesFromRuleData(ruleData); |
} |
+ void clearFeatures() |
+ { |
+ m_ruleFeatureSet->clear(); |
+ } |
+ |
void collectInvalidationSetsForClass(InvalidationLists& invalidationLists, const AtomicString& className) const |
{ |
Element* element = Traversal<HTMLElement>::firstChild(*Traversal<HTMLElement>::firstChild(*m_document->body())); |
@@ -255,6 +260,11 @@ public: |
EXPECT_EQ(count, m_ruleFeatureSet->uncommonAttributeRules.size()); |
} |
+ void expectFullRecalcForRuleSetInvalidation(bool expected) |
+ { |
+ EXPECT_EQ(expected, m_ruleFeatureSet->needsFullRecalcForRuleSetInvalidation()); |
+ } |
+ |
private: |
PersistentPartObject<RuleFeatureSet> m_ruleFeatureSet; |
Persistent<Document> m_document; |
@@ -905,4 +915,146 @@ TEST_F(RuleFeatureSetTest, nthInvalidationAnyDescendant) |
expectClassInvalidation("a", invalidationLists.descendants); |
} |
+TEST_F(RuleFeatureSetTest, RuleSetInvalidationTypeSelector) |
+{ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("div")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("* div")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("body *")); |
+ expectFullRecalcForRuleSetInvalidation(true); |
+} |
+ |
+TEST_F(RuleFeatureSetTest, RuleSetInvalidationClassIdAttr) |
+{ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".c")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".c *")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("#i")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("#i *")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("[attr]")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("[attr] *")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+} |
+ |
+TEST_F(RuleFeatureSetTest, RuleSetInvalidationHoverActiveFocus) |
+{ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":hover:active:focus")); |
+ expectFullRecalcForRuleSetInvalidation(true); |
+} |
+ |
+TEST_F(RuleFeatureSetTest, RuleSetInvalidationHostContext) |
+{ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host-context(.x)")); |
+ expectFullRecalcForRuleSetInvalidation(true); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host-context(.x) .y")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+} |
+ |
+TEST_F(RuleFeatureSetTest, RuleSetInvalidationHost) |
+{ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host(.x)")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host(*) .y")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host(.x) .y")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+} |
+ |
+TEST_F(RuleFeatureSetTest, RuleSetInvalidationNot) |
+{ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":not(.x)")); |
+ expectFullRecalcForRuleSetInvalidation(true); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":not(.x) :hover")); |
+ expectFullRecalcForRuleSetInvalidation(true); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":not(.x) .y")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":not(.x) + .y")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+} |
+ |
+TEST_F(RuleFeatureSetTest, RuleSetInvalidationCustomPseudo) |
+{ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("::-webkit-slider-thumb")); |
+ expectFullRecalcForRuleSetInvalidation(true); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".x::-webkit-slider-thumb")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".x + ::-webkit-slider-thumb")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+} |
+ |
+TEST_F(RuleFeatureSetTest, RuleSetInvalidationSlotted) |
+{ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("::slotted(*)")); |
+ expectFullRecalcForRuleSetInvalidation(true); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("::slotted(.y)")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".x::slotted(.y)")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("[x] ::slotted(.y)")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+} |
+ |
+TEST_F(RuleFeatureSetTest, RuleSetInvalidationAnyPseudo) |
+{ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(*, #x)")); |
+ expectFullRecalcForRuleSetInvalidation(true); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".x:-webkit-any(*, #y)")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(:-webkit-any(.a, .b), #x)")); |
+ expectFullRecalcForRuleSetInvalidation(false); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(:-webkit-any(.a, *), #x)")); |
+ expectFullRecalcForRuleSetInvalidation(true); |
+ clearFeatures(); |
+ |
+ EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(*, .a) *")); |
+ expectFullRecalcForRuleSetInvalidation(true); |
+} |
+ |
} // namespace blink |