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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // 1. If the active aura window is correctly set when a top level widget is | 310 // 1. If the active aura window is correctly set when a top level widget is |
311 // created. | 311 // created. |
312 // 2. If the active aura window in widget 1 created above, is set to NULL when | 312 // 2. If the active aura window in widget 1 created above, is set to NULL when |
313 // another top level widget is created and focused. | 313 // another top level widget is created and focused. |
314 // 3. On focusing the native platform window for widget 1, the active aura | 314 // 3. On focusing the native platform window for widget 1, the active aura |
315 // window for widget 1 should be set and that for widget 2 should reset. | 315 // window for widget 1 should be set and that for widget 2 should reset. |
316 // TODO(ananta): Discuss with erg on how to write this test for linux x11 aura. | 316 // TODO(ananta): Discuss with erg on how to write this test for linux x11 aura. |
317 TEST_F(WidgetTestInteractive, DesktopNativeWidgetAuraActivationAndFocusTest) { | 317 TEST_F(WidgetTestInteractive, DesktopNativeWidgetAuraActivationAndFocusTest) { |
318 // Create widget 1 and expect the active window to be its window. | 318 // Create widget 1 and expect the active window to be its window. |
319 View* focusable_view1 = new View; | 319 View* focusable_view1 = new View; |
320 focusable_view1->SetFocusable(true); | 320 focusable_view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
321 Widget* widget1 = CreateWidget(); | 321 Widget* widget1 = CreateWidget(); |
322 widget1->GetContentsView()->AddChildView(focusable_view1); | 322 widget1->GetContentsView()->AddChildView(focusable_view1); |
323 widget1->Show(); | 323 widget1->Show(); |
324 aura::Window* root_window1 = widget1->GetNativeView()->GetRootWindow(); | 324 aura::Window* root_window1 = widget1->GetNativeView()->GetRootWindow(); |
325 focusable_view1->RequestFocus(); | 325 focusable_view1->RequestFocus(); |
326 | 326 |
327 EXPECT_TRUE(root_window1 != NULL); | 327 EXPECT_TRUE(root_window1 != NULL); |
328 aura::client::ActivationClient* activation_client1 = | 328 aura::client::ActivationClient* activation_client1 = |
329 aura::client::GetActivationClient(root_window1); | 329 aura::client::GetActivationClient(root_window1); |
330 EXPECT_TRUE(activation_client1 != NULL); | 330 EXPECT_TRUE(activation_client1 != NULL); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 | 632 |
633 RunPendingMessages(); | 633 RunPendingMessages(); |
634 | 634 |
635 toplevel->CloseNow(); | 635 toplevel->CloseNow(); |
636 } | 636 } |
637 | 637 |
638 // Test view focus restoration when a widget is deactivated and re-activated. | 638 // Test view focus restoration when a widget is deactivated and re-activated. |
639 TEST_F(WidgetTestInteractive, ViewFocusOnWidgetActivationChanges) { | 639 TEST_F(WidgetTestInteractive, ViewFocusOnWidgetActivationChanges) { |
640 Widget* widget1 = CreateTopLevelPlatformWidget(); | 640 Widget* widget1 = CreateTopLevelPlatformWidget(); |
641 View* view1 = new View; | 641 View* view1 = new View; |
642 view1->SetFocusable(true); | 642 view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
643 widget1->GetContentsView()->AddChildView(view1); | 643 widget1->GetContentsView()->AddChildView(view1); |
644 | 644 |
645 Widget* widget2 = CreateTopLevelPlatformWidget(); | 645 Widget* widget2 = CreateTopLevelPlatformWidget(); |
646 View* view2a = new View; | 646 View* view2a = new View; |
647 View* view2b = new View; | 647 View* view2b = new View; |
648 view2a->SetFocusable(true); | 648 view2a->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
649 view2b->SetFocusable(true); | 649 view2b->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
650 widget2->GetContentsView()->AddChildView(view2a); | 650 widget2->GetContentsView()->AddChildView(view2a); |
651 widget2->GetContentsView()->AddChildView(view2b); | 651 widget2->GetContentsView()->AddChildView(view2b); |
652 | 652 |
653 ShowSync(widget1); | 653 ShowSync(widget1); |
654 EXPECT_TRUE(widget1->IsActive()); | 654 EXPECT_TRUE(widget1->IsActive()); |
655 view1->RequestFocus(); | 655 view1->RequestFocus(); |
656 EXPECT_EQ(view1, widget1->GetFocusManager()->GetFocusedView()); | 656 EXPECT_EQ(view1, widget1->GetFocusManager()->GetFocusedView()); |
657 | 657 |
658 ShowSync(widget2); | 658 ShowSync(widget2); |
659 EXPECT_TRUE(widget2->IsActive()); | 659 EXPECT_TRUE(widget2->IsActive()); |
(...skipping 21 matching lines...) Expand all Loading... |
681 } | 681 } |
682 | 682 |
683 #if defined(OS_WIN) | 683 #if defined(OS_WIN) |
684 | 684 |
685 // Test view focus retention when a widget's HWND is disabled and re-enabled. | 685 // Test view focus retention when a widget's HWND is disabled and re-enabled. |
686 TEST_F(WidgetTestInteractive, ViewFocusOnHWNDEnabledChanges) { | 686 TEST_F(WidgetTestInteractive, ViewFocusOnHWNDEnabledChanges) { |
687 Widget* widget = CreateTopLevelFramelessPlatformWidget(); | 687 Widget* widget = CreateTopLevelFramelessPlatformWidget(); |
688 widget->SetContentsView(new View); | 688 widget->SetContentsView(new View); |
689 for (size_t i = 0; i < 2; ++i) { | 689 for (size_t i = 0; i < 2; ++i) { |
690 widget->GetContentsView()->AddChildView(new View); | 690 widget->GetContentsView()->AddChildView(new View); |
691 widget->GetContentsView()->child_at(i)->SetFocusable(true); | 691 widget->GetContentsView()->child_at(i)->SetFocusBehavior( |
| 692 views::View::FocusBehavior::ALWAYS); |
692 } | 693 } |
693 | 694 |
694 widget->Show(); | 695 widget->Show(); |
695 widget->GetNativeWindow()->GetHost()->Show(); | 696 widget->GetNativeWindow()->GetHost()->Show(); |
696 const HWND hwnd = HWNDForWidget(widget); | 697 const HWND hwnd = HWNDForWidget(widget); |
697 EXPECT_TRUE(::IsWindow(hwnd)); | 698 EXPECT_TRUE(::IsWindow(hwnd)); |
698 EXPECT_TRUE(::IsWindowEnabled(hwnd)); | 699 EXPECT_TRUE(::IsWindowEnabled(hwnd)); |
699 EXPECT_EQ(hwnd, ::GetActiveWindow()); | 700 EXPECT_EQ(hwnd, ::GetActiveWindow()); |
700 | 701 |
701 for (int i = 0; i < widget->GetContentsView()->child_count(); ++i) { | 702 for (int i = 0; i < widget->GetContentsView()->child_count(); ++i) { |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 #endif // !defined(OS_WIN) | 1081 #endif // !defined(OS_WIN) |
1081 | 1082 |
1082 // Create first widget and view, activate the widget, and focus the view. | 1083 // Create first widget and view, activate the widget, and focus the view. |
1083 Widget widget1; | 1084 Widget widget1; |
1084 Widget::InitParams params1 = CreateParams(Widget::InitParams::TYPE_POPUP); | 1085 Widget::InitParams params1 = CreateParams(Widget::InitParams::TYPE_POPUP); |
1085 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1086 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
1086 params1.activatable = Widget::InitParams::ACTIVATABLE_YES; | 1087 params1.activatable = Widget::InitParams::ACTIVATABLE_YES; |
1087 widget1.Init(params1); | 1088 widget1.Init(params1); |
1088 | 1089 |
1089 View* view1 = new View(); | 1090 View* view1 = new View(); |
1090 view1->SetFocusable(true); | 1091 view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
1091 widget1.GetRootView()->AddChildView(view1); | 1092 widget1.GetRootView()->AddChildView(view1); |
1092 | 1093 |
1093 ActivateSync(&widget1); | 1094 ActivateSync(&widget1); |
1094 | 1095 |
1095 FocusManager* focus_manager1 = widget1.GetFocusManager(); | 1096 FocusManager* focus_manager1 = widget1.GetFocusManager(); |
1096 ASSERT_TRUE(focus_manager1); | 1097 ASSERT_TRUE(focus_manager1); |
1097 focus_manager1->SetFocusedView(view1); | 1098 focus_manager1->SetFocusedView(view1); |
1098 EXPECT_EQ(view1, focus_manager1->GetFocusedView()); | 1099 EXPECT_EQ(view1, focus_manager1->GetFocusedView()); |
1099 | 1100 |
1100 // Create second widget and view, activate the widget, and focus the view. | 1101 // Create second widget and view, activate the widget, and focus the view. |
1101 Widget widget2; | 1102 Widget widget2; |
1102 Widget::InitParams params2 = CreateParams(Widget::InitParams::TYPE_POPUP); | 1103 Widget::InitParams params2 = CreateParams(Widget::InitParams::TYPE_POPUP); |
1103 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1104 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
1104 params2.activatable = Widget::InitParams::ACTIVATABLE_YES; | 1105 params2.activatable = Widget::InitParams::ACTIVATABLE_YES; |
1105 widget2.Init(params2); | 1106 widget2.Init(params2); |
1106 | 1107 |
1107 View* view2 = new View(); | 1108 View* view2 = new View(); |
1108 view2->SetFocusable(true); | 1109 view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
1109 widget2.GetRootView()->AddChildView(view2); | 1110 widget2.GetRootView()->AddChildView(view2); |
1110 | 1111 |
1111 ActivateSync(&widget2); | 1112 ActivateSync(&widget2); |
1112 EXPECT_TRUE(widget2.IsActive()); | 1113 EXPECT_TRUE(widget2.IsActive()); |
1113 EXPECT_FALSE(widget1.IsActive()); | 1114 EXPECT_FALSE(widget1.IsActive()); |
1114 | 1115 |
1115 FocusManager* focus_manager2 = widget2.GetFocusManager(); | 1116 FocusManager* focus_manager2 = widget2.GetFocusManager(); |
1116 ASSERT_TRUE(focus_manager2); | 1117 ASSERT_TRUE(focus_manager2); |
1117 focus_manager2->SetFocusedView(view2); | 1118 focus_manager2->SetFocusedView(view2); |
1118 EXPECT_EQ(view2, focus_manager2->GetFocusedView()); | 1119 EXPECT_EQ(view2, focus_manager2->GetFocusedView()); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 RunPendingMessages(); | 1260 RunPendingMessages(); |
1260 } | 1261 } |
1261 | 1262 |
1262 // Testing initial focus is assigned properly for normal top-level widgets, | 1263 // Testing initial focus is assigned properly for normal top-level widgets, |
1263 // and subclasses that specify a initially focused child view. | 1264 // and subclasses that specify a initially focused child view. |
1264 TEST_F(WidgetTestInteractive, InitialFocus) { | 1265 TEST_F(WidgetTestInteractive, InitialFocus) { |
1265 // By default, there is no initially focused view (even if there is a | 1266 // By default, there is no initially focused view (even if there is a |
1266 // focusable subview). | 1267 // focusable subview). |
1267 Widget* toplevel(CreateTopLevelPlatformWidget()); | 1268 Widget* toplevel(CreateTopLevelPlatformWidget()); |
1268 View* view = new View; | 1269 View* view = new View; |
1269 view->SetFocusable(true); | 1270 view->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
1270 toplevel->GetContentsView()->AddChildView(view); | 1271 toplevel->GetContentsView()->AddChildView(view); |
1271 | 1272 |
1272 ShowSync(toplevel); | 1273 ShowSync(toplevel); |
1273 toplevel->Show(); | 1274 toplevel->Show(); |
1274 EXPECT_FALSE(view->HasFocus()); | 1275 EXPECT_FALSE(view->HasFocus()); |
1275 EXPECT_FALSE(toplevel->GetFocusManager()->GetStoredFocusView()); | 1276 EXPECT_FALSE(toplevel->GetFocusManager()->GetStoredFocusView()); |
1276 toplevel->CloseNow(); | 1277 toplevel->CloseNow(); |
1277 | 1278 |
1278 // Testing a widget which specifies a initially focused view. | 1279 // Testing a widget which specifies a initially focused view. |
1279 TestInitialFocusWidgetDelegate delegate(GetContext()); | 1280 TestInitialFocusWidgetDelegate delegate(GetContext()); |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1794 | 1795 |
1795 ui::KeyEvent key_event2(key_event); | 1796 ui::KeyEvent key_event2(key_event); |
1796 widget->OnKeyEvent(&key_event2); | 1797 widget->OnKeyEvent(&key_event2); |
1797 EXPECT_FALSE(key_event2.stopped_propagation()); | 1798 EXPECT_FALSE(key_event2.stopped_propagation()); |
1798 | 1799 |
1799 widget->CloseNow(); | 1800 widget->CloseNow(); |
1800 } | 1801 } |
1801 | 1802 |
1802 } // namespace test | 1803 } // namespace test |
1803 } // namespace views | 1804 } // namespace views |
OLD | NEW |