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 "base/macros.h" | 7 #include "base/macros.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "ui/base/accelerators/accelerator.h" | 9 #include "ui/base/accelerators/accelerator.h" |
10 #include "ui/views/controls/button/label_button.h" | 10 #include "ui/views/controls/button/label_button.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 View* test_view_main = new View(); | 104 View* test_view_main = new View(); |
105 std::unique_ptr<Widget> widget_main(new Widget()); | 105 std::unique_ptr<Widget> widget_main(new Widget()); |
106 Widget::InitParams params_main = CreateParams(Widget::InitParams::TYPE_POPUP); | 106 Widget::InitParams params_main = CreateParams(Widget::InitParams::TYPE_POPUP); |
107 params_main.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 107 params_main.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
108 // By default, TYPE_POPUP is not activatable. | 108 // By default, TYPE_POPUP is not activatable. |
109 params_main.activatable = Widget::InitParams::ACTIVATABLE_YES; | 109 params_main.activatable = Widget::InitParams::ACTIVATABLE_YES; |
110 params_main.bounds = gfx::Rect(0, 0, 20, 20); | 110 params_main.bounds = gfx::Rect(0, 0, 20, 20); |
111 widget_main->Init(params_main); | 111 widget_main->Init(params_main); |
112 View* root_main = widget_main->GetRootView(); | 112 View* root_main = widget_main->GetRootView(); |
113 root_main->AddChildView(test_view_main); | 113 root_main->AddChildView(test_view_main); |
| 114 widget_main->Show(); |
114 widget_main->Activate(); | 115 widget_main->Activate(); |
115 test_view_main->GetFocusManager()->SetFocusedView(test_view_main); | 116 test_view_main->GetFocusManager()->SetFocusedView(test_view_main); |
116 EXPECT_TRUE(widget_main->IsActive()); | 117 EXPECT_TRUE(widget_main->IsActive()); |
117 EXPECT_TRUE(test_view_main->HasFocus()); | 118 EXPECT_TRUE(test_view_main->HasFocus()); |
118 | 119 |
119 TestBarView* test_view_bar = new TestBarView(); | 120 TestBarView* test_view_bar = new TestBarView(); |
120 std::unique_ptr<Widget> widget_bar(new Widget()); | 121 std::unique_ptr<Widget> widget_bar(new Widget()); |
121 Widget::InitParams params_bar = CreateParams(Widget::InitParams::TYPE_POPUP); | 122 Widget::InitParams params_bar = CreateParams(Widget::InitParams::TYPE_POPUP); |
122 params_bar.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 123 params_bar.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
123 params_bar.activatable = Widget::InitParams::ACTIVATABLE_YES; | 124 params_bar.activatable = Widget::InitParams::ACTIVATABLE_YES; |
124 params_bar.bounds = gfx::Rect(50, 50, 650, 650); | 125 params_bar.bounds = gfx::Rect(50, 50, 650, 650); |
125 widget_bar->Init(params_bar); | 126 widget_bar->Init(params_bar); |
126 View* root_bar = widget_bar->GetRootView(); | 127 View* root_bar = widget_bar->GetRootView(); |
127 root_bar->AddChildView(test_view_bar); | 128 root_bar->AddChildView(test_view_bar); |
128 widget_bar->Show(); | 129 widget_bar->Show(); |
129 widget_bar->Activate(); | 130 widget_bar->Activate(); |
130 | 131 |
131 // Set pane focus succeeds, focus on child. | 132 // Set pane focus succeeds, focus on child. |
132 EXPECT_TRUE(test_view_bar->SetPaneFocusAndFocusDefault()); | 133 EXPECT_TRUE(test_view_bar->SetPaneFocusAndFocusDefault()); |
133 EXPECT_FALSE(test_view_main->HasFocus()); | 134 EXPECT_FALSE(test_view_main->HasFocus()); |
134 EXPECT_FALSE(widget_main->IsActive()); | 135 EXPECT_FALSE(widget_main->IsActive()); |
135 EXPECT_EQ(test_view_bar, test_view_bar->GetPaneFocusTraversable()); | 136 EXPECT_EQ(test_view_bar, test_view_bar->GetPaneFocusTraversable()); |
136 EXPECT_EQ(test_view_bar->child_button(), | 137 EXPECT_EQ(test_view_bar->child_button(), |
137 test_view_bar->GetWidget()->GetFocusManager()->GetFocusedView()); | 138 test_view_bar->GetWidget()->GetFocusManager()->GetFocusedView()); |
138 | 139 |
139 // Deactivate() is only reliable on Ash. On Windows it uses ::GetNextWindow() | 140 if (!IsMus()) { |
140 // to simply activate another window, and which one is not predictable. On | 141 // Deactivate() is only reliable on Ash. On Windows it uses |
141 // Mac, Deactivate() is not implemented. Note that TestBarView calls | 142 // ::GetNextWindow() to simply activate another window, and which one is not |
142 // set_allow_deactivate_on_esc(true), which is only otherwise used in Ash. | 143 // predictable. On Mac, Deactivate() is not implemented. Note that |
| 144 // TestBarView calls set_allow_deactivate_on_esc(true), which is only |
| 145 // otherwise used in Ash. |
143 #if !defined(OS_MACOSX) || defined(USE_ASH) | 146 #if !defined(OS_MACOSX) || defined(USE_ASH) |
144 // Esc should deactivate the widget. | 147 // Esc should deactivate the widget. |
145 test_view_bar->AcceleratorPressed(test_view_bar->escape_key()); | 148 test_view_bar->AcceleratorPressed(test_view_bar->escape_key()); |
146 EXPECT_TRUE(widget_main->IsActive()); | 149 EXPECT_TRUE(widget_main->IsActive()); |
147 EXPECT_FALSE(widget_bar->IsActive()); | 150 EXPECT_FALSE(widget_bar->IsActive()); |
148 #endif | 151 #endif |
| 152 } |
149 | 153 |
150 widget_bar->CloseNow(); | 154 widget_bar->CloseNow(); |
151 widget_bar.reset(); | 155 widget_bar.reset(); |
152 | 156 |
153 widget_main->CloseNow(); | 157 widget_main->CloseNow(); |
154 widget_main.reset(); | 158 widget_main.reset(); |
155 } | 159 } |
156 | 160 |
157 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { | 161 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { |
158 TestBarView* test_view = new TestBarView(); | 162 TestBarView* test_view = new TestBarView(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 228 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
225 | 229 |
226 // ESC | 230 // ESC |
227 test_view->AcceleratorPressed(test_view->escape_key()); | 231 test_view->AcceleratorPressed(test_view->escape_key()); |
228 EXPECT_EQ(original_test_view->third_child_button(), | 232 EXPECT_EQ(original_test_view->third_child_button(), |
229 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 233 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
230 widget->CloseNow(); | 234 widget->CloseNow(); |
231 widget.reset(); | 235 widget.reset(); |
232 } | 236 } |
233 } // namespace views | 237 } // namespace views |
OLD | NEW |