Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: ui/views/corewm/focus_controller_unittest.cc

Issue 14298013: Check focusability in WindowFocusedFromInputEvent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update FocusController tests Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/corewm/focus_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/corewm/focus_controller.h" 5 #include "ui/views/corewm/focus_controller.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "ui/aura/client/activation_change_observer.h" 9 #include "ui/aura/client/activation_change_observer.h"
10 #include "ui/aura/client/activation_client.h" 10 #include "ui/aura/client/activation_client.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // Test base for tests where focus is directly set to a target window. 291 // Test base for tests where focus is directly set to a target window.
292 class FocusControllerDirectTestBase : public FocusControllerTestBase { 292 class FocusControllerDirectTestBase : public FocusControllerTestBase {
293 protected: 293 protected:
294 FocusControllerDirectTestBase() {} 294 FocusControllerDirectTestBase() {}
295 295
296 // Different test types shift focus in different ways. 296 // Different test types shift focus in different ways.
297 virtual void FocusWindowDirect(aura::Window* window) = 0; 297 virtual void FocusWindowDirect(aura::Window* window) = 0;
298 virtual void ActivateWindowDirect(aura::Window* window) = 0; 298 virtual void ActivateWindowDirect(aura::Window* window) = 0;
299 virtual void DeactivateWindowDirect(aura::Window* window) = 0; 299 virtual void DeactivateWindowDirect(aura::Window* window) = 0;
300 300
301 // Input events do not change focus if the window can not be focused.
302 virtual bool IsInputEvent() = 0;
303
301 void FocusWindowById(int id) { 304 void FocusWindowById(int id) {
302 aura::Window* window = root_window()->GetChildById(id); 305 aura::Window* window = root_window()->GetChildById(id);
303 DCHECK(window); 306 DCHECK(window);
304 FocusWindowDirect(window); 307 FocusWindowDirect(window);
305 } 308 }
306 void ActivateWindowById(int id) { 309 void ActivateWindowById(int id) {
307 aura::Window* window = root_window()->GetChildById(id); 310 aura::Window* window = root_window()->GetChildById(id);
308 DCHECK(window); 311 DCHECK(window);
309 ActivateWindowDirect(window); 312 ActivateWindowDirect(window);
310 } 313 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // Focus should _not_ shift to the parent of the already-focused window. 432 // Focus should _not_ shift to the parent of the already-focused window.
430 EXPECT_EQ(11, GetFocusedWindowId()); 433 EXPECT_EQ(11, GetFocusedWindowId());
431 } 434 }
432 virtual void FocusRulesOverride() OVERRIDE { 435 virtual void FocusRulesOverride() OVERRIDE {
433 EXPECT_EQ(NULL, GetFocusedWindow()); 436 EXPECT_EQ(NULL, GetFocusedWindow());
434 FocusWindowById(11); 437 FocusWindowById(11);
435 EXPECT_EQ(11, GetFocusedWindowId()); 438 EXPECT_EQ(11, GetFocusedWindowId());
436 439
437 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(211)); 440 test_focus_rules()->set_focus_restriction(root_window()->GetChildById(211));
438 FocusWindowById(12); 441 FocusWindowById(12);
439 EXPECT_EQ(211, GetFocusedWindowId()); 442 // Input events leave focus unchanged; direct API calls will change focus
443 // to the restricted window.
444 int focused_window = IsInputEvent() ? 11 : 211;
445 EXPECT_EQ(focused_window, GetFocusedWindowId());
440 446
441 test_focus_rules()->set_focus_restriction(NULL); 447 test_focus_rules()->set_focus_restriction(NULL);
442 FocusWindowById(12); 448 FocusWindowById(12);
443 EXPECT_EQ(12, GetFocusedWindowId()); 449 EXPECT_EQ(12, GetFocusedWindowId());
444 } 450 }
445 virtual void ActivationRulesOverride() OVERRIDE { 451 virtual void ActivationRulesOverride() OVERRIDE {
446 ActivateWindowById(1); 452 ActivateWindowById(1);
447 EXPECT_EQ(1, GetActiveWindowId()); 453 EXPECT_EQ(1, GetActiveWindowId());
448 EXPECT_EQ(1, GetFocusedWindowId()); 454 EXPECT_EQ(1, GetFocusedWindowId());
449 455
450 aura::Window* w3 = root_window()->GetChildById(3); 456 aura::Window* w3 = root_window()->GetChildById(3);
451 test_focus_rules()->set_focus_restriction(w3); 457 test_focus_rules()->set_focus_restriction(w3);
452 458
453 ActivateWindowById(2); 459 ActivateWindowById(2);
454 // FocusRules restricts focus and activation to 3. 460 // Input events leave activation unchanged; direct API calls will activate
455 EXPECT_EQ(3, GetActiveWindowId()); 461 // the restricted window.
456 EXPECT_EQ(3, GetFocusedWindowId()); 462 int active_window = IsInputEvent() ? 1 : 3;
463 EXPECT_EQ(active_window, GetActiveWindowId());
464 EXPECT_EQ(active_window, GetFocusedWindowId());
457 465
458 test_focus_rules()->set_focus_restriction(NULL); 466 test_focus_rules()->set_focus_restriction(NULL);
459 ActivateWindowById(2); 467 ActivateWindowById(2);
460 EXPECT_EQ(2, GetActiveWindowId()); 468 EXPECT_EQ(2, GetActiveWindowId());
461 EXPECT_EQ(2, GetFocusedWindowId()); 469 EXPECT_EQ(2, GetFocusedWindowId());
462 } 470 }
463 virtual void ShiftFocusOnActivation() OVERRIDE { 471 virtual void ShiftFocusOnActivation() OVERRIDE {
464 // When a window is activated, by default that window is also focused. 472 // When a window is activated, by default that window is also focused.
465 // An ActivationChangeObserver may shift focus to another window within the 473 // An ActivationChangeObserver may shift focus to another window within the
466 // same activatable window. 474 // same activatable window.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 // Overridden from FocusControllerTestBase: 574 // Overridden from FocusControllerTestBase:
567 virtual void FocusWindowDirect(aura::Window* window) OVERRIDE { 575 virtual void FocusWindowDirect(aura::Window* window) OVERRIDE {
568 FocusWindow(window); 576 FocusWindow(window);
569 } 577 }
570 virtual void ActivateWindowDirect(aura::Window* window) OVERRIDE { 578 virtual void ActivateWindowDirect(aura::Window* window) OVERRIDE {
571 ActivateWindow(window); 579 ActivateWindow(window);
572 } 580 }
573 virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE { 581 virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE {
574 DeactivateWindow(window); 582 DeactivateWindow(window);
575 } 583 }
584 virtual bool IsInputEvent() OVERRIDE { return false; }
576 585
577 DISALLOW_COPY_AND_ASSIGN(FocusControllerApiTest); 586 DISALLOW_COPY_AND_ASSIGN(FocusControllerApiTest);
578 }; 587 };
579 588
580 // Focus and Activation changes via input events. 589 // Focus and Activation changes via input events.
581 class FocusControllerMouseEventTest : public FocusControllerDirectTestBase { 590 class FocusControllerMouseEventTest : public FocusControllerDirectTestBase {
582 public: 591 public:
583 FocusControllerMouseEventTest() {} 592 FocusControllerMouseEventTest() {}
584 593
585 private: 594 private:
586 // Overridden from FocusControllerTestBase: 595 // Overridden from FocusControllerTestBase:
587 virtual void FocusWindowDirect(aura::Window* window) OVERRIDE { 596 virtual void FocusWindowDirect(aura::Window* window) OVERRIDE {
588 aura::test::EventGenerator generator(root_window(), window); 597 aura::test::EventGenerator generator(root_window(), window);
589 generator.ClickLeftButton(); 598 generator.ClickLeftButton();
590 } 599 }
591 virtual void ActivateWindowDirect(aura::Window* window) OVERRIDE { 600 virtual void ActivateWindowDirect(aura::Window* window) OVERRIDE {
592 aura::test::EventGenerator generator(root_window(), window); 601 aura::test::EventGenerator generator(root_window(), window);
593 generator.ClickLeftButton(); 602 generator.ClickLeftButton();
594 } 603 }
595 virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE { 604 virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE {
596 aura::Window* next_activatable = 605 aura::Window* next_activatable =
597 test_focus_rules()->GetNextActivatableWindow(window); 606 test_focus_rules()->GetNextActivatableWindow(window);
598 aura::test::EventGenerator generator(root_window(), next_activatable); 607 aura::test::EventGenerator generator(root_window(), next_activatable);
599 generator.ClickLeftButton(); 608 generator.ClickLeftButton();
600 } 609 }
610 virtual bool IsInputEvent() OVERRIDE { return true; }
601 611
602 DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest); 612 DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest);
603 }; 613 };
604 614
605 class FocusControllerGestureEventTest : public FocusControllerDirectTestBase { 615 class FocusControllerGestureEventTest : public FocusControllerDirectTestBase {
606 public: 616 public:
607 FocusControllerGestureEventTest() {} 617 FocusControllerGestureEventTest() {}
608 618
609 private: 619 private:
610 // Overridden from FocusControllerTestBase: 620 // Overridden from FocusControllerTestBase:
611 virtual void FocusWindowDirect(aura::Window* window) OVERRIDE { 621 virtual void FocusWindowDirect(aura::Window* window) OVERRIDE {
612 aura::test::EventGenerator generator(root_window(), window); 622 aura::test::EventGenerator generator(root_window(), window);
613 generator.GestureTapAt(window->bounds().CenterPoint()); 623 generator.GestureTapAt(window->bounds().CenterPoint());
614 } 624 }
615 virtual void ActivateWindowDirect(aura::Window* window) OVERRIDE { 625 virtual void ActivateWindowDirect(aura::Window* window) OVERRIDE {
616 aura::test::EventGenerator generator(root_window(), window); 626 aura::test::EventGenerator generator(root_window(), window);
617 generator.GestureTapAt(window->bounds().CenterPoint()); 627 generator.GestureTapAt(window->bounds().CenterPoint());
618 } 628 }
619 virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE { 629 virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE {
620 aura::Window* next_activatable = 630 aura::Window* next_activatable =
621 test_focus_rules()->GetNextActivatableWindow(window); 631 test_focus_rules()->GetNextActivatableWindow(window);
622 aura::test::EventGenerator generator(root_window(), next_activatable); 632 aura::test::EventGenerator generator(root_window(), next_activatable);
623 generator.GestureTapAt(window->bounds().CenterPoint()); 633 generator.GestureTapAt(window->bounds().CenterPoint());
624 } 634 }
635 virtual bool IsInputEvent() OVERRIDE { return true; }
625 636
626 DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest); 637 DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest);
627 }; 638 };
628 639
629 // Test base for tests where focus is implicitly set to a window as the result 640 // Test base for tests where focus is implicitly set to a window as the result
630 // of a disposition change to the focused window or the hierarchy that contains 641 // of a disposition change to the focused window or the hierarchy that contains
631 // it. 642 // it.
632 class FocusControllerImplicitTestBase : public FocusControllerTestBase { 643 class FocusControllerImplicitTestBase : public FocusControllerTestBase {
633 protected: 644 protected:
634 explicit FocusControllerImplicitTestBase(bool parent) : parent_(parent) {} 645 explicit FocusControllerImplicitTestBase(bool parent) : parent_(parent) {}
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 // activation change observer are ignored. 950 // activation change observer are ignored.
940 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); 951 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation);
941 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); 952 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide);
942 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); 953 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation);
943 954
944 // Clicking on a window which has capture should not result in a focus change. 955 // Clicking on a window which has capture should not result in a focus change.
945 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); 956 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow);
946 957
947 } // namespace corewm 958 } // namespace corewm
948 } // namespace views 959 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/focus_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698