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