base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / wm / core / focus_controller_unittest.cc
bloba773821daad586dee163547eaa8c5da26c4ea46f
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"
7 #include <map>
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"
29 namespace wm {
31 class FocusNotificationObserver : public aura::client::ActivationChangeObserver,
32 public aura::client::FocusChangeObserver {
33 public:
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 ~FocusNotificationObserver() override {}
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_;
56 private:
57 // Overridden from aura::client::ActivationChangeObserver:
58 void OnWindowActivated(aura::Window* gained_active,
59 aura::Window* lost_active) override {
60 ++activation_changed_count_;
62 void OnAttemptToReactivateWindow(aura::Window* request_active,
63 aura::Window* actual_active) override {
64 ++reactivation_count_;
65 reactivation_requested_window_ = request_active;
66 reactivation_actual_window_ = actual_active;
69 // Overridden from aura::client::FocusChangeObserver:
70 void OnWindowFocused(aura::Window* gained_focus,
71 aura::Window* lost_focus) override {
72 ++focus_changed_count_;
75 int activation_changed_count_;
76 int focus_changed_count_;
77 int reactivation_count_;
78 aura::Window* reactivation_requested_window_;
79 aura::Window* reactivation_actual_window_;
81 DISALLOW_COPY_AND_ASSIGN(FocusNotificationObserver);
84 class WindowDeleter {
85 public:
86 virtual aura::Window* GetDeletedWindow() = 0;
88 protected:
89 virtual ~WindowDeleter() {}
92 // ActivationChangeObserver and FocusChangeObserver that keeps track of whether
93 // it was notified about activation changes or focus changes with a deleted
94 // window.
95 class RecordingActivationAndFocusChangeObserver
96 : public aura::client::ActivationChangeObserver,
97 public aura::client::FocusChangeObserver {
98 public:
99 RecordingActivationAndFocusChangeObserver(aura::Window* root,
100 WindowDeleter* deleter)
101 : root_(root),
102 deleter_(deleter),
103 was_notified_with_deleted_window_(false) {
104 aura::client::GetActivationClient(root_)->AddObserver(this);
105 aura::client::GetFocusClient(root_)->AddObserver(this);
107 ~RecordingActivationAndFocusChangeObserver() override {
108 aura::client::GetActivationClient(root_)->RemoveObserver(this);
109 aura::client::GetFocusClient(root_)->RemoveObserver(this);
112 bool was_notified_with_deleted_window() const {
113 return was_notified_with_deleted_window_;
116 // Overridden from aura::client::ActivationChangeObserver:
117 void OnWindowActivated(aura::Window* gained_active,
118 aura::Window* lost_active) override {
119 if (lost_active && lost_active == deleter_->GetDeletedWindow())
120 was_notified_with_deleted_window_ = true;
123 // Overridden from aura::client::FocusChangeObserver:
124 void OnWindowFocused(aura::Window* gained_focus,
125 aura::Window* lost_focus) override {
126 if (lost_focus && lost_focus == deleter_->GetDeletedWindow())
127 was_notified_with_deleted_window_ = true;
130 private:
131 aura::Window* root_;
133 // Not owned.
134 WindowDeleter* deleter_;
136 // Whether the observer was notified about the loss of activation or the
137 // loss of focus with a window already deleted by |deleter_| as the
138 // |lost_active| or |lost_focus| parameter.
139 bool was_notified_with_deleted_window_;
141 DISALLOW_COPY_AND_ASSIGN(RecordingActivationAndFocusChangeObserver);
144 // ActivationChangeObserver that deletes the window losing activation.
145 class DeleteOnLoseActivationChangeObserver :
146 public aura::client::ActivationChangeObserver,
147 public WindowDeleter {
148 public:
149 explicit DeleteOnLoseActivationChangeObserver(aura::Window* window)
150 : root_(window->GetRootWindow()),
151 window_(window),
152 did_delete_(false) {
153 aura::client::GetActivationClient(root_)->AddObserver(this);
155 ~DeleteOnLoseActivationChangeObserver() override {
156 aura::client::GetActivationClient(root_)->RemoveObserver(this);
159 // Overridden from aura::client::ActivationChangeObserver:
160 void OnWindowActivated(aura::Window* gained_active,
161 aura::Window* lost_active) override {
162 if (window_ && lost_active == window_) {
163 delete lost_active;
164 did_delete_ = true;
168 // Overridden from WindowDeleter:
169 aura::Window* GetDeletedWindow() override {
170 return did_delete_ ? window_ : NULL;
173 private:
174 aura::Window* root_;
175 aura::Window* window_;
176 bool did_delete_;
178 DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseActivationChangeObserver);
181 // FocusChangeObserver that deletes the window losing focus.
182 class DeleteOnLoseFocusChangeObserver
183 : public aura::client::FocusChangeObserver,
184 public WindowDeleter {
185 public:
186 explicit DeleteOnLoseFocusChangeObserver(aura::Window* window)
187 : root_(window->GetRootWindow()),
188 window_(window),
189 did_delete_(false) {
190 aura::client::GetFocusClient(root_)->AddObserver(this);
192 ~DeleteOnLoseFocusChangeObserver() override {
193 aura::client::GetFocusClient(root_)->RemoveObserver(this);
196 // Overridden from aura::client::FocusChangeObserver:
197 void OnWindowFocused(aura::Window* gained_focus,
198 aura::Window* lost_focus) override {
199 if (window_ && lost_focus == window_) {
200 delete lost_focus;
201 did_delete_ = true;
205 // Overridden from WindowDeleter:
206 aura::Window* GetDeletedWindow() override {
207 return did_delete_ ? window_ : NULL;
210 private:
211 aura::Window* root_;
212 aura::Window* window_;
213 bool did_delete_;
215 DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseFocusChangeObserver);
218 class ScopedFocusNotificationObserver : public FocusNotificationObserver {
219 public:
220 ScopedFocusNotificationObserver(aura::Window* root_window)
221 : root_window_(root_window) {
222 aura::client::GetActivationClient(root_window_)->AddObserver(this);
223 aura::client::GetFocusClient(root_window_)->AddObserver(this);
225 ~ScopedFocusNotificationObserver() override {
226 aura::client::GetActivationClient(root_window_)->RemoveObserver(this);
227 aura::client::GetFocusClient(root_window_)->RemoveObserver(this);
230 private:
231 aura::Window* root_window_;
233 DISALLOW_COPY_AND_ASSIGN(ScopedFocusNotificationObserver);
236 class ScopedTargetFocusNotificationObserver : public FocusNotificationObserver {
237 public:
238 ScopedTargetFocusNotificationObserver(aura::Window* root_window, int id)
239 : target_(root_window->GetChildById(id)) {
240 aura::client::SetActivationChangeObserver(target_, this);
241 aura::client::SetFocusChangeObserver(target_, this);
242 tracker_.Add(target_);
244 ~ScopedTargetFocusNotificationObserver() override {
245 if (tracker_.Contains(target_)) {
246 aura::client::SetActivationChangeObserver(target_, NULL);
247 aura::client::SetFocusChangeObserver(target_, NULL);
251 private:
252 aura::Window* target_;
253 aura::WindowTracker tracker_;
255 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver);
258 class ScopedFocusedTextInputClientChanger
259 : public ScopedFocusNotificationObserver {
260 public:
261 ScopedFocusedTextInputClientChanger(aura::Window* root_window,
262 ui::TextInputClient* text_input_client)
263 : ScopedFocusNotificationObserver(root_window),
264 text_input_client_(text_input_client) {}
266 private:
267 // Overridden from aura::client::FocusChangeObserver:
268 void OnWindowFocused(aura::Window* gained_focus,
269 aura::Window* lost_focus) override {
270 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(
271 text_input_client_);
274 ui::TextInputClient* text_input_client_;
277 // Used to fake the handling of events in the pre-target phase.
278 class SimpleEventHandler : public ui::EventHandler {
279 public:
280 SimpleEventHandler() {}
281 ~SimpleEventHandler() override {}
283 // Overridden from ui::EventHandler:
284 void OnMouseEvent(ui::MouseEvent* event) override { event->SetHandled(); }
285 void OnGestureEvent(ui::GestureEvent* event) override { event->SetHandled(); }
287 private:
288 DISALLOW_COPY_AND_ASSIGN(SimpleEventHandler);
291 class FocusShiftingActivationObserver
292 : public aura::client::ActivationChangeObserver {
293 public:
294 explicit FocusShiftingActivationObserver(aura::Window* activated_window)
295 : activated_window_(activated_window),
296 shift_focus_to_(NULL) {}
297 ~FocusShiftingActivationObserver() override {}
299 void set_shift_focus_to(aura::Window* shift_focus_to) {
300 shift_focus_to_ = shift_focus_to;
303 private:
304 // Overridden from aura::client::ActivationChangeObserver:
305 void OnWindowActivated(aura::Window* gained_active,
306 aura::Window* lost_active) override {
307 // Shift focus to a child. This should prevent the default focusing from
308 // occurring in FocusController::FocusWindow().
309 if (gained_active == activated_window_) {
310 aura::client::FocusClient* client =
311 aura::client::GetFocusClient(gained_active);
312 client->FocusWindow(shift_focus_to_);
316 aura::Window* activated_window_;
317 aura::Window* shift_focus_to_;
319 DISALLOW_COPY_AND_ASSIGN(FocusShiftingActivationObserver);
322 // BaseFocusRules subclass that allows basic overrides of focus/activation to
323 // be tested. This is intended more as a test that the override system works at
324 // all, rather than as an exhaustive set of use cases, those should be covered
325 // in tests for those FocusRules implementations.
326 class TestFocusRules : public BaseFocusRules {
327 public:
328 TestFocusRules() : focus_restriction_(NULL) {}
330 // Restricts focus and activation to this window and its child hierarchy.
331 void set_focus_restriction(aura::Window* focus_restriction) {
332 focus_restriction_ = focus_restriction;
335 // Overridden from BaseFocusRules:
336 bool SupportsChildActivation(aura::Window* window) const override {
337 // In FocusControllerTests, only the RootWindow has activatable children.
338 return window->GetRootWindow() == window;
340 bool CanActivateWindow(aura::Window* window) const override {
341 // Restricting focus to a non-activatable child window means the activatable
342 // parent outside the focus restriction is activatable.
343 bool can_activate =
344 CanFocusOrActivate(window) || window->Contains(focus_restriction_);
345 return can_activate ? BaseFocusRules::CanActivateWindow(window) : false;
347 bool CanFocusWindow(aura::Window* window) const override {
348 return CanFocusOrActivate(window) ?
349 BaseFocusRules::CanFocusWindow(window) : false;
351 aura::Window* GetActivatableWindow(aura::Window* window) const override {
352 return BaseFocusRules::GetActivatableWindow(
353 CanFocusOrActivate(window) ? window : focus_restriction_);
355 aura::Window* GetFocusableWindow(aura::Window* window) const override {
356 return BaseFocusRules::GetFocusableWindow(
357 CanFocusOrActivate(window) ? window : focus_restriction_);
359 aura::Window* GetNextActivatableWindow(aura::Window* ignore) const override {
360 aura::Window* next_activatable =
361 BaseFocusRules::GetNextActivatableWindow(ignore);
362 return CanFocusOrActivate(next_activatable) ?
363 next_activatable : GetActivatableWindow(focus_restriction_);
366 private:
367 bool CanFocusOrActivate(aura::Window* window) const {
368 return !focus_restriction_ || focus_restriction_->Contains(window);
371 aura::Window* focus_restriction_;
373 DISALLOW_COPY_AND_ASSIGN(TestFocusRules);
376 // Common infrastructure shared by all FocusController test types.
377 class FocusControllerTestBase : public aura::test::AuraTestBase {
378 protected:
379 FocusControllerTestBase() {}
381 // Overridden from aura::test::AuraTestBase:
382 void SetUp() override {
383 wm_state_.reset(new wm::WMState);
384 // FocusController registers itself as an Env observer so it can catch all
385 // window initializations, including the root_window()'s, so we create it
386 // before allowing the base setup.
387 test_focus_rules_ = new TestFocusRules;
388 focus_controller_.reset(new FocusController(test_focus_rules_));
389 aura::test::AuraTestBase::SetUp();
390 root_window()->AddPreTargetHandler(focus_controller_.get());
391 aura::client::SetFocusClient(root_window(), focus_controller_.get());
392 aura::client::SetActivationClient(root_window(), focus_controller_.get());
394 // Hierarchy used by all tests:
395 // root_window
396 // +-- w1
397 // | +-- w11
398 // | +-- w12
399 // +-- w2
400 // | +-- w21
401 // | +-- w211
402 // +-- w3
403 aura::Window* w1 = aura::test::CreateTestWindowWithDelegate(
404 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 1,
405 gfx::Rect(0, 0, 50, 50), root_window());
406 aura::test::CreateTestWindowWithDelegate(
407 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 11,
408 gfx::Rect(5, 5, 10, 10), w1);
409 aura::test::CreateTestWindowWithDelegate(
410 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 12,
411 gfx::Rect(15, 15, 10, 10), w1);
412 aura::Window* w2 = aura::test::CreateTestWindowWithDelegate(
413 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 2,
414 gfx::Rect(75, 75, 50, 50), root_window());
415 aura::Window* w21 = aura::test::CreateTestWindowWithDelegate(
416 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 21,
417 gfx::Rect(5, 5, 10, 10), w2);
418 aura::test::CreateTestWindowWithDelegate(
419 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 211,
420 gfx::Rect(1, 1, 5, 5), w21);
421 aura::test::CreateTestWindowWithDelegate(
422 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3,
423 gfx::Rect(125, 125, 50, 50), root_window());
425 void TearDown() override {
426 root_window()->RemovePreTargetHandler(focus_controller_.get());
427 aura::test::AuraTestBase::TearDown();
428 test_focus_rules_ = NULL; // Owned by FocusController.
429 focus_controller_.reset();
430 wm_state_.reset();
433 void FocusWindow(aura::Window* window) {
434 aura::client::GetFocusClient(root_window())->FocusWindow(window);
436 aura::Window* GetFocusedWindow() {
437 return aura::client::GetFocusClient(root_window())->GetFocusedWindow();
439 int GetFocusedWindowId() {
440 aura::Window* focused_window = GetFocusedWindow();
441 return focused_window ? focused_window->id() : -1;
443 void ActivateWindow(aura::Window* window) {
444 aura::client::GetActivationClient(root_window())->ActivateWindow(window);
446 void DeactivateWindow(aura::Window* window) {
447 aura::client::GetActivationClient(root_window())->DeactivateWindow(window);
449 aura::Window* GetActiveWindow() {
450 return aura::client::GetActivationClient(root_window())->GetActiveWindow();
452 int GetActiveWindowId() {
453 aura::Window* active_window = GetActiveWindow();
454 return active_window ? active_window->id() : -1;
457 TestFocusRules* test_focus_rules() { return test_focus_rules_; }
459 // Test functions.
460 virtual void BasicFocus() = 0;
461 virtual void BasicActivation() = 0;
462 virtual void FocusEvents() = 0;
463 virtual void DuplicateFocusEvents() {}
464 virtual void ActivationEvents() = 0;
465 virtual void ReactivationEvents() {}
466 virtual void DuplicateActivationEvents() {}
467 virtual void ShiftFocusWithinActiveWindow() {}
468 virtual void ShiftFocusToChildOfInactiveWindow() {}
469 virtual void ShiftFocusToParentOfFocusedWindow() {}
470 virtual void FocusRulesOverride() = 0;
471 virtual void ActivationRulesOverride() = 0;
472 virtual void ShiftFocusOnActivation() {}
473 virtual void ShiftFocusOnActivationDueToHide() {}
474 virtual void NoShiftActiveOnActivation() {}
475 virtual void FocusChangeDuringDrag() {}
476 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {}
477 virtual void DontPassDeletedWindow() {}
478 virtual void FocusedTextInputClient() {}
480 private:
481 scoped_ptr<FocusController> focus_controller_;
482 TestFocusRules* test_focus_rules_;
483 scoped_ptr<wm::WMState> wm_state_;
485 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase);
488 // Test base for tests where focus is directly set to a target window.
489 class FocusControllerDirectTestBase : public FocusControllerTestBase {
490 protected:
491 FocusControllerDirectTestBase() {}
493 // Different test types shift focus in different ways.
494 virtual void FocusWindowDirect(aura::Window* window) = 0;
495 virtual void ActivateWindowDirect(aura::Window* window) = 0;
496 virtual void DeactivateWindowDirect(aura::Window* window) = 0;
498 // Input events do not change focus if the window can not be focused.
499 virtual bool IsInputEvent() = 0;
501 void FocusWindowById(int id) {
502 aura::Window* window = root_window()->GetChildById(id);
503 DCHECK(window);
504 FocusWindowDirect(window);
506 void ActivateWindowById(int id) {
507 aura::Window* window = root_window()->GetChildById(id);
508 DCHECK(window);
509 ActivateWindowDirect(window);
512 // Overridden from FocusControllerTestBase:
513 void BasicFocus() override {
514 EXPECT_EQ(NULL, GetFocusedWindow());
515 FocusWindowById(1);
516 EXPECT_EQ(1, GetFocusedWindowId());
517 FocusWindowById(2);
518 EXPECT_EQ(2, GetFocusedWindowId());
520 void BasicActivation() override {
521 EXPECT_EQ(NULL, GetActiveWindow());
522 ActivateWindowById(1);
523 EXPECT_EQ(1, GetActiveWindowId());
524 ActivateWindowById(2);
525 EXPECT_EQ(2, GetActiveWindowId());
526 // Verify that attempting to deactivate NULL does not crash and does not
527 // change activation.
528 DeactivateWindow(NULL);
529 EXPECT_EQ(2, GetActiveWindowId());
530 DeactivateWindow(GetActiveWindow());
531 EXPECT_EQ(1, GetActiveWindowId());
533 void FocusEvents() override {
534 ScopedFocusNotificationObserver root_observer(root_window());
535 ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
536 ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
538 root_observer.ExpectCounts(0, 0);
539 observer1.ExpectCounts(0, 0);
540 observer2.ExpectCounts(0, 0);
542 FocusWindowById(1);
543 root_observer.ExpectCounts(1, 1);
544 observer1.ExpectCounts(1, 1);
545 observer2.ExpectCounts(0, 0);
547 FocusWindowById(2);
548 root_observer.ExpectCounts(2, 2);
549 observer1.ExpectCounts(2, 2);
550 observer2.ExpectCounts(1, 1);
552 void DuplicateFocusEvents() override {
553 // Focusing an existing focused window should not resend focus events.
554 ScopedFocusNotificationObserver root_observer(root_window());
555 ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
557 root_observer.ExpectCounts(0, 0);
558 observer1.ExpectCounts(0, 0);
560 FocusWindowById(1);
561 root_observer.ExpectCounts(1, 1);
562 observer1.ExpectCounts(1, 1);
564 FocusWindowById(1);
565 root_observer.ExpectCounts(1, 1);
566 observer1.ExpectCounts(1, 1);
568 void ActivationEvents() override {
569 ActivateWindowById(1);
571 ScopedFocusNotificationObserver root_observer(root_window());
572 ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
573 ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
575 root_observer.ExpectCounts(0, 0);
576 observer1.ExpectCounts(0, 0);
577 observer2.ExpectCounts(0, 0);
579 ActivateWindowById(2);
580 root_observer.ExpectCounts(1, 1);
581 observer1.ExpectCounts(1, 1);
582 observer2.ExpectCounts(1, 1);
584 void ReactivationEvents() override {
585 ActivateWindowById(1);
586 ScopedFocusNotificationObserver root_observer(root_window());
587 EXPECT_EQ(0, root_observer.reactivation_count());
588 root_window()->GetChildById(2)->Hide();
589 // When we attempt to activate "2", which cannot be activated because it
590 // is not visible, "1" will be reactivated.
591 ActivateWindowById(2);
592 EXPECT_EQ(1, root_observer.reactivation_count());
593 EXPECT_EQ(root_window()->GetChildById(2),
594 root_observer.reactivation_requested_window());
595 EXPECT_EQ(root_window()->GetChildById(1),
596 root_observer.reactivation_actual_window());
598 void DuplicateActivationEvents() override {
599 // Activating an existing active window should not resend activation events.
600 ActivateWindowById(1);
602 ScopedFocusNotificationObserver root_observer(root_window());
603 ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
604 ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
606 root_observer.ExpectCounts(0, 0);
607 observer1.ExpectCounts(0, 0);
608 observer2.ExpectCounts(0, 0);
610 ActivateWindowById(2);
611 root_observer.ExpectCounts(1, 1);
612 observer1.ExpectCounts(1, 1);
613 observer2.ExpectCounts(1, 1);
615 ActivateWindowById(2);
616 root_observer.ExpectCounts(1, 1);
617 observer1.ExpectCounts(1, 1);
618 observer2.ExpectCounts(1, 1);
620 void ShiftFocusWithinActiveWindow() override {
621 ActivateWindowById(1);
622 EXPECT_EQ(1, GetActiveWindowId());
623 EXPECT_EQ(1, GetFocusedWindowId());
624 FocusWindowById(11);
625 EXPECT_EQ(11, GetFocusedWindowId());
626 FocusWindowById(12);
627 EXPECT_EQ(12, GetFocusedWindowId());
629 void ShiftFocusToChildOfInactiveWindow() override {
630 ActivateWindowById(2);
631 EXPECT_EQ(2, GetActiveWindowId());
632 EXPECT_EQ(2, GetFocusedWindowId());
633 FocusWindowById(11);
634 EXPECT_EQ(1, GetActiveWindowId());
635 EXPECT_EQ(11, GetFocusedWindowId());
637 void ShiftFocusToParentOfFocusedWindow() override {
638 ActivateWindowById(1);
639 EXPECT_EQ(1, GetFocusedWindowId());
640 FocusWindowById(11);
641 EXPECT_EQ(11, GetFocusedWindowId());
642 FocusWindowById(1);
643 // Focus should _not_ shift to the parent of the already-focused window.
644 EXPECT_EQ(11, GetFocusedWindowId());
646 void FocusRulesOverride() override {
647 EXPECT_EQ(NULL, GetFocusedWindow());
648 FocusWindowById(11);
649 EXPECT_EQ(11, GetFocusedWindowId());
651 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(211));
652 FocusWindowById(12);
653 // Input events leave focus unchanged; direct API calls will change focus
654 // to the restricted window.
655 int focused_window = IsInputEvent() ? 11 : 211;
656 EXPECT_EQ(focused_window, GetFocusedWindowId());
658 test_focus_rules()->set_focus_restriction(NULL);
659 FocusWindowById(12);
660 EXPECT_EQ(12, GetFocusedWindowId());
662 void ActivationRulesOverride() override {
663 ActivateWindowById(1);
664 EXPECT_EQ(1, GetActiveWindowId());
665 EXPECT_EQ(1, GetFocusedWindowId());
667 aura::Window* w3 = root_window()->GetChildById(3);
668 test_focus_rules()->set_focus_restriction(w3);
670 ActivateWindowById(2);
671 // Input events leave activation unchanged; direct API calls will activate
672 // the restricted window.
673 int active_window = IsInputEvent() ? 1 : 3;
674 EXPECT_EQ(active_window, GetActiveWindowId());
675 EXPECT_EQ(active_window, GetFocusedWindowId());
677 test_focus_rules()->set_focus_restriction(NULL);
678 ActivateWindowById(2);
679 EXPECT_EQ(2, GetActiveWindowId());
680 EXPECT_EQ(2, GetFocusedWindowId());
682 void ShiftFocusOnActivation() override {
683 // When a window is activated, by default that window is also focused.
684 // An ActivationChangeObserver may shift focus to another window within the
685 // same activatable window.
686 ActivateWindowById(2);
687 EXPECT_EQ(2, GetFocusedWindowId());
688 ActivateWindowById(1);
689 EXPECT_EQ(1, GetFocusedWindowId());
691 ActivateWindowById(2);
693 aura::Window* target = root_window()->GetChildById(1);
694 aura::client::ActivationClient* client =
695 aura::client::GetActivationClient(root_window());
697 scoped_ptr<FocusShiftingActivationObserver> observer(
698 new FocusShiftingActivationObserver(target));
699 observer->set_shift_focus_to(target->GetChildById(11));
700 client->AddObserver(observer.get());
702 ActivateWindowById(1);
704 // w1's ActivationChangeObserver shifted focus to this child, pre-empting
705 // FocusController's default setting.
706 EXPECT_EQ(11, GetFocusedWindowId());
708 ActivateWindowById(2);
709 EXPECT_EQ(2, GetFocusedWindowId());
711 // Simulate a focus reset by the ActivationChangeObserver. This should
712 // trigger the default setting in FocusController.
713 observer->set_shift_focus_to(NULL);
714 ActivateWindowById(1);
715 EXPECT_EQ(1, GetFocusedWindowId());
717 client->RemoveObserver(observer.get());
719 ActivateWindowById(2);
720 EXPECT_EQ(2, GetFocusedWindowId());
721 ActivateWindowById(1);
722 EXPECT_EQ(1, GetFocusedWindowId());
724 void ShiftFocusOnActivationDueToHide() override {
725 // Similar to ShiftFocusOnActivation except the activation change is
726 // triggered by hiding the active window.
727 ActivateWindowById(1);
728 EXPECT_EQ(1, GetFocusedWindowId());
730 // Removes window 3 as candidate for next activatable window.
731 root_window()->GetChildById(3)->Hide();
732 EXPECT_EQ(1, GetFocusedWindowId());
734 aura::Window* target = root_window()->GetChildById(2);
735 aura::client::ActivationClient* client =
736 aura::client::GetActivationClient(root_window());
738 scoped_ptr<FocusShiftingActivationObserver> observer(
739 new FocusShiftingActivationObserver(target));
740 observer->set_shift_focus_to(target->GetChildById(21));
741 client->AddObserver(observer.get());
743 // Hide the active window.
744 root_window()->GetChildById(1)->Hide();
746 EXPECT_EQ(21, GetFocusedWindowId());
748 client->RemoveObserver(observer.get());
750 void NoShiftActiveOnActivation() override {
751 // When a window is activated, we need to prevent any change to activation
752 // from being made in response to an activation change notification.
755 void FocusChangeDuringDrag() override {
756 scoped_ptr<aura::client::DefaultCaptureClient> capture_client(
757 new aura::client::DefaultCaptureClient(root_window()));
758 // Activating an inactive window during drag should activate the window.
759 // This emulates the behavior of tab dragging which is merged into the
760 // window below.
761 ActivateWindowById(1);
763 EXPECT_EQ(1, GetActiveWindowId());
764 EXPECT_EQ(1, GetFocusedWindowId());
766 aura::Window* w2 = root_window()->GetChildById(2);
767 ui::test::EventGenerator generator(root_window(), w2);
768 generator.PressLeftButton();
769 aura::client::GetCaptureClient(root_window())->SetCapture(w2);
770 EXPECT_EQ(2, GetActiveWindowId());
771 EXPECT_EQ(2, GetFocusedWindowId());
772 generator.MoveMouseTo(gfx::Point(0, 0));
774 // Emulate the behavior of merging a tab into an inactive window:
775 // transferring the mouse capture and activate the window.
776 aura::Window* w1 = root_window()->GetChildById(1);
777 aura::client::GetCaptureClient(root_window())->SetCapture(w1);
778 aura::client::GetActivationClient(root_window())->ActivateWindow(w1);
779 EXPECT_EQ(1, GetActiveWindowId());
780 EXPECT_EQ(1, GetFocusedWindowId());
782 generator.ReleaseLeftButton();
783 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1);
786 // Verifies focus change is honored while capture held.
787 void ChangeFocusWhenNothingFocusedAndCaptured() override {
788 scoped_ptr<aura::client::DefaultCaptureClient> capture_client(
789 new aura::client::DefaultCaptureClient(root_window()));
790 aura::Window* w1 = root_window()->GetChildById(1);
791 aura::client::GetCaptureClient(root_window())->SetCapture(w1);
793 EXPECT_EQ(-1, GetActiveWindowId());
794 EXPECT_EQ(-1, GetFocusedWindowId());
796 FocusWindowById(1);
798 EXPECT_EQ(1, GetActiveWindowId());
799 EXPECT_EQ(1, GetFocusedWindowId());
801 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1);
804 // Verifies if a window that loses activation or focus is deleted during
805 // observer notification we don't pass the deleted window to other observers.
806 void DontPassDeletedWindow() override {
807 FocusWindowById(1);
809 EXPECT_EQ(1, GetActiveWindowId());
810 EXPECT_EQ(1, GetFocusedWindowId());
813 aura::Window* to_delete = root_window()->GetChildById(1);
814 DeleteOnLoseActivationChangeObserver observer1(to_delete);
815 RecordingActivationAndFocusChangeObserver observer2(root_window(),
816 &observer1);
818 FocusWindowById(2);
820 EXPECT_EQ(2, GetActiveWindowId());
821 EXPECT_EQ(2, GetFocusedWindowId());
823 EXPECT_EQ(to_delete, observer1.GetDeletedWindow());
824 EXPECT_FALSE(observer2.was_notified_with_deleted_window());
828 aura::Window* to_delete = root_window()->GetChildById(2);
829 DeleteOnLoseFocusChangeObserver observer1(to_delete);
830 RecordingActivationAndFocusChangeObserver observer2(root_window(),
831 &observer1);
833 FocusWindowById(3);
835 EXPECT_EQ(3, GetActiveWindowId());
836 EXPECT_EQ(3, GetFocusedWindowId());
838 EXPECT_EQ(to_delete, observer1.GetDeletedWindow());
839 EXPECT_FALSE(observer2.was_notified_with_deleted_window());
843 // Verifies if the focused text input client is cleared when a window gains
844 // or loses the focus.
845 void FocusedTextInputClient() override {
846 ui::TextInputFocusManager* text_input_focus_manager =
847 ui::TextInputFocusManager::GetInstance();
848 ui::DummyTextInputClient text_input_client;
849 ui::TextInputClient* null_text_input_client = NULL;
851 EXPECT_EQ(null_text_input_client,
852 text_input_focus_manager->GetFocusedTextInputClient());
854 text_input_focus_manager->FocusTextInputClient(&text_input_client);
855 EXPECT_EQ(&text_input_client,
856 text_input_focus_manager->GetFocusedTextInputClient());
857 FocusWindowById(1);
858 // The focused text input client gets cleared when a window gets focused
859 // unless any of observers sets the focused text input client.
860 EXPECT_EQ(null_text_input_client,
861 text_input_focus_manager->GetFocusedTextInputClient());
863 ScopedFocusedTextInputClientChanger text_input_focus_changer(
864 root_window(), &text_input_client);
865 EXPECT_EQ(null_text_input_client,
866 text_input_focus_manager->GetFocusedTextInputClient());
867 FocusWindowById(2);
868 // |text_input_focus_changer| sets the focused text input client.
869 EXPECT_EQ(&text_input_client,
870 text_input_focus_manager->GetFocusedTextInputClient());
872 FocusWindow(NULL);
873 // The focused text input client gets cleared when a window loses the focus.
874 EXPECT_EQ(null_text_input_client,
875 text_input_focus_manager->GetFocusedTextInputClient());
878 private:
879 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase);
882 // Focus and Activation changes via aura::client::ActivationClient API.
883 class FocusControllerApiTest : public FocusControllerDirectTestBase {
884 public:
885 FocusControllerApiTest() {}
887 private:
888 // Overridden from FocusControllerTestBase:
889 void FocusWindowDirect(aura::Window* window) override { FocusWindow(window); }
890 void ActivateWindowDirect(aura::Window* window) override {
891 ActivateWindow(window);
893 void DeactivateWindowDirect(aura::Window* window) override {
894 DeactivateWindow(window);
896 bool IsInputEvent() override { return false; }
898 DISALLOW_COPY_AND_ASSIGN(FocusControllerApiTest);
901 // Focus and Activation changes via input events.
902 class FocusControllerMouseEventTest : public FocusControllerDirectTestBase {
903 public:
904 FocusControllerMouseEventTest() {}
906 // Tests that a handled mouse or gesture event does not trigger a window
907 // activation.
908 void IgnoreHandledEvent() {
909 EXPECT_EQ(NULL, GetActiveWindow());
910 aura::Window* w1 = root_window()->GetChildById(1);
911 SimpleEventHandler handler;
912 root_window()->PrependPreTargetHandler(&handler);
913 ui::test::EventGenerator generator(root_window(), w1);
914 generator.ClickLeftButton();
915 EXPECT_EQ(NULL, GetActiveWindow());
916 generator.GestureTapAt(w1->bounds().CenterPoint());
917 EXPECT_EQ(NULL, GetActiveWindow());
918 root_window()->RemovePreTargetHandler(&handler);
919 generator.ClickLeftButton();
920 EXPECT_EQ(1, GetActiveWindowId());
923 private:
924 // Overridden from FocusControllerTestBase:
925 void FocusWindowDirect(aura::Window* window) override {
926 ui::test::EventGenerator generator(root_window(), window);
927 generator.ClickLeftButton();
929 void ActivateWindowDirect(aura::Window* window) override {
930 ui::test::EventGenerator generator(root_window(), window);
931 generator.ClickLeftButton();
933 void DeactivateWindowDirect(aura::Window* window) override {
934 aura::Window* next_activatable =
935 test_focus_rules()->GetNextActivatableWindow(window);
936 ui::test::EventGenerator generator(root_window(), next_activatable);
937 generator.ClickLeftButton();
939 bool IsInputEvent() override { return true; }
941 DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest);
944 class FocusControllerGestureEventTest : public FocusControllerDirectTestBase {
945 public:
946 FocusControllerGestureEventTest() {}
948 private:
949 // Overridden from FocusControllerTestBase:
950 void FocusWindowDirect(aura::Window* window) override {
951 ui::test::EventGenerator generator(root_window(), window);
952 generator.GestureTapAt(window->bounds().CenterPoint());
954 void ActivateWindowDirect(aura::Window* window) override {
955 ui::test::EventGenerator generator(root_window(), window);
956 generator.GestureTapAt(window->bounds().CenterPoint());
958 void DeactivateWindowDirect(aura::Window* window) override {
959 aura::Window* next_activatable =
960 test_focus_rules()->GetNextActivatableWindow(window);
961 ui::test::EventGenerator generator(root_window(), next_activatable);
962 generator.GestureTapAt(window->bounds().CenterPoint());
964 bool IsInputEvent() override { return true; }
966 DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest);
969 // Test base for tests where focus is implicitly set to a window as the result
970 // of a disposition change to the focused window or the hierarchy that contains
971 // it.
972 class FocusControllerImplicitTestBase : public FocusControllerTestBase {
973 protected:
974 explicit FocusControllerImplicitTestBase(bool parent) : parent_(parent) {}
976 aura::Window* GetDispositionWindow(aura::Window* window) {
977 return parent_ ? window->parent() : window;
980 // Change the disposition of |window| in such a way as it will lose focus.
981 virtual void ChangeWindowDisposition(aura::Window* window) = 0;
983 // Allow each disposition change test to add additional post-disposition
984 // change expectations.
985 virtual void PostDispositionChangeExpectations() {}
987 // Overridden from FocusControllerTestBase:
988 void BasicFocus() override {
989 EXPECT_EQ(NULL, GetFocusedWindow());
991 aura::Window* w211 = root_window()->GetChildById(211);
992 FocusWindow(w211);
993 EXPECT_EQ(211, GetFocusedWindowId());
995 ChangeWindowDisposition(w211);
996 // BasicFocusRules passes focus to the parent.
997 EXPECT_EQ(parent_ ? 2 : 21, GetFocusedWindowId());
999 void BasicActivation() override {
1000 DCHECK(!parent_) << "Activation tests don't support parent changes.";
1002 EXPECT_EQ(NULL, GetActiveWindow());
1004 aura::Window* w2 = root_window()->GetChildById(2);
1005 ActivateWindow(w2);
1006 EXPECT_EQ(2, GetActiveWindowId());
1008 ChangeWindowDisposition(w2);
1009 EXPECT_EQ(3, GetActiveWindowId());
1010 PostDispositionChangeExpectations();
1012 void FocusEvents() override {
1013 aura::Window* w211 = root_window()->GetChildById(211);
1014 FocusWindow(w211);
1016 ScopedFocusNotificationObserver root_observer(root_window());
1017 ScopedTargetFocusNotificationObserver observer211(root_window(), 211);
1018 root_observer.ExpectCounts(0, 0);
1019 observer211.ExpectCounts(0, 0);
1021 ChangeWindowDisposition(w211);
1022 root_observer.ExpectCounts(0, 1);
1023 observer211.ExpectCounts(0, 1);
1025 void ActivationEvents() override {
1026 DCHECK(!parent_) << "Activation tests don't support parent changes.";
1028 aura::Window* w2 = root_window()->GetChildById(2);
1029 ActivateWindow(w2);
1031 ScopedFocusNotificationObserver root_observer(root_window());
1032 ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
1033 ScopedTargetFocusNotificationObserver observer3(root_window(), 3);
1034 root_observer.ExpectCounts(0, 0);
1035 observer2.ExpectCounts(0, 0);
1036 observer3.ExpectCounts(0, 0);
1038 ChangeWindowDisposition(w2);
1039 root_observer.ExpectCounts(1, 1);
1040 observer2.ExpectCounts(1, 1);
1041 observer3.ExpectCounts(1, 1);
1043 void FocusRulesOverride() override {
1044 EXPECT_EQ(NULL, GetFocusedWindow());
1045 aura::Window* w211 = root_window()->GetChildById(211);
1046 FocusWindow(w211);
1047 EXPECT_EQ(211, GetFocusedWindowId());
1049 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(11));
1050 ChangeWindowDisposition(w211);
1051 // Normally, focus would shift to the parent (w21) but the override shifts
1052 // it to 11.
1053 EXPECT_EQ(11, GetFocusedWindowId());
1055 test_focus_rules()->set_focus_restriction(NULL);
1057 void ActivationRulesOverride() override {
1058 DCHECK(!parent_) << "Activation tests don't support parent changes.";
1060 aura::Window* w1 = root_window()->GetChildById(1);
1061 ActivateWindow(w1);
1063 EXPECT_EQ(1, GetActiveWindowId());
1064 EXPECT_EQ(1, GetFocusedWindowId());
1066 aura::Window* w3 = root_window()->GetChildById(3);
1067 test_focus_rules()->set_focus_restriction(w3);
1069 // Normally, activation/focus would move to w2, but since we have a focus
1070 // restriction, it should move to w3 instead.
1071 ChangeWindowDisposition(w1);
1072 EXPECT_EQ(3, GetActiveWindowId());
1073 EXPECT_EQ(3, GetFocusedWindowId());
1075 test_focus_rules()->set_focus_restriction(NULL);
1076 ActivateWindow(root_window()->GetChildById(2));
1077 EXPECT_EQ(2, GetActiveWindowId());
1078 EXPECT_EQ(2, GetFocusedWindowId());
1081 private:
1082 // When true, the disposition change occurs to the parent of the window
1083 // instead of to the window. This verifies that changes occurring in the
1084 // hierarchy that contains the window affect the window's focus.
1085 bool parent_;
1087 DISALLOW_COPY_AND_ASSIGN(FocusControllerImplicitTestBase);
1090 // Focus and Activation changes in response to window visibility changes.
1091 class FocusControllerHideTest : public FocusControllerImplicitTestBase {
1092 public:
1093 FocusControllerHideTest() : FocusControllerImplicitTestBase(false) {}
1095 protected:
1096 FocusControllerHideTest(bool parent)
1097 : FocusControllerImplicitTestBase(parent) {}
1099 // Overridden from FocusControllerImplicitTestBase:
1100 void ChangeWindowDisposition(aura::Window* window) override {
1101 GetDispositionWindow(window)->Hide();
1104 private:
1105 DISALLOW_COPY_AND_ASSIGN(FocusControllerHideTest);
1108 // Focus and Activation changes in response to window parent visibility
1109 // changes.
1110 class FocusControllerParentHideTest : public FocusControllerHideTest {
1111 public:
1112 FocusControllerParentHideTest() : FocusControllerHideTest(true) {}
1114 private:
1115 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentHideTest);
1118 // Focus and Activation changes in response to window destruction.
1119 class FocusControllerDestructionTest : public FocusControllerImplicitTestBase {
1120 public:
1121 FocusControllerDestructionTest() : FocusControllerImplicitTestBase(false) {}
1123 protected:
1124 FocusControllerDestructionTest(bool parent)
1125 : FocusControllerImplicitTestBase(parent) {}
1127 // Overridden from FocusControllerImplicitTestBase:
1128 void ChangeWindowDisposition(aura::Window* window) override {
1129 delete GetDispositionWindow(window);
1132 private:
1133 DISALLOW_COPY_AND_ASSIGN(FocusControllerDestructionTest);
1136 // Focus and Activation changes in response to window parent destruction.
1137 class FocusControllerParentDestructionTest
1138 : public FocusControllerDestructionTest {
1139 public:
1140 FocusControllerParentDestructionTest()
1141 : FocusControllerDestructionTest(true) {}
1143 private:
1144 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentDestructionTest);
1147 // Focus and Activation changes in response to window removal.
1148 class FocusControllerRemovalTest : public FocusControllerImplicitTestBase {
1149 public:
1150 FocusControllerRemovalTest() : FocusControllerImplicitTestBase(false) {}
1152 protected:
1153 FocusControllerRemovalTest(bool parent)
1154 : FocusControllerImplicitTestBase(parent) {}
1156 // Overridden from FocusControllerImplicitTestBase:
1157 void ChangeWindowDisposition(aura::Window* window) override {
1158 aura::Window* disposition_window = GetDispositionWindow(window);
1159 disposition_window->parent()->RemoveChild(disposition_window);
1160 window_owner_.reset(disposition_window);
1162 void TearDown() override {
1163 window_owner_.reset();
1164 FocusControllerImplicitTestBase::TearDown();
1167 private:
1168 scoped_ptr<aura::Window> window_owner_;
1170 DISALLOW_COPY_AND_ASSIGN(FocusControllerRemovalTest);
1173 // Focus and Activation changes in response to window parent removal.
1174 class FocusControllerParentRemovalTest : public FocusControllerRemovalTest {
1175 public:
1176 FocusControllerParentRemovalTest() : FocusControllerRemovalTest(true) {}
1178 private:
1179 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentRemovalTest);
1183 #define FOCUS_CONTROLLER_TEST(TESTCLASS, TESTNAME) \
1184 TEST_F(TESTCLASS, TESTNAME) { TESTNAME(); }
1186 // Runs direct focus change tests (input events and API calls).
1187 #define DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1188 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, TESTNAME) \
1189 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, TESTNAME) \
1190 FOCUS_CONTROLLER_TEST(FocusControllerGestureEventTest, TESTNAME)
1192 // Runs implicit focus change tests for disposition changes to target.
1193 #define IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME) \
1194 FOCUS_CONTROLLER_TEST(FocusControllerHideTest, TESTNAME) \
1195 FOCUS_CONTROLLER_TEST(FocusControllerDestructionTest, TESTNAME) \
1196 FOCUS_CONTROLLER_TEST(FocusControllerRemovalTest, TESTNAME)
1198 // Runs implicit focus change tests for disposition changes to target's parent
1199 // hierarchy.
1200 #define IMPLICIT_FOCUS_CHANGE_PARENT_TESTS(TESTNAME) \
1201 /* TODO(beng): parent destruction tests are not supported at
1202 present due to workspace manager issues. \
1203 FOCUS_CONTROLLER_TEST(FocusControllerParentDestructionTest, TESTNAME) */ \
1204 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, TESTNAME) \
1205 FOCUS_CONTROLLER_TEST(FocusControllerParentRemovalTest, TESTNAME)
1207 // Runs all implicit focus change tests (changes to the target and target's
1208 // parent hierarchy)
1209 #define IMPLICIT_FOCUS_CHANGE_TESTS(TESTNAME) \
1210 IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME) \
1211 IMPLICIT_FOCUS_CHANGE_PARENT_TESTS(TESTNAME)
1213 // Runs all possible focus change tests.
1214 #define ALL_FOCUS_TESTS(TESTNAME) \
1215 DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1216 IMPLICIT_FOCUS_CHANGE_TESTS(TESTNAME)
1218 // Runs focus change tests that apply only to the target. For example,
1219 // implicit activation changes caused by window disposition changes do not
1220 // occur when changes to the containing hierarchy happen.
1221 #define TARGET_FOCUS_TESTS(TESTNAME) \
1222 DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1223 IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME)
1225 // - Focuses a window, verifies that focus changed.
1226 ALL_FOCUS_TESTS(BasicFocus);
1228 // - Activates a window, verifies that activation changed.
1229 TARGET_FOCUS_TESTS(BasicActivation);
1231 // - Focuses a window, verifies that focus events were dispatched.
1232 ALL_FOCUS_TESTS(FocusEvents);
1234 // - Focuses or activates a window multiple times, verifies that events are only
1235 // dispatched when focus/activation actually changes.
1236 DIRECT_FOCUS_CHANGE_TESTS(DuplicateFocusEvents);
1237 DIRECT_FOCUS_CHANGE_TESTS(DuplicateActivationEvents);
1239 // - Activates a window, verifies that activation events were dispatched.
1240 TARGET_FOCUS_TESTS(ActivationEvents);
1242 // - Attempts to active a hidden window, verifies that current window is
1243 // attempted to be reactivated and the appropriate event dispatched.
1244 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, ReactivationEvents);
1246 // - Input events/API calls shift focus between focusable windows within the
1247 // active window.
1248 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusWithinActiveWindow);
1250 // - Input events/API calls to a child window of an inactive window shifts
1251 // activation to the activatable parent and focuses the child.
1252 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToChildOfInactiveWindow);
1254 // - Input events/API calls to focus the parent of the focused window do not
1255 // shift focus away from the child.
1256 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToParentOfFocusedWindow);
1258 // - Verifies that FocusRules determine what can be focused.
1259 ALL_FOCUS_TESTS(FocusRulesOverride);
1261 // - Verifies that FocusRules determine what can be activated.
1262 TARGET_FOCUS_TESTS(ActivationRulesOverride);
1264 // - Verifies that attempts to change focus or activation from a focus or
1265 // activation change observer are ignored.
1266 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation);
1267 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide);
1268 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation);
1270 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, FocusChangeDuringDrag);
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
1279 // changes.
1280 ALL_FOCUS_TESTS(FocusedTextInputClient);
1282 // If a mouse event was handled, it should not activate a window.
1283 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent);
1285 } // namespace wm