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 #include <windows.h> |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/path_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/win/scoped_comptr.h" |
| 12 #include "base/win/scoped_variant.h" |
| 13 #include "mojo/edk/embedder/embedder.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/aura/window.h" |
| 16 #include "ui/aura/window_tree_host.h" |
| 17 #include "ui/base/ime/input_method.h" |
| 18 #include "ui/base/ime/text_edit_commands.h" |
| 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/base/ui_base_paths.h" |
| 21 #include "ui/gfx/geometry/rect.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, DISABLED_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, DISABLED_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, DISABLED_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_->SetBounds(gfx::Rect(100, 100, 500, 500)); |
| 154 LONG x2, y2, width2, height2; |
| 155 caret_accessible.Reset(); |
| 156 EXPECT_HRESULT_SUCCEEDED(AccessibleObjectFromWindow( |
| 157 hwnd, static_cast<DWORD>(OBJID_CARET), IID_IAccessible, |
| 158 reinterpret_cast<void**>(caret_accessible.GetAddressOf()))); |
| 159 EXPECT_EQ(S_OK, |
| 160 caret_accessible->accLocation(&x2, &y2, &width2, &height2, self_)); |
| 161 EXPECT_NE(x, x2); |
| 162 EXPECT_NE(y, y2); |
| 163 // The width and height of the caret shouldn't change. |
| 164 EXPECT_EQ(width, width2); |
| 165 EXPECT_EQ(height, height2); |
| 166 |
| 167 // Try maximizing the window. |
| 168 SendMessage(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0); |
| 169 LONG x3, y3, width3, height3; |
| 170 EXPECT_HRESULT_FAILED( |
| 171 caret_accessible->accLocation(&x3, &y3, &width3, &height3, self_)); |
| 172 caret_accessible.Reset(); |
| 173 |
| 174 EXPECT_HRESULT_SUCCEEDED(AccessibleObjectFromWindow( |
| 175 hwnd, static_cast<DWORD>(OBJID_CARET), IID_IAccessible, |
| 176 reinterpret_cast<void**>(caret_accessible.GetAddressOf()))); |
| 177 EXPECT_EQ(S_OK, |
| 178 caret_accessible->accLocation(&x3, &y3, &width3, &height3, self_)); |
| 179 EXPECT_NE(x2, x3); |
| 180 EXPECT_NE(y2, y3); |
| 181 // The width and height of the caret shouldn't change. |
| 182 EXPECT_EQ(width, width3); |
| 183 EXPECT_EQ(height, height3); |
| 184 } |
| 185 |
| 186 } // namespace views |
OLD | NEW |