Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: ui/views/accessible_pane_view_unittest.cc

Issue 1268293002: [MacViews] Fix AccessiblePaneViewTest.SetPaneFocusAndRestore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/ui_base.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // By default, TYPE_POPUP is not activatable.
118 params_main.activatable = Widget::InitParams::ACTIVATABLE_YES;
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);
114 EXPECT_TRUE(widget_main->IsActive()); 125 EXPECT_TRUE(widget_main->IsActive());
115 EXPECT_TRUE(test_view_main->HasFocus()); 126 EXPECT_TRUE(test_view_main->HasFocus());
116 127
117 TestBarView* test_view_bar = new TestBarView(); 128 TestBarView* test_view_bar = new TestBarView();
118 scoped_ptr<Widget> widget_bar(new Widget()); 129 scoped_ptr<Widget> widget_bar(new Widget());
119 Widget::InitParams params_bar = CreateParams(Widget::InitParams::TYPE_POPUP); 130 Widget::InitParams params_bar = CreateParams(Widget::InitParams::TYPE_POPUP);
120 params_bar.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 131 params_bar.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
132 params_bar.activatable = Widget::InitParams::ACTIVATABLE_YES;
121 params_bar.bounds = gfx::Rect(50, 50, 650, 650); 133 params_bar.bounds = gfx::Rect(50, 50, 650, 650);
122 widget_bar->Init(params_bar); 134 widget_bar->Init(params_bar);
123 View* root_bar = widget_bar->GetRootView(); 135 View* root_bar = widget_bar->GetRootView();
124 root_bar->AddChildView(test_view_bar); 136 root_bar->AddChildView(test_view_bar);
125 widget_bar->Show(); 137 widget_bar->Show();
126 widget_bar->Activate(); 138 widget_bar->Activate();
127 139
128 // Set pane focus succeeds, focus on child. 140 // Set pane focus succeeds, focus on child.
129 EXPECT_TRUE(test_view_bar->SetPaneFocusAndFocusDefault()); 141 EXPECT_TRUE(test_view_bar->SetPaneFocusAndFocusDefault());
130 EXPECT_FALSE(test_view_main->HasFocus()); 142 EXPECT_FALSE(test_view_main->HasFocus());
131 EXPECT_FALSE(widget_main->IsActive()); 143 EXPECT_FALSE(widget_main->IsActive());
132 EXPECT_EQ(test_view_bar, test_view_bar->GetPaneFocusTraversable()); 144 EXPECT_EQ(test_view_bar, test_view_bar->GetPaneFocusTraversable());
133 EXPECT_EQ(test_view_bar->child_button(), 145 EXPECT_EQ(test_view_bar->child_button(),
134 test_view_bar->GetWidget()->GetFocusManager()->GetFocusedView()); 146 test_view_bar->GetWidget()->GetFocusManager()->GetFocusedView());
135 147
148 // Deactivate() is only reliable on Ash. On Windows it uses ::GetNextWindow()
149 // to simply activate∆ another window, and which one is not predictable. On
tapted 2015/08/06 09:07:33 nit: a capital "delta" (∆) seems to have appeared
jackhou1 2015/08/06 23:40:17 Done.
150 // Mac, Deactivate() is not implemented. Note that TestBarView calls
151 // set_allow_deactivate_on_esc(true), which is only otherwise used in Ash.
152 #if !defined(OS_MACOSX) || defined(USE_ASH)
153 // Esc should deactivate the widget.
136 test_view_bar->AcceleratorPressed(test_view_bar->escape_key()); 154 test_view_bar->AcceleratorPressed(test_view_bar->escape_key());
137 EXPECT_TRUE(widget_main->IsActive()); 155 EXPECT_TRUE(widget_main->IsActive());
138 EXPECT_FALSE(widget_bar->IsActive()); 156 EXPECT_FALSE(widget_bar->IsActive());
157 #endif
139 158
140 widget_bar->CloseNow(); 159 widget_bar->CloseNow();
141 widget_bar.reset(); 160 widget_bar.reset();
142 161
143 widget_main->CloseNow(); 162 widget_main->CloseNow();
144 widget_main.reset(); 163 widget_main.reset();
145 } 164 }
146 165
147 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { 166 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) {
148 TestBarView* test_view = new TestBarView(); 167 TestBarView* test_view = new TestBarView();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); 233 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
215 234
216 // ESC 235 // ESC
217 test_view->AcceleratorPressed(test_view->escape_key()); 236 test_view->AcceleratorPressed(test_view->escape_key());
218 EXPECT_EQ(original_test_view->third_child_button(), 237 EXPECT_EQ(original_test_view->third_child_button(),
219 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); 238 test_view->GetWidget()->GetFocusManager()->GetFocusedView());
220 widget->CloseNow(); 239 widget->CloseNow();
221 widget.reset(); 240 widget.reset();
222 } 241 }
223 } // namespace views 242 } // namespace views
OLDNEW
« no previous file with comments | « ui/base/ui_base.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698