| OLD | NEW |
| 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/CSSParserContext.h" | 10 #include "core/css/parser/CSSParserContext.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 UseCounter& useCounter2 = dummyHolder2->document().frameHost()->useCounter(); | 166 UseCounter& useCounter2 = dummyHolder2->document().frameHost()->useCounter(); |
| 167 EXPECT_TRUE(sheet2); | 167 EXPECT_TRUE(sheet2); |
| 168 EXPECT_TRUE(useCounter2.isCounted(CSSPropertyColor)); | 168 EXPECT_TRUE(useCounter2.isCounted(CSSPropertyColor)); |
| 169 EXPECT_FALSE(useCounter2.isCounted(CSSPropertyBackgroundColor)); | 169 EXPECT_FALSE(useCounter2.isCounted(CSSPropertyBackgroundColor)); |
| 170 } | 170 } |
| 171 | 171 |
| 172 TEST_F(CSSLazyParsingTest, SimpleRuleUsagePercent) { | 172 TEST_F(CSSLazyParsingTest, SimpleRuleUsagePercent) { |
| 173 CSSParserContext* context = CSSParserContext::create(HTMLStandardMode); | 173 CSSParserContext* context = CSSParserContext::create(HTMLStandardMode); |
| 174 StyleSheetContents* styleSheet = StyleSheetContents::create(context); | 174 StyleSheetContents* styleSheet = StyleSheetContents::create(context); |
| 175 | 175 |
| 176 std::string metricName = "Style.LazyUsage.Percent"; | 176 std::string usageMetric = "Style.LazyUsage.Percent"; |
| 177 m_histogramTester.expectTotalCount(metricName, 0); | 177 std::string totalRulesMetric = "Style.TotalLazyRules"; |
| 178 std::string totalRulesFullUsageMetric = "Style.TotalLazyRules.FullUsage"; |
| 179 m_histogramTester.expectTotalCount(usageMetric, 0); |
| 178 | 180 |
| 179 String sheetText = | 181 String sheetText = |
| 180 "body { background-color: red; }" | 182 "body { background-color: red; }" |
| 181 "p { color: blue; }" | 183 "p { color: blue; }" |
| 182 "a { color: yellow; }" | 184 "a { color: yellow; }" |
| 183 "#id { color: blue; }" | 185 "#id { color: blue; }" |
| 184 "div { color: grey; }"; | 186 "div { color: grey; }"; |
| 185 CSSParser::parseSheet(context, styleSheet, sheetText, true /* lazy parse */); | 187 CSSParser::parseSheet(context, styleSheet, sheetText, true /* lazy parse */); |
| 186 | 188 |
| 187 m_histogramTester.expectTotalCount(metricName, 1); | 189 m_histogramTester.expectTotalCount(totalRulesMetric, 1); |
| 188 m_histogramTester.expectUniqueSample(metricName, | 190 m_histogramTester.expectUniqueSample(totalRulesMetric, 5, 1); |
| 191 |
| 192 // Only log the full usage metric when all the rules have been actually |
| 193 // parsed. |
| 194 m_histogramTester.expectTotalCount(totalRulesFullUsageMetric, 0); |
| 195 |
| 196 m_histogramTester.expectTotalCount(usageMetric, 1); |
| 197 m_histogramTester.expectUniqueSample(usageMetric, |
| 189 CSSLazyParsingState::UsageGe0, 1); | 198 CSSLazyParsingState::UsageGe0, 1); |
| 190 | 199 |
| 191 ruleAt(styleSheet, 0)->properties(); | 200 ruleAt(styleSheet, 0)->properties(); |
| 192 m_histogramTester.expectTotalCount(metricName, 2); | 201 m_histogramTester.expectTotalCount(usageMetric, 2); |
| 193 m_histogramTester.expectBucketCount(metricName, | 202 m_histogramTester.expectBucketCount(usageMetric, |
| 194 CSSLazyParsingState::UsageGt10, 1); | 203 CSSLazyParsingState::UsageGt10, 1); |
| 195 | 204 |
| 196 ruleAt(styleSheet, 1)->properties(); | 205 ruleAt(styleSheet, 1)->properties(); |
| 197 m_histogramTester.expectTotalCount(metricName, 3); | 206 m_histogramTester.expectTotalCount(usageMetric, 3); |
| 198 m_histogramTester.expectBucketCount(metricName, | 207 m_histogramTester.expectBucketCount(usageMetric, |
| 199 CSSLazyParsingState::UsageGt25, 1); | 208 CSSLazyParsingState::UsageGt25, 1); |
| 200 | 209 |
| 201 ruleAt(styleSheet, 2)->properties(); | 210 ruleAt(styleSheet, 2)->properties(); |
| 202 m_histogramTester.expectTotalCount(metricName, 4); | 211 m_histogramTester.expectTotalCount(usageMetric, 4); |
| 203 m_histogramTester.expectBucketCount(metricName, | 212 m_histogramTester.expectBucketCount(usageMetric, |
| 204 CSSLazyParsingState::UsageGt50, 1); | 213 CSSLazyParsingState::UsageGt50, 1); |
| 205 | 214 |
| 206 ruleAt(styleSheet, 3)->properties(); | 215 ruleAt(styleSheet, 3)->properties(); |
| 207 m_histogramTester.expectTotalCount(metricName, 5); | 216 m_histogramTester.expectTotalCount(usageMetric, 5); |
| 208 m_histogramTester.expectBucketCount(metricName, | 217 m_histogramTester.expectBucketCount(usageMetric, |
| 209 CSSLazyParsingState::UsageGt75, 1); | 218 CSSLazyParsingState::UsageGt75, 1); |
| 210 | 219 |
| 220 // Only log the full usage metric when all the rules have been actually |
| 221 // parsed. |
| 222 m_histogramTester.expectTotalCount(totalRulesFullUsageMetric, 0); |
| 223 |
| 211 // Parsing the last rule bumps both Gt90 and All buckets. | 224 // Parsing the last rule bumps both Gt90 and All buckets. |
| 212 ruleAt(styleSheet, 4)->properties(); | 225 ruleAt(styleSheet, 4)->properties(); |
| 213 m_histogramTester.expectTotalCount(metricName, 7); | 226 m_histogramTester.expectTotalCount(usageMetric, 7); |
| 214 m_histogramTester.expectBucketCount(metricName, | 227 m_histogramTester.expectBucketCount(usageMetric, |
| 215 CSSLazyParsingState::UsageGt90, 1); | 228 CSSLazyParsingState::UsageGt90, 1); |
| 216 m_histogramTester.expectBucketCount(metricName, CSSLazyParsingState::UsageAll, | 229 m_histogramTester.expectBucketCount(usageMetric, |
| 217 1); | 230 CSSLazyParsingState::UsageAll, 1); |
| 231 |
| 232 m_histogramTester.expectTotalCount(totalRulesFullUsageMetric, 1); |
| 233 m_histogramTester.expectUniqueSample(totalRulesFullUsageMetric, 5, 1); |
| 218 } | 234 } |
| 219 | 235 |
| 220 } // namespace blink | 236 } // namespace blink |
| OLD | NEW |