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

Side by Side Diff: Source/core/css/resolver/MatchResultTest.cpp

Issue 1282243002: Prepare for multiple !important author ranges. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Missing STACK_ALLOCATED() Created 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/css/resolver/MatchResult.h"
7
8 #include "core/css/StylePropertySet.h"
9 #include <gtest/gtest.h>
10
11 namespace blink {
12
13 class MatchResultTest : public ::testing::Test {
14 protected:
15 void SetUp() override;
16
17 const StylePropertySet* propertySet(unsigned index) const
18 {
19 return propertySets[index].get();
20 }
21
22 private:
23 WillBePersistentHeapVector<RefPtrWillBeMember<MutableStylePropertySet>, 6> p ropertySets;
24 };
25
26 void MatchResultTest::SetUp()
27 {
28 for (unsigned i = 0; i < 6; i++)
29 propertySets.append(MutableStylePropertySet::create());
30 }
31
32 void testMatchedPropertiesRange(const MatchedPropertiesRange& range, int expecte dLength, const StylePropertySet** expectedSets)
33 {
34 EXPECT_EQ(expectedLength, range.end() - range.begin());
35 for (const auto& matchedProperties : range)
36 EXPECT_EQ(*expectedSets++, matchedProperties.properties);
37 }
38
39 TEST_F(MatchResultTest, UARules)
40 {
41 const StylePropertySet* uaSets[] = { propertySet(0), propertySet(1) };
42
43 MatchResult result;
44 result.addMatchedProperties(uaSets[0]);
45 result.addMatchedProperties(uaSets[1]);
46 result.finishAddingUARules();
47
48 result.finishAddingAuthorRulesForTreeScope();
49
50 testMatchedPropertiesRange(result.allRules(), 2, uaSets);
51 testMatchedPropertiesRange(result.uaRules(), 2, uaSets);
52 testMatchedPropertiesRange(result.authorRules(), 0, nullptr);
53
54 ImportantAuthorRanges important(result);
55 EXPECT_EQ(important.end(), important.begin());
56 }
57
58 TEST_F(MatchResultTest, AuthorRules)
59 {
60 const StylePropertySet* authorSets[] = { propertySet(0), propertySet(1) };
61
62 MatchResult result;
63
64 result.finishAddingUARules();
65 result.addMatchedProperties(authorSets[0]);
66 result.addMatchedProperties(authorSets[1]);
67 result.finishAddingAuthorRulesForTreeScope();
68
69 testMatchedPropertiesRange(result.allRules(), 2, authorSets);
70 testMatchedPropertiesRange(result.uaRules(), 0, nullptr);
71 testMatchedPropertiesRange(result.authorRules(), 2, authorSets);
72
73 ImportantAuthorRanges important(result);
74 EXPECT_EQ(important.end(), ++important.begin());
75 }
76
77 TEST_F(MatchResultTest, UAAndAuthorRules)
78 {
79 const StylePropertySet* allSets[] = { propertySet(0), propertySet(1), proper tySet(2), propertySet(3) };
80 const StylePropertySet** uaSets = &allSets[0];
81 const StylePropertySet** authorSets = &allSets[2];
82
83 MatchResult result;
84
85 result.addMatchedProperties(uaSets[0]);
86 result.addMatchedProperties(uaSets[1]);
87 result.finishAddingUARules();
88
89 result.addMatchedProperties(authorSets[0]);
90 result.addMatchedProperties(authorSets[1]);
91 result.finishAddingAuthorRulesForTreeScope();
92
93 testMatchedPropertiesRange(result.allRules(), 4, allSets);
94 testMatchedPropertiesRange(result.uaRules(), 2, uaSets);
95 testMatchedPropertiesRange(result.authorRules(), 2, authorSets);
96
97 ImportantAuthorRanges important(result);
98 EXPECT_EQ(important.end(), ++important.begin());
99 }
100
101 TEST_F(MatchResultTest, AuthorRulesMultipleScopes)
102 {
103 const StylePropertySet* authorSets[] = { propertySet(0), propertySet(1), pro pertySet(2), propertySet(3) };
104
105 MatchResult result;
106
107 result.finishAddingUARules();
108
109 result.addMatchedProperties(authorSets[0]);
110 result.addMatchedProperties(authorSets[1]);
111 result.finishAddingAuthorRulesForTreeScope();
112
113 result.addMatchedProperties(authorSets[2]);
114 result.addMatchedProperties(authorSets[3]);
115 result.finishAddingAuthorRulesForTreeScope();
116
117 testMatchedPropertiesRange(result.allRules(), 4, authorSets);
118 testMatchedPropertiesRange(result.uaRules(), 0, nullptr);
119 testMatchedPropertiesRange(result.authorRules(), 4, authorSets);
120
121 ImportantAuthorRanges important(result);
122
123 auto iter = important.begin();
124 EXPECT_NE(important.end(), iter);
125 testMatchedPropertiesRange(*iter, 2, &authorSets[2]);
126
127 ++iter;
128 EXPECT_NE(important.end(), iter);
129 testMatchedPropertiesRange(*iter, 2, authorSets);
130
131 ++iter;
132 EXPECT_EQ(important.end(), iter);
133 }
134
135 TEST_F(MatchResultTest, UARulesAndAuthorRulesMultipleScopes)
136 {
137 const StylePropertySet* allSets[] = { propertySet(0), propertySet(1), proper tySet(2), propertySet(3), propertySet(4), propertySet(5) };
138 const StylePropertySet** uaSets = &allSets[0];
139 const StylePropertySet** authorSets = &allSets[2];
140
141 MatchResult result;
142
143 result.addMatchedProperties(uaSets[0]);
144 result.addMatchedProperties(uaSets[1]);
145 result.finishAddingUARules();
146
147 result.addMatchedProperties(authorSets[0]);
148 result.addMatchedProperties(authorSets[1]);
149 result.finishAddingAuthorRulesForTreeScope();
150
151 result.addMatchedProperties(authorSets[2]);
152 result.addMatchedProperties(authorSets[3]);
153 result.finishAddingAuthorRulesForTreeScope();
154
155 testMatchedPropertiesRange(result.allRules(), 6, allSets);
156 testMatchedPropertiesRange(result.uaRules(), 2, uaSets);
157 testMatchedPropertiesRange(result.authorRules(), 4, authorSets);
158
159 ImportantAuthorRanges important(result);
160
161 ImportantAuthorRangeIterator iter = important.begin();
162 EXPECT_NE(important.end(), iter);
163 testMatchedPropertiesRange(*iter, 2, &authorSets[2]);
164
165 ++iter;
166 EXPECT_NE(important.end(), iter);
167 testMatchedPropertiesRange(*iter, 2, authorSets);
168
169 ++iter;
170 EXPECT_EQ(important.end(), iter);
171 }
172
173 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/resolver/MatchResult.cpp ('k') | Source/core/css/resolver/MatchedPropertiesCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698