| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/path_service.h" | |
| 8 #include "ui/aura/window.h" | 7 #include "ui/aura/window.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | |
| 10 #include "ui/base/ui_base_paths.h" | |
| 11 #include "ui/gl/test/gl_surface_test_support.h" | |
| 12 #include "ui/views/controls/textfield/textfield.h" | 8 #include "ui/views/controls/textfield/textfield.h" |
| 13 #include "ui/views/test/native_widget_factory.h" | 9 #include "ui/views/test/native_widget_factory.h" |
| 14 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_interactive_ui_test_base.h" |
| 15 #include "ui/views/test/widget_test.h" | 11 #include "ui/views/test/widget_test.h" |
| 16 #include "ui/views/widget/widget_delegate.h" | |
| 17 #include "ui/wm/core/base_focus_rules.h" | 12 #include "ui/wm/core/base_focus_rules.h" |
| 18 #include "ui/wm/core/focus_controller.h" | 13 #include "ui/wm/core/focus_controller.h" |
| 19 | 14 |
| 20 namespace views { | 15 namespace views { |
| 21 namespace test { | 16 namespace test { |
| 22 | 17 |
| 18 namespace { |
| 19 |
| 23 class TestFocusRules : public wm::BaseFocusRules { | 20 class TestFocusRules : public wm::BaseFocusRules { |
| 24 public: | 21 public: |
| 25 TestFocusRules() {} | 22 TestFocusRules() {} |
| 26 ~TestFocusRules() override {} | 23 ~TestFocusRules() override {} |
| 27 | 24 |
| 28 void set_can_activate(bool can_activate) { can_activate_ = can_activate; } | 25 void set_can_activate(bool can_activate) { can_activate_ = can_activate; } |
| 29 | 26 |
| 30 // wm::BaseFocusRules overrides: | 27 // wm::BaseFocusRules overrides: |
| 31 bool SupportsChildActivation(aura::Window* window) const override { | 28 bool SupportsChildActivation(aura::Window* window) const override { |
| 32 return true; | 29 return true; |
| 33 } | 30 } |
| 34 | 31 |
| 35 bool CanActivateWindow(aura::Window* window) const override { | 32 bool CanActivateWindow(aura::Window* window) const override { |
| 36 return can_activate_; | 33 return can_activate_; |
| 37 } | 34 } |
| 38 | 35 |
| 39 private: | 36 private: |
| 40 bool can_activate_ = true; | 37 bool can_activate_ = true; |
| 41 | 38 |
| 42 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); | 39 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); |
| 43 }; | 40 }; |
| 44 | 41 |
| 45 class NativeWidgetAuraTest : public ViewsTestBase { | 42 } // namespace |
| 46 public: | |
| 47 NativeWidgetAuraTest() {} | |
| 48 ~NativeWidgetAuraTest() override {} | |
| 49 | 43 |
| 50 void SetUp() override { | 44 using NativeWidgetAuraTest = ViewsInteractiveUITestBase; |
| 51 gl::GLSurfaceTestSupport::InitializeOneOff(); | |
| 52 ui::RegisterPathProvider(); | |
| 53 base::FilePath ui_test_pak_path; | |
| 54 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); | |
| 55 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | |
| 56 | |
| 57 ViewsTestBase::SetUp(); | |
| 58 } | |
| 59 | |
| 60 NativeWidget* CreateNativeWidget(const Widget::InitParams& params, | |
| 61 Widget* widget) { | |
| 62 return CreatePlatformNativeWidgetImpl(params, widget, kDefault, nullptr); | |
| 63 } | |
| 64 | |
| 65 private: | |
| 66 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest); | |
| 67 }; | |
| 68 | 45 |
| 69 // When requesting view focus from a non-active top level widget, focus is not | 46 // When requesting view focus from a non-active top level widget, focus is not |
| 70 // instantly given. Instead, the view is firstly stored and then it is attempted | 47 // instantly given. Instead, the view is firstly stored and then it is attempted |
| 71 // to activate the widget. If widget is currently not activatable, focus should | 48 // to activate the widget. If widget is currently not activatable, focus should |
| 72 // not be grabbed. And focus will be given/restored the next time the widget is | 49 // not be grabbed. And focus will be given/restored the next time the widget is |
| 73 // made active. (crbug.com/621791) | 50 // made active. (crbug.com/621791) |
| 74 TEST_F(NativeWidgetAuraTest, NonActiveWindowRequestImeFocus) { | 51 TEST_F(NativeWidgetAuraTest, NonActiveWindowRequestImeFocus) { |
| 75 TestFocusRules* test_focus_rules = new TestFocusRules; | 52 TestFocusRules* test_focus_rules = new TestFocusRules; |
| 76 std::unique_ptr<wm::FocusController> focus_controller = | 53 std::unique_ptr<wm::FocusController> focus_controller = |
| 77 base::MakeUnique<wm::FocusController>(test_focus_rules); | 54 base::MakeUnique<wm::FocusController>(test_focus_rules); |
| 78 aura::client::SetActivationClient(GetContext(), focus_controller.get()); | 55 aura::client::SetActivationClient(GetContext(), focus_controller.get()); |
| 79 | 56 |
| 80 Widget* widget1 = new Widget; | 57 Widget* widget1 = new Widget; |
| 81 Widget::InitParams params1(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 58 Widget::InitParams params1(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 82 params1.context = GetContext(); | 59 params1.context = GetContext(); |
| 83 params1.native_widget = CreateNativeWidget(params1, widget1); | 60 params1.native_widget = |
| 61 CreatePlatformNativeWidgetImpl(params1, widget1, kDefault, nullptr); |
| 84 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 62 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 85 widget1->Init(params1); | 63 widget1->Init(params1); |
| 86 Textfield* textfield1 = new Textfield; | 64 Textfield* textfield1 = new Textfield; |
| 87 widget1->GetRootView()->AddChildView(textfield1); | 65 widget1->GetRootView()->AddChildView(textfield1); |
| 88 | 66 |
| 89 Widget* widget2 = new Widget; | 67 Widget* widget2 = new Widget; |
| 90 Widget::InitParams params2(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 68 Widget::InitParams params2(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 91 params2.context = GetContext(); | 69 params2.context = GetContext(); |
| 92 params2.native_widget = CreateNativeWidget(params2, widget2); | 70 params2.native_widget = |
| 71 CreatePlatformNativeWidgetImpl(params2, widget2, kDefault, nullptr); |
| 93 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 72 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 94 widget2->Init(params2); | 73 widget2->Init(params2); |
| 95 Textfield* textfield2a = new Textfield; | 74 Textfield* textfield2a = new Textfield; |
| 96 widget2->GetRootView()->AddChildView(textfield2a); | 75 widget2->GetRootView()->AddChildView(textfield2a); |
| 97 Textfield* textfield2b = new Textfield; | 76 Textfield* textfield2b = new Textfield; |
| 98 widget2->GetRootView()->AddChildView(textfield2b); | 77 widget2->GetRootView()->AddChildView(textfield2b); |
| 99 | 78 |
| 100 views::test::WidgetActivationWaiter waiter1(widget1, true); | 79 views::test::WidgetActivationWaiter waiter1(widget1, true); |
| 101 widget1->Show(); | 80 widget1->Show(); |
| 102 waiter1.Wait(); | 81 waiter1.Wait(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 EXPECT_TRUE(textfield2a->HasFocus()); | 100 EXPECT_TRUE(textfield2a->HasFocus()); |
| 122 EXPECT_FALSE(textfield2b->HasFocus()); | 101 EXPECT_FALSE(textfield2b->HasFocus()); |
| 123 EXPECT_FALSE(textfield1->HasFocus()); | 102 EXPECT_FALSE(textfield1->HasFocus()); |
| 124 | 103 |
| 125 widget1->CloseNow(); | 104 widget1->CloseNow(); |
| 126 widget2->CloseNow(); | 105 widget2->CloseNow(); |
| 127 } | 106 } |
| 128 | 107 |
| 129 } // namespace test | 108 } // namespace test |
| 130 } // namespace views | 109 } // namespace views |
| OLD | NEW |