Exclude TrayIMETest.PerformActionOnDetailedView under valgrind, where it crashes.
[chromium-blink-merge.git] / ui / wm / core / focus_controller_unittest.cc
blobd871777565cfc927858269a59866f16f8af5c0dc
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/events/event.h"
19 #include "ui/events/event_constants.h"
20 #include "ui/events/event_handler.h"
21 #include "ui/events/test/event_generator.h"
22 #include "ui/wm/core/base_focus_rules.h"
23 #include "ui/wm/core/window_util.h"
24 #include "ui/wm/core/wm_state.h"
25 #include "ui/wm/public/activation_change_observer.h"
26 #include "ui/wm/public/activation_client.h"
28 namespace wm {
30 class FocusNotificationObserver : public aura::client::ActivationChangeObserver,
31 public aura::client::FocusChangeObserver {
32 public:
33 FocusNotificationObserver()
34 : last_activation_reason_(ActivationReason::ACTIVATION_CLIENT),
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 ActivationReason last_activation_reason() const {
47 return last_activation_reason_;
49 int reactivation_count() const {
50 return reactivation_count_;
52 aura::Window* reactivation_requested_window() const {
53 return reactivation_requested_window_;
55 aura::Window* reactivation_actual_window() const {
56 return reactivation_actual_window_;
59 private:
60 // Overridden from aura::client::ActivationChangeObserver:
61 void OnWindowActivated(ActivationReason reason,
62 aura::Window* gained_active,
63 aura::Window* lost_active) override {
64 last_activation_reason_ = reason;
65 ++activation_changed_count_;
67 void OnAttemptToReactivateWindow(aura::Window* request_active,
68 aura::Window* actual_active) override {
69 ++reactivation_count_;
70 reactivation_requested_window_ = request_active;
71 reactivation_actual_window_ = actual_active;
74 // Overridden from aura::client::FocusChangeObserver:
75 void OnWindowFocused(aura::Window* gained_focus,
76 aura::Window* lost_focus) override {
77 ++focus_changed_count_;
80 ActivationReason last_activation_reason_;
81 int activation_changed_count_;
82 int focus_changed_count_;
83 int reactivation_count_;
84 aura::Window* reactivation_requested_window_;
85 aura::Window* reactivation_actual_window_;
87 DISALLOW_COPY_AND_ASSIGN(FocusNotificationObserver);
90 class WindowDeleter {
91 public:
92 virtual aura::Window* GetDeletedWindow() = 0;
94 protected:
95 virtual ~WindowDeleter() {}
98 // ActivationChangeObserver and FocusChangeObserver that keeps track of whether
99 // it was notified about activation changes or focus changes with a deleted
100 // window.
101 class RecordingActivationAndFocusChangeObserver
102 : public aura::client::ActivationChangeObserver,
103 public aura::client::FocusChangeObserver {
104 public:
105 RecordingActivationAndFocusChangeObserver(aura::Window* root,
106 WindowDeleter* deleter)
107 : root_(root),
108 deleter_(deleter),
109 was_notified_with_deleted_window_(false) {
110 aura::client::GetActivationClient(root_)->AddObserver(this);
111 aura::client::GetFocusClient(root_)->AddObserver(this);
113 ~RecordingActivationAndFocusChangeObserver() override {
114 aura::client::GetActivationClient(root_)->RemoveObserver(this);
115 aura::client::GetFocusClient(root_)->RemoveObserver(this);
118 bool was_notified_with_deleted_window() const {
119 return was_notified_with_deleted_window_;
122 // Overridden from aura::client::ActivationChangeObserver:
123 void OnWindowActivated(ActivationReason reason,
124 aura::Window* gained_active,
125 aura::Window* lost_active) override {
126 if (lost_active && lost_active == deleter_->GetDeletedWindow())
127 was_notified_with_deleted_window_ = true;
130 // Overridden from aura::client::FocusChangeObserver:
131 void OnWindowFocused(aura::Window* gained_focus,
132 aura::Window* lost_focus) override {
133 if (lost_focus && lost_focus == deleter_->GetDeletedWindow())
134 was_notified_with_deleted_window_ = true;
137 private:
138 aura::Window* root_;
140 // Not owned.
141 WindowDeleter* deleter_;
143 // Whether the observer was notified about the loss of activation or the
144 // loss of focus with a window already deleted by |deleter_| as the
145 // |lost_active| or |lost_focus| parameter.
146 bool was_notified_with_deleted_window_;
148 DISALLOW_COPY_AND_ASSIGN(RecordingActivationAndFocusChangeObserver);
151 // ActivationChangeObserver that deletes the window losing activation.
152 class DeleteOnLoseActivationChangeObserver :
153 public aura::client::ActivationChangeObserver,
154 public WindowDeleter {
155 public:
156 explicit DeleteOnLoseActivationChangeObserver(aura::Window* window)
157 : root_(window->GetRootWindow()),
158 window_(window),
159 did_delete_(false) {
160 aura::client::GetActivationClient(root_)->AddObserver(this);
162 ~DeleteOnLoseActivationChangeObserver() override {
163 aura::client::GetActivationClient(root_)->RemoveObserver(this);
166 // Overridden from aura::client::ActivationChangeObserver:
167 void OnWindowActivated(ActivationReason reason,
168 aura::Window* gained_active,
169 aura::Window* lost_active) override {
170 if (window_ && lost_active == window_) {
171 delete lost_active;
172 did_delete_ = true;
176 // Overridden from WindowDeleter:
177 aura::Window* GetDeletedWindow() override {
178 return did_delete_ ? window_ : NULL;
181 private:
182 aura::Window* root_;
183 aura::Window* window_;
184 bool did_delete_;
186 DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseActivationChangeObserver);
189 // FocusChangeObserver that deletes the window losing focus.
190 class DeleteOnLoseFocusChangeObserver
191 : public aura::client::FocusChangeObserver,
192 public WindowDeleter {
193 public:
194 explicit DeleteOnLoseFocusChangeObserver(aura::Window* window)
195 : root_(window->GetRootWindow()),
196 window_(window),
197 did_delete_(false) {
198 aura::client::GetFocusClient(root_)->AddObserver(this);
200 ~DeleteOnLoseFocusChangeObserver() override {
201 aura::client::GetFocusClient(root_)->RemoveObserver(this);
204 // Overridden from aura::client::FocusChangeObserver:
205 void OnWindowFocused(aura::Window* gained_focus,
206 aura::Window* lost_focus) override {
207 if (window_ && lost_focus == window_) {
208 delete lost_focus;
209 did_delete_ = true;
213 // Overridden from WindowDeleter:
214 aura::Window* GetDeletedWindow() override {
215 return did_delete_ ? window_ : NULL;
218 private:
219 aura::Window* root_;
220 aura::Window* window_;
221 bool did_delete_;
223 DISALLOW_COPY_AND_ASSIGN(DeleteOnLoseFocusChangeObserver);
226 class ScopedFocusNotificationObserver : public FocusNotificationObserver {
227 public:
228 ScopedFocusNotificationObserver(aura::Window* root_window)
229 : root_window_(root_window) {
230 aura::client::GetActivationClient(root_window_)->AddObserver(this);
231 aura::client::GetFocusClient(root_window_)->AddObserver(this);
233 ~ScopedFocusNotificationObserver() override {
234 aura::client::GetActivationClient(root_window_)->RemoveObserver(this);
235 aura::client::GetFocusClient(root_window_)->RemoveObserver(this);
238 private:
239 aura::Window* root_window_;
241 DISALLOW_COPY_AND_ASSIGN(ScopedFocusNotificationObserver);
244 class ScopedTargetFocusNotificationObserver : public FocusNotificationObserver {
245 public:
246 ScopedTargetFocusNotificationObserver(aura::Window* root_window, int id)
247 : target_(root_window->GetChildById(id)) {
248 aura::client::SetActivationChangeObserver(target_, this);
249 aura::client::SetFocusChangeObserver(target_, this);
250 tracker_.Add(target_);
252 ~ScopedTargetFocusNotificationObserver() override {
253 if (tracker_.Contains(target_)) {
254 aura::client::SetActivationChangeObserver(target_, NULL);
255 aura::client::SetFocusChangeObserver(target_, NULL);
259 private:
260 aura::Window* target_;
261 aura::WindowTracker tracker_;
263 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver);
266 // Used to fake the handling of events in the pre-target phase.
267 class SimpleEventHandler : public ui::EventHandler {
268 public:
269 SimpleEventHandler() {}
270 ~SimpleEventHandler() override {}
272 // Overridden from ui::EventHandler:
273 void OnMouseEvent(ui::MouseEvent* event) override { event->SetHandled(); }
274 void OnGestureEvent(ui::GestureEvent* event) override { event->SetHandled(); }
276 private:
277 DISALLOW_COPY_AND_ASSIGN(SimpleEventHandler);
280 class FocusShiftingActivationObserver
281 : public aura::client::ActivationChangeObserver {
282 public:
283 explicit FocusShiftingActivationObserver(aura::Window* activated_window)
284 : activated_window_(activated_window),
285 shift_focus_to_(NULL) {}
286 ~FocusShiftingActivationObserver() override {}
288 void set_shift_focus_to(aura::Window* shift_focus_to) {
289 shift_focus_to_ = shift_focus_to;
292 private:
293 // Overridden from aura::client::ActivationChangeObserver:
294 void OnWindowActivated(ActivationReason reason,
295 aura::Window* gained_active,
296 aura::Window* lost_active) override {
297 // Shift focus to a child. This should prevent the default focusing from
298 // occurring in FocusController::FocusWindow().
299 if (gained_active == activated_window_) {
300 aura::client::FocusClient* client =
301 aura::client::GetFocusClient(gained_active);
302 client->FocusWindow(shift_focus_to_);
306 aura::Window* activated_window_;
307 aura::Window* shift_focus_to_;
309 DISALLOW_COPY_AND_ASSIGN(FocusShiftingActivationObserver);
312 // BaseFocusRules subclass that allows basic overrides of focus/activation to
313 // be tested. This is intended more as a test that the override system works at
314 // all, rather than as an exhaustive set of use cases, those should be covered
315 // in tests for those FocusRules implementations.
316 class TestFocusRules : public BaseFocusRules {
317 public:
318 TestFocusRules() : focus_restriction_(NULL) {}
320 // Restricts focus and activation to this window and its child hierarchy.
321 void set_focus_restriction(aura::Window* focus_restriction) {
322 focus_restriction_ = focus_restriction;
325 // Overridden from BaseFocusRules:
326 bool SupportsChildActivation(aura::Window* window) const override {
327 // In FocusControllerTests, only the RootWindow has activatable children.
328 return window->GetRootWindow() == window;
330 bool CanActivateWindow(aura::Window* window) const override {
331 // Restricting focus to a non-activatable child window means the activatable
332 // parent outside the focus restriction is activatable.
333 bool can_activate =
334 CanFocusOrActivate(window) || window->Contains(focus_restriction_);
335 return can_activate ? BaseFocusRules::CanActivateWindow(window) : false;
337 bool CanFocusWindow(aura::Window* window) const override {
338 return CanFocusOrActivate(window) ?
339 BaseFocusRules::CanFocusWindow(window) : false;
341 aura::Window* GetActivatableWindow(aura::Window* window) const override {
342 return BaseFocusRules::GetActivatableWindow(
343 CanFocusOrActivate(window) ? window : focus_restriction_);
345 aura::Window* GetFocusableWindow(aura::Window* window) const override {
346 return BaseFocusRules::GetFocusableWindow(
347 CanFocusOrActivate(window) ? window : focus_restriction_);
349 aura::Window* GetNextActivatableWindow(aura::Window* ignore) const override {
350 aura::Window* next_activatable =
351 BaseFocusRules::GetNextActivatableWindow(ignore);
352 return CanFocusOrActivate(next_activatable) ?
353 next_activatable : GetActivatableWindow(focus_restriction_);
356 private:
357 bool CanFocusOrActivate(aura::Window* window) const {
358 return !focus_restriction_ || focus_restriction_->Contains(window);
361 aura::Window* focus_restriction_;
363 DISALLOW_COPY_AND_ASSIGN(TestFocusRules);
366 // Common infrastructure shared by all FocusController test types.
367 class FocusControllerTestBase : public aura::test::AuraTestBase {
368 protected:
369 FocusControllerTestBase() {}
371 // Overridden from aura::test::AuraTestBase:
372 void SetUp() override {
373 wm_state_.reset(new wm::WMState);
374 // FocusController registers itself as an Env observer so it can catch all
375 // window initializations, including the root_window()'s, so we create it
376 // before allowing the base setup.
377 test_focus_rules_ = new TestFocusRules;
378 focus_controller_.reset(new FocusController(test_focus_rules_));
379 aura::test::AuraTestBase::SetUp();
380 root_window()->AddPreTargetHandler(focus_controller_.get());
381 aura::client::SetFocusClient(root_window(), focus_controller_.get());
382 aura::client::SetActivationClient(root_window(), focus_controller_.get());
384 // Hierarchy used by all tests:
385 // root_window
386 // +-- w1
387 // | +-- w11
388 // | +-- w12
389 // +-- w2
390 // | +-- w21
391 // | +-- w211
392 // +-- w3
393 aura::Window* w1 = aura::test::CreateTestWindowWithDelegate(
394 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 1,
395 gfx::Rect(0, 0, 50, 50), root_window());
396 aura::test::CreateTestWindowWithDelegate(
397 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 11,
398 gfx::Rect(5, 5, 10, 10), w1);
399 aura::test::CreateTestWindowWithDelegate(
400 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 12,
401 gfx::Rect(15, 15, 10, 10), w1);
402 aura::Window* w2 = aura::test::CreateTestWindowWithDelegate(
403 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 2,
404 gfx::Rect(75, 75, 50, 50), root_window());
405 aura::Window* w21 = aura::test::CreateTestWindowWithDelegate(
406 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 21,
407 gfx::Rect(5, 5, 10, 10), w2);
408 aura::test::CreateTestWindowWithDelegate(
409 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 211,
410 gfx::Rect(1, 1, 5, 5), w21);
411 aura::test::CreateTestWindowWithDelegate(
412 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3,
413 gfx::Rect(125, 125, 50, 50), root_window());
415 void TearDown() override {
416 root_window()->RemovePreTargetHandler(focus_controller_.get());
417 aura::test::AuraTestBase::TearDown();
418 test_focus_rules_ = NULL; // Owned by FocusController.
419 focus_controller_.reset();
420 wm_state_.reset();
423 void FocusWindow(aura::Window* window) {
424 aura::client::GetFocusClient(root_window())->FocusWindow(window);
426 aura::Window* GetFocusedWindow() {
427 return aura::client::GetFocusClient(root_window())->GetFocusedWindow();
429 int GetFocusedWindowId() {
430 aura::Window* focused_window = GetFocusedWindow();
431 return focused_window ? focused_window->id() : -1;
433 void ActivateWindow(aura::Window* window) {
434 aura::client::GetActivationClient(root_window())->ActivateWindow(window);
436 void DeactivateWindow(aura::Window* window) {
437 aura::client::GetActivationClient(root_window())->DeactivateWindow(window);
439 aura::Window* GetActiveWindow() {
440 return aura::client::GetActivationClient(root_window())->GetActiveWindow();
442 int GetActiveWindowId() {
443 aura::Window* active_window = GetActiveWindow();
444 return active_window ? active_window->id() : -1;
447 TestFocusRules* test_focus_rules() { return test_focus_rules_; }
449 // Test functions.
450 virtual void BasicFocus() = 0;
451 virtual void BasicActivation() = 0;
452 virtual void FocusEvents() = 0;
453 virtual void DuplicateFocusEvents() {}
454 virtual void ActivationEvents() = 0;
455 virtual void ReactivationEvents() {}
456 virtual void DuplicateActivationEvents() {}
457 virtual void ShiftFocusWithinActiveWindow() {}
458 virtual void ShiftFocusToChildOfInactiveWindow() {}
459 virtual void ShiftFocusToParentOfFocusedWindow() {}
460 virtual void FocusRulesOverride() = 0;
461 virtual void ActivationRulesOverride() = 0;
462 virtual void ShiftFocusOnActivation() {}
463 virtual void ShiftFocusOnActivationDueToHide() {}
464 virtual void NoShiftActiveOnActivation() {}
465 virtual void FocusChangeDuringDrag() {}
466 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {}
467 virtual void DontPassDeletedWindow() {}
468 virtual void StackWindowAtTopOnActivation() {}
470 private:
471 scoped_ptr<FocusController> focus_controller_;
472 TestFocusRules* test_focus_rules_;
473 scoped_ptr<wm::WMState> wm_state_;
475 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase);
478 // Test base for tests where focus is directly set to a target window.
479 class FocusControllerDirectTestBase : public FocusControllerTestBase {
480 protected:
481 FocusControllerDirectTestBase() {}
483 // Different test types shift focus in different ways.
484 virtual void FocusWindowDirect(aura::Window* window) = 0;
485 virtual void ActivateWindowDirect(aura::Window* window) = 0;
486 virtual void DeactivateWindowDirect(aura::Window* window) = 0;
488 // Input events do not change focus if the window can not be focused.
489 virtual bool IsInputEvent() = 0;
491 // Returns the expected ActivationReason caused by calling the
492 // ActivatedWindowDirect(...) or DeactivateWindowDirect(...) methods.
493 virtual aura::client::ActivationChangeObserver::ActivationReason
494 GetExpectedActivationReason() const = 0;
496 void FocusWindowById(int id) {
497 aura::Window* window = root_window()->GetChildById(id);
498 DCHECK(window);
499 FocusWindowDirect(window);
501 void ActivateWindowById(int id) {
502 aura::Window* window = root_window()->GetChildById(id);
503 DCHECK(window);
504 ActivateWindowDirect(window);
507 // Overridden from FocusControllerTestBase:
508 void BasicFocus() override {
509 EXPECT_EQ(NULL, GetFocusedWindow());
510 FocusWindowById(1);
511 EXPECT_EQ(1, GetFocusedWindowId());
512 FocusWindowById(2);
513 EXPECT_EQ(2, GetFocusedWindowId());
515 void BasicActivation() override {
516 EXPECT_EQ(NULL, GetActiveWindow());
517 ActivateWindowById(1);
518 EXPECT_EQ(1, GetActiveWindowId());
519 ActivateWindowById(2);
520 EXPECT_EQ(2, GetActiveWindowId());
521 // Verify that attempting to deactivate NULL does not crash and does not
522 // change activation.
523 DeactivateWindow(NULL);
524 EXPECT_EQ(2, GetActiveWindowId());
525 DeactivateWindow(GetActiveWindow());
526 EXPECT_EQ(1, GetActiveWindowId());
528 void FocusEvents() override {
529 ScopedFocusNotificationObserver root_observer(root_window());
530 ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
531 ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
533 root_observer.ExpectCounts(0, 0);
534 observer1.ExpectCounts(0, 0);
535 observer2.ExpectCounts(0, 0);
537 FocusWindowById(1);
538 root_observer.ExpectCounts(1, 1);
539 observer1.ExpectCounts(1, 1);
540 observer2.ExpectCounts(0, 0);
542 FocusWindowById(2);
543 root_observer.ExpectCounts(2, 2);
544 observer1.ExpectCounts(2, 2);
545 observer2.ExpectCounts(1, 1);
547 void DuplicateFocusEvents() override {
548 // Focusing an existing focused window should not resend focus events.
549 ScopedFocusNotificationObserver root_observer(root_window());
550 ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
552 root_observer.ExpectCounts(0, 0);
553 observer1.ExpectCounts(0, 0);
555 FocusWindowById(1);
556 root_observer.ExpectCounts(1, 1);
557 observer1.ExpectCounts(1, 1);
559 FocusWindowById(1);
560 root_observer.ExpectCounts(1, 1);
561 observer1.ExpectCounts(1, 1);
563 void ActivationEvents() override {
564 ActivateWindowById(1);
566 ScopedFocusNotificationObserver root_observer(root_window());
567 ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
568 ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
570 root_observer.ExpectCounts(0, 0);
571 observer1.ExpectCounts(0, 0);
572 observer2.ExpectCounts(0, 0);
574 ActivateWindowById(2);
575 root_observer.ExpectCounts(1, 1);
576 EXPECT_EQ(GetExpectedActivationReason(),
577 root_observer.last_activation_reason());
578 observer1.ExpectCounts(1, 1);
579 observer2.ExpectCounts(1, 1);
581 void ReactivationEvents() override {
582 ActivateWindowById(1);
583 ScopedFocusNotificationObserver root_observer(root_window());
584 EXPECT_EQ(0, root_observer.reactivation_count());
585 root_window()->GetChildById(2)->Hide();
586 // When we attempt to activate "2", which cannot be activated because it
587 // is not visible, "1" will be reactivated.
588 ActivateWindowById(2);
589 EXPECT_EQ(1, root_observer.reactivation_count());
590 EXPECT_EQ(root_window()->GetChildById(2),
591 root_observer.reactivation_requested_window());
592 EXPECT_EQ(root_window()->GetChildById(1),
593 root_observer.reactivation_actual_window());
595 void DuplicateActivationEvents() override {
596 // Activating an existing active window should not resend activation events.
597 ActivateWindowById(1);
599 ScopedFocusNotificationObserver root_observer(root_window());
600 ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
601 ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
603 root_observer.ExpectCounts(0, 0);
604 observer1.ExpectCounts(0, 0);
605 observer2.ExpectCounts(0, 0);
607 ActivateWindowById(2);
608 root_observer.ExpectCounts(1, 1);
609 observer1.ExpectCounts(1, 1);
610 observer2.ExpectCounts(1, 1);
612 ActivateWindowById(2);
613 root_observer.ExpectCounts(1, 1);
614 observer1.ExpectCounts(1, 1);
615 observer2.ExpectCounts(1, 1);
617 void ShiftFocusWithinActiveWindow() override {
618 ActivateWindowById(1);
619 EXPECT_EQ(1, GetActiveWindowId());
620 EXPECT_EQ(1, GetFocusedWindowId());
621 FocusWindowById(11);
622 EXPECT_EQ(11, GetFocusedWindowId());
623 FocusWindowById(12);
624 EXPECT_EQ(12, GetFocusedWindowId());
626 void ShiftFocusToChildOfInactiveWindow() override {
627 ActivateWindowById(2);
628 EXPECT_EQ(2, GetActiveWindowId());
629 EXPECT_EQ(2, GetFocusedWindowId());
630 FocusWindowById(11);
631 EXPECT_EQ(1, GetActiveWindowId());
632 EXPECT_EQ(11, GetFocusedWindowId());
634 void ShiftFocusToParentOfFocusedWindow() override {
635 ActivateWindowById(1);
636 EXPECT_EQ(1, GetFocusedWindowId());
637 FocusWindowById(11);
638 EXPECT_EQ(11, GetFocusedWindowId());
639 FocusWindowById(1);
640 // Focus should _not_ shift to the parent of the already-focused window.
641 EXPECT_EQ(11, GetFocusedWindowId());
643 void FocusRulesOverride() override {
644 EXPECT_EQ(NULL, GetFocusedWindow());
645 FocusWindowById(11);
646 EXPECT_EQ(11, GetFocusedWindowId());
648 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(211));
649 FocusWindowById(12);
650 // Input events leave focus unchanged; direct API calls will change focus
651 // to the restricted window.
652 int focused_window = IsInputEvent() ? 11 : 211;
653 EXPECT_EQ(focused_window, GetFocusedWindowId());
655 test_focus_rules()->set_focus_restriction(NULL);
656 FocusWindowById(12);
657 EXPECT_EQ(12, GetFocusedWindowId());
659 void ActivationRulesOverride() override {
660 ActivateWindowById(1);
661 EXPECT_EQ(1, GetActiveWindowId());
662 EXPECT_EQ(1, GetFocusedWindowId());
664 aura::Window* w3 = root_window()->GetChildById(3);
665 test_focus_rules()->set_focus_restriction(w3);
667 ActivateWindowById(2);
668 // Input events leave activation unchanged; direct API calls will activate
669 // the restricted window.
670 int active_window = IsInputEvent() ? 1 : 3;
671 EXPECT_EQ(active_window, GetActiveWindowId());
672 EXPECT_EQ(active_window, GetFocusedWindowId());
674 test_focus_rules()->set_focus_restriction(NULL);
675 ActivateWindowById(2);
676 EXPECT_EQ(2, GetActiveWindowId());
677 EXPECT_EQ(2, GetFocusedWindowId());
679 void ShiftFocusOnActivation() override {
680 // When a window is activated, by default that window is also focused.
681 // An ActivationChangeObserver may shift focus to another window within the
682 // same activatable window.
683 ActivateWindowById(2);
684 EXPECT_EQ(2, GetFocusedWindowId());
685 ActivateWindowById(1);
686 EXPECT_EQ(1, GetFocusedWindowId());
688 ActivateWindowById(2);
690 aura::Window* target = root_window()->GetChildById(1);
691 aura::client::ActivationClient* client =
692 aura::client::GetActivationClient(root_window());
694 scoped_ptr<FocusShiftingActivationObserver> observer(
695 new FocusShiftingActivationObserver(target));
696 observer->set_shift_focus_to(target->GetChildById(11));
697 client->AddObserver(observer.get());
699 ActivateWindowById(1);
701 // w1's ActivationChangeObserver shifted focus to this child, pre-empting
702 // FocusController's default setting.
703 EXPECT_EQ(11, GetFocusedWindowId());
705 ActivateWindowById(2);
706 EXPECT_EQ(2, GetFocusedWindowId());
708 // Simulate a focus reset by the ActivationChangeObserver. This should
709 // trigger the default setting in FocusController.
710 observer->set_shift_focus_to(NULL);
711 ActivateWindowById(1);
712 EXPECT_EQ(1, GetFocusedWindowId());
714 client->RemoveObserver(observer.get());
716 ActivateWindowById(2);
717 EXPECT_EQ(2, GetFocusedWindowId());
718 ActivateWindowById(1);
719 EXPECT_EQ(1, GetFocusedWindowId());
721 void ShiftFocusOnActivationDueToHide() override {
722 // Similar to ShiftFocusOnActivation except the activation change is
723 // triggered by hiding the active window.
724 ActivateWindowById(1);
725 EXPECT_EQ(1, GetFocusedWindowId());
727 // Removes window 3 as candidate for next activatable window.
728 root_window()->GetChildById(3)->Hide();
729 EXPECT_EQ(1, GetFocusedWindowId());
731 aura::Window* target = root_window()->GetChildById(2);
732 aura::client::ActivationClient* client =
733 aura::client::GetActivationClient(root_window());
735 scoped_ptr<FocusShiftingActivationObserver> observer(
736 new FocusShiftingActivationObserver(target));
737 observer->set_shift_focus_to(target->GetChildById(21));
738 client->AddObserver(observer.get());
740 // Hide the active window.
741 root_window()->GetChildById(1)->Hide();
743 EXPECT_EQ(21, GetFocusedWindowId());
745 client->RemoveObserver(observer.get());
747 void NoShiftActiveOnActivation() override {
748 // When a window is activated, we need to prevent any change to activation
749 // from being made in response to an activation change notification.
752 void FocusChangeDuringDrag() override {
753 scoped_ptr<aura::client::DefaultCaptureClient> capture_client(
754 new aura::client::DefaultCaptureClient(root_window()));
755 // Activating an inactive window during drag should activate the window.
756 // This emulates the behavior of tab dragging which is merged into the
757 // window below.
758 ActivateWindowById(1);
760 EXPECT_EQ(1, GetActiveWindowId());
761 EXPECT_EQ(1, GetFocusedWindowId());
763 aura::Window* w2 = root_window()->GetChildById(2);
764 ui::test::EventGenerator generator(root_window(), w2);
765 generator.PressLeftButton();
766 aura::client::GetCaptureClient(root_window())->SetCapture(w2);
767 EXPECT_EQ(2, GetActiveWindowId());
768 EXPECT_EQ(2, GetFocusedWindowId());
769 generator.MoveMouseTo(gfx::Point(0, 0));
771 // Emulate the behavior of merging a tab into an inactive window:
772 // transferring the mouse capture and activate the window.
773 aura::Window* w1 = root_window()->GetChildById(1);
774 aura::client::GetCaptureClient(root_window())->SetCapture(w1);
775 aura::client::GetActivationClient(root_window())->ActivateWindow(w1);
776 EXPECT_EQ(1, GetActiveWindowId());
777 EXPECT_EQ(1, GetFocusedWindowId());
779 generator.ReleaseLeftButton();
780 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1);
783 // Verifies focus change is honored while capture held.
784 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());
793 FocusWindowById(1);
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 void DontPassDeletedWindow() override {
804 FocusWindowById(1);
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(),
813 &observer1);
815 FocusWindowById(2);
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(),
828 &observer1);
830 FocusWindowById(3);
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 // Test that the activation of the current active window will bring the window
841 // to the top of the window stack.
842 void StackWindowAtTopOnActivation() override {
843 // Create a window, show it and then activate it.
844 scoped_ptr<aura::Window> window1 =
845 make_scoped_ptr(new aura::Window(nullptr));
846 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL);
847 window1->Init(ui::LAYER_TEXTURED);
848 root_window()->AddChild(window1.get());
849 window1->Show();
850 ActivateWindow(window1.get());
851 EXPECT_EQ(window1.get(), root_window()->children().back());
852 EXPECT_EQ(window1.get(), GetActiveWindow());
854 // Create another window, show it but don't activate it. The window is not
855 // the active window but is placed on top of window stack.
856 scoped_ptr<aura::Window> window2 =
857 make_scoped_ptr(new aura::Window(nullptr));
858 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL);
859 window2->Init(ui::LAYER_TEXTURED);
860 root_window()->AddChild(window2.get());
861 window2->Show();
862 EXPECT_EQ(window2.get(), root_window()->children().back());
863 EXPECT_EQ(window1.get(), GetActiveWindow());
865 // Try to reactivate the active window. It should bring the active window
866 // to the top of the window stack.
867 ActivateWindow(window1.get());
868 EXPECT_EQ(window1.get(), root_window()->children().back());
869 EXPECT_EQ(window1.get(), GetActiveWindow());
872 private:
873 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase);
876 // Focus and Activation changes via aura::client::ActivationClient API.
877 class FocusControllerApiTest : public FocusControllerDirectTestBase {
878 public:
879 FocusControllerApiTest() {}
881 private:
882 // Overridden from FocusControllerTestBase:
883 void FocusWindowDirect(aura::Window* window) override { FocusWindow(window); }
884 void ActivateWindowDirect(aura::Window* window) override {
885 ActivateWindow(window);
887 void DeactivateWindowDirect(aura::Window* window) override {
888 DeactivateWindow(window);
890 bool IsInputEvent() override { return false; }
891 // Overridden from FocusControllerDirectTestBase:
892 aura::client::ActivationChangeObserver::ActivationReason
893 GetExpectedActivationReason() const override {
894 return aura::client::ActivationChangeObserver::ActivationReason::
895 ACTIVATION_CLIENT;
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 // Overridden from FocusControllerDirectTestBase:
940 bool IsInputEvent() override { return true; }
941 aura::client::ActivationChangeObserver::ActivationReason
942 GetExpectedActivationReason() const override {
943 return aura::client::ActivationChangeObserver::ActivationReason::
944 INPUT_EVENT;
947 DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest);
950 class FocusControllerGestureEventTest : public FocusControllerDirectTestBase {
951 public:
952 FocusControllerGestureEventTest() {}
954 private:
955 // Overridden from FocusControllerTestBase:
956 void FocusWindowDirect(aura::Window* window) override {
957 ui::test::EventGenerator generator(root_window(), window);
958 generator.GestureTapAt(window->bounds().CenterPoint());
960 void ActivateWindowDirect(aura::Window* window) override {
961 ui::test::EventGenerator generator(root_window(), window);
962 generator.GestureTapAt(window->bounds().CenterPoint());
964 void DeactivateWindowDirect(aura::Window* window) override {
965 aura::Window* next_activatable =
966 test_focus_rules()->GetNextActivatableWindow(window);
967 ui::test::EventGenerator generator(root_window(), next_activatable);
968 generator.GestureTapAt(window->bounds().CenterPoint());
970 bool IsInputEvent() override { return true; }
971 aura::client::ActivationChangeObserver::ActivationReason
972 GetExpectedActivationReason() const override {
973 return aura::client::ActivationChangeObserver::ActivationReason::
974 INPUT_EVENT;
977 DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest);
980 // Test base for tests where focus is implicitly set to a window as the result
981 // of a disposition change to the focused window or the hierarchy that contains
982 // it.
983 class FocusControllerImplicitTestBase : public FocusControllerTestBase {
984 protected:
985 explicit FocusControllerImplicitTestBase(bool parent) : parent_(parent) {}
987 aura::Window* GetDispositionWindow(aura::Window* window) {
988 return parent_ ? window->parent() : window;
991 // Returns the expected ActivationReason caused by calling the
992 // ActivatedWindowDirect(...) or DeactivateWindowDirect(...) methods.
993 aura::client::ActivationChangeObserver::ActivationReason
994 GetExpectedActivationReason() const {
995 return aura::client::ActivationChangeObserver::ActivationReason::
996 WINDOW_DISPOSITION_CHANGED;
999 // Change the disposition of |window| in such a way as it will lose focus.
1000 virtual void ChangeWindowDisposition(aura::Window* window) = 0;
1002 // Allow each disposition change test to add additional post-disposition
1003 // change expectations.
1004 virtual void PostDispositionChangeExpectations() {}
1006 // Overridden from FocusControllerTestBase:
1007 void BasicFocus() override {
1008 EXPECT_EQ(NULL, GetFocusedWindow());
1010 aura::Window* w211 = root_window()->GetChildById(211);
1011 FocusWindow(w211);
1012 EXPECT_EQ(211, GetFocusedWindowId());
1014 ChangeWindowDisposition(w211);
1015 // BasicFocusRules passes focus to the parent.
1016 EXPECT_EQ(parent_ ? 2 : 21, GetFocusedWindowId());
1018 void BasicActivation() override {
1019 DCHECK(!parent_) << "Activation tests don't support parent changes.";
1021 EXPECT_EQ(NULL, GetActiveWindow());
1023 aura::Window* w2 = root_window()->GetChildById(2);
1024 ActivateWindow(w2);
1025 EXPECT_EQ(2, GetActiveWindowId());
1027 ChangeWindowDisposition(w2);
1028 EXPECT_EQ(3, GetActiveWindowId());
1029 PostDispositionChangeExpectations();
1031 void FocusEvents() override {
1032 aura::Window* w211 = root_window()->GetChildById(211);
1033 FocusWindow(w211);
1035 ScopedFocusNotificationObserver root_observer(root_window());
1036 ScopedTargetFocusNotificationObserver observer211(root_window(), 211);
1037 root_observer.ExpectCounts(0, 0);
1038 observer211.ExpectCounts(0, 0);
1040 ChangeWindowDisposition(w211);
1041 root_observer.ExpectCounts(0, 1);
1042 observer211.ExpectCounts(0, 1);
1044 void ActivationEvents() override {
1045 DCHECK(!parent_) << "Activation tests don't support parent changes.";
1047 aura::Window* w2 = root_window()->GetChildById(2);
1048 ActivateWindow(w2);
1050 ScopedFocusNotificationObserver root_observer(root_window());
1051 ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
1052 ScopedTargetFocusNotificationObserver observer3(root_window(), 3);
1053 root_observer.ExpectCounts(0, 0);
1054 observer2.ExpectCounts(0, 0);
1055 observer3.ExpectCounts(0, 0);
1057 ChangeWindowDisposition(w2);
1058 root_observer.ExpectCounts(1, 1);
1059 EXPECT_EQ(GetExpectedActivationReason(),
1060 root_observer.last_activation_reason());
1061 observer2.ExpectCounts(1, 1);
1062 observer3.ExpectCounts(1, 1);
1064 void FocusRulesOverride() override {
1065 EXPECT_EQ(NULL, GetFocusedWindow());
1066 aura::Window* w211 = root_window()->GetChildById(211);
1067 FocusWindow(w211);
1068 EXPECT_EQ(211, GetFocusedWindowId());
1070 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(11));
1071 ChangeWindowDisposition(w211);
1072 // Normally, focus would shift to the parent (w21) but the override shifts
1073 // it to 11.
1074 EXPECT_EQ(11, GetFocusedWindowId());
1076 test_focus_rules()->set_focus_restriction(NULL);
1078 void ActivationRulesOverride() override {
1079 DCHECK(!parent_) << "Activation tests don't support parent changes.";
1081 aura::Window* w1 = root_window()->GetChildById(1);
1082 ActivateWindow(w1);
1084 EXPECT_EQ(1, GetActiveWindowId());
1085 EXPECT_EQ(1, GetFocusedWindowId());
1087 aura::Window* w3 = root_window()->GetChildById(3);
1088 test_focus_rules()->set_focus_restriction(w3);
1090 // Normally, activation/focus would move to w2, but since we have a focus
1091 // restriction, it should move to w3 instead.
1092 ChangeWindowDisposition(w1);
1093 EXPECT_EQ(3, GetActiveWindowId());
1094 EXPECT_EQ(3, GetFocusedWindowId());
1096 test_focus_rules()->set_focus_restriction(NULL);
1097 ActivateWindow(root_window()->GetChildById(2));
1098 EXPECT_EQ(2, GetActiveWindowId());
1099 EXPECT_EQ(2, GetFocusedWindowId());
1102 private:
1103 // When true, the disposition change occurs to the parent of the window
1104 // instead of to the window. This verifies that changes occurring in the
1105 // hierarchy that contains the window affect the window's focus.
1106 bool parent_;
1108 DISALLOW_COPY_AND_ASSIGN(FocusControllerImplicitTestBase);
1111 // Focus and Activation changes in response to window visibility changes.
1112 class FocusControllerHideTest : public FocusControllerImplicitTestBase {
1113 public:
1114 FocusControllerHideTest() : FocusControllerImplicitTestBase(false) {}
1116 protected:
1117 FocusControllerHideTest(bool parent)
1118 : FocusControllerImplicitTestBase(parent) {}
1120 // Overridden from FocusControllerImplicitTestBase:
1121 void ChangeWindowDisposition(aura::Window* window) override {
1122 GetDispositionWindow(window)->Hide();
1125 private:
1126 DISALLOW_COPY_AND_ASSIGN(FocusControllerHideTest);
1129 // Focus and Activation changes in response to window parent visibility
1130 // changes.
1131 class FocusControllerParentHideTest : public FocusControllerHideTest {
1132 public:
1133 FocusControllerParentHideTest() : FocusControllerHideTest(true) {}
1135 // The parent window's visibility change should not change its transient child
1136 // window's modality property.
1137 void TransientChildWindowActivationTest() {
1138 aura::Window* w1 = root_window()->GetChildById(1);
1139 aura::Window* w11 = root_window()->GetChildById(11);
1140 ::wm::AddTransientChild(w1, w11);
1141 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
1143 EXPECT_EQ(ui::MODAL_TYPE_NONE, w1->GetProperty(aura::client::kModalKey));
1144 EXPECT_EQ(ui::MODAL_TYPE_WINDOW, w11->GetProperty(aura::client::kModalKey));
1146 // Hide the parent window w1 and show it again.
1147 w1->Hide();
1148 w1->Show();
1150 // Test that child window w11 doesn't change its modality property.
1151 EXPECT_EQ(ui::MODAL_TYPE_NONE, w1->GetProperty(aura::client::kModalKey));
1152 EXPECT_EQ(ui::MODAL_TYPE_WINDOW, w11->GetProperty(aura::client::kModalKey));
1155 private:
1156 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentHideTest);
1159 // Focus and Activation changes in response to window destruction.
1160 class FocusControllerDestructionTest : public FocusControllerImplicitTestBase {
1161 public:
1162 FocusControllerDestructionTest() : FocusControllerImplicitTestBase(false) {}
1164 protected:
1165 FocusControllerDestructionTest(bool parent)
1166 : FocusControllerImplicitTestBase(parent) {}
1168 // Overridden from FocusControllerImplicitTestBase:
1169 void ChangeWindowDisposition(aura::Window* window) override {
1170 delete GetDispositionWindow(window);
1173 private:
1174 DISALLOW_COPY_AND_ASSIGN(FocusControllerDestructionTest);
1177 // Focus and Activation changes in response to window parent destruction.
1178 class FocusControllerParentDestructionTest
1179 : public FocusControllerDestructionTest {
1180 public:
1181 FocusControllerParentDestructionTest()
1182 : FocusControllerDestructionTest(true) {}
1184 private:
1185 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentDestructionTest);
1188 // Focus and Activation changes in response to window removal.
1189 class FocusControllerRemovalTest : public FocusControllerImplicitTestBase {
1190 public:
1191 FocusControllerRemovalTest() : FocusControllerImplicitTestBase(false) {}
1193 protected:
1194 FocusControllerRemovalTest(bool parent)
1195 : FocusControllerImplicitTestBase(parent) {}
1197 // Overridden from FocusControllerImplicitTestBase:
1198 void ChangeWindowDisposition(aura::Window* window) override {
1199 aura::Window* disposition_window = GetDispositionWindow(window);
1200 disposition_window->parent()->RemoveChild(disposition_window);
1201 window_owner_.reset(disposition_window);
1203 void TearDown() override {
1204 window_owner_.reset();
1205 FocusControllerImplicitTestBase::TearDown();
1208 private:
1209 scoped_ptr<aura::Window> window_owner_;
1211 DISALLOW_COPY_AND_ASSIGN(FocusControllerRemovalTest);
1214 // Focus and Activation changes in response to window parent removal.
1215 class FocusControllerParentRemovalTest : public FocusControllerRemovalTest {
1216 public:
1217 FocusControllerParentRemovalTest() : FocusControllerRemovalTest(true) {}
1219 private:
1220 DISALLOW_COPY_AND_ASSIGN(FocusControllerParentRemovalTest);
1224 #define FOCUS_CONTROLLER_TEST(TESTCLASS, TESTNAME) \
1225 TEST_F(TESTCLASS, TESTNAME) { TESTNAME(); }
1227 // Runs direct focus change tests (input events and API calls).
1228 #define DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1229 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, TESTNAME) \
1230 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, TESTNAME) \
1231 FOCUS_CONTROLLER_TEST(FocusControllerGestureEventTest, TESTNAME)
1233 // Runs implicit focus change tests for disposition changes to target.
1234 #define IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME) \
1235 FOCUS_CONTROLLER_TEST(FocusControllerHideTest, TESTNAME) \
1236 FOCUS_CONTROLLER_TEST(FocusControllerDestructionTest, TESTNAME) \
1237 FOCUS_CONTROLLER_TEST(FocusControllerRemovalTest, TESTNAME)
1239 // Runs implicit focus change tests for disposition changes to target's parent
1240 // hierarchy.
1241 #define IMPLICIT_FOCUS_CHANGE_PARENT_TESTS(TESTNAME) \
1242 /* TODO(beng): parent destruction tests are not supported at
1243 present due to workspace manager issues. \
1244 FOCUS_CONTROLLER_TEST(FocusControllerParentDestructionTest, TESTNAME) */ \
1245 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, TESTNAME) \
1246 FOCUS_CONTROLLER_TEST(FocusControllerParentRemovalTest, TESTNAME)
1248 // Runs all implicit focus change tests (changes to the target and target's
1249 // parent hierarchy)
1250 #define IMPLICIT_FOCUS_CHANGE_TESTS(TESTNAME) \
1251 IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME) \
1252 IMPLICIT_FOCUS_CHANGE_PARENT_TESTS(TESTNAME)
1254 // Runs all possible focus change tests.
1255 #define ALL_FOCUS_TESTS(TESTNAME) \
1256 DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1257 IMPLICIT_FOCUS_CHANGE_TESTS(TESTNAME)
1259 // Runs focus change tests that apply only to the target. For example,
1260 // implicit activation changes caused by window disposition changes do not
1261 // occur when changes to the containing hierarchy happen.
1262 #define TARGET_FOCUS_TESTS(TESTNAME) \
1263 DIRECT_FOCUS_CHANGE_TESTS(TESTNAME) \
1264 IMPLICIT_FOCUS_CHANGE_TARGET_TESTS(TESTNAME)
1266 // - Focuses a window, verifies that focus changed.
1267 ALL_FOCUS_TESTS(BasicFocus);
1269 // - Activates a window, verifies that activation changed.
1270 TARGET_FOCUS_TESTS(BasicActivation);
1272 // - Focuses a window, verifies that focus events were dispatched.
1273 ALL_FOCUS_TESTS(FocusEvents);
1275 // - Focuses or activates a window multiple times, verifies that events are only
1276 // dispatched when focus/activation actually changes.
1277 DIRECT_FOCUS_CHANGE_TESTS(DuplicateFocusEvents);
1278 DIRECT_FOCUS_CHANGE_TESTS(DuplicateActivationEvents);
1280 // - Activates a window, verifies that activation events were dispatched.
1281 TARGET_FOCUS_TESTS(ActivationEvents);
1283 // - Attempts to active a hidden window, verifies that current window is
1284 // attempted to be reactivated and the appropriate event dispatched.
1285 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, ReactivationEvents);
1287 // - Input events/API calls shift focus between focusable windows within the
1288 // active window.
1289 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusWithinActiveWindow);
1291 // - Input events/API calls to a child window of an inactive window shifts
1292 // activation to the activatable parent and focuses the child.
1293 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToChildOfInactiveWindow);
1295 // - Input events/API calls to focus the parent of the focused window do not
1296 // shift focus away from the child.
1297 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToParentOfFocusedWindow);
1299 // - Verifies that FocusRules determine what can be focused.
1300 ALL_FOCUS_TESTS(FocusRulesOverride);
1302 // - Verifies that FocusRules determine what can be activated.
1303 TARGET_FOCUS_TESTS(ActivationRulesOverride);
1305 // - Verifies that attempts to change focus or activation from a focus or
1306 // activation change observer are ignored.
1307 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation);
1308 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide);
1309 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation);
1311 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, FocusChangeDuringDrag);
1313 FOCUS_CONTROLLER_TEST(FocusControllerApiTest,
1314 ChangeFocusWhenNothingFocusedAndCaptured);
1316 // See description above DontPassDeletedWindow() for details.
1317 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow);
1319 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, StackWindowAtTopOnActivation);
1321 // See description above TransientChildWindowActivationTest() for details.
1322 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest,
1323 TransientChildWindowActivationTest);
1325 // If a mouse event was handled, it should not activate a window.
1326 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent);
1328 } // namespace wm