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/path_service.h" | |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "base/win/scoped_comptr.h" | |
10 #include "base/win/scoped_variant.h" | |
11 #include "ui/aura/window.h" | |
12 #include "ui/aura/window_tree_host.h" | |
13 #include "ui/base/ime/input_method.h" | |
14 #include "ui/base/ime/text_edit_commands.h" | |
15 #include "ui/base/resource/resource_bundle.h" | |
16 #include "ui/base/ui_base_paths.h" | |
17 #include "ui/gfx/geometry/rect.h" | |
18 #include "ui/gfx/native_widget_types.h" | |
19 #include "ui/gl/test/gl_surface_test_support.h" | |
20 #include "ui/views/controls/textfield/textfield.h" | |
21 #include "ui/views/controls/textfield/textfield_test_api.h" | |
22 #include "ui/views/test/widget_test.h" | |
23 #include "ui/views/widget/widget.h" | |
24 | |
25 namespace ui { | |
26 | |
27 namespace { | |
28 | |
29 class AXFakeCaretWinTest : public views::test::WidgetTest { | |
30 public: | |
31 AXFakeCaretWinTest() {} | |
32 ~AXFakeCaretWinTest() override {} | |
33 | |
34 void SetUp() { | |
35 gl::GLSurfaceTestSupport::InitializeOneOff(); | |
dmazzoni
2017/06/15 06:00:27
Why this line?
| |
36 RegisterPathProvider(); | |
37 base::FilePath ui_test_pak_path; | |
38 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); | |
39 ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | |
dmazzoni
2017/06/15 06:00:27
Are these lines needed? Why?
| |
40 | |
41 views::test::WidgetTest::SetUp(); | |
42 } | |
43 }; | |
44 | |
45 } // namespace | |
46 | |
47 #if defined(OS_WIN) | |
48 TEST_F(AXFakeCaretWinTest, TestOnCaretBoundsChangeInTextField) { | |
49 test_views_delegate()->set_use_desktop_native_widgets(true); | |
50 views::Widget* widget = CreateNativeDesktopWidget(); | |
51 widget->SetBounds(gfx::Rect(0, 0, 200, 200)); | |
52 views::Textfield* textfield = new views::Textfield(); | |
53 textfield->SetBounds(0, 0, 200, 20); | |
54 textfield->SetText(base::ASCIIToUTF16("Some text.")); | |
55 views::TextfieldTestApi textfield_test_api(textfield); | |
56 widget->GetRootView()->AddChildView(textfield); | |
57 widget->Show(); | |
58 textfield->RequestFocus(); | |
59 ASSERT_TRUE(widget->IsActive()); | |
60 ASSERT_TRUE(textfield->HasFocus()); | |
61 ASSERT_EQ(ui::TEXT_INPUT_TYPE_TEXT, | |
62 widget->GetInputMethod()->GetTextInputType()); | |
63 | |
64 base::win::ScopedComPtr<IAccessible> caret_accessible; | |
65 base::win::ScopedVariant self(CHILDID_SELF); | |
66 gfx::NativeWindow native_window = widget->GetNativeWindow(); | |
67 ASSERT_NE(nullptr, native_window); | |
68 HWND hwnd = native_window->GetHost()->GetAcceleratedWidget(); | |
69 EXPECT_HRESULT_SUCCEEDED(AccessibleObjectFromWindow( | |
70 hwnd, static_cast<DWORD>(OBJID_CARET), IID_IAccessible, | |
71 reinterpret_cast<void**>(caret_accessible.GetAddressOf()))); | |
72 | |
73 textfield_test_api.ExecuteTextEditCommand( | |
74 TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT); | |
75 gfx::Point caret_position = textfield_test_api.GetCursorViewOrigin(); | |
76 LONG x, y, width, height; | |
77 EXPECT_EQ(S_OK, caret_accessible->accLocation(&x, &y, &width, &height, self)); | |
78 EXPECT_EQ(caret_position.x(), x); | |
79 EXPECT_EQ(caret_position.y(), y); | |
80 EXPECT_EQ(1, width); | |
81 EXPECT_EQ(1, height); | |
82 | |
83 textfield_test_api.ExecuteTextEditCommand( | |
84 TextEditCommand::MOVE_TO_END_OF_DOCUMENT); | |
85 caret_position = textfield_test_api.GetCursorViewOrigin(); | |
dmazzoni
2017/06/15 06:00:27
It might be nice to call this caret_position2 and
| |
86 EXPECT_EQ(S_OK, caret_accessible->accLocation(&x, &y, &width, &height, self)); | |
87 EXPECT_EQ(caret_position.x(), x); | |
88 EXPECT_EQ(caret_position.y(), y); | |
89 EXPECT_EQ(1, width); | |
90 EXPECT_EQ(1, height); | |
91 | |
92 widget->CloseNow(); | |
93 } | |
94 #endif // defined(OS_WIN) | |
95 | |
96 } // namespace ui | |
OLD | NEW |