| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/accessibility/browser_accessibility_win.h" | 5 #include "content/browser/accessibility/browser_accessibility_win.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 std::string text_value = line1 + '\n' + line2; | 333 std::string text_value = line1 + '\n' + line2; |
| 334 | 334 |
| 335 ui::AXNodeData root; | 335 ui::AXNodeData root; |
| 336 root.id = 1; | 336 root.id = 1; |
| 337 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 337 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 338 root.child_ids.push_back(2); | 338 root.child_ids.push_back(2); |
| 339 | 339 |
| 340 ui::AXNodeData text_field; | 340 ui::AXNodeData text_field; |
| 341 text_field.id = 2; | 341 text_field.id = 2; |
| 342 text_field.role = ui::AX_ROLE_TEXT_FIELD; | 342 text_field.role = ui::AX_ROLE_TEXT_FIELD; |
| 343 text_field.state = ui::AX_STATE_EDITABLE; | 343 text_field.state = 1 << ui::AX_STATE_EDITABLE; |
| 344 text_field.AddStringAttribute(ui::AX_ATTR_VALUE, text_value); | 344 text_field.SetValue(text_value); |
| 345 std::vector<int32_t> line_start_offsets; | 345 std::vector<int32_t> line_start_offsets; |
| 346 line_start_offsets.push_back(15); | 346 line_start_offsets.push_back(15); |
| 347 text_field.AddIntListAttribute( | 347 text_field.AddIntListAttribute( |
| 348 ui::AX_ATTR_LINE_BREAKS, line_start_offsets); | 348 ui::AX_ATTR_LINE_BREAKS, line_start_offsets); |
| 349 text_field.child_ids.push_back(3); | 349 text_field.child_ids.push_back(3); |
| 350 text_field.child_ids.push_back(5); | 350 text_field.child_ids.push_back(5); |
| 351 text_field.child_ids.push_back(6); | 351 text_field.child_ids.push_back(6); |
| 352 | 352 |
| 353 ui::AXNodeData static_text1; | 353 ui::AXNodeData static_text1; |
| 354 static_text1.id = 3; | 354 static_text1.id = 3; |
| 355 static_text1.role = ui::AX_ROLE_STATIC_TEXT; | 355 static_text1.role = ui::AX_ROLE_STATIC_TEXT; |
| 356 static_text1.state = ui::AX_STATE_EDITABLE; | 356 static_text1.state = 1 << ui::AX_STATE_EDITABLE; |
| 357 static_text1.AddStringAttribute(ui::AX_ATTR_NAME, line1); | 357 static_text1.SetName(line1); |
| 358 static_text1.child_ids.push_back(4); | 358 static_text1.child_ids.push_back(4); |
| 359 | 359 |
| 360 ui::AXNodeData inline_box1; | 360 ui::AXNodeData inline_box1; |
| 361 inline_box1.id = 4; | 361 inline_box1.id = 4; |
| 362 inline_box1.role = ui::AX_ROLE_INLINE_TEXT_BOX; | 362 inline_box1.role = ui::AX_ROLE_INLINE_TEXT_BOX; |
| 363 inline_box1.state = ui::AX_STATE_EDITABLE; | 363 inline_box1.state = 1 << ui::AX_STATE_EDITABLE; |
| 364 inline_box1.AddStringAttribute(ui::AX_ATTR_NAME, line1); | 364 inline_box1.SetName(line1); |
| 365 std::vector<int32_t> word_start_offsets1; | 365 std::vector<int32_t> word_start_offsets1; |
| 366 word_start_offsets1.push_back(0); | 366 word_start_offsets1.push_back(0); |
| 367 word_start_offsets1.push_back(4); | 367 word_start_offsets1.push_back(4); |
| 368 word_start_offsets1.push_back(8); | 368 word_start_offsets1.push_back(8); |
| 369 inline_box1.AddIntListAttribute( | 369 inline_box1.AddIntListAttribute( |
| 370 ui::AX_ATTR_WORD_STARTS, word_start_offsets1); | 370 ui::AX_ATTR_WORD_STARTS, word_start_offsets1); |
| 371 | 371 |
| 372 ui::AXNodeData line_break; | 372 ui::AXNodeData line_break; |
| 373 line_break.id = 5; | 373 line_break.id = 5; |
| 374 line_break.role = ui::AX_ROLE_LINE_BREAK; | 374 line_break.role = ui::AX_ROLE_LINE_BREAK; |
| 375 line_break.state = ui::AX_STATE_EDITABLE; | 375 line_break.state = 1 << ui::AX_STATE_EDITABLE; |
| 376 line_break.AddStringAttribute(ui::AX_ATTR_NAME, "\n"); | 376 line_break.SetName("\n"); |
| 377 | 377 |
| 378 ui::AXNodeData static_text2; | 378 ui::AXNodeData static_text2; |
| 379 static_text2.id = 6; | 379 static_text2.id = 6; |
| 380 static_text2.role = ui::AX_ROLE_STATIC_TEXT; | 380 static_text2.role = ui::AX_ROLE_STATIC_TEXT; |
| 381 static_text2.state = ui::AX_STATE_EDITABLE; | 381 static_text2.state = 1 << ui::AX_STATE_EDITABLE; |
| 382 static_text2.AddStringAttribute(ui::AX_ATTR_NAME, line2); | 382 static_text2.SetName(line2); |
| 383 static_text2.child_ids.push_back(7); | 383 static_text2.child_ids.push_back(7); |
| 384 | 384 |
| 385 ui::AXNodeData inline_box2; | 385 ui::AXNodeData inline_box2; |
| 386 inline_box2.id = 7; | 386 inline_box2.id = 7; |
| 387 inline_box2.role = ui::AX_ROLE_INLINE_TEXT_BOX; | 387 inline_box2.role = ui::AX_ROLE_INLINE_TEXT_BOX; |
| 388 inline_box2.state = ui::AX_STATE_EDITABLE; | 388 inline_box2.state = 1 << ui::AX_STATE_EDITABLE; |
| 389 inline_box2.AddStringAttribute(ui::AX_ATTR_NAME, line2); | 389 inline_box2.SetName(line2); |
| 390 std::vector<int32_t> word_start_offsets2; | 390 std::vector<int32_t> word_start_offsets2; |
| 391 word_start_offsets2.push_back(0); | 391 word_start_offsets2.push_back(0); |
| 392 word_start_offsets2.push_back(5); | 392 word_start_offsets2.push_back(5); |
| 393 word_start_offsets2.push_back(10); | 393 word_start_offsets2.push_back(10); |
| 394 inline_box2.AddIntListAttribute( | 394 inline_box2.AddIntListAttribute( |
| 395 ui::AX_ATTR_WORD_STARTS, word_start_offsets2); | 395 ui::AX_ATTR_WORD_STARTS, word_start_offsets2); |
| 396 | 396 |
| 397 CountedBrowserAccessibility::reset(); | 397 CountedBrowserAccessibility::reset(); |
| 398 std::unique_ptr<BrowserAccessibilityManager> manager( | 398 std::unique_ptr<BrowserAccessibilityManager> manager( |
| 399 BrowserAccessibilityManager::Create( | 399 BrowserAccessibilityManager::Create( |
| 400 MakeAXTreeUpdate(root, text_field, static_text1, inline_box1, | 400 MakeAXTreeUpdate(root, text_field, static_text1, inline_box1, |
| 401 line_break, static_text2, inline_box2), | 401 line_break, static_text2, inline_box2), |
| 402 nullptr, new CountedBrowserAccessibilityFactory())); | 402 nullptr, new CountedBrowserAccessibilityFactory())); |
| 403 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances()); | 403 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances()); |
| 404 | 404 |
| 405 BrowserAccessibilityWin* root_obj = | 405 BrowserAccessibilityWin* root_obj = |
| 406 ToBrowserAccessibilityWin(manager->GetRoot()); | 406 ToBrowserAccessibilityWin(manager->GetRoot()); |
| 407 ASSERT_NE(nullptr, root_obj); | 407 ASSERT_NE(nullptr, root_obj); |
| 408 ASSERT_EQ(1U, root_obj->PlatformChildCount()); | 408 ASSERT_EQ(1U, root_obj->PlatformChildCount()); |
| 409 | 409 |
| 410 BrowserAccessibilityWin* text_field_obj = | 410 BrowserAccessibilityWin* text_field_obj = |
| 411 ToBrowserAccessibilityWin(root_obj->PlatformGetChild(0)); | 411 ToBrowserAccessibilityWin(root_obj->PlatformGetChild(0)); |
| 412 ASSERT_NE(nullptr, text_field_obj); | 412 ASSERT_NE(nullptr, text_field_obj); |
| 413 ASSERT_EQ(0U, text_field_obj->PlatformChildCount()); | |
| 414 | 413 |
| 415 long text_len; | 414 long text_len; |
| 416 EXPECT_EQ(S_OK, text_field_obj->get_nCharacters(&text_len)); | 415 EXPECT_EQ(S_OK, text_field_obj->get_nCharacters(&text_len)); |
| 417 | 416 |
| 418 base::win::ScopedBstr text; | 417 base::win::ScopedBstr text; |
| 419 EXPECT_EQ(S_OK, text_field_obj->get_text(0, text_len, text.Receive())); | 418 EXPECT_EQ(S_OK, text_field_obj->get_text(0, text_len, text.Receive())); |
| 420 EXPECT_EQ(text_value, base::UTF16ToUTF8(base::string16(text))); | 419 EXPECT_EQ(text_value, base::UTF16ToUTF8(base::string16(text))); |
| 421 text.Reset(); | 420 text.Reset(); |
| 422 | 421 |
| 423 EXPECT_EQ(S_OK, text_field_obj->get_text(0, 4, text.Receive())); | 422 EXPECT_EQ(S_OK, text_field_obj->get_text(0, 4, text.Receive())); |
| (...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 | 1996 |
| 1998 ASSERT_NE(nullptr, manager->GetRoot()); | 1997 ASSERT_NE(nullptr, manager->GetRoot()); |
| 1999 BrowserAccessibilityWin* ax_root = | 1998 BrowserAccessibilityWin* ax_root = |
| 2000 ToBrowserAccessibilityWin(manager->GetRoot()); | 1999 ToBrowserAccessibilityWin(manager->GetRoot()); |
| 2001 ASSERT_NE(nullptr, ax_root); | 2000 ASSERT_NE(nullptr, ax_root); |
| 2002 ASSERT_EQ(1U, ax_root->PlatformChildCount()); | 2001 ASSERT_EQ(1U, ax_root->PlatformChildCount()); |
| 2003 | 2002 |
| 2004 BrowserAccessibilityWin* ax_combo_box = | 2003 BrowserAccessibilityWin* ax_combo_box = |
| 2005 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(0)); | 2004 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(0)); |
| 2006 ASSERT_NE(nullptr, ax_combo_box); | 2005 ASSERT_NE(nullptr, ax_combo_box); |
| 2007 ASSERT_EQ(0U, ax_combo_box->PlatformChildCount()); | 2006 ASSERT_EQ(1U, ax_combo_box->PlatformChildCount()); |
| 2008 | 2007 |
| 2009 HRESULT hr; | 2008 HRESULT hr; |
| 2010 LONG start_offset, end_offset; | 2009 LONG start_offset, end_offset; |
| 2011 base::win::ScopedBstr text_attributes; | 2010 base::win::ScopedBstr text_attributes; |
| 2012 | 2011 |
| 2013 // Ensure that the first part of the value is not marked misspelled. | 2012 // Ensure that the first part of the value is not marked misspelled. |
| 2014 for (LONG offset = 0; offset < value1_length; ++offset) { | 2013 for (LONG offset = 0; offset < value1_length; ++offset) { |
| 2015 hr = ax_combo_box->get_attributes(offset, &start_offset, &end_offset, | 2014 hr = ax_combo_box->get_attributes(offset, &start_offset, &end_offset, |
| 2016 text_attributes.Receive()); | 2015 text_attributes.Receive()); |
| 2017 EXPECT_EQ(S_OK, hr); | 2016 EXPECT_EQ(S_OK, hr); |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2466 std::vector<AXEventNotificationDetails> events = {event}; | 2465 std::vector<AXEventNotificationDetails> events = {event}; |
| 2467 manager->OnAccessibilityEvents(events); | 2466 manager->OnAccessibilityEvents(events); |
| 2468 | 2467 |
| 2469 EXPECT_HRESULT_SUCCEEDED(ax_child1->get_nRelations(&n_relations)); | 2468 EXPECT_HRESULT_SUCCEEDED(ax_child1->get_nRelations(&n_relations)); |
| 2470 EXPECT_EQ(2, n_relations); | 2469 EXPECT_EQ(2, n_relations); |
| 2471 EXPECT_HRESULT_SUCCEEDED(ax_child2->get_nRelations(&n_relations)); | 2470 EXPECT_HRESULT_SUCCEEDED(ax_child2->get_nRelations(&n_relations)); |
| 2472 EXPECT_EQ(2, n_relations); | 2471 EXPECT_EQ(2, n_relations); |
| 2473 } | 2472 } |
| 2474 | 2473 |
| 2475 } // namespace content | 2474 } // namespace content |
| OLD | NEW |