From ed66ab4b53b78e5ee9db2a165b476840dc605a3e Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Mon, 30 Jan 2017 15:42:02 -0800 Subject: [PATCH] Bug 1334572 - Dispatch WindowLowered/Raised events asynchronously in test mode (for marionette) (r=smaug) MozReview-Commit-ID: Kwgl6sX4OoU --- dom/base/nsFocusManager.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index 59a89ab80d61..ad1bf6c95306 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -2204,10 +2204,18 @@ nsFocusManager::RaiseWindow(nsPIDOMWindowOuter* aWindow) if (sTestMode) { // In test mode, emulate the existing window being lowered and the new - // window being raised. - if (mActiveWindow) - WindowLowered(mActiveWindow); - WindowRaised(aWindow); + // window being raised. This happens in a separate runnable to avoid + // touching multiple windows in the current runnable. + nsCOMPtr active(mActiveWindow); + nsCOMPtr window(aWindow); + RefPtr self(this); + NS_DispatchToCurrentThread( + NS_NewRunnableFunction([self, active, window] () -> void { + if (active) { + self->WindowLowered(active); + } + self->WindowRaised(window); + })); return; }