Chromium Code Reviews| Index: ui/views/test/widget_test.cc |
| diff --git a/ui/views/test/widget_test.cc b/ui/views/test/widget_test.cc |
| index d67e951ce23eeba26abce4340ca8c3ce1216a796..f068fd35a6b0a90d8774a16589ae7828a1e10f5c 100644 |
| --- a/ui/views/test/widget_test.cc |
| +++ b/ui/views/test/widget_test.cc |
| @@ -150,5 +150,45 @@ View* TestInitialFocusWidgetDelegate::GetInitiallyFocusedView() { |
| return view_; |
| } |
| +WidgetActivationWaiter::WidgetActivationWaiter(Widget* widget, bool active) |
| + : observed_(false), active_(active) { |
| +#if defined(OS_WIN) |
| + // On Windows, a HWND can receive a WM_ACTIVATE message without the value |
| + // of ::GetActiveWindow() updating to reflect that change. This can cause |
| + // the active window reported by IsActive() to get out of sync. Usually this |
| + // happens after a call to HWNDMessageHandler::Deactivate() which works by |
| + // activating some other window, which might be in another application. |
| + // Doing this can trigger the native OS activation-blocker, causing the |
| + // taskbar icon to flash instead. But since activation of native widgets on |
| + // Windows is synchronous, we never have to wait anyway, so it's safe to |
| + // return here. |
| + if (active == widget->IsActive()) { |
| + observed_ = true; |
| + return; |
| + } |
| +#endif |
| + // Always expect a change for tests using this. |
| + EXPECT_NE(active, widget->IsActive()); |
|
sky
2016/10/12 16:05:43
I think this is error prone for a general class. Y
Qiang(Joe) Xu
2016/10/12 16:55:58
Done.
|
| + widget->AddObserver(this); |
| +} |
| + |
| +WidgetActivationWaiter::~WidgetActivationWaiter() {} |
| + |
| +void WidgetActivationWaiter::Wait() { |
| + if (!observed_) |
| + run_loop_.Run(); |
| +} |
| + |
| +void WidgetActivationWaiter::OnWidgetActivationChanged(Widget* widget, |
| + bool active) { |
| + if (active_ != active) |
| + return; |
| + |
| + observed_ = true; |
| + widget->RemoveObserver(this); |
| + if (run_loop_.running()) |
| + run_loop_.Quit(); |
| +} |
| + |
| } // namespace test |
| } // namespace views |