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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 // 1. If the active aura window is correctly set when a top level widget is | 311 // 1. If the active aura window is correctly set when a top level widget is |
312 // created. | 312 // created. |
313 // 2. If the active aura window in widget 1 created above, is set to NULL when | 313 // 2. If the active aura window in widget 1 created above, is set to NULL when |
314 // another top level widget is created and focused. | 314 // another top level widget is created and focused. |
315 // 3. On focusing the native platform window for widget 1, the active aura | 315 // 3. On focusing the native platform window for widget 1, the active aura |
316 // window for widget 1 should be set and that for widget 2 should reset. | 316 // window for widget 1 should be set and that for widget 2 should reset. |
317 // TODO(ananta): Discuss with erg on how to write this test for linux x11 aura. | 317 // TODO(ananta): Discuss with erg on how to write this test for linux x11 aura. |
318 TEST_F(WidgetTestInteractive, DesktopNativeWidgetAuraActivationAndFocusTest) { | 318 TEST_F(WidgetTestInteractive, DesktopNativeWidgetAuraActivationAndFocusTest) { |
319 // Create widget 1 and expect the active window to be its window. | 319 // Create widget 1 and expect the active window to be its window. |
320 View* focusable_view1 = new View; | 320 View* focusable_view1 = new View; |
321 focusable_view1->SetFocusable(true); | 321 focusable_view1->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
322 Widget* widget1 = CreateWidget(); | 322 Widget* widget1 = CreateWidget(); |
323 widget1->GetContentsView()->AddChildView(focusable_view1); | 323 widget1->GetContentsView()->AddChildView(focusable_view1); |
324 widget1->Show(); | 324 widget1->Show(); |
325 aura::Window* root_window1 = widget1->GetNativeView()->GetRootWindow(); | 325 aura::Window* root_window1 = widget1->GetNativeView()->GetRootWindow(); |
326 focusable_view1->RequestFocus(); | 326 focusable_view1->RequestFocus(); |
327 | 327 |
328 EXPECT_TRUE(root_window1 != NULL); | 328 EXPECT_TRUE(root_window1 != NULL); |
329 aura::client::ActivationClient* activation_client1 = | 329 aura::client::ActivationClient* activation_client1 = |
330 aura::client::GetActivationClient(root_window1); | 330 aura::client::GetActivationClient(root_window1); |
331 EXPECT_TRUE(activation_client1 != NULL); | 331 EXPECT_TRUE(activation_client1 != NULL); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 | 595 |
596 RunPendingMessages(); | 596 RunPendingMessages(); |
597 | 597 |
598 toplevel->CloseNow(); | 598 toplevel->CloseNow(); |
599 } | 599 } |
600 | 600 |
601 // Test view focus restoration when a widget is deactivated and re-activated. | 601 // Test view focus restoration when a widget is deactivated and re-activated. |
602 TEST_F(WidgetTestInteractive, ViewFocusOnWidgetActivationChanges) { | 602 TEST_F(WidgetTestInteractive, ViewFocusOnWidgetActivationChanges) { |
603 Widget* widget1 = CreateTopLevelPlatformWidget(); | 603 Widget* widget1 = CreateTopLevelPlatformWidget(); |
604 View* view1 = new View; | 604 View* view1 = new View; |
605 view1->SetFocusable(true); | 605 view1->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
606 widget1->GetContentsView()->AddChildView(view1); | 606 widget1->GetContentsView()->AddChildView(view1); |
607 | 607 |
608 Widget* widget2 = CreateTopLevelPlatformWidget(); | 608 Widget* widget2 = CreateTopLevelPlatformWidget(); |
609 View* view2a = new View; | 609 View* view2a = new View; |
610 View* view2b = new View; | 610 View* view2b = new View; |
611 view2a->SetFocusable(true); | 611 view2a->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
612 view2b->SetFocusable(true); | 612 view2b->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
613 widget2->GetContentsView()->AddChildView(view2a); | 613 widget2->GetContentsView()->AddChildView(view2a); |
614 widget2->GetContentsView()->AddChildView(view2b); | 614 widget2->GetContentsView()->AddChildView(view2b); |
615 | 615 |
616 ShowSync(widget1); | 616 ShowSync(widget1); |
617 EXPECT_TRUE(widget1->IsActive()); | 617 EXPECT_TRUE(widget1->IsActive()); |
618 view1->RequestFocus(); | 618 view1->RequestFocus(); |
619 EXPECT_EQ(view1, widget1->GetFocusManager()->GetFocusedView()); | 619 EXPECT_EQ(view1, widget1->GetFocusManager()->GetFocusedView()); |
620 | 620 |
621 ShowSync(widget2); | 621 ShowSync(widget2); |
622 EXPECT_TRUE(widget2->IsActive()); | 622 EXPECT_TRUE(widget2->IsActive()); |
(...skipping 21 matching lines...) Expand all Loading... |
644 } | 644 } |
645 | 645 |
646 #if defined(OS_WIN) | 646 #if defined(OS_WIN) |
647 | 647 |
648 // Test view focus retention when a widget's HWND is disabled and re-enabled. | 648 // Test view focus retention when a widget's HWND is disabled and re-enabled. |
649 TEST_F(WidgetTestInteractive, ViewFocusOnHWNDEnabledChanges) { | 649 TEST_F(WidgetTestInteractive, ViewFocusOnHWNDEnabledChanges) { |
650 Widget* widget = CreateTopLevelFramelessPlatformWidget(); | 650 Widget* widget = CreateTopLevelFramelessPlatformWidget(); |
651 widget->SetContentsView(new View); | 651 widget->SetContentsView(new View); |
652 for (size_t i = 0; i < 2; ++i) { | 652 for (size_t i = 0; i < 2; ++i) { |
653 widget->GetContentsView()->AddChildView(new View); | 653 widget->GetContentsView()->AddChildView(new View); |
654 widget->GetContentsView()->child_at(i)->SetFocusable(true); | 654 widget->GetContentsView()->child_at(i)->SetFocusBehavior( |
| 655 View::FocusBehavior::ALWAYS); |
655 } | 656 } |
656 | 657 |
657 widget->Show(); | 658 widget->Show(); |
658 widget->GetNativeWindow()->GetHost()->Show(); | 659 widget->GetNativeWindow()->GetHost()->Show(); |
659 const HWND hwnd = HWNDForWidget(widget); | 660 const HWND hwnd = HWNDForWidget(widget); |
660 EXPECT_TRUE(::IsWindow(hwnd)); | 661 EXPECT_TRUE(::IsWindow(hwnd)); |
661 EXPECT_TRUE(::IsWindowEnabled(hwnd)); | 662 EXPECT_TRUE(::IsWindowEnabled(hwnd)); |
662 EXPECT_EQ(hwnd, ::GetActiveWindow()); | 663 EXPECT_EQ(hwnd, ::GetActiveWindow()); |
663 | 664 |
664 for (int i = 0; i < widget->GetContentsView()->child_count(); ++i) { | 665 for (int i = 0; i < widget->GetContentsView()->child_count(); ++i) { |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 #endif // !defined(OS_WIN) | 1044 #endif // !defined(OS_WIN) |
1044 | 1045 |
1045 // Create first widget and view, activate the widget, and focus the view. | 1046 // Create first widget and view, activate the widget, and focus the view. |
1046 Widget widget1; | 1047 Widget widget1; |
1047 Widget::InitParams params1 = CreateParams(Widget::InitParams::TYPE_POPUP); | 1048 Widget::InitParams params1 = CreateParams(Widget::InitParams::TYPE_POPUP); |
1048 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1049 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
1049 params1.activatable = Widget::InitParams::ACTIVATABLE_YES; | 1050 params1.activatable = Widget::InitParams::ACTIVATABLE_YES; |
1050 widget1.Init(params1); | 1051 widget1.Init(params1); |
1051 | 1052 |
1052 View* view1 = new View(); | 1053 View* view1 = new View(); |
1053 view1->SetFocusable(true); | 1054 view1->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
1054 widget1.GetRootView()->AddChildView(view1); | 1055 widget1.GetRootView()->AddChildView(view1); |
1055 | 1056 |
1056 ActivateSync(&widget1); | 1057 ActivateSync(&widget1); |
1057 | 1058 |
1058 FocusManager* focus_manager1 = widget1.GetFocusManager(); | 1059 FocusManager* focus_manager1 = widget1.GetFocusManager(); |
1059 ASSERT_TRUE(focus_manager1); | 1060 ASSERT_TRUE(focus_manager1); |
1060 focus_manager1->SetFocusedView(view1); | 1061 focus_manager1->SetFocusedView(view1); |
1061 EXPECT_EQ(view1, focus_manager1->GetFocusedView()); | 1062 EXPECT_EQ(view1, focus_manager1->GetFocusedView()); |
1062 | 1063 |
1063 // Create second widget and view, activate the widget, and focus the view. | 1064 // Create second widget and view, activate the widget, and focus the view. |
1064 Widget widget2; | 1065 Widget widget2; |
1065 Widget::InitParams params2 = CreateParams(Widget::InitParams::TYPE_POPUP); | 1066 Widget::InitParams params2 = CreateParams(Widget::InitParams::TYPE_POPUP); |
1066 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1067 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
1067 params2.activatable = Widget::InitParams::ACTIVATABLE_YES; | 1068 params2.activatable = Widget::InitParams::ACTIVATABLE_YES; |
1068 widget2.Init(params2); | 1069 widget2.Init(params2); |
1069 | 1070 |
1070 View* view2 = new View(); | 1071 View* view2 = new View(); |
1071 view2->SetFocusable(true); | 1072 view2->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
1072 widget2.GetRootView()->AddChildView(view2); | 1073 widget2.GetRootView()->AddChildView(view2); |
1073 | 1074 |
1074 ActivateSync(&widget2); | 1075 ActivateSync(&widget2); |
1075 EXPECT_TRUE(widget2.IsActive()); | 1076 EXPECT_TRUE(widget2.IsActive()); |
1076 EXPECT_FALSE(widget1.IsActive()); | 1077 EXPECT_FALSE(widget1.IsActive()); |
1077 | 1078 |
1078 FocusManager* focus_manager2 = widget2.GetFocusManager(); | 1079 FocusManager* focus_manager2 = widget2.GetFocusManager(); |
1079 ASSERT_TRUE(focus_manager2); | 1080 ASSERT_TRUE(focus_manager2); |
1080 focus_manager2->SetFocusedView(view2); | 1081 focus_manager2->SetFocusedView(view2); |
1081 EXPECT_EQ(view2, focus_manager2->GetFocusedView()); | 1082 EXPECT_EQ(view2, focus_manager2->GetFocusedView()); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 RunPendingMessages(); | 1223 RunPendingMessages(); |
1223 } | 1224 } |
1224 | 1225 |
1225 // Testing initial focus is assigned properly for normal top-level widgets, | 1226 // Testing initial focus is assigned properly for normal top-level widgets, |
1226 // and subclasses that specify a initially focused child view. | 1227 // and subclasses that specify a initially focused child view. |
1227 TEST_F(WidgetTestInteractive, InitialFocus) { | 1228 TEST_F(WidgetTestInteractive, InitialFocus) { |
1228 // By default, there is no initially focused view (even if there is a | 1229 // By default, there is no initially focused view (even if there is a |
1229 // focusable subview). | 1230 // focusable subview). |
1230 Widget* toplevel(CreateTopLevelPlatformWidget()); | 1231 Widget* toplevel(CreateTopLevelPlatformWidget()); |
1231 View* view = new View; | 1232 View* view = new View; |
1232 view->SetFocusable(true); | 1233 view->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
1233 toplevel->GetContentsView()->AddChildView(view); | 1234 toplevel->GetContentsView()->AddChildView(view); |
1234 | 1235 |
1235 ShowSync(toplevel); | 1236 ShowSync(toplevel); |
1236 toplevel->Show(); | 1237 toplevel->Show(); |
1237 EXPECT_FALSE(view->HasFocus()); | 1238 EXPECT_FALSE(view->HasFocus()); |
1238 EXPECT_FALSE(toplevel->GetFocusManager()->GetStoredFocusView()); | 1239 EXPECT_FALSE(toplevel->GetFocusManager()->GetStoredFocusView()); |
1239 toplevel->CloseNow(); | 1240 toplevel->CloseNow(); |
1240 | 1241 |
1241 // Testing a widget which specifies a initially focused view. | 1242 // Testing a widget which specifies a initially focused view. |
1242 TestInitialFocusWidgetDelegate delegate(GetContext()); | 1243 TestInitialFocusWidgetDelegate delegate(GetContext()); |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1757 | 1758 |
1758 ui::KeyEvent key_event2(key_event); | 1759 ui::KeyEvent key_event2(key_event); |
1759 widget->OnKeyEvent(&key_event2); | 1760 widget->OnKeyEvent(&key_event2); |
1760 EXPECT_FALSE(key_event2.stopped_propagation()); | 1761 EXPECT_FALSE(key_event2.stopped_propagation()); |
1761 | 1762 |
1762 widget->CloseNow(); | 1763 widget->CloseNow(); |
1763 } | 1764 } |
1764 | 1765 |
1765 } // namespace test | 1766 } // namespace test |
1766 } // namespace views | 1767 } // namespace views |
OLD | NEW |