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/wm_state.h"
26 #include "ui/wm/public/activation_change_observer.h"
27 #include "ui/wm/public/activation_client.h"
31 class FocusNotificationObserver
: public aura::client::ActivationChangeObserver
,
32 public aura::client::FocusChangeObserver
{
34 FocusNotificationObserver()
35 : activation_changed_count_(0),
36 focus_changed_count_(0),
37 reactivation_count_(0),
38 reactivation_requested_window_(NULL
),
39 reactivation_actual_window_(NULL
) {}
40 virtual ~FocusNotificationObserver() {}
42 void ExpectCounts(int activation_changed_count
, int focus_changed_count
) {
43 EXPECT_EQ(activation_changed_count
, activation_changed_count_
);
44 EXPECT_EQ(focus_changed_count
, focus_changed_count_
);
46 int reactivation_count() const {
47 return reactivation_count_
;
49 aura::Window
* reactivation_requested_window() const {
50 return reactivation_requested_window_
;
52 aura::Window
* reactivation_actual_window() const {
53 return reactivation_actual_window_
;
57 // Overridden from aura::client::ActivationChangeObserver:
58 virtual void OnWindowActivated(aura::Window
* gained_active
,
59 aura::Window
* lost_active
) OVERRIDE
{
60 ++activation_changed_count_
;
62 virtual void OnAttemptToReactivateWindow(
63 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 virtual 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 virtual ~RecordingActivationAndFocusChangeObserver() {
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 virtual 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 virtual 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 virtual ~DeleteOnLoseActivationChangeObserver() {
157 aura::client::GetActivationClient(root_
)->RemoveObserver(this);
160 // Overridden from aura::client::ActivationChangeObserver:
161 virtual void OnWindowActivated(aura::Window
* gained_active
,
162 aura::Window
* lost_active
) OVERRIDE
{
163 if (window_
&& lost_active
== window_
) {
169 // Overridden from WindowDeleter:
170 virtual 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 virtual ~DeleteOnLoseFocusChangeObserver() {
194 aura::client::GetFocusClient(root_
)->RemoveObserver(this);
197 // Overridden from aura::client::FocusChangeObserver:
198 virtual void OnWindowFocused(aura::Window
* gained_focus
,
199 aura::Window
* lost_focus
) OVERRIDE
{
200 if (window_
&& lost_focus
== window_
) {
206 // Overridden from WindowDeleter:
207 virtual 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 virtual ~ScopedFocusNotificationObserver() {
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 virtual ~ScopedTargetFocusNotificationObserver() {
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 virtual 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 virtual ~SimpleEventHandler() {}
284 // Overridden from ui::EventHandler:
285 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
{
288 virtual void OnGestureEvent(ui::GestureEvent
* event
) OVERRIDE
{
293 DISALLOW_COPY_AND_ASSIGN(SimpleEventHandler
);
296 class FocusShiftingActivationObserver
297 : public aura::client::ActivationChangeObserver
{
299 explicit FocusShiftingActivationObserver(aura::Window
* activated_window
)
300 : activated_window_(activated_window
),
301 shift_focus_to_(NULL
) {}
302 virtual ~FocusShiftingActivationObserver() {}
304 void set_shift_focus_to(aura::Window
* shift_focus_to
) {
305 shift_focus_to_
= shift_focus_to
;
309 // Overridden from aura::client::ActivationChangeObserver:
310 virtual void OnWindowActivated(aura::Window
* gained_active
,
311 aura::Window
* lost_active
) OVERRIDE
{
312 // Shift focus to a child. This should prevent the default focusing from
313 // occurring in FocusController::FocusWindow().
314 if (gained_active
== activated_window_
) {
315 aura::client::FocusClient
* client
=
316 aura::client::GetFocusClient(gained_active
);
317 client
->FocusWindow(shift_focus_to_
);
321 aura::Window
* activated_window_
;
322 aura::Window
* shift_focus_to_
;
324 DISALLOW_COPY_AND_ASSIGN(FocusShiftingActivationObserver
);
327 // BaseFocusRules subclass that allows basic overrides of focus/activation to
328 // be tested. This is intended more as a test that the override system works at
329 // all, rather than as an exhaustive set of use cases, those should be covered
330 // in tests for those FocusRules implementations.
331 class TestFocusRules
: public BaseFocusRules
{
333 TestFocusRules() : focus_restriction_(NULL
) {}
335 // Restricts focus and activation to this window and its child hierarchy.
336 void set_focus_restriction(aura::Window
* focus_restriction
) {
337 focus_restriction_
= focus_restriction
;
340 // Overridden from BaseFocusRules:
341 virtual bool SupportsChildActivation(aura::Window
* window
) const OVERRIDE
{
342 // In FocusControllerTests, only the RootWindow has activatable children.
343 return window
->GetRootWindow() == window
;
345 virtual bool CanActivateWindow(aura::Window
* window
) const OVERRIDE
{
346 // Restricting focus to a non-activatable child window means the activatable
347 // parent outside the focus restriction is activatable.
349 CanFocusOrActivate(window
) || window
->Contains(focus_restriction_
);
350 return can_activate
? BaseFocusRules::CanActivateWindow(window
) : false;
352 virtual bool CanFocusWindow(aura::Window
* window
) const OVERRIDE
{
353 return CanFocusOrActivate(window
) ?
354 BaseFocusRules::CanFocusWindow(window
) : false;
356 virtual aura::Window
* GetActivatableWindow(
357 aura::Window
* window
) const OVERRIDE
{
358 return BaseFocusRules::GetActivatableWindow(
359 CanFocusOrActivate(window
) ? window
: focus_restriction_
);
361 virtual aura::Window
* GetFocusableWindow(
362 aura::Window
* window
) const OVERRIDE
{
363 return BaseFocusRules::GetFocusableWindow(
364 CanFocusOrActivate(window
) ? window
: focus_restriction_
);
366 virtual aura::Window
* GetNextActivatableWindow(
367 aura::Window
* ignore
) const OVERRIDE
{
368 aura::Window
* next_activatable
=
369 BaseFocusRules::GetNextActivatableWindow(ignore
);
370 return CanFocusOrActivate(next_activatable
) ?
371 next_activatable
: GetActivatableWindow(focus_restriction_
);
375 bool CanFocusOrActivate(aura::Window
* window
) const {
376 return !focus_restriction_
|| focus_restriction_
->Contains(window
);
379 aura::Window
* focus_restriction_
;
381 DISALLOW_COPY_AND_ASSIGN(TestFocusRules
);
384 // Common infrastructure shared by all FocusController test types.
385 class FocusControllerTestBase
: public aura::test::AuraTestBase
{
387 FocusControllerTestBase() {}
389 // Overridden from aura::test::AuraTestBase:
390 virtual void SetUp() OVERRIDE
{
391 wm_state_
.reset(new wm::WMState
);
392 // FocusController registers itself as an Env observer so it can catch all
393 // window initializations, including the root_window()'s, so we create it
394 // before allowing the base setup.
395 test_focus_rules_
= new TestFocusRules
;
396 focus_controller_
.reset(new FocusController(test_focus_rules_
));
397 aura::test::AuraTestBase::SetUp();
398 root_window()->AddPreTargetHandler(focus_controller_
.get());
399 aura::client::SetFocusClient(root_window(), focus_controller_
.get());
400 aura::client::SetActivationClient(root_window(), focus_controller_
.get());
402 // Hierarchy used by all tests:
411 aura::Window
* w1
= aura::test::CreateTestWindowWithDelegate(
412 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 1,
413 gfx::Rect(0, 0, 50, 50), root_window());
414 aura::test::CreateTestWindowWithDelegate(
415 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 11,
416 gfx::Rect(5, 5, 10, 10), w1
);
417 aura::test::CreateTestWindowWithDelegate(
418 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 12,
419 gfx::Rect(15, 15, 10, 10), w1
);
420 aura::Window
* w2
= aura::test::CreateTestWindowWithDelegate(
421 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 2,
422 gfx::Rect(75, 75, 50, 50), root_window());
423 aura::Window
* w21
= aura::test::CreateTestWindowWithDelegate(
424 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 21,
425 gfx::Rect(5, 5, 10, 10), w2
);
426 aura::test::CreateTestWindowWithDelegate(
427 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 211,
428 gfx::Rect(1, 1, 5, 5), w21
);
429 aura::test::CreateTestWindowWithDelegate(
430 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3,
431 gfx::Rect(125, 125, 50, 50), root_window());
433 virtual void TearDown() OVERRIDE
{
434 root_window()->RemovePreTargetHandler(focus_controller_
.get());
435 aura::test::AuraTestBase::TearDown();
436 test_focus_rules_
= NULL
; // Owned by FocusController.
437 focus_controller_
.reset();
441 void FocusWindow(aura::Window
* window
) {
442 aura::client::GetFocusClient(root_window())->FocusWindow(window
);
444 aura::Window
* GetFocusedWindow() {
445 return aura::client::GetFocusClient(root_window())->GetFocusedWindow();
447 int GetFocusedWindowId() {
448 aura::Window
* focused_window
= GetFocusedWindow();
449 return focused_window
? focused_window
->id() : -1;
451 void ActivateWindow(aura::Window
* window
) {
452 aura::client::GetActivationClient(root_window())->ActivateWindow(window
);
454 void DeactivateWindow(aura::Window
* window
) {
455 aura::client::GetActivationClient(root_window())->DeactivateWindow(window
);
457 aura::Window
* GetActiveWindow() {
458 return aura::client::GetActivationClient(root_window())->GetActiveWindow();
460 int GetActiveWindowId() {
461 aura::Window
* active_window
= GetActiveWindow();
462 return active_window
? active_window
->id() : -1;
465 TestFocusRules
* test_focus_rules() { return test_focus_rules_
; }
468 virtual void BasicFocus() = 0;
469 virtual void BasicActivation() = 0;
470 virtual void FocusEvents() = 0;
471 virtual void DuplicateFocusEvents() {}
472 virtual void ActivationEvents() = 0;
473 virtual void ReactivationEvents() {}
474 virtual void DuplicateActivationEvents() {}
475 virtual void ShiftFocusWithinActiveWindow() {}
476 virtual void ShiftFocusToChildOfInactiveWindow() {}
477 virtual void ShiftFocusToParentOfFocusedWindow() {}
478 virtual void FocusRulesOverride() = 0;
479 virtual void ActivationRulesOverride() = 0;
480 virtual void ShiftFocusOnActivation() {}
481 virtual void ShiftFocusOnActivationDueToHide() {}
482 virtual void NoShiftActiveOnActivation() {}
483 virtual void NoFocusChangeOnClickOnCaptureWindow() {}
484 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {}
485 virtual void DontPassDeletedWindow() {}
486 virtual void FocusedTextInputClient() {}
489 scoped_ptr
<FocusController
> focus_controller_
;
490 TestFocusRules
* test_focus_rules_
;
491 scoped_ptr
<wm::WMState
> wm_state_
;
493 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase
);
496 // Test base for tests where focus is directly set to a target window.
497 class FocusControllerDirectTestBase
: public FocusControllerTestBase
{
499 FocusControllerDirectTestBase() {}
501 // Different test types shift focus in different ways.
502 virtual void FocusWindowDirect(aura::Window
* window
) = 0;
503 virtual void ActivateWindowDirect(aura::Window
* window
) = 0;
504 virtual void DeactivateWindowDirect(aura::Window
* window
) = 0;
506 // Input events do not change focus if the window can not be focused.
507 virtual bool IsInputEvent() = 0;
509 void FocusWindowById(int id
) {
510 aura::Window
* window
= root_window()->GetChildById(id
);
512 FocusWindowDirect(window
);
514 void ActivateWindowById(int id
) {
515 aura::Window
* window
= root_window()->GetChildById(id
);
517 ActivateWindowDirect(window
);
520 // Overridden from FocusControllerTestBase:
521 virtual void BasicFocus() OVERRIDE
{
522 EXPECT_EQ(NULL
, GetFocusedWindow());
524 EXPECT_EQ(1, GetFocusedWindowId());
526 EXPECT_EQ(2, GetFocusedWindowId());
528 virtual void BasicActivation() OVERRIDE
{
529 EXPECT_EQ(NULL
, GetActiveWindow());
530 ActivateWindowById(1);
531 EXPECT_EQ(1, GetActiveWindowId());
532 ActivateWindowById(2);
533 EXPECT_EQ(2, GetActiveWindowId());
534 // Verify that attempting to deactivate NULL does not crash and does not
535 // change activation.
536 DeactivateWindow(NULL
);
537 EXPECT_EQ(2, GetActiveWindowId());
538 DeactivateWindow(GetActiveWindow());
539 EXPECT_EQ(1, GetActiveWindowId());
541 virtual void FocusEvents() OVERRIDE
{
542 ScopedFocusNotificationObserver
root_observer(root_window());
543 ScopedTargetFocusNotificationObserver
observer1(root_window(), 1);
544 ScopedTargetFocusNotificationObserver
observer2(root_window(), 2);
546 root_observer
.ExpectCounts(0, 0);
547 observer1
.ExpectCounts(0, 0);
548 observer2
.ExpectCounts(0, 0);
551 root_observer
.ExpectCounts(1, 1);
552 observer1
.ExpectCounts(1, 1);
553 observer2
.ExpectCounts(0, 0);
556 root_observer
.ExpectCounts(2, 2);
557 observer1
.ExpectCounts(2, 2);
558 observer2
.ExpectCounts(1, 1);
560 virtual void DuplicateFocusEvents() OVERRIDE
{
561 // Focusing an existing focused window should not resend focus events.
562 ScopedFocusNotificationObserver
root_observer(root_window());
563 ScopedTargetFocusNotificationObserver
observer1(root_window(), 1);
565 root_observer
.ExpectCounts(0, 0);
566 observer1
.ExpectCounts(0, 0);
569 root_observer
.ExpectCounts(1, 1);
570 observer1
.ExpectCounts(1, 1);
573 root_observer
.ExpectCounts(1, 1);
574 observer1
.ExpectCounts(1, 1);
576 virtual void ActivationEvents() OVERRIDE
{
577 ActivateWindowById(1);
579 ScopedFocusNotificationObserver
root_observer(root_window());
580 ScopedTargetFocusNotificationObserver
observer1(root_window(), 1);
581 ScopedTargetFocusNotificationObserver
observer2(root_window(), 2);
583 root_observer
.ExpectCounts(0, 0);
584 observer1
.ExpectCounts(0, 0);
585 observer2
.ExpectCounts(0, 0);
587 ActivateWindowById(2);
588 root_observer
.ExpectCounts(1, 1);
589 observer1
.ExpectCounts(1, 1);
590 observer2
.ExpectCounts(1, 1);
592 virtual void ReactivationEvents() OVERRIDE
{
593 ActivateWindowById(1);
594 ScopedFocusNotificationObserver
root_observer(root_window());
595 EXPECT_EQ(0, root_observer
.reactivation_count());
596 root_window()->GetChildById(2)->Hide();
597 // When we attempt to activate "2", which cannot be activated because it
598 // is not visible, "1" will be reactivated.
599 ActivateWindowById(2);
600 EXPECT_EQ(1, root_observer
.reactivation_count());
601 EXPECT_EQ(root_window()->GetChildById(2),
602 root_observer
.reactivation_requested_window());
603 EXPECT_EQ(root_window()->GetChildById(1),
604 root_observer
.reactivation_actual_window());
606 virtual void DuplicateActivationEvents() OVERRIDE
{
607 // Activating an existing active window should not resend activation events.
608 ActivateWindowById(1);
610 ScopedFocusNotificationObserver
root_observer(root_window());
611 ScopedTargetFocusNotificationObserver
observer1(root_window(), 1);
612 ScopedTargetFocusNotificationObserver
observer2(root_window(), 2);
614 root_observer
.ExpectCounts(0, 0);
615 observer1
.ExpectCounts(0, 0);
616 observer2
.ExpectCounts(0, 0);
618 ActivateWindowById(2);
619 root_observer
.ExpectCounts(1, 1);
620 observer1
.ExpectCounts(1, 1);
621 observer2
.ExpectCounts(1, 1);
623 ActivateWindowById(2);
624 root_observer
.ExpectCounts(1, 1);
625 observer1
.ExpectCounts(1, 1);
626 observer2
.ExpectCounts(1, 1);
628 virtual void ShiftFocusWithinActiveWindow() OVERRIDE
{
629 ActivateWindowById(1);
630 EXPECT_EQ(1, GetActiveWindowId());
631 EXPECT_EQ(1, GetFocusedWindowId());
633 EXPECT_EQ(11, GetFocusedWindowId());
635 EXPECT_EQ(12, GetFocusedWindowId());
637 virtual void ShiftFocusToChildOfInactiveWindow() OVERRIDE
{
638 ActivateWindowById(2);
639 EXPECT_EQ(2, GetActiveWindowId());
640 EXPECT_EQ(2, GetFocusedWindowId());
642 EXPECT_EQ(1, GetActiveWindowId());
643 EXPECT_EQ(11, GetFocusedWindowId());
645 virtual void ShiftFocusToParentOfFocusedWindow() OVERRIDE
{
646 ActivateWindowById(1);
647 EXPECT_EQ(1, GetFocusedWindowId());
649 EXPECT_EQ(11, GetFocusedWindowId());
651 // Focus should _not_ shift to the parent of the already-focused window.
652 EXPECT_EQ(11, GetFocusedWindowId());
654 virtual void FocusRulesOverride() OVERRIDE
{
655 EXPECT_EQ(NULL
, GetFocusedWindow());
657 EXPECT_EQ(11, GetFocusedWindowId());
659 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(211));
661 // Input events leave focus unchanged; direct API calls will change focus
662 // to the restricted window.
663 int focused_window
= IsInputEvent() ? 11 : 211;
664 EXPECT_EQ(focused_window
, GetFocusedWindowId());
666 test_focus_rules()->set_focus_restriction(NULL
);
668 EXPECT_EQ(12, GetFocusedWindowId());
670 virtual void ActivationRulesOverride() OVERRIDE
{
671 ActivateWindowById(1);
672 EXPECT_EQ(1, GetActiveWindowId());
673 EXPECT_EQ(1, GetFocusedWindowId());
675 aura::Window
* w3
= root_window()->GetChildById(3);
676 test_focus_rules()->set_focus_restriction(w3
);
678 ActivateWindowById(2);
679 // Input events leave activation unchanged; direct API calls will activate
680 // the restricted window.
681 int active_window
= IsInputEvent() ? 1 : 3;
682 EXPECT_EQ(active_window
, GetActiveWindowId());
683 EXPECT_EQ(active_window
, GetFocusedWindowId());
685 test_focus_rules()->set_focus_restriction(NULL
);
686 ActivateWindowById(2);
687 EXPECT_EQ(2, GetActiveWindowId());
688 EXPECT_EQ(2, GetFocusedWindowId());
690 virtual void ShiftFocusOnActivation() OVERRIDE
{
691 // When a window is activated, by default that window is also focused.
692 // An ActivationChangeObserver may shift focus to another window within the
693 // same activatable window.
694 ActivateWindowById(2);
695 EXPECT_EQ(2, GetFocusedWindowId());
696 ActivateWindowById(1);
697 EXPECT_EQ(1, GetFocusedWindowId());
699 ActivateWindowById(2);
701 aura::Window
* target
= root_window()->GetChildById(1);
702 aura::client::ActivationClient
* client
=
703 aura::client::GetActivationClient(root_window());
705 scoped_ptr
<FocusShiftingActivationObserver
> observer(
706 new FocusShiftingActivationObserver(target
));
707 observer
->set_shift_focus_to(target
->GetChildById(11));
708 client
->AddObserver(observer
.get());
710 ActivateWindowById(1);
712 // w1's ActivationChangeObserver shifted focus to this child, pre-empting
713 // FocusController's default setting.
714 EXPECT_EQ(11, GetFocusedWindowId());
716 ActivateWindowById(2);
717 EXPECT_EQ(2, GetFocusedWindowId());
719 // Simulate a focus reset by the ActivationChangeObserver. This should
720 // trigger the default setting in FocusController.
721 observer
->set_shift_focus_to(NULL
);
722 ActivateWindowById(1);
723 EXPECT_EQ(1, GetFocusedWindowId());
725 client
->RemoveObserver(observer
.get());
727 ActivateWindowById(2);
728 EXPECT_EQ(2, GetFocusedWindowId());
729 ActivateWindowById(1);
730 EXPECT_EQ(1, GetFocusedWindowId());
732 virtual void ShiftFocusOnActivationDueToHide() OVERRIDE
{
733 // Similar to ShiftFocusOnActivation except the activation change is
734 // triggered by hiding the active window.
735 ActivateWindowById(1);
736 EXPECT_EQ(1, GetFocusedWindowId());
738 // Removes window 3 as candidate for next activatable window.
739 root_window()->GetChildById(3)->Hide();
740 EXPECT_EQ(1, GetFocusedWindowId());
742 aura::Window
* target
= root_window()->GetChildById(2);
743 aura::client::ActivationClient
* client
=
744 aura::client::GetActivationClient(root_window());
746 scoped_ptr
<FocusShiftingActivationObserver
> observer(
747 new FocusShiftingActivationObserver(target
));
748 observer
->set_shift_focus_to(target
->GetChildById(21));
749 client
->AddObserver(observer
.get());
751 // Hide the active window.
752 root_window()->GetChildById(1)->Hide();
754 EXPECT_EQ(21, GetFocusedWindowId());
756 client
->RemoveObserver(observer
.get());
758 virtual void NoShiftActiveOnActivation() OVERRIDE
{
759 // When a window is activated, we need to prevent any change to activation
760 // from being made in response to an activation change notification.
763 virtual void NoFocusChangeOnClickOnCaptureWindow() OVERRIDE
{
764 scoped_ptr
<aura::client::DefaultCaptureClient
> capture_client(
765 new aura::client::DefaultCaptureClient(root_window()));
766 // Clicking on a window which has capture should not cause a focus change
767 // to the window. This test verifies whether that is indeed the case.
768 ActivateWindowById(1);
770 EXPECT_EQ(1, GetActiveWindowId());
771 EXPECT_EQ(1, GetFocusedWindowId());
773 aura::Window
* w2
= root_window()->GetChildById(2);
774 aura::client::GetCaptureClient(root_window())->SetCapture(w2
);
775 ui::test::EventGenerator
generator(root_window(), w2
);
776 generator
.ClickLeftButton();
778 EXPECT_EQ(1, GetActiveWindowId());
779 EXPECT_EQ(1, GetFocusedWindowId());
780 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w2
);
783 // Verifies focus change is honored while capture held.
784 virtual void ChangeFocusWhenNothingFocusedAndCaptured() OVERRIDE
{
785 scoped_ptr
<aura::client::DefaultCaptureClient
> capture_client(
786 new aura::client::DefaultCaptureClient(root_window()));
787 aura::Window
* w1
= root_window()->GetChildById(1);
788 aura::client::GetCaptureClient(root_window())->SetCapture(w1
);
790 EXPECT_EQ(-1, GetActiveWindowId());
791 EXPECT_EQ(-1, GetFocusedWindowId());
795 EXPECT_EQ(1, GetActiveWindowId());
796 EXPECT_EQ(1, GetFocusedWindowId());
798 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1
);
801 // Verifies if a window that loses activation or focus is deleted during
802 // observer notification we don't pass the deleted window to other observers.
803 virtual void DontPassDeletedWindow() OVERRIDE
{
806 EXPECT_EQ(1, GetActiveWindowId());
807 EXPECT_EQ(1, GetFocusedWindowId());
810 aura::Window
* to_delete
= root_window()->GetChildById(1);
811 DeleteOnLoseActivationChangeObserver
observer1(to_delete
);
812 RecordingActivationAndFocusChangeObserver
observer2(root_window(),
817 EXPECT_EQ(2, GetActiveWindowId());
818 EXPECT_EQ(2, GetFocusedWindowId());
820 EXPECT_EQ(to_delete
, observer1
.GetDeletedWindow());
821 EXPECT_FALSE(observer2
.was_notified_with_deleted_window());
825 aura::Window
* to_delete
= root_window()->GetChildById(2);
826 DeleteOnLoseFocusChangeObserver
observer1(to_delete
);
827 RecordingActivationAndFocusChangeObserver
observer2(root_window(),
832 EXPECT_EQ(3, GetActiveWindowId());
833 EXPECT_EQ(3, GetFocusedWindowId());
835 EXPECT_EQ(to_delete
, observer1
.GetDeletedWindow());
836 EXPECT_FALSE(observer2
.was_notified_with_deleted_window());
840 // Verifies if the focused text input client is cleared when a window gains
841 // or loses the focus.
842 virtual void FocusedTextInputClient() OVERRIDE
{
843 ui::TextInputFocusManager
* text_input_focus_manager
=
844 ui::TextInputFocusManager::GetInstance();
845 ui::DummyTextInputClient text_input_client
;
846 ui::TextInputClient
* null_text_input_client
= NULL
;
848 EXPECT_EQ(null_text_input_client
,
849 text_input_focus_manager
->GetFocusedTextInputClient());
851 text_input_focus_manager
->FocusTextInputClient(&text_input_client
);
852 EXPECT_EQ(&text_input_client
,
853 text_input_focus_manager
->GetFocusedTextInputClient());
855 // The focused text input client gets cleared when a window gets focused
856 // unless any of observers sets the focused text input client.
857 EXPECT_EQ(null_text_input_client
,
858 text_input_focus_manager
->GetFocusedTextInputClient());
860 ScopedFocusedTextInputClientChanger
text_input_focus_changer(
861 root_window(), &text_input_client
);
862 EXPECT_EQ(null_text_input_client
,
863 text_input_focus_manager
->GetFocusedTextInputClient());
865 // |text_input_focus_changer| sets the focused text input client.
866 EXPECT_EQ(&text_input_client
,
867 text_input_focus_manager
->GetFocusedTextInputClient());
870 // The focused text input client gets cleared when a window loses the focus.
871 EXPECT_EQ(null_text_input_client
,
872 text_input_focus_manager
->GetFocusedTextInputClient());
876 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase
);
879 // Focus and Activation changes via aura::client::ActivationClient API.
880 class FocusControllerApiTest
: public FocusControllerDirectTestBase
{
882 FocusControllerApiTest() {}
885 // Overridden from FocusControllerTestBase:
886 virtual void FocusWindowDirect(aura::Window
* window
) OVERRIDE
{
889 virtual void ActivateWindowDirect(aura::Window
* window
) OVERRIDE
{
890 ActivateWindow(window
);
892 virtual void DeactivateWindowDirect(aura::Window
* window
) OVERRIDE
{
893 DeactivateWindow(window
);
895 virtual bool IsInputEvent() OVERRIDE
{ return false; }
897 DISALLOW_COPY_AND_ASSIGN(FocusControllerApiTest
);
900 // Focus and Activation changes via input events.
901 class FocusControllerMouseEventTest
: public FocusControllerDirectTestBase
{
903 FocusControllerMouseEventTest() {}
905 // Tests that a handled mouse or gesture event does not trigger a window
907 void IgnoreHandledEvent() {
908 EXPECT_EQ(NULL
, GetActiveWindow());
909 aura::Window
* w1
= root_window()->GetChildById(1);
910 SimpleEventHandler handler
;
911 root_window()->PrependPreTargetHandler(&handler
);
912 ui::test::EventGenerator
generator(root_window(), w1
);
913 generator
.ClickLeftButton();
914 EXPECT_EQ(NULL
, GetActiveWindow());
915 generator
.GestureTapAt(w1
->bounds().CenterPoint());
916 EXPECT_EQ(NULL
, GetActiveWindow());
917 root_window()->RemovePreTargetHandler(&handler
);
918 generator
.ClickLeftButton();
919 EXPECT_EQ(1, GetActiveWindowId());
923 // Overridden from FocusControllerTestBase:
924 virtual void FocusWindowDirect(aura::Window
* window
) OVERRIDE
{
925 ui::test::EventGenerator
generator(root_window(), window
);
926 generator
.ClickLeftButton();
928 virtual void ActivateWindowDirect(aura::Window
* window
) OVERRIDE
{
929 ui::test::EventGenerator
generator(root_window(), window
);
930 generator
.ClickLeftButton();
932 virtual void DeactivateWindowDirect(aura::Window
* window
) OVERRIDE
{
933 aura::Window
* next_activatable
=
934 test_focus_rules()->GetNextActivatableWindow(window
);
935 ui::test::EventGenerator
generator(root_window(), next_activatable
);
936 generator
.ClickLeftButton();
938 virtual bool IsInputEvent() OVERRIDE
{ return true; }
940 DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest
);
943 class FocusControllerGestureEventTest
: public FocusControllerDirectTestBase
{
945 FocusControllerGestureEventTest() {}
948 // Overridden from FocusControllerTestBase:
949 virtual void FocusWindowDirect(aura::Window
* window
) OVERRIDE
{
950 ui::test::EventGenerator
generator(root_window(), window
);
951 generator
.GestureTapAt(window
->bounds().CenterPoint());
953 virtual void ActivateWindowDirect(aura::Window
* window
) OVERRIDE
{
954 ui::test::EventGenerator
generator(root_window(), window
);
955 generator
.GestureTapAt(window
->bounds().CenterPoint());
957 virtual void DeactivateWindowDirect(aura::Window
* window
) OVERRIDE
{
958 aura::Window
* next_activatable
=
959 test_focus_rules()->GetNextActivatableWindow(window
);
960 ui::test::EventGenerator
generator(root_window(), next_activatable
);
961 generator
.GestureTapAt(window
->bounds().CenterPoint());
963 virtual bool IsInputEvent() OVERRIDE
{ return true; }
965 DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest
);
968 // Test base for tests where focus is implicitly set to a window as the result
969 // of a disposition change to the focused window or the hierarchy that contains
971 class FocusControllerImplicitTestBase
: public FocusControllerTestBase
{
973 explicit FocusControllerImplicitTestBase(bool parent
) : parent_(parent
) {}
975 aura::Window
* GetDispositionWindow(aura::Window
* window
) {
976 return parent_
? window
->parent() : window
;
979 // Change the disposition of |window| in such a way as it will lose focus.
980 virtual void ChangeWindowDisposition(aura::Window
* window
) = 0;
982 // Allow each disposition change test to add additional post-disposition
983 // change expectations.
984 virtual void PostDispostionChangeExpectations() {}
986 // Overridden from FocusControllerTestBase:
987 virtual void BasicFocus() OVERRIDE
{
988 EXPECT_EQ(NULL
, GetFocusedWindow());
990 aura::Window
* w211
= root_window()->GetChildById(211);
992 EXPECT_EQ(211, GetFocusedWindowId());
994 ChangeWindowDisposition(w211
);
995 // BasicFocusRules passes focus to the parent.
996 EXPECT_EQ(parent_
? 2 : 21, GetFocusedWindowId());
998 virtual void BasicActivation() OVERRIDE
{
999 DCHECK(!parent_
) << "Activation tests don't support parent changes.";
1001 EXPECT_EQ(NULL
, GetActiveWindow());
1003 aura::Window
* w2
= root_window()->GetChildById(2);
1005 EXPECT_EQ(2, GetActiveWindowId());
1007 ChangeWindowDisposition(w2
);
1008 EXPECT_EQ(3, GetActiveWindowId());
1009 PostDispostionChangeExpectations();
1011 virtual void FocusEvents() OVERRIDE
{
1012 aura::Window
* w211
= root_window()->GetChildById(211);
1015 ScopedFocusNotificationObserver
root_observer(root_window());
1016 ScopedTargetFocusNotificationObserver
observer211(root_window(), 211);
1017 root_observer
.ExpectCounts(0, 0);
1018 observer211
.ExpectCounts(0, 0);
1020 ChangeWindowDisposition(w211
);
1021 root_observer
.ExpectCounts(0, 1);
1022 observer211
.ExpectCounts(0, 1);
1024 virtual void ActivationEvents() OVERRIDE
{
1025 DCHECK(!parent_
) << "Activation tests don't support parent changes.";
1027 aura::Window
* w2
= root_window()->GetChildById(2);
1030 ScopedFocusNotificationObserver
root_observer(root_window());
1031 ScopedTargetFocusNotificationObserver
observer2(root_window(), 2);
1032 ScopedTargetFocusNotificationObserver
observer3(root_window(), 3);
1033 root_observer
.ExpectCounts(0, 0);
1034 observer2
.ExpectCounts(0, 0);
1035 observer3
.ExpectCounts(0, 0);
1037 ChangeWindowDisposition(w2
);
1038 root_observer
.ExpectCounts(1, 1);
1039 observer2
.ExpectCounts(1, 1);
1040 observer3
.ExpectCounts(1, 1);
1042 virtual void FocusRulesOverride() OVERRIDE
{
1043 EXPECT_EQ(NULL
, GetFocusedWindow());
1044 aura::Window
* w211
= root_window()->GetChildById(211);
1046 EXPECT_EQ(211, GetFocusedWindowId());
1048 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(11));
1049 ChangeWindowDisposition(w211
);
1050 // Normally, focus would shift to the parent (w21) but the override shifts
1052 EXPECT_EQ(11, GetFocusedWindowId());
1054 test_focus_rules()->set_focus_restriction(NULL
);
1056 virtual void ActivationRulesOverride() OVERRIDE
{
1057 DCHECK(!parent_
) << "Activation tests don't support parent changes.";
1059 aura::Window
* w1
= root_window()->GetChildById(1);
1062 EXPECT_EQ(1, GetActiveWindowId());
1063 EXPECT_EQ(1, GetFocusedWindowId());
1065 aura::Window
* w3
= root_window()->GetChildById(3);
1066 test_focus_rules()->set_focus_restriction(w3
);
1068 // Normally, activation/focus would move to w2, but since we have a focus
1069 // restriction, it should move to w3 instead.
1070 ChangeWindowDisposition(w1
);
1071 EXPECT_EQ(3, GetActiveWindowId());
1072 EXPECT_EQ(3, GetFocusedWindowId());
1074 test_focus_rules()->set_focus_restriction(NULL
);
1075 ActivateWindow(root_window()->GetChildById(2));
1076 EXPECT_EQ(2, GetActiveWindowId());
1077 EXPECT_EQ(2, GetFocusedWindowId());
1081 // When true, the disposition change occurs to the parent of the window
1082 // instead of to the window. This verifies that changes occurring in the
1083 // hierarchy that contains the window affect the window's focus.
1086 DISALLOW_COPY_AND_ASSIGN(FocusControllerImplicitTestBase
);
1089 // Focus and Activation changes in response to window visibility changes.
1090 class FocusControllerHideTest
: public FocusControllerImplicitTestBase
{
1092 FocusControllerHideTest() : FocusControllerImplicitTestBase(false) {}
1095 FocusControllerHideTest(bool parent
)
1096 : FocusControllerImplicitTestBase(parent
) {}
1098 // Overridden from FocusControllerImplicitTestBase:
1099 virtual void ChangeWindowDisposition(aura::Window
* window
) OVERRIDE
{
1100 GetDispositionWindow(window
)->Hide();
1104 DISALLOW_COPY_AND_ASSIGN(FocusControllerHideTest
);
1107 // Focus and Activation changes in response to window parent visibility
1109 class FocusControllerParentHideTest
: public FocusControllerHideTest
{
1111 FocusControllerParentHideTest() : FocusControllerHideTest(true) {}
1114 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentHideTest
);
1117 // Focus and Activation changes in response to window destruction.
1118 class FocusControllerDestructionTest
: public FocusControllerImplicitTestBase
{
1120 FocusControllerDestructionTest() : FocusControllerImplicitTestBase(false) {}
1123 FocusControllerDestructionTest(bool parent
)
1124 : FocusControllerImplicitTestBase(parent
) {}
1126 // Overridden from FocusControllerImplicitTestBase:
1127 virtual void ChangeWindowDisposition(aura::Window
* window
) OVERRIDE
{
1128 delete GetDispositionWindow(window
);
1132 DISALLOW_COPY_AND_ASSIGN(FocusControllerDestructionTest
);
1135 // Focus and Activation changes in response to window parent destruction.
1136 class FocusControllerParentDestructionTest
1137 : public FocusControllerDestructionTest
{
1139 FocusControllerParentDestructionTest()
1140 : FocusControllerDestructionTest(true) {}
1143 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentDestructionTest
);
1146 // Focus and Activation changes in response to window removal.
1147 class FocusControllerRemovalTest
: public FocusControllerImplicitTestBase
{
1149 FocusControllerRemovalTest() : FocusControllerImplicitTestBase(false) {}
1152 FocusControllerRemovalTest(bool parent
)
1153 : FocusControllerImplicitTestBase(parent
) {}
1155 // Overridden from FocusControllerImplicitTestBase:
1156 virtual void ChangeWindowDisposition(aura::Window
* window
) OVERRIDE
{
1157 aura::Window
* disposition_window
= GetDispositionWindow(window
);
1158 disposition_window
->parent()->RemoveChild(disposition_window
);
1159 window_owner_
.reset(disposition_window
);
1161 virtual void TearDown() OVERRIDE
{
1162 window_owner_
.reset();
1163 FocusControllerImplicitTestBase::TearDown();
1167 scoped_ptr
<aura::Window
> window_owner_
;
1169 DISALLOW_COPY_AND_ASSIGN(FocusControllerRemovalTest
);
1172 // Focus and Activation changes in response to window parent removal.
1173 class FocusControllerParentRemovalTest
: public FocusControllerRemovalTest
{
1175 FocusControllerParentRemovalTest() : FocusControllerRemovalTest(true) {}
1178 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentRemovalTest
);
1182 #define FOCUS_CONTROLLER_TEST(TESTCLASS, TESTNAME) \
1183 TEST_F(TESTCLASS, TESTNAME) { TESTNAME(); }
1185 // Runs direct focus change tests (input events and API calls).
1186 #define DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1187 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, TESTNAME) \
1188 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, TESTNAME) \
1189 FOCUS_CONTROLLER_TEST(FocusControllerGestureEventTest, TESTNAME)
1191 // Runs implicit focus change tests for disposition changes to target.
1192 #define IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME) \
1193 FOCUS_CONTROLLER_TEST(FocusControllerHideTest, TESTNAME) \
1194 FOCUS_CONTROLLER_TEST(FocusControllerDestructionTest, TESTNAME) \
1195 FOCUS_CONTROLLER_TEST(FocusControllerRemovalTest, TESTNAME)
1197 // Runs implicit focus change tests for disposition changes to target's parent
1199 #define IMPLICIT_FOCUS_CHANGE_PARENT_TESTS(TESTNAME) \
1200 /* TODO(beng): parent destruction tests are not supported at
1201 present due to workspace manager issues. \
1202 FOCUS_CONTROLLER_TEST(FocusControllerParentDestructionTest, TESTNAME) */ \
1203 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, TESTNAME) \
1204 FOCUS_CONTROLLER_TEST(FocusControllerParentRemovalTest, TESTNAME)
1206 // Runs all implicit focus change tests (changes to the target and target's
1207 // parent hierarchy)
1208 #define IMPLICIT_FOCUS_CHANGE_TESTS(TESTNAME) \
1209 IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME) \
1210 IMPLICIT_FOCUS_CHANGE_PARENT_TESTS(TESTNAME)
1212 // Runs all possible focus change tests.
1213 #define ALL_FOCUS_TESTS(TESTNAME) \
1214 DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1215 IMPLICIT_FOCUS_CHANGE_TESTS(TESTNAME)
1217 // Runs focus change tests that apply only to the target. For example,
1218 // implicit activation changes caused by window disposition changes do not
1219 // occur when changes to the containing hierarchy happen.
1220 #define TARGET_FOCUS_TESTS(TESTNAME) \
1221 DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1222 IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME)
1224 // - Focuses a window, verifies that focus changed.
1225 ALL_FOCUS_TESTS(BasicFocus
);
1227 // - Activates a window, verifies that activation changed.
1228 TARGET_FOCUS_TESTS(BasicActivation
);
1230 // - Focuses a window, verifies that focus events were dispatched.
1231 ALL_FOCUS_TESTS(FocusEvents
);
1233 // - Focuses or activates a window multiple times, verifies that events are only
1234 // dispatched when focus/activation actually changes.
1235 DIRECT_FOCUS_CHANGE_TESTS(DuplicateFocusEvents
);
1236 DIRECT_FOCUS_CHANGE_TESTS(DuplicateActivationEvents
);
1238 // - Activates a window, verifies that activation events were dispatched.
1239 TARGET_FOCUS_TESTS(ActivationEvents
);
1241 // - Attempts to active a hidden window, verifies that current window is
1242 // attempted to be reactivated and the appropriate event dispatched.
1243 FOCUS_CONTROLLER_TEST(FocusControllerApiTest
, ReactivationEvents
);
1245 // - Input events/API calls shift focus between focusable windows within the
1247 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusWithinActiveWindow
);
1249 // - Input events/API calls to a child window of an inactive window shifts
1250 // activation to the activatable parent and focuses the child.
1251 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToChildOfInactiveWindow
);
1253 // - Input events/API calls to focus the parent of the focused window do not
1254 // shift focus away from the child.
1255 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToParentOfFocusedWindow
);
1257 // - Verifies that FocusRules determine what can be focused.
1258 ALL_FOCUS_TESTS(FocusRulesOverride
);
1260 // - Verifies that FocusRules determine what can be activated.
1261 TARGET_FOCUS_TESTS(ActivationRulesOverride
);
1263 // - Verifies that attempts to change focus or activation from a focus or
1264 // activation change observer are ignored.
1265 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation
);
1266 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide
);
1267 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation
);
1269 // Clicking on a window which has capture should not result in a focus change.
1270 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow
);
1272 FOCUS_CONTROLLER_TEST(FocusControllerApiTest
,
1273 ChangeFocusWhenNothingFocusedAndCaptured
);
1275 // See description above DontPassDeletedWindow() for details.
1276 FOCUS_CONTROLLER_TEST(FocusControllerApiTest
, DontPassDeletedWindow
);
1278 // - Verifies that the focused text input client is cleard when the window focus
1280 ALL_FOCUS_TESTS(FocusedTextInputClient
);
1282 // If a mouse event was handled, it should not activate a window.
1283 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest
, IgnoreHandledEvent
);