Commit 039da5b7 authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

Remove MutableStyle from dark-mode unittests.

I don't believe(?) there is actually a way to set the opacity on a
viewport. (Either with the @viewport rule, or the style fixup[1]).

This removes one of the unittests, and removes the logic which
was reading the opacity from the viewport.

[1] https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/dom/document.cc?q=viewport_style&sq=package:chromium&dr=C&l=2122

Bug: 813068
Change-Id: I29d1b45c848c3ddca48a04523ec358094e97755b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1637044Reviewed-by: default avatarAran Gilman <gilmanmh@google.com>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665148}
parent d100ef16
...@@ -21,7 +21,7 @@ bool HasLightBackground(const LayoutView& root) { ...@@ -21,7 +21,7 @@ bool HasLightBackground(const LayoutView& root) {
const ComputedStyle& style = root.StyleRef(); const ComputedStyle& style = root.StyleRef();
if (style.HasBackground()) { if (style.HasBackground()) {
Color color = style.VisitedDependentColor(GetCSSPropertyBackgroundColor()); Color color = style.VisitedDependentColor(GetCSSPropertyBackgroundColor());
return IsLight(color, style.Opacity()); return IsLight(color);
} }
// If we can't easily determine the background color, default to inverting the // If we can't easily determine the background color, default to inverting the
......
...@@ -29,9 +29,6 @@ TEST_F(ApplyDarkModeCheckTest, LightSolidBackgroundAlwaysFiltered) { ...@@ -29,9 +29,6 @@ TEST_F(ApplyDarkModeCheckTest, LightSolidBackgroundAlwaysFiltered) {
TEST_F(ApplyDarkModeCheckTest, DarkSolidBackgroundFilteredIfPolicyIsFilterAll) { TEST_F(ApplyDarkModeCheckTest, DarkSolidBackgroundFilteredIfPolicyIsFilterAll) {
GetDocument().body()->SetInlineStyleProperty(CSSPropertyID::kBackgroundColor, GetDocument().body()->SetInlineStyleProperty(CSSPropertyID::kBackgroundColor,
CSSValueID::kBlack); CSSValueID::kBlack);
// TODO(https://crbug.com/925949): Set opacity the same way as the other CSS
// properties.
GetLayoutView().MutableStyle()->SetOpacity(0.9);
UpdateAllLifecyclePhasesForTest(); UpdateAllLifecyclePhasesForTest();
EXPECT_FALSE(ShouldApplyDarkModeFilterToPage( EXPECT_FALSE(ShouldApplyDarkModeFilterToPage(
...@@ -40,20 +37,6 @@ TEST_F(ApplyDarkModeCheckTest, DarkSolidBackgroundFilteredIfPolicyIsFilterAll) { ...@@ -40,20 +37,6 @@ TEST_F(ApplyDarkModeCheckTest, DarkSolidBackgroundFilteredIfPolicyIsFilterAll) {
GetLayoutView())); GetLayoutView()));
} }
TEST_F(ApplyDarkModeCheckTest, DarkLowOpacityBackgroundAlwaysFiltered) {
GetDocument().body()->SetInlineStyleProperty(CSSPropertyID::kBackgroundColor,
CSSValueID::kBlack);
// TODO(https://crbug.com/925949): Set opacity the same way as the other CSS
// properties.
GetLayoutView().MutableStyle()->SetOpacity(0.1);
UpdateAllLifecyclePhasesForTest();
EXPECT_TRUE(ShouldApplyDarkModeFilterToPage(
DarkModePagePolicy::kFilterByBackground, GetLayoutView()));
EXPECT_TRUE(ShouldApplyDarkModeFilterToPage(DarkModePagePolicy::kFilterAll,
GetLayoutView()));
}
TEST_F(ApplyDarkModeCheckTest, DarkTransparentBackgroundAlwaysFiltered) { TEST_F(ApplyDarkModeCheckTest, DarkTransparentBackgroundAlwaysFiltered) {
GetDocument().body()->SetInlineStyleProperty(CSSPropertyID::kBackgroundColor, GetDocument().body()->SetInlineStyleProperty(CSSPropertyID::kBackgroundColor,
CSSValueID::kTransparent); CSSValueID::kTransparent);
......
...@@ -13,12 +13,11 @@ namespace blink { ...@@ -13,12 +13,11 @@ namespace blink {
const float kOpacityThreshold = 0.4; const float kOpacityThreshold = 0.4;
// TODO(https://crbug.com/925949): Find a better algorithm for this. // TODO(https://crbug.com/925949): Find a better algorithm for this.
bool IsLight(const Color& color, float opacity) { bool IsLight(const Color& color) {
// Multiply the opacity by the alpha value to get a more accurate sense of how // Use the alpha value as the opacity.
// transparent the element is. float opacity = (color.Alpha() / 255);
float real_opacity = opacity * (color.Alpha() / 255);
// Assume the color is light if the background is sufficiently transparent. // Assume the color is light if the background is sufficiently transparent.
if (real_opacity < kOpacityThreshold) { if (opacity < kOpacityThreshold) {
return true; return true;
} }
double hue; double hue;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
namespace blink { namespace blink {
bool PLATFORM_EXPORT IsLight(const Color& color, float opacity); bool PLATFORM_EXPORT IsLight(const Color& color);
} // namespace blink } // namespace blink
......
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