Bug 1609024 - Remove cache mechanism which is not very useful. r=hiro,snorp,mccr8
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 21 May 2020 17:02:06 +0000
changeset 531474 7ded7f391f1b90c8ccc81bf151d289a802470317
parent 531473 25949e2cd466c5031bf65338f8c2fb07f246a06c
child 531475 e562d64f2bf9a26db09e338b701f98d11e1d2629
push id37440
push userabutkovits@mozilla.com
push dateFri, 22 May 2020 09:43:16 +0000
treeherdermozilla-central@fbf71e4d2e21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershiro, snorp, mccr8
bugs1609024
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1609024 - Remove cache mechanism which is not very useful. r=hiro,snorp,mccr8 I don't think all this complexity is worth it for having a marginally-more-realistic testing story. Using the pref just works and we should do that, I think. Differential Revision: https://phabricator.services.mozilla.com/D59980
devtools/client/shared/test/browser_layoutHelpers.js
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
dom/ipc/BrowserParent.cpp
dom/ipc/BrowserParent.h
dom/ipc/PBrowser.ipdl
ipc/ipdl/sync-messages.ini
layout/style/test/test_mq_changes_in_iframe.html
layout/style/test/test_mq_prefers_reduced_motion_dynamic.html
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java
widget/LookAndFeel.h
widget/PuppetWidget.cpp
widget/PuppetWidget.h
widget/android/nsLookAndFeel.cpp
widget/android/nsLookAndFeel.h
widget/android/nsWindow.cpp
widget/android/nsWindow.h
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
widget/cocoa/nsLookAndFeel.h
widget/cocoa/nsLookAndFeel.mm
widget/gtk/nsLookAndFeel.cpp
widget/gtk/nsLookAndFeel.h
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
widget/nsIWidget.h
widget/nsXPLookAndFeel.cpp
widget/nsXPLookAndFeel.h
--- a/devtools/client/shared/test/browser_layoutHelpers.js
+++ b/devtools/client/shared/test/browser_layoutHelpers.js
@@ -99,16 +99,17 @@ async function runTest(win) {
     win.scrollY,
     2,
     "Element partially visible below should appear below " +
       "if parameter is false."
   );
   is(win.scrollX, xPos, "scrollX position has not changed.");
 
   // Check smooth flag (scroll goes below the viewport)
+  await pushPref("ui.prefersReducedMotion", 0);
 
   info("Checking smooth flag");
   is(
     win.matchMedia("(prefers-reduced-motion)").matches,
     false,
     "Reduced motion is disabled"
   );
 
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -4040,36 +4040,16 @@ nsDOMWindowUtils::EnsureDirtyRootFrame()
     return NS_ERROR_FAILURE;
   }
 
   presShell->FrameNeedsReflow(frame, IntrinsicDirty::StyleChange,
                               NS_FRAME_IS_DIRTY);
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsDOMWindowUtils::SetPrefersReducedMotionOverrideForTest(bool aValue) {
-  nsIWidget* widget = GetWidget();
-  if (!widget) {
-    return NS_OK;
-  }
-
-  return widget->SetPrefersReducedMotionOverrideForTest(aValue);
-}
-
-NS_IMETHODIMP
-nsDOMWindowUtils::ResetPrefersReducedMotionOverrideForTest() {
-  nsIWidget* widget = GetWidget();
-  if (!widget) {
-    return NS_OK;
-  }
-
-  return widget->ResetPrefersReducedMotionOverrideForTest();
-}
-
 NS_INTERFACE_MAP_BEGIN(nsTranslationNodeList)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_INTERFACE_MAP_ENTRY(nsITranslationNodeList)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_ADDREF(nsTranslationNodeList)
 NS_IMPL_RELEASE(nsTranslationNodeList)
 
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -1996,28 +1996,16 @@ interface nsIDOMWindowUtils : nsISupport
   /**
    * Returns the number of times this document for this window has
    * been painted to the screen.
    *
    * Use this instead of window.mozPaintCount
    */
   readonly attribute unsigned long long paintCount;
 
-  /**
-   * Simulate the system setting corresponding to 'prefers-reduced-motion'
-   * media queries feature is changed to 'on' or 'off'.
-   *
-   * This function doesn't work on Windows.
-   */
-  void setPrefersReducedMotionOverrideForTest(in boolean aValue);
-  /**
-   * Reset the internal state to be used for above setPrefersReducedMotion.
-   */
-  void resetPrefersReducedMotionOverrideForTest();
-
   // These consts are only for testing purposes.
   const long DEFAULT_MOUSE_POINTER_ID = 0;
   const long DEFAULT_PEN_POINTER_ID   = 1;
   const long DEFAULT_TOUCH_POINTER_ID = 2;
 
   // Match mozilla::MouseButton.
   const long MOUSE_BUTTON_LEFT_BUTTON   = 0;
   const long MOUSE_BUTTON_MIDDLE_BUTTON = 1;
--- a/dom/ipc/BrowserParent.cpp
+++ b/dom/ipc/BrowserParent.cpp
@@ -1804,34 +1804,16 @@ mozilla::ipc::IPCResult BrowserParent::R
   AutoSynthesizedEventResponder responder(this, aObserverId, "cleartouch");
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (widget) {
     widget->ClearNativeTouchSequence(responder.GetObserver());
   }
   return IPC_OK();
 }
 
-mozilla::ipc::IPCResult
-BrowserParent::RecvSetPrefersReducedMotionOverrideForTest(const bool& aValue) {
-  nsCOMPtr<nsIWidget> widget = GetWidget();
-  if (widget) {
-    widget->SetPrefersReducedMotionOverrideForTest(aValue);
-  }
-  return IPC_OK();
-}
-
-mozilla::ipc::IPCResult
-BrowserParent::RecvResetPrefersReducedMotionOverrideForTest() {
-  nsCOMPtr<nsIWidget> widget = GetWidget();
-  if (widget) {
-    widget->ResetPrefersReducedMotionOverrideForTest();
-  }
-  return IPC_OK();
-}
-
 void BrowserParent::SendRealKeyEvent(WidgetKeyboardEvent& aEvent) {
   if (mIsDestroyed || !mIsReadyToHandleInputEvents) {
     return;
   }
   aEvent.mRefPoint = TransformParentToChild(aEvent.mRefPoint);
 
   if (aEvent.mMessage == eKeyPress) {
     // XXX Should we do this only when input context indicates an editor having
--- a/dom/ipc/BrowserParent.h
+++ b/dom/ipc/BrowserParent.h
@@ -560,20 +560,16 @@ class BrowserParent final : public PBrow
 
   mozilla::ipc::IPCResult RecvSynthesizeNativeTouchTap(
       const LayoutDeviceIntPoint& aPoint, const bool& aLongTap,
       const uint64_t& aObserverId);
 
   mozilla::ipc::IPCResult RecvClearNativeTouchSequence(
       const uint64_t& aObserverId);
 
-  mozilla::ipc::IPCResult RecvSetPrefersReducedMotionOverrideForTest(
-      const bool& aValue);
-  mozilla::ipc::IPCResult RecvResetPrefersReducedMotionOverrideForTest();
-
   void SendMouseEvent(const nsAString& aType, float aX, float aY,
                       int32_t aButton, int32_t aClickCount, int32_t aModifiers);
 
   /**
    * The following Send*Event() marks aEvent as posted to remote process if
    * it succeeded.  So, you can check the result with
    * aEvent.HasBeenPostedToRemoteProcess().
    */
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -676,19 +676,16 @@ parent:
      * @param aOrigin origin string of the document that is requesting access.
      */
     async ShowCanvasPermissionPrompt(nsCString aOrigin,
                                      bool aHideDoorHanger);
 
     sync SetSystemFont(nsCString aFontName);
     sync GetSystemFont() returns (nsCString retval);
 
-    sync SetPrefersReducedMotionOverrideForTest(bool aValue);
-    sync ResetPrefersReducedMotionOverrideForTest();
-
     /**
      * Called once this PBrowser's OOP subdoc no longer blocks its
      * embedding element's and embedding doc's 'load' events.
      */
     async MaybeFireEmbedderLoadEvents(EmbedderElementEventType aFireEventAtEmbeddingElement);
 
     async ScrollRectIntoView(nsRect aRect, ScrollAxis aVertical,
                              ScrollAxis aHorizontal, ScrollFlags aScrollFlags,
--- a/ipc/ipdl/sync-messages.ini
+++ b/ipc/ipdl/sync-messages.ini
@@ -837,20 +837,16 @@ description = legacy sync IPC - please a
 [PBrowser::DispatchKeyboardEvent]
 description = legacy sync IPC - please add detailed description
 [PBrowser::EnsureLayersConnected]
 description = legacy sync IPC - please add detailed description
 [PBrowser::SetSystemFont]
 description = test only
 [PBrowser::GetSystemFont]
 description = test only
-[PBrowser::SetPrefersReducedMotionOverrideForTest]
-description = test only
-[PBrowser::ResetPrefersReducedMotionOverrideForTest]
-description = test only
 [PContent::SyncMessage]
 description = JS MessageManager implementation
 [PContent::LoadPlugin]
 description = Legacy NPAPI IPC
 [PContent::ConnectPluginBridge]
 description = Legacy NPAPI IPC
 [PContent::IsSecureURI]
 description = legacy sync IPC - please add detailed description
--- a/layout/style/test/test_mq_changes_in_iframe.html
+++ b/layout/style/test/test_mq_changes_in_iframe.html
@@ -10,17 +10,17 @@
 <p id="display"></p>
 <div id="content" style="display: none"></div>
 <iframe id="iframe"></iframe>
 <pre id="test"></pre>
 <script>
 add_task(async () => {
   const mqString = "(prefers-reduced-motion: reduce)";
 
-  SpecialPowers.DOMWindowUtils.setPrefersReducedMotionOverrideForTest(false);
+  await SpecialPowers.pushPrefEnv({ set: [['ui.prefersReducedMotion', 0]]});
 
   iframe.src = SimpleTest.getTestFileURL("mq_changes_child.html")
                          .replace("mochi.test:8888", "example.com");
   await new Promise(resolve => window.addEventListener("message", event => {
     if (event.data == "ready") {
       resolve();
     }
   }, { once: true } ));
@@ -34,23 +34,21 @@ add_task(async () => {
   const changedInIFrame = new Promise(resolve => {
     window.addEventListener("message", event => {
       if ("matches" in event.data) {
         resolve(event.data.matches);
       }
     }, { once: true });
   });
 
-  SpecialPowers.DOMWindowUtils.setPrefersReducedMotionOverrideForTest(true);
+  await SpecialPowers.pushPrefEnv({ set: [['ui.prefersReducedMotion', 1]]});
 
   const results =
       await Promise.allSettled([ changedInThisDocument, changedInIFrame ]);
 
   results.forEach(result => {
     is(result.status, "fulfilled");
     ok(result.value, `Matches ${mqString}`);
   });
-
-  SpecialPowers.DOMWindowUtils.resetPrefersReducedMotionOverrideForTest();
 });
 </script>
 </body>
 </html>
--- a/layout/style/test/test_mq_prefers_reduced_motion_dynamic.html
+++ b/layout/style/test/test_mq_prefers_reduced_motion_dynamic.html
@@ -35,22 +35,22 @@ async function promiseForChange(mediaQue
     }, { once: true });
   });
 }
 
 add_task(async () => {
   const initiallyMatches =
       window.matchMedia('(prefers-reduced-motion: reduce)').matches;
 
-  SpecialPowers.DOMWindowUtils.setPrefersReducedMotionOverrideForTest(false);
+  const changePromise = initiallyMatches ? promiseForChange('(prefers-reduced-motion: reduce)') : null;
 
-  if (initiallyMatches) {
-    await promiseForChange('(prefers-reduced-motion: reduce)');
-  } else {
-    await waitForFrame();
+  await SpecialPowers.pushPrefEnv({ set: [['ui.prefersReducedMotion', 0]]});
+
+  if (changePromise) {
+    await changePromise;
   }
 
   ok(!window.matchMedia('(prefers-reduced-motion: reduce)').matches,
      'Does not matches prefers-reduced-motion: reduced) when the system sets ' +
      'prefers-reduced-motion false');
   ok(!window.matchMedia('(prefers-reduced-motion)').matches,
      'Does not matches (prefers-reduced-motion) when the system sets ' +
      'prefers-reduced-motion false');
@@ -59,28 +59,28 @@ add_task(async () => {
      'prefers-reduced-motion false');
 });
 
 add_task(async () => {
   const reduce = promiseForChange('(prefers-reduced-motion: reduce)');
   const booleanContext = promiseForChange('(prefers-reduced-motion)');
   const noPreference = promiseForChange('(prefers-reduced-motion: no-preference)');
 
-  SpecialPowers.DOMWindowUtils.setPrefersReducedMotionOverrideForTest(true);
+  await SpecialPowers.pushPrefEnv({ set: [['ui.prefersReducedMotion', 1]]});
 
   const [ reduceResult, booleanContextResult, noPreferenceResult ] =
     await Promise.all([ reduce, booleanContext, noPreference ]);
 
   ok(reduceResult,
      'Matches (prefers-reduced-motion: reduced) when the system sets ' +
      'prefers-reduced-motion true');
   ok(booleanContextResult,
      'Matches (prefers-reduced-motion) when the system sets ' +
      'prefers-reduced-motion true');
   ok(!noPreferenceResult,
      'Does not matches (prefers-reduced-motion: no-preference) when the ' +
      'system sets prefers-reduced-motion true');
 
-  SpecialPowers.DOMWindowUtils.resetPrefersReducedMotionOverrideForTest();
+  await SpecialPowers.flushPrefEnv();
 });
 </script>
 </body>
 </html>
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java
@@ -103,23 +103,16 @@ public class GeckoSystemStateListener
         ContentResolver contentResolver = sApplicationContext.getContentResolver();
 
         return Settings.Global.getFloat(contentResolver,
                                         Settings.Global.ANIMATOR_DURATION_SCALE,
                                         1) == 0.0f;
     }
 
     @WrapForJNI(calledFrom = "gecko")
-    private static void notifyPrefersReducedMotionChangedForTest() {
-        ContentResolver contentResolver = sApplicationContext.getContentResolver();
-        Uri animationSetting = Settings.System.getUriFor(Settings.Global.ANIMATOR_DURATION_SCALE);
-        contentResolver.notifyChange(animationSetting, null);
-    }
-
-    @WrapForJNI(calledFrom = "gecko")
     /**
      * For prefers-color-scheme media queries feature.
      */
     private static boolean isNightMode() {
         return sIsNightMode;
     }
 
     public void updateNightMode(final int newUIMode) {
--- a/widget/LookAndFeel.h
+++ b/widget/LookAndFeel.h
@@ -521,25 +521,16 @@ class LookAndFeel {
   static void NativeInit();
 
   /**
    * If the implementation is caching values, these accessors allow the
    * cache to be exported and imported.
    */
   static nsTArray<LookAndFeelInt> GetIntCache();
   static void SetIntCache(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache);
-  /**
-   * Set a flag indicating whether the cache should be cleared in RefreshImpl()
-   * or not.
-   */
-  static void SetShouldRetainCacheForTest(bool aValue);
-
-  static void SetPrefersReducedMotionOverrideForTest(bool aValue);
-
-  static void ResetPrefersReducedMotionOverrideForTest();
 };
 
 }  // namespace mozilla
 
 // On the Mac, GetColor(ColorID::TextSelectForeground, color) returns this
 // constant to specify that the foreground color should not be changed
 // (ie. a colored text keeps its colors  when selected).
 // Of course if other plaforms work like the Mac, they can use it too.
--- a/widget/PuppetWidget.cpp
+++ b/widget/PuppetWidget.cpp
@@ -1443,28 +1443,10 @@ nsresult PuppetWidget::SetSystemFont(con
 nsresult PuppetWidget::GetSystemFont(nsCString& aFontName) {
   if (!mBrowserChild) {
     return NS_ERROR_FAILURE;
   }
   mBrowserChild->SendGetSystemFont(&aFontName);
   return NS_OK;
 }
 
-nsresult PuppetWidget::SetPrefersReducedMotionOverrideForTest(bool aValue) {
-  if (!mBrowserChild) {
-    return NS_ERROR_FAILURE;
-  }
-
-  mBrowserChild->SendSetPrefersReducedMotionOverrideForTest(aValue);
-  return NS_OK;
-}
-
-nsresult PuppetWidget::ResetPrefersReducedMotionOverrideForTest() {
-  if (!mBrowserChild) {
-    return NS_ERROR_FAILURE;
-  }
-
-  mBrowserChild->SendResetPrefersReducedMotionOverrideForTest();
-  return NS_OK;
-}
-
 }  // namespace widget
 }  // namespace mozilla
--- a/widget/PuppetWidget.h
+++ b/widget/PuppetWidget.h
@@ -308,19 +308,16 @@ class PuppetWidget : public nsBaseWidget
   virtual void LookUpDictionary(
       const nsAString& aText,
       const nsTArray<mozilla::FontRange>& aFontRangeArray,
       const bool aIsVertical, const LayoutDeviceIntPoint& aPoint) override;
 
   nsresult SetSystemFont(const nsCString& aFontName) override;
   nsresult GetSystemFont(nsCString& aFontName) override;
 
-  nsresult SetPrefersReducedMotionOverrideForTest(bool aValue) override;
-  nsresult ResetPrefersReducedMotionOverrideForTest() override;
-
   // TextEventDispatcherListener
   using nsBaseWidget::NotifyIME;
   NS_IMETHOD NotifyIME(TextEventDispatcher* aTextEventDispatcher,
                        const IMENotification& aNotification) override;
   NS_IMETHOD_(IMENotificationRequests) GetIMENotificationRequests() override;
   NS_IMETHOD_(void)
   OnRemovedFrom(TextEventDispatcher* aTextEventDispatcher) override;
   NS_IMETHOD_(void)
--- a/widget/android/nsLookAndFeel.cpp
+++ b/widget/android/nsLookAndFeel.cpp
@@ -12,22 +12,16 @@
 #include "mozilla/FontPropertyTypes.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/java/GeckoAppShellWrappers.h"
 #include "mozilla/java/GeckoSystemStateListenerWrappers.h"
 
 using namespace mozilla;
 using mozilla::dom::ContentChild;
 
-bool nsLookAndFeel::mInitializedSystemColors = false;
-AndroidSystemColors nsLookAndFeel::mSystemColors;
-
-bool nsLookAndFeel::mInitializedShowPassword = false;
-bool nsLookAndFeel::mShowPassword = true;
-
 static const char16_t UNICODE_BULLET = 0x2022;
 
 nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() {}
 
 nsLookAndFeel::~nsLookAndFeel() {}
 
 #define BG_PRELIGHT_COLOR NS_RGB(0xee, 0xee, 0xee)
 #define FG_PRELIGHT_COLOR NS_RGB(0x77, 0x77, 0x77)
@@ -73,28 +67,21 @@ nsresult nsLookAndFeel::GetSystemColors(
 void nsLookAndFeel::NativeInit() {
   EnsureInitSystemColors();
   EnsureInitShowPassword();
   RecordTelemetry();
 }
 
 /* virtual */
 void nsLookAndFeel::RefreshImpl() {
-  if (mShouldRetainCacheForTest) {
-    return;
-  }
-
   nsXPLookAndFeel::RefreshImpl();
 
   mInitializedSystemColors = false;
   mInitializedShowPassword = false;
-
-  if (XRE_IsParentProcess()) {
-    mPrefersReducedMotionCached = false;
-  }
+  mPrefersReducedMotionCached = false;
 }
 
 nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
   nsresult rv = NS_OK;
 
   EnsureInitSystemColors();
   if (!mInitializedSystemColors) {
     // Failure to initialize colors is an error condition. Return black.
@@ -382,16 +369,17 @@ nsresult nsLookAndFeel::GetIntImpl(IntID
     case eIntID_ContextMenuOffsetHorizontal:
       aResult = 2;
       break;
 
     case eIntID_PrefersReducedMotion:
       if (!mPrefersReducedMotionCached && XRE_IsParentProcess()) {
         mPrefersReducedMotion =
             java::GeckoSystemStateListener::PrefersReducedMotion() ? 1 : 0;
+        mPrefersReducedMotionCached = true;
       }
       aResult = mPrefersReducedMotion;
       break;
 
     case eIntID_PrimaryPointerCapabilities:
       aResult = java::GeckoAppShell::GetPrimaryPointerCapabilities();
       break;
     case eIntID_AllPointerCapabilities:
--- a/widget/android/nsLookAndFeel.h
+++ b/widget/android/nsLookAndFeel.h
@@ -23,20 +23,22 @@ class nsLookAndFeel final : public nsXPL
   virtual bool GetEchoPasswordImpl() override;
   virtual uint32_t GetPasswordMaskDelayImpl() override;
   virtual char16_t GetPasswordCharacterImpl() override;
   virtual nsTArray<LookAndFeelInt> GetIntCacheImpl() override;
   virtual void SetIntCacheImpl(
       const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) override;
 
  protected:
-  static bool mInitializedSystemColors;
-  static mozilla::AndroidSystemColors mSystemColors;
-  static bool mInitializedShowPassword;
-  static bool mShowPassword;
+  bool mInitializedSystemColors = false;
+  mozilla::AndroidSystemColors mSystemColors;
+  bool mInitializedShowPassword = false;
+  bool mShowPassword = false;
+  int32_t mPrefersReducedMotion = -1;
+  bool mPrefersReducedMotionCached = false;
 
   nsresult GetSystemColors();
 
   void EnsureInitSystemColors();
   void EnsureInitShowPassword();
 };
 
 #endif
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -2385,29 +2385,16 @@ void nsWindow::UpdateDynamicToolbarOffse
     mWidgetListener->DynamicToolbarOffsetChanged(aOffset);
   }
 
   if (mAttachedWidgetListener) {
     mAttachedWidgetListener->DynamicToolbarOffsetChanged(aOffset);
   }
 }
 
-nsresult nsWindow::SetPrefersReducedMotionOverrideForTest(bool aValue) {
-  LookAndFeel::SetPrefersReducedMotionOverrideForTest(aValue);
-
-  // Notify as if the corresponding setting changed.
-  java::GeckoSystemStateListener::NotifyPrefersReducedMotionChangedForTest();
-  return NS_OK;
-}
-
-nsresult nsWindow::ResetPrefersReducedMotionOverrideForTest() {
-  LookAndFeel::ResetPrefersReducedMotionOverrideForTest();
-  return NS_OK;
-}
-
 ScreenIntMargin nsWindow::GetSafeAreaInsets() const { return mSafeAreaInsets; }
 
 void nsWindow::UpdateSafeAreaInsets(const ScreenIntMargin& aSafeAreaInsets) {
   mSafeAreaInsets = aSafeAreaInsets;
 
   if (mWidgetListener) {
     mWidgetListener->SafeAreaInsetsChanged(aSafeAreaInsets);
   }
@@ -2423,17 +2410,16 @@ auto nsWindow::GeckoViewSupport::OnLoadR
     bool aIsTopLevel) const -> java::GeckoResult::LocalRef {
   GeckoSession::Window::LocalRef window(mGeckoViewWindow);
   if (!window) {
     return nullptr;
   }
   return window->OnLoadRequest(aUri, aWindowType, aFlags, aTriggeringUri,
                                aHasUserGesture, aIsTopLevel);
 }
-
 already_AddRefed<nsIWidget> nsIWidget::CreateTopLevelWindow() {
   nsCOMPtr<nsIWidget> window = new nsWindow();
   return window.forget();
 }
 
 already_AddRefed<nsIWidget> nsIWidget::CreateChildWindow() {
   nsCOMPtr<nsIWidget> window = new nsWindow();
   return window.forget();
--- a/widget/android/nsWindow.h
+++ b/widget/android/nsWindow.h
@@ -327,19 +327,16 @@ class nsWindow final : public nsBaseWidg
                               const CSSToScreenScale& aZoom) override;
   void RecvScreenPixels(mozilla::ipc::Shmem&& aMem,
                         const ScreenIntSize& aSize) override;
   void UpdateDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight) override;
   mozilla::ScreenIntCoord GetDynamicToolbarMaxHeight() const override {
     return mDynamicToolbarMaxHeight;
   }
 
-  nsresult SetPrefersReducedMotionOverrideForTest(bool aValue) override;
-  nsresult ResetPrefersReducedMotionOverrideForTest() override;
-
   void UpdateDynamicToolbarOffset(mozilla::ScreenIntCoord aOffset);
 
   virtual mozilla::ScreenIntMargin GetSafeAreaInsets() const override;
   void UpdateSafeAreaInsets(const mozilla::ScreenIntMargin& aSafeAreaInsets);
 
  protected:
   void BringToFront();
   nsWindow* FindTopLevel();
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -487,19 +487,16 @@ class nsChildView final : public nsBaseW
 
   virtual LayoutDeviceIntRegion GetOpaqueWidgetRegion() override;
 
   void DispatchAPZWheelInputEvent(mozilla::InputData& aEvent, bool aCanTriggerSwipe);
   nsEventStatus DispatchAPZInputEvent(mozilla::InputData& aEvent);
 
   void SwipeFinished();
 
-  nsresult SetPrefersReducedMotionOverrideForTest(bool aValue) override;
-  nsresult ResetPrefersReducedMotionOverrideForTest() override;
-
   // Called when the main thread enters a phase during which visual changes
   // are imminent and any layer updates on the compositor thread would interfere
   // with visual atomicity.
   // "Async" CATransactions are CATransactions which happen on a thread that's
   // not the main thread.
   void SuspendAsyncCATransactions();
 
   // Called when we know that the current main thread paint will be completed once
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2232,41 +2232,16 @@ void nsChildView::LookUpDictionary(const
     }
   }
 
   [mView showDefinitionForAttributedString:attrStr atPoint:pt];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
-nsresult nsChildView::SetPrefersReducedMotionOverrideForTest(bool aValue) {
-  LookAndFeel::SetPrefersReducedMotionOverrideForTest(aValue);
-
-  if (nsCocoaFeatures::OnMojaveOrLater() &&
-      NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification) {
-    [[[NSWorkspace sharedWorkspace] notificationCenter]
-        postNotificationName:NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification
-                      object:nil];
-  } else if (nsCocoaFeatures::OnYosemiteOrLater() &&
-             NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification) {
-    [[NSNotificationCenter defaultCenter]
-        postNotificationName:NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification
-                      object:nil];
-  } else {
-    return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
-}
-
-nsresult nsChildView::ResetPrefersReducedMotionOverrideForTest() {
-  LookAndFeel::ResetPrefersReducedMotionOverrideForTest();
-  return NS_OK;
-}
-
 #ifdef ACCESSIBILITY
 already_AddRefed<a11y::Accessible> nsChildView::GetDocumentAccessible() {
   if (!mozilla::a11y::ShouldA11yBeEnabled()) return nullptr;
 
   // mAccessible might be dead if accessibility was previously disabled and is
   // now being enabled again.
   if (mAccessible && mAccessible->IsAlive()) {
     RefPtr<a11y::Accessible> ret;
--- a/widget/cocoa/nsLookAndFeel.h
+++ b/widget/cocoa/nsLookAndFeel.h
@@ -43,16 +43,19 @@ class nsLookAndFeel final : public nsXPL
   bool mUseOverlayScrollbarsCached;
 
   int32_t mAllowOverlayScrollbarsOverlap;
   bool mAllowOverlayScrollbarsOverlapCached;
 
   int32_t mSystemUsesDarkTheme;
   bool mSystemUsesDarkThemeCached;
 
+  int32_t mPrefersReducedMotion = -1;
+  bool mPrefersReducedMotionCached = false;
+
   nscolor mColorTextSelectBackground;
   nscolor mColorTextSelectBackgroundDisabled;
   nscolor mColorHighlight;
   nscolor mColorMenuHover;
   nscolor mColorTextSelectForeground;
   nscolor mColorMenuHoverText;
   nscolor mColorButtonText;
   bool mHasColorButtonText;
--- a/widget/cocoa/nsLookAndFeel.mm
+++ b/widget/cocoa/nsLookAndFeel.mm
@@ -93,20 +93,16 @@ static nscolor GetColorFromNSColorWithAl
                  (unsigned int)([deviceColor greenComponent] * 255.0),
                  (unsigned int)([deviceColor blueComponent] * 255.0),
                  (unsigned int)(alpha * 255.0));
 }
 
 void nsLookAndFeel::NativeInit() { EnsureInit(); }
 
 void nsLookAndFeel::RefreshImpl() {
-  if (mShouldRetainCacheForTest) {
-    return;
-  }
-
   nsXPLookAndFeel::RefreshImpl();
 
   // We should only clear the cache if we're in the main browser process.
   // Otherwise, we should wait for the parent to inform us of new values
   // to cache via LookAndFeel::SetIntCache.
   if (XRE_IsParentProcess()) {
     mUseOverlayScrollbarsCached = false;
     mAllowOverlayScrollbarsOverlapCached = false;
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -259,30 +259,23 @@ nsresult nsLookAndFeel::InitCellHighligh
   }
   NS_HSV2RGB(mMozCellHighlightBackground, hue, sat, luminance, alpha);
   return NS_OK;
 }
 
 void nsLookAndFeel::NativeInit() { EnsureInit(); }
 
 void nsLookAndFeel::RefreshImpl() {
-  if (mShouldRetainCacheForTest) {
-    return;
-  }
-
   nsXPLookAndFeel::RefreshImpl();
   moz_gtk_refresh();
 
   mDefaultFontCached = false;
   mButtonFontCached = false;
   mFieldFontCached = false;
   mMenuFontCached = false;
-  if (XRE_IsParentProcess()) {
-    mPrefersReducedMotionCached = false;
-  }
 
   mInitialized = false;
 }
 
 nsTArray<LookAndFeelInt> nsLookAndFeel::GetIntCacheImpl() {
   nsTArray<LookAndFeelInt> lookAndFeelIntCache =
       nsXPLookAndFeel::GetIntCacheImpl();
 
@@ -302,17 +295,16 @@ void nsLookAndFeel::SetIntCacheImpl(
     const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) {
   for (const auto& entry : aLookAndFeelIntCache) {
     switch (entry.id) {
       case eIntID_SystemUsesDarkTheme:
         mSystemUsesDarkTheme = entry.value;
         break;
       case eIntID_PrefersReducedMotion:
         mPrefersReducedMotion = entry.value;
-        mPrefersReducedMotionCached = true;
         break;
       case eIntID_UseAccessibilityTheme:
         mHighContrast = entry.value;
         break;
     }
   }
 }
 
@@ -738,23 +730,16 @@ nsresult nsLookAndFeel::GetIntImpl(IntID
                     : false;
       break;
     }
     case eIntID_GTKCSDReversedPlacement:
       EnsureInit();
       aResult = mCSDReversedPlacement;
       break;
     case eIntID_PrefersReducedMotion: {
-      if (!mPrefersReducedMotionCached && XRE_IsParentProcess()) {
-        gboolean enableAnimations;
-        GtkSettings* settings = gtk_settings_get_default();
-        g_object_get(settings, "gtk-enable-animations", &enableAnimations,
-                     nullptr);
-        mPrefersReducedMotion = enableAnimations ? 0 : 1;
-      }
       aResult = mPrefersReducedMotion;
       break;
     }
     case eIntID_SystemUsesDarkTheme: {
       EnsureInit();
       aResult = mSystemUsesDarkTheme;
       break;
     }
@@ -1026,16 +1011,21 @@ void nsLookAndFeel::EnsureInit() {
     // results.  Instead mSystemUsesDarkTheme in the child processes is updated
     // via our caching machinery.
     mSystemUsesDarkTheme =
         (RelativeLuminanceUtils::Compute(GDK_RGBA_TO_NS_RGBA(bg)) <
          RelativeLuminanceUtils::Compute(GDK_RGBA_TO_NS_RGBA(fg)));
 
     mHighContrast = StaticPrefs::widget_content_gtk_high_contrast_enabled() &&
                     GetGtkTheme().Find(NS_LITERAL_CSTRING("HighContrast")) >= 0;
+
+    gboolean enableAnimations = false;
+    g_object_get(settings, "gtk-enable-animations", &enableAnimations,
+                 nullptr);
+    mPrefersReducedMotion = !enableAnimations;
   }
 
   // The label is not added to a parent widget, but shared for constructing
   // different style contexts.  The node hierarchy is constructed only on
   // the label style context.
   GtkWidget* labelWidget = gtk_label_new("M");
   g_object_ref_sink(labelWidget);
 
--- a/widget/gtk/nsLookAndFeel.h
+++ b/widget/gtk/nsLookAndFeel.h
@@ -95,16 +95,17 @@ class nsLookAndFeel final : public nsXPL
   bool mMenuSupportsDrag = false;
   bool mCSDAvailable = false;
   bool mCSDHideTitlebarByDefault = false;
   bool mCSDMaximizeButton = false;
   bool mCSDMinimizeButton = false;
   bool mCSDCloseButton = false;
   bool mCSDReversedPlacement = false;
   bool mSystemUsesDarkTheme = false;
+  bool mPrefersReducedMotion = false;
   bool mHighContrast = false;
   bool mInitialized = false;
 
   void EnsureInit();
   void ConfigureContentGtkTheme();
 
  private:
   nsresult InitCellHighlightColors();
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -8192,32 +8192,16 @@ void nsWindow::LockAspectRatio(bool aSho
     mAspectRatio = 0.0;
     LOG(("nsWindow::LockAspectRatio() [%p] removed aspect ratio\n",
          (void*)this));
   }
 
   ApplySizeConstraints();
 }
 
-nsresult nsWindow::SetPrefersReducedMotionOverrideForTest(bool aValue) {
-  LookAndFeel::SetPrefersReducedMotionOverrideForTest(aValue);
-
-  // Notify as if the corresponding setting changed.
-  g_object_notify(G_OBJECT(gtk_settings_get_default()),
-                  "gtk-enable-animations");
-
-  return NS_OK;
-}
-
-nsresult nsWindow::ResetPrefersReducedMotionOverrideForTest() {
-  LookAndFeel::ResetPrefersReducedMotionOverrideForTest();
-
-  return NS_OK;
-}
-
 #ifdef MOZ_WAYLAND
 void nsWindow::SetEGLNativeWindowSize(
     const LayoutDeviceIntSize& aEGLWindowSize) {
   if (mContainer && !mIsX11Display) {
     moz_container_wayland_egl_window_set_size(mContainer, aEGLWindowSize.width,
                                               aEGLWindowSize.height);
   }
 }
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -402,19 +402,16 @@ class nsWindow final : public nsBaseWidg
   LayoutDeviceIntPoint GdkEventCoordsToDevicePixels(gdouble x, gdouble y);
   LayoutDeviceIntRect GdkRectToDevicePixels(GdkRectangle rect);
 
   virtual bool WidgetTypeSupportsAcceleration() override;
 
   nsresult SetSystemFont(const nsCString& aFontName) override;
   nsresult GetSystemFont(nsCString& aFontName) override;
 
-  nsresult SetPrefersReducedMotionOverrideForTest(bool aValue) final;
-  nsresult ResetPrefersReducedMotionOverrideForTest() final;
-
   typedef enum {
     CSD_SUPPORT_SYSTEM,  // CSD including shadows
     CSD_SUPPORT_CLIENT,  // CSD without shadows
     CSD_SUPPORT_NONE,    // WM does not support CSD at all
     CSD_SUPPORT_UNKNOWN
   } CSDSupportLevel;
   /**
    * Get the support of Client Side Decoration by checking
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -1710,23 +1710,16 @@ class nsIWidget : public nsISupports {
    */
   virtual nsresult SetSystemFont(const nsCString& aFontName) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
   virtual nsresult GetSystemFont(nsCString& aFontName) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
-  virtual nsresult SetPrefersReducedMotionOverrideForTest(bool aValue) {
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-  virtual nsresult ResetPrefersReducedMotionOverrideForTest() {
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-
   // Get rectangle of the screen where the window is placed.
   // It's used to detect popup overflow under Wayland because
   // Screenmanager does not work under it.
 #ifdef MOZ_WAYLAND
   virtual nsresult GetScreenRect(LayoutDeviceIntRect* aRect) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
   virtual nsRect GetPreferredPopupRect() {
--- a/widget/nsXPLookAndFeel.cpp
+++ b/widget/nsXPLookAndFeel.cpp
@@ -1078,36 +1078,9 @@ nsTArray<LookAndFeelInt> LookAndFeel::Ge
 }
 
 // static
 void LookAndFeel::SetIntCache(
     const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) {
   return nsLookAndFeel::GetInstance()->SetIntCacheImpl(aLookAndFeelIntCache);
 }
 
-// static
-void LookAndFeel::SetShouldRetainCacheForTest(bool aValue) {
-  nsLookAndFeel::GetInstance()->SetShouldRetainCacheImplForTest(aValue);
-}
-
-// static
-void LookAndFeel::SetPrefersReducedMotionOverrideForTest(bool aValue) {
-  // Tell that the cache value we are going to set isn't cleared via
-  // nsPresContext::ThemeChangedInternal which is called right before
-  // we queue the media feature value change for this prefers-reduced-motion
-  // change.
-  SetShouldRetainCacheForTest(true);
-
-  int32_t value = aValue ? 1 : 0;
-
-  AutoTArray<LookAndFeelInt, 1> lookAndFeelCache;
-  lookAndFeelCache.AppendElement(
-      LookAndFeelInt{.id = eIntID_PrefersReducedMotion, .value = value});
-
-  SetIntCache(lookAndFeelCache);
-}
-
-// static
-void LookAndFeel::ResetPrefersReducedMotionOverrideForTest() {
-  SetShouldRetainCacheForTest(false);
-}
-
 }  // namespace mozilla
--- a/widget/nsXPLookAndFeel.h
+++ b/widget/nsXPLookAndFeel.h
@@ -70,19 +70,16 @@ class nsXPLookAndFeel : public mozilla::
 
   virtual bool GetEchoPasswordImpl() { return false; }
 
   virtual uint32_t GetPasswordMaskDelayImpl() { return 600; }
 
   virtual nsTArray<LookAndFeelInt> GetIntCacheImpl();
   virtual void SetIntCacheImpl(
       const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) {}
-  void SetShouldRetainCacheImplForTest(bool aValue) {
-    mShouldRetainCacheForTest = aValue;
-  }
 
   virtual void NativeInit() = 0;
 
  protected:
   nsXPLookAndFeel() = default;
 
   static void IntPrefChanged(nsLookAndFeelIntPref* data);
   static void FloatPrefChanged(nsLookAndFeelFloatPref* data);
@@ -106,17 +103,11 @@ class nsXPLookAndFeel : public mozilla::
    * the array see nsXPLookAndFeel.cpp
    */
   static const char sColorPrefs[][41];
   static int32_t sCachedColors[size_t(LookAndFeel::ColorID::End)];
   static int32_t sCachedColorBits[COLOR_CACHE_SIZE];
 
   static nsXPLookAndFeel* sInstance;
   static bool sShutdown;
-
-  int32_t mPrefersReducedMotion = -1;
-  bool mPrefersReducedMotionCached = false;
-  // True if we shouldn't clear the cache value in RefreshImpl().
-  // NOTE: This should be used only for testing.
-  bool mShouldRetainCacheForTest = false;
 };
 
 #endif