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

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

Issue 1889993002: Implemented RuleSet diff for active stylesheets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
(Empty)
1 // Copyright 2016 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 "core/css/ActiveStyleSheets.h"
6
7 #include "core/css/CSSStyleSheet.h"
8 #include "core/css/MediaQueryEvaluator.h"
9 #include "core/css/StyleSheetContents.h"
10 #include "core/css/parser/CSSParserMode.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace blink {
14
15 class ActiveStyleSheetsTest : public ::testing::Test {
16 public:
17 static CSSStyleSheet* createSheet()
18 {
19 StyleSheetContents* contents = StyleSheetContents::create(CSSParserConte xt(HTMLStandardMode, nullptr));
20 contents->ensureRuleSet(MediaQueryEvaluator(), RuleHasDocumentSecurityOr igin);
21 return CSSStyleSheet::create(contents);
22 }
23 };
24
25 TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_NoChange)
26 {
27 ActiveStyleSheetVector oldSheets;
28 ActiveStyleSheetVector newSheets;
29 HeapVector<Member<RuleSet>> changedRuleSets;
30
31 EXPECT_EQ(NoActiveSheetsChanged, compareActiveStyleSheets(oldSheets, newShee ts, changedRuleSets));
32 EXPECT_EQ(0u, changedRuleSets.size());
33
34 CSSStyleSheet* sheet1 = createSheet();
35 CSSStyleSheet* sheet2 = createSheet();
36
37 oldSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
38 oldSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
39
40 newSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
41 newSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
42
43 EXPECT_EQ(NoActiveSheetsChanged, compareActiveStyleSheets(oldSheets, newShee ts, changedRuleSets));
44 EXPECT_EQ(0u, changedRuleSets.size());
45 }
46
47 TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_AppendedToEmpty)
48 {
49 ActiveStyleSheetVector oldSheets;
50 ActiveStyleSheetVector newSheets;
51 HeapVector<Member<RuleSet>> changedRuleSets;
52
53 CSSStyleSheet* sheet1 = createSheet();
54 CSSStyleSheet* sheet2 = createSheet();
55
56 newSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
57 newSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
58
59 EXPECT_EQ(ActiveSheetsAppended, compareActiveStyleSheets(oldSheets, newSheet s, changedRuleSets));
60 EXPECT_EQ(2u, changedRuleSets.size());
61 }
62
63 TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_AppendedToNonEmpty)
64 {
65 ActiveStyleSheetVector oldSheets;
66 ActiveStyleSheetVector newSheets;
67 HeapVector<Member<RuleSet>> changedRuleSets;
68
69 CSSStyleSheet* sheet1 = createSheet();
70 CSSStyleSheet* sheet2 = createSheet();
71
72 oldSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
73 newSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
74 newSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
75
76 EXPECT_EQ(ActiveSheetsAppended, compareActiveStyleSheets(oldSheets, newSheet s, changedRuleSets));
77 EXPECT_EQ(1u, changedRuleSets.size());
78 }
79
80 TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_Mutated)
81 {
82 ActiveStyleSheetVector oldSheets;
83 ActiveStyleSheetVector newSheets;
84 HeapVector<Member<RuleSet>> changedRuleSets;
85
86 CSSStyleSheet* sheet1 = createSheet();
87 CSSStyleSheet* sheet2 = createSheet();
88 CSSStyleSheet* sheet3 = createSheet();
89
90 oldSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
91 oldSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
92 oldSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));
93
94 sheet2->contents()->clearRuleSet();
95 sheet2->contents()->ensureRuleSet(MediaQueryEvaluator(), RuleHasDocumentSecu rityOrigin);
96
97 EXPECT_NE(oldSheets[1].second, &sheet2->contents()->ruleSet());
98
99 newSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
100 newSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
101 newSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));
102
103 EXPECT_EQ(ActiveSheetsChanged, compareActiveStyleSheets(oldSheets, newSheets , changedRuleSets));
104 ASSERT_EQ(2u, changedRuleSets.size());
105 EXPECT_EQ(&sheet2->contents()->ruleSet(), changedRuleSets[0]);
106 EXPECT_EQ(oldSheets[1].second, changedRuleSets[1]);
107 }
108
109 TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_Inserted)
110 {
111 ActiveStyleSheetVector oldSheets;
112 ActiveStyleSheetVector newSheets;
113 HeapVector<Member<RuleSet>> changedRuleSets;
114
115 CSSStyleSheet* sheet1 = createSheet();
116 CSSStyleSheet* sheet2 = createSheet();
117 CSSStyleSheet* sheet3 = createSheet();
118
119 oldSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
120 oldSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));
121
122 newSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
123 newSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
124 newSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));
125
126 EXPECT_EQ(ActiveSheetsChanged, compareActiveStyleSheets(oldSheets, newSheets , changedRuleSets));
127 ASSERT_EQ(1u, changedRuleSets.size());
128 EXPECT_EQ(&sheet2->contents()->ruleSet(), changedRuleSets[0]);
129 }
130
131 TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_Removed)
132 {
133 ActiveStyleSheetVector oldSheets;
134 ActiveStyleSheetVector newSheets;
135 HeapVector<Member<RuleSet>> changedRuleSets;
136
137 CSSStyleSheet* sheet1 = createSheet();
138 CSSStyleSheet* sheet2 = createSheet();
139 CSSStyleSheet* sheet3 = createSheet();
140
141 oldSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
142 oldSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
143 oldSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));
144
145 newSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
146 newSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));
147
148 EXPECT_EQ(ActiveSheetsChanged, compareActiveStyleSheets(oldSheets, newSheets , changedRuleSets));
149 ASSERT_EQ(1u, changedRuleSets.size());
150 EXPECT_EQ(&sheet2->contents()->ruleSet(), changedRuleSets[0]);
151 }
152
153 TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_RemovedAll)
154 {
155 ActiveStyleSheetVector oldSheets;
156 ActiveStyleSheetVector newSheets;
157 HeapVector<Member<RuleSet>> changedRuleSets;
158
159 CSSStyleSheet* sheet1 = createSheet();
160 CSSStyleSheet* sheet2 = createSheet();
161 CSSStyleSheet* sheet3 = createSheet();
162
163 oldSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
164 oldSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
165 oldSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));
166
167 EXPECT_EQ(ActiveSheetsChanged, compareActiveStyleSheets(oldSheets, newSheets , changedRuleSets));
168 EXPECT_EQ(3u, changedRuleSets.size());
169 }
170
171 TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_InsertedAndRemoved)
172 {
173 ActiveStyleSheetVector oldSheets;
174 ActiveStyleSheetVector newSheets;
175 HeapVector<Member<RuleSet>> changedRuleSets;
176
177 CSSStyleSheet* sheet1 = createSheet();
178 CSSStyleSheet* sheet2 = createSheet();
179 CSSStyleSheet* sheet3 = createSheet();
180
181 oldSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
182 oldSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
183
184 newSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
185 newSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));
186
187 EXPECT_EQ(ActiveSheetsChanged, compareActiveStyleSheets(oldSheets, newSheets , changedRuleSets));
188 ASSERT_EQ(2u, changedRuleSets.size());
189 EXPECT_EQ(&sheet1->contents()->ruleSet(), changedRuleSets[0]);
190 EXPECT_EQ(&sheet3->contents()->ruleSet(), changedRuleSets[1]);
191 }
192
193 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/ActiveStyleSheets.cpp ('k') | third_party/WebKit/Source/core/css/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698