Force-dark and color-scheme: only light

#450471085 Filed 2025-10-09 New CL 8692733

Bug: with #enable-force-dark on and a light system theme, both white boxes become dark. The right box has color-scheme: only light, which should keep it white. The left box has no opt-out and should stay dark.

Before and after in the same build

Both captures use the same locally built content_shell, the same HTML, and preferredColorScheme=1,forceDarkModeEnabled=true. Only ForceDarkRespectsColorSchemeOnly is disabled for BEFORE.

BEFORE / kill switch off Both boxes dark: opt-out ignored
Before: both white boxes darkened
AFTER / kill switch on Only the normal box is dark
After: only light box stays white
Normal box, both runsRGB (18, 18, 18)
Opted-out box, before → after RGB (18, 18, 18) → (255, 255, 255)

Rendered / Expected / Diff

Rendered and Expected are screenshots from the same local content_shell with force-dark enabled. A live iframe in an ordinary browser would show both boxes white because force-dark is off; open the repro in a browser launched with the flags below to check it yourself.

Rendered before fix: both tiles dark under force-dark

Captured Chromium rendering with force-dark on and ForceDarkRespectsColorSchemeOnly disabled; both tiles dark.

Scope and verification

ComputedStyleBuilder::SetUsedColorScheme() no longer forces dark for a single only scheme; ExtractColorSchemes() ignores only when multiple schemes are listed. The base pixel test covers a dark system theme and the virtual test covers a light theme with force-dark enabled.

2 ForceDarkTest unit tests and 2 pixel web tests pass. The light-theme forced-dark pixel test fails with an image diff when the kill switch is off. The local Chrome build also shows the white opt-out tile.

Open repro Capture script CL 8692733 Issue

To see the live behavior with the local Chrome build, run cr https://static.januschka.com/i-450471085/repro.html --blink-settings=preferredColorScheme=1,forceDarkModeEnabled=true. Add --disable-blink-features=ForceDarkRespectsColorSchemeOnly for the BEFORE behavior. The capture script uses Pillow and websocket-client; run xvfb-run -a python3 capture_screenshots.py from this directory.