Commit 630b85ce authored by Stephen McGruer's avatar Stephen McGruer Committed by Commit Bot

Make sure --force-prefers-reduced-motion always overrides system setting

After https://crrev.com/e90092dea, the --force-prefers-reduced-motion
flag could be accidentally ignored if the system-level setting was
changed after the browser had started. This CL restores the behavior so
that the flag always wins, and adds a test to ensure that.

Bug: None
Change-Id: I46927e3821f1118f38f4896d07755b3eaebe48b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1921553Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720197}
parent 245b84a9
......@@ -140,14 +140,15 @@ void Animation::UpdatePrefersReducedMotion() {
// static
bool Animation::PrefersReducedMotion() {
if (!prefers_reduced_motion_.has_value()) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForcePrefersReducedMotion)) {
prefers_reduced_motion_ = true;
} else {
UpdatePrefersReducedMotion();
}
// --force-prefers-reduced-motion must always override
// |prefers_reduced_motion_|, so check it first.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForcePrefersReducedMotion)) {
return true;
}
if (!prefers_reduced_motion_.has_value())
UpdatePrefersReducedMotion();
return prefers_reduced_motion_.value();
}
......
......@@ -84,6 +84,9 @@ class ANIMATION_EXPORT Animation : public AnimationContainerElement {
// Should only be called from the browser process, on the UI thread.
static bool PrefersReducedMotion();
static void UpdatePrefersReducedMotion();
static void SetPrefersReducedMotionForTesting(bool prefers_reduced_motion) {
prefers_reduced_motion_ = prefers_reduced_motion;
}
protected:
// Invoked from Start to allow subclasses to prepare for the animation.
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
......@@ -9,6 +10,7 @@
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/animation/test_animation_delegate.h"
#include "ui/gfx/switches.h"
#if defined(OS_WIN)
#include <windows.h>
......@@ -158,4 +160,18 @@ TEST_F(AnimationTest, StartState) {
EXPECT_EQ(0.0, animation.GetCurrentValue());
}
///////////////////////////////////////////////////////////////////////////////
// PrefersReducedMotion tests
TEST_F(AnimationTest, PrefersReducedMotionRespectsOverrideFlag) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kForcePrefersReducedMotion, "1");
EXPECT_TRUE(Animation::PrefersReducedMotion());
// It doesn't matter what the system setting says; the flag should continue to
// override it.
Animation::SetPrefersReducedMotionForTesting(false);
EXPECT_TRUE(Animation::PrefersReducedMotion());
}
} // namespace gfx
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