Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: third_party/WebKit/Source/core/css/RuleFeatureSetTest.cpp

Issue 2326033002: Prepare to use invalidation set for adding/removing RuleSets. (Closed)
Patch Set: Rebased Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/RuleFeature.h" 5 #include "core/css/RuleFeature.h"
6 6
7 #include "core/css/CSSSelectorList.h" 7 #include "core/css/CSSSelectorList.h"
8 #include "core/css/RuleSet.h" 8 #include "core/css/RuleSet.h"
9 #include "core/css/StylePropertySet.h" 9 #include "core/css/StylePropertySet.h"
10 #include "core/css/StyleRule.h" 10 #include "core/css/StyleRule.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 RuleFeatureSet::SelectorPreMatch collectFeatures(const String& selectorText) 79 RuleFeatureSet::SelectorPreMatch collectFeatures(const String& selectorText)
80 { 80 {
81 CSSSelectorList selectorList = CSSParser::parseSelector(strictCSSParserC ontext(), nullptr, selectorText); 81 CSSSelectorList selectorList = CSSParser::parseSelector(strictCSSParserC ontext(), nullptr, selectorText);
82 82
83 StyleRule* styleRule = StyleRule::create(std::move(selectorList), Mutabl eStylePropertySet::create(HTMLStandardMode)); 83 StyleRule* styleRule = StyleRule::create(std::move(selectorList), Mutabl eStylePropertySet::create(HTMLStandardMode));
84 RuleData ruleData(styleRule, 0, 0, RuleHasNoSpecialState); 84 RuleData ruleData(styleRule, 0, 0, RuleHasNoSpecialState);
85 return m_ruleFeatureSet->collectFeaturesFromRuleData(ruleData); 85 return m_ruleFeatureSet->collectFeaturesFromRuleData(ruleData);
86 } 86 }
87 87
88 void clearFeatures()
89 {
90 m_ruleFeatureSet->clear();
91 }
92
88 void collectInvalidationSetsForClass(InvalidationLists& invalidationLists, c onst AtomicString& className) const 93 void collectInvalidationSetsForClass(InvalidationLists& invalidationLists, c onst AtomicString& className) const
89 { 94 {
90 Element* element = Traversal<HTMLElement>::firstChild(*Traversal<HTMLEle ment>::firstChild(*m_document->body())); 95 Element* element = Traversal<HTMLElement>::firstChild(*Traversal<HTMLEle ment>::firstChild(*m_document->body()));
91 m_ruleFeatureSet->collectInvalidationSetsForClass(invalidationLists, *el ement, className); 96 m_ruleFeatureSet->collectInvalidationSetsForClass(invalidationLists, *el ement, className);
92 } 97 }
93 98
94 void collectInvalidationSetsForId(InvalidationLists& invalidationLists, cons t AtomicString& id) const 99 void collectInvalidationSetsForId(InvalidationLists& invalidationLists, cons t AtomicString& id) const
95 { 100 {
96 Element* element = Traversal<HTMLElement>::firstChild(*Traversal<HTMLEle ment>::firstChild(*m_document->body())); 101 Element* element = Traversal<HTMLElement>::firstChild(*Traversal<HTMLEle ment>::firstChild(*m_document->body()));
97 m_ruleFeatureSet->collectInvalidationSetsForId(invalidationLists, *eleme nt, id); 102 m_ruleFeatureSet->collectInvalidationSetsForId(invalidationLists, *eleme nt, id);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 void expectSiblingRuleCount(unsigned count) 253 void expectSiblingRuleCount(unsigned count)
249 { 254 {
250 EXPECT_EQ(count, m_ruleFeatureSet->siblingRules.size()); 255 EXPECT_EQ(count, m_ruleFeatureSet->siblingRules.size());
251 } 256 }
252 257
253 void expectUncommonAttributeRuleCount(unsigned count) 258 void expectUncommonAttributeRuleCount(unsigned count)
254 { 259 {
255 EXPECT_EQ(count, m_ruleFeatureSet->uncommonAttributeRules.size()); 260 EXPECT_EQ(count, m_ruleFeatureSet->uncommonAttributeRules.size());
256 } 261 }
257 262
263 void expectFullRecalcForRuleSetInvalidation(bool expected)
264 {
265 EXPECT_EQ(expected, m_ruleFeatureSet->needsFullRecalcForRuleSetInvalidat ion());
266 }
267
258 private: 268 private:
259 PersistentPartObject<RuleFeatureSet> m_ruleFeatureSet; 269 PersistentPartObject<RuleFeatureSet> m_ruleFeatureSet;
260 Persistent<Document> m_document; 270 Persistent<Document> m_document;
261 }; 271 };
262 272
263 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling1) 273 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling1)
264 { 274 {
265 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".p")); 275 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".p"));
266 276
267 InvalidationLists invalidationLists; 277 InvalidationLists invalidationLists;
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 { 908 {
899 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".blah:-webkit-a ny(#nomatch, :nth-child(2n)) .a")); 909 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".blah:-webkit-a ny(#nomatch, :nth-child(2n)) .a"));
900 910
901 InvalidationLists invalidationLists; 911 InvalidationLists invalidationLists;
902 collectNthInvalidationSet(invalidationLists); 912 collectNthInvalidationSet(invalidationLists);
903 913
904 expectNoSelfInvalidation(invalidationLists.descendants); 914 expectNoSelfInvalidation(invalidationLists.descendants);
905 expectClassInvalidation("a", invalidationLists.descendants); 915 expectClassInvalidation("a", invalidationLists.descendants);
906 } 916 }
907 917
918 TEST_F(RuleFeatureSetTest, RuleSetInvalidationTypeSelector)
919 {
920 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("div"));
921 expectFullRecalcForRuleSetInvalidation(false);
922 clearFeatures();
923
924 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("* div"));
925 expectFullRecalcForRuleSetInvalidation(false);
926 clearFeatures();
927
928 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("body *"));
929 expectFullRecalcForRuleSetInvalidation(true);
930 }
931
932 TEST_F(RuleFeatureSetTest, RuleSetInvalidationClassIdAttr)
933 {
934 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".c"));
935 expectFullRecalcForRuleSetInvalidation(false);
936 clearFeatures();
937
938 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".c *"));
939 expectFullRecalcForRuleSetInvalidation(false);
940 clearFeatures();
941
942 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("#i"));
943 expectFullRecalcForRuleSetInvalidation(false);
944 clearFeatures();
945
946 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("#i *"));
947 expectFullRecalcForRuleSetInvalidation(false);
948 clearFeatures();
949
950 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("[attr]"));
951 expectFullRecalcForRuleSetInvalidation(false);
952 clearFeatures();
953
954 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("[attr] *"));
955 expectFullRecalcForRuleSetInvalidation(false);
956 }
957
958 TEST_F(RuleFeatureSetTest, RuleSetInvalidationHoverActiveFocus)
959 {
960 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":hover:active:f ocus"));
961 expectFullRecalcForRuleSetInvalidation(true);
962 }
963
964 TEST_F(RuleFeatureSetTest, RuleSetInvalidationHostContext)
965 {
966 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host-context(. x)"));
967 expectFullRecalcForRuleSetInvalidation(true);
968 clearFeatures();
969
970 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host-context(. x) .y"));
971 expectFullRecalcForRuleSetInvalidation(false);
972 }
973
974 TEST_F(RuleFeatureSetTest, RuleSetInvalidationHost)
975 {
976 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host(.x)"));
977 expectFullRecalcForRuleSetInvalidation(false);
978 clearFeatures();
979
980 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host(*) .y"));
981 expectFullRecalcForRuleSetInvalidation(false);
982 clearFeatures();
983
984 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host(.x) .y")) ;
985 expectFullRecalcForRuleSetInvalidation(false);
986 }
987
988 TEST_F(RuleFeatureSetTest, RuleSetInvalidationNot)
989 {
990 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":not(.x)"));
991 expectFullRecalcForRuleSetInvalidation(true);
992 clearFeatures();
993
994 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":not(.x) :hover "));
995 expectFullRecalcForRuleSetInvalidation(true);
996 clearFeatures();
997
998 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":not(.x) .y"));
999 expectFullRecalcForRuleSetInvalidation(false);
1000 clearFeatures();
1001
1002 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":not(.x) + .y") );
1003 expectFullRecalcForRuleSetInvalidation(false);
1004 }
1005
1006 TEST_F(RuleFeatureSetTest, RuleSetInvalidationCustomPseudo)
1007 {
1008 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("::-webkit-slide r-thumb"));
1009 expectFullRecalcForRuleSetInvalidation(true);
1010 clearFeatures();
1011
1012 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".x::-webkit-sli der-thumb"));
1013 expectFullRecalcForRuleSetInvalidation(false);
1014 clearFeatures();
1015
1016 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".x + ::-webkit- slider-thumb"));
1017 expectFullRecalcForRuleSetInvalidation(false);
1018 }
1019
1020 TEST_F(RuleFeatureSetTest, RuleSetInvalidationSlotted)
1021 {
1022 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("::slotted(*)")) ;
1023 expectFullRecalcForRuleSetInvalidation(true);
1024 clearFeatures();
1025
1026 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("::slotted(.y)") );
1027 expectFullRecalcForRuleSetInvalidation(false);
1028 clearFeatures();
1029
1030 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".x::slotted(.y) "));
1031 expectFullRecalcForRuleSetInvalidation(false);
1032 clearFeatures();
1033
1034 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("[x] ::slotted(. y)"));
1035 expectFullRecalcForRuleSetInvalidation(false);
1036 }
1037
1038 TEST_F(RuleFeatureSetTest, RuleSetInvalidationAnyPseudo)
1039 {
1040 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(*, #x)"));
1041 expectFullRecalcForRuleSetInvalidation(true);
1042 clearFeatures();
1043
1044 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".x:-webkit-any( *, #y)"));
1045 expectFullRecalcForRuleSetInvalidation(false);
1046 clearFeatures();
1047
1048 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(:- webkit-any(.a, .b), #x)"));
1049 expectFullRecalcForRuleSetInvalidation(false);
1050 clearFeatures();
1051
1052 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(:- webkit-any(.a, *), #x)"));
1053 expectFullRecalcForRuleSetInvalidation(true);
1054 clearFeatures();
1055
1056 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(*, .a) *"));
1057 expectFullRecalcForRuleSetInvalidation(true);
1058 }
1059
908 } // namespace blink 1060 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/RuleFeature.cpp ('k') | third_party/WebKit/Source/core/css/RuleSet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698