| 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 |
| 11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
| 12 #include "base/gfx/rect.h" | 12 #include "base/gfx/rect.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
| 15 #include "views/background.h" | 15 #include "views/background.h" |
| 16 #include "views/border.h" | 16 #include "views/border.h" |
| 17 #include "views/controls/button/checkbox.h" | 17 #include "views/controls/button/checkbox.h" |
| 18 #include "views/controls/button/native_button.h" | 18 #include "views/controls/button/native_button.h" |
| 19 #include "views/controls/button/radio_button.h" | 19 #include "views/controls/button/radio_button.h" |
| 20 #include "views/controls/combobox/combobox.h" | 20 #include "views/controls/combobox/combobox.h" |
| 21 #include "views/controls/combobox/native_combobox_wrapper.h" |
| 21 #include "views/controls/label.h" | 22 #include "views/controls/label.h" |
| 22 #include "views/controls/link.h" | 23 #include "views/controls/link.h" |
| 23 #include "views/controls/scroll_view.h" | 24 #include "views/controls/scroll_view.h" |
| 24 #include "views/controls/tabbed_pane.h" | 25 #include "views/controls/tabbed_pane.h" |
| 25 #include "views/controls/textfield/textfield.h" | 26 #include "views/controls/textfield/textfield.h" |
| 26 #include "views/widget/accelerator_handler.h" | 27 #include "views/widget/accelerator_handler.h" |
| 27 #include "views/widget/root_view.h" | 28 #include "views/widget/root_view.h" |
| 28 #include "views/widget/widget_win.h" | 29 #include "views/widget/widget_win.h" |
| 29 #include "views/window/window_delegate.h" | 30 #include "views/window/window_delegate.h" |
| 30 #include "views/window/window_win.h" | 31 #include "views/window/window_win.h" |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 }; | 719 }; |
| 719 | 720 |
| 720 class TestTextfield : public Textfield { | 721 class TestTextfield : public Textfield { |
| 721 public: | 722 public: |
| 722 TestTextfield() { } | 723 TestTextfield() { } |
| 723 virtual HWND TestGetNativeComponent() { | 724 virtual HWND TestGetNativeComponent() { |
| 724 return native_wrapper_->GetTestingHandle(); | 725 return native_wrapper_->GetTestingHandle(); |
| 725 } | 726 } |
| 726 }; | 727 }; |
| 727 | 728 |
| 729 class TestCombobox : public Combobox, public Combobox::Model { |
| 730 public: |
| 731 TestCombobox() : Combobox(this) { } |
| 732 virtual HWND TestGetNativeComponent() { |
| 733 return native_wrapper_->GetTestingHandle(); |
| 734 } |
| 735 virtual int GetItemCount(Combobox* source) { |
| 736 return 10; |
| 737 } |
| 738 virtual std::wstring GetItemAt(Combobox* source, int index) { |
| 739 return L"Hello combo"; |
| 740 } |
| 741 }; |
| 742 |
| 728 class TestTabbedPane : public TabbedPane { | 743 class TestTabbedPane : public TabbedPane { |
| 729 public: | 744 public: |
| 730 TestTabbedPane() { } | 745 TestTabbedPane() { } |
| 731 virtual HWND TestGetNativeControlHWND() { | 746 virtual HWND TestGetNativeControlHWND() { |
| 732 return GetNativeControlHWND(); | 747 return GetNativeControlHWND(); |
| 733 } | 748 } |
| 734 }; | 749 }; |
| 735 | 750 |
| 736 // Tests that NativeControls do set the focus View appropriately on the | 751 // Tests that NativeControls do set the focus View appropriately on the |
| 737 // FocusManager. | 752 // FocusManager. |
| 738 TEST_F(FocusManagerTest, FocusNativeControls) { | 753 TEST_F(FocusManagerTest, FocusNativeControls) { |
| 739 TestNativeButton* button = new TestNativeButton(L"Press me"); | 754 TestNativeButton* button = new TestNativeButton(L"Press me"); |
| 740 TestCheckbox* checkbox = new TestCheckbox(L"Checkbox"); | 755 TestCheckbox* checkbox = new TestCheckbox(L"Checkbox"); |
| 741 TestRadioButton* radio_button = new TestRadioButton(L"RadioButton"); | 756 TestRadioButton* radio_button = new TestRadioButton(L"RadioButton"); |
| 742 TestTextfield* textfield = new TestTextfield(); | 757 TestTextfield* textfield = new TestTextfield(); |
| 758 TestCombobox* combobox = new TestCombobox(); |
| 743 TestTabbedPane* tabbed_pane = new TestTabbedPane(); | 759 TestTabbedPane* tabbed_pane = new TestTabbedPane(); |
| 744 TestNativeButton* tab_button = new TestNativeButton(L"tab button"); | 760 TestNativeButton* tab_button = new TestNativeButton(L"tab button"); |
| 745 | 761 |
| 746 content_view_->AddChildView(button); | 762 content_view_->AddChildView(button); |
| 747 content_view_->AddChildView(checkbox); | 763 content_view_->AddChildView(checkbox); |
| 748 content_view_->AddChildView(radio_button); | 764 content_view_->AddChildView(radio_button); |
| 749 content_view_->AddChildView(textfield); | 765 content_view_->AddChildView(textfield); |
| 766 content_view_->AddChildView(combobox); |
| 750 content_view_->AddChildView(tabbed_pane); | 767 content_view_->AddChildView(tabbed_pane); |
| 751 tabbed_pane->AddTab(L"Awesome tab", tab_button); | 768 tabbed_pane->AddTab(L"Awesome tab", tab_button); |
| 752 | 769 |
| 753 // Simulate the native HWNDs getting the native focus. | 770 // Simulate the native HWNDs getting the native focus. |
| 754 ::SendMessage(button->TestGetNativeControlHWND(), WM_SETFOCUS, NULL, NULL); | 771 ::SendMessage(button->TestGetNativeControlHWND(), WM_SETFOCUS, NULL, NULL); |
| 755 EXPECT_EQ(button, GetFocusManager()->GetFocusedView()); | 772 EXPECT_EQ(button, GetFocusManager()->GetFocusedView()); |
| 756 | 773 |
| 757 ::SendMessage(checkbox->TestGetNativeControlHWND(), WM_SETFOCUS, NULL, NULL); | 774 ::SendMessage(checkbox->TestGetNativeControlHWND(), WM_SETFOCUS, NULL, NULL); |
| 758 EXPECT_EQ(checkbox, GetFocusManager()->GetFocusedView()); | 775 EXPECT_EQ(checkbox, GetFocusManager()->GetFocusedView()); |
| 759 | 776 |
| 760 ::SendMessage(radio_button->TestGetNativeControlHWND(), WM_SETFOCUS, | 777 ::SendMessage(radio_button->TestGetNativeControlHWND(), WM_SETFOCUS, |
| 761 NULL, NULL); | 778 NULL, NULL); |
| 762 EXPECT_EQ(radio_button, GetFocusManager()->GetFocusedView()); | 779 EXPECT_EQ(radio_button, GetFocusManager()->GetFocusedView()); |
| 763 | 780 |
| 764 ::SendMessage(textfield->TestGetNativeComponent(), WM_SETFOCUS, NULL, NULL); | 781 ::SendMessage(textfield->TestGetNativeComponent(), WM_SETFOCUS, NULL, NULL); |
| 765 EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView()); | 782 EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView()); |
| 766 | 783 |
| 784 ::SendMessage(combobox->TestGetNativeComponent(), WM_SETFOCUS, NULL, NULL); |
| 785 EXPECT_EQ(combobox, GetFocusManager()->GetFocusedView()); |
| 786 |
| 767 ::SendMessage(tabbed_pane->TestGetNativeControlHWND(), WM_SETFOCUS, | 787 ::SendMessage(tabbed_pane->TestGetNativeControlHWND(), WM_SETFOCUS, |
| 768 NULL, NULL); | 788 NULL, NULL); |
| 769 EXPECT_EQ(tabbed_pane, GetFocusManager()->GetFocusedView()); | 789 EXPECT_EQ(tabbed_pane, GetFocusManager()->GetFocusedView()); |
| 770 | 790 |
| 771 ::SendMessage(tab_button->TestGetNativeControlHWND(), WM_SETFOCUS, | 791 ::SendMessage(tab_button->TestGetNativeControlHWND(), WM_SETFOCUS, |
| 772 NULL, NULL); | 792 NULL, NULL); |
| 773 EXPECT_EQ(tab_button, GetFocusManager()->GetFocusedView()); | 793 EXPECT_EQ(tab_button, GetFocusManager()->GetFocusedView()); |
| 774 } | 794 } |
| 775 | 795 |
| 776 // Test that when activating/deactivating the top window, the focus is stored/ | 796 // Test that when activating/deactivating the top window, the focus is stored/ |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 EXPECT_EQ(target.accelerator_count(), 1); | 1128 EXPECT_EQ(target.accelerator_count(), 1); |
| 1109 EXPECT_EQ(NULL, | 1129 EXPECT_EQ(NULL, |
| 1110 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); | 1130 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); |
| 1111 | 1131 |
| 1112 // Hitting the return key again; nothing should happen. | 1132 // Hitting the return key again; nothing should happen. |
| 1113 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); | 1133 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); |
| 1114 EXPECT_EQ(target.accelerator_count(), 1); | 1134 EXPECT_EQ(target.accelerator_count(), 1); |
| 1115 } | 1135 } |
| 1116 | 1136 |
| 1117 } // namespace views | 1137 } // namespace views |
| OLD | NEW |