| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Disabled right now as this won't work on BuildBots right now as this test | 5 // Disabled right now as this won't work on BuildBots right now as this test |
| 6 // require the box it runs on to be unlocked (and no screen-savers). | 6 // require the box it runs on to be unlocked (and no screen-savers). |
| 7 // The test actually simulates mouse and key events, so if the screen is locked, | 7 // The test actually simulates mouse and key events, so if the screen is locked, |
| 8 // the events don't go to the Chrome window. | 8 // the events don't go to the Chrome window. |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 class TestNativeButton : public NativeButton { | 692 class TestNativeButton : public NativeButton { |
| 693 public: | 693 public: |
| 694 explicit TestNativeButton(const std::wstring& text) | 694 explicit TestNativeButton(const std::wstring& text) |
| 695 : NativeButton(NULL, text) { | 695 : NativeButton(NULL, text) { |
| 696 }; | 696 }; |
| 697 virtual HWND TestGetNativeControlHWND() { | 697 virtual HWND TestGetNativeControlHWND() { |
| 698 return native_wrapper_->GetTestingHandle(); | 698 return native_wrapper_->GetTestingHandle(); |
| 699 } | 699 } |
| 700 }; | 700 }; |
| 701 | 701 |
| 702 class TestCheckbox : public Checkbox { |
| 703 public: |
| 704 explicit TestCheckbox(const std::wstring& text) : Checkbox(text) { |
| 705 }; |
| 706 virtual HWND TestGetNativeControlHWND() { |
| 707 return native_wrapper_->GetTestingHandle(); |
| 708 } |
| 709 }; |
| 710 |
| 711 class TestRadioButton : public RadioButton { |
| 712 public: |
| 713 explicit TestRadioButton(const std::wstring& text) : RadioButton(text, 1) { |
| 714 }; |
| 715 virtual HWND TestGetNativeControlHWND() { |
| 716 return native_wrapper_->GetTestingHandle(); |
| 717 } |
| 718 }; |
| 719 |
| 702 class TestTextfield : public Textfield { | 720 class TestTextfield : public Textfield { |
| 703 public: | 721 public: |
| 704 TestTextfield() { } | 722 TestTextfield() { } |
| 705 virtual HWND TestGetNativeComponent() { | 723 virtual HWND TestGetNativeComponent() { |
| 706 return native_wrapper_->GetTestingHandle(); | 724 return native_wrapper_->GetTestingHandle(); |
| 707 } | 725 } |
| 708 }; | 726 }; |
| 709 | 727 |
| 710 class TestTabbedPane : public TabbedPane { | 728 class TestTabbedPane : public TabbedPane { |
| 711 public: | 729 public: |
| 712 TestTabbedPane() { } | 730 TestTabbedPane() { } |
| 713 virtual HWND TestGetNativeControlHWND() { | 731 virtual HWND TestGetNativeControlHWND() { |
| 714 return GetNativeControlHWND(); | 732 return GetNativeControlHWND(); |
| 715 } | 733 } |
| 716 }; | 734 }; |
| 717 | 735 |
| 718 // Tests that NativeControls do set the focus View appropriately on the | 736 // Tests that NativeControls do set the focus View appropriately on the |
| 719 // FocusManager. | 737 // FocusManager. |
| 720 TEST_F(FocusManagerTest, FocusNativeControls) { | 738 TEST_F(FocusManagerTest, FocusNativeControls) { |
| 721 TestNativeButton* button = new TestNativeButton(L"Press me"); | 739 TestNativeButton* button = new TestNativeButton(L"Press me"); |
| 740 TestCheckbox* checkbox = new TestCheckbox(L"Checkbox"); |
| 741 TestRadioButton* radio_button = new TestRadioButton(L"RadioButton"); |
| 722 TestTextfield* textfield = new TestTextfield(); | 742 TestTextfield* textfield = new TestTextfield(); |
| 723 TestTabbedPane* tabbed_pane = new TestTabbedPane(); | 743 TestTabbedPane* tabbed_pane = new TestTabbedPane(); |
| 724 TestNativeButton* tab_button = new TestNativeButton(L"tab button"); | 744 TestNativeButton* tab_button = new TestNativeButton(L"tab button"); |
| 725 | 745 |
| 726 content_view_->AddChildView(button); | 746 content_view_->AddChildView(button); |
| 747 content_view_->AddChildView(checkbox); |
| 748 content_view_->AddChildView(radio_button); |
| 727 content_view_->AddChildView(textfield); | 749 content_view_->AddChildView(textfield); |
| 728 content_view_->AddChildView(tabbed_pane); | 750 content_view_->AddChildView(tabbed_pane); |
| 729 tabbed_pane->AddTab(L"Awesome tab", tab_button); | 751 tabbed_pane->AddTab(L"Awesome tab", tab_button); |
| 730 | 752 |
| 731 // Simulate the native HWNDs getting the native focus. | 753 // Simulate the native HWNDs getting the native focus. |
| 732 ::SendMessage(button->TestGetNativeControlHWND(), WM_SETFOCUS, NULL, NULL); | 754 ::SendMessage(button->TestGetNativeControlHWND(), WM_SETFOCUS, NULL, NULL); |
| 733 EXPECT_EQ(button, GetFocusManager()->GetFocusedView()); | 755 EXPECT_EQ(button, GetFocusManager()->GetFocusedView()); |
| 734 | 756 |
| 757 ::SendMessage(checkbox->TestGetNativeControlHWND(), WM_SETFOCUS, NULL, NULL); |
| 758 EXPECT_EQ(checkbox, GetFocusManager()->GetFocusedView()); |
| 759 |
| 760 ::SendMessage(radio_button->TestGetNativeControlHWND(), WM_SETFOCUS, |
| 761 NULL, NULL); |
| 762 EXPECT_EQ(radio_button, GetFocusManager()->GetFocusedView()); |
| 763 |
| 735 ::SendMessage(textfield->TestGetNativeComponent(), WM_SETFOCUS, NULL, NULL); | 764 ::SendMessage(textfield->TestGetNativeComponent(), WM_SETFOCUS, NULL, NULL); |
| 736 EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView()); | 765 EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView()); |
| 737 | 766 |
| 738 ::SendMessage(tabbed_pane->TestGetNativeControlHWND(), WM_SETFOCUS, | 767 ::SendMessage(tabbed_pane->TestGetNativeControlHWND(), WM_SETFOCUS, |
| 739 NULL, NULL); | 768 NULL, NULL); |
| 740 EXPECT_EQ(tabbed_pane, GetFocusManager()->GetFocusedView()); | 769 EXPECT_EQ(tabbed_pane, GetFocusManager()->GetFocusedView()); |
| 741 | 770 |
| 742 ::SendMessage(tab_button->TestGetNativeControlHWND(), WM_SETFOCUS, | 771 ::SendMessage(tab_button->TestGetNativeControlHWND(), WM_SETFOCUS, |
| 743 NULL, NULL); | 772 NULL, NULL); |
| 744 EXPECT_EQ(tab_button, GetFocusManager()->GetFocusedView()); | 773 EXPECT_EQ(tab_button, GetFocusManager()->GetFocusedView()); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 EXPECT_EQ(target.accelerator_count(), 1); | 1140 EXPECT_EQ(target.accelerator_count(), 1); |
| 1112 EXPECT_EQ(NULL, | 1141 EXPECT_EQ(NULL, |
| 1113 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); | 1142 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); |
| 1114 | 1143 |
| 1115 // Hitting the return key again; nothing should happen. | 1144 // Hitting the return key again; nothing should happen. |
| 1116 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); | 1145 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); |
| 1117 EXPECT_EQ(target.accelerator_count(), 1); | 1146 EXPECT_EQ(target.accelerator_count(), 1); |
| 1118 } | 1147 } |
| 1119 | 1148 |
| 1120 } // namespace views | 1149 } // namespace views |
| OLD | NEW |