OLD | NEW |
---|---|
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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 2752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2763 | 2763 |
2764 View* child = new View(); | 2764 View* child = new View(); |
2765 root.AddChildView(child); | 2765 root.AddChildView(child); |
2766 | 2766 |
2767 View* foo1 = new View(); | 2767 View* foo1 = new View(); |
2768 child->AddChildView(foo1); | 2768 child->AddChildView(foo1); |
2769 View* foo2 = new View(); | 2769 View* foo2 = new View(); |
2770 child->AddChildView(foo2); | 2770 child->AddChildView(foo2); |
2771 View* foo3 = new View(); | 2771 View* foo3 = new View(); |
2772 child->AddChildView(foo3); | 2772 child->AddChildView(foo3); |
2773 foo1->set_focusable(true); | 2773 foo1->SetFocusable(true); |
2774 foo2->set_focusable(true); | 2774 foo2->SetFocusable(true); |
2775 foo3->set_focusable(true); | 2775 foo3->SetFocusable(true); |
2776 | 2776 |
2777 ASSERT_EQ(0, child->GetIndexOf(foo1)); | 2777 ASSERT_EQ(0, child->GetIndexOf(foo1)); |
2778 ASSERT_EQ(1, child->GetIndexOf(foo2)); | 2778 ASSERT_EQ(1, child->GetIndexOf(foo2)); |
2779 ASSERT_EQ(2, child->GetIndexOf(foo3)); | 2779 ASSERT_EQ(2, child->GetIndexOf(foo3)); |
2780 ASSERT_EQ(foo2, foo1->GetNextFocusableView()); | 2780 ASSERT_EQ(foo2, foo1->GetNextFocusableView()); |
2781 ASSERT_EQ(foo3, foo2->GetNextFocusableView()); | 2781 ASSERT_EQ(foo3, foo2->GetNextFocusableView()); |
2782 ASSERT_EQ(NULL, foo3->GetNextFocusableView()); | 2782 ASSERT_EQ(NULL, foo3->GetNextFocusableView()); |
2783 | 2783 |
2784 // Move |foo2| at the end. | 2784 // Move |foo2| at the end. |
2785 child->ReorderChildView(foo2, -1); | 2785 child->ReorderChildView(foo2, -1); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2890 // Check that calling |AddChildView()| does not change the order. | 2890 // Check that calling |AddChildView()| does not change the order. |
2891 v1.AddChildView(&v2); | 2891 v1.AddChildView(&v2); |
2892 EXPECT_EQ(0, v1.GetIndexOf(&v2)); | 2892 EXPECT_EQ(0, v1.GetIndexOf(&v2)); |
2893 EXPECT_EQ(1, v1.GetIndexOf(&v3)); | 2893 EXPECT_EQ(1, v1.GetIndexOf(&v3)); |
2894 v1.AddChildView(&v3); | 2894 v1.AddChildView(&v3); |
2895 EXPECT_EQ(0, v1.GetIndexOf(&v2)); | 2895 EXPECT_EQ(0, v1.GetIndexOf(&v2)); |
2896 EXPECT_EQ(1, v1.GetIndexOf(&v3)); | 2896 EXPECT_EQ(1, v1.GetIndexOf(&v3)); |
2897 } | 2897 } |
2898 | 2898 |
2899 //////////////////////////////////////////////////////////////////////////////// | 2899 //////////////////////////////////////////////////////////////////////////////// |
2900 // FocusManager | |
2901 //////////////////////////////////////////////////////////////////////////////// | |
2902 | |
2903 TEST_F(ViewTest, ReviseFocusedViewForUnfocusableView) { | |
2904 // Create a View and focus it. | |
2905 View* view = new View(); | |
2906 view->SetFocusable(true); | |
2907 | |
2908 scoped_ptr<Widget> widget(new Widget()); | |
2909 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | |
2910 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
2911 widget->Init(params); | |
2912 widget->GetRootView()->AddChildView(view); | |
2913 | |
2914 FocusManager* focus_manager = widget->GetFocusManager(); | |
2915 ASSERT_TRUE(focus_manager); | |
2916 | |
2917 focus_manager->SetFocusedView(view); | |
2918 EXPECT_EQ(view, focus_manager->GetFocusedView()); | |
2919 | |
2920 // Disable the focused view and check if it loses focus. | |
2921 view->SetEnabled(false); | |
2922 EXPECT_EQ(NULL, focus_manager->GetFocusedView()); | |
2923 | |
2924 // Re-enable and re-focus. | |
2925 view->SetEnabled(true); | |
2926 focus_manager->SetFocusedView(view); | |
2927 EXPECT_EQ(view, focus_manager->GetFocusedView()); | |
2928 | |
2929 // Hide the focused view and check it it loses focus. | |
2930 view->SetVisible(false); | |
2931 EXPECT_EQ(NULL, focus_manager->GetFocusedView()); | |
2932 | |
2933 // Re-show and re-focus. | |
2934 view->SetVisible(true); | |
2935 focus_manager->SetFocusedView(view); | |
2936 EXPECT_EQ(view, focus_manager->GetFocusedView()); | |
2937 | |
2938 // Set as not focusable and check if it loses focus. | |
2939 view->SetFocusable(false); | |
2940 EXPECT_EQ(NULL, focus_manager->GetFocusedView()); | |
2941 } | |
2942 | |
2943 TEST_F(ViewTest, DisableViewDoesNotActivateWidget) { | |
sky
2013/12/13 17:41:57
Focus related tests need to be in interactive_ui_t
| |
2944 // Create first widget and view, activate the widget, and focus the view. | |
2945 scoped_ptr<Widget> widget1(new Widget()); | |
2946 Widget::InitParams params1 = CreateParams(Widget::InitParams::TYPE_POPUP); | |
2947 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
2948 widget1->Init(params1); | |
2949 | |
2950 View* view1 = new View(); | |
2951 view1->SetFocusable(true); | |
2952 widget1->GetRootView()->AddChildView(view1); | |
2953 | |
2954 widget1->Activate(); | |
2955 EXPECT_TRUE(widget1->IsActive()); | |
2956 | |
2957 FocusManager* focus_manager1 = widget1->GetFocusManager(); | |
2958 ASSERT_TRUE(focus_manager1); | |
2959 focus_manager1->SetFocusedView(view1); | |
2960 EXPECT_EQ(view1, focus_manager1->GetFocusedView()); | |
2961 | |
2962 // Create second widget and view, activate the widget, and focus the view. | |
2963 scoped_ptr<Widget> widget2(new Widget()); | |
2964 Widget::InitParams params2 = CreateParams(Widget::InitParams::TYPE_POPUP); | |
2965 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
2966 widget2->Init(params2); | |
2967 | |
2968 View* view2 = new View(); | |
2969 view2->SetFocusable(true); | |
2970 widget2->GetRootView()->AddChildView(view2); | |
2971 | |
2972 widget2->Activate(); | |
2973 EXPECT_TRUE(widget2->IsActive()); | |
2974 EXPECT_FALSE(widget1->IsActive()); | |
2975 | |
2976 FocusManager* focus_manager2 = widget2->GetFocusManager(); | |
2977 ASSERT_TRUE(focus_manager2); | |
2978 focus_manager2->SetFocusedView(view2); | |
2979 EXPECT_EQ(view2, focus_manager2->GetFocusedView()); | |
2980 | |
2981 // Disable the first view and make sure it loses focus, but its widget is not | |
2982 // activated. | |
2983 view1->SetEnabled(false); | |
2984 EXPECT_NE(view1, focus_manager1->GetFocusedView()); | |
2985 EXPECT_FALSE(widget1->IsActive()); | |
2986 EXPECT_TRUE(widget2->IsActive()); | |
2987 } | |
2988 | |
2989 //////////////////////////////////////////////////////////////////////////////// | |
2900 // Layers | 2990 // Layers |
2901 //////////////////////////////////////////////////////////////////////////////// | 2991 //////////////////////////////////////////////////////////////////////////////// |
2902 | 2992 |
2903 #if defined(USE_AURA) | 2993 #if defined(USE_AURA) |
2904 | 2994 |
2905 namespace { | 2995 namespace { |
2906 | 2996 |
2907 // Test implementation of LayerAnimator. | 2997 // Test implementation of LayerAnimator. |
2908 class TestLayerAnimator : public ui::LayerAnimator { | 2998 class TestLayerAnimator : public ui::LayerAnimator { |
2909 public: | 2999 public: |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3482 const std::vector<ui::Layer*>& child_layers_post = root_layer->children(); | 3572 const std::vector<ui::Layer*>& child_layers_post = root_layer->children(); |
3483 ASSERT_EQ(3u, child_layers_post.size()); | 3573 ASSERT_EQ(3u, child_layers_post.size()); |
3484 EXPECT_EQ(v1->layer(), child_layers_post[0]); | 3574 EXPECT_EQ(v1->layer(), child_layers_post[0]); |
3485 EXPECT_EQ(v2->layer(), child_layers_post[1]); | 3575 EXPECT_EQ(v2->layer(), child_layers_post[1]); |
3486 EXPECT_EQ(v1_old_layer, child_layers_post[2]); | 3576 EXPECT_EQ(v1_old_layer, child_layers_post[2]); |
3487 } | 3577 } |
3488 | 3578 |
3489 #endif // USE_AURA | 3579 #endif // USE_AURA |
3490 | 3580 |
3491 } // namespace views | 3581 } // namespace views |
OLD | NEW |