1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "ui/wm/core/focus_controller.h"
6 
7 #include <map>
8 
9 #include "base/macros.h"
10 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/client/default_capture_client.h"
12 #include "ui/aura/client/focus_change_observer.h"
13 #include "ui/aura/test/aura_test_base.h"
14 #include "ui/aura/test/test_window_delegate.h"
15 #include "ui/aura/test/test_windows.h"
16 #include "ui/aura/window.h"
17 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/aura/window_tracker.h"
19 #include "ui/events/event.h"
20 #include "ui/events/event_constants.h"
21 #include "ui/events/event_handler.h"
22 #include "ui/events/test/event_generator.h"
23 #include "ui/wm/core/base_focus_rules.h"
24 #include "ui/wm/core/window_util.h"
25 #include "ui/wm/public/activation_change_observer.h"
26 #include "ui/wm/public/activation_client.h"
27 
28 // EXPECT_DCHECK executes statement and expects a DCHECK death when DCHECK is
29 // enabled.
30 #if DCHECK_IS_ON()
31 #define EXPECT_DCHECK(statement, regex) \
32   EXPECT_DEATH_IF_SUPPORTED(statement, regex)
33 #else
34 #define EXPECT_DCHECK(statement, regex) \
35   { statement; }
36 #endif
37 
38 namespace wm {
39 
40 class FocusNotificationObserver : public ActivationChangeObserver,
41                                   public aura::client::FocusChangeObserver {
42  public:
FocusNotificationObserver()43   FocusNotificationObserver()
44       : last_activation_reason_(ActivationReason::ACTIVATION_CLIENT),
45         activation_changed_count_(0),
46         focus_changed_count_(0),
47         reactivation_count_(0),
48         reactivation_requested_window_(NULL),
49         reactivation_actual_window_(NULL) {}
~FocusNotificationObserver()50   ~FocusNotificationObserver() override {}
51 
ExpectCounts(int activation_changed_count,int focus_changed_count)52   void ExpectCounts(int activation_changed_count, int focus_changed_count) {
53     EXPECT_EQ(activation_changed_count, activation_changed_count_);
54     EXPECT_EQ(focus_changed_count, focus_changed_count_);
55   }
last_activation_reason() const56   ActivationReason last_activation_reason() const {
57     return last_activation_reason_;
58   }
reactivation_count() const59   int reactivation_count() const {
60     return reactivation_count_;
61   }
reactivation_requested_window() const62   aura::Window* reactivation_requested_window() const {
63     return reactivation_requested_window_;
64   }
reactivation_actual_window() const65   aura::Window* reactivation_actual_window() const {
66     return reactivation_actual_window_;
67   }
68 
69  private:
70   // Overridden from ActivationChangeObserver:
OnWindowActivated(ActivationReason reason,aura::Window * gained_active,aura::Window * lost_active)71   void OnWindowActivated(ActivationReason reason,
72                          aura::Window* gained_active,
73                          aura::Window* lost_active) override {
74     last_activation_reason_ = reason;
75     ++activation_changed_count_;
76   }
OnAttemptToReactivateWindow(aura::Window * request_active,aura::Window * actual_active)77   void OnAttemptToReactivateWindow(aura::Window* request_active,
78                                    aura::Window* actual_active) override {
79     ++reactivation_count_;
80     reactivation_requested_window_ = request_active;
81     reactivation_actual_window_ = actual_active;
82   }
83 
84   // Overridden from aura::client::FocusChangeObserver:
OnWindowFocused(aura::Window * gained_focus,aura::Window * lost_focus)85   void OnWindowFocused(aura::Window* gained_focus,
86                        aura::Window* lost_focus) override {
87     ++focus_changed_count_;
88   }
89 
90   ActivationReason last_activation_reason_;
91   int activation_changed_count_;
92   int focus_changed_count_;
93   int reactivation_count_;
94   aura::Window* reactivation_requested_window_;
95   aura::Window* reactivation_actual_window_;
96 
97   DISALLOW_COPY_AND_ASSIGN(FocusNotificationObserver);
98 };
99 
100 class WindowDeleter {
101  public:
102   virtual aura::Window* GetDeletedWindow() = 0;
103 
104  protected:
~WindowDeleter()105   virtual ~WindowDeleter() {}
106 };
107 
108 // ActivationChangeObserver and FocusChangeObserver that keeps track of whether
109 // it was notified about activation changes or focus changes with a deleted
110 // window.
111 class RecordingActivationAndFocusChangeObserver
112     : public ActivationChangeObserver,
113       public aura::client::FocusChangeObserver {
114  public:
RecordingActivationAndFocusChangeObserver(aura::Window * root,WindowDeleter * deleter)115   RecordingActivationAndFocusChangeObserver(aura::Window* root,
116                                             WindowDeleter* deleter)
117       : root_(root),
118         deleter_(deleter),
119         was_notified_with_deleted_window_(false) {
120     GetActivationClient(root_)->AddObserver(this);
121     aura::client::GetFocusClient(root_)->AddObserver(this);
122   }
~RecordingActivationAndFocusChangeObserver()123   ~RecordingActivationAndFocusChangeObserver() override {
124     GetActivationClient(root_)->RemoveObserver(this);
125     aura::client::GetFocusClient(root_)->RemoveObserver(this);
126   }
127 
was_notified_with_deleted_window() const128   bool was_notified_with_deleted_window() const {
129     return was_notified_with_deleted_window_;
130   }
131 
132   // Overridden from ActivationChangeObserver:
OnWindowActivating(ActivationReason reason,aura::Window * gaining_active,aura::Window * losing_active)133   void OnWindowActivating(ActivationReason reason,
134                           aura::Window* gaining_active,
135                           aura::Window* losing_active) override {
136     if (deleter_->GetDeletedWindow()) {
137       // A deleted window during activation should never be return as either the
138       // gaining or losing active windows, nor should it be returned as the
139       // currently active one.
140       auto* active_window = GetActivationClient(root_)->GetActiveWindow();
141       EXPECT_NE(active_window, deleter_->GetDeletedWindow());
142       EXPECT_NE(gaining_active, deleter_->GetDeletedWindow());
143       EXPECT_NE(losing_active, deleter_->GetDeletedWindow());
144     }
145   }
146 
OnWindowActivated(ActivationReason reason,aura::Window * gained_active,aura::Window * lost_active)147   void OnWindowActivated(ActivationReason reason,
148                          aura::Window* gained_active,
149                          aura::Window* lost_active) override {
150     if (lost_active && lost_active == deleter_->GetDeletedWindow())
151       was_notified_with_deleted_window_ = true;
152   }
153 
154   // Overridden from aura::client::FocusChangeObserver:
OnWindowFocused(aura::Window * gained_focus,aura::Window * lost_focus)155   void OnWindowFocused(aura::Window* gained_focus,
156                        aura::Window* lost_focus) override {
157     if (lost_focus && lost_focus == deleter_->GetDeletedWindow())
158       was_notified_with_deleted_window_ = true;
159   }
160 
161  private:
162   aura::Window* root_;
163 
164   // Not owned.
165   WindowDeleter* deleter_;
166 
167   // Whether the observer was notified about the loss of activation or the
168   // loss of focus with a window already deleted by |deleter_| as the
169   // |lost_active| or |lost_focus| parameter.
170   bool was_notified_with_deleted_window_;
171 
172   DISALLOW_COPY_AND_ASSIGN(RecordingActivationAndFocusChangeObserver);
173 };
174 
175 // Hides a window when activation changes.
176 class HideOnLoseActivationChangeObserver : public ActivationChangeObserver {
177  public:
HideOnLoseActivationChangeObserver(aura::Window * window_to_hide)178   explicit HideOnLoseActivationChangeObserver(aura::Window* window_to_hide)
179       : root_(window_to_hide->GetRootWindow()),
180         window_to_hide_(window_to_hide) {
181     GetActivationClient(root_)->AddObserver(this);
182   }
183 
~HideOnLoseActivationChangeObserver()184   ~HideOnLoseActivationChangeObserver() override {
185     GetActivationClient(root_)->RemoveObserver(this);
186   }
187 
window_to_hide()188   aura::Window* window_to_hide() { return window_to_hide_; }
189 
190  private:
191   // Overridden from ActivationChangeObserver:
OnWindowActivated(ActivationReason reason,aura::Window * gained_active,aura::Window * lost_active)192   void OnWindowActivated(ActivationReason reason,
193                          aura::Window* gained_active,
194                          aura::Window* lost_active) override {
195     if (window_to_hide_) {
196       aura::Window* window_to_hide = window_to_hide_;
197       window_to_hide_ = nullptr;
198       window_to_hide->Hide();
199     }
200   }
201 
202   aura::Window* root_;
203   aura::Window* window_to_hide_;
204 
205   DISALLOW_COPY_AND_ASSIGN(HideOnLoseActivationChangeObserver);
206 };
207 
208 // ActivationChangeObserver that deletes the window losing activation.
209 class DeleteOnActivationChangeObserver : public ActivationChangeObserver,
210                                          public WindowDeleter {
211  public:
212   // If |delete_on_activating| is true, |window| will be deleted when
213   // OnWindowActivating() is called, otherwise, it will be deleted when
214   // OnWindowActivated() is called.
215   // If |delete_window_losing_active| is true, |window| will be deleted if it is
216   // the window losing activation, otherwise, will be deleted if it is the one
217   // gaining activation.
DeleteOnActivationChangeObserver(aura::Window * window,bool delete_on_activating,bool delete_window_losing_active)218   DeleteOnActivationChangeObserver(aura::Window* window,
219                                    bool delete_on_activating,
220                                    bool delete_window_losing_active)
221       : root_(window->GetRootWindow()),
222         window_(window),
223         delete_on_activating_(delete_on_activating),
224         delete_window_losing_active_(delete_window_losing_active),
225         did_delete_(false) {
226     GetActivationClient(root_)->AddObserver(this);
227   }
~DeleteOnActivationChangeObserver()228   ~DeleteOnActivationChangeObserver() override {
229     GetActivationClient(root_)->RemoveObserver(this);
230   }
231 
232   // Overridden from ActivationChangeObserver:
OnWindowActivating(ActivationReason reason,aura::Window * gaining_active,aura::Window * losing_active)233   void OnWindowActivating(ActivationReason reason,
234                           aura::Window* gaining_active,
235                           aura::Window* losing_active) override {
236     if (!delete_on_activating_)
237       return;
238 
239     auto* window_to_delete =
240         delete_window_losing_active_ ? losing_active : gaining_active;
241     if (window_ && window_to_delete == window_) {
242       delete window_to_delete;
243       did_delete_ = true;
244     }
245   }
246 
OnWindowActivated(ActivationReason reason,aura::Window * gained_active,aura::Window * lost_active)247   void OnWindowActivated(ActivationReason reason,
248                          aura::Window* gained_active,
249                          aura::Window* lost_active) override {
250     if (delete_on_activating_)
251       return;
252 
253     auto* window_to_delete =
254         delete_window_losing_active_ ? lost_active : gained_active;
255     if (window_ && window_to_delete == window_) {
256       delete window_to_delete;
257       did_delete_ = true;
258     }
259   }
260 
261   // Overridden from WindowDeleter:
GetDeletedWindow()262   aura::Window* GetDeletedWindow() override {
263     return did_delete_ ? window_ : NULL;
264   }
265 
266  private:
267   aura::Window* root_;
268   aura::Window* window_;
269   const bool delete_on_activating_;
270   const bool delete_window_losing_active_;
271   bool did_delete_;
272 
273   DISALLOW_COPY_AND_ASSIGN(DeleteOnActivationChangeObserver);
274 };
275 
276 // FocusChangeObserver that deletes the window losing focus.
277 class DeleteOnLoseFocusChangeObserver
278     : public aura::client::FocusChangeObserver,
279       public WindowDeleter {
280  public:
DeleteOnLoseFocusChangeObserver(aura::Window * window)281   explicit DeleteOnLoseFocusChangeObserver(aura::Window* window)
282       : root_(window->GetRootWindow()),
283         window_(window),
284         did_delete_(false) {
285     aura::client::GetFocusClient(root_)->AddObserver(this);
286   }
~DeleteOnLoseFocusChangeObserver()287   ~DeleteOnLoseFocusChangeObserver() override {
288     aura::client::GetFocusClient(root_)->RemoveObserver(this);
289   }
290 
291   // Overridden from aura::client::FocusChangeObserver:
OnWindowFocused(aura::Window * gained_focus,aura::Window * lost_focus)292   void OnWindowFocused(aura::Window* gained_focus,
293                        aura::Window* lost_focus) override {
294     if (window_ && lost_focus == window_) {
295       delete lost_focus;
296       did_delete_ = true;
297     }
298   }
299 
300   // Overridden from WindowDeleter:
GetDeletedWindow()301   aura::Window* GetDeletedWindow() override {
302     return did_delete_ ? window_ : NULL;
303   }
304 
305  private:
306   aura::Window* root_;
307   aura::Window* window_;
308   bool did_delete_;
309 
310   DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseFocusChangeObserver);
311 };
312 
313 class ScopedFocusNotificationObserver : public FocusNotificationObserver {
314  public:
ScopedFocusNotificationObserver(aura::Window * root_window)315   ScopedFocusNotificationObserver(aura::Window* root_window)
316       : root_window_(root_window) {
317     GetActivationClient(root_window_)->AddObserver(this);
318     aura::client::GetFocusClient(root_window_)->AddObserver(this);
319   }
~ScopedFocusNotificationObserver()320   ~ScopedFocusNotificationObserver() override {
321     GetActivationClient(root_window_)->RemoveObserver(this);
322     aura::client::GetFocusClient(root_window_)->RemoveObserver(this);
323   }
324 
325  private:
326   aura::Window* root_window_;
327 
328   DISALLOW_COPY_AND_ASSIGN(ScopedFocusNotificationObserver);
329 };
330 
331 class ScopedTargetFocusNotificationObserver : public FocusNotificationObserver {
332  public:
ScopedTargetFocusNotificationObserver(aura::Window * root_window,int id)333   ScopedTargetFocusNotificationObserver(aura::Window* root_window, int id)
334       : target_(root_window->GetChildById(id)) {
335     SetActivationChangeObserver(target_, this);
336     aura::client::SetFocusChangeObserver(target_, this);
337     tracker_.Add(target_);
338   }
~ScopedTargetFocusNotificationObserver()339   ~ScopedTargetFocusNotificationObserver() override {
340     if (tracker_.Contains(target_)) {
341       SetActivationChangeObserver(target_, NULL);
342       aura::client::SetFocusChangeObserver(target_, NULL);
343     }
344   }
345 
346  private:
347   aura::Window* target_;
348   aura::WindowTracker tracker_;
349 
350   DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver);
351 };
352 
353 // Used to fake the handling of events in the pre-target phase.
354 class SimpleEventHandler : public ui::EventHandler {
355  public:
SimpleEventHandler()356   SimpleEventHandler() {}
~SimpleEventHandler()357   ~SimpleEventHandler() override {}
358 
359   // Overridden from ui::EventHandler:
OnMouseEvent(ui::MouseEvent * event)360   void OnMouseEvent(ui::MouseEvent* event) override { event->SetHandled(); }
OnGestureEvent(ui::GestureEvent * event)361   void OnGestureEvent(ui::GestureEvent* event) override { event->SetHandled(); }
362 
363  private:
364   DISALLOW_COPY_AND_ASSIGN(SimpleEventHandler);
365 };
366 
367 class FocusShiftingActivationObserver : public ActivationChangeObserver {
368  public:
FocusShiftingActivationObserver(aura::Window * activated_window)369   explicit FocusShiftingActivationObserver(aura::Window* activated_window)
370       : activated_window_(activated_window),
371         shift_focus_to_(NULL) {}
~FocusShiftingActivationObserver()372   ~FocusShiftingActivationObserver() override {}
373 
set_shift_focus_to(aura::Window * shift_focus_to)374   void set_shift_focus_to(aura::Window* shift_focus_to) {
375     shift_focus_to_ = shift_focus_to;
376   }
377 
378  private:
379   // Overridden from ActivationChangeObserver:
OnWindowActivated(ActivationReason reason,aura::Window * gained_active,aura::Window * lost_active)380   void OnWindowActivated(ActivationReason reason,
381                          aura::Window* gained_active,
382                          aura::Window* lost_active) override {
383     // Shift focus to a child. This should prevent the default focusing from
384     // occurring in FocusController::FocusWindow().
385     if (gained_active == activated_window_) {
386       aura::client::FocusClient* client =
387           aura::client::GetFocusClient(gained_active);
388       client->FocusWindow(shift_focus_to_);
389     }
390   }
391 
392   aura::Window* activated_window_;
393   aura::Window* shift_focus_to_;
394 
395   DISALLOW_COPY_AND_ASSIGN(FocusShiftingActivationObserver);
396 };
397 
398 class ActivateWhileActivatingObserver : public ActivationChangeObserver {
399  public:
ActivateWhileActivatingObserver(aura::Window * to_observe,aura::Window * to_activate,aura::Window * to_focus)400   ActivateWhileActivatingObserver(aura::Window* to_observe,
401                                   aura::Window* to_activate,
402                                   aura::Window* to_focus)
403       : to_observe_(to_observe),
404         to_activate_(to_activate),
405         to_focus_(to_focus) {
406     GetActivationClient(to_observe_->GetRootWindow())->AddObserver(this);
407   }
~ActivateWhileActivatingObserver()408   ~ActivateWhileActivatingObserver() override {
409     GetActivationClient(to_observe_->GetRootWindow())->RemoveObserver(this);
410   }
411 
412  private:
413   // Overridden from ActivationChangeObserver:
OnWindowActivating(ActivationReason reason,aura::Window * gaining_active,aura::Window * losing_active)414   void OnWindowActivating(ActivationReason reason,
415                           aura::Window* gaining_active,
416                           aura::Window* losing_active) override {
417     if (gaining_active != to_observe_)
418       return;
419 
420     if (to_activate_)
421       ActivateWindow(to_activate_);
422     if (to_focus_)
423       FocusWindow(to_focus_);
424   }
OnWindowActivated(ActivationReason reason,aura::Window * gained_active,aura::Window * lost_active)425   void OnWindowActivated(ActivationReason reason,
426                          aura::Window* gained_active,
427                          aura::Window* lost_active) override {}
428 
ActivateWindow(aura::Window * window)429   void ActivateWindow(aura::Window* window) {
430     GetActivationClient(to_observe_->GetRootWindow())->ActivateWindow(window);
431   }
432 
FocusWindow(aura::Window * window)433   void FocusWindow(aura::Window* window) {
434     aura::client::GetFocusClient(to_observe_->GetRootWindow())
435         ->FocusWindow(window);
436   }
437 
438   aura::Window* to_observe_;
439   aura::Window* to_activate_;
440   aura::Window* to_focus_;
441 
442   DISALLOW_COPY_AND_ASSIGN(ActivateWhileActivatingObserver);
443 };
444 
445 // BaseFocusRules subclass that allows basic overrides of focus/activation to
446 // be tested. This is intended more as a test that the override system works at
447 // all, rather than as an exhaustive set of use cases, those should be covered
448 // in tests for those FocusRules implementations.
449 class TestFocusRules : public BaseFocusRules {
450  public:
TestFocusRules()451   TestFocusRules() : focus_restriction_(NULL) {}
452 
453   // Restricts focus and activation to this window and its child hierarchy.
set_focus_restriction(aura::Window * focus_restriction)454   void set_focus_restriction(aura::Window* focus_restriction) {
455     focus_restriction_ = focus_restriction;
456   }
457 
458   // Overridden from BaseFocusRules:
SupportsChildActivation(const aura::Window * window) const459   bool SupportsChildActivation(const aura::Window* window) const override {
460     // In FocusControllerTests, only the RootWindow has activatable children.
461     return window->GetRootWindow() == window;
462   }
CanActivateWindow(const aura::Window * window) const463   bool CanActivateWindow(const aura::Window* window) const override {
464     // Restricting focus to a non-activatable child window means the activatable
465     // parent outside the focus restriction is activatable.
466     bool can_activate =
467         CanFocusOrActivate(window) || window->Contains(focus_restriction_);
468     return can_activate ? BaseFocusRules::CanActivateWindow(window) : false;
469   }
CanFocusWindow(const aura::Window * window,const ui::Event * event) const470   bool CanFocusWindow(const aura::Window* window,
471                       const ui::Event* event) const override {
472     return CanFocusOrActivate(window)
473                ? BaseFocusRules::CanFocusWindow(window, event)
474                : false;
475   }
GetActivatableWindow(aura::Window * window) const476   aura::Window* GetActivatableWindow(aura::Window* window) const override {
477     return BaseFocusRules::GetActivatableWindow(
478         CanFocusOrActivate(window) ? window : focus_restriction_);
479   }
GetFocusableWindow(aura::Window * window) const480   aura::Window* GetFocusableWindow(aura::Window* window) const override {
481     return BaseFocusRules::GetFocusableWindow(
482         CanFocusOrActivate(window) ? window : focus_restriction_);
483   }
GetNextActivatableWindow(aura::Window * ignore) const484   aura::Window* GetNextActivatableWindow(aura::Window* ignore) const override {
485     aura::Window* next_activatable =
486         BaseFocusRules::GetNextActivatableWindow(ignore);
487     return CanFocusOrActivate(next_activatable) ?
488         next_activatable : GetActivatableWindow(focus_restriction_);
489   }
490 
491  private:
CanFocusOrActivate(const aura::Window * window) const492   bool CanFocusOrActivate(const aura::Window* window) const {
493     return !focus_restriction_ || focus_restriction_->Contains(window);
494   }
495 
496   aura::Window* focus_restriction_;
497 
498   DISALLOW_COPY_AND_ASSIGN(TestFocusRules);
499 };
500 
501 // Common infrastructure shared by all FocusController test types.
502 class FocusControllerTestBase : public aura::test::AuraTestBase {
503  protected:
FocusControllerTestBase()504   FocusControllerTestBase() {}
505 
506   // Overridden from aura::test::AuraTestBase:
SetUp()507   void SetUp() override {
508     // FocusController registers itself as an Env observer so it can catch all
509     // window initializations, including the root_window()'s, so we create it
510     // before allowing the base setup.
511     test_focus_rules_ = new TestFocusRules;
512     focus_controller_ = std::make_unique<FocusController>(test_focus_rules_);
513     aura::test::AuraTestBase::SetUp();
514     root_window()->AddPreTargetHandler(focus_controller_.get());
515     aura::client::SetFocusClient(root_window(), focus_controller_.get());
516     SetActivationClient(root_window(), focus_controller_.get());
517 
518     // Hierarchy used by all tests:
519     // root_window
520     //       +-- w1
521     //       |    +-- w11
522     //       |    +-- w12
523     //       +-- w2
524     //       |    +-- w21
525     //       |         +-- w211
526     //       +-- w3
527     aura::Window* w1 = aura::test::CreateTestWindowWithDelegate(
528         aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 1,
529         gfx::Rect(0, 0, 50, 50), root_window());
530     aura::test::CreateTestWindowWithDelegate(
531         aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 11,
532         gfx::Rect(5, 5, 10, 10), w1);
533     aura::test::CreateTestWindowWithDelegate(
534         aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 12,
535         gfx::Rect(15, 15, 10, 10), w1);
536     aura::Window* w2 = aura::test::CreateTestWindowWithDelegate(
537         aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 2,
538         gfx::Rect(75, 75, 50, 50), root_window());
539     aura::Window* w21 = aura::test::CreateTestWindowWithDelegate(
540         aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 21,
541         gfx::Rect(5, 5, 10, 10), w2);
542     aura::test::CreateTestWindowWithDelegate(
543         aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 211,
544         gfx::Rect(1, 1, 5, 5), w21);
545     aura::test::CreateTestWindowWithDelegate(
546         aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3,
547         gfx::Rect(125, 125, 50, 50), root_window());
548   }
TearDown()549   void TearDown() override {
550     root_window()->RemovePreTargetHandler(focus_controller_.get());
551     aura::test::AuraTestBase::TearDown();
552     test_focus_rules_ = NULL;  // Owned by FocusController.
553     focus_controller_.reset();
554   }
555 
FocusWindow(aura::Window * window)556   void FocusWindow(aura::Window* window) {
557     aura::client::GetFocusClient(root_window())->FocusWindow(window);
558   }
GetFocusedWindow()559   aura::Window* GetFocusedWindow() {
560     return aura::client::GetFocusClient(root_window())->GetFocusedWindow();
561   }
GetFocusedWindowId()562   int GetFocusedWindowId() {
563     aura::Window* focused_window = GetFocusedWindow();
564     return focused_window ? focused_window->id() : -1;
565   }
ActivateWindow(aura::Window * window)566   void ActivateWindow(aura::Window* window) {
567     GetActivationClient(root_window())->ActivateWindow(window);
568   }
DeactivateWindow(aura::Window * window)569   void DeactivateWindow(aura::Window* window) {
570     GetActivationClient(root_window())->DeactivateWindow(window);
571   }
GetActiveWindow()572   aura::Window* GetActiveWindow() {
573     return GetActivationClient(root_window())->GetActiveWindow();
574   }
GetActiveWindowId()575   int GetActiveWindowId() {
576     aura::Window* active_window = GetActiveWindow();
577     return active_window ? active_window->id() : -1;
578   }
579 
test_focus_rules()580   TestFocusRules* test_focus_rules() { return test_focus_rules_; }
581 
582   // Test functions.
583   virtual void BasicFocus() = 0;
584   virtual void BasicActivation() = 0;
585   virtual void FocusEvents() = 0;
DuplicateFocusEvents()586   virtual void DuplicateFocusEvents() {}
587   virtual void ActivationEvents() = 0;
ReactivationEvents()588   virtual void ReactivationEvents() {}
DuplicateActivationEvents()589   virtual void DuplicateActivationEvents() {}
ShiftFocusWithinActiveWindow()590   virtual void ShiftFocusWithinActiveWindow() {}
ShiftFocusToChildOfInactiveWindow()591   virtual void ShiftFocusToChildOfInactiveWindow() {}
ShiftFocusToParentOfFocusedWindow()592   virtual void ShiftFocusToParentOfFocusedWindow() {}
593   virtual void FocusRulesOverride() = 0;
594   virtual void ActivationRulesOverride() = 0;
ShiftFocusOnActivation()595   virtual void ShiftFocusOnActivation() {}
ShiftFocusOnActivationDueToHide()596   virtual void ShiftFocusOnActivationDueToHide() {}
NoShiftActiveOnActivation()597   virtual void NoShiftActiveOnActivation() {}
FocusChangeDuringDrag()598   virtual void FocusChangeDuringDrag() {}
ChangeFocusWhenNothingFocusedAndCaptured()599   virtual void ChangeFocusWhenNothingFocusedAndCaptured() {}
DontPassDeletedWindow()600   virtual void DontPassDeletedWindow() {}
StackWindowAtTopOnActivation()601   virtual void StackWindowAtTopOnActivation() {}
HideFocusedWindowDuringActivationLoss()602   virtual void HideFocusedWindowDuringActivationLoss() {}
ActivateWhileActivating()603   virtual void ActivateWhileActivating() {}
604 
605  private:
606   std::unique_ptr<FocusController> focus_controller_;
607   TestFocusRules* test_focus_rules_;
608 
609   DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase);
610 };
611 
612 // Test base for tests where focus is directly set to a target window.
613 class FocusControllerDirectTestBase : public FocusControllerTestBase {
614  protected:
FocusControllerDirectTestBase()615   FocusControllerDirectTestBase() {}
616 
617   // Different test types shift focus in different ways.
618   virtual void FocusWindowDirect(aura::Window* window) = 0;
619   virtual void ActivateWindowDirect(aura::Window* window) = 0;
620   virtual void DeactivateWindowDirect(aura::Window* window) = 0;
621 
622   // Input events do not change focus if the window can not be focused.
623   virtual bool IsInputEvent() = 0;
624 
625   // Returns the expected ActivationReason caused by calling the
626   // ActivatedWindowDirect(...) or DeactivateWindowDirect(...) methods.
627   virtual ActivationChangeObserver::ActivationReason
628   GetExpectedActivationReason() const = 0;
629 
FocusWindowById(int id)630   void FocusWindowById(int id) {
631     aura::Window* window = root_window()->GetChildById(id);
632     DCHECK(window);
633     FocusWindowDirect(window);
634   }
ActivateWindowById(int id)635   void ActivateWindowById(int id) {
636     aura::Window* window = root_window()->GetChildById(id);
637     DCHECK(window);
638     ActivateWindowDirect(window);
639   }
640 
641   // Overridden from FocusControllerTestBase:
BasicFocus()642   void BasicFocus() override {
643     EXPECT_EQ(NULL, GetFocusedWindow());
644     FocusWindowById(1);
645     EXPECT_EQ(1, GetFocusedWindowId());
646     FocusWindowById(2);
647     EXPECT_EQ(2, GetFocusedWindowId());
648   }
BasicActivation()649   void BasicActivation() override {
650     EXPECT_EQ(NULL, GetActiveWindow());
651     ActivateWindowById(1);
652     EXPECT_EQ(1, GetActiveWindowId());
653     ActivateWindowById(2);
654     EXPECT_EQ(2, GetActiveWindowId());
655     // Verify that attempting to deactivate NULL does not crash and does not
656     // change activation.
657     DeactivateWindow(NULL);
658     EXPECT_EQ(2, GetActiveWindowId());
659     DeactivateWindow(GetActiveWindow());
660     EXPECT_EQ(1, GetActiveWindowId());
661   }
FocusEvents()662   void FocusEvents() override {
663     ScopedFocusNotificationObserver root_observer(root_window());
664     ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
665     ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
666 
667     root_observer.ExpectCounts(0, 0);
668     observer1.ExpectCounts(0, 0);
669     observer2.ExpectCounts(0, 0);
670 
671     FocusWindowById(1);
672     root_observer.ExpectCounts(1, 1);
673     observer1.ExpectCounts(1, 1);
674     observer2.ExpectCounts(0, 0);
675 
676     FocusWindowById(2);
677     root_observer.ExpectCounts(2, 2);
678     observer1.ExpectCounts(2, 2);
679     observer2.ExpectCounts(1, 1);
680   }
DuplicateFocusEvents()681   void DuplicateFocusEvents() override {
682     // Focusing an existing focused window should not resend focus events.
683     ScopedFocusNotificationObserver root_observer(root_window());
684     ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
685 
686     root_observer.ExpectCounts(0, 0);
687     observer1.ExpectCounts(0, 0);
688 
689     FocusWindowById(1);
690     root_observer.ExpectCounts(1, 1);
691     observer1.ExpectCounts(1, 1);
692 
693     FocusWindowById(1);
694     root_observer.ExpectCounts(1, 1);
695     observer1.ExpectCounts(1, 1);
696   }
ActivationEvents()697   void ActivationEvents() override {
698     ActivateWindowById(1);
699 
700     ScopedFocusNotificationObserver root_observer(root_window());
701     ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
702     ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
703 
704     root_observer.ExpectCounts(0, 0);
705     observer1.ExpectCounts(0, 0);
706     observer2.ExpectCounts(0, 0);
707 
708     ActivateWindowById(2);
709     root_observer.ExpectCounts(1, 1);
710     EXPECT_EQ(GetExpectedActivationReason(),
711               root_observer.last_activation_reason());
712     observer1.ExpectCounts(1, 1);
713     observer2.ExpectCounts(1, 1);
714   }
ReactivationEvents()715   void ReactivationEvents() override {
716     ActivateWindowById(1);
717     ScopedFocusNotificationObserver root_observer(root_window());
718     EXPECT_EQ(0, root_observer.reactivation_count());
719     root_window()->GetChildById(2)->Hide();
720     // When we attempt to activate "2", which cannot be activated because it
721     // is not visible, "1" will be reactivated.
722     ActivateWindowById(2);
723     EXPECT_EQ(1, root_observer.reactivation_count());
724     EXPECT_EQ(root_window()->GetChildById(2),
725               root_observer.reactivation_requested_window());
726     EXPECT_EQ(root_window()->GetChildById(1),
727               root_observer.reactivation_actual_window());
728   }
DuplicateActivationEvents()729   void DuplicateActivationEvents() override {
730     // Activating an existing active window should not resend activation events.
731     ActivateWindowById(1);
732 
733     ScopedFocusNotificationObserver root_observer(root_window());
734     ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
735     ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
736 
737     root_observer.ExpectCounts(0, 0);
738     observer1.ExpectCounts(0, 0);
739     observer2.ExpectCounts(0, 0);
740 
741     ActivateWindowById(2);
742     root_observer.ExpectCounts(1, 1);
743     observer1.ExpectCounts(1, 1);
744     observer2.ExpectCounts(1, 1);
745 
746     ActivateWindowById(2);
747     root_observer.ExpectCounts(1, 1);
748     observer1.ExpectCounts(1, 1);
749     observer2.ExpectCounts(1, 1);
750   }
ShiftFocusWithinActiveWindow()751   void ShiftFocusWithinActiveWindow() override {
752     ActivateWindowById(1);
753     EXPECT_EQ(1, GetActiveWindowId());
754     EXPECT_EQ(1, GetFocusedWindowId());
755     FocusWindowById(11);
756     EXPECT_EQ(11, GetFocusedWindowId());
757     FocusWindowById(12);
758     EXPECT_EQ(12, GetFocusedWindowId());
759   }
ShiftFocusToChildOfInactiveWindow()760   void ShiftFocusToChildOfInactiveWindow() override {
761     ActivateWindowById(2);
762     EXPECT_EQ(2, GetActiveWindowId());
763     EXPECT_EQ(2, GetFocusedWindowId());
764     FocusWindowById(11);
765     EXPECT_EQ(1, GetActiveWindowId());
766     EXPECT_EQ(11, GetFocusedWindowId());
767   }
ShiftFocusToParentOfFocusedWindow()768   void ShiftFocusToParentOfFocusedWindow() override {
769     ActivateWindowById(1);
770     EXPECT_EQ(1, GetFocusedWindowId());
771     FocusWindowById(11);
772     EXPECT_EQ(11, GetFocusedWindowId());
773     FocusWindowById(1);
774     // Focus should _not_ shift to the parent of the already-focused window.
775     EXPECT_EQ(11, GetFocusedWindowId());
776   }
FocusRulesOverride()777   void FocusRulesOverride() override {
778     EXPECT_EQ(NULL, GetFocusedWindow());
779     FocusWindowById(11);
780     EXPECT_EQ(11, GetFocusedWindowId());
781 
782     test_focus_rules()->set_focus_restriction(root_window()->GetChildById(211));
783     FocusWindowById(12);
784     // Input events leave focus unchanged; direct API calls will change focus
785     // to the restricted window.
786     int focused_window = IsInputEvent() ? 11 : 211;
787     EXPECT_EQ(focused_window, GetFocusedWindowId());
788 
789     test_focus_rules()->set_focus_restriction(NULL);
790     FocusWindowById(12);
791     EXPECT_EQ(12, GetFocusedWindowId());
792   }
ActivationRulesOverride()793   void ActivationRulesOverride() override {
794     ActivateWindowById(1);
795     EXPECT_EQ(1, GetActiveWindowId());
796     EXPECT_EQ(1, GetFocusedWindowId());
797 
798     aura::Window* w3 = root_window()->GetChildById(3);
799     test_focus_rules()->set_focus_restriction(w3);
800 
801     ActivateWindowById(2);
802     // Input events leave activation unchanged; direct API calls will activate
803     // the restricted window.
804     int active_window = IsInputEvent() ? 1 : 3;
805     EXPECT_EQ(active_window, GetActiveWindowId());
806     EXPECT_EQ(active_window, GetFocusedWindowId());
807 
808     test_focus_rules()->set_focus_restriction(NULL);
809     ActivateWindowById(2);
810     EXPECT_EQ(2, GetActiveWindowId());
811     EXPECT_EQ(2, GetFocusedWindowId());
812   }
ShiftFocusOnActivation()813   void ShiftFocusOnActivation() override {
814     // When a window is activated, by default that window is also focused.
815     // An ActivationChangeObserver may shift focus to another window within the
816     // same activatable window.
817     ActivateWindowById(2);
818     EXPECT_EQ(2, GetFocusedWindowId());
819     ActivateWindowById(1);
820     EXPECT_EQ(1, GetFocusedWindowId());
821 
822     ActivateWindowById(2);
823 
824     aura::Window* target = root_window()->GetChildById(1);
825     ActivationClient* client = GetActivationClient(root_window());
826 
827     std::unique_ptr<FocusShiftingActivationObserver> observer(
828         new FocusShiftingActivationObserver(target));
829     observer->set_shift_focus_to(target->GetChildById(11));
830     client->AddObserver(observer.get());
831 
832     ActivateWindowById(1);
833 
834     // w1's ActivationChangeObserver shifted focus to this child, pre-empting
835     // FocusController's default setting.
836     EXPECT_EQ(11, GetFocusedWindowId());
837 
838     ActivateWindowById(2);
839     EXPECT_EQ(2, GetFocusedWindowId());
840 
841     // Simulate a focus reset by the ActivationChangeObserver. This should
842     // trigger the default setting in FocusController.
843     observer->set_shift_focus_to(NULL);
844     ActivateWindowById(1);
845     EXPECT_EQ(1, GetFocusedWindowId());
846 
847     client->RemoveObserver(observer.get());
848 
849     ActivateWindowById(2);
850     EXPECT_EQ(2, GetFocusedWindowId());
851     ActivateWindowById(1);
852     EXPECT_EQ(1, GetFocusedWindowId());
853   }
ShiftFocusOnActivationDueToHide()854   void ShiftFocusOnActivationDueToHide() override {
855     // Similar to ShiftFocusOnActivation except the activation change is
856     // triggered by hiding the active window.
857     ActivateWindowById(1);
858     EXPECT_EQ(1, GetFocusedWindowId());
859 
860     // Removes window 3 as candidate for next activatable window.
861     root_window()->GetChildById(3)->Hide();
862     EXPECT_EQ(1, GetFocusedWindowId());
863 
864     aura::Window* target = root_window()->GetChildById(2);
865     ActivationClient* client = GetActivationClient(root_window());
866 
867     std::unique_ptr<FocusShiftingActivationObserver> observer(
868         new FocusShiftingActivationObserver(target));
869     observer->set_shift_focus_to(target->GetChildById(21));
870     client->AddObserver(observer.get());
871 
872     // Hide the active window.
873     root_window()->GetChildById(1)->Hide();
874 
875     EXPECT_EQ(21, GetFocusedWindowId());
876 
877     client->RemoveObserver(observer.get());
878   }
NoShiftActiveOnActivation()879   void NoShiftActiveOnActivation() override {
880     // When a window is activated, we need to prevent any change to activation
881     // from being made in response to an activation change notification.
882   }
883 
FocusChangeDuringDrag()884   void FocusChangeDuringDrag() override {
885     std::unique_ptr<aura::client::DefaultCaptureClient> capture_client(
886         new aura::client::DefaultCaptureClient(root_window()));
887     // Activating an inactive window during drag should activate the window.
888     // This emulates the behavior of tab dragging which is merged into the
889     // window below.
890     ActivateWindowById(1);
891 
892     EXPECT_EQ(1, GetActiveWindowId());
893     EXPECT_EQ(1, GetFocusedWindowId());
894 
895     aura::Window* w2 = root_window()->GetChildById(2);
896     ui::test::EventGenerator generator(root_window(), w2);
897     generator.PressLeftButton();
898     aura::client::GetCaptureClient(root_window())->SetCapture(w2);
899     EXPECT_EQ(2, GetActiveWindowId());
900     EXPECT_EQ(2, GetFocusedWindowId());
901     generator.MoveMouseTo(gfx::Point(0, 0));
902 
903     // Emulate the behavior of merging a tab into an inactive window:
904     // transferring the mouse capture and activate the window.
905     aura::Window* w1 = root_window()->GetChildById(1);
906     aura::client::GetCaptureClient(root_window())->SetCapture(w1);
907     GetActivationClient(root_window())->ActivateWindow(w1);
908     EXPECT_EQ(1, GetActiveWindowId());
909     EXPECT_EQ(1, GetFocusedWindowId());
910 
911     generator.ReleaseLeftButton();
912     aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1);
913   }
914 
915   // Verifies focus change is honored while capture held.
ChangeFocusWhenNothingFocusedAndCaptured()916   void ChangeFocusWhenNothingFocusedAndCaptured() override {
917     std::unique_ptr<aura::client::DefaultCaptureClient> capture_client(
918         new aura::client::DefaultCaptureClient(root_window()));
919     aura::Window* w1 = root_window()->GetChildById(1);
920     aura::client::GetCaptureClient(root_window())->SetCapture(w1);
921 
922     EXPECT_EQ(-1, GetActiveWindowId());
923     EXPECT_EQ(-1, GetFocusedWindowId());
924 
925     FocusWindowById(1);
926 
927     EXPECT_EQ(1, GetActiveWindowId());
928     EXPECT_EQ(1, GetFocusedWindowId());
929 
930     aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1);
931   }
932 
933   // Verifies if a window that loses activation or focus is deleted during
934   // observer notification we don't pass the deleted window to other observers.
DontPassDeletedWindow()935   void DontPassDeletedWindow() override {
936     FocusWindowById(1);
937 
938     EXPECT_EQ(1, GetActiveWindowId());
939     EXPECT_EQ(1, GetFocusedWindowId());
940 
941     {
942       aura::Window* to_delete = root_window()->GetChildById(1);
943       DeleteOnActivationChangeObserver observer1(
944           to_delete,
945           /*delete_on_activating=*/true,
946           /*delete_window_losing_active=*/true);
947       RecordingActivationAndFocusChangeObserver observer2(root_window(),
948                                                           &observer1);
949 
950       FocusWindowById(2);
951 
952       EXPECT_EQ(2, GetActiveWindowId());
953       EXPECT_EQ(2, GetFocusedWindowId());
954 
955       EXPECT_EQ(to_delete, observer1.GetDeletedWindow());
956       EXPECT_FALSE(observer2.was_notified_with_deleted_window());
957     }
958 
959     {
960       aura::Window* to_delete = root_window()->GetChildById(2);
961       DeleteOnActivationChangeObserver observer1(
962           to_delete, /*delete_on_activating=*/false,
963           /*delete_window_losing_active=*/true);
964       RecordingActivationAndFocusChangeObserver observer2(root_window(),
965                                                           &observer1);
966 
967       FocusWindowById(3);
968 
969       EXPECT_EQ(3, GetActiveWindowId());
970       EXPECT_EQ(3, GetFocusedWindowId());
971 
972       EXPECT_EQ(to_delete, observer1.GetDeletedWindow());
973       EXPECT_FALSE(observer2.was_notified_with_deleted_window());
974     }
975 
976     {
977       aura::test::CreateTestWindowWithDelegate(
978           aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 4,
979           gfx::Rect(125, 125, 50, 50), root_window());
980 
981       EXPECT_EQ(3, GetActiveWindowId());
982       EXPECT_EQ(3, GetFocusedWindowId());
983 
984       aura::Window* to_delete = root_window()->GetChildById(3);
985       DeleteOnLoseFocusChangeObserver observer1(to_delete);
986       RecordingActivationAndFocusChangeObserver observer2(root_window(),
987                                                           &observer1);
988 
989       FocusWindowById(4);
990 
991       EXPECT_EQ(4, GetActiveWindowId());
992       EXPECT_EQ(4, GetFocusedWindowId());
993 
994       EXPECT_EQ(to_delete, observer1.GetDeletedWindow());
995       EXPECT_FALSE(observer2.was_notified_with_deleted_window());
996     }
997 
998     {
999       aura::test::CreateTestWindowWithDelegate(
1000           aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 5,
1001           gfx::Rect(125, 125, 50, 50), root_window());
1002       aura::test::CreateTestWindowWithDelegate(
1003           aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 6,
1004           gfx::Rect(125, 125, 50, 50), root_window());
1005 
1006       EXPECT_EQ(4, GetActiveWindowId());
1007       EXPECT_EQ(4, GetFocusedWindowId());
1008 
1009       // Delete the window that is gaining activation at both the "activating"
1010       // and "activated" phases. Make sure the activations were interrupted
1011       // properly and the correct next activatable window is activated.
1012       aura::Window* to_delete1 = root_window()->GetChildById(5);
1013       DeleteOnActivationChangeObserver observer1(
1014           to_delete1, /*delete_on_activating=*/false,
1015           /*delete_window_losing_active=*/false);
1016       RecordingActivationAndFocusChangeObserver observer2(root_window(),
1017                                                           &observer1);
1018       // Test a recursive scenario by having another observer that would delete
1019       // the next activatable window during the "activating" phase.
1020       aura::Window* to_delete2 = root_window()->GetChildById(6);
1021       DeleteOnActivationChangeObserver observer3(
1022           to_delete2, /*delete_on_activating=*/true,
1023           /*delete_window_losing_active=*/false);
1024       RecordingActivationAndFocusChangeObserver observer4(root_window(),
1025                                                           &observer3);
1026 
1027       FocusWindowById(5);
1028 
1029       EXPECT_EQ(4, GetActiveWindowId());
1030       EXPECT_EQ(4, GetFocusedWindowId());
1031 
1032       EXPECT_EQ(to_delete1, observer1.GetDeletedWindow());
1033       EXPECT_FALSE(observer2.was_notified_with_deleted_window());
1034       EXPECT_EQ(to_delete2, observer3.GetDeletedWindow());
1035       EXPECT_FALSE(observer4.was_notified_with_deleted_window());
1036     }
1037   }
1038 
1039   // Test that the activation of the current active window will bring the window
1040   // to the top of the window stack.
StackWindowAtTopOnActivation()1041   void StackWindowAtTopOnActivation() override {
1042     // Create a window, show it and then activate it.
1043     std::unique_ptr<aura::Window> window1 =
1044         std::make_unique<aura::Window>(nullptr);
1045     window1->SetType(aura::client::WINDOW_TYPE_NORMAL);
1046     window1->Init(ui::LAYER_TEXTURED);
1047     root_window()->AddChild(window1.get());
1048     window1->Show();
1049     ActivateWindow(window1.get());
1050     EXPECT_EQ(window1.get(), root_window()->children().back());
1051     EXPECT_EQ(window1.get(), GetActiveWindow());
1052 
1053     // Create another window, show it but don't activate it. The window is not
1054     // the active window but is placed on top of window stack.
1055     std::unique_ptr<aura::Window> window2 =
1056         std::make_unique<aura::Window>(nullptr);
1057     window2->SetType(aura::client::WINDOW_TYPE_NORMAL);
1058     window2->Init(ui::LAYER_TEXTURED);
1059     root_window()->AddChild(window2.get());
1060     window2->Show();
1061     EXPECT_EQ(window2.get(), root_window()->children().back());
1062     EXPECT_EQ(window1.get(), GetActiveWindow());
1063 
1064     // Try to reactivate the active window. It should bring the active window
1065     // to the top of the window stack.
1066     ActivateWindow(window1.get());
1067     EXPECT_EQ(window1.get(), root_window()->children().back());
1068     EXPECT_EQ(window1.get(), GetActiveWindow());
1069   }
1070 
1071   // Verifies focus isn't left when during notification of an activation change
1072   // the focused window is hidden.
HideFocusedWindowDuringActivationLoss()1073   void HideFocusedWindowDuringActivationLoss() override {
1074     aura::Window* w11 = root_window()->GetChildById(11);
1075     FocusWindow(w11);
1076     EXPECT_EQ(11, GetFocusedWindowId());
1077     EXPECT_EQ(1, GetActiveWindowId());
1078     {
1079       HideOnLoseActivationChangeObserver observer(w11);
1080       ActivateWindowById(2);
1081       EXPECT_EQ(nullptr, observer.window_to_hide());
1082       EXPECT_EQ(2, GetActiveWindowId());
1083       EXPECT_EQ(2, GetFocusedWindowId());
1084     }
1085   }
1086 
1087   // Tests that activating a window while a window is being activated is a
1088   // no-op.
ActivateWhileActivating()1089   void ActivateWhileActivating() override {
1090     aura::Window* w1 = root_window()->GetChildById(1);
1091     aura::Window* w2 = root_window()->GetChildById(2);
1092 
1093     ActivateWindowById(3);
1094     // Activate a window while it is being activated does not DCHECK and the
1095     // window is made active.
1096     {
1097       ActivateWhileActivatingObserver observer(/*to_observe=*/w1,
1098                                                /*to_activate=*/w1,
1099                                                /*to_focus=*/nullptr);
1100       ActivateWindow(w1);
1101       EXPECT_EQ(1, GetActiveWindowId());
1102     }
1103 
1104     ActivateWindowById(3);
1105     // Focus a window while it is being activated does not DCHECK and the
1106     // window is made active and focused.
1107     {
1108       ActivateWhileActivatingObserver observer(/*to_observe=*/w1,
1109                                                /*to_activate=*/nullptr,
1110                                                /*to_focus=*/w1);
1111       ActivateWindow(w1);
1112       EXPECT_EQ(1, GetActiveWindowId());
1113       EXPECT_EQ(1, GetFocusedWindowId());
1114     }
1115 
1116     ActivateWindowById(3);
1117     // Shift focus while activating a window is allowed as long as it does
1118     // not attempt to activate a different window.
1119     {
1120       aura::Window* w11 = root_window()->GetChildById(11);
1121       aura::Window* w12 = root_window()->GetChildById(12);
1122       ActivateWhileActivatingObserver observer(/*to_observe=*/w1,
1123                                                /*to_activate=*/nullptr,
1124                                                /*to_focus=*/w12);
1125       FocusWindow(w11);
1126       EXPECT_EQ(1, GetActiveWindowId());
1127       EXPECT_EQ(12, GetFocusedWindowId());
1128     }
1129 
1130     ActivateWindowById(3);
1131     // Activate a different window while activating one fails. The window being
1132     // activated in the 1st activation request will be activated.
1133     {
1134       ActivateWhileActivatingObserver observer(/*to_observe=*/w2,
1135                                                /*to_activate=*/w1,
1136                                                /*to_focus=*/nullptr);
1137       // This should hit a DCHECK.
1138       EXPECT_DCHECK(
1139           {
1140             ActivateWindow(w2);
1141             EXPECT_EQ(2, GetActiveWindowId());
1142           },
1143           "");
1144     }
1145   }
1146 
1147  private:
1148   DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase);
1149 };
1150 
1151 // Focus and Activation changes via ActivationClient API.
1152 class FocusControllerApiTest : public FocusControllerDirectTestBase {
1153  public:
FocusControllerApiTest()1154   FocusControllerApiTest() {}
1155 
1156  private:
1157   // Overridden from FocusControllerTestBase:
FocusWindowDirect(aura::Window * window)1158   void FocusWindowDirect(aura::Window* window) override { FocusWindow(window); }
ActivateWindowDirect(aura::Window * window)1159   void ActivateWindowDirect(aura::Window* window) override {
1160     ActivateWindow(window);
1161   }
DeactivateWindowDirect(aura::Window * window)1162   void DeactivateWindowDirect(aura::Window* window) override {
1163     DeactivateWindow(window);
1164   }
IsInputEvent()1165   bool IsInputEvent() override { return false; }
1166   // Overridden from FocusControllerDirectTestBase:
GetExpectedActivationReason() const1167   ActivationChangeObserver::ActivationReason GetExpectedActivationReason()
1168       const override {
1169     return ActivationChangeObserver::ActivationReason::ACTIVATION_CLIENT;
1170   }
1171 
1172   DISALLOW_COPY_AND_ASSIGN(FocusControllerApiTest);
1173 };
1174 
1175 // Focus and Activation changes via input events.
1176 class FocusControllerMouseEventTest : public FocusControllerDirectTestBase {
1177  public:
FocusControllerMouseEventTest()1178   FocusControllerMouseEventTest() {}
1179 
1180   // Tests that a handled mouse or gesture event does not trigger a window
1181   // activation.
IgnoreHandledEvent()1182   void IgnoreHandledEvent() {
1183     EXPECT_EQ(NULL, GetActiveWindow());
1184     aura::Window* w1 = root_window()->GetChildById(1);
1185     SimpleEventHandler handler;
1186     root_window()->AddPreTargetHandler(&handler,
1187                                        ui::EventTarget::Priority::kSystem);
1188     ui::test::EventGenerator generator(root_window(), w1);
1189     generator.ClickLeftButton();
1190     EXPECT_EQ(NULL, GetActiveWindow());
1191     generator.GestureTapAt(w1->bounds().CenterPoint());
1192     EXPECT_EQ(NULL, GetActiveWindow());
1193     root_window()->RemovePreTargetHandler(&handler);
1194     generator.ClickLeftButton();
1195     EXPECT_EQ(1, GetActiveWindowId());
1196   }
1197 
1198  private:
1199   // Overridden from FocusControllerTestBase:
FocusWindowDirect(aura::Window * window)1200   void FocusWindowDirect(aura::Window* window) override {
1201     ui::test::EventGenerator generator(root_window(), window);
1202     generator.ClickLeftButton();
1203   }
ActivateWindowDirect(aura::Window * window)1204   void ActivateWindowDirect(aura::Window* window) override {
1205     ui::test::EventGenerator generator(root_window(), window);
1206     generator.ClickLeftButton();
1207   }
DeactivateWindowDirect(aura::Window * window)1208   void DeactivateWindowDirect(aura::Window* window) override {
1209     aura::Window* next_activatable =
1210         test_focus_rules()->GetNextActivatableWindow(window);
1211     ui::test::EventGenerator generator(root_window(), next_activatable);
1212     generator.ClickLeftButton();
1213   }
1214   // Overridden from FocusControllerDirectTestBase:
IsInputEvent()1215   bool IsInputEvent() override { return true; }
GetExpectedActivationReason() const1216   ActivationChangeObserver::ActivationReason GetExpectedActivationReason()
1217       const override {
1218     return ActivationChangeObserver::ActivationReason::INPUT_EVENT;
1219   }
1220 
1221   DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest);
1222 };
1223 
1224 class FocusControllerGestureEventTest : public FocusControllerDirectTestBase {
1225  public:
FocusControllerGestureEventTest()1226   FocusControllerGestureEventTest() {}
1227 
1228  private:
1229   // Overridden from FocusControllerTestBase:
FocusWindowDirect(aura::Window * window)1230   void FocusWindowDirect(aura::Window* window) override {
1231     ui::test::EventGenerator generator(root_window(), window);
1232     generator.GestureTapAt(window->bounds().CenterPoint());
1233   }
ActivateWindowDirect(aura::Window * window)1234   void ActivateWindowDirect(aura::Window* window) override {
1235     ui::test::EventGenerator generator(root_window(), window);
1236     generator.GestureTapAt(window->bounds().CenterPoint());
1237   }
DeactivateWindowDirect(aura::Window * window)1238   void DeactivateWindowDirect(aura::Window* window) override {
1239     aura::Window* next_activatable =
1240         test_focus_rules()->GetNextActivatableWindow(window);
1241     ui::test::EventGenerator generator(root_window(), next_activatable);
1242     generator.GestureTapAt(window->bounds().CenterPoint());
1243   }
IsInputEvent()1244   bool IsInputEvent() override { return true; }
GetExpectedActivationReason() const1245   ActivationChangeObserver::ActivationReason GetExpectedActivationReason()
1246       const override {
1247     return ActivationChangeObserver::ActivationReason::INPUT_EVENT;
1248   }
1249 
1250   DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest);
1251 };
1252 
1253 // Test base for tests where focus is implicitly set to a window as the result
1254 // of a disposition change to the focused window or the hierarchy that contains
1255 // it.
1256 class FocusControllerImplicitTestBase : public FocusControllerTestBase {
1257  protected:
FocusControllerImplicitTestBase(bool parent)1258   explicit FocusControllerImplicitTestBase(bool parent) : parent_(parent) {}
1259 
GetDispositionWindow(aura::Window * window)1260   aura::Window* GetDispositionWindow(aura::Window* window) {
1261     return parent_ ? window->parent() : window;
1262   }
1263 
1264   // Returns the expected ActivationReason caused by calling the
1265   // ActivatedWindowDirect(...) or DeactivateWindowDirect(...) methods.
GetExpectedActivationReason() const1266   ActivationChangeObserver::ActivationReason GetExpectedActivationReason()
1267       const {
1268     return ActivationChangeObserver::ActivationReason::
1269         WINDOW_DISPOSITION_CHANGED;
1270   }
1271 
1272   // Change the disposition of |window| in such a way as it will lose focus.
1273   virtual void ChangeWindowDisposition(aura::Window* window) = 0;
1274 
1275   // Allow each disposition change test to add additional post-disposition
1276   // change expectations.
PostDispositionChangeExpectations()1277   virtual void PostDispositionChangeExpectations() {}
1278 
1279   // Overridden from FocusControllerTestBase:
BasicFocus()1280   void BasicFocus() override {
1281     EXPECT_EQ(NULL, GetFocusedWindow());
1282 
1283     aura::Window* w211 = root_window()->GetChildById(211);
1284     FocusWindow(w211);
1285     EXPECT_EQ(211, GetFocusedWindowId());
1286 
1287     ChangeWindowDisposition(w211);
1288     // BasicFocusRules passes focus to the parent.
1289     EXPECT_EQ(parent_ ? 2 : 21, GetFocusedWindowId());
1290   }
BasicActivation()1291   void BasicActivation() override {
1292     DCHECK(!parent_) << "Activation tests don't support parent changes.";
1293 
1294     EXPECT_EQ(NULL, GetActiveWindow());
1295 
1296     aura::Window* w2 = root_window()->GetChildById(2);
1297     ActivateWindow(w2);
1298     EXPECT_EQ(2, GetActiveWindowId());
1299 
1300     ChangeWindowDisposition(w2);
1301     EXPECT_EQ(3, GetActiveWindowId());
1302     PostDispositionChangeExpectations();
1303   }
FocusEvents()1304   void FocusEvents() override {
1305     aura::Window* w211 = root_window()->GetChildById(211);
1306     FocusWindow(w211);
1307 
1308     ScopedFocusNotificationObserver root_observer(root_window());
1309     ScopedTargetFocusNotificationObserver observer211(root_window(), 211);
1310     root_observer.ExpectCounts(0, 0);
1311     observer211.ExpectCounts(0, 0);
1312 
1313     ChangeWindowDisposition(w211);
1314     root_observer.ExpectCounts(0, 1);
1315     observer211.ExpectCounts(0, 1);
1316   }
ActivationEvents()1317   void ActivationEvents() override {
1318     DCHECK(!parent_) << "Activation tests don't support parent changes.";
1319 
1320     aura::Window* w2 = root_window()->GetChildById(2);
1321     ActivateWindow(w2);
1322 
1323     ScopedFocusNotificationObserver root_observer(root_window());
1324     ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
1325     ScopedTargetFocusNotificationObserver observer3(root_window(), 3);
1326     root_observer.ExpectCounts(0, 0);
1327     observer2.ExpectCounts(0, 0);
1328     observer3.ExpectCounts(0, 0);
1329 
1330     ChangeWindowDisposition(w2);
1331     root_observer.ExpectCounts(1, 1);
1332     EXPECT_EQ(GetExpectedActivationReason(),
1333               root_observer.last_activation_reason());
1334     observer2.ExpectCounts(1, 1);
1335     observer3.ExpectCounts(1, 1);
1336   }
FocusRulesOverride()1337   void FocusRulesOverride() override {
1338     EXPECT_EQ(NULL, GetFocusedWindow());
1339     aura::Window* w211 = root_window()->GetChildById(211);
1340     FocusWindow(w211);
1341     EXPECT_EQ(211, GetFocusedWindowId());
1342 
1343     test_focus_rules()->set_focus_restriction(root_window()->GetChildById(11));
1344     ChangeWindowDisposition(w211);
1345     // Normally, focus would shift to the parent (w21) but the override shifts
1346     // it to 11.
1347     EXPECT_EQ(11, GetFocusedWindowId());
1348 
1349     test_focus_rules()->set_focus_restriction(NULL);
1350   }
ActivationRulesOverride()1351   void ActivationRulesOverride() override {
1352     DCHECK(!parent_) << "Activation tests don't support parent changes.";
1353 
1354     aura::Window* w1 = root_window()->GetChildById(1);
1355     ActivateWindow(w1);
1356 
1357     EXPECT_EQ(1, GetActiveWindowId());
1358     EXPECT_EQ(1, GetFocusedWindowId());
1359 
1360     aura::Window* w3 = root_window()->GetChildById(3);
1361     test_focus_rules()->set_focus_restriction(w3);
1362 
1363     // Normally, activation/focus would move to w2, but since we have a focus
1364     // restriction, it should move to w3 instead.
1365     ChangeWindowDisposition(w1);
1366     EXPECT_EQ(3, GetActiveWindowId());
1367     EXPECT_EQ(3, GetFocusedWindowId());
1368 
1369     test_focus_rules()->set_focus_restriction(NULL);
1370     ActivateWindow(root_window()->GetChildById(2));
1371     EXPECT_EQ(2, GetActiveWindowId());
1372     EXPECT_EQ(2, GetFocusedWindowId());
1373   }
1374 
1375  private:
1376   // When true, the disposition change occurs to the parent of the window
1377   // instead of to the window. This verifies that changes occurring in the
1378   // hierarchy that contains the window affect the window's focus.
1379   bool parent_;
1380 
1381   DISALLOW_COPY_AND_ASSIGN(FocusControllerImplicitTestBase);
1382 };
1383 
1384 // Focus and Activation changes in response to window visibility changes.
1385 class FocusControllerHideTest : public FocusControllerImplicitTestBase {
1386  public:
FocusControllerHideTest()1387   FocusControllerHideTest() : FocusControllerImplicitTestBase(false) {}
1388 
1389  protected:
FocusControllerHideTest(bool parent)1390   FocusControllerHideTest(bool parent)
1391       : FocusControllerImplicitTestBase(parent) {}
1392 
1393   // Overridden from FocusControllerImplicitTestBase:
ChangeWindowDisposition(aura::Window * window)1394   void ChangeWindowDisposition(aura::Window* window) override {
1395     GetDispositionWindow(window)->Hide();
1396   }
1397 
1398  private:
1399   DISALLOW_COPY_AND_ASSIGN(FocusControllerHideTest);
1400 };
1401 
1402 // Focus and Activation changes in response to window parent visibility
1403 // changes.
1404 class FocusControllerParentHideTest : public FocusControllerHideTest {
1405  public:
FocusControllerParentHideTest()1406   FocusControllerParentHideTest() : FocusControllerHideTest(true) {}
1407 
1408   // The parent window's visibility change should not change its transient child
1409   // window's modality property.
TransientChildWindowActivationTest()1410   void TransientChildWindowActivationTest() {
1411     aura::Window* w1 = root_window()->GetChildById(1);
1412     aura::Window* w11 = root_window()->GetChildById(11);
1413     ::wm::AddTransientChild(w1, w11);
1414     w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
1415 
1416     EXPECT_EQ(ui::MODAL_TYPE_NONE, w1->GetProperty(aura::client::kModalKey));
1417     EXPECT_EQ(ui::MODAL_TYPE_WINDOW, w11->GetProperty(aura::client::kModalKey));
1418 
1419     // Hide the parent window w1 and show it again.
1420     w1->Hide();
1421     w1->Show();
1422 
1423     // Test that child window w11 doesn't change its modality property.
1424     EXPECT_EQ(ui::MODAL_TYPE_NONE, w1->GetProperty(aura::client::kModalKey));
1425     EXPECT_EQ(ui::MODAL_TYPE_WINDOW, w11->GetProperty(aura::client::kModalKey));
1426   }
1427 
1428  private:
1429   DISALLOW_COPY_AND_ASSIGN(FocusControllerParentHideTest);
1430 };
1431 
1432 // Focus and Activation changes in response to window destruction.
1433 class FocusControllerDestructionTest : public FocusControllerImplicitTestBase {
1434  public:
FocusControllerDestructionTest()1435   FocusControllerDestructionTest() : FocusControllerImplicitTestBase(false) {}
1436 
1437  protected:
FocusControllerDestructionTest(bool parent)1438   FocusControllerDestructionTest(bool parent)
1439       : FocusControllerImplicitTestBase(parent) {}
1440 
1441   // Overridden from FocusControllerImplicitTestBase:
ChangeWindowDisposition(aura::Window * window)1442   void ChangeWindowDisposition(aura::Window* window) override {
1443     delete GetDispositionWindow(window);
1444   }
1445 
1446  private:
1447   DISALLOW_COPY_AND_ASSIGN(FocusControllerDestructionTest);
1448 };
1449 
1450 // Focus and Activation changes in response to window parent destruction.
1451 class FocusControllerParentDestructionTest
1452     : public FocusControllerDestructionTest {
1453  public:
FocusControllerParentDestructionTest()1454   FocusControllerParentDestructionTest()
1455       : FocusControllerDestructionTest(true) {}
1456 
1457  private:
1458   DISALLOW_COPY_AND_ASSIGN(FocusControllerParentDestructionTest);
1459 };
1460 
1461 // Focus and Activation changes in response to window removal.
1462 class FocusControllerRemovalTest : public FocusControllerImplicitTestBase {
1463  public:
FocusControllerRemovalTest()1464   FocusControllerRemovalTest() : FocusControllerImplicitTestBase(false) {}
1465 
1466  protected:
FocusControllerRemovalTest(bool parent)1467   FocusControllerRemovalTest(bool parent)
1468       : FocusControllerImplicitTestBase(parent) {}
1469 
1470   // Overridden from FocusControllerImplicitTestBase:
ChangeWindowDisposition(aura::Window * window)1471   void ChangeWindowDisposition(aura::Window* window) override {
1472     aura::Window* disposition_window = GetDispositionWindow(window);
1473     disposition_window->parent()->RemoveChild(disposition_window);
1474     window_owner_.reset(disposition_window);
1475   }
TearDown()1476   void TearDown() override {
1477     window_owner_.reset();
1478     FocusControllerImplicitTestBase::TearDown();
1479   }
1480 
1481  private:
1482   std::unique_ptr<aura::Window> window_owner_;
1483 
1484   DISALLOW_COPY_AND_ASSIGN(FocusControllerRemovalTest);
1485 };
1486 
1487 // Focus and Activation changes in response to window parent removal.
1488 class FocusControllerParentRemovalTest : public FocusControllerRemovalTest {
1489  public:
FocusControllerParentRemovalTest()1490   FocusControllerParentRemovalTest() : FocusControllerRemovalTest(true) {}
1491 
1492  private:
1493   DISALLOW_COPY_AND_ASSIGN(FocusControllerParentRemovalTest);
1494 };
1495 
1496 
1497 #define FOCUS_CONTROLLER_TEST(TESTCLASS, TESTNAME) \
1498     TEST_F(TESTCLASS, TESTNAME) { TESTNAME(); }
1499 
1500 // Runs direct focus change tests (input events and API calls).
1501 #define DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1502     FOCUS_CONTROLLER_TEST(FocusControllerApiTest, TESTNAME) \
1503     FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, TESTNAME) \
1504     FOCUS_CONTROLLER_TEST(FocusControllerGestureEventTest, TESTNAME)
1505 
1506 // Runs implicit focus change tests for disposition changes to target.
1507 #define IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME) \
1508     FOCUS_CONTROLLER_TEST(FocusControllerHideTest, TESTNAME) \
1509     FOCUS_CONTROLLER_TEST(FocusControllerDestructionTest, TESTNAME) \
1510     FOCUS_CONTROLLER_TEST(FocusControllerRemovalTest, TESTNAME)
1511 
1512 // Runs implicit focus change tests for disposition changes to target's parent
1513 // hierarchy.
1514 #define IMPLICIT_FOCUS_CHANGE_PARENT_TESTS(TESTNAME) \
1515     /* TODO(beng): parent destruction tests are not supported at
1516        present due to workspace manager issues. \
1517     FOCUS_CONTROLLER_TEST(FocusControllerParentDestructionTest, TESTNAME) */ \
1518     FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, TESTNAME) \
1519     FOCUS_CONTROLLER_TEST(FocusControllerParentRemovalTest, TESTNAME)
1520 
1521 // Runs all implicit focus change tests (changes to the target and target's
1522 // parent hierarchy)
1523 #define IMPLICIT_FOCUS_CHANGE_TESTS(TESTNAME) \
1524     IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME) \
1525     IMPLICIT_FOCUS_CHANGE_PARENT_TESTS(TESTNAME)
1526 
1527 // Runs all possible focus change tests.
1528 #define ALL_FOCUS_TESTS(TESTNAME) \
1529     DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1530     IMPLICIT_FOCUS_CHANGE_TESTS(TESTNAME)
1531 
1532 // Runs focus change tests that apply only to the target. For example,
1533 // implicit activation changes caused by window disposition changes do not
1534 // occur when changes to the containing hierarchy happen.
1535 #define TARGET_FOCUS_TESTS(TESTNAME) \
1536     DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1537     IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME)
1538 
1539 // - Focuses a window, verifies that focus changed.
1540 ALL_FOCUS_TESTS(BasicFocus)
1541 
1542 // - Activates a window, verifies that activation changed.
1543 TARGET_FOCUS_TESTS(BasicActivation)
1544 
1545 // - Focuses a window, verifies that focus events were dispatched.
1546 ALL_FOCUS_TESTS(FocusEvents)
1547 
1548 // - Focuses or activates a window multiple times, verifies that events are only
1549 //   dispatched when focus/activation actually changes.
1550 DIRECT_FOCUS_CHANGE_TESTS(DuplicateFocusEvents)
1551 DIRECT_FOCUS_CHANGE_TESTS(DuplicateActivationEvents)
1552 
1553 // - Activates a window, verifies that activation events were dispatched.
1554 TARGET_FOCUS_TESTS(ActivationEvents)
1555 
1556 // - Attempts to active a hidden window, verifies that current window is
1557 //   attempted to be reactivated and the appropriate event dispatched.
1558 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, ReactivationEvents)
1559 
1560 // - Input events/API calls shift focus between focusable windows within the
1561 //   active window.
1562 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusWithinActiveWindow)
1563 
1564 // - Input events/API calls to a child window of an inactive window shifts
1565 //   activation to the activatable parent and focuses the child.
1566 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToChildOfInactiveWindow)
1567 
1568 // - Input events/API calls to focus the parent of the focused window do not
1569 //   shift focus away from the child.
1570 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToParentOfFocusedWindow)
1571 
1572 // - Verifies that FocusRules determine what can be focused.
1573 ALL_FOCUS_TESTS(FocusRulesOverride)
1574 
1575 // - Verifies that FocusRules determine what can be activated.
1576 TARGET_FOCUS_TESTS(ActivationRulesOverride)
1577 
1578 // - Verifies that attempts to change focus or activation from a focus or
1579 //   activation change observer are ignored.
1580 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation)
1581 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide)
1582 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation)
1583 
1584 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, FocusChangeDuringDrag)
1585 
1586 FOCUS_CONTROLLER_TEST(FocusControllerApiTest,
1587                       ChangeFocusWhenNothingFocusedAndCaptured)
1588 
1589 // See description above DontPassDeletedWindow() for details.
1590 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow)
1591 
1592 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, StackWindowAtTopOnActivation)
1593 
1594 FOCUS_CONTROLLER_TEST(FocusControllerApiTest,
1595                       HideFocusedWindowDuringActivationLoss)
1596 
1597 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, ActivateWhileActivating)
1598 
1599 // See description above TransientChildWindowActivationTest() for details.
1600 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest,
1601                       TransientChildWindowActivationTest)
1602 
1603 // If a mouse event was handled, it should not activate a window.
1604 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent)
1605 
1606 }  // namespace wm
1607