Commit 88bf2a73 authored by Rob Dodson's avatar Rob Dodson Committed by Commit Bot

Add use counters for :focus and :focus-visible.

The goal of this change is to track developer uptake of :focus-visible,
once it ships from behind a flag. We also want to monitor the usage
of :focus. This data will help us explore possibly switching the UA stylesheet
over to using :focus-visible someday.


R=aboxhall@chromium.org

Bug: 817199
Change-Id: I257ab590f03d28831ec517b67f42e6f86a156ee9
Reviewed-on: https://chromium-review.googlesource.com/954102Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarTakayoshi Kochi <kochi@chromium.org>
Reviewed-by: default avatarLuna Lu <loonybear@chromium.org>
Reviewed-by: default avatarRick Byers <rbyers@chromium.org>
Commit-Queue: Rob Dodson <robdodson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542279}
parent f9b7ab57
...@@ -945,6 +945,15 @@ void CSSSelectorParser::RecordUsageAndDeprecations( ...@@ -945,6 +945,15 @@ void CSSSelectorParser::RecordUsageAndDeprecations(
DCHECK(RuntimeEnabledFeatures::CSSMatchesEnabled()); DCHECK(RuntimeEnabledFeatures::CSSMatchesEnabled());
feature = WebFeature::kCSSSelectorPseudoMatches; feature = WebFeature::kCSSSelectorPseudoMatches;
break; break;
case CSSSelector::kPseudoFocusVisible:
DCHECK(RuntimeEnabledFeatures::CSSFocusVisibleEnabled());
if (context_->Mode() != kUASheetMode)
feature = WebFeature::kCSSSelectorPseudoFocusVisible;
break;
case CSSSelector::kPseudoFocus:
if (context_->Mode() != kUASheetMode)
feature = WebFeature::kCSSSelectorPseudoFocus;
break;
case CSSSelector::kPseudoAnyLink: case CSSSelector::kPseudoAnyLink:
feature = WebFeature::kCSSSelectorPseudoAnyLink; feature = WebFeature::kCSSSelectorPseudoAnyLink;
break; break;
......
...@@ -249,47 +249,6 @@ TEST_F(UseCounterTest, SVGImageContextAnimatedCSSProperties) { ...@@ -249,47 +249,6 @@ TEST_F(UseCounterTest, SVGImageContextAnimatedCSSProperties) {
[&](LocalFrame* frame) { use_counter.DidCommitLoad(frame); }, kSvgUrl); [&](LocalFrame* frame) { use_counter.DidCommitLoad(frame); }, kSvgUrl);
} }
TEST_F(UseCounterTest, CSSSelectorPseudoAnyLink) {
std::unique_ptr<DummyPageHolder> dummy_page_holder =
DummyPageHolder::Create(IntSize(800, 600));
Document& document = dummy_page_holder->GetDocument();
WebFeature feature = WebFeature::kCSSSelectorPseudoAnyLink;
EXPECT_FALSE(UseCounter::IsCounted(document, feature));
document.documentElement()->SetInnerHTMLFromString(
"<style>:any-link { color: red; }</style>");
EXPECT_TRUE(UseCounter::IsCounted(document, feature));
}
TEST_F(UseCounterTest, CSSSelectorPseudoWebkitAnyLink) {
std::unique_ptr<DummyPageHolder> dummy_page_holder =
DummyPageHolder::Create(IntSize(800, 600));
Document& document = dummy_page_holder->GetDocument();
WebFeature feature = WebFeature::kCSSSelectorPseudoWebkitAnyLink;
EXPECT_FALSE(UseCounter::IsCounted(document, feature));
document.documentElement()->SetInnerHTMLFromString(
"<style>:-webkit-any-link { color: red; }</style>");
EXPECT_TRUE(UseCounter::IsCounted(document, feature));
}
TEST_F(UseCounterTest, CSSTypedOMStylePropertyMap) {
UseCounter use_counter;
WebFeature feature = WebFeature::kCSSTypedOMStylePropertyMap;
EXPECT_FALSE(use_counter.IsCounted(GetDocument(), feature));
use_counter.Count(GetDocument(), feature);
EXPECT_TRUE(use_counter.IsCounted(GetDocument(), feature));
}
TEST_F(UseCounterTest, CSSSelectorPseudoMatches) {
std::unique_ptr<DummyPageHolder> dummy_page_holder =
DummyPageHolder::Create(IntSize(800, 600));
Document& document = dummy_page_holder->GetDocument();
WebFeature feature = WebFeature::kCSSSelectorPseudoMatches;
EXPECT_FALSE(UseCounter::IsCounted(document, feature));
document.documentElement()->SetInnerHTMLFromString(
"<style>.a+:matches(.b, .c+.d) { color: red; }</style>");
EXPECT_TRUE(UseCounter::IsCounted(document, feature));
}
TEST_F(UseCounterTest, InspectorDisablesMeasurement) { TEST_F(UseCounterTest, InspectorDisablesMeasurement) {
UseCounter use_counter; UseCounter use_counter;
...@@ -336,6 +295,58 @@ TEST_F(UseCounterTest, InspectorDisablesMeasurement) { ...@@ -336,6 +295,58 @@ TEST_F(UseCounterTest, InspectorDisablesMeasurement) {
UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram(property), 1); UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram(property), 1);
} }
/*
* Counter-specific tests
*
* NOTE: Most individual UseCounters don't need dedicated test cases. They are
* "tested" by analyzing the data they generate including on some known pages.
* Feel free to add tests for counters where the triggering logic is
* non-trivial, but it's not required. Manual analysis is necessary to trust the
* data anyway, real-world pages are full of edge-cases and surprises that you
* won't find in unit testing anyway.
*/
TEST_F(UseCounterTest, CSSSelectorPseudoAnyLink) {
std::unique_ptr<DummyPageHolder> dummy_page_holder =
DummyPageHolder::Create(IntSize(800, 600));
Document& document = dummy_page_holder->GetDocument();
WebFeature feature = WebFeature::kCSSSelectorPseudoAnyLink;
EXPECT_FALSE(UseCounter::IsCounted(document, feature));
document.documentElement()->SetInnerHTMLFromString(
"<style>:any-link { color: red; }</style>");
EXPECT_TRUE(UseCounter::IsCounted(document, feature));
}
TEST_F(UseCounterTest, CSSSelectorPseudoWebkitAnyLink) {
std::unique_ptr<DummyPageHolder> dummy_page_holder =
DummyPageHolder::Create(IntSize(800, 600));
Document& document = dummy_page_holder->GetDocument();
WebFeature feature = WebFeature::kCSSSelectorPseudoWebkitAnyLink;
EXPECT_FALSE(UseCounter::IsCounted(document, feature));
document.documentElement()->SetInnerHTMLFromString(
"<style>:-webkit-any-link { color: red; }</style>");
EXPECT_TRUE(UseCounter::IsCounted(document, feature));
}
TEST_F(UseCounterTest, CSSTypedOMStylePropertyMap) {
UseCounter use_counter;
WebFeature feature = WebFeature::kCSSTypedOMStylePropertyMap;
EXPECT_FALSE(use_counter.IsCounted(GetDocument(), feature));
use_counter.Count(GetDocument(), feature);
EXPECT_TRUE(use_counter.IsCounted(GetDocument(), feature));
}
TEST_F(UseCounterTest, CSSSelectorPseudoMatches) {
std::unique_ptr<DummyPageHolder> dummy_page_holder =
DummyPageHolder::Create(IntSize(800, 600));
Document& document = dummy_page_holder->GetDocument();
WebFeature feature = WebFeature::kCSSSelectorPseudoMatches;
EXPECT_FALSE(UseCounter::IsCounted(document, feature));
document.documentElement()->SetInnerHTMLFromString(
"<style>.a+:matches(.b, .c+.d) { color: red; }</style>");
EXPECT_TRUE(UseCounter::IsCounted(document, feature));
}
TEST_F(UseCounterTest, DropMeasurementOnViewSourcePages) { TEST_F(UseCounterTest, DropMeasurementOnViewSourcePages) {
UseCounter use_counter; UseCounter use_counter;
SetIsViewSource(); SetIsViewSource();
......
...@@ -1876,6 +1876,8 @@ enum WebFeature { ...@@ -1876,6 +1876,8 @@ enum WebFeature {
kRtcPeerConnectionId = 2384, kRtcPeerConnectionId = 2384,
kV8PaintWorkletGlobalScope_RegisterPaint_Method = 2385, kV8PaintWorkletGlobalScope_RegisterPaint_Method = 2385,
kV8PaintWorkletGlobalScope_DevicePixelRatio_AttributeGetter = 2386, kV8PaintWorkletGlobalScope_DevicePixelRatio_AttributeGetter = 2386,
kCSSSelectorPseudoFocus = 2387,
kCSSSelectorPseudoFocusVisible = 2388,
// Add new features immediately above this line. Don't change assigned // Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots. // numbers of any item, and don't reuse removed slots.
......
...@@ -17943,6 +17943,8 @@ Called by update_net_error_codes.py.--> ...@@ -17943,6 +17943,8 @@ Called by update_net_error_codes.py.-->
<int value="2385" label="V8PaintWorkletGlobalScope_RegisterPaint_Method"/> <int value="2385" label="V8PaintWorkletGlobalScope_RegisterPaint_Method"/>
<int value="2386" <int value="2386"
label="V8PaintWorkletGlobalScope_DevicePixelRatio_AttributeGetter"/> label="V8PaintWorkletGlobalScope_DevicePixelRatio_AttributeGetter"/>
<int value="2387" label="CSSSelectorPseudoFocus"/>
<int value="2388" label="CSSSelectorPseudoFocusVisible"/>
</enum> </enum>
<enum name="FeedbackSource"> <enum name="FeedbackSource">
...@@ -27862,9 +27864,9 @@ Called by update_use_counter_css.py.--> ...@@ -27862,9 +27864,9 @@ Called by update_use_counter_css.py.-->
<int value="175" label="webkit-appearance"/> <int value="175" label="webkit-appearance"/>
<int value="176" label="webkit-aspect-ratio"/> <int value="176" label="webkit-aspect-ratio"/>
<int value="177" label="alias-webkit-backface-visibility"/> <int value="177" label="alias-webkit-backface-visibility"/>
<int value="178" label="webkit-background-clip"/> <int value="178" label="alias-webkit-background-clip"/>
<int value="179" label="webkit-background-composite"/> <int value="179" label="webkit-background-composite"/>
<int value="180" label="webkit-background-origin"/> <int value="180" label="alias-webkit-background-origin"/>
<int value="181" label="alias-webkit-background-size"/> <int value="181" label="alias-webkit-background-size"/>
<int value="182" label="webkit-border-after"/> <int value="182" label="webkit-border-after"/>
<int value="183" label="webkit-border-after-color"/> <int value="183" label="webkit-border-after-color"/>
...@@ -28275,6 +28277,8 @@ Called by update_use_counter_css.py.--> ...@@ -28275,6 +28277,8 @@ Called by update_use_counter_css.py.-->
<int value="588" label="font-variant-east-asian"/> <int value="588" label="font-variant-east-asian"/>
<int value="589" label="text-decoration-skip-ink"/> <int value="589" label="text-decoration-skip-ink"/>
<int value="590" label="scroll-customization"/> <int value="590" label="scroll-customization"/>
<int value="591" label="row-gap"/>
<int value="592" label="gap"/>
</enum> </enum>
<enum name="MappedEditingCommands"> <enum name="MappedEditingCommands">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment