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

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

Issue 2235723002: Use invalidation sets for nth invalidations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment ::before/::after Created 4 years, 4 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 { 107 {
108 Element* element = Traversal<HTMLElement>::firstChild(*Traversal<HTMLEle ment>::firstChild(*m_document->body())); 108 Element* element = Traversal<HTMLElement>::firstChild(*Traversal<HTMLEle ment>::firstChild(*m_document->body()));
109 m_ruleFeatureSet->collectInvalidationSetsForPseudoClass(invalidationList s, *element, pseudo); 109 m_ruleFeatureSet->collectInvalidationSetsForPseudoClass(invalidationList s, *element, pseudo);
110 } 110 }
111 111
112 void collectUniversalSiblingInvalidationSet(InvalidationLists& invalidationL ists) 112 void collectUniversalSiblingInvalidationSet(InvalidationLists& invalidationL ists)
113 { 113 {
114 m_ruleFeatureSet->collectUniversalSiblingInvalidationSet(invalidationLis ts, 1); 114 m_ruleFeatureSet->collectUniversalSiblingInvalidationSet(invalidationLis ts, 1);
115 } 115 }
116 116
117 void collectNthInvalidationSet(InvalidationLists& invalidationLists)
118 {
119 m_ruleFeatureSet->collectNthInvalidationSet(invalidationLists);
120 }
121
117 const HashSet<AtomicString>& classSet(const InvalidationSet& invalidationSet ) 122 const HashSet<AtomicString>& classSet(const InvalidationSet& invalidationSet )
118 { 123 {
119 return invalidationSet.classSetForTesting(); 124 return invalidationSet.classSetForTesting();
120 } 125 }
121 126
122 const HashSet<AtomicString>& idSet(const InvalidationSet& invalidationSet) 127 const HashSet<AtomicString>& idSet(const InvalidationSet& invalidationSet)
123 { 128 {
124 return invalidationSet.idSetForTesting(); 129 return invalidationSet.idSetForTesting();
125 } 130 }
126 131
(...skipping 17 matching lines...) Expand all
144 EXPECT_EQ(1u, invalidationSets.size()); 149 EXPECT_EQ(1u, invalidationSets.size());
145 EXPECT_TRUE(invalidationSets[0]->invalidatesSelf()); 150 EXPECT_TRUE(invalidationSets[0]->invalidatesSelf());
146 } 151 }
147 152
148 void expectNoSelfInvalidation(InvalidationSetVector& invalidationSets) 153 void expectNoSelfInvalidation(InvalidationSetVector& invalidationSets)
149 { 154 {
150 EXPECT_EQ(1u, invalidationSets.size()); 155 EXPECT_EQ(1u, invalidationSets.size());
151 EXPECT_FALSE(invalidationSets[0]->invalidatesSelf()); 156 EXPECT_FALSE(invalidationSets[0]->invalidatesSelf());
152 } 157 }
153 158
159 void expectWholeSubtreeInvalidation(InvalidationSetVector& invalidationSets)
160 {
161 EXPECT_EQ(1u, invalidationSets.size());
162 EXPECT_TRUE(invalidationSets[0]->wholeSubtreeInvalid());
163 }
164
154 void expectClassInvalidation(const AtomicString& className, InvalidationSetV ector& invalidationSets) 165 void expectClassInvalidation(const AtomicString& className, InvalidationSetV ector& invalidationSets)
155 { 166 {
156 EXPECT_EQ(1u, invalidationSets.size()); 167 EXPECT_EQ(1u, invalidationSets.size());
157 HashSet<AtomicString> classes = classSet(*invalidationSets[0]); 168 HashSet<AtomicString> classes = classSet(*invalidationSets[0]);
158 EXPECT_EQ(1u, classes.size()); 169 EXPECT_EQ(1u, classes.size());
159 EXPECT_TRUE(classes.contains(className)); 170 EXPECT_TRUE(classes.contains(className));
160 } 171 }
161 172
162 void expectSiblingInvalidation(unsigned maxDirectAdjacentSelectors, const At omicString& siblingName, InvalidationSetVector& invalidationSets) 173 void expectSiblingInvalidation(unsigned maxDirectAdjacentSelectors, const At omicString& siblingName, InvalidationSetVector& invalidationSets)
163 { 174 {
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 TEST_F(RuleFeatureSetTest, nonUniversalSiblingInvalidationLink) 727 TEST_F(RuleFeatureSetTest, nonUniversalSiblingInvalidationLink)
717 { 728 {
718 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("#x:link + .a")) ; 729 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("#x:link + .a")) ;
719 730
720 InvalidationLists invalidationLists; 731 InvalidationLists invalidationLists;
721 collectUniversalSiblingInvalidationSet(invalidationLists); 732 collectUniversalSiblingInvalidationSet(invalidationLists);
722 733
723 expectNoInvalidation(invalidationLists.siblings); 734 expectNoInvalidation(invalidationLists.siblings);
724 } 735 }
725 736
737 TEST_F(RuleFeatureSetTest, nthInvalidationUniversal)
738 {
739 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":nth-child(2n)" ));
740
741 InvalidationLists invalidationLists;
742 collectNthInvalidationSet(invalidationLists);
743
744 expectNoSelfInvalidation(invalidationLists.descendants);
745 expectWholeSubtreeInvalidation(invalidationLists.descendants);
746 }
747
748 TEST_F(RuleFeatureSetTest, nthInvalidationClass)
749 {
750 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a:nth-child(2n )"));
751
752 InvalidationLists invalidationLists;
753 collectNthInvalidationSet(invalidationLists);
754
755 expectNoSelfInvalidation(invalidationLists.descendants);
756 expectClassInvalidation("a", invalidationLists.descendants);
757 }
758
759 TEST_F(RuleFeatureSetTest, nthInvalidationUniversalDescendant)
760 {
761 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":nth-child(2n) *"));
762
763 InvalidationLists invalidationLists;
764 collectNthInvalidationSet(invalidationLists);
765
766 expectNoSelfInvalidation(invalidationLists.descendants);
767 expectWholeSubtreeInvalidation(invalidationLists.descendants);
768 }
769
770 TEST_F(RuleFeatureSetTest, nthInvalidationDescendant)
771 {
772 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":nth-child(2n) .a"));
773
774 InvalidationLists invalidationLists;
775 collectNthInvalidationSet(invalidationLists);
776
777 expectNoSelfInvalidation(invalidationLists.descendants);
778 expectClassInvalidation("a", invalidationLists.descendants);
779 }
780
781 TEST_F(RuleFeatureSetTest, nthInvalidationSibling)
782 {
783 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":nth-child(2n) + .a"));
784
785 InvalidationLists invalidationLists;
786 collectNthInvalidationSet(invalidationLists);
787
788 expectNoInvalidation(invalidationLists.siblings);
789 expectNoSelfInvalidation(invalidationLists.descendants);
790 expectClassInvalidation("a", invalidationLists.descendants);
791 }
792
793 TEST_F(RuleFeatureSetTest, nthInvalidationSiblingDescendant)
794 {
795 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":nth-child(2n) + .a .b"));
796
797 InvalidationLists invalidationLists;
798 collectNthInvalidationSet(invalidationLists);
799
800 expectNoInvalidation(invalidationLists.siblings);
801 expectNoSelfInvalidation(invalidationLists.descendants);
802 expectClassInvalidation("b", invalidationLists.descendants);
803 }
804
805 TEST_F(RuleFeatureSetTest, nthInvalidationNot)
806 {
807 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":not(:nth-child (2n))"));
808
809 InvalidationLists invalidationLists;
810 collectNthInvalidationSet(invalidationLists);
811
812 expectNoSelfInvalidation(invalidationLists.descendants);
813 expectWholeSubtreeInvalidation(invalidationLists.descendants);
814 }
815
816 TEST_F(RuleFeatureSetTest, nthInvalidationNotClass)
817 {
818 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a:not(:nth-chi ld(2n))"));
819
820 InvalidationLists invalidationLists;
821 collectNthInvalidationSet(invalidationLists);
822
823 expectNoSelfInvalidation(invalidationLists.descendants);
824 expectClassInvalidation("a", invalidationLists.descendants);
825 }
826
827 TEST_F(RuleFeatureSetTest, nthInvalidationNotDescendant)
828 {
829 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".blah:not(:nth- child(2n)) .a"));
830
831 InvalidationLists invalidationLists;
832 collectNthInvalidationSet(invalidationLists);
833
834 expectNoSelfInvalidation(invalidationLists.descendants);
835 expectClassInvalidation("a", invalidationLists.descendants);
836 }
837
838 TEST_F(RuleFeatureSetTest, nthInvalidationAny)
839 {
840 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(#n omatch, :nth-child(2n))"));
841
842 InvalidationLists invalidationLists;
843 collectNthInvalidationSet(invalidationLists);
844
845 expectNoSelfInvalidation(invalidationLists.descendants);
846 expectWholeSubtreeInvalidation(invalidationLists.descendants);
847 }
848
849 TEST_F(RuleFeatureSetTest, nthInvalidationAnyClass)
850 {
851 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a:-webkit-any( #nomatch, :nth-child(2n))"));
852
853 InvalidationLists invalidationLists;
854 collectNthInvalidationSet(invalidationLists);
855
856 expectNoSelfInvalidation(invalidationLists.descendants);
857 expectClassInvalidation("a", invalidationLists.descendants);
858 }
859
860 TEST_F(RuleFeatureSetTest, nthInvalidationAnyDescendant)
861 {
862 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".blah:-webkit-a ny(#nomatch, :nth-child(2n)) .a"));
863
864 InvalidationLists invalidationLists;
865 collectNthInvalidationSet(invalidationLists);
866
867 expectNoSelfInvalidation(invalidationLists.descendants);
868 expectClassInvalidation("a", invalidationLists.descendants);
869 }
870
726 } // namespace blink 871 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/RuleFeature.cpp ('k') | third_party/WebKit/Source/core/css/invalidation/StyleInvalidator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698