summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/css/style_engine_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/css/style_engine_test.cc')
-rw-r--r--chromium/third_party/blink/renderer/core/css/style_engine_test.cc116
1 files changed, 112 insertions, 4 deletions
diff --git a/chromium/third_party/blink/renderer/core/css/style_engine_test.cc b/chromium/third_party/blink/renderer/core/css/style_engine_test.cc
index 26cd17b201c..2e52cb263ec 100644
--- a/chromium/third_party/blink/renderer/core/css/style_engine_test.cc
+++ b/chromium/third_party/blink/renderer/core/css/style_engine_test.cc
@@ -6,6 +6,7 @@
#include <memory>
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/blink/public/platform/web_color_scheme.h"
#include "third_party/blink/public/platform/web_float_rect.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/css/css_font_selector.h"
@@ -41,6 +42,7 @@ using namespace css_test_helpers;
class StyleEngineTest : public testing::Test {
protected:
void SetUp() override;
+ void TearDown() override;
Document& GetDocument() { return dummy_page_holder_->GetDocument(); }
StyleEngine& GetStyleEngine() { return GetDocument().GetStyleEngine(); }
@@ -64,12 +66,17 @@ class StyleEngineTest : public testing::Test {
private:
std::unique_ptr<DummyPageHolder> dummy_page_holder_;
+ RuntimeEnabledFeatures::Backup features_backup_;
};
void StyleEngineTest::SetUp() {
dummy_page_holder_ = DummyPageHolder::Create(IntSize(800, 600));
}
+void StyleEngineTest::TearDown() {
+ features_backup_.Restore();
+}
+
StyleEngineTest::RuleSetInvalidation
StyleEngineTest::ScheduleInvalidationsForRules(TreeScope& tree_scope,
const String& css_text) {
@@ -1189,21 +1196,22 @@ TEST_F(StyleEngineTest, StyleSheetsForStyleSheetList_ShadowRoot) {
EXPECT_FALSE(GetStyleEngine().NeedsActiveStyleUpdate());
}
-class StyleEngineClient : public frame_test_helpers::TestWebViewClient {
+class StyleEngineClient : public frame_test_helpers::TestWebWidgetClient {
public:
- StyleEngineClient() : device_scale_factor_(1.f) {}
+ // WebWidgetClient overrides.
void ConvertWindowToViewport(WebFloatRect* rect) override {
rect->x *= device_scale_factor_;
rect->y *= device_scale_factor_;
rect->width *= device_scale_factor_;
rect->height *= device_scale_factor_;
}
+
void set_device_scale_factor(float device_scale_factor) {
device_scale_factor_ = device_scale_factor;
}
private:
- float device_scale_factor_;
+ float device_scale_factor_ = 1.f;
};
TEST_F(StyleEngineTest, ViewportDescriptionForZoomDSF) {
@@ -1212,7 +1220,7 @@ TEST_F(StyleEngineTest, ViewportDescriptionForZoomDSF) {
frame_test_helpers::WebViewHelper web_view_helper;
WebViewImpl* web_view_impl =
- web_view_helper.Initialize(nullptr, &client, nullptr, nullptr);
+ web_view_helper.Initialize(nullptr, nullptr, &client);
web_view_impl->MainFrameWidget()->UpdateAllLifecyclePhases(
WebWidget::LifecycleUpdateReason::kTest);
@@ -1476,6 +1484,55 @@ TEST_F(StyleEngineTest, MediaQueriesChangeDefaultFontSize) {
GetCSSPropertyColor()));
}
+TEST_F(StyleEngineTest, MediaQueriesChangeColorScheme) {
+ RuntimeEnabledFeatures::SetMediaQueryPrefersColorSchemeEnabled(true);
+
+ GetDocument().body()->SetInnerHTMLFromString(R"HTML(
+ <style>
+ body { color: red }
+ @media (prefers-color-scheme: dark) {
+ body { color: green }
+ }
+ </style>
+ <body></body>
+ )HTML");
+
+ UpdateAllLifecyclePhases();
+ EXPECT_EQ(MakeRGB(255, 0, 0),
+ GetDocument().body()->GetComputedStyle()->VisitedDependentColor(
+ GetCSSPropertyColor()));
+
+ GetDocument().GetSettings()->SetPreferredColorScheme(WebColorScheme::kDark);
+ UpdateAllLifecyclePhases();
+ EXPECT_EQ(MakeRGB(0, 128, 0),
+ GetDocument().body()->GetComputedStyle()->VisitedDependentColor(
+ GetCSSPropertyColor()));
+}
+
+TEST_F(StyleEngineTest, MediaQueriesChangePrefersReducedMotion) {
+ RuntimeEnabledFeatures::SetMediaQueryPrefersReducedMotionEnabled(true);
+ GetDocument().body()->SetInnerHTMLFromString(R"HTML(
+ <style>
+ body { color: red }
+ @media (prefers-reduced-motion: reduce) {
+ body { color: green }
+ }
+ </style>
+ <body></body>
+ )HTML");
+
+ UpdateAllLifecyclePhases();
+ EXPECT_EQ(MakeRGB(255, 0, 0),
+ GetDocument().body()->GetComputedStyle()->VisitedDependentColor(
+ GetCSSPropertyColor()));
+
+ GetDocument().GetSettings()->SetPrefersReducedMotion(true);
+ UpdateAllLifecyclePhases();
+ EXPECT_EQ(MakeRGB(0, 128, 0),
+ GetDocument().body()->GetComputedStyle()->VisitedDependentColor(
+ GetCSSPropertyColor()));
+}
+
TEST_F(StyleEngineTest, ShadowRootStyleRecalcCrash) {
GetDocument().body()->SetInnerHTMLFromString("<div id=host></div>");
HTMLElement* host = ToHTMLElement(GetDocument().getElementById("host"));
@@ -1716,4 +1773,55 @@ TEST_F(StyleEngineTest, CSSSelectorEmptyWhitespaceOnlyFail) {
EXPECT_TRUE(is_counted(div_elements->item(4)));
}
+TEST_F(StyleEngineTest, EnsuredComputedStyleRecalc) {
+ GetDocument().body()->SetInnerHTMLFromString(R"HTML(
+ <div style="display:none">
+ <div>
+ <div id="computed">
+ <span id="span"><span>XXX</span></span>
+ </div>
+ </div>
+ </div>
+ )HTML");
+ UpdateAllLifecyclePhases();
+
+ Element* computed = GetDocument().getElementById("computed");
+ Element* span_outer = GetDocument().getElementById("span");
+ Node* span_inner = span_outer->firstChild();
+
+ // Initially all null in display:none subtree.
+ EXPECT_FALSE(computed->GetComputedStyle());
+ EXPECT_FALSE(span_outer->GetComputedStyle());
+ EXPECT_FALSE(span_inner->GetComputedStyle());
+
+ // Force computed style down to #computed.
+ computed->EnsureComputedStyle();
+ UpdateAllLifecyclePhases();
+ EXPECT_TRUE(computed->GetComputedStyle());
+ EXPECT_FALSE(span_outer->GetComputedStyle());
+ EXPECT_FALSE(span_inner->GetComputedStyle());
+
+ // Setting span color should not create ComputedStyles during style recalc.
+ span_outer->SetInlineStyleProperty(CSSPropertyColor, "blue");
+ EXPECT_TRUE(span_outer->NeedsStyleRecalc());
+ GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc);
+ GetStyleEngine().RecalcStyle(kNoChange);
+ GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kStyleClean);
+
+ EXPECT_FALSE(span_outer->NeedsStyleRecalc());
+ EXPECT_FALSE(span_outer->GetComputedStyle());
+ EXPECT_FALSE(span_inner->GetComputedStyle());
+ // #computed still non-null because #span_outer is the recalc root.
+ EXPECT_TRUE(computed->GetComputedStyle());
+
+ // Triggering style recalc which propagates the color down the tree should
+ // clear ComputedStyle objects in the display:none subtree.
+ GetDocument().body()->SetInlineStyleProperty(CSSPropertyColor, "pink");
+ UpdateAllLifecyclePhases();
+
+ EXPECT_FALSE(computed->GetComputedStyle());
+ EXPECT_FALSE(span_outer->GetComputedStyle());
+ EXPECT_FALSE(span_inner->GetComputedStyle());
+}
+
} // namespace blink