OLD | NEW |
| (Empty) |
1 // Copyright 2017 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 <oleacc.h> | |
6 | |
7 #include "base/macros.h" | |
8 #include "base/path_service.h" | |
9 #include "base/strings/utf_string_conversions.h" | |
10 #include "base/win/scoped_comptr.h" | |
11 #include "base/win/scoped_variant.h" | |
12 #include "mojo/edk/embedder/embedder.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include "ui/aura/window.h" | |
15 #include "ui/aura/window_tree_host.h" | |
16 #include "ui/base/ime/input_method.h" | |
17 #include "ui/base/ime/text_edit_commands.h" | |
18 #include "ui/base/resource/resource_bundle.h" | |
19 #include "ui/base/ui_base_paths.h" | |
20 #include "ui/gfx/geometry/rect.h" | |
21 #include "ui/gfx/geometry/vector2d.h" | |
22 #include "ui/gfx/native_widget_types.h" | |
23 #include "ui/gl/test/gl_surface_test_support.h" | |
24 #include "ui/views/controls/textfield/textfield.h" | |
25 #include "ui/views/controls/textfield/textfield_test_api.h" | |
26 #include "ui/views/test/widget_test.h" | |
27 #include "ui/views/widget/widget.h" | |
28 | |
29 namespace views { | |
30 | |
31 namespace { | |
32 | |
33 class AXSystemCaretWinTest : public test::WidgetTest { | |
34 public: | |
35 AXSystemCaretWinTest() : self_(CHILDID_SELF) {} | |
36 ~AXSystemCaretWinTest() override {} | |
37 | |
38 void SetUp() override { | |
39 mojo::edk::Init(); | |
40 gl::GLSurfaceTestSupport::InitializeOneOff(); | |
41 ui::RegisterPathProvider(); | |
42 base::FilePath ui_test_pak_path; | |
43 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); | |
44 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | |
45 test::WidgetTest::SetUp(); | |
46 | |
47 widget_ = CreateNativeDesktopWidget(); | |
48 widget_->SetBounds(gfx::Rect(0, 0, 200, 200)); | |
49 textfield_ = new Textfield(); | |
50 textfield_->SetBounds(0, 0, 200, 20); | |
51 textfield_->SetText(base::ASCIIToUTF16("Some text.")); | |
52 widget_->GetRootView()->AddChildView(textfield_); | |
53 test::WidgetActivationWaiter waiter(widget_, true); | |
54 widget_->Show(); | |
55 waiter.Wait(); | |
56 textfield_->RequestFocus(); | |
57 ASSERT_TRUE(widget_->IsActive()); | |
58 ASSERT_TRUE(textfield_->HasFocus()); | |
59 ASSERT_EQ(ui::TEXT_INPUT_TYPE_TEXT, | |
60 widget_->GetInputMethod()->GetTextInputType()); | |
61 } | |
62 | |
63 void TearDown() override { | |
64 widget_->CloseNow(); | |
65 test::WidgetTest::TearDown(); | |
66 ui::ResourceBundle::CleanupSharedInstance(); | |
67 } | |
68 | |
69 protected: | |
70 Widget* widget_; | |
71 Textfield* textfield_; | |
72 base::win::ScopedVariant self_; | |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(AXSystemCaretWinTest); | |
75 }; | |
76 | |
77 } // namespace | |
78 | |
79 TEST_F(AXSystemCaretWinTest, TestOnCaretBoundsChangeInTextField) { | |
80 TextfieldTestApi textfield_test_api(textfield_); | |
81 base::win::ScopedComPtr<IAccessible> caret_accessible; | |
82 gfx::NativeWindow native_window = widget_->GetNativeWindow(); | |
83 ASSERT_NE(nullptr, native_window); | |
84 HWND hwnd = native_window->GetHost()->GetAcceleratedWidget(); | |
85 EXPECT_HRESULT_SUCCEEDED(AccessibleObjectFromWindow( | |
86 hwnd, static_cast<DWORD>(OBJID_CARET), IID_IAccessible, | |
87 reinterpret_cast<void**>(caret_accessible.GetAddressOf()))); | |
88 | |
89 textfield_test_api.ExecuteTextEditCommand( | |
90 ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT); | |
91 gfx::Point caret_position = textfield_test_api.GetCursorViewOrigin(); | |
92 LONG x, y, width, height; | |
93 EXPECT_EQ(S_OK, | |
94 caret_accessible->accLocation(&x, &y, &width, &height, self_)); | |
95 EXPECT_EQ(caret_position.x(), x); | |
96 EXPECT_EQ(caret_position.y(), y); | |
97 EXPECT_EQ(1, width); | |
98 | |
99 textfield_test_api.ExecuteTextEditCommand( | |
100 ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT); | |
101 gfx::Point caret_position2 = textfield_test_api.GetCursorViewOrigin(); | |
102 EXPECT_NE(caret_position, caret_position2); | |
103 EXPECT_EQ(S_OK, | |
104 caret_accessible->accLocation(&x, &y, &width, &height, self_)); | |
105 EXPECT_EQ(caret_position2.x(), x); | |
106 EXPECT_EQ(caret_position2.y(), y); | |
107 EXPECT_EQ(1, width); | |
108 } | |
109 | |
110 TEST_F(AXSystemCaretWinTest, TestOnInputTypeChangeInTextField) { | |
111 base::win::ScopedComPtr<IAccessible> caret_accessible; | |
112 gfx::NativeWindow native_window = widget_->GetNativeWindow(); | |
113 ASSERT_NE(nullptr, native_window); | |
114 HWND hwnd = native_window->GetHost()->GetAcceleratedWidget(); | |
115 EXPECT_HRESULT_SUCCEEDED(AccessibleObjectFromWindow( | |
116 hwnd, static_cast<DWORD>(OBJID_CARET), IID_IAccessible, | |
117 reinterpret_cast<void**>(caret_accessible.GetAddressOf()))); | |
118 LONG x, y, width, height; | |
119 EXPECT_EQ(S_OK, | |
120 caret_accessible->accLocation(&x, &y, &width, &height, self_)); | |
121 | |
122 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
123 // Caret object should still be valid. | |
124 EXPECT_EQ(S_OK, | |
125 caret_accessible->accLocation(&x, &y, &width, &height, self_)); | |
126 | |
127 // Retrieving the caret again should also work. | |
128 caret_accessible.Reset(); | |
129 EXPECT_HRESULT_SUCCEEDED(AccessibleObjectFromWindow( | |
130 hwnd, static_cast<DWORD>(OBJID_CARET), IID_IAccessible, | |
131 reinterpret_cast<void**>(caret_accessible.GetAddressOf()))); | |
132 LONG x2, y2, width2, height2; | |
133 EXPECT_EQ(S_OK, | |
134 caret_accessible->accLocation(&x2, &y2, &width2, &height2, self_)); | |
135 EXPECT_EQ(x, x2); | |
136 EXPECT_EQ(y, y2); | |
137 EXPECT_EQ(width, width2); | |
138 EXPECT_EQ(height, height2); | |
139 } | |
140 | |
141 TEST_F(AXSystemCaretWinTest, TestMovingWindow) { | |
142 base::win::ScopedComPtr<IAccessible> caret_accessible; | |
143 gfx::NativeWindow native_window = widget_->GetNativeWindow(); | |
144 ASSERT_NE(nullptr, native_window); | |
145 HWND hwnd = native_window->GetHost()->GetAcceleratedWidget(); | |
146 EXPECT_HRESULT_SUCCEEDED(AccessibleObjectFromWindow( | |
147 hwnd, static_cast<DWORD>(OBJID_CARET), IID_IAccessible, | |
148 reinterpret_cast<void**>(caret_accessible.GetAddressOf()))); | |
149 LONG x, y, width, height; | |
150 EXPECT_EQ(S_OK, | |
151 caret_accessible->accLocation(&x, &y, &width, &height, self_)); | |
152 | |
153 widget_->RunMoveLoop(gfx::Vector2d(), Widget::MOVE_LOOP_SOURCE_MOUSE, | |
154 Widget::MOVE_LOOP_ESCAPE_BEHAVIOR_DONT_HIDE); | |
155 // Retrieving the caret again should work but its location should be invalid. | |
156 caret_accessible.Reset(); | |
157 EXPECT_HRESULT_SUCCEEDED(AccessibleObjectFromWindow( | |
158 hwnd, static_cast<DWORD>(OBJID_CARET), IID_IAccessible, | |
159 reinterpret_cast<void**>(caret_accessible.GetAddressOf()))); | |
160 LONG x2, y2, width2, height2; | |
161 EXPECT_EQ(S_FALSE, | |
162 caret_accessible->accLocation(&x2, &y2, &width2, &height2, self_)); | |
163 EXPECT_EQ(0, x2); | |
164 EXPECT_EQ(0, y2); | |
165 EXPECT_EQ(0, width2); | |
166 EXPECT_EQ(0, height2); | |
167 } | |
168 | |
169 } // namespace views | |
OLD | NEW |