Commit 7af81cb4 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

Avoid use-counting for UA sheet

Change-Id: Ic049d5d75cc399b98223ff469ad2c2c55ce231dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2484797Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819040}
parent af2f9f92
......@@ -1209,6 +1209,8 @@ void CSSSelectorParser::RecordUsageAndDeprecations(
const CSSSelectorList& selector_list) {
if (!context_->IsUseCounterRecordingEnabled())
return;
if (context_->Mode() == kUASheetMode)
return;
for (const CSSSelector* selector = selector_list.FirstForCSSOM(); selector;
selector = CSSSelectorList::Next(*selector)) {
......@@ -1225,12 +1227,10 @@ void CSSSelectorParser::RecordUsageAndDeprecations(
break;
case CSSSelector::kPseudoFocusVisible:
DCHECK(RuntimeEnabledFeatures::CSSFocusVisibleEnabled());
if (context_->Mode() != kUASheetMode)
feature = WebFeature::kCSSSelectorPseudoFocusVisible;
feature = WebFeature::kCSSSelectorPseudoFocusVisible;
break;
case CSSSelector::kPseudoFocus:
if (context_->Mode() != kUASheetMode)
feature = WebFeature::kCSSSelectorPseudoFocus;
feature = WebFeature::kCSSSelectorPseudoFocus;
break;
case CSSSelector::kPseudoAnyLink:
feature = WebFeature::kCSSSelectorPseudoAnyLink;
......@@ -1268,26 +1268,20 @@ void CSSSelectorParser::RecordUsageAndDeprecations(
feature = WebFeature::kCSSSelectorPseudoFullScreen;
break;
case CSSSelector::kPseudoListBox:
if (context_->Mode() != kUASheetMode)
feature = WebFeature::kCSSSelectorInternalPseudoListBox;
feature = WebFeature::kCSSSelectorInternalPseudoListBox;
break;
case CSSSelector::kPseudoWebKitCustomElement:
if (context_->Mode() != kUASheetMode)
feature = FeatureForWebKitCustomPseudoElement(current->Value());
feature = FeatureForWebKitCustomPseudoElement(current->Value());
break;
case CSSSelector::kPseudoSpatialNavigationFocus:
if (context_->Mode() != kUASheetMode) {
feature =
WebFeature::kCSSSelectorInternalPseudoSpatialNavigationFocus;
}
feature =
WebFeature::kCSSSelectorInternalPseudoSpatialNavigationFocus;
break;
case CSSSelector::kPseudoReadOnly:
if (context_->Mode() != kUASheetMode)
feature = WebFeature::kCSSSelectorPseudoReadOnly;
feature = WebFeature::kCSSSelectorPseudoReadOnly;
break;
case CSSSelector::kPseudoReadWrite:
if (context_->Mode() != kUASheetMode)
feature = WebFeature::kCSSSelectorPseudoReadWrite;
feature = WebFeature::kCSSSelectorPseudoReadWrite;
break;
default:
break;
......
......@@ -685,25 +685,31 @@ TEST(CSSSelectorParserTest, ShadowPartAndBeforeAfterPseudoElementValid) {
}
}
TEST(CSSSelectorParserTest, UseCountShadowPseudo) {
static bool IsCounted(const char* selector,
CSSParserMode mode,
WebFeature feature) {
auto dummy_holder = std::make_unique<DummyPageHolder>(IntSize(500, 500));
Document* doc = &dummy_holder->GetDocument();
Page::InsertOrdinaryPageForTesting(&dummy_holder->GetPage());
auto* context = MakeGarbageCollected<CSSParserContext>(
kHTMLStandardMode, SecureContextMode::kSecureContext,
CSSParserContext::kLiveProfile, doc);
mode, SecureContextMode::kSecureContext, CSSParserContext::kLiveProfile,
doc);
auto* sheet = MakeGarbageCollected<StyleSheetContents>(context);
auto ExpectCount = [doc, context, sheet](const char* selector,
WebFeature feature) {
EXPECT_FALSE(doc->IsUseCounted(feature));
DCHECK(!doc->IsUseCounted(feature));
CSSTokenizer tokenizer(selector);
const auto tokens = tokenizer.TokenizeToEOF();
CSSParserTokenRange range(tokens);
CSSSelectorParser::ParseSelector(range, context, sheet);
CSSTokenizer tokenizer(selector);
const auto tokens = tokenizer.TokenizeToEOF();
CSSParserTokenRange range(tokens);
CSSSelectorParser::ParseSelector(range, context, sheet);
return doc->IsUseCounted(feature);
}
EXPECT_TRUE(doc->IsUseCounted(feature));
TEST(CSSSelectorParserTest, UseCountShadowPseudo) {
auto ExpectCount = [](const char* selector, WebFeature feature) {
SCOPED_TRACE(selector);
EXPECT_TRUE(IsCounted(selector, kHTMLStandardMode, feature));
};
ExpectCount("::cue", WebFeature::kCSSSelectorCue);
......@@ -821,6 +827,30 @@ TEST(CSSSelectorParserTest, UseCountShadowPseudo) {
WebFeature::kCSSSelectorWebkitUnknownPseudo);
}
TEST(CSSSelectorParserTest, IsWhereUseCount) {
const auto is_feature = WebFeature::kCSSSelectorPseudoIs;
EXPECT_FALSE(IsCounted(".a", kHTMLStandardMode, is_feature));
EXPECT_FALSE(IsCounted(":not(.a)", kHTMLStandardMode, is_feature));
EXPECT_FALSE(IsCounted(":where(.a)", kHTMLStandardMode, is_feature));
EXPECT_TRUE(IsCounted(":is()", kHTMLStandardMode, is_feature));
EXPECT_TRUE(IsCounted(":is(.a)", kHTMLStandardMode, is_feature));
EXPECT_TRUE(IsCounted(":not(:is(.a))", kHTMLStandardMode, is_feature));
EXPECT_TRUE(IsCounted(".a:is(.b)", kHTMLStandardMode, is_feature));
EXPECT_TRUE(IsCounted(":is(.a).b", kHTMLStandardMode, is_feature));
EXPECT_FALSE(IsCounted(":is(.a)", kUASheetMode, is_feature));
const auto where_feature = WebFeature::kCSSSelectorPseudoWhere;
EXPECT_FALSE(IsCounted(".a", kHTMLStandardMode, where_feature));
EXPECT_FALSE(IsCounted(":not(.a)", kHTMLStandardMode, where_feature));
EXPECT_FALSE(IsCounted(":is(.a)", kHTMLStandardMode, where_feature));
EXPECT_TRUE(IsCounted(":where()", kHTMLStandardMode, where_feature));
EXPECT_TRUE(IsCounted(":where(.a)", kHTMLStandardMode, where_feature));
EXPECT_TRUE(IsCounted(":not(:where(.a))", kHTMLStandardMode, where_feature));
EXPECT_TRUE(IsCounted(".a:where(.b)", kHTMLStandardMode, where_feature));
EXPECT_TRUE(IsCounted(":where(.a).b", kHTMLStandardMode, where_feature));
EXPECT_FALSE(IsCounted(":where(.a)", kUASheetMode, where_feature));
}
TEST(CSSSelectorParserTest, ImplicitShadowCrossingCombinators) {
struct ShadowCombinatorTest {
const char* input;
......
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