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

Side by Side Diff: ui/views/focus/focus_manager_unittest.cc

Issue 679233002: Standardize usage of virtual/override/final specifiers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « ui/views/focus/focus_manager_factory.cc ('k') | ui/views/focus/focus_traversal_unittest.cc » ('j') | 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/focus/focus_manager.h" 5 #include "ui/views/focus/focus_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 30 matching lines...) Expand all
41 }; 41 };
42 42
43 class SimpleTestView : public View { 43 class SimpleTestView : public View {
44 public: 44 public:
45 SimpleTestView(std::vector<FocusTestEvent>* event_list, int view_id) 45 SimpleTestView(std::vector<FocusTestEvent>* event_list, int view_id)
46 : event_list_(event_list) { 46 : event_list_(event_list) {
47 SetFocusable(true); 47 SetFocusable(true);
48 set_id(view_id); 48 set_id(view_id);
49 } 49 }
50 50
51 virtual void OnFocus() override { 51 void OnFocus() override {
52 event_list_->push_back(FocusTestEvent(ON_FOCUS, id())); 52 event_list_->push_back(FocusTestEvent(ON_FOCUS, id()));
53 } 53 }
54 54
55 virtual void OnBlur() override { 55 void OnBlur() override {
56 event_list_->push_back(FocusTestEvent(ON_BLUR, id())); 56 event_list_->push_back(FocusTestEvent(ON_BLUR, id()));
57 } 57 }
58 58
59 private: 59 private:
60 std::vector<FocusTestEvent>* event_list_; 60 std::vector<FocusTestEvent>* event_list_;
61 61
62 DISALLOW_COPY_AND_ASSIGN(SimpleTestView); 62 DISALLOW_COPY_AND_ASSIGN(SimpleTestView);
63 }; 63 };
64 64
65 // Tests that the appropriate Focus related methods are called when a View 65 // Tests that the appropriate Focus related methods are called when a View
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 158 }
159 159
160 // Counts accelerator calls. 160 // Counts accelerator calls.
161 class TestAcceleratorTarget : public ui::AcceleratorTarget { 161 class TestAcceleratorTarget : public ui::AcceleratorTarget {
162 public: 162 public:
163 explicit TestAcceleratorTarget(bool process_accelerator) 163 explicit TestAcceleratorTarget(bool process_accelerator)
164 : accelerator_count_(0), 164 : accelerator_count_(0),
165 process_accelerator_(process_accelerator), 165 process_accelerator_(process_accelerator),
166 can_handle_accelerators_(true) {} 166 can_handle_accelerators_(true) {}
167 167
168 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) override { 168 bool AcceleratorPressed(const ui::Accelerator& accelerator) override {
169 ++accelerator_count_; 169 ++accelerator_count_;
170 return process_accelerator_; 170 return process_accelerator_;
171 } 171 }
172 172
173 virtual bool CanHandleAccelerators() const override { 173 bool CanHandleAccelerators() const override {
174 return can_handle_accelerators_; 174 return can_handle_accelerators_;
175 } 175 }
176 176
177 int accelerator_count() const { return accelerator_count_; } 177 int accelerator_count() const { return accelerator_count_; }
178 178
179 void set_can_handle_accelerators(bool can_handle_accelerators) { 179 void set_can_handle_accelerators(bool can_handle_accelerators) {
180 can_handle_accelerators_ = can_handle_accelerators; 180 can_handle_accelerators_ = can_handle_accelerators;
181 } 181 }
182 182
183 private: 183 private:
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // Unregisters itself when its accelerator is invoked. 418 // Unregisters itself when its accelerator is invoked.
419 class SelfUnregisteringAcceleratorTarget : public ui::AcceleratorTarget { 419 class SelfUnregisteringAcceleratorTarget : public ui::AcceleratorTarget {
420 public: 420 public:
421 SelfUnregisteringAcceleratorTarget(ui::Accelerator accelerator, 421 SelfUnregisteringAcceleratorTarget(ui::Accelerator accelerator,
422 FocusManager* focus_manager) 422 FocusManager* focus_manager)
423 : accelerator_(accelerator), 423 : accelerator_(accelerator),
424 focus_manager_(focus_manager), 424 focus_manager_(focus_manager),
425 accelerator_count_(0) { 425 accelerator_count_(0) {
426 } 426 }
427 427
428 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) override { 428 bool AcceleratorPressed(const ui::Accelerator& accelerator) override {
429 ++accelerator_count_; 429 ++accelerator_count_;
430 focus_manager_->UnregisterAccelerator(accelerator, this); 430 focus_manager_->UnregisterAccelerator(accelerator, this);
431 return true; 431 return true;
432 } 432 }
433 433
434 virtual bool CanHandleAccelerators() const override { 434 bool CanHandleAccelerators() const override { return true; }
435 return true;
436 }
437 435
438 int accelerator_count() const { return accelerator_count_; } 436 int accelerator_count() const { return accelerator_count_; }
439 437
440 private: 438 private:
441 ui::Accelerator accelerator_; 439 ui::Accelerator accelerator_;
442 FocusManager* focus_manager_; 440 FocusManager* focus_manager_;
443 int accelerator_count_; 441 int accelerator_count_;
444 442
445 DISALLOW_COPY_AND_ASSIGN(SelfUnregisteringAcceleratorTarget); 443 DISALLOW_COPY_AND_ASSIGN(SelfUnregisteringAcceleratorTarget);
446 }; 444 };
(...skipping 28 matching lines...) Expand all
475 protected: 473 protected:
476 typedef std::vector<std::string> DtorTrackVector; 474 typedef std::vector<std::string> DtorTrackVector;
477 475
478 class FocusManagerDtorTracked : public FocusManager { 476 class FocusManagerDtorTracked : public FocusManager {
479 public: 477 public:
480 FocusManagerDtorTracked(Widget* widget, DtorTrackVector* dtor_tracker) 478 FocusManagerDtorTracked(Widget* widget, DtorTrackVector* dtor_tracker)
481 : FocusManager(widget, NULL /* delegate */), 479 : FocusManager(widget, NULL /* delegate */),
482 dtor_tracker_(dtor_tracker) { 480 dtor_tracker_(dtor_tracker) {
483 } 481 }
484 482
485 virtual ~FocusManagerDtorTracked() { 483 ~FocusManagerDtorTracked() override {
486 dtor_tracker_->push_back("FocusManagerDtorTracked"); 484 dtor_tracker_->push_back("FocusManagerDtorTracked");
487 } 485 }
488 486
489 DtorTrackVector* dtor_tracker_; 487 DtorTrackVector* dtor_tracker_;
490 488
491 private: 489 private:
492 DISALLOW_COPY_AND_ASSIGN(FocusManagerDtorTracked); 490 DISALLOW_COPY_AND_ASSIGN(FocusManagerDtorTracked);
493 }; 491 };
494 492
495 class TestFocusManagerFactory : public FocusManagerFactory { 493 class TestFocusManagerFactory : public FocusManagerFactory {
496 public: 494 public:
497 explicit TestFocusManagerFactory(DtorTrackVector* dtor_tracker) 495 explicit TestFocusManagerFactory(DtorTrackVector* dtor_tracker)
498 : dtor_tracker_(dtor_tracker) { 496 : dtor_tracker_(dtor_tracker) {
499 } 497 }
500 498
501 virtual FocusManager* CreateFocusManager(Widget* widget, 499 FocusManager* CreateFocusManager(Widget* widget,
502 bool desktop_widget) override { 500 bool desktop_widget) override {
503 return new FocusManagerDtorTracked(widget, dtor_tracker_); 501 return new FocusManagerDtorTracked(widget, dtor_tracker_);
504 } 502 }
505 503
506 private: 504 private:
507 DtorTrackVector* dtor_tracker_; 505 DtorTrackVector* dtor_tracker_;
508 DISALLOW_COPY_AND_ASSIGN(TestFocusManagerFactory); 506 DISALLOW_COPY_AND_ASSIGN(TestFocusManagerFactory);
509 }; 507 };
510 508
511 class LabelButtonDtorTracked : public LabelButton { 509 class LabelButtonDtorTracked : public LabelButton {
512 public: 510 public:
513 LabelButtonDtorTracked(const base::string16& text, 511 LabelButtonDtorTracked(const base::string16& text,
514 DtorTrackVector* dtor_tracker) 512 DtorTrackVector* dtor_tracker)
515 : LabelButton(NULL, text), 513 : LabelButton(NULL, text),
516 dtor_tracker_(dtor_tracker) { 514 dtor_tracker_(dtor_tracker) {
517 SetStyle(STYLE_BUTTON); 515 SetStyle(STYLE_BUTTON);
518 }; 516 };
519 virtual ~LabelButtonDtorTracked() { 517 ~LabelButtonDtorTracked() override {
520 dtor_tracker_->push_back("LabelButtonDtorTracked"); 518 dtor_tracker_->push_back("LabelButtonDtorTracked");
521 } 519 }
522 520
523 DtorTrackVector* dtor_tracker_; 521 DtorTrackVector* dtor_tracker_;
524 }; 522 };
525 523
526 class WindowDtorTracked : public Widget { 524 class WindowDtorTracked : public Widget {
527 public: 525 public:
528 explicit WindowDtorTracked(DtorTrackVector* dtor_tracker) 526 explicit WindowDtorTracked(DtorTrackVector* dtor_tracker)
529 : dtor_tracker_(dtor_tracker) { 527 : dtor_tracker_(dtor_tracker) {
530 } 528 }
531 529
532 virtual ~WindowDtorTracked() { 530 ~WindowDtorTracked() override {
533 dtor_tracker_->push_back("WindowDtorTracked"); 531 dtor_tracker_->push_back("WindowDtorTracked");
534 } 532 }
535 533
536 DtorTrackVector* dtor_tracker_; 534 DtorTrackVector* dtor_tracker_;
537 }; 535 };
538 536
539 virtual void SetUp() { 537 void SetUp() override {
540 ViewsTestBase::SetUp(); 538 ViewsTestBase::SetUp();
541 FocusManagerFactory::Install(new TestFocusManagerFactory(&dtor_tracker_)); 539 FocusManagerFactory::Install(new TestFocusManagerFactory(&dtor_tracker_));
542 // Create WindowDtorTracked that uses FocusManagerDtorTracked. 540 // Create WindowDtorTracked that uses FocusManagerDtorTracked.
543 Widget* widget = new WindowDtorTracked(&dtor_tracker_); 541 Widget* widget = new WindowDtorTracked(&dtor_tracker_);
544 Widget::InitParams params; 542 Widget::InitParams params;
545 params.delegate = this; 543 params.delegate = this;
546 params.bounds = gfx::Rect(0, 0, 100, 100); 544 params.bounds = gfx::Rect(0, 0, 100, 100);
547 widget->Init(params); 545 widget->Init(params);
548 546
549 tracked_focus_manager_ = 547 tracked_focus_manager_ =
550 static_cast<FocusManagerDtorTracked*>(GetFocusManager()); 548 static_cast<FocusManagerDtorTracked*>(GetFocusManager());
551 widget->Show(); 549 widget->Show();
552 } 550 }
553 551
554 virtual void TearDown() { 552 void TearDown() override {
555 FocusManagerFactory::Install(NULL); 553 FocusManagerFactory::Install(NULL);
556 ViewsTestBase::TearDown(); 554 ViewsTestBase::TearDown();
557 } 555 }
558 556
559 FocusManager* tracked_focus_manager_; 557 FocusManager* tracked_focus_manager_;
560 DtorTrackVector dtor_tracker_; 558 DtorTrackVector dtor_tracker_;
561 }; 559 };
562 560
563 namespace { 561 namespace {
564 562
565 class FocusInAboutToRequestFocusFromTabTraversalView : public View { 563 class FocusInAboutToRequestFocusFromTabTraversalView : public View {
566 public: 564 public:
567 FocusInAboutToRequestFocusFromTabTraversalView() : view_to_focus_(NULL) {} 565 FocusInAboutToRequestFocusFromTabTraversalView() : view_to_focus_(NULL) {}
568 566
569 void set_view_to_focus(View* view) { view_to_focus_ = view; } 567 void set_view_to_focus(View* view) { view_to_focus_ = view; }
570 568
571 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) override { 569 void AboutToRequestFocusFromTabTraversal(bool reverse) override {
572 view_to_focus_->RequestFocus(); 570 view_to_focus_->RequestFocus();
573 } 571 }
574 572
575 private: 573 private:
576 views::View* view_to_focus_; 574 views::View* view_to_focus_;
577 575
578 DISALLOW_COPY_AND_ASSIGN(FocusInAboutToRequestFocusFromTabTraversalView); 576 DISALLOW_COPY_AND_ASSIGN(FocusInAboutToRequestFocusFromTabTraversalView);
579 }; 577 };
580 } // namespace 578 } // namespace
581 579
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 EXPECT_EQ(v2, GetWidget()->GetFocusManager()->GetStoredFocusView()); 694 EXPECT_EQ(v2, GetWidget()->GetFocusManager()->GetStoredFocusView());
697 } 695 }
698 696
699 namespace { 697 namespace {
700 698
701 class FocusManagerArrowKeyTraversalTest : public FocusManagerTest { 699 class FocusManagerArrowKeyTraversalTest : public FocusManagerTest {
702 public: 700 public:
703 FocusManagerArrowKeyTraversalTest() 701 FocusManagerArrowKeyTraversalTest()
704 : previous_arrow_key_traversal_enabled_(false) { 702 : previous_arrow_key_traversal_enabled_(false) {
705 } 703 }
706 virtual ~FocusManagerArrowKeyTraversalTest() {} 704 ~FocusManagerArrowKeyTraversalTest() override {}
707 705
708 // FocusManagerTest overrides: 706 // FocusManagerTest overrides:
709 virtual void SetUp() override { 707 void SetUp() override {
710 FocusManagerTest::SetUp(); 708 FocusManagerTest::SetUp();
711 709
712 previous_arrow_key_traversal_enabled_ = 710 previous_arrow_key_traversal_enabled_ =
713 FocusManager::arrow_key_traversal_enabled(); 711 FocusManager::arrow_key_traversal_enabled();
714 } 712 }
715 virtual void TearDown() override { 713 void TearDown() override {
716 FocusManager::set_arrow_key_traversal_enabled( 714 FocusManager::set_arrow_key_traversal_enabled(
717 previous_arrow_key_traversal_enabled_); 715 previous_arrow_key_traversal_enabled_);
718 FocusManagerTest::TearDown(); 716 FocusManagerTest::TearDown();
719 } 717 }
720 718
721 private: 719 private:
722 bool previous_arrow_key_traversal_enabled_; 720 bool previous_arrow_key_traversal_enabled_;
723 721
724 DISALLOW_COPY_AND_ASSIGN(FocusManagerArrowKeyTraversalTest); 722 DISALLOW_COPY_AND_ASSIGN(FocusManagerArrowKeyTraversalTest);
725 }; 723 };
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 GetFocusManager()->StoreFocusedView(true); 777 GetFocusManager()->StoreFocusedView(true);
780 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); 778 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView());
781 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); 779 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView());
782 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); 780 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView());
783 } 781 }
784 782
785 class TextInputTestView : public View { 783 class TextInputTestView : public View {
786 public: 784 public:
787 TextInputTestView() {} 785 TextInputTestView() {}
788 786
789 virtual ui::TextInputClient* GetTextInputClient() override { 787 ui::TextInputClient* GetTextInputClient() override {
790 return &text_input_client_; 788 return &text_input_client_;
791 } 789 }
792 790
793 private: 791 private:
794 ui::DummyTextInputClient text_input_client_; 792 ui::DummyTextInputClient text_input_client_;
795 793
796 DISALLOW_COPY_AND_ASSIGN(TextInputTestView); 794 DISALLOW_COPY_AND_ASSIGN(TextInputTestView);
797 }; 795 };
798 796
799 TEST_F(FocusManagerTest, TextInputClient) { 797 TEST_F(FocusManagerTest, TextInputClient) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 836
839 namespace { 837 namespace {
840 838
841 // Trivial WidgetDelegate implementation that allows setting return value of 839 // Trivial WidgetDelegate implementation that allows setting return value of
842 // ShouldAdvanceFocusToTopLevelWidget(). 840 // ShouldAdvanceFocusToTopLevelWidget().
843 class AdvanceFocusWidgetDelegate : public WidgetDelegate { 841 class AdvanceFocusWidgetDelegate : public WidgetDelegate {
844 public: 842 public:
845 explicit AdvanceFocusWidgetDelegate(Widget* widget) 843 explicit AdvanceFocusWidgetDelegate(Widget* widget)
846 : widget_(widget), 844 : widget_(widget),
847 should_advance_focus_to_parent_(false) {} 845 should_advance_focus_to_parent_(false) {}
848 virtual ~AdvanceFocusWidgetDelegate() {} 846 ~AdvanceFocusWidgetDelegate() override {}
849 847
850 void set_should_advance_focus_to_parent(bool value) { 848 void set_should_advance_focus_to_parent(bool value) {
851 should_advance_focus_to_parent_ = value; 849 should_advance_focus_to_parent_ = value;
852 } 850 }
853 851
854 // WidgetDelegate overrides: 852 // WidgetDelegate overrides:
855 virtual bool ShouldAdvanceFocusToTopLevelWidget() const override { 853 bool ShouldAdvanceFocusToTopLevelWidget() const override {
856 return should_advance_focus_to_parent_; 854 return should_advance_focus_to_parent_;
857 } 855 }
858 virtual Widget* GetWidget() override { return widget_; } 856 Widget* GetWidget() override { return widget_; }
859 virtual const Widget* GetWidget() const override { return widget_; } 857 const Widget* GetWidget() const override { return widget_; }
860 858
861 private: 859 private:
862 Widget* widget_; 860 Widget* widget_;
863 bool should_advance_focus_to_parent_; 861 bool should_advance_focus_to_parent_;
864 862
865 DISALLOW_COPY_AND_ASSIGN(AdvanceFocusWidgetDelegate); 863 DISALLOW_COPY_AND_ASSIGN(AdvanceFocusWidgetDelegate);
866 }; 864 };
867 865
868 } // namespace 866 } // namespace
869 867
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); 909 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView());
912 910
913 // Allow focus to go to the parent, and focus backwards which should now move 911 // Allow focus to go to the parent, and focus backwards which should now move
914 // up |widget_view| (in the parent). 912 // up |widget_view| (in the parent).
915 delegate->set_should_advance_focus_to_parent(true); 913 delegate->set_should_advance_focus_to_parent(true);
916 GetFocusManager()->AdvanceFocus(true); 914 GetFocusManager()->AdvanceFocus(true);
917 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); 915 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView());
918 } 916 }
919 917
920 } // namespace views 918 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/focus/focus_manager_factory.cc ('k') | ui/views/focus/focus_traversal_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698