| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/accessibility/platform/ax_platform_node.h" | 5 #include "ui/accessibility/platform/ax_platform_node.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlcom.h> | 8 #include <atlcom.h> |
| 9 #include <oleacc.h> | 9 #include <oleacc.h> |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 iaccessible->AddRef(); | 88 iaccessible->AddRef(); |
| 89 return ScopedComPtr<IAccessible>(iaccessible); | 89 return ScopedComPtr<IAccessible>(iaccessible); |
| 90 } | 90 } |
| 91 | 91 |
| 92 ScopedComPtr<IAccessible> GetRootIAccessible() { | 92 ScopedComPtr<IAccessible> GetRootIAccessible() { |
| 93 return IAccessibleFromNode(GetRootNode()); | 93 return IAccessibleFromNode(GetRootNode()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 ScopedComPtr<IAccessible2> ToIAccessible2( | 96 ScopedComPtr<IAccessible2> ToIAccessible2( |
| 97 ScopedComPtr<IAccessible> accessible) { | 97 ScopedComPtr<IAccessible> accessible) { |
| 98 CHECK(accessible.get()); | 98 CHECK(accessible.Get()); |
| 99 ScopedComPtr<IServiceProvider> service_provider; | 99 ScopedComPtr<IServiceProvider> service_provider; |
| 100 service_provider.QueryFrom(accessible.get()); | 100 service_provider.QueryFrom(accessible.Get()); |
| 101 ScopedComPtr<IAccessible2> result; | 101 ScopedComPtr<IAccessible2> result; |
| 102 CHECK(SUCCEEDED( | 102 CHECK(SUCCEEDED( |
| 103 service_provider->QueryService(IID_IAccessible2, result.Receive()))); | 103 service_provider->QueryService(IID_IAccessible2, result.Receive()))); |
| 104 return result; | 104 return result; |
| 105 } | 105 } |
| 106 | 106 |
| 107 std::unique_ptr<AXTree> tree_; | 107 std::unique_ptr<AXTree> tree_; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 TEST_F(AXPlatformNodeWinTest, TestIAccessibleDetachedObject) { | 110 TEST_F(AXPlatformNodeWinTest, TestIAccessibleDetachedObject) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 EXPECT_EQ(S_OK, root_iaccessible->get_accChildCount(&child_count)); | 284 EXPECT_EQ(S_OK, root_iaccessible->get_accChildCount(&child_count)); |
| 285 EXPECT_EQ(2L, child_count); | 285 EXPECT_EQ(2L, child_count); |
| 286 EXPECT_EQ(S_OK, button_iaccessible->get_accChildCount(&child_count)); | 286 EXPECT_EQ(S_OK, button_iaccessible->get_accChildCount(&child_count)); |
| 287 EXPECT_EQ(0L, child_count); | 287 EXPECT_EQ(0L, child_count); |
| 288 EXPECT_EQ(S_OK, checkbox_iaccessible->get_accChildCount(&child_count)); | 288 EXPECT_EQ(S_OK, checkbox_iaccessible->get_accChildCount(&child_count)); |
| 289 EXPECT_EQ(0L, child_count); | 289 EXPECT_EQ(0L, child_count); |
| 290 | 290 |
| 291 { | 291 { |
| 292 ScopedComPtr<IDispatch> result; | 292 ScopedComPtr<IDispatch> result; |
| 293 EXPECT_EQ(S_OK, root_iaccessible->get_accChild(SELF, result.Receive())); | 293 EXPECT_EQ(S_OK, root_iaccessible->get_accChild(SELF, result.Receive())); |
| 294 EXPECT_EQ(result.get(), root_iaccessible); | 294 EXPECT_EQ(result.Get(), root_iaccessible); |
| 295 } | 295 } |
| 296 | 296 |
| 297 { | 297 { |
| 298 ScopedComPtr<IDispatch> result; | 298 ScopedComPtr<IDispatch> result; |
| 299 ScopedVariant child1(1); | 299 ScopedVariant child1(1); |
| 300 EXPECT_EQ(S_OK, root_iaccessible->get_accChild(child1, result.Receive())); | 300 EXPECT_EQ(S_OK, root_iaccessible->get_accChild(child1, result.Receive())); |
| 301 EXPECT_EQ(result.get(), button_iaccessible); | 301 EXPECT_EQ(result.Get(), button_iaccessible); |
| 302 } | 302 } |
| 303 | 303 |
| 304 { | 304 { |
| 305 ScopedComPtr<IDispatch> result; | 305 ScopedComPtr<IDispatch> result; |
| 306 ScopedVariant child2(2); | 306 ScopedVariant child2(2); |
| 307 EXPECT_EQ(S_OK, root_iaccessible->get_accChild(child2, result.Receive())); | 307 EXPECT_EQ(S_OK, root_iaccessible->get_accChild(child2, result.Receive())); |
| 308 EXPECT_EQ(result.get(), checkbox_iaccessible); | 308 EXPECT_EQ(result.Get(), checkbox_iaccessible); |
| 309 } | 309 } |
| 310 | 310 |
| 311 { | 311 { |
| 312 // Asking for child id 3 should fail. | 312 // Asking for child id 3 should fail. |
| 313 ScopedComPtr<IDispatch> result; | 313 ScopedComPtr<IDispatch> result; |
| 314 ScopedVariant child3(3); | 314 ScopedVariant child3(3); |
| 315 EXPECT_EQ(E_INVALIDARG, | 315 EXPECT_EQ(E_INVALIDARG, |
| 316 root_iaccessible->get_accChild(child3, result.Receive())); | 316 root_iaccessible->get_accChild(child3, result.Receive())); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // We should be able to ask for the button by its unique id too. | 319 // We should be able to ask for the button by its unique id too. |
| 320 LONG button_unique_id; | 320 LONG button_unique_id; |
| 321 ScopedComPtr<IAccessible2> button_iaccessible2 = | 321 ScopedComPtr<IAccessible2> button_iaccessible2 = |
| 322 ToIAccessible2(button_iaccessible); | 322 ToIAccessible2(button_iaccessible); |
| 323 button_iaccessible2->get_uniqueID(&button_unique_id); | 323 button_iaccessible2->get_uniqueID(&button_unique_id); |
| 324 ASSERT_LT(button_unique_id, 0); | 324 ASSERT_LT(button_unique_id, 0); |
| 325 { | 325 { |
| 326 ScopedComPtr<IDispatch> result; | 326 ScopedComPtr<IDispatch> result; |
| 327 ScopedVariant button_id_variant(button_unique_id); | 327 ScopedVariant button_id_variant(button_unique_id); |
| 328 EXPECT_EQ(S_OK, root_iaccessible->get_accChild(button_id_variant, | 328 EXPECT_EQ(S_OK, root_iaccessible->get_accChild(button_id_variant, |
| 329 result.Receive())); | 329 result.Receive())); |
| 330 EXPECT_EQ(result.get(), button_iaccessible); | 330 EXPECT_EQ(result.Get(), button_iaccessible); |
| 331 } | 331 } |
| 332 | 332 |
| 333 // We shouldn't be able to ask for the root node by its unique ID | 333 // We shouldn't be able to ask for the root node by its unique ID |
| 334 // from one of its children, though. | 334 // from one of its children, though. |
| 335 LONG root_unique_id; | 335 LONG root_unique_id; |
| 336 ScopedComPtr<IAccessible2> root_iaccessible2 = | 336 ScopedComPtr<IAccessible2> root_iaccessible2 = |
| 337 ToIAccessible2(root_iaccessible); | 337 ToIAccessible2(root_iaccessible); |
| 338 root_iaccessible2->get_uniqueID(&root_unique_id); | 338 root_iaccessible2->get_uniqueID(&root_unique_id); |
| 339 ASSERT_LT(root_unique_id, 0); | 339 ASSERT_LT(root_unique_id, 0); |
| 340 { | 340 { |
| 341 ScopedComPtr<IDispatch> result; | 341 ScopedComPtr<IDispatch> result; |
| 342 ScopedVariant root_id_variant(root_unique_id); | 342 ScopedVariant root_id_variant(root_unique_id); |
| 343 EXPECT_EQ(E_INVALIDARG, button_iaccessible->get_accChild(root_id_variant, | 343 EXPECT_EQ(E_INVALIDARG, button_iaccessible->get_accChild(root_id_variant, |
| 344 result.Receive())); | 344 result.Receive())); |
| 345 } | 345 } |
| 346 | 346 |
| 347 // Now check parents. | 347 // Now check parents. |
| 348 { | 348 { |
| 349 ScopedComPtr<IDispatch> result; | 349 ScopedComPtr<IDispatch> result; |
| 350 EXPECT_EQ(S_OK, button_iaccessible->get_accParent(result.Receive())); | 350 EXPECT_EQ(S_OK, button_iaccessible->get_accParent(result.Receive())); |
| 351 EXPECT_EQ(result.get(), root_iaccessible); | 351 EXPECT_EQ(result.Get(), root_iaccessible); |
| 352 } | 352 } |
| 353 | 353 |
| 354 { | 354 { |
| 355 ScopedComPtr<IDispatch> result; | 355 ScopedComPtr<IDispatch> result; |
| 356 EXPECT_EQ(S_OK, checkbox_iaccessible->get_accParent(result.Receive())); | 356 EXPECT_EQ(S_OK, checkbox_iaccessible->get_accParent(result.Receive())); |
| 357 EXPECT_EQ(result.get(), root_iaccessible); | 357 EXPECT_EQ(result.Get(), root_iaccessible); |
| 358 } | 358 } |
| 359 | 359 |
| 360 { | 360 { |
| 361 ScopedComPtr<IDispatch> result; | 361 ScopedComPtr<IDispatch> result; |
| 362 EXPECT_EQ(S_FALSE, root_iaccessible->get_accParent(result.Receive())); | 362 EXPECT_EQ(S_FALSE, root_iaccessible->get_accParent(result.Receive())); |
| 363 } | 363 } |
| 364 } | 364 } |
| 365 | 365 |
| 366 TEST_F(AXPlatformNodeWinTest, TestIAccessible2IndexInParent) { | 366 TEST_F(AXPlatformNodeWinTest, TestIAccessible2IndexInParent) { |
| 367 AXNodeData root; | 367 AXNodeData root; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 AXNodeData text_field_node; | 402 AXNodeData text_field_node; |
| 403 text_field_node.id = 1; | 403 text_field_node.id = 1; |
| 404 text_field_node.role = ui::AX_ROLE_TEXT_FIELD; | 404 text_field_node.role = ui::AX_ROLE_TEXT_FIELD; |
| 405 text_field_node.state = 1 << ui::AX_STATE_EDITABLE; | 405 text_field_node.state = 1 << ui::AX_STATE_EDITABLE; |
| 406 text_field_node.SetValue("Hi"); | 406 text_field_node.SetValue("Hi"); |
| 407 | 407 |
| 408 Init(text_field_node); | 408 Init(text_field_node); |
| 409 ScopedComPtr<IAccessible2> ia2_text_field = | 409 ScopedComPtr<IAccessible2> ia2_text_field = |
| 410 ToIAccessible2(GetRootIAccessible()); | 410 ToIAccessible2(GetRootIAccessible()); |
| 411 ScopedComPtr<IAccessibleText> text_field; | 411 ScopedComPtr<IAccessibleText> text_field; |
| 412 text_field.QueryFrom(ia2_text_field.get()); | 412 text_field.QueryFrom(ia2_text_field.Get()); |
| 413 ASSERT_NE(nullptr, text_field); | 413 ASSERT_NE(nullptr, text_field); |
| 414 | 414 |
| 415 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 0, 1)); | 415 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 0, 1)); |
| 416 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 1, 0)); | 416 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 1, 0)); |
| 417 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 2, 2)); | 417 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 2, 2)); |
| 418 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, IA2_TEXT_OFFSET_CARET, | 418 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, IA2_TEXT_OFFSET_CARET, |
| 419 IA2_TEXT_OFFSET_LENGTH)); | 419 IA2_TEXT_OFFSET_LENGTH)); |
| 420 | 420 |
| 421 EXPECT_HRESULT_FAILED(text_field->setSelection(1, 0, 0)); | 421 EXPECT_HRESULT_FAILED(text_field->setSelection(1, 0, 0)); |
| 422 EXPECT_HRESULT_FAILED(text_field->setSelection(0, 0, 5)); | 422 EXPECT_HRESULT_FAILED(text_field->setSelection(0, 0, 5)); |
| 423 } | 423 } |
| 424 | 424 |
| 425 } // namespace ui | 425 } // namespace ui |
| OLD | NEW |