Chromium Code Reviews| 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/label_button.h" | 8 #include "ui/views/controls/button/label_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" |
| 11 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
| 12 | 12 |
| 13 #if defined(OS_MACOSX) | |
| 14 #include "ui/base/test/scoped_fake_nswindow_focus.h" | |
| 15 #endif | |
| 16 | |
| 13 namespace views { | 17 namespace views { |
| 14 | 18 |
| 15 // TODO(alicet): bring pane rotation into views and add tests. | 19 // TODO(alicet): bring pane rotation into views and add tests. |
| 16 // See browser_view.cc for details. | 20 // See browser_view.cc for details. |
| 17 | 21 |
| 18 typedef ViewsTestBase AccessiblePaneViewTest; | 22 typedef ViewsTestBase AccessiblePaneViewTest; |
| 19 | 23 |
| 20 class TestBarView : public AccessiblePaneView, | 24 class TestBarView : public AccessiblePaneView, |
| 21 public ButtonListener { | 25 public ButtonListener { |
| 22 public: | 26 public: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 // Set focus on non child view, focus failed, stays on pane. | 95 // Set focus on non child view, focus failed, stays on pane. |
| 92 EXPECT_TRUE(test_view->SetPaneFocus(test_view->not_child_button())); | 96 EXPECT_TRUE(test_view->SetPaneFocus(test_view->not_child_button())); |
| 93 EXPECT_FALSE(test_view->not_child_button() == | 97 EXPECT_FALSE(test_view->not_child_button() == |
| 94 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 98 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 95 EXPECT_EQ(test_view->child_button(), | 99 EXPECT_EQ(test_view->child_button(), |
| 96 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 100 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 97 widget->CloseNow(); | 101 widget->CloseNow(); |
| 98 widget.reset(); | 102 widget.reset(); |
| 99 } | 103 } |
| 100 | 104 |
| 101 // This test will not work properly in Windows because it uses ::GetNextWindow | |
| 102 // on deactivate which is rather unpredictable where the focus will land. | |
| 103 TEST_F(AccessiblePaneViewTest, SetPaneFocusAndRestore) { | 105 TEST_F(AccessiblePaneViewTest, SetPaneFocusAndRestore) { |
| 106 #if defined(OS_MACOSX) | |
| 107 // On Aura platforms, this test creates Ash windows and only interacts with | |
| 108 // the Ash window manager. On Mac, it creates native windows, but since unit | |
| 109 // tests cannot gain key status, fake it out here. | |
| 110 ui::test::ScopedFakeNSWindowFocus fake_focus; | |
| 111 #endif | |
| 112 | |
| 104 View* test_view_main = new View(); | 113 View* test_view_main = new View(); |
| 105 scoped_ptr<Widget> widget_main(new Widget()); | 114 scoped_ptr<Widget> widget_main(new Widget()); |
| 106 Widget::InitParams params_main = CreateParams(Widget::InitParams::TYPE_POPUP); | 115 Widget::InitParams params_main = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 107 params_main.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 116 params_main.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 117 params_main.activatable = Widget::InitParams::ACTIVATABLE_YES; | |
| 108 params_main.bounds = gfx::Rect(0, 0, 20, 20); | 118 params_main.bounds = gfx::Rect(0, 0, 20, 20); |
| 109 widget_main->Init(params_main); | 119 widget_main->Init(params_main); |
| 110 View* root_main = widget_main->GetRootView(); | 120 View* root_main = widget_main->GetRootView(); |
| 111 root_main->AddChildView(test_view_main); | 121 root_main->AddChildView(test_view_main); |
| 112 widget_main->Activate(); | 122 widget_main->Activate(); |
| 113 test_view_main->GetFocusManager()->SetFocusedView(test_view_main); | 123 test_view_main->GetFocusManager()->SetFocusedView(test_view_main); |
| 114 EXPECT_TRUE(widget_main->IsActive()); | 124 EXPECT_TRUE(widget_main->IsActive()); |
| 115 EXPECT_TRUE(test_view_main->HasFocus()); | 125 EXPECT_TRUE(test_view_main->HasFocus()); |
| 116 | 126 |
| 117 TestBarView* test_view_bar = new TestBarView(); | 127 TestBarView* test_view_bar = new TestBarView(); |
| 118 scoped_ptr<Widget> widget_bar(new Widget()); | 128 scoped_ptr<Widget> widget_bar(new Widget()); |
| 119 Widget::InitParams params_bar = CreateParams(Widget::InitParams::TYPE_POPUP); | 129 Widget::InitParams params_bar = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 120 params_bar.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 130 params_bar.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 131 params_bar.activatable = Widget::InitParams::ACTIVATABLE_YES; | |
| 121 params_bar.bounds = gfx::Rect(50, 50, 650, 650); | 132 params_bar.bounds = gfx::Rect(50, 50, 650, 650); |
| 122 widget_bar->Init(params_bar); | 133 widget_bar->Init(params_bar); |
| 123 View* root_bar = widget_bar->GetRootView(); | 134 View* root_bar = widget_bar->GetRootView(); |
| 124 root_bar->AddChildView(test_view_bar); | 135 root_bar->AddChildView(test_view_bar); |
| 125 widget_bar->Show(); | 136 widget_bar->Show(); |
| 126 widget_bar->Activate(); | 137 widget_bar->Activate(); |
| 127 | 138 |
| 128 // Set pane focus succeeds, focus on child. | 139 // Set pane focus succeeds, focus on child. |
| 129 EXPECT_TRUE(test_view_bar->SetPaneFocusAndFocusDefault()); | 140 EXPECT_TRUE(test_view_bar->SetPaneFocusAndFocusDefault()); |
| 130 EXPECT_FALSE(test_view_main->HasFocus()); | 141 EXPECT_FALSE(test_view_main->HasFocus()); |
| 131 EXPECT_FALSE(widget_main->IsActive()); | 142 EXPECT_FALSE(widget_main->IsActive()); |
| 132 EXPECT_EQ(test_view_bar, test_view_bar->GetPaneFocusTraversable()); | 143 EXPECT_EQ(test_view_bar, test_view_bar->GetPaneFocusTraversable()); |
| 133 EXPECT_EQ(test_view_bar->child_button(), | 144 EXPECT_EQ(test_view_bar->child_button(), |
| 134 test_view_bar->GetWidget()->GetFocusManager()->GetFocusedView()); | 145 test_view_bar->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 135 | 146 |
| 147 // Deactivate() is only reliable on Ash. On Windows it uses ::GetNextWindow | |
|
tapted
2015/08/06 06:49:12
nit: ::GetNextWindow()
jackhou1
2015/08/06 07:35:02
Done.
| |
| 148 // simply activates another window, and which one is not predictable. On Mac, | |
|
tapted
2015/08/06 06:49:12
simply activates -> to simply activate
jackhou1
2015/08/06 07:35:02
Done.
| |
| 149 // Deactivate() is not implemented. | |
|
tapted
2015/08/06 06:49:12
Add:
Note that TestBarView calls set_allow_deacti
jackhou1
2015/08/06 07:35:02
Done.
| |
| 150 #if !defined(OS_MACOSX) || defined(USE_ASH) | |
| 151 // Esc should deactivate the widget. | |
| 136 test_view_bar->AcceleratorPressed(test_view_bar->escape_key()); | 152 test_view_bar->AcceleratorPressed(test_view_bar->escape_key()); |
| 137 EXPECT_TRUE(widget_main->IsActive()); | 153 EXPECT_TRUE(widget_main->IsActive()); |
| 138 EXPECT_FALSE(widget_bar->IsActive()); | 154 EXPECT_FALSE(widget_bar->IsActive()); |
| 155 #endif | |
| 139 | 156 |
| 140 widget_bar->CloseNow(); | 157 widget_bar->CloseNow(); |
| 141 widget_bar.reset(); | 158 widget_bar.reset(); |
| 142 | 159 |
| 143 widget_main->CloseNow(); | 160 widget_main->CloseNow(); |
| 144 widget_main.reset(); | 161 widget_main.reset(); |
| 145 } | 162 } |
| 146 | 163 |
| 147 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { | 164 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { |
| 148 TestBarView* test_view = new TestBarView(); | 165 TestBarView* test_view = new TestBarView(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 231 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 215 | 232 |
| 216 // ESC | 233 // ESC |
| 217 test_view->AcceleratorPressed(test_view->escape_key()); | 234 test_view->AcceleratorPressed(test_view->escape_key()); |
| 218 EXPECT_EQ(original_test_view->third_child_button(), | 235 EXPECT_EQ(original_test_view->third_child_button(), |
| 219 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 236 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 220 widget->CloseNow(); | 237 widget->CloseNow(); |
| 221 widget.reset(); | 238 widget.reset(); |
| 222 } | 239 } |
| 223 } // namespace views | 240 } // namespace views |
| OLD | NEW |