| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 105 // This test will not work properly in Windows because it uses ::GetNextWindow |
| 102 // on deactivate which is rather unpredictable where the focus will land. | 106 // on deactivate which is rather unpredictable where the focus will land. |
| 103 TEST_F(AccessiblePaneViewTest, SetPaneFocusAndRestore) { | 107 TEST_F(AccessiblePaneViewTest, SetPaneFocusAndRestore) { |
| 108 #if defined(OS_MACOSX) |
| 109 // On Aura platforms, this test creates Ash windows and only interacts with |
| 110 // the Ash window manager. On Mac, it creates native windows, but since unit |
| 111 // tests cannot gain key status, fake it out here. |
| 112 ui::test::ScopedFakeNSWindowFocus fake_focus; |
| 113 #endif |
| 114 |
| 104 View* test_view_main = new View(); | 115 View* test_view_main = new View(); |
| 105 scoped_ptr<Widget> widget_main(new Widget()); | 116 scoped_ptr<Widget> widget_main(new Widget()); |
| 106 Widget::InitParams params_main = CreateParams(Widget::InitParams::TYPE_POPUP); | 117 Widget::InitParams params_main = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 107 params_main.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 118 params_main.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 108 params_main.bounds = gfx::Rect(0, 0, 20, 20); | 119 params_main.bounds = gfx::Rect(0, 0, 20, 20); |
| 109 widget_main->Init(params_main); | 120 widget_main->Init(params_main); |
| 110 View* root_main = widget_main->GetRootView(); | 121 View* root_main = widget_main->GetRootView(); |
| 111 root_main->AddChildView(test_view_main); | 122 root_main->AddChildView(test_view_main); |
| 112 widget_main->Activate(); | 123 widget_main->Activate(); |
| 113 test_view_main->GetFocusManager()->SetFocusedView(test_view_main); | 124 test_view_main->GetFocusManager()->SetFocusedView(test_view_main); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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 // Esc should deactivate the widget. |
| 148 // Widget::Deactivate is not supported on Mac. |
| 149 #if !defined(OS_MACOSX) |
| 136 test_view_bar->AcceleratorPressed(test_view_bar->escape_key()); | 150 test_view_bar->AcceleratorPressed(test_view_bar->escape_key()); |
| 137 EXPECT_TRUE(widget_main->IsActive()); | 151 EXPECT_TRUE(widget_main->IsActive()); |
| 138 EXPECT_FALSE(widget_bar->IsActive()); | 152 EXPECT_FALSE(widget_bar->IsActive()); |
| 153 #endif |
| 139 | 154 |
| 140 widget_bar->CloseNow(); | 155 widget_bar->CloseNow(); |
| 141 widget_bar.reset(); | 156 widget_bar.reset(); |
| 142 | 157 |
| 143 widget_main->CloseNow(); | 158 widget_main->CloseNow(); |
| 144 widget_main.reset(); | 159 widget_main.reset(); |
| 145 } | 160 } |
| 146 | 161 |
| 147 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { | 162 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { |
| 148 TestBarView* test_view = new TestBarView(); | 163 TestBarView* test_view = new TestBarView(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 229 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 215 | 230 |
| 216 // ESC | 231 // ESC |
| 217 test_view->AcceleratorPressed(test_view->escape_key()); | 232 test_view->AcceleratorPressed(test_view->escape_key()); |
| 218 EXPECT_EQ(original_test_view->third_child_button(), | 233 EXPECT_EQ(original_test_view->third_child_button(), |
| 219 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 234 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 220 widget->CloseNow(); | 235 widget->CloseNow(); |
| 221 widget.reset(); | 236 widget.reset(); |
| 222 } | 237 } |
| 223 } // namespace views | 238 } // namespace views |
| OLD | NEW |