Commit cda2d10e authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Add counter for :empty failing for white-space only.

If we are changing :empty to match when there are whitespace children,
we need to know to what extent this affects existing content.

Bug: 447880
Change-Id: I53906fe6295f42cdc72d5ca6d6e58e1aa60786c3
Reviewed-on: https://chromium-review.googlesource.com/c/1326003
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606443}
parent 66530d6d
......@@ -2073,6 +2073,7 @@ enum WebFeature {
kAdClick = 2621,
kUpdateWithoutShippingOptionOnShippingAddressChange = 2622,
kUpdateWithoutShippingOptionOnShippingOptionChange = 2623,
kCSSSelectorEmptyWhitespaceOnlyFail = 2624,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
// Also, run update_use_counter_feature_enum.py in
......
......@@ -761,6 +761,7 @@ bool SelectorChecker::CheckPseudoClass(const SelectorCheckingContext& context,
return CheckPseudoNot(context, result);
case CSSSelector::kPseudoEmpty: {
bool result = true;
bool has_whitespace = false;
for (Node* n = element.firstChild(); n; n = n->nextSibling()) {
if (n->IsElementNode()) {
result = false;
......@@ -769,11 +770,20 @@ bool SelectorChecker::CheckPseudoClass(const SelectorCheckingContext& context,
if (n->IsTextNode()) {
Text* text_node = ToText(n);
if (!text_node->data().IsEmpty()) {
result = false;
break;
if (text_node->ContainsOnlyWhitespaceOrEmpty()) {
has_whitespace = true;
} else {
result = false;
break;
}
}
}
}
if (result && has_whitespace) {
UseCounter::Count(context.element->GetDocument(),
WebFeature::kCSSSelectorEmptyWhitespaceOnlyFail);
result = false;
}
if (mode_ == kResolvingStyle)
element.SetStyleAffectedByEmpty();
return result;
......
......@@ -26,6 +26,7 @@
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/viewport_data.h"
#include "third_party/blink/renderer/core/html/html_collection.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/html/html_span_element.h"
#include "third_party/blink/renderer/core/html/html_style_element.h"
......@@ -1658,4 +1659,37 @@ TEST_F(StyleEngineTest, InitialDataCreation) {
EXPECT_NE(data1, GetStyleEngine().MaybeCreateAndGetInitialData());
}
TEST_F(StyleEngineTest, CSSSelectorEmptyWhitespaceOnlyFail) {
GetDocument().body()->SetInnerHTMLFromString(R"HTML(
<style>.match:empty { background-color: red }</style>
<div></div>
<div> <span></span></div>
<div> <!-- -->X</div>
<div></div>
<div> <!-- --></div>
)HTML");
GetDocument().View()->UpdateAllLifecyclePhases();
EXPECT_FALSE(UseCounter::IsCounted(
GetDocument(), WebFeature::kCSSSelectorEmptyWhitespaceOnlyFail));
auto* div_elements = GetDocument().getElementsByTagName("div");
ASSERT_TRUE(div_elements);
ASSERT_EQ(5u, div_elements->length());
auto is_counted = [](Element* element) {
element->setAttribute(blink::html_names::kClassAttr, "match");
element->GetDocument().View()->UpdateAllLifecyclePhases();
return UseCounter::IsCounted(
element->GetDocument(),
WebFeature::kCSSSelectorEmptyWhitespaceOnlyFail);
};
EXPECT_FALSE(is_counted(div_elements->item(0)));
EXPECT_FALSE(is_counted(div_elements->item(1)));
EXPECT_FALSE(is_counted(div_elements->item(2)));
EXPECT_FALSE(is_counted(div_elements->item(3)));
EXPECT_TRUE(is_counted(div_elements->item(4)));
}
} // namespace blink
......@@ -20680,6 +20680,7 @@ Called by update_net_error_codes.py.-->
<int value="2621" label="AdClick"/>
<int value="2622" label="UpdateWithoutShippingOptionOnShippingAddressChange"/>
<int value="2623" label="UpdateWithoutShippingOptionOnShippingOptionChange"/>
<int value="2624" label="CSSSelectorEmptyWhitespaceOnlyFail"/>
</enum>
<enum name="FeaturePolicyFeature">
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