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

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: Remove dependent patch. 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
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::ScopedFakeNSWindowKeyStatus fake_key;
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();
tapted 2015/08/05 07:07:17 I think this should fail since widget->CanActivate
jackhou1 2015/08/06 00:22:30 CanActivate() returns false on the other platforms
tapted 2015/08/06 01:21:17 I think this is a bug though. other platforms shou
jackhou1 2015/08/06 01:51:35 I meant that Activate seems to unconditionally act
tapted 2015/08/06 03:01:00 I think this is only true on ChromeOS (and possibl
jackhou1 2015/08/06 06:10:57 I think the test still works because it only creat
tapted 2015/08/06 06:49:12 Ah, so it is. Perhaps comment above the `= ACTIVAT
jackhou1 2015/08/06 07:35:02 Done.
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;
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 // Esc should deactivate the widget.
148 // Widget::Deactivate is not supported on Mac.
tapted 2015/08/06 03:01:00 I think it's more correct to say that Deactivation
jackhou1 2015/08/06 06:10:57 Done.
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
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
OLDNEW
« ui/base/test/scoped_fake_nswindow_focus.mm ('K') | « ui/base/ui_base.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698