Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 #if defined(USE_AURA) | |
| 249 void ActivatePlatformWindowSync(Widget* widget) { | |
|
tapted
2015/05/01 01:54:25
Hi There! I'd like to get these tests working on M
tapted
2015/05/01 09:10:17
Looks like ActivateSync() can do the job on Linux.
| |
| 250 #if defined(OS_WIN) | |
| 251 ::SetActiveWindow( | |
| 252 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); | |
| 253 #elif defined(OS_CHROMEOS) | |
| 254 widget->Activate(); | |
| 255 #elif defined(USE_X11) | |
| 256 if (!widget->IsActive()) { | |
| 257 WidgetActivationWaiterX11 waiter(widget, true); | |
| 258 widget->Activate(); | |
| 259 waiter.Wait(); | |
| 260 } | |
| 261 #else | |
| 262 ActivateSync(widget); | |
| 263 #endif | |
| 264 } | |
| 265 #endif | |
| 266 | |
| 217 // Calls ShowInactive() on a Widget, and spins a run loop. The goal is to give | 267 // 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 | 268 // 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. | 269 // doesn't expect that to happen, so there is nothing to wait for. |
| 220 void ShowInactiveSync(Widget* widget) { | 270 void ShowInactiveSync(Widget* widget) { |
| 221 widget->ShowInactive(); | 271 widget->ShowInactive(); |
| 222 RunPendingMessagesForActiveStatusChange(); | 272 RunPendingMessagesForActiveStatusChange(); |
| 223 } | 273 } |
| 224 | 274 |
| 225 } // namespace | 275 } // namespace |
| 226 | 276 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 248 #if !defined(OS_MACOSX) | 298 #if !defined(OS_MACOSX) |
| 249 controller->ContextMenuTimerFired(); | 299 controller->ContextMenuTimerFired(); |
| 250 #endif | 300 #endif |
| 251 } | 301 } |
| 252 } | 302 } |
| 253 | 303 |
| 254 static bool IsQuickMenuVisible(TouchSelectionControllerImpl* controller) { | 304 static bool IsQuickMenuVisible(TouchSelectionControllerImpl* controller) { |
| 255 DCHECK(controller); | 305 DCHECK(controller); |
| 256 return controller->context_menu_ && controller->context_menu_->visible(); | 306 return controller->context_menu_ && controller->context_menu_->visible(); |
| 257 } | 307 } |
| 308 | |
| 309 scoped_ptr<Widget> CreateWidget() { | |
| 310 #if !defined(USE_AURA) | |
| 311 return NULL; | |
| 312 #else | |
| 313 scoped_ptr<Widget> widget(new Widget); | |
| 314 Widget::InitParams params = | |
| 315 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 316 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 317 params.bounds = gfx::Rect(0, 0, 200, 200); | |
| 318 #if defined(OS_CHROMEOS) | |
| 319 params.native_widget = NULL; | |
| 320 #else | |
| 321 params.native_widget = new DesktopNativeWidgetAura(widget.get()); | |
| 322 #endif | |
| 323 widget->Init(params); | |
| 324 return widget.Pass(); | |
| 325 #endif | |
| 326 } | |
| 258 }; | 327 }; |
| 259 | 328 |
| 260 #if defined(OS_WIN) | 329 #if defined(OS_WIN) |
| 261 // Tests whether activation and focus change works correctly in Windows. | 330 // Tests whether activation and focus change works correctly in Windows. |
| 262 // We test the following:- | 331 // We test the following:- |
| 263 // 1. If the active aura window is correctly set when a top level widget is | 332 // 1. If the active aura window is correctly set when a top level widget is |
| 264 // created. | 333 // created. |
| 265 // 2. If the active aura window in widget 1 created above, is set to NULL when | 334 // 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. | 335 // another top level widget is created and focused. |
| 267 // 3. On focusing the native platform window for widget 1, the active aura | 336 // 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. | 337 // 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. | 338 // TODO(ananta): Discuss with erg on how to write this test for linux x11 aura. |
| 270 TEST_F(WidgetTestInteractive, DesktopNativeWidgetAuraActivationAndFocusTest) { | 339 TEST_F(WidgetTestInteractive, DesktopNativeWidgetAuraActivationAndFocusTest) { |
| 271 // Create widget 1 and expect the active window to be its window. | 340 // Create widget 1 and expect the active window to be its window. |
| 272 View* contents_view1 = new View; | 341 View* contents_view1 = new View; |
| 273 contents_view1->SetFocusable(true); | 342 contents_view1->SetFocusable(true); |
| 274 Widget widget1; | 343 scoped_ptr<Widget> widget1(CreateWidget()); |
| 275 Widget::InitParams init_params = | 344 widget1->SetContentsView(contents_view1); |
| 276 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 345 widget1->Show(); |
| 277 init_params.bounds = gfx::Rect(0, 0, 200, 200); | 346 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(); | 347 contents_view1->RequestFocus(); |
| 285 | 348 |
| 286 EXPECT_TRUE(root_window1 != NULL); | 349 EXPECT_TRUE(root_window1 != NULL); |
| 287 aura::client::ActivationClient* activation_client1 = | 350 aura::client::ActivationClient* activation_client1 = |
| 288 aura::client::GetActivationClient(root_window1); | 351 aura::client::GetActivationClient(root_window1); |
| 289 EXPECT_TRUE(activation_client1 != NULL); | 352 EXPECT_TRUE(activation_client1 != NULL); |
| 290 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); | 353 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1->GetNativeView()); |
| 291 | 354 |
| 292 // Create widget 2 and expect the active window to be its window. | 355 // Create widget 2 and expect the active window to be its window. |
| 293 View* contents_view2 = new View; | 356 View* contents_view2 = new View; |
| 294 Widget widget2; | 357 scoped_ptr<Widget> widget2(CreateWidget()); |
| 295 Widget::InitParams init_params2 = | 358 widget2->SetContentsView(contents_view2); |
| 296 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 359 widget2->Show(); |
| 297 init_params2.bounds = gfx::Rect(0, 0, 200, 200); | 360 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(); | 361 contents_view2->RequestFocus(); |
| 305 ::SetActiveWindow( | 362 ActivatePlatformWindowSync(widget2.get()); |
| 306 root_window2->GetHost()->GetAcceleratedWidget()); | |
| 307 | 363 |
| 308 aura::client::ActivationClient* activation_client2 = | 364 aura::client::ActivationClient* activation_client2 = |
| 309 aura::client::GetActivationClient(root_window2); | 365 aura::client::GetActivationClient(root_window2); |
| 310 EXPECT_TRUE(activation_client2 != NULL); | 366 EXPECT_TRUE(activation_client2 != NULL); |
| 311 EXPECT_EQ(activation_client2->GetActiveWindow(), widget2.GetNativeView()); | 367 EXPECT_EQ(activation_client2->GetActiveWindow(), widget2->GetNativeView()); |
| 312 EXPECT_EQ(activation_client1->GetActiveWindow(), | 368 EXPECT_EQ(activation_client1->GetActiveWindow(), |
| 313 reinterpret_cast<aura::Window*>(NULL)); | 369 reinterpret_cast<aura::Window*>(NULL)); |
| 314 | 370 |
| 315 // Now set focus back to widget 1 and expect the active window to be its | 371 // Now set focus back to widget 1 and expect the active window to be its |
| 316 // window. | 372 // window. |
| 317 contents_view1->RequestFocus(); | 373 contents_view1->RequestFocus(); |
| 318 ::SetActiveWindow( | 374 ActivatePlatformWindowSync(widget1.get()); |
| 319 root_window1->GetHost()->GetAcceleratedWidget()); | |
| 320 EXPECT_EQ(activation_client2->GetActiveWindow(), | 375 EXPECT_EQ(activation_client2->GetActiveWindow(), |
| 321 reinterpret_cast<aura::Window*>(NULL)); | 376 reinterpret_cast<aura::Window*>(NULL)); |
| 322 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); | 377 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1->GetNativeView()); |
| 323 } | 378 } |
| 324 #endif // defined(OS_WIN) | 379 #endif // defined(OS_WIN) |
| 325 | 380 |
| 326 TEST_F(WidgetTestInteractive, CaptureAutoReset) { | 381 TEST_F(WidgetTestInteractive, CaptureAutoReset) { |
| 327 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); | 382 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); |
| 328 View* container = new View; | 383 View* container = new View; |
| 329 toplevel->SetContentsView(container); | 384 toplevel->SetContentsView(container); |
| 330 | 385 |
| 331 EXPECT_FALSE(toplevel->HasCapture()); | 386 EXPECT_FALSE(toplevel->HasCapture()); |
| 332 toplevel->SetCapture(NULL); | 387 toplevel->SetCapture(NULL); |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 #endif | 919 #endif |
| 865 | 920 |
| 866 // Test that touch selection quick menu is not activated when opened. | 921 // Test that touch selection quick menu is not activated when opened. |
| 867 TEST_F(WidgetTestInteractive, MAYBE_TouchSelectionQuickMenuIsNotActivated) { | 922 TEST_F(WidgetTestInteractive, MAYBE_TouchSelectionQuickMenuIsNotActivated) { |
| 868 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 923 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 869 switches::kEnableTouchEditing); | 924 switches::kEnableTouchEditing); |
| 870 #if defined(OS_WIN) | 925 #if defined(OS_WIN) |
| 871 views_delegate().set_use_desktop_native_widgets(true); | 926 views_delegate().set_use_desktop_native_widgets(true); |
| 872 #endif // !defined(OS_WIN) | 927 #endif // !defined(OS_WIN) |
| 873 | 928 |
| 874 Widget widget; | 929 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 | 930 |
| 881 Textfield* textfield = new Textfield; | 931 Textfield* textfield = new Textfield; |
| 882 textfield->SetBounds(0, 0, 200, 20); | 932 textfield->SetBounds(0, 0, 200, 20); |
| 883 textfield->SetText(base::ASCIIToUTF16("some text")); | 933 textfield->SetText(base::ASCIIToUTF16("some text")); |
| 884 widget.GetRootView()->AddChildView(textfield); | 934 widget->GetRootView()->AddChildView(textfield); |
| 885 | 935 |
| 886 widget.Show(); | 936 widget->Show(); |
| 887 textfield->RequestFocus(); | 937 textfield->RequestFocus(); |
| 888 textfield->SelectAll(true); | 938 textfield->SelectAll(true); |
| 889 TextfieldTestApi textfield_test_api(textfield); | 939 TextfieldTestApi textfield_test_api(textfield); |
| 890 | 940 |
| 891 RunPendingMessages(); | 941 RunPendingMessages(); |
| 892 | 942 |
| 893 ui::test::EventGenerator generator(widget.GetNativeWindow()); | 943 ui::test::EventGenerator generator(widget->GetNativeWindow()); |
| 894 generator.GestureTapAt(gfx::Point(10, 10)); | 944 generator.GestureTapAt(gfx::Point(10, 10)); |
| 895 ShowQuickMenuImmediately(static_cast<TouchSelectionControllerImpl*>( | 945 ShowQuickMenuImmediately(static_cast<TouchSelectionControllerImpl*>( |
| 896 textfield_test_api.touch_selection_controller())); | 946 textfield_test_api.touch_selection_controller())); |
| 897 | 947 |
| 898 EXPECT_TRUE(textfield->HasFocus()); | 948 EXPECT_TRUE(textfield->HasFocus()); |
| 899 EXPECT_TRUE(widget.IsActive()); | 949 EXPECT_TRUE(widget->IsActive()); |
| 900 EXPECT_TRUE(IsQuickMenuVisible(static_cast<TouchSelectionControllerImpl*>( | 950 EXPECT_TRUE(IsQuickMenuVisible(static_cast<TouchSelectionControllerImpl*>( |
| 901 textfield_test_api.touch_selection_controller()))); | 951 textfield_test_api.touch_selection_controller()))); |
| 902 } | 952 } |
| 903 | 953 |
| 904 TEST_F(WidgetTestInteractive, DisableViewDoesNotActivateWidget) { | 954 TEST_F(WidgetTestInteractive, DisableViewDoesNotActivateWidget) { |
| 905 #if defined(OS_WIN) | 955 #if defined(OS_WIN) |
| 906 views_delegate().set_use_desktop_native_widgets(true); | 956 views_delegate().set_use_desktop_native_widgets(true); |
| 907 #endif // !defined(OS_WIN) | 957 #endif // !defined(OS_WIN) |
| 908 | 958 |
| 909 // Create first widget and view, activate the widget, and focus the view. | 959 // Create first widget and view, activate the widget, and focus the view. |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1397 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), | 1447 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), |
| 1398 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 1448 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 1399 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1449 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
| 1400 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1450 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
| 1401 ASSERT_FALSE(details.dispatcher_destroyed); | 1451 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1402 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1452 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
| 1403 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1453 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
| 1404 } | 1454 } |
| 1405 #endif // defined(OS_WIN) | 1455 #endif // defined(OS_WIN) |
| 1406 | 1456 |
| 1457 #if defined(USE_AURA) | |
| 1458 // Test input method focus changes affected by top window activaction. | |
| 1459 TEST_F(WidgetTestInteractive, InputMethodFocus_activation) { | |
| 1460 scoped_ptr<Widget> widget(CreateWidget()); | |
| 1461 scoped_ptr<Textfield> textfield(new Textfield); | |
| 1462 widget->GetRootView()->AddChildView(textfield.get()); | |
| 1463 widget->Show(); | |
| 1464 textfield->RequestFocus(); | |
| 1465 | |
| 1466 ActivatePlatformWindowSync(widget.get()); | |
| 1467 | |
| 1468 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, | |
| 1469 widget->GetInputMethod()->GetTextInputType()); | |
| 1470 | |
| 1471 widget->Deactivate(); | |
| 1472 | |
| 1473 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
| 1474 widget->GetInputMethod()->GetTextInputType()); | |
| 1475 } | |
| 1476 | |
| 1477 // Test input method focus changes affected by focus changes within 1 window. | |
| 1478 TEST_F(WidgetTestInteractive, InputMethodFocus_1_window) { | |
| 1479 scoped_ptr<Widget> widget(CreateWidget()); | |
| 1480 scoped_ptr<Textfield> textfield1(new Textfield); | |
| 1481 scoped_ptr<Textfield> textfield2(new Textfield); | |
| 1482 textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
| 1483 widget->GetRootView()->AddChildView(textfield1.get()); | |
| 1484 widget->GetRootView()->AddChildView(textfield2.get()); | |
| 1485 widget->Show(); | |
| 1486 | |
| 1487 ActivatePlatformWindowSync(widget.get()); | |
| 1488 | |
| 1489 textfield1->RequestFocus(); | |
| 1490 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, | |
| 1491 widget->GetInputMethod()->GetTextInputType()); | |
| 1492 | |
| 1493 textfield2->RequestFocus(); | |
| 1494 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, | |
| 1495 widget->GetInputMethod()->GetTextInputType()); | |
| 1496 | |
| 1497 // Window::Blur doesn't work for CrOS, because it uses NWA instead of DNWA and | |
| 1498 // involves the AuraTestHelper which setup the input method as DummyInputMethod. | |
| 1499 // Please refer to CreateWidget method above. | |
| 1500 #if !defined(OS_CHROMEOS) | |
| 1501 aura::Window* window = widget->GetNativeWindow(); | |
| 1502 window->Blur(); | |
| 1503 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
| 1504 widget->GetInputMethod()->GetTextInputType()); | |
| 1505 | |
| 1506 window->Focus(); | |
| 1507 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, | |
| 1508 widget->GetInputMethod()->GetTextInputType()); | |
| 1509 | |
| 1510 window->Blur(); | |
| 1511 textfield1->RequestFocus(); | |
| 1512 window->Focus(); | |
| 1513 EXPECT_TRUE(window->HasFocus()); | |
| 1514 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, | |
| 1515 widget->GetInputMethod()->GetTextInputType()); | |
| 1516 #endif | |
| 1517 } | |
| 1518 | |
| 1519 // Test input method focus changes affected by focus changes cross 2 windows | |
| 1520 // which shares the same top window. | |
| 1521 TEST_F(WidgetTestInteractive, InputMethodFocus_2_windows) { | |
| 1522 scoped_ptr<Widget> widget(CreateWidget()); | |
| 1523 widget->Show(); | |
| 1524 | |
| 1525 views::View* parent_root = new View; | |
| 1526 scoped_ptr<Widget> parent(new Widget); | |
| 1527 Widget::InitParams parent_params(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 1528 parent_params.ownership = | |
| 1529 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 1530 parent_params.context = widget->GetNativeWindow(); | |
| 1531 parent->Init(parent_params); | |
| 1532 parent->SetContentsView(parent_root); | |
| 1533 parent->SetBounds(gfx::Rect(100, 100, 100, 100)); | |
| 1534 parent->Show(); | |
| 1535 | |
| 1536 scoped_ptr<Widget> child(new Widget()); | |
| 1537 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); | |
| 1538 child_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 1539 child_params.parent = parent->GetNativeWindow(); | |
| 1540 child->Init(child_params); | |
| 1541 child->SetBounds(gfx::Rect(0, 0, 50, 50)); | |
| 1542 child->Show(); | |
| 1543 | |
| 1544 scoped_ptr<Textfield> textfield_parent(new Textfield); | |
| 1545 scoped_ptr<Textfield> textfield_child(new Textfield); | |
| 1546 textfield_parent->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
| 1547 parent->GetRootView()->AddChildView(textfield_parent.get()); | |
| 1548 child->GetRootView()->AddChildView(textfield_child.get()); | |
| 1549 | |
| 1550 EXPECT_EQ(parent->GetInputMethod(), child->GetInputMethod()); | |
| 1551 | |
| 1552 textfield_parent->RequestFocus(); | |
| 1553 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, | |
| 1554 parent->GetInputMethod()->GetTextInputType()); | |
| 1555 | |
| 1556 textfield_child->RequestFocus(); | |
| 1557 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, | |
| 1558 parent->GetInputMethod()->GetTextInputType()); | |
| 1559 | |
| 1560 // Window::Blur doesn't work for CrOS, because it uses NWA instead of DNWA and | |
| 1561 // involves the AuraTestHelper which setup the input method as DummyInputMethod. | |
| 1562 // Please refer to CreateWidget method above. | |
| 1563 #if !defined(OS_CHROMEOS) | |
| 1564 child->GetNativeWindow()->Blur(); | |
| 1565 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
| 1566 parent->GetInputMethod()->GetTextInputType()); | |
| 1567 | |
| 1568 child->GetNativeWindow()->Focus(); | |
| 1569 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, | |
| 1570 parent->GetInputMethod()->GetTextInputType()); | |
| 1571 | |
| 1572 textfield_parent->RequestFocus(); | |
| 1573 parent->GetNativeWindow()->Blur(); | |
| 1574 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
| 1575 parent->GetInputMethod()->GetTextInputType()); | |
| 1576 | |
| 1577 parent->GetNativeWindow()->Focus(); | |
| 1578 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, | |
| 1579 parent->GetInputMethod()->GetTextInputType()); | |
| 1580 #endif | |
| 1581 } | |
| 1582 | |
| 1583 // Test input method focus changes affected by focus changes cross 2 top | |
| 1584 // windows. | |
| 1585 TEST_F(WidgetTestInteractive, InputMethodFocus_2_top_windows) { | |
| 1586 scoped_ptr<Widget> widget1(CreateWidget()); | |
| 1587 scoped_ptr<Widget> widget2(CreateWidget()); | |
| 1588 scoped_ptr<Textfield> textfield1(new Textfield); | |
| 1589 scoped_ptr<Textfield> textfield2(new Textfield); | |
| 1590 textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
| 1591 widget1->GetRootView()->AddChildView(textfield1.get()); | |
| 1592 widget2->GetRootView()->AddChildView(textfield2.get()); | |
| 1593 widget1->Show(); | |
| 1594 widget2->Show(); | |
| 1595 | |
| 1596 textfield1->RequestFocus(); | |
| 1597 textfield2->RequestFocus(); | |
| 1598 | |
| 1599 ActivatePlatformWindowSync(widget1.get()); | |
| 1600 | |
| 1601 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, | |
| 1602 widget1->GetInputMethod()->GetTextInputType()); | |
| 1603 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
| 1604 widget2->GetInputMethod()->GetTextInputType()); | |
| 1605 | |
| 1606 ActivatePlatformWindowSync(widget2.get()); | |
| 1607 | |
| 1608 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
| 1609 widget1->GetInputMethod()->GetTextInputType()); | |
| 1610 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, | |
| 1611 widget2->GetInputMethod()->GetTextInputType()); | |
| 1612 } | |
| 1613 | |
| 1614 // Test input method focus changes affected by textfield's state changes. | |
| 1615 TEST_F(WidgetTestInteractive, InputMethodFocus_textfield) { | |
| 1616 scoped_ptr<Widget> widget(CreateWidget()); | |
| 1617 scoped_ptr<Textfield> textfield(new Textfield); | |
| 1618 widget->GetRootView()->AddChildView(textfield.get()); | |
| 1619 widget->Show(); | |
| 1620 ActivatePlatformWindowSync(widget.get()); | |
| 1621 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
| 1622 widget->GetInputMethod()->GetTextInputType()); | |
| 1623 | |
| 1624 textfield->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
| 1625 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
| 1626 widget->GetInputMethod()->GetTextInputType()); | |
| 1627 | |
| 1628 textfield->RequestFocus(); | |
| 1629 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, | |
| 1630 widget->GetInputMethod()->GetTextInputType()); | |
| 1631 | |
| 1632 textfield->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); | |
| 1633 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, | |
| 1634 widget->GetInputMethod()->GetTextInputType()); | |
| 1635 | |
| 1636 textfield->SetReadOnly(true); | |
| 1637 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
| 1638 widget->GetInputMethod()->GetTextInputType()); | |
| 1639 } | |
| 1640 #endif // defined(USE_AURA) | |
| 1641 | |
| 1407 } // namespace test | 1642 } // namespace test |
| 1408 } // namespace views | 1643 } // namespace views |
| OLD | NEW |