OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 View* view1 = new View(); | 843 View* view1 = new View(); |
844 view1->SetFocusable(true); | 844 view1->SetFocusable(true); |
845 View* view2 = new View(); | 845 View* view2 = new View(); |
846 view2->SetFocusable(true); | 846 view2->SetFocusable(true); |
847 content_view_->AddChildView(view1); | 847 content_view_->AddChildView(view1); |
848 content_view_->AddChildView(view2); | 848 content_view_->AddChildView(view2); |
849 | 849 |
850 TestFocusChangeListener listener; | 850 TestFocusChangeListener listener; |
851 AddFocusChangeListener(&listener); | 851 AddFocusChangeListener(&listener); |
852 | 852 |
| 853 // Visual Studio 2010 has problems converting NULL to the null pointer for |
| 854 // std::pair. See http://connect.microsoft.com/VisualStudio/feedback/details/
520043/error-converting-from-null-to-a-pointer-type-in-std-pair |
| 855 // It will work if we pass nullptr. |
| 856 #if defined(_MSC_VER) && _MSC_VER >= 1600 |
| 857 views::View* null_view = nullptr; |
| 858 #else |
| 859 views::View* null_view = NULL; |
| 860 #endif |
| 861 |
853 view1->RequestFocus(); | 862 view1->RequestFocus(); |
854 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); | 863 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); |
855 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(NULL, view1)); | 864 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(null_view, view1)); |
856 listener.ClearFocusChanges(); | 865 listener.ClearFocusChanges(); |
857 | 866 |
858 view2->RequestFocus(); | 867 view2->RequestFocus(); |
859 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); | 868 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); |
860 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view1, view2)); | 869 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view1, view2)); |
861 listener.ClearFocusChanges(); | 870 listener.ClearFocusChanges(); |
862 | 871 |
863 GetFocusManager()->ClearFocus(); | 872 GetFocusManager()->ClearFocus(); |
864 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); | 873 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); |
865 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view2, NULL)); | 874 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view2, null_view)); |
866 } | 875 } |
867 | 876 |
868 class TestNativeButton : public NativeButton { | 877 class TestNativeButton : public NativeButton { |
869 public: | 878 public: |
870 explicit TestNativeButton(const std::wstring& text) | 879 explicit TestNativeButton(const std::wstring& text) |
871 : NativeButton(NULL, text) { | 880 : NativeButton(NULL, text) { |
872 }; | 881 }; |
873 virtual gfx::NativeView TestGetNativeControlView() { | 882 virtual gfx::NativeView TestGetNativeControlView() { |
874 return native_wrapper_->GetTestingHandle(); | 883 return native_wrapper_->GetTestingHandle(); |
875 } | 884 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 content_view_->AddChildView(view); | 989 content_view_->AddChildView(view); |
981 message_loop()->RunAllPending(); | 990 message_loop()->RunAllPending(); |
982 | 991 |
983 TestFocusChangeListener listener; | 992 TestFocusChangeListener listener; |
984 AddFocusChangeListener(&listener); | 993 AddFocusChangeListener(&listener); |
985 | 994 |
986 view->RequestFocus(); | 995 view->RequestFocus(); |
987 message_loop()->RunAllPending(); | 996 message_loop()->RunAllPending(); |
988 // MessageLoopForUI::current()->Run(new AcceleratorHandler()); | 997 // MessageLoopForUI::current()->Run(new AcceleratorHandler()); |
989 | 998 |
| 999 // Visual Studio 2010 has problems converting NULL to the null pointer for |
| 1000 // std::pair. See http://connect.microsoft.com/VisualStudio/feedback/details/
520043/error-converting-from-null-to-a-pointer-type-in-std-pair |
| 1001 // It will work if we pass nullptr. |
| 1002 #if defined(_MSC_VER) && _MSC_VER >= 1600 |
| 1003 views::View* null_view = nullptr; |
| 1004 #else |
| 1005 views::View* null_view = NULL; |
| 1006 #endif |
| 1007 |
990 // Deacivate the window, it should store its focus. | 1008 // Deacivate the window, it should store its focus. |
991 SimulateDeactivateWindow(); | 1009 SimulateDeactivateWindow(); |
992 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); | 1010 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); |
993 ASSERT_EQ(2, static_cast<int>(listener.focus_changes().size())); | 1011 ASSERT_EQ(2, static_cast<int>(listener.focus_changes().size())); |
994 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(NULL, view)); | 1012 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(null_view, view)); |
995 EXPECT_TRUE(listener.focus_changes()[1] == ViewPair(view, NULL)); | 1013 EXPECT_TRUE(listener.focus_changes()[1] == ViewPair(view, null_view)); |
996 listener.ClearFocusChanges(); | 1014 listener.ClearFocusChanges(); |
997 | 1015 |
998 // Reactivate, focus should come-back to the previously focused view. | 1016 // Reactivate, focus should come-back to the previously focused view. |
999 SimulateActivateWindow(); | 1017 SimulateActivateWindow(); |
1000 EXPECT_EQ(view, GetFocusManager()->GetFocusedView()); | 1018 EXPECT_EQ(view, GetFocusManager()->GetFocusedView()); |
1001 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); | 1019 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); |
1002 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(NULL, view)); | 1020 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(null_view, view)); |
1003 listener.ClearFocusChanges(); | 1021 listener.ClearFocusChanges(); |
1004 | 1022 |
1005 // Same test with a NativeControl. | 1023 // Same test with a NativeControl. |
1006 button->RequestFocus(); | 1024 button->RequestFocus(); |
1007 SimulateDeactivateWindow(); | 1025 SimulateDeactivateWindow(); |
1008 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); | 1026 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); |
1009 ASSERT_EQ(2, static_cast<int>(listener.focus_changes().size())); | 1027 ASSERT_EQ(2, static_cast<int>(listener.focus_changes().size())); |
1010 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view, button)); | 1028 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view, button)); |
1011 EXPECT_TRUE(listener.focus_changes()[1] == ViewPair(button, NULL)); | 1029 EXPECT_TRUE(listener.focus_changes()[1] == ViewPair(button, null_view)); |
1012 listener.ClearFocusChanges(); | 1030 listener.ClearFocusChanges(); |
1013 | 1031 |
1014 SimulateActivateWindow(); | 1032 SimulateActivateWindow(); |
1015 EXPECT_EQ(button, GetFocusManager()->GetFocusedView()); | 1033 EXPECT_EQ(button, GetFocusManager()->GetFocusedView()); |
1016 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); | 1034 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); |
1017 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(NULL, button)); | 1035 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(null_view, button)); |
1018 listener.ClearFocusChanges(); | 1036 listener.ClearFocusChanges(); |
1019 | 1037 |
1020 /* | 1038 /* |
1021 // Now test that while the window is inactive we can change the focused view | 1039 // Now test that while the window is inactive we can change the focused view |
1022 // (we do that in several places). | 1040 // (we do that in several places). |
1023 SimulateDeactivateWindow(); | 1041 SimulateDeactivateWindow(); |
1024 // TODO: would have to mock the window being inactive (with a TestWidgetWin | 1042 // TODO: would have to mock the window being inactive (with a TestWidgetWin |
1025 // that would return false on IsActive()). | 1043 // that would return false on IsActive()). |
1026 GetFocusManager()->SetFocusedView(view); | 1044 GetFocusManager()->SetFocusedView(view); |
1027 ::SendMessage(window_->GetNativeWindow(), WM_ACTIVATE, WA_ACTIVE, NULL); | 1045 ::SendMessage(window_->GetNativeWindow(), WM_ACTIVATE, WA_ACTIVE, NULL); |
1028 | 1046 |
1029 EXPECT_EQ(view, GetFocusManager()->GetFocusedView()); | 1047 EXPECT_EQ(view, GetFocusManager()->GetFocusedView()); |
1030 ASSERT_EQ(2, static_cast<int>(listener.focus_changes().size())); | 1048 ASSERT_EQ(2, static_cast<int>(listener.focus_changes().size())); |
1031 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(button, NULL)); | 1049 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(button, null_view)); |
1032 EXPECT_TRUE(listener.focus_changes()[1] == ViewPair(NULL, view)); | 1050 EXPECT_TRUE(listener.focus_changes()[1] == ViewPair(null_view, view)); |
1033 */ | 1051 */ |
1034 } | 1052 } |
1035 | 1053 |
1036 TEST_F(FocusManagerTest, ContainsView) { | 1054 TEST_F(FocusManagerTest, ContainsView) { |
1037 View* view = new View(); | 1055 View* view = new View(); |
1038 scoped_ptr<View> detached_view(new View()); | 1056 scoped_ptr<View> detached_view(new View()); |
1039 TabbedPane* tabbed_pane = new TabbedPane(); | 1057 TabbedPane* tabbed_pane = new TabbedPane(); |
1040 TabbedPane* nested_tabbed_pane = new TabbedPane(); | 1058 TabbedPane* nested_tabbed_pane = new TabbedPane(); |
1041 NativeButton* tab_button = new NativeButton(NULL, L"tab button"); | 1059 NativeButton* tab_button = new NativeButton(NULL, L"tab button"); |
1042 | 1060 |
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 // Focus manager should be the last one to destruct. | 1739 // Focus manager should be the last one to destruct. |
1722 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); | 1740 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); |
1723 | 1741 |
1724 // Clear window_ so that we don't try to close it again. | 1742 // Clear window_ so that we don't try to close it again. |
1725 window_ = NULL; | 1743 window_ = NULL; |
1726 } | 1744 } |
1727 | 1745 |
1728 #endif // defined(OS_CHROMEOS) | 1746 #endif // defined(OS_CHROMEOS) |
1729 | 1747 |
1730 } // namespace views | 1748 } // namespace views |
OLD | NEW |