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

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

Issue 2474483002: [LazyParseCSS] Ensure UseCounting has parity with strict parsing (Closed)
Patch Set: s/!/!!/ Created 4 years 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 2016 The Chromium Authors. All rights reserved. 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 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/CSSStyleSheet.h" 5 #include "core/css/CSSStyleSheet.h"
6 #include "core/css/StyleRule.h" 6 #include "core/css/StyleRule.h"
7 #include "core/css/StyleSheetContents.h" 7 #include "core/css/StyleSheetContents.h"
8 #include "core/css/parser/CSSLazyParsingState.h" 8 #include "core/css/parser/CSSLazyParsingState.h"
9 #include "core/css/parser/CSSParser.h" 9 #include "core/css/parser/CSSParser.h"
10 #include "core/css/parser/CSSParserMode.h" 10 #include "core/css/parser/CSSParserMode.h"
(...skipping 11 matching lines...) Expand all
22 bool hasParsedProperties(StyleRule* rule) { 22 bool hasParsedProperties(StyleRule* rule) {
23 return rule->hasParsedProperties(); 23 return rule->hasParsedProperties();
24 } 24 }
25 25
26 StyleRule* ruleAt(StyleSheetContents* sheet, size_t index) { 26 StyleRule* ruleAt(StyleSheetContents* sheet, size_t index) {
27 return toStyleRule(sheet->childRules()[index]); 27 return toStyleRule(sheet->childRules()[index]);
28 } 28 }
29 29
30 protected: 30 protected:
31 HistogramTester m_histogramTester; 31 HistogramTester m_histogramTester;
32 Persistent<StyleSheetContents> m_cachedContents;
32 }; 33 };
33 34
34 TEST_F(CSSLazyParsingTest, Simple) { 35 TEST_F(CSSLazyParsingTest, Simple) {
35 CSSParserContext context(HTMLStandardMode, nullptr); 36 CSSParserContext context(HTMLStandardMode, nullptr);
36 StyleSheetContents* styleSheet = StyleSheetContents::create(context); 37 StyleSheetContents* styleSheet = StyleSheetContents::create(context);
37 38
38 String sheetText = "body { background-color: red; }"; 39 String sheetText = "body { background-color: red; }";
39 CSSParser::parseSheet(context, styleSheet, sheetText, true /* lazy parse */); 40 CSSParser::parseSheet(context, styleSheet, sheetText, true /* lazy parse */);
40 StyleRule* rule = ruleAt(styleSheet, 0); 41 StyleRule* rule = ruleAt(styleSheet, 0);
41 EXPECT_FALSE(hasParsedProperties(rule)); 42 EXPECT_FALSE(hasParsedProperties(rule));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 113 }
113 114
114 // Regression test for crbug.com/660290 where we change the underlying owning 115 // Regression test for crbug.com/660290 where we change the underlying owning
115 // document from the StyleSheetContents without changing the UseCounter. This 116 // document from the StyleSheetContents without changing the UseCounter. This
116 // test ensures that the new UseCounter is used when doing new parsing work. 117 // test ensures that the new UseCounter is used when doing new parsing work.
117 TEST_F(CSSLazyParsingTest, ChangeDocuments) { 118 TEST_F(CSSLazyParsingTest, ChangeDocuments) {
118 std::unique_ptr<DummyPageHolder> dummyHolder = 119 std::unique_ptr<DummyPageHolder> dummyHolder =
119 DummyPageHolder::create(IntSize(500, 500)); 120 DummyPageHolder::create(IntSize(500, 500));
120 CSSParserContext context(HTMLStandardMode, 121 CSSParserContext context(HTMLStandardMode,
121 UseCounter::getFrom(&dummyHolder->document())); 122 UseCounter::getFrom(&dummyHolder->document()));
122 StyleSheetContents* styleSheet = StyleSheetContents::create(context); 123 m_cachedContents = StyleSheetContents::create(context);
123 CSSStyleSheet* sheet = 124 {
124 CSSStyleSheet::create(styleSheet, dummyHolder->document()); 125 CSSStyleSheet* sheet =
125 DCHECK(sheet); 126 CSSStyleSheet::create(m_cachedContents, dummyHolder->document());
127 DCHECK(sheet);
126 128
127 String sheetText = "body { background-color: red; } p { color: orange; }"; 129 String sheetText = "body { background-color: red; } p { color: orange; }";
128 CSSParser::parseSheet(context, styleSheet, sheetText, true /* lazy parse */); 130 CSSParser::parseSheet(context, m_cachedContents, sheetText,
131 true /* lazy parse */);
129 132
130 // Parse the first property set with the first document as owner. 133 // Parse the first property set with the first document as owner.
131 StyleRule* rule = ruleAt(styleSheet, 0); 134 StyleRule* rule = ruleAt(m_cachedContents, 0);
132 EXPECT_FALSE(hasParsedProperties(rule)); 135 EXPECT_FALSE(hasParsedProperties(rule));
133 rule->properties(); 136 rule->properties();
134 EXPECT_TRUE(hasParsedProperties(rule)); 137 EXPECT_TRUE(hasParsedProperties(rule));
135 138
136 EXPECT_EQ(&dummyHolder->document(), styleSheet->singleOwnerDocument()); 139 EXPECT_EQ(&dummyHolder->document(),
140 m_cachedContents->singleOwnerDocument());
141 UseCounter& useCounter1 = dummyHolder->document().frameHost()->useCounter();
142 EXPECT_TRUE(useCounter1.isCounted(CSSPropertyBackgroundColor));
143 EXPECT_FALSE(useCounter1.isCounted(CSSPropertyColor));
137 144
138 // Change owner document. 145 // Change owner document.
139 styleSheet->unregisterClient(sheet); 146 m_cachedContents->unregisterClient(sheet);
147 dummyHolder.reset();
148 }
149 // Ensure no stack references to oilpan objects.
150 ThreadState::current()->collectAllGarbage();
151
140 std::unique_ptr<DummyPageHolder> dummyHolder2 = 152 std::unique_ptr<DummyPageHolder> dummyHolder2 =
141 DummyPageHolder::create(IntSize(500, 500)); 153 DummyPageHolder::create(IntSize(500, 500));
142 CSSStyleSheet::create(styleSheet, dummyHolder2->document()); 154 CSSStyleSheet* sheet2 =
155 CSSStyleSheet::create(m_cachedContents, dummyHolder2->document());
143 156
144 EXPECT_EQ(&dummyHolder2->document(), styleSheet->singleOwnerDocument()); 157 EXPECT_EQ(&dummyHolder2->document(), m_cachedContents->singleOwnerDocument());
145 158
146 // Parse the second property set with the second document as owner. 159 // Parse the second property set with the second document as owner.
147 StyleRule* rule2 = ruleAt(styleSheet, 1); 160 StyleRule* rule2 = ruleAt(m_cachedContents, 1);
148 EXPECT_FALSE(hasParsedProperties(rule2)); 161 EXPECT_FALSE(hasParsedProperties(rule2));
149 rule2->properties(); 162 rule2->properties();
150 EXPECT_TRUE(hasParsedProperties(rule2)); 163 EXPECT_TRUE(hasParsedProperties(rule2));
151 164
152 UseCounter& useCounter1 = dummyHolder->document().frameHost()->useCounter();
153 UseCounter& useCounter2 = dummyHolder2->document().frameHost()->useCounter(); 165 UseCounter& useCounter2 = dummyHolder2->document().frameHost()->useCounter();
154 EXPECT_TRUE(useCounter1.isCounted(CSSPropertyBackgroundColor)); 166 EXPECT_TRUE(sheet2);
155 EXPECT_TRUE(useCounter2.isCounted(CSSPropertyColor)); 167 EXPECT_TRUE(useCounter2.isCounted(CSSPropertyColor));
156 EXPECT_FALSE(useCounter2.isCounted(CSSPropertyBackgroundColor)); 168 EXPECT_FALSE(useCounter2.isCounted(CSSPropertyBackgroundColor));
157 EXPECT_FALSE(useCounter1.isCounted(CSSPropertyColor));
158 } 169 }
159 170
160 TEST_F(CSSLazyParsingTest, SimpleRuleUsagePercent) { 171 TEST_F(CSSLazyParsingTest, SimpleRuleUsagePercent) {
161 CSSParserContext context(HTMLStandardMode, nullptr); 172 CSSParserContext context(HTMLStandardMode, nullptr);
162 StyleSheetContents* styleSheet = StyleSheetContents::create(context); 173 StyleSheetContents* styleSheet = StyleSheetContents::create(context);
163 174
164 std::string metricName = "Style.LazyUsage.Percent"; 175 std::string metricName = "Style.LazyUsage.Percent";
165 m_histogramTester.expectTotalCount(metricName, 0); 176 m_histogramTester.expectTotalCount(metricName, 0);
166 177
167 String sheetText = 178 String sheetText =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // Parsing the last rule bumps both Gt90 and All buckets. 210 // Parsing the last rule bumps both Gt90 and All buckets.
200 ruleAt(styleSheet, 4)->properties(); 211 ruleAt(styleSheet, 4)->properties();
201 m_histogramTester.expectTotalCount(metricName, 7); 212 m_histogramTester.expectTotalCount(metricName, 7);
202 m_histogramTester.expectBucketCount(metricName, 213 m_histogramTester.expectBucketCount(metricName,
203 CSSLazyParsingState::UsageGt90, 1); 214 CSSLazyParsingState::UsageGt90, 1);
204 m_histogramTester.expectBucketCount(metricName, CSSLazyParsingState::UsageAll, 215 m_histogramTester.expectBucketCount(metricName, CSSLazyParsingState::UsageAll,
205 1); 216 1);
206 } 217 }
207 218
208 } // namespace blink 219 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698