OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/views/widget/native_widget_aura.h" | |
6 | |
7 #include "base/path_service.h" | |
8 #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" | |
13 #include "ui/views/test/native_widget_factory.h" | |
14 #include "ui/views/test/views_test_base.h" | |
15 #include "ui/views/test/widget_test.h" | |
16 #include "ui/views/widget/widget_delegate.h" | |
17 #include "ui/wm/core/base_focus_rules.h" | |
18 #include "ui/wm/core/focus_controller.h" | |
19 | |
20 namespace views { | |
21 namespace test { | |
22 | |
23 class TestFocusRules : public wm::BaseFocusRules { | |
24 public: | |
25 TestFocusRules() {} | |
26 ~TestFocusRules() override {} | |
27 | |
28 void set_can_activate(bool can_activate) { can_activate_ = can_activate; } | |
29 | |
30 // wm::BaseFocusRules overrides: | |
31 bool SupportsChildActivation(aura::Window* window) const override { | |
32 return true; | |
33 } | |
34 | |
35 bool CanActivateWindow(aura::Window* window) const override { | |
36 return can_activate_; | |
37 } | |
38 | |
39 private: | |
40 bool can_activate_ = true; | |
41 | |
42 DISALLOW_COPY_AND_ASSIGN(TestFocusRules); | |
43 }; | |
44 | |
45 class NativeWidgetAuraTest : public ViewsTestBase { | |
46 public: | |
47 NativeWidgetAuraTest() {} | |
48 ~NativeWidgetAuraTest() override {} | |
49 | |
50 void SetUp() override { | |
51 gl::GLSurfaceTestSupport::InitializeOneOff(); | |
sky
2016/10/21 03:14:18
Ugh, we should really move this to a common base c
Qiang(Joe) Xu
2016/10/21 16:23:06
Done.
| |
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 | |
69 // (crbug.com/621791) | |
sky
2016/10/21 03:14:18
Please add a descriptive comment. You shouldn't ne
Qiang(Joe) Xu
2016/10/21 16:23:07
Done.
| |
70 TEST_F(NativeWidgetAuraTest, NonActiveWindowRequestImeFocus) { | |
71 TestFocusRules* test_focus_rules = new TestFocusRules; | |
72 std::unique_ptr<wm::FocusController> focus_controller = | |
73 base::MakeUnique<wm::FocusController>(test_focus_rules); | |
74 aura::client::SetActivationClient(GetContext(), focus_controller.get()); | |
75 | |
76 Widget* widget1 = new Widget; | |
77 Widget::InitParams params1(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
78 params1.context = GetContext(); | |
79 params1.native_widget = CreateNativeWidget(params1, widget1); | |
80 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
81 widget1->Init(params1); | |
82 Textfield* textfield1 = new Textfield; | |
83 widget1->GetRootView()->AddChildView(textfield1); | |
84 | |
85 Widget* widget2 = new Widget; | |
86 Widget::InitParams params2(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
87 params2.context = GetContext(); | |
88 params2.native_widget = CreateNativeWidget(params2, widget2); | |
89 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
90 widget2->Init(params2); | |
91 Textfield* textfield2a = new Textfield; | |
92 widget2->GetRootView()->AddChildView(textfield2a); | |
93 Textfield* textfield2b = new Textfield; | |
94 widget2->GetRootView()->AddChildView(textfield2b); | |
95 | |
96 views::test::WidgetActivationWaiter waiter1(widget1, true); | |
97 widget1->Show(); | |
98 waiter1.Wait(); | |
99 textfield1->RequestFocus(); | |
100 EXPECT_TRUE(textfield1->HasFocus()); | |
101 EXPECT_FALSE(textfield2a->HasFocus()); | |
102 EXPECT_FALSE(textfield2b->HasFocus()); | |
103 | |
104 // Don't allow window activation at this step. | |
105 test_focus_rules->set_can_activate(false); | |
106 textfield2a->RequestFocus(); | |
107 EXPECT_TRUE(textfield1->HasFocus()); | |
108 EXPECT_FALSE(textfield2a->HasFocus()); | |
109 EXPECT_FALSE(textfield2b->HasFocus()); | |
110 | |
111 // Allow window activation and |widget2| gets activated at this step, focus | |
112 // should be properly restored. | |
113 test_focus_rules->set_can_activate(true); | |
114 views::test::WidgetActivationWaiter waiter2(widget2, true); | |
115 widget2->Activate(); | |
116 waiter2.Wait(); | |
117 EXPECT_TRUE(textfield2a->HasFocus()); | |
118 EXPECT_FALSE(textfield2b->HasFocus()); | |
119 EXPECT_FALSE(textfield1->HasFocus()); | |
120 | |
121 widget1->CloseNow(); | |
122 widget2->CloseNow(); | |
123 } | |
124 | |
125 } // namespace test | |
126 } // namespace views | |
OLD | NEW |