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