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

Side by Side Diff: ui/views/widget/widget_interactive_uitest.cc

Issue 1108733002: Add tests for input method focusing to Widget interactive ui tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add more test. Created 5 years, 7 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 | « no previous file | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_tree_host.h"
14 #include "ui/base/ime/input_method.h"
15 #include "ui/base/ime/text_input_client.h"
12 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/base/ui_base_paths.h" 17 #include "ui/base/ui_base_paths.h"
14 #include "ui/base/ui_base_switches.h" 18 #include "ui/base/ui_base_switches.h"
15 #include "ui/events/event_processor.h" 19 #include "ui/events/event_processor.h"
16 #include "ui/events/event_utils.h" 20 #include "ui/events/event_utils.h"
17 #include "ui/events/test/event_generator.h" 21 #include "ui/events/test/event_generator.h"
18 #include "ui/gfx/native_widget_types.h" 22 #include "ui/gfx/native_widget_types.h"
19 #include "ui/gl/gl_surface.h" 23 #include "ui/gl/gl_surface.h"
20 #include "ui/views/controls/textfield/textfield.h" 24 #include "ui/views/controls/textfield/textfield.h"
21 #include "ui/views/controls/textfield/textfield_test_api.h" 25 #include "ui/views/controls/textfield/textfield_test_api.h"
22 #include "ui/views/focus/focus_manager.h" 26 #include "ui/views/focus/focus_manager.h"
27 #include "ui/views/ime/input_method.h"
23 #include "ui/views/test/focus_manager_test.h" 28 #include "ui/views/test/focus_manager_test.h"
24 #include "ui/views/test/widget_test.h" 29 #include "ui/views/test/widget_test.h"
25 #include "ui/views/touchui/touch_selection_controller_impl.h" 30 #include "ui/views/touchui/touch_selection_controller_impl.h"
31 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
26 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
27 #include "ui/views/window/dialog_delegate.h" 33 #include "ui/views/window/dialog_delegate.h"
28 #include "ui/wm/public/activation_client.h" 34 #include "ui/wm/public/activation_client.h"
29 35
30 #if defined(OS_WIN) 36 #if defined(OS_WIN)
31 #include "ui/aura/window.h"
32 #include "ui/aura/window_tree_host.h"
33 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
34 #include "ui/views/win/hwnd_util.h" 37 #include "ui/views/win/hwnd_util.h"
38 #elif defined(USE_X11)
39 #include "ui/base/x/x11_util.h"
40 #include "ui/views/test/x11_property_change_waiter.h"
35 #endif 41 #endif
36 42
37 namespace views { 43 namespace views {
38 namespace test { 44 namespace test {
39 45
40 namespace { 46 namespace {
41 47
42 // A View that closes the Widget and exits the current message-loop when it 48 // A View that closes the Widget and exits the current message-loop when it
43 // receives a mouse-release event. 49 // receives a mouse-release event.
44 class ExitLoopOnRelease : public View { 50 class ExitLoopOnRelease : public View {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 run_loop_.Quit(); 174 run_loop_.Quit();
169 } 175 }
170 176
171 private: 177 private:
172 base::RunLoop run_loop_; 178 base::RunLoop run_loop_;
173 bool observed_; 179 bool observed_;
174 180
175 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter); 181 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter);
176 }; 182 };
177 183
184 #if defined(USE_X11)
185 class WidgetActivationWaiterX11 : public X11PropertyChangeWaiter {
186 public:
187 explicit WidgetActivationWaiterX11(Widget* widget, bool active)
188 : X11PropertyChangeWaiter(ui::GetX11RootWindow(), "_NET_ACTIVE_WINDOW"),
189 window_(widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()) {
190 EXPECT_NE(active, widget->IsActive());
191 }
192
193 ~WidgetActivationWaiterX11() override {}
194
195 private:
196 // X11PropertyChangeWaiter:
197 bool ShouldKeepOnWaiting(const ui::PlatformEvent& event) override {
198 XID xid = 0;
199 ui::GetXIDProperty(ui::GetX11RootWindow(), "_NET_ACTIVE_WINDOW", &xid);
200 return xid != window_;
201 }
202
203 XID window_;
204
205 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiterX11);
206 };
207 #endif
208
178 ui::WindowShowState GetWidgetShowState(const Widget* widget) { 209 ui::WindowShowState GetWidgetShowState(const Widget* widget) {
179 // Use IsMaximized/IsMinimized/IsFullScreen instead of GetWindowPlacement 210 // Use IsMaximized/IsMinimized/IsFullScreen instead of GetWindowPlacement
180 // because the former is implemented on all platforms but the latter is not. 211 // because the former is implemented on all platforms but the latter is not.
181 return widget->IsFullscreen() ? ui::SHOW_STATE_FULLSCREEN : 212 return widget->IsFullscreen() ? ui::SHOW_STATE_FULLSCREEN :
182 widget->IsMaximized() ? ui::SHOW_STATE_MAXIMIZED : 213 widget->IsMaximized() ? ui::SHOW_STATE_MAXIMIZED :
183 widget->IsMinimized() ? ui::SHOW_STATE_MINIMIZED : 214 widget->IsMinimized() ? ui::SHOW_STATE_MINIMIZED :
184 widget->IsActive() ? ui::SHOW_STATE_NORMAL : 215 widget->IsActive() ? ui::SHOW_STATE_NORMAL :
185 ui::SHOW_STATE_INACTIVE; 216 ui::SHOW_STATE_INACTIVE;
186 } 217 }
187 218
(...skipping 19 matching lines...) Expand all
207 } 238 }
208 239
209 // Like for ActivateSync(), wait for a widget to become active, but Show() the 240 // Like for ActivateSync(), wait for a widget to become active, but Show() the
210 // widget rather than calling Activate(). 241 // widget rather than calling Activate().
211 void ShowSync(Widget* widget) { 242 void ShowSync(Widget* widget) {
212 WidgetActivationWaiter waiter(widget, true); 243 WidgetActivationWaiter waiter(widget, true);
213 widget->Show(); 244 widget->Show();
214 waiter.Wait(); 245 waiter.Wait();
215 } 246 }
216 247
248 void ActivatePlatformWindowSync(Widget* widget) {
249 #if defined(OS_WIN)
250 ::SetActiveWindow(
251 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget());
252 #elif defined(OS_CHROMEOS)
253 widget->Activate();
254 #elif defined(USE_X11)
255 if (!widget->IsActive()) {
256 WidgetActivationWaiterX11 waiter(widget, true);
257 widget->Activate();
258 waiter.Wait();
259 }
260 #else
261 ActivateSync(widget);
262 #endif
263 }
264
217 // Calls ShowInactive() on a Widget, and spins a run loop. The goal is to give 265 // Calls ShowInactive() on a Widget, and spins a run loop. The goal is to give
218 // the OS a chance to activate a widget. However, for this case, the test 266 // the OS a chance to activate a widget. However, for this case, the test
219 // doesn't expect that to happen, so there is nothing to wait for. 267 // doesn't expect that to happen, so there is nothing to wait for.
220 void ShowInactiveSync(Widget* widget) { 268 void ShowInactiveSync(Widget* widget) {
221 widget->ShowInactive(); 269 widget->ShowInactive();
222 RunPendingMessagesForActiveStatusChange(); 270 RunPendingMessagesForActiveStatusChange();
223 } 271 }
224 272
225 } // namespace 273 } // namespace
226 274
(...skipping 21 matching lines...) Expand all
248 #if !defined(OS_MACOSX) 296 #if !defined(OS_MACOSX)
249 controller->ContextMenuTimerFired(); 297 controller->ContextMenuTimerFired();
250 #endif 298 #endif
251 } 299 }
252 } 300 }
253 301
254 static bool IsQuickMenuVisible(TouchSelectionControllerImpl* controller) { 302 static bool IsQuickMenuVisible(TouchSelectionControllerImpl* controller) {
255 DCHECK(controller); 303 DCHECK(controller);
256 return controller->context_menu_ && controller->context_menu_->visible(); 304 return controller->context_menu_ && controller->context_menu_->visible();
257 } 305 }
306
307 scoped_ptr<Widget> CreateWidget() {
308 scoped_ptr<Widget> widget(new Widget);
309 Widget::InitParams params =
310 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
311 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
312 params.bounds = gfx::Rect(0, 0, 200, 200);
313 #if defined(OS_CHROMEOS)
314 params.native_widget = NULL;
315 #else
316 params.native_widget = new DesktopNativeWidgetAura(widget.get());
317 #endif
318 widget->Init(params);
319 return widget.Pass();
320 }
258 }; 321 };
259 322
260 #if defined(OS_WIN) 323 #if defined(OS_WIN)
261 // Tests whether activation and focus change works correctly in Windows. 324 // Tests whether activation and focus change works correctly in Windows.
262 // We test the following:- 325 // We test the following:-
263 // 1. If the active aura window is correctly set when a top level widget is 326 // 1. If the active aura window is correctly set when a top level widget is
264 // created. 327 // created.
265 // 2. If the active aura window in widget 1 created above, is set to NULL when 328 // 2. If the active aura window in widget 1 created above, is set to NULL when
266 // another top level widget is created and focused. 329 // another top level widget is created and focused.
267 // 3. On focusing the native platform window for widget 1, the active aura 330 // 3. On focusing the native platform window for widget 1, the active aura
268 // window for widget 1 should be set and that for widget 2 should reset. 331 // window for widget 1 should be set and that for widget 2 should reset.
269 // TODO(ananta): Discuss with erg on how to write this test for linux x11 aura. 332 // TODO(ananta): Discuss with erg on how to write this test for linux x11 aura.
270 TEST_F(WidgetTestInteractive, DesktopNativeWidgetAuraActivationAndFocusTest) { 333 TEST_F(WidgetTestInteractive, DesktopNativeWidgetAuraActivationAndFocusTest) {
271 // Create widget 1 and expect the active window to be its window. 334 // Create widget 1 and expect the active window to be its window.
272 View* contents_view1 = new View; 335 View* contents_view1 = new View;
273 contents_view1->SetFocusable(true); 336 contents_view1->SetFocusable(true);
274 Widget widget1; 337 scoped_ptr<Widget> widget1(CreateWidget());
275 Widget::InitParams init_params = 338 widget1->SetContentsView(contents_view1);
276 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 339 widget1->Show();
277 init_params.bounds = gfx::Rect(0, 0, 200, 200); 340 aura::Window* root_window1= widget1->GetNativeView()->GetRootWindow();
278 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
279 init_params.native_widget = new DesktopNativeWidgetAura(&widget1);
280 widget1.Init(init_params);
281 widget1.SetContentsView(contents_view1);
282 widget1.Show();
283 aura::Window* root_window1= widget1.GetNativeView()->GetRootWindow();
284 contents_view1->RequestFocus(); 341 contents_view1->RequestFocus();
285 342
286 EXPECT_TRUE(root_window1 != NULL); 343 EXPECT_TRUE(root_window1 != NULL);
287 aura::client::ActivationClient* activation_client1 = 344 aura::client::ActivationClient* activation_client1 =
288 aura::client::GetActivationClient(root_window1); 345 aura::client::GetActivationClient(root_window1);
289 EXPECT_TRUE(activation_client1 != NULL); 346 EXPECT_TRUE(activation_client1 != NULL);
290 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); 347 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1->GetNativeView());
291 348
292 // Create widget 2 and expect the active window to be its window. 349 // Create widget 2 and expect the active window to be its window.
293 View* contents_view2 = new View; 350 View* contents_view2 = new View;
294 Widget widget2; 351 scoped_ptr<Widget> widget2(CreateWidget());
295 Widget::InitParams init_params2 = 352 widget2->SetContentsView(contents_view2);
296 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 353 widget2->Show();
297 init_params2.bounds = gfx::Rect(0, 0, 200, 200); 354 aura::Window* root_window2 = widget2->GetNativeView()->GetRootWindow();
298 init_params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
299 init_params2.native_widget = new DesktopNativeWidgetAura(&widget2);
300 widget2.Init(init_params2);
301 widget2.SetContentsView(contents_view2);
302 widget2.Show();
303 aura::Window* root_window2 = widget2.GetNativeView()->GetRootWindow();
304 contents_view2->RequestFocus(); 355 contents_view2->RequestFocus();
305 ::SetActiveWindow( 356 ::SetActiveWindow(
306 root_window2->GetHost()->GetAcceleratedWidget()); 357 root_window2->GetHost()->GetAcceleratedWidget());
sadrul 2015/04/28 05:12:57 Use the new ActivatePlatformWindowSync (here and e
Shu Chen 2015/04/28 06:46:29 Done.
307 358
308 aura::client::ActivationClient* activation_client2 = 359 aura::client::ActivationClient* activation_client2 =
309 aura::client::GetActivationClient(root_window2); 360 aura::client::GetActivationClient(root_window2);
310 EXPECT_TRUE(activation_client2 != NULL); 361 EXPECT_TRUE(activation_client2 != NULL);
311 EXPECT_EQ(activation_client2->GetActiveWindow(), widget2.GetNativeView()); 362 EXPECT_EQ(activation_client2->GetActiveWindow(), widget2->GetNativeView());
312 EXPECT_EQ(activation_client1->GetActiveWindow(), 363 EXPECT_EQ(activation_client1->GetActiveWindow(),
313 reinterpret_cast<aura::Window*>(NULL)); 364 reinterpret_cast<aura::Window*>(NULL));
314 365
315 // Now set focus back to widget 1 and expect the active window to be its 366 // Now set focus back to widget 1 and expect the active window to be its
316 // window. 367 // window.
317 contents_view1->RequestFocus(); 368 contents_view1->RequestFocus();
318 ::SetActiveWindow( 369 ::SetActiveWindow(
319 root_window1->GetHost()->GetAcceleratedWidget()); 370 root_window1->GetHost()->GetAcceleratedWidget());
320 EXPECT_EQ(activation_client2->GetActiveWindow(), 371 EXPECT_EQ(activation_client2->GetActiveWindow(),
321 reinterpret_cast<aura::Window*>(NULL)); 372 reinterpret_cast<aura::Window*>(NULL));
322 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); 373 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1->GetNativeView());
323 } 374 }
324 #endif // defined(OS_WIN) 375 #endif // defined(OS_WIN)
325 376
326 TEST_F(WidgetTestInteractive, CaptureAutoReset) { 377 TEST_F(WidgetTestInteractive, CaptureAutoReset) {
327 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); 378 Widget* toplevel = CreateTopLevelFramelessPlatformWidget();
328 View* container = new View; 379 View* container = new View;
329 toplevel->SetContentsView(container); 380 toplevel->SetContentsView(container);
330 381
331 EXPECT_FALSE(toplevel->HasCapture()); 382 EXPECT_FALSE(toplevel->HasCapture());
332 toplevel->SetCapture(NULL); 383 toplevel->SetCapture(NULL);
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 #endif 915 #endif
865 916
866 // Test that touch selection quick menu is not activated when opened. 917 // Test that touch selection quick menu is not activated when opened.
867 TEST_F(WidgetTestInteractive, MAYBE_TouchSelectionQuickMenuIsNotActivated) { 918 TEST_F(WidgetTestInteractive, MAYBE_TouchSelectionQuickMenuIsNotActivated) {
868 base::CommandLine::ForCurrentProcess()->AppendSwitch( 919 base::CommandLine::ForCurrentProcess()->AppendSwitch(
869 switches::kEnableTouchEditing); 920 switches::kEnableTouchEditing);
870 #if defined(OS_WIN) 921 #if defined(OS_WIN)
871 views_delegate().set_use_desktop_native_widgets(true); 922 views_delegate().set_use_desktop_native_widgets(true);
872 #endif // !defined(OS_WIN) 923 #endif // !defined(OS_WIN)
873 924
874 Widget widget; 925 scoped_ptr<Widget> widget(CreateWidget());
875 Widget::InitParams init_params =
876 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
877 init_params.bounds = gfx::Rect(0, 0, 200, 200);
878 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
879 widget.Init(init_params);
880 926
881 Textfield* textfield = new Textfield; 927 Textfield* textfield = new Textfield;
882 textfield->SetBounds(0, 0, 200, 20); 928 textfield->SetBounds(0, 0, 200, 20);
883 textfield->SetText(base::ASCIIToUTF16("some text")); 929 textfield->SetText(base::ASCIIToUTF16("some text"));
884 widget.GetRootView()->AddChildView(textfield); 930 widget->GetRootView()->AddChildView(textfield);
885 931
886 widget.Show(); 932 widget->Show();
887 textfield->RequestFocus(); 933 textfield->RequestFocus();
888 textfield->SelectAll(true); 934 textfield->SelectAll(true);
889 TextfieldTestApi textfield_test_api(textfield); 935 TextfieldTestApi textfield_test_api(textfield);
890 936
891 RunPendingMessages(); 937 RunPendingMessages();
892 938
893 ui::test::EventGenerator generator(widget.GetNativeWindow()); 939 ui::test::EventGenerator generator(widget->GetNativeWindow());
894 generator.GestureTapAt(gfx::Point(10, 10)); 940 generator.GestureTapAt(gfx::Point(10, 10));
895 ShowQuickMenuImmediately(static_cast<TouchSelectionControllerImpl*>( 941 ShowQuickMenuImmediately(static_cast<TouchSelectionControllerImpl*>(
896 textfield_test_api.touch_selection_controller())); 942 textfield_test_api.touch_selection_controller()));
897 943
898 EXPECT_TRUE(textfield->HasFocus()); 944 EXPECT_TRUE(textfield->HasFocus());
899 EXPECT_TRUE(widget.IsActive()); 945 EXPECT_TRUE(widget->IsActive());
900 EXPECT_TRUE(IsQuickMenuVisible(static_cast<TouchSelectionControllerImpl*>( 946 EXPECT_TRUE(IsQuickMenuVisible(static_cast<TouchSelectionControllerImpl*>(
901 textfield_test_api.touch_selection_controller()))); 947 textfield_test_api.touch_selection_controller())));
902 } 948 }
903 949
904 TEST_F(WidgetTestInteractive, DisableViewDoesNotActivateWidget) { 950 TEST_F(WidgetTestInteractive, DisableViewDoesNotActivateWidget) {
905 #if defined(OS_WIN) 951 #if defined(OS_WIN)
906 views_delegate().set_use_desktop_native_widgets(true); 952 views_delegate().set_use_desktop_native_widgets(true);
907 #endif // !defined(OS_WIN) 953 #endif // !defined(OS_WIN)
908 954
909 // Create first widget and view, activate the widget, and focus the view. 955 // Create first widget and view, activate the widget, and focus the view.
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), 1443 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(),
1398 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 1444 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
1399 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> 1445 ui::EventDispatchDetails details = widget1.GetNativeWindow()->
1400 GetHost()->event_processor()->OnEventFromSource(&mouse_event); 1446 GetHost()->event_processor()->OnEventFromSource(&mouse_event);
1401 ASSERT_FALSE(details.dispatcher_destroyed); 1447 ASSERT_FALSE(details.dispatcher_destroyed);
1402 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); 1448 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent());
1403 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); 1449 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent());
1404 } 1450 }
1405 #endif // defined(OS_WIN) 1451 #endif // defined(OS_WIN)
1406 1452
1453 TEST_F(WidgetTestInteractive, InputMethodFocus_activation) {
1454 scoped_ptr<Widget> widget(CreateWidget());
1455 scoped_ptr<Textfield> textfield(new Textfield);
1456 widget->GetRootView()->AddChildView(textfield.get());
1457 widget->Show();
1458 textfield->RequestFocus();
1459
1460 ActivatePlatformWindowSync(widget.get());
1461
1462 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
1463 widget->GetInputMethod()->GetTextInputType());
1464
1465 widget->Deactivate();
1466
1467 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
1468 widget->GetInputMethod()->GetTextInputType());
1469 }
1470
1471 TEST_F(WidgetTestInteractive, InputMethodFocus_1_window) {
1472 scoped_ptr<Widget> widget(CreateWidget());
1473 scoped_ptr<Textfield> textfield1(new Textfield);
1474 scoped_ptr<Textfield> textfield2(new Textfield);
1475 textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
1476 widget->GetRootView()->AddChildView(textfield1.get());
1477 widget->GetRootView()->AddChildView(textfield2.get());
1478 widget->Show();
1479
1480 ActivatePlatformWindowSync(widget.get());
1481
1482 textfield1->RequestFocus();
1483 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
1484 widget->GetInputMethod()->GetTextInputType());
1485
1486 textfield2->RequestFocus();
1487 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD,
1488 widget->GetInputMethod()->GetTextInputType());
1489 #if !defined(OS_CHROMEOS) // Window::Blur doesn't work for CrOS
sadrul 2015/04/28 05:12:57 Is there a bug for this? Do we know why Blur doesn
Shu Chen 2015/04/28 06:46:29 There is no bug. Please see my explanation in the
1490 aura::Window* window = widget->GetNativeWindow();
1491 window->Blur();
1492 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
1493 widget->GetInputMethod()->GetTextInputType());
1494
1495 window->Focus();
1496 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD,
1497 widget->GetInputMethod()->GetTextInputType());
1498
1499 window->Blur();
1500 textfield1->RequestFocus();
1501 window->Focus();
1502 EXPECT_TRUE(window->HasFocus());
1503 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
1504 widget->GetInputMethod()->GetTextInputType());
1505 #endif
1506 }
1507
1508 TEST_F(WidgetTestInteractive, InputMethodFocus_2_windows) {
1509 scoped_ptr<Widget> widget(CreateWidget());
1510 widget->Show();
1511
1512 views::View* parent_root = new View;
1513 scoped_ptr<Widget> parent(new Widget);
1514 Widget::InitParams parent_params(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
1515 parent_params.ownership =
1516 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1517 parent_params.context = widget->GetNativeWindow();
1518 parent->Init(parent_params);
1519 parent->SetContentsView(parent_root);
1520 parent->SetBounds(gfx::Rect(100, 100, 100, 100));
1521 parent->Show();
1522
1523 scoped_ptr<Widget> child(new Widget());
1524 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL);
1525 child_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1526 child_params.parent = parent->GetNativeWindow();
1527 child->Init(child_params);
1528 child->SetBounds(gfx::Rect(0, 0, 50, 50));
1529 child->Show();
1530
1531 scoped_ptr<Textfield> textfield_parent(new Textfield);
1532 scoped_ptr<Textfield> textfield_child(new Textfield);
1533 textfield_parent->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
1534 parent->GetRootView()->AddChildView(textfield_parent.get());
1535 child->GetRootView()->AddChildView(textfield_child.get());
1536
1537 EXPECT_EQ(parent->GetInputMethod(), child->GetInputMethod());
1538
1539 textfield_parent->RequestFocus();
1540 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD,
1541 parent->GetInputMethod()->GetTextInputType());
1542
1543 textfield_child->RequestFocus();
1544 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
1545 parent->GetInputMethod()->GetTextInputType());
1546
1547 #if !defined(OS_CHROMEOS) // Window::Blur doesn't work for CrOS
1548 child->GetNativeWindow()->Blur();
1549 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
1550 parent->GetInputMethod()->GetTextInputType());
1551
1552 child->GetNativeWindow()->Focus();
1553 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
1554 parent->GetInputMethod()->GetTextInputType());
1555
1556 textfield_parent->RequestFocus();
1557 parent->GetNativeWindow()->Blur();
1558 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
1559 parent->GetInputMethod()->GetTextInputType());
1560
1561 parent->GetNativeWindow()->Focus();
1562 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD,
1563 parent->GetInputMethod()->GetTextInputType());
1564 #endif
1565 }
1566
1567 TEST_F(WidgetTestInteractive, InputMethodFocus_2_top_windows) {
1568 scoped_ptr<Widget> widget1(CreateWidget());
1569 scoped_ptr<Widget> widget2(CreateWidget());
1570 scoped_ptr<Textfield> textfield1(new Textfield);
1571 scoped_ptr<Textfield> textfield2(new Textfield);
1572 textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
1573 widget1->GetRootView()->AddChildView(textfield1.get());
1574 widget2->GetRootView()->AddChildView(textfield2.get());
1575 widget1->Show();
1576 widget2->Show();
1577
1578 textfield1->RequestFocus();
1579 textfield2->RequestFocus();
1580
1581 ActivatePlatformWindowSync(widget1.get());
1582
1583 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
1584 widget1->GetInputMethod()->GetTextInputType());
1585 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
1586 widget2->GetInputMethod()->GetTextInputType());
1587
1588 ActivatePlatformWindowSync(widget2.get());
1589
1590 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
1591 widget1->GetInputMethod()->GetTextInputType());
1592 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD,
1593 widget2->GetInputMethod()->GetTextInputType());
1594 }
1595
1596 TEST_F(WidgetTestInteractive, InputMethodFocus_textfield) {
sadrul 2015/04/28 05:12:57 For each test, please add a comment explaining wha
Shu Chen 2015/04/28 06:46:29 Done.
1597 scoped_ptr<Widget> widget(CreateWidget());
1598 scoped_ptr<Textfield> textfield(new Textfield);
1599 widget->GetRootView()->AddChildView(textfield.get());
1600 widget->Show();
1601 ActivatePlatformWindowSync(widget.get());
1602 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
1603 widget->GetInputMethod()->GetTextInputType());
1604
1605 textfield->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
1606 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
1607 widget->GetInputMethod()->GetTextInputType());
1608
1609 textfield->RequestFocus();
1610 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD,
1611 widget->GetInputMethod()->GetTextInputType());
1612
1613 textfield->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT);
1614 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
1615 widget->GetInputMethod()->GetTextInputType());
1616
1617 textfield->SetReadOnly(true);
1618 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
1619 widget->GetInputMethod()->GetTextInputType());
1620 }
1621
1407 } // namespace test 1622 } // namespace test
1408 } // namespace views 1623 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698