| 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 "ui/views/accessible_pane_view.h" | 5 #include "ui/views/accessible_pane_view.h" |
| 6 | 6 |
| 7 #include "ui/base/accelerators/accelerator.h" | 7 #include "ui/base/accelerators/accelerator.h" |
| 8 #include "ui/views/controls/button/text_button.h" | 8 #include "ui/views/controls/button/text_button.h" |
| 9 #include "ui/views/layout/fill_layout.h" | 9 #include "ui/views/layout/fill_layout.h" |
| 10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 not_child_button_.reset(new TextButton(this, label)); | 64 not_child_button_.reset(new TextButton(this, label)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 View* TestBarView::GetDefaultFocusableChild() { | 67 View* TestBarView::GetDefaultFocusableChild() { |
| 68 return child_button_.get(); | 68 return child_button_.get(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST_F(AccessiblePaneViewTest, SimpleSetPaneFocus) { | 71 TEST_F(AccessiblePaneViewTest, SimpleSetPaneFocus) { |
| 72 TestBarView* test_view = new TestBarView(); | 72 TestBarView* test_view = new TestBarView(); |
| 73 scoped_ptr<Widget> widget(new Widget()); | 73 scoped_ptr<Widget> widget(new Widget()); |
| 74 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 74 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 75 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 76 params.bounds = gfx::Rect(50, 50, 650, 650); | 75 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 77 widget->Init(params); | 76 widget->Init(params); |
| 78 View* root = widget->GetRootView(); | 77 View* root = widget->GetRootView(); |
| 79 root->AddChildView(test_view); | 78 root->AddChildView(test_view); |
| 80 widget->Show(); | 79 widget->Show(); |
| 81 widget->Activate(); | 80 widget->Activate(); |
| 82 | 81 |
| 83 // Set pane focus succeeds, focus on child. | 82 // Set pane focus succeeds, focus on child. |
| 84 EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); | 83 EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); |
| 85 EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); | 84 EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); |
| 86 EXPECT_EQ(test_view->child_button(), | 85 EXPECT_EQ(test_view->child_button(), |
| 87 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 86 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 88 | 87 |
| 89 // Set focus on non child view, focus failed, stays on pane. | 88 // Set focus on non child view, focus failed, stays on pane. |
| 90 EXPECT_TRUE(test_view->SetPaneFocus(test_view->not_child_button())); | 89 EXPECT_TRUE(test_view->SetPaneFocus(test_view->not_child_button())); |
| 91 EXPECT_FALSE(test_view->not_child_button() == | 90 EXPECT_FALSE(test_view->not_child_button() == |
| 92 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 91 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 93 EXPECT_EQ(test_view->child_button(), | 92 EXPECT_EQ(test_view->child_button(), |
| 94 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 93 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 95 widget->CloseNow(); | 94 widget->CloseNow(); |
| 96 widget.reset(); | 95 widget.reset(); |
| 97 } | 96 } |
| 98 | 97 |
| 99 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { | 98 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { |
| 100 TestBarView* test_view = new TestBarView(); | 99 TestBarView* test_view = new TestBarView(); |
| 101 TestBarView* test_view_2 = new TestBarView(); | 100 TestBarView* test_view_2 = new TestBarView(); |
| 102 scoped_ptr<Widget> widget(new Widget()); | 101 scoped_ptr<Widget> widget(new Widget()); |
| 103 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 102 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 104 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 105 params.bounds = gfx::Rect(50, 50, 650, 650); | 103 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 106 widget->Init(params); | 104 widget->Init(params); |
| 107 View* root = widget->GetRootView(); | 105 View* root = widget->GetRootView(); |
| 108 root->AddChildView(test_view); | 106 root->AddChildView(test_view); |
| 109 root->AddChildView(test_view_2); | 107 root->AddChildView(test_view_2); |
| 110 widget->Show(); | 108 widget->Show(); |
| 111 widget->Activate(); | 109 widget->Activate(); |
| 112 | 110 |
| 113 // Set pane focus succeeds, focus on child. | 111 // Set pane focus succeeds, focus on child. |
| 114 EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); | 112 EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); |
| 115 EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); | 113 EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); |
| 116 EXPECT_EQ(test_view->child_button(), | 114 EXPECT_EQ(test_view->child_button(), |
| 117 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 115 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 118 | 116 |
| 119 // Set focus on another test_view, focus move to that pane. | 117 // Set focus on another test_view, focus move to that pane. |
| 120 EXPECT_TRUE(test_view_2->SetPaneFocus(test_view_2->second_child_button())); | 118 EXPECT_TRUE(test_view_2->SetPaneFocus(test_view_2->second_child_button())); |
| 121 EXPECT_FALSE(test_view->child_button() == | 119 EXPECT_FALSE(test_view->child_button() == |
| 122 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 120 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 123 EXPECT_EQ(test_view_2->second_child_button(), | 121 EXPECT_EQ(test_view_2->second_child_button(), |
| 124 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 122 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 125 widget->CloseNow(); | 123 widget->CloseNow(); |
| 126 widget.reset(); | 124 widget.reset(); |
| 127 } | 125 } |
| 128 | 126 |
| 129 TEST_F(AccessiblePaneViewTest, PaneFocusTraversal) { | 127 TEST_F(AccessiblePaneViewTest, PaneFocusTraversal) { |
| 130 TestBarView* test_view = new TestBarView(); | 128 TestBarView* test_view = new TestBarView(); |
| 131 TestBarView* original_test_view = new TestBarView(); | 129 TestBarView* original_test_view = new TestBarView(); |
| 132 scoped_ptr<Widget> widget(new Widget()); | 130 scoped_ptr<Widget> widget(new Widget()); |
| 133 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 131 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 134 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 135 params.bounds = gfx::Rect(50, 50, 650, 650); | 132 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 136 widget->Init(params); | 133 widget->Init(params); |
| 137 View* root = widget->GetRootView(); | 134 View* root = widget->GetRootView(); |
| 138 root->AddChildView(original_test_view); | 135 root->AddChildView(original_test_view); |
| 139 root->AddChildView(test_view); | 136 root->AddChildView(test_view); |
| 140 widget->Show(); | 137 widget->Show(); |
| 141 widget->Activate(); | 138 widget->Activate(); |
| 142 | 139 |
| 143 // Set pane focus on first view. | 140 // Set pane focus on first view. |
| 144 EXPECT_TRUE(original_test_view->SetPaneFocus( | 141 EXPECT_TRUE(original_test_view->SetPaneFocus( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 166 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 163 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 167 | 164 |
| 168 // ESC | 165 // ESC |
| 169 test_view->AcceleratorPressed(test_view->escape_key()); | 166 test_view->AcceleratorPressed(test_view->escape_key()); |
| 170 EXPECT_EQ(original_test_view->third_child_button(), | 167 EXPECT_EQ(original_test_view->third_child_button(), |
| 171 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 168 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 172 widget->CloseNow(); | 169 widget->CloseNow(); |
| 173 widget.reset(); | 170 widget.reset(); |
| 174 } | 171 } |
| 175 } // namespace views | 172 } // namespace views |
| OLD | NEW |