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.
5 #include "ui/wm/core/focus_controller.h"
9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/client/default_capture_client.h"
11 #include "ui/aura/client/focus_change_observer.h"
12 #include "ui/aura/test/aura_test_base.h"
13 #include "ui/aura/test/test_window_delegate.h"
14 #include "ui/aura/test/test_windows.h"
15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/aura/window_tracker.h"
18 #include "ui/base/ime/dummy_text_input_client.h"
19 #include "ui/base/ime/text_input_focus_manager.h"
20 #include "ui/events/event.h"
21 #include "ui/events/event_constants.h"
22 #include "ui/events/event_handler.h"
23 #include "ui/events/test/event_generator.h"
24 #include "ui/wm/core/base_focus_rules.h"
25 #include "ui/wm/core/window_util.h"
26 #include "ui/wm/core/wm_state.h"
27 #include "ui/wm/public/activation_change_observer.h"
28 #include "ui/wm/public/activation_client.h"
32 class FocusNotificationObserver
: public aura::client::ActivationChangeObserver
,
33 public aura::client::FocusChangeObserver
{
35 FocusNotificationObserver()
36 : activation_changed_count_(0),
37 focus_changed_count_(0),
38 reactivation_count_(0),
39 reactivation_requested_window_(NULL
),
40 reactivation_actual_window_(NULL
) {}
41 ~FocusNotificationObserver() override
{}
43 void ExpectCounts(int activation_changed_count
, int focus_changed_count
) {
44 EXPECT_EQ(activation_changed_count
, activation_changed_count_
);
45 EXPECT_EQ(focus_changed_count
, focus_changed_count_
);
47 int reactivation_count() const {
48 return reactivation_count_
;
50 aura::Window
* reactivation_requested_window() const {
51 return reactivation_requested_window_
;
53 aura::Window
* reactivation_actual_window() const {
54 return reactivation_actual_window_
;
58 // Overridden from aura::client::ActivationChangeObserver:
59 void OnWindowActivated(aura::Window
* gained_active
,
60 aura::Window
* lost_active
) override
{
61 ++activation_changed_count_
;
63 void OnAttemptToReactivateWindow(aura::Window
* request_active
,
64 aura::Window
* actual_active
) override
{
65 ++reactivation_count_
;
66 reactivation_requested_window_
= request_active
;
67 reactivation_actual_window_
= actual_active
;
70 // Overridden from aura::client::FocusChangeObserver:
71 void OnWindowFocused(aura::Window
* gained_focus
,
72 aura::Window
* lost_focus
) override
{
73 ++focus_changed_count_
;
76 int activation_changed_count_
;
77 int focus_changed_count_
;
78 int reactivation_count_
;
79 aura::Window
* reactivation_requested_window_
;
80 aura::Window
* reactivation_actual_window_
;
82 DISALLOW_COPY_AND_ASSIGN(FocusNotificationObserver
);
87 virtual aura::Window
* GetDeletedWindow() = 0;
90 virtual ~WindowDeleter() {}
93 // ActivationChangeObserver and FocusChangeObserver that keeps track of whether
94 // it was notified about activation changes or focus changes with a deleted
96 class RecordingActivationAndFocusChangeObserver
97 : public aura::client::ActivationChangeObserver
,
98 public aura::client::FocusChangeObserver
{
100 RecordingActivationAndFocusChangeObserver(aura::Window
* root
,
101 WindowDeleter
* deleter
)
104 was_notified_with_deleted_window_(false) {
105 aura::client::GetActivationClient(root_
)->AddObserver(this);
106 aura::client::GetFocusClient(root_
)->AddObserver(this);
108 ~RecordingActivationAndFocusChangeObserver() override
{
109 aura::client::GetActivationClient(root_
)->RemoveObserver(this);
110 aura::client::GetFocusClient(root_
)->RemoveObserver(this);
113 bool was_notified_with_deleted_window() const {
114 return was_notified_with_deleted_window_
;
117 // Overridden from aura::client::ActivationChangeObserver:
118 void OnWindowActivated(aura::Window
* gained_active
,
119 aura::Window
* lost_active
) override
{
120 if (lost_active
&& lost_active
== deleter_
->GetDeletedWindow())
121 was_notified_with_deleted_window_
= true;
124 // Overridden from aura::client::FocusChangeObserver:
125 void OnWindowFocused(aura::Window
* gained_focus
,
126 aura::Window
* lost_focus
) override
{
127 if (lost_focus
&& lost_focus
== deleter_
->GetDeletedWindow())
128 was_notified_with_deleted_window_
= true;
135 WindowDeleter
* deleter_
;
137 // Whether the observer was notified about the loss of activation or the
138 // loss of focus with a window already deleted by |deleter_| as the
139 // |lost_active| or |lost_focus| parameter.
140 bool was_notified_with_deleted_window_
;
142 DISALLOW_COPY_AND_ASSIGN(RecordingActivationAndFocusChangeObserver
);
145 // ActivationChangeObserver that deletes the window losing activation.
146 class DeleteOnLoseActivationChangeObserver
:
147 public aura::client::ActivationChangeObserver
,
148 public WindowDeleter
{
150 explicit DeleteOnLoseActivationChangeObserver(aura::Window
* window
)
151 : root_(window
->GetRootWindow()),
154 aura::client::GetActivationClient(root_
)->AddObserver(this);
156 ~DeleteOnLoseActivationChangeObserver() override
{
157 aura::client::GetActivationClient(root_
)->RemoveObserver(this);
160 // Overridden from aura::client::ActivationChangeObserver:
161 void OnWindowActivated(aura::Window
* gained_active
,
162 aura::Window
* lost_active
) override
{
163 if (window_
&& lost_active
== window_
) {
169 // Overridden from WindowDeleter:
170 aura::Window
* GetDeletedWindow() override
{
171 return did_delete_
? window_
: NULL
;
176 aura::Window
* window_
;
179 DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseActivationChangeObserver
);
182 // FocusChangeObserver that deletes the window losing focus.
183 class DeleteOnLoseFocusChangeObserver
184 : public aura::client::FocusChangeObserver
,
185 public WindowDeleter
{
187 explicit DeleteOnLoseFocusChangeObserver(aura::Window
* window
)
188 : root_(window
->GetRootWindow()),
191 aura::client::GetFocusClient(root_
)->AddObserver(this);
193 ~DeleteOnLoseFocusChangeObserver() override
{
194 aura::client::GetFocusClient(root_
)->RemoveObserver(this);
197 // Overridden from aura::client::FocusChangeObserver:
198 void OnWindowFocused(aura::Window
* gained_focus
,
199 aura::Window
* lost_focus
) override
{
200 if (window_
&& lost_focus
== window_
) {
206 // Overridden from WindowDeleter:
207 aura::Window
* GetDeletedWindow() override
{
208 return did_delete_
? window_
: NULL
;
213 aura::Window
* window_
;
216 DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseFocusChangeObserver
);
219 class ScopedFocusNotificationObserver
: public FocusNotificationObserver
{
221 ScopedFocusNotificationObserver(aura::Window
* root_window
)
222 : root_window_(root_window
) {
223 aura::client::GetActivationClient(root_window_
)->AddObserver(this);
224 aura::client::GetFocusClient(root_window_
)->AddObserver(this);
226 ~ScopedFocusNotificationObserver() override
{
227 aura::client::GetActivationClient(root_window_
)->RemoveObserver(this);
228 aura::client::GetFocusClient(root_window_
)->RemoveObserver(this);
232 aura::Window
* root_window_
;
234 DISALLOW_COPY_AND_ASSIGN(ScopedFocusNotificationObserver
);
237 class ScopedTargetFocusNotificationObserver
: public FocusNotificationObserver
{
239 ScopedTargetFocusNotificationObserver(aura::Window
* root_window
, int id
)
240 : target_(root_window
->GetChildById(id
)) {
241 aura::client::SetActivationChangeObserver(target_
, this);
242 aura::client::SetFocusChangeObserver(target_
, this);
243 tracker_
.Add(target_
);
245 ~ScopedTargetFocusNotificationObserver() override
{
246 if (tracker_
.Contains(target_
)) {
247 aura::client::SetActivationChangeObserver(target_
, NULL
);
248 aura::client::SetFocusChangeObserver(target_
, NULL
);
253 aura::Window
* target_
;
254 aura::WindowTracker tracker_
;
256 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver
);
259 class ScopedFocusedTextInputClientChanger
260 : public ScopedFocusNotificationObserver
{
262 ScopedFocusedTextInputClientChanger(aura::Window
* root_window
,
263 ui::TextInputClient
* text_input_client
)
264 : ScopedFocusNotificationObserver(root_window
),
265 text_input_client_(text_input_client
) {}
268 // Overridden from aura::client::FocusChangeObserver:
269 void OnWindowFocused(aura::Window
* gained_focus
,
270 aura::Window
* lost_focus
) override
{
271 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(
275 ui::TextInputClient
* text_input_client_
;
278 // Used to fake the handling of events in the pre-target phase.
279 class SimpleEventHandler
: public ui::EventHandler
{
281 SimpleEventHandler() {}
282 ~SimpleEventHandler() override
{}
284 // Overridden from ui::EventHandler:
285 void OnMouseEvent(ui::MouseEvent
* event
) override
{ event
->SetHandled(); }
286 void OnGestureEvent(ui::GestureEvent
* event
) override
{ event
->SetHandled(); }
289 DISALLOW_COPY_AND_ASSIGN(SimpleEventHandler
);
292 class FocusShiftingActivationObserver
293 : public aura::client::ActivationChangeObserver
{
295 explicit FocusShiftingActivationObserver(aura::Window
* activated_window
)
296 : activated_window_(activated_window
),
297 shift_focus_to_(NULL
) {}
298 ~FocusShiftingActivationObserver() override
{}
300 void set_shift_focus_to(aura::Window
* shift_focus_to
) {
301 shift_focus_to_
= shift_focus_to
;
305 // Overridden from aura::client::ActivationChangeObserver:
306 void OnWindowActivated(aura::Window
* gained_active
,
307 aura::Window
* lost_active
) override
{
308 // Shift focus to a child. This should prevent the default focusing from
309 // occurring in FocusController::FocusWindow().
310 if (gained_active
== activated_window_
) {
311 aura::client::FocusClient
* client
=
312 aura::client::GetFocusClient(gained_active
);
313 client
->FocusWindow(shift_focus_to_
);
317 aura::Window
* activated_window_
;
318 aura::Window
* shift_focus_to_
;
320 DISALLOW_COPY_AND_ASSIGN(FocusShiftingActivationObserver
);
323 // BaseFocusRules subclass that allows basic overrides of focus/activation to
324 // be tested. This is intended more as a test that the override system works at
325 // all, rather than as an exhaustive set of use cases, those should be covered
326 // in tests for those FocusRules implementations.
327 class TestFocusRules
: public BaseFocusRules
{
329 TestFocusRules() : focus_restriction_(NULL
) {}
331 // Restricts focus and activation to this window and its child hierarchy.
332 void set_focus_restriction(aura::Window
* focus_restriction
) {
333 focus_restriction_
= focus_restriction
;
336 // Overridden from BaseFocusRules:
337 bool SupportsChildActivation(aura::Window
* window
) const override
{
338 // In FocusControllerTests, only the RootWindow has activatable children.
339 return window
->GetRootWindow() == window
;
341 bool CanActivateWindow(aura::Window
* window
) const override
{
342 // Restricting focus to a non-activatable child window means the activatable
343 // parent outside the focus restriction is activatable.
345 CanFocusOrActivate(window
) || window
->Contains(focus_restriction_
);
346 return can_activate
? BaseFocusRules::CanActivateWindow(window
) : false;
348 bool CanFocusWindow(aura::Window
* window
) const override
{
349 return CanFocusOrActivate(window
) ?
350 BaseFocusRules::CanFocusWindow(window
) : false;
352 aura::Window
* GetActivatableWindow(aura::Window
* window
) const override
{
353 return BaseFocusRules::GetActivatableWindow(
354 CanFocusOrActivate(window
) ? window
: focus_restriction_
);
356 aura::Window
* GetFocusableWindow(aura::Window
* window
) const override
{
357 return BaseFocusRules::GetFocusableWindow(
358 CanFocusOrActivate(window
) ? window
: focus_restriction_
);
360 aura::Window
* GetNextActivatableWindow(aura::Window
* ignore
) const override
{
361 aura::Window
* next_activatable
=
362 BaseFocusRules::GetNextActivatableWindow(ignore
);
363 return CanFocusOrActivate(next_activatable
) ?
364 next_activatable
: GetActivatableWindow(focus_restriction_
);
368 bool CanFocusOrActivate(aura::Window
* window
) const {
369 return !focus_restriction_
|| focus_restriction_
->Contains(window
);
372 aura::Window
* focus_restriction_
;
374 DISALLOW_COPY_AND_ASSIGN(TestFocusRules
);
377 // Common infrastructure shared by all FocusController test types.
378 class FocusControllerTestBase
: public aura::test::AuraTestBase
{
380 FocusControllerTestBase() {}
382 // Overridden from aura::test::AuraTestBase:
383 void SetUp() override
{
384 wm_state_
.reset(new wm::WMState
);
385 // FocusController registers itself as an Env observer so it can catch all
386 // window initializations, including the root_window()'s, so we create it
387 // before allowing the base setup.
388 test_focus_rules_
= new TestFocusRules
;
389 focus_controller_
.reset(new FocusController(test_focus_rules_
));
390 aura::test::AuraTestBase::SetUp();
391 root_window()->AddPreTargetHandler(focus_controller_
.get());
392 aura::client::SetFocusClient(root_window(), focus_controller_
.get());
393 aura::client::SetActivationClient(root_window(), focus_controller_
.get());
395 // Hierarchy used by all tests:
404 aura::Window
* w1
= aura::test::CreateTestWindowWithDelegate(
405 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 1,
406 gfx::Rect(0, 0, 50, 50), root_window());
407 aura::test::CreateTestWindowWithDelegate(
408 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 11,
409 gfx::Rect(5, 5, 10, 10), w1
);
410 aura::test::CreateTestWindowWithDelegate(
411 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 12,
412 gfx::Rect(15, 15, 10, 10), w1
);
413 aura::Window
* w2
= aura::test::CreateTestWindowWithDelegate(
414 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 2,
415 gfx::Rect(75, 75, 50, 50), root_window());
416 aura::Window
* w21
= aura::test::CreateTestWindowWithDelegate(
417 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 21,
418 gfx::Rect(5, 5, 10, 10), w2
);
419 aura::test::CreateTestWindowWithDelegate(
420 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 211,
421 gfx::Rect(1, 1, 5, 5), w21
);
422 aura::test::CreateTestWindowWithDelegate(
423 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3,
424 gfx::Rect(125, 125, 50, 50), root_window());
426 void TearDown() override
{
427 root_window()->RemovePreTargetHandler(focus_controller_
.get());
428 aura::test::AuraTestBase::TearDown();
429 test_focus_rules_
= NULL
; // Owned by FocusController.
430 focus_controller_
.reset();
434 void FocusWindow(aura::Window
* window
) {
435 aura::client::GetFocusClient(root_window())->FocusWindow(window
);
437 aura::Window
* GetFocusedWindow() {
438 return aura::client::GetFocusClient(root_window())->GetFocusedWindow();
440 int GetFocusedWindowId() {
441 aura::Window
* focused_window
= GetFocusedWindow();
442 return focused_window
? focused_window
->id() : -1;
444 void ActivateWindow(aura::Window
* window
) {
445 aura::client::GetActivationClient(root_window())->ActivateWindow(window
);
447 void DeactivateWindow(aura::Window
* window
) {
448 aura::client::GetActivationClient(root_window())->DeactivateWindow(window
);
450 aura::Window
* GetActiveWindow() {
451 return aura::client::GetActivationClient(root_window())->GetActiveWindow();
453 int GetActiveWindowId() {
454 aura::Window
* active_window
= GetActiveWindow();
455 return active_window
? active_window
->id() : -1;
458 TestFocusRules
* test_focus_rules() { return test_focus_rules_
; }
461 virtual void BasicFocus() = 0;
462 virtual void BasicActivation() = 0;
463 virtual void FocusEvents() = 0;
464 virtual void DuplicateFocusEvents() {}
465 virtual void ActivationEvents() = 0;
466 virtual void ReactivationEvents() {}
467 virtual void DuplicateActivationEvents() {}
468 virtual void ShiftFocusWithinActiveWindow() {}
469 virtual void ShiftFocusToChildOfInactiveWindow() {}
470 virtual void ShiftFocusToParentOfFocusedWindow() {}
471 virtual void FocusRulesOverride() = 0;
472 virtual void ActivationRulesOverride() = 0;
473 virtual void ShiftFocusOnActivation() {}
474 virtual void ShiftFocusOnActivationDueToHide() {}
475 virtual void NoShiftActiveOnActivation() {}
476 virtual void FocusChangeDuringDrag() {}
477 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {}
478 virtual void DontPassDeletedWindow() {}
479 virtual void FocusedTextInputClient() {}
482 scoped_ptr
<FocusController
> focus_controller_
;
483 TestFocusRules
* test_focus_rules_
;
484 scoped_ptr
<wm::WMState
> wm_state_
;
486 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase
);
489 // Test base for tests where focus is directly set to a target window.
490 class FocusControllerDirectTestBase
: public FocusControllerTestBase
{
492 FocusControllerDirectTestBase() {}
494 // Different test types shift focus in different ways.
495 virtual void FocusWindowDirect(aura::Window
* window
) = 0;
496 virtual void ActivateWindowDirect(aura::Window
* window
) = 0;
497 virtual void DeactivateWindowDirect(aura::Window
* window
) = 0;
499 // Input events do not change focus if the window can not be focused.
500 virtual bool IsInputEvent() = 0;
502 void FocusWindowById(int id
) {
503 aura::Window
* window
= root_window()->GetChildById(id
);
505 FocusWindowDirect(window
);
507 void ActivateWindowById(int id
) {
508 aura::Window
* window
= root_window()->GetChildById(id
);
510 ActivateWindowDirect(window
);
513 // Overridden from FocusControllerTestBase:
514 void BasicFocus() override
{
515 EXPECT_EQ(NULL
, GetFocusedWindow());
517 EXPECT_EQ(1, GetFocusedWindowId());
519 EXPECT_EQ(2, GetFocusedWindowId());
521 void BasicActivation() override
{
522 EXPECT_EQ(NULL
, GetActiveWindow());
523 ActivateWindowById(1);
524 EXPECT_EQ(1, GetActiveWindowId());
525 ActivateWindowById(2);
526 EXPECT_EQ(2, GetActiveWindowId());
527 // Verify that attempting to deactivate NULL does not crash and does not
528 // change activation.
529 DeactivateWindow(NULL
);
530 EXPECT_EQ(2, GetActiveWindowId());
531 DeactivateWindow(GetActiveWindow());
532 EXPECT_EQ(1, GetActiveWindowId());
534 void FocusEvents() override
{
535 ScopedFocusNotificationObserver
root_observer(root_window());
536 ScopedTargetFocusNotificationObserver
observer1(root_window(), 1);
537 ScopedTargetFocusNotificationObserver
observer2(root_window(), 2);
539 root_observer
.ExpectCounts(0, 0);
540 observer1
.ExpectCounts(0, 0);
541 observer2
.ExpectCounts(0, 0);
544 root_observer
.ExpectCounts(1, 1);
545 observer1
.ExpectCounts(1, 1);
546 observer2
.ExpectCounts(0, 0);
549 root_observer
.ExpectCounts(2, 2);
550 observer1
.ExpectCounts(2, 2);
551 observer2
.ExpectCounts(1, 1);
553 void DuplicateFocusEvents() override
{
554 // Focusing an existing focused window should not resend focus events.
555 ScopedFocusNotificationObserver
root_observer(root_window());
556 ScopedTargetFocusNotificationObserver
observer1(root_window(), 1);
558 root_observer
.ExpectCounts(0, 0);
559 observer1
.ExpectCounts(0, 0);
562 root_observer
.ExpectCounts(1, 1);
563 observer1
.ExpectCounts(1, 1);
566 root_observer
.ExpectCounts(1, 1);
567 observer1
.ExpectCounts(1, 1);
569 void ActivationEvents() override
{
570 ActivateWindowById(1);
572 ScopedFocusNotificationObserver
root_observer(root_window());
573 ScopedTargetFocusNotificationObserver
observer1(root_window(), 1);
574 ScopedTargetFocusNotificationObserver
observer2(root_window(), 2);
576 root_observer
.ExpectCounts(0, 0);
577 observer1
.ExpectCounts(0, 0);
578 observer2
.ExpectCounts(0, 0);
580 ActivateWindowById(2);
581 root_observer
.ExpectCounts(1, 1);
582 observer1
.ExpectCounts(1, 1);
583 observer2
.ExpectCounts(1, 1);
585 void ReactivationEvents() override
{
586 ActivateWindowById(1);
587 ScopedFocusNotificationObserver
root_observer(root_window());
588 EXPECT_EQ(0, root_observer
.reactivation_count());
589 root_window()->GetChildById(2)->Hide();
590 // When we attempt to activate "2", which cannot be activated because it
591 // is not visible, "1" will be reactivated.
592 ActivateWindowById(2);
593 EXPECT_EQ(1, root_observer
.reactivation_count());
594 EXPECT_EQ(root_window()->GetChildById(2),
595 root_observer
.reactivation_requested_window());
596 EXPECT_EQ(root_window()->GetChildById(1),
597 root_observer
.reactivation_actual_window());
599 void DuplicateActivationEvents() override
{
600 // Activating an existing active window should not resend activation events.
601 ActivateWindowById(1);
603 ScopedFocusNotificationObserver
root_observer(root_window());
604 ScopedTargetFocusNotificationObserver
observer1(root_window(), 1);
605 ScopedTargetFocusNotificationObserver
observer2(root_window(), 2);
607 root_observer
.ExpectCounts(0, 0);
608 observer1
.ExpectCounts(0, 0);
609 observer2
.ExpectCounts(0, 0);
611 ActivateWindowById(2);
612 root_observer
.ExpectCounts(1, 1);
613 observer1
.ExpectCounts(1, 1);
614 observer2
.ExpectCounts(1, 1);
616 ActivateWindowById(2);
617 root_observer
.ExpectCounts(1, 1);
618 observer1
.ExpectCounts(1, 1);
619 observer2
.ExpectCounts(1, 1);
621 void ShiftFocusWithinActiveWindow() override
{
622 ActivateWindowById(1);
623 EXPECT_EQ(1, GetActiveWindowId());
624 EXPECT_EQ(1, GetFocusedWindowId());
626 EXPECT_EQ(11, GetFocusedWindowId());
628 EXPECT_EQ(12, GetFocusedWindowId());
630 void ShiftFocusToChildOfInactiveWindow() override
{
631 ActivateWindowById(2);
632 EXPECT_EQ(2, GetActiveWindowId());
633 EXPECT_EQ(2, GetFocusedWindowId());
635 EXPECT_EQ(1, GetActiveWindowId());
636 EXPECT_EQ(11, GetFocusedWindowId());
638 void ShiftFocusToParentOfFocusedWindow() override
{
639 ActivateWindowById(1);
640 EXPECT_EQ(1, GetFocusedWindowId());
642 EXPECT_EQ(11, GetFocusedWindowId());
644 // Focus should _not_ shift to the parent of the already-focused window.
645 EXPECT_EQ(11, GetFocusedWindowId());
647 void FocusRulesOverride() override
{
648 EXPECT_EQ(NULL
, GetFocusedWindow());
650 EXPECT_EQ(11, GetFocusedWindowId());
652 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(211));
654 // Input events leave focus unchanged; direct API calls will change focus
655 // to the restricted window.
656 int focused_window
= IsInputEvent() ? 11 : 211;
657 EXPECT_EQ(focused_window
, GetFocusedWindowId());
659 test_focus_rules()->set_focus_restriction(NULL
);
661 EXPECT_EQ(12, GetFocusedWindowId());
663 void ActivationRulesOverride() override
{
664 ActivateWindowById(1);
665 EXPECT_EQ(1, GetActiveWindowId());
666 EXPECT_EQ(1, GetFocusedWindowId());
668 aura::Window
* w3
= root_window()->GetChildById(3);
669 test_focus_rules()->set_focus_restriction(w3
);
671 ActivateWindowById(2);
672 // Input events leave activation unchanged; direct API calls will activate
673 // the restricted window.
674 int active_window
= IsInputEvent() ? 1 : 3;
675 EXPECT_EQ(active_window
, GetActiveWindowId());
676 EXPECT_EQ(active_window
, GetFocusedWindowId());
678 test_focus_rules()->set_focus_restriction(NULL
);
679 ActivateWindowById(2);
680 EXPECT_EQ(2, GetActiveWindowId());
681 EXPECT_EQ(2, GetFocusedWindowId());
683 void ShiftFocusOnActivation() override
{
684 // When a window is activated, by default that window is also focused.
685 // An ActivationChangeObserver may shift focus to another window within the
686 // same activatable window.
687 ActivateWindowById(2);
688 EXPECT_EQ(2, GetFocusedWindowId());
689 ActivateWindowById(1);
690 EXPECT_EQ(1, GetFocusedWindowId());
692 ActivateWindowById(2);
694 aura::Window
* target
= root_window()->GetChildById(1);
695 aura::client::ActivationClient
* client
=
696 aura::client::GetActivationClient(root_window());
698 scoped_ptr
<FocusShiftingActivationObserver
> observer(
699 new FocusShiftingActivationObserver(target
));
700 observer
->set_shift_focus_to(target
->GetChildById(11));
701 client
->AddObserver(observer
.get());
703 ActivateWindowById(1);
705 // w1's ActivationChangeObserver shifted focus to this child, pre-empting
706 // FocusController's default setting.
707 EXPECT_EQ(11, GetFocusedWindowId());
709 ActivateWindowById(2);
710 EXPECT_EQ(2, GetFocusedWindowId());
712 // Simulate a focus reset by the ActivationChangeObserver. This should
713 // trigger the default setting in FocusController.
714 observer
->set_shift_focus_to(NULL
);
715 ActivateWindowById(1);
716 EXPECT_EQ(1, GetFocusedWindowId());
718 client
->RemoveObserver(observer
.get());
720 ActivateWindowById(2);
721 EXPECT_EQ(2, GetFocusedWindowId());
722 ActivateWindowById(1);
723 EXPECT_EQ(1, GetFocusedWindowId());
725 void ShiftFocusOnActivationDueToHide() override
{
726 // Similar to ShiftFocusOnActivation except the activation change is
727 // triggered by hiding the active window.
728 ActivateWindowById(1);
729 EXPECT_EQ(1, GetFocusedWindowId());
731 // Removes window 3 as candidate for next activatable window.
732 root_window()->GetChildById(3)->Hide();
733 EXPECT_EQ(1, GetFocusedWindowId());
735 aura::Window
* target
= root_window()->GetChildById(2);
736 aura::client::ActivationClient
* client
=
737 aura::client::GetActivationClient(root_window());
739 scoped_ptr
<FocusShiftingActivationObserver
> observer(
740 new FocusShiftingActivationObserver(target
));
741 observer
->set_shift_focus_to(target
->GetChildById(21));
742 client
->AddObserver(observer
.get());
744 // Hide the active window.
745 root_window()->GetChildById(1)->Hide();
747 EXPECT_EQ(21, GetFocusedWindowId());
749 client
->RemoveObserver(observer
.get());
751 void NoShiftActiveOnActivation() override
{
752 // When a window is activated, we need to prevent any change to activation
753 // from being made in response to an activation change notification.
756 void FocusChangeDuringDrag() override
{
757 scoped_ptr
<aura::client::DefaultCaptureClient
> capture_client(
758 new aura::client::DefaultCaptureClient(root_window()));
759 // Activating an inactive window during drag should activate the window.
760 // This emulates the behavior of tab dragging which is merged into the
762 ActivateWindowById(1);
764 EXPECT_EQ(1, GetActiveWindowId());
765 EXPECT_EQ(1, GetFocusedWindowId());
767 aura::Window
* w2
= root_window()->GetChildById(2);
768 ui::test::EventGenerator
generator(root_window(), w2
);
769 generator
.PressLeftButton();
770 aura::client::GetCaptureClient(root_window())->SetCapture(w2
);
771 EXPECT_EQ(2, GetActiveWindowId());
772 EXPECT_EQ(2, GetFocusedWindowId());
773 generator
.MoveMouseTo(gfx::Point(0, 0));
775 // Emulate the behavior of merging a tab into an inactive window:
776 // transferring the mouse capture and activate the window.
777 aura::Window
* w1
= root_window()->GetChildById(1);
778 aura::client::GetCaptureClient(root_window())->SetCapture(w1
);
779 aura::client::GetActivationClient(root_window())->ActivateWindow(w1
);
780 EXPECT_EQ(1, GetActiveWindowId());
781 EXPECT_EQ(1, GetFocusedWindowId());
783 generator
.ReleaseLeftButton();
784 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1
);
787 // Verifies focus change is honored while capture held.
788 void ChangeFocusWhenNothingFocusedAndCaptured() override
{
789 scoped_ptr
<aura::client::DefaultCaptureClient
> capture_client(
790 new aura::client::DefaultCaptureClient(root_window()));
791 aura::Window
* w1
= root_window()->GetChildById(1);
792 aura::client::GetCaptureClient(root_window())->SetCapture(w1
);
794 EXPECT_EQ(-1, GetActiveWindowId());
795 EXPECT_EQ(-1, GetFocusedWindowId());
799 EXPECT_EQ(1, GetActiveWindowId());
800 EXPECT_EQ(1, GetFocusedWindowId());
802 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1
);
805 // Verifies if a window that loses activation or focus is deleted during
806 // observer notification we don't pass the deleted window to other observers.
807 void DontPassDeletedWindow() override
{
810 EXPECT_EQ(1, GetActiveWindowId());
811 EXPECT_EQ(1, GetFocusedWindowId());
814 aura::Window
* to_delete
= root_window()->GetChildById(1);
815 DeleteOnLoseActivationChangeObserver
observer1(to_delete
);
816 RecordingActivationAndFocusChangeObserver
observer2(root_window(),
821 EXPECT_EQ(2, GetActiveWindowId());
822 EXPECT_EQ(2, GetFocusedWindowId());
824 EXPECT_EQ(to_delete
, observer1
.GetDeletedWindow());
825 EXPECT_FALSE(observer2
.was_notified_with_deleted_window());
829 aura::Window
* to_delete
= root_window()->GetChildById(2);
830 DeleteOnLoseFocusChangeObserver
observer1(to_delete
);
831 RecordingActivationAndFocusChangeObserver
observer2(root_window(),
836 EXPECT_EQ(3, GetActiveWindowId());
837 EXPECT_EQ(3, GetFocusedWindowId());
839 EXPECT_EQ(to_delete
, observer1
.GetDeletedWindow());
840 EXPECT_FALSE(observer2
.was_notified_with_deleted_window());
844 // Verifies if the focused text input client is cleared when a window gains
845 // or loses the focus.
846 void FocusedTextInputClient() override
{
847 ui::TextInputFocusManager
* text_input_focus_manager
=
848 ui::TextInputFocusManager::GetInstance();
849 ui::DummyTextInputClient text_input_client
;
850 ui::TextInputClient
* null_text_input_client
= NULL
;
852 EXPECT_EQ(null_text_input_client
,
853 text_input_focus_manager
->GetFocusedTextInputClient());
855 text_input_focus_manager
->FocusTextInputClient(&text_input_client
);
856 EXPECT_EQ(&text_input_client
,
857 text_input_focus_manager
->GetFocusedTextInputClient());
859 // The focused text input client gets cleared when a window gets focused
860 // unless any of observers sets the focused text input client.
861 EXPECT_EQ(null_text_input_client
,
862 text_input_focus_manager
->GetFocusedTextInputClient());
864 ScopedFocusedTextInputClientChanger
text_input_focus_changer(
865 root_window(), &text_input_client
);
866 EXPECT_EQ(null_text_input_client
,
867 text_input_focus_manager
->GetFocusedTextInputClient());
869 // |text_input_focus_changer| sets the focused text input client.
870 EXPECT_EQ(&text_input_client
,
871 text_input_focus_manager
->GetFocusedTextInputClient());
874 // The focused text input client gets cleared when a window loses the focus.
875 EXPECT_EQ(null_text_input_client
,
876 text_input_focus_manager
->GetFocusedTextInputClient());
880 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase
);
883 // Focus and Activation changes via aura::client::ActivationClient API.
884 class FocusControllerApiTest
: public FocusControllerDirectTestBase
{
886 FocusControllerApiTest() {}
889 // Overridden from FocusControllerTestBase:
890 void FocusWindowDirect(aura::Window
* window
) override
{ FocusWindow(window
); }
891 void ActivateWindowDirect(aura::Window
* window
) override
{
892 ActivateWindow(window
);
894 void DeactivateWindowDirect(aura::Window
* window
) override
{
895 DeactivateWindow(window
);
897 bool IsInputEvent() override
{ return false; }
899 DISALLOW_COPY_AND_ASSIGN(FocusControllerApiTest
);
902 // Focus and Activation changes via input events.
903 class FocusControllerMouseEventTest
: public FocusControllerDirectTestBase
{
905 FocusControllerMouseEventTest() {}
907 // Tests that a handled mouse or gesture event does not trigger a window
909 void IgnoreHandledEvent() {
910 EXPECT_EQ(NULL
, GetActiveWindow());
911 aura::Window
* w1
= root_window()->GetChildById(1);
912 SimpleEventHandler handler
;
913 root_window()->PrependPreTargetHandler(&handler
);
914 ui::test::EventGenerator
generator(root_window(), w1
);
915 generator
.ClickLeftButton();
916 EXPECT_EQ(NULL
, GetActiveWindow());
917 generator
.GestureTapAt(w1
->bounds().CenterPoint());
918 EXPECT_EQ(NULL
, GetActiveWindow());
919 root_window()->RemovePreTargetHandler(&handler
);
920 generator
.ClickLeftButton();
921 EXPECT_EQ(1, GetActiveWindowId());
925 // Overridden from FocusControllerTestBase:
926 void FocusWindowDirect(aura::Window
* window
) override
{
927 ui::test::EventGenerator
generator(root_window(), window
);
928 generator
.ClickLeftButton();
930 void ActivateWindowDirect(aura::Window
* window
) override
{
931 ui::test::EventGenerator
generator(root_window(), window
);
932 generator
.ClickLeftButton();
934 void DeactivateWindowDirect(aura::Window
* window
) override
{
935 aura::Window
* next_activatable
=
936 test_focus_rules()->GetNextActivatableWindow(window
);
937 ui::test::EventGenerator
generator(root_window(), next_activatable
);
938 generator
.ClickLeftButton();
940 bool IsInputEvent() override
{ return true; }
942 DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest
);
945 class FocusControllerGestureEventTest
: public FocusControllerDirectTestBase
{
947 FocusControllerGestureEventTest() {}
950 // Overridden from FocusControllerTestBase:
951 void FocusWindowDirect(aura::Window
* window
) override
{
952 ui::test::EventGenerator
generator(root_window(), window
);
953 generator
.GestureTapAt(window
->bounds().CenterPoint());
955 void ActivateWindowDirect(aura::Window
* window
) override
{
956 ui::test::EventGenerator
generator(root_window(), window
);
957 generator
.GestureTapAt(window
->bounds().CenterPoint());
959 void DeactivateWindowDirect(aura::Window
* window
) override
{
960 aura::Window
* next_activatable
=
961 test_focus_rules()->GetNextActivatableWindow(window
);
962 ui::test::EventGenerator
generator(root_window(), next_activatable
);
963 generator
.GestureTapAt(window
->bounds().CenterPoint());
965 bool IsInputEvent() override
{ return true; }
967 DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest
);
970 // Test base for tests where focus is implicitly set to a window as the result
971 // of a disposition change to the focused window or the hierarchy that contains
973 class FocusControllerImplicitTestBase
: public FocusControllerTestBase
{
975 explicit FocusControllerImplicitTestBase(bool parent
) : parent_(parent
) {}
977 aura::Window
* GetDispositionWindow(aura::Window
* window
) {
978 return parent_
? window
->parent() : window
;
981 // Change the disposition of |window| in such a way as it will lose focus.
982 virtual void ChangeWindowDisposition(aura::Window
* window
) = 0;
984 // Allow each disposition change test to add additional post-disposition
985 // change expectations.
986 virtual void PostDispositionChangeExpectations() {}
988 // Overridden from FocusControllerTestBase:
989 void BasicFocus() override
{
990 EXPECT_EQ(NULL
, GetFocusedWindow());
992 aura::Window
* w211
= root_window()->GetChildById(211);
994 EXPECT_EQ(211, GetFocusedWindowId());
996 ChangeWindowDisposition(w211
);
997 // BasicFocusRules passes focus to the parent.
998 EXPECT_EQ(parent_
? 2 : 21, GetFocusedWindowId());
1000 void BasicActivation() override
{
1001 DCHECK(!parent_
) << "Activation tests don't support parent changes.";
1003 EXPECT_EQ(NULL
, GetActiveWindow());
1005 aura::Window
* w2
= root_window()->GetChildById(2);
1007 EXPECT_EQ(2, GetActiveWindowId());
1009 ChangeWindowDisposition(w2
);
1010 EXPECT_EQ(3, GetActiveWindowId());
1011 PostDispositionChangeExpectations();
1013 void FocusEvents() override
{
1014 aura::Window
* w211
= root_window()->GetChildById(211);
1017 ScopedFocusNotificationObserver
root_observer(root_window());
1018 ScopedTargetFocusNotificationObserver
observer211(root_window(), 211);
1019 root_observer
.ExpectCounts(0, 0);
1020 observer211
.ExpectCounts(0, 0);
1022 ChangeWindowDisposition(w211
);
1023 root_observer
.ExpectCounts(0, 1);
1024 observer211
.ExpectCounts(0, 1);
1026 void ActivationEvents() override
{
1027 DCHECK(!parent_
) << "Activation tests don't support parent changes.";
1029 aura::Window
* w2
= root_window()->GetChildById(2);
1032 ScopedFocusNotificationObserver
root_observer(root_window());
1033 ScopedTargetFocusNotificationObserver
observer2(root_window(), 2);
1034 ScopedTargetFocusNotificationObserver
observer3(root_window(), 3);
1035 root_observer
.ExpectCounts(0, 0);
1036 observer2
.ExpectCounts(0, 0);
1037 observer3
.ExpectCounts(0, 0);
1039 ChangeWindowDisposition(w2
);
1040 root_observer
.ExpectCounts(1, 1);
1041 observer2
.ExpectCounts(1, 1);
1042 observer3
.ExpectCounts(1, 1);
1044 void FocusRulesOverride() override
{
1045 EXPECT_EQ(NULL
, GetFocusedWindow());
1046 aura::Window
* w211
= root_window()->GetChildById(211);
1048 EXPECT_EQ(211, GetFocusedWindowId());
1050 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(11));
1051 ChangeWindowDisposition(w211
);
1052 // Normally, focus would shift to the parent (w21) but the override shifts
1054 EXPECT_EQ(11, GetFocusedWindowId());
1056 test_focus_rules()->set_focus_restriction(NULL
);
1058 void ActivationRulesOverride() override
{
1059 DCHECK(!parent_
) << "Activation tests don't support parent changes.";
1061 aura::Window
* w1
= root_window()->GetChildById(1);
1064 EXPECT_EQ(1, GetActiveWindowId());
1065 EXPECT_EQ(1, GetFocusedWindowId());
1067 aura::Window
* w3
= root_window()->GetChildById(3);
1068 test_focus_rules()->set_focus_restriction(w3
);
1070 // Normally, activation/focus would move to w2, but since we have a focus
1071 // restriction, it should move to w3 instead.
1072 ChangeWindowDisposition(w1
);
1073 EXPECT_EQ(3, GetActiveWindowId());
1074 EXPECT_EQ(3, GetFocusedWindowId());
1076 test_focus_rules()->set_focus_restriction(NULL
);
1077 ActivateWindow(root_window()->GetChildById(2));
1078 EXPECT_EQ(2, GetActiveWindowId());
1079 EXPECT_EQ(2, GetFocusedWindowId());
1083 // When true, the disposition change occurs to the parent of the window
1084 // instead of to the window. This verifies that changes occurring in the
1085 // hierarchy that contains the window affect the window's focus.
1088 DISALLOW_COPY_AND_ASSIGN(FocusControllerImplicitTestBase
);
1091 // Focus and Activation changes in response to window visibility changes.
1092 class FocusControllerHideTest
: public FocusControllerImplicitTestBase
{
1094 FocusControllerHideTest() : FocusControllerImplicitTestBase(false) {}
1097 FocusControllerHideTest(bool parent
)
1098 : FocusControllerImplicitTestBase(parent
) {}
1100 // Overridden from FocusControllerImplicitTestBase:
1101 void ChangeWindowDisposition(aura::Window
* window
) override
{
1102 GetDispositionWindow(window
)->Hide();
1106 DISALLOW_COPY_AND_ASSIGN(FocusControllerHideTest
);
1109 // Focus and Activation changes in response to window parent visibility
1111 class FocusControllerParentHideTest
: public FocusControllerHideTest
{
1113 FocusControllerParentHideTest() : FocusControllerHideTest(true) {}
1115 // The parent window's visibility change should not change its transient child
1116 // window's modality property.
1117 void TransientChildWindowActivationTest() {
1118 aura::Window
* w1
= root_window()->GetChildById(1);
1119 aura::Window
* w11
= root_window()->GetChildById(11);
1120 ::wm::AddTransientChild(w1
, w11
);
1121 w11
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
1123 EXPECT_EQ(ui::MODAL_TYPE_NONE
, w1
->GetProperty(aura::client::kModalKey
));
1124 EXPECT_EQ(ui::MODAL_TYPE_WINDOW
, w11
->GetProperty(aura::client::kModalKey
));
1126 // Hide the parent window w1 and show it again.
1130 // Test that child window w11 doesn't change its modality property.
1131 EXPECT_EQ(ui::MODAL_TYPE_NONE
, w1
->GetProperty(aura::client::kModalKey
));
1132 EXPECT_EQ(ui::MODAL_TYPE_WINDOW
, w11
->GetProperty(aura::client::kModalKey
));
1136 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentHideTest
);
1139 // Focus and Activation changes in response to window destruction.
1140 class FocusControllerDestructionTest
: public FocusControllerImplicitTestBase
{
1142 FocusControllerDestructionTest() : FocusControllerImplicitTestBase(false) {}
1145 FocusControllerDestructionTest(bool parent
)
1146 : FocusControllerImplicitTestBase(parent
) {}
1148 // Overridden from FocusControllerImplicitTestBase:
1149 void ChangeWindowDisposition(aura::Window
* window
) override
{
1150 delete GetDispositionWindow(window
);
1154 DISALLOW_COPY_AND_ASSIGN(FocusControllerDestructionTest
);
1157 // Focus and Activation changes in response to window parent destruction.
1158 class FocusControllerParentDestructionTest
1159 : public FocusControllerDestructionTest
{
1161 FocusControllerParentDestructionTest()
1162 : FocusControllerDestructionTest(true) {}
1165 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentDestructionTest
);
1168 // Focus and Activation changes in response to window removal.
1169 class FocusControllerRemovalTest
: public FocusControllerImplicitTestBase
{
1171 FocusControllerRemovalTest() : FocusControllerImplicitTestBase(false) {}
1174 FocusControllerRemovalTest(bool parent
)
1175 : FocusControllerImplicitTestBase(parent
) {}
1177 // Overridden from FocusControllerImplicitTestBase:
1178 void ChangeWindowDisposition(aura::Window
* window
) override
{
1179 aura::Window
* disposition_window
= GetDispositionWindow(window
);
1180 disposition_window
->parent()->RemoveChild(disposition_window
);
1181 window_owner_
.reset(disposition_window
);
1183 void TearDown() override
{
1184 window_owner_
.reset();
1185 FocusControllerImplicitTestBase::TearDown();
1189 scoped_ptr
<aura::Window
> window_owner_
;
1191 DISALLOW_COPY_AND_ASSIGN(FocusControllerRemovalTest
);
1194 // Focus and Activation changes in response to window parent removal.
1195 class FocusControllerParentRemovalTest
: public FocusControllerRemovalTest
{
1197 FocusControllerParentRemovalTest() : FocusControllerRemovalTest(true) {}
1200 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentRemovalTest
);
1204 #define FOCUS_CONTROLLER_TEST(TESTCLASS, TESTNAME) \
1205 TEST_F(TESTCLASS, TESTNAME) { TESTNAME(); }
1207 // Runs direct focus change tests (input events and API calls).
1208 #define DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1209 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, TESTNAME) \
1210 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, TESTNAME) \
1211 FOCUS_CONTROLLER_TEST(FocusControllerGestureEventTest, TESTNAME)
1213 // Runs implicit focus change tests for disposition changes to target.
1214 #define IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME) \
1215 FOCUS_CONTROLLER_TEST(FocusControllerHideTest, TESTNAME) \
1216 FOCUS_CONTROLLER_TEST(FocusControllerDestructionTest, TESTNAME) \
1217 FOCUS_CONTROLLER_TEST(FocusControllerRemovalTest, TESTNAME)
1219 // Runs implicit focus change tests for disposition changes to target's parent
1221 #define IMPLICIT_FOCUS_CHANGE_PARENT_TESTS(TESTNAME) \
1222 /* TODO(beng): parent destruction tests are not supported at
1223 present due to workspace manager issues. \
1224 FOCUS_CONTROLLER_TEST(FocusControllerParentDestructionTest, TESTNAME) */ \
1225 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, TESTNAME) \
1226 FOCUS_CONTROLLER_TEST(FocusControllerParentRemovalTest, TESTNAME)
1228 // Runs all implicit focus change tests (changes to the target and target's
1229 // parent hierarchy)
1230 #define IMPLICIT_FOCUS_CHANGE_TESTS(TESTNAME) \
1231 IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME) \
1232 IMPLICIT_FOCUS_CHANGE_PARENT_TESTS(TESTNAME)
1234 // Runs all possible focus change tests.
1235 #define ALL_FOCUS_TESTS(TESTNAME) \
1236 DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1237 IMPLICIT_FOCUS_CHANGE_TESTS(TESTNAME)
1239 // Runs focus change tests that apply only to the target. For example,
1240 // implicit activation changes caused by window disposition changes do not
1241 // occur when changes to the containing hierarchy happen.
1242 #define TARGET_FOCUS_TESTS(TESTNAME) \
1243 DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1244 IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME)
1246 // - Focuses a window, verifies that focus changed.
1247 ALL_FOCUS_TESTS(BasicFocus
);
1249 // - Activates a window, verifies that activation changed.
1250 TARGET_FOCUS_TESTS(BasicActivation
);
1252 // - Focuses a window, verifies that focus events were dispatched.
1253 ALL_FOCUS_TESTS(FocusEvents
);
1255 // - Focuses or activates a window multiple times, verifies that events are only
1256 // dispatched when focus/activation actually changes.
1257 DIRECT_FOCUS_CHANGE_TESTS(DuplicateFocusEvents
);
1258 DIRECT_FOCUS_CHANGE_TESTS(DuplicateActivationEvents
);
1260 // - Activates a window, verifies that activation events were dispatched.
1261 TARGET_FOCUS_TESTS(ActivationEvents
);
1263 // - Attempts to active a hidden window, verifies that current window is
1264 // attempted to be reactivated and the appropriate event dispatched.
1265 FOCUS_CONTROLLER_TEST(FocusControllerApiTest
, ReactivationEvents
);
1267 // - Input events/API calls shift focus between focusable windows within the
1269 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusWithinActiveWindow
);
1271 // - Input events/API calls to a child window of an inactive window shifts
1272 // activation to the activatable parent and focuses the child.
1273 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToChildOfInactiveWindow
);
1275 // - Input events/API calls to focus the parent of the focused window do not
1276 // shift focus away from the child.
1277 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToParentOfFocusedWindow
);
1279 // - Verifies that FocusRules determine what can be focused.
1280 ALL_FOCUS_TESTS(FocusRulesOverride
);
1282 // - Verifies that FocusRules determine what can be activated.
1283 TARGET_FOCUS_TESTS(ActivationRulesOverride
);
1285 // - Verifies that attempts to change focus or activation from a focus or
1286 // activation change observer are ignored.
1287 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation
);
1288 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide
);
1289 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation
);
1291 FOCUS_CONTROLLER_TEST(FocusControllerApiTest
, FocusChangeDuringDrag
);
1293 FOCUS_CONTROLLER_TEST(FocusControllerApiTest
,
1294 ChangeFocusWhenNothingFocusedAndCaptured
);
1296 // See description above DontPassDeletedWindow() for details.
1297 FOCUS_CONTROLLER_TEST(FocusControllerApiTest
, DontPassDeletedWindow
);
1299 // See description above TransientChildWindowActivationTest() for details.
1300 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest
,
1301 TransientChildWindowActivationTest
);
1303 // - Verifies that the focused text input client is cleard when the window focus
1305 ALL_FOCUS_TESTS(FocusedTextInputClient
);
1307 // If a mouse event was handled, it should not activate a window.
1308 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest
, IgnoreHandledEvent
);