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( ...@@ -1209,6 +1209,8 @@ void CSSSelectorParser::RecordUsageAndDeprecations(
const CSSSelectorList& selector_list) { const CSSSelectorList& selector_list) {
if (!context_->IsUseCounterRecordingEnabled()) if (!context_->IsUseCounterRecordingEnabled())
return; return;
if (context_->Mode() == kUASheetMode)
return;
for (const CSSSelector* selector = selector_list.FirstForCSSOM(); selector; for (const CSSSelector* selector = selector_list.FirstForCSSOM(); selector;
selector = CSSSelectorList::Next(*selector)) { selector = CSSSelectorList::Next(*selector)) {
...@@ -1225,12 +1227,10 @@ void CSSSelectorParser::RecordUsageAndDeprecations( ...@@ -1225,12 +1227,10 @@ void CSSSelectorParser::RecordUsageAndDeprecations(
break; break;
case CSSSelector::kPseudoFocusVisible: case CSSSelector::kPseudoFocusVisible:
DCHECK(RuntimeEnabledFeatures::CSSFocusVisibleEnabled()); DCHECK(RuntimeEnabledFeatures::CSSFocusVisibleEnabled());
if (context_->Mode() != kUASheetMode) feature = WebFeature::kCSSSelectorPseudoFocusVisible;
feature = WebFeature::kCSSSelectorPseudoFocusVisible;
break; break;
case CSSSelector::kPseudoFocus: case CSSSelector::kPseudoFocus:
if (context_->Mode() != kUASheetMode) feature = WebFeature::kCSSSelectorPseudoFocus;
feature = WebFeature::kCSSSelectorPseudoFocus;
break; break;
case CSSSelector::kPseudoAnyLink: case CSSSelector::kPseudoAnyLink:
feature = WebFeature::kCSSSelectorPseudoAnyLink; feature = WebFeature::kCSSSelectorPseudoAnyLink;
...@@ -1268,26 +1268,20 @@ void CSSSelectorParser::RecordUsageAndDeprecations( ...@@ -1268,26 +1268,20 @@ void CSSSelectorParser::RecordUsageAndDeprecations(
feature = WebFeature::kCSSSelectorPseudoFullScreen; feature = WebFeature::kCSSSelectorPseudoFullScreen;
break; break;
case CSSSelector::kPseudoListBox: case CSSSelector::kPseudoListBox:
if (context_->Mode() != kUASheetMode) feature = WebFeature::kCSSSelectorInternalPseudoListBox;
feature = WebFeature::kCSSSelectorInternalPseudoListBox;
break; break;
case CSSSelector::kPseudoWebKitCustomElement: case CSSSelector::kPseudoWebKitCustomElement:
if (context_->Mode() != kUASheetMode) feature = FeatureForWebKitCustomPseudoElement(current->Value());
feature = FeatureForWebKitCustomPseudoElement(current->Value());
break; break;
case CSSSelector::kPseudoSpatialNavigationFocus: case CSSSelector::kPseudoSpatialNavigationFocus:
if (context_->Mode() != kUASheetMode) { feature =
feature = WebFeature::kCSSSelectorInternalPseudoSpatialNavigationFocus;
WebFeature::kCSSSelectorInternalPseudoSpatialNavigationFocus;
}
break; break;
case CSSSelector::kPseudoReadOnly: case CSSSelector::kPseudoReadOnly:
if (context_->Mode() != kUASheetMode) feature = WebFeature::kCSSSelectorPseudoReadOnly;
feature = WebFeature::kCSSSelectorPseudoReadOnly;
break; break;
case CSSSelector::kPseudoReadWrite: case CSSSelector::kPseudoReadWrite:
if (context_->Mode() != kUASheetMode) feature = WebFeature::kCSSSelectorPseudoReadWrite;
feature = WebFeature::kCSSSelectorPseudoReadWrite;
break; break;
default: default:
break; break;
......
...@@ -685,25 +685,31 @@ TEST(CSSSelectorParserTest, ShadowPartAndBeforeAfterPseudoElementValid) { ...@@ -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)); auto dummy_holder = std::make_unique<DummyPageHolder>(IntSize(500, 500));
Document* doc = &dummy_holder->GetDocument(); Document* doc = &dummy_holder->GetDocument();
Page::InsertOrdinaryPageForTesting(&dummy_holder->GetPage()); Page::InsertOrdinaryPageForTesting(&dummy_holder->GetPage());
auto* context = MakeGarbageCollected<CSSParserContext>( auto* context = MakeGarbageCollected<CSSParserContext>(
kHTMLStandardMode, SecureContextMode::kSecureContext, mode, SecureContextMode::kSecureContext, CSSParserContext::kLiveProfile,
CSSParserContext::kLiveProfile, doc); doc);
auto* sheet = MakeGarbageCollected<StyleSheetContents>(context); auto* sheet = MakeGarbageCollected<StyleSheetContents>(context);
auto ExpectCount = [doc, context, sheet](const char* selector, DCHECK(!doc->IsUseCounted(feature));
WebFeature feature) {
EXPECT_FALSE(doc->IsUseCounted(feature));
CSSTokenizer tokenizer(selector); CSSTokenizer tokenizer(selector);
const auto tokens = tokenizer.TokenizeToEOF(); const auto tokens = tokenizer.TokenizeToEOF();
CSSParserTokenRange range(tokens); CSSParserTokenRange range(tokens);
CSSSelectorParser::ParseSelector(range, context, sheet); 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); ExpectCount("::cue", WebFeature::kCSSSelectorCue);
...@@ -821,6 +827,30 @@ TEST(CSSSelectorParserTest, UseCountShadowPseudo) { ...@@ -821,6 +827,30 @@ TEST(CSSSelectorParserTest, UseCountShadowPseudo) {
WebFeature::kCSSSelectorWebkitUnknownPseudo); 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) { TEST(CSSSelectorParserTest, ImplicitShadowCrossingCombinators) {
struct ShadowCombinatorTest { struct ShadowCombinatorTest {
const char* input; 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