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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "base/win/scoped_bstr.h" | 7 #include "base/win/scoped_bstr.h" |
8 #include "base/win/scoped_comptr.h" | 8 #include "base/win/scoped_comptr.h" |
9 #include "base/win/scoped_variant.h" | 9 #include "base/win/scoped_variant.h" |
10 #include "content/browser/accessibility/browser_accessibility_manager.h" | 10 #include "content/browser/accessibility/browser_accessibility_manager.h" |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 477 |
478 // Delete the manager and test that all BrowserAccessibility instances are | 478 // Delete the manager and test that all BrowserAccessibility instances are |
479 // deleted. | 479 // deleted. |
480 manager.reset(); | 480 manager.reset(); |
481 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 481 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
482 } | 482 } |
483 | 483 |
484 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { | 484 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { |
485 const std::string text1_name = "One two three."; | 485 const std::string text1_name = "One two three."; |
486 const std::string text2_name = " Four five six."; | 486 const std::string text2_name = " Four five six."; |
| 487 const size_t text_name_len = text1_name.length() + text2_name.length(); |
487 | 488 |
488 ui::AXNodeData text1; | 489 ui::AXNodeData text1; |
489 text1.id = 11; | 490 text1.id = 11; |
490 text1.role = ui::AX_ROLE_STATIC_TEXT; | 491 text1.role = ui::AX_ROLE_STATIC_TEXT; |
491 text1.state = 1 << ui::AX_STATE_READ_ONLY; | 492 text1.state = 1 << ui::AX_STATE_READ_ONLY; |
492 text1.SetName(text1_name); | 493 text1.SetName(text1_name); |
493 | 494 |
494 ui::AXNodeData text2; | 495 ui::AXNodeData text2; |
495 text2.id = 12; | 496 text2.id = 12; |
496 text2.role = ui::AX_ROLE_STATIC_TEXT; | 497 text2.role = ui::AX_ROLE_STATIC_TEXT; |
497 text2.state = 1 << ui::AX_STATE_READ_ONLY; | 498 text2.state = 1 << ui::AX_STATE_READ_ONLY; |
498 text2.SetName(text2_name); | 499 text2.SetName(text2_name); |
499 | 500 |
500 ui::AXNodeData root; | 501 ui::AXNodeData root; |
501 root.id = 1; | 502 root.id = 1; |
502 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 503 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
503 root.state = 1 << ui::AX_STATE_READ_ONLY; | 504 root.state = 1 << ui::AX_STATE_READ_ONLY; |
504 root.child_ids.push_back(11); | 505 root.child_ids.push_back(11); |
505 root.child_ids.push_back(12); | 506 root.child_ids.push_back(12); |
506 | 507 |
507 CountedBrowserAccessibility::reset(); | 508 CountedBrowserAccessibility::reset(); |
508 scoped_ptr<BrowserAccessibilityManager> manager( | 509 scoped_ptr<BrowserAccessibilityManager> manager( |
509 BrowserAccessibilityManager::Create( | 510 BrowserAccessibilityManager::Create( |
510 MakeAXTreeUpdate(root, text1, text2), | 511 MakeAXTreeUpdate(root, text1, text2), nullptr, |
511 NULL, new CountedBrowserAccessibilityFactory())); | 512 new CountedBrowserAccessibilityFactory())); |
512 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); | 513 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); |
513 | 514 |
514 BrowserAccessibilityWin* root_obj = | 515 BrowserAccessibilityWin* root_obj = |
515 manager->GetRoot()->ToBrowserAccessibilityWin(); | 516 manager->GetRoot()->ToBrowserAccessibilityWin(); |
516 | 517 |
517 long text_len; | 518 long text_len; |
518 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); | 519 EXPECT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
| 520 EXPECT_EQ(text_name_len, text_len); |
519 | 521 |
520 base::win::ScopedBstr text; | 522 base::win::ScopedBstr text; |
521 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); | 523 EXPECT_EQ(S_OK, root_obj->get_text(0, text_name_len, text.Receive())); |
522 EXPECT_EQ(text1_name + text2_name, base::UTF16ToUTF8(base::string16(text))); | 524 EXPECT_EQ(text1_name + text2_name, base::UTF16ToUTF8(base::string16(text))); |
523 | 525 |
524 long hyperlink_count; | 526 long hyperlink_count; |
525 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); | 527 EXPECT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
526 EXPECT_EQ(0, hyperlink_count); | 528 EXPECT_EQ(0, hyperlink_count); |
527 | 529 |
528 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; | 530 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
529 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); | 531 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
530 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive())); | 532 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive())); |
531 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); | 533 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
532 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive())); | |
533 | 534 |
534 long hyperlink_index; | 535 long hyperlink_index; |
535 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); | 536 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
536 EXPECT_EQ(-1, hyperlink_index); | 537 EXPECT_EQ(-1, hyperlink_index); |
537 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); | 538 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
538 EXPECT_EQ(-1, hyperlink_index); | 539 EXPECT_EQ(-1, hyperlink_index); |
539 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); | 540 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); |
540 EXPECT_EQ(-1, hyperlink_index); | 541 EXPECT_EQ(-1, hyperlink_index); |
541 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); | 542 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); |
542 EXPECT_EQ(-1, hyperlink_index); | 543 EXPECT_EQ(-1, hyperlink_index); |
543 | 544 |
544 // Delete the manager and test that all BrowserAccessibility instances are | |
545 // deleted. | |
546 manager.reset(); | 545 manager.reset(); |
547 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 546 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
548 } | 547 } |
549 | 548 |
550 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { | 549 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { |
551 const std::string text1_name = "One two three."; | 550 const base::string16 text1_name = L"One two three."; |
552 const std::string text2_name = " Four five six."; | 551 const base::string16 combo_box_name = L"City:"; |
553 const std::string button1_text_name = "red"; | 552 const base::string16 combo_box_value = L"Happyland"; |
554 const std::string link1_text_name = "blue"; | 553 const base::string16 text2_name = L" Four five six."; |
| 554 const base::string16 button_text_name = L"Red"; |
| 555 const base::string16 link_text_name = L"Blue"; |
| 556 // Each control (combo box, button and link) will be represented by an |
| 557 // embedded object character. |
| 558 const base::string16 embed(1, BrowserAccessibilityWin::kEmbeddedCharacter); |
| 559 const base::string16 root_hypertext = |
| 560 text1_name + embed + text2_name + embed + embed; |
| 561 const size_t root_hypertext_len = root_hypertext.length(); |
555 | 562 |
556 ui::AXNodeData text1; | 563 ui::AXNodeData text1; |
557 text1.id = 11; | 564 text1.id = 11; |
558 text1.role = ui::AX_ROLE_STATIC_TEXT; | 565 text1.role = ui::AX_ROLE_STATIC_TEXT; |
559 text1.state = 1 << ui::AX_STATE_READ_ONLY; | 566 text1.state = 1 << ui::AX_STATE_READ_ONLY; |
560 text1.SetName(text1_name); | 567 text1.SetName(base::UTF16ToUTF8(text1_name)); |
| 568 |
| 569 ui::AXNodeData combo_box; |
| 570 combo_box.id = 12; |
| 571 combo_box.role = ui::AX_ROLE_COMBO_BOX; |
| 572 combo_box.SetName(base::UTF16ToUTF8(combo_box_name)); |
| 573 combo_box.SetValue(base::UTF16ToUTF8(combo_box_value)); |
561 | 574 |
562 ui::AXNodeData text2; | 575 ui::AXNodeData text2; |
563 text2.id = 12; | 576 text2.id = 13; |
564 text2.role = ui::AX_ROLE_STATIC_TEXT; | 577 text2.role = ui::AX_ROLE_STATIC_TEXT; |
565 text2.state = 1 << ui::AX_STATE_READ_ONLY; | 578 text2.state = 1 << ui::AX_STATE_READ_ONLY; |
566 text2.SetName(text2_name); | 579 text2.SetName(base::UTF16ToUTF8(text2_name)); |
567 | 580 |
568 ui::AXNodeData button1, button1_text; | 581 ui::AXNodeData button, button_text; |
569 button1.id = 13; | 582 button.id = 14; |
570 button1_text.id = 15; | 583 button_text.id = 16; |
571 button1_text.SetName(button1_text_name); | 584 button_text.SetName(base::UTF16ToUTF8(button_text_name)); |
572 button1.role = ui::AX_ROLE_BUTTON; | 585 button.role = ui::AX_ROLE_BUTTON; |
573 button1_text.role = ui::AX_ROLE_STATIC_TEXT; | 586 button_text.role = ui::AX_ROLE_STATIC_TEXT; |
574 button1.state = 1 << ui::AX_STATE_READ_ONLY; | 587 button.state = 1 << ui::AX_STATE_READ_ONLY; |
575 button1_text.state = 1 << ui::AX_STATE_READ_ONLY; | 588 button_text.state = 1 << ui::AX_STATE_READ_ONLY; |
576 button1.child_ids.push_back(15); | 589 button.child_ids.push_back(16); |
577 | 590 |
578 ui::AXNodeData link1, link1_text; | 591 ui::AXNodeData link, link_text; |
579 link1.id = 14; | 592 link.id = 15; |
580 link1_text.id = 16; | 593 link_text.id = 17; |
581 link1_text.SetName(link1_text_name); | 594 link_text.SetName(base::UTF16ToUTF8(link_text_name)); |
582 link1.role = ui::AX_ROLE_LINK; | 595 link.role = ui::AX_ROLE_LINK; |
583 link1_text.role = ui::AX_ROLE_STATIC_TEXT; | 596 link_text.role = ui::AX_ROLE_STATIC_TEXT; |
584 link1.state = 1 << ui::AX_STATE_READ_ONLY; | 597 link.state = 1 << ui::AX_STATE_READ_ONLY; |
585 link1_text.state = 1 << ui::AX_STATE_READ_ONLY; | 598 link_text.state = 1 << ui::AX_STATE_READ_ONLY; |
586 link1.child_ids.push_back(16); | 599 link.child_ids.push_back(17); |
587 | 600 |
588 ui::AXNodeData root; | 601 ui::AXNodeData root; |
589 root.id = 1; | 602 root.id = 1; |
590 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 603 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
591 root.state = 1 << ui::AX_STATE_READ_ONLY; | 604 root.state = 1 << ui::AX_STATE_READ_ONLY; |
592 root.child_ids.push_back(11); | 605 root.child_ids.push_back(11); |
| 606 root.child_ids.push_back(12); |
593 root.child_ids.push_back(13); | 607 root.child_ids.push_back(13); |
594 root.child_ids.push_back(12); | |
595 root.child_ids.push_back(14); | 608 root.child_ids.push_back(14); |
| 609 root.child_ids.push_back(15); |
596 | 610 |
597 CountedBrowserAccessibility::reset(); | 611 CountedBrowserAccessibility::reset(); |
598 scoped_ptr<BrowserAccessibilityManager> manager( | 612 scoped_ptr<BrowserAccessibilityManager> manager( |
599 BrowserAccessibilityManager::Create( | 613 BrowserAccessibilityManager::Create( |
600 MakeAXTreeUpdate(root, | 614 MakeAXTreeUpdate(root, text1, combo_box, text2, button, button_text, |
601 text1, button1, button1_text, | 615 link, link_text), |
602 text2, link1, link1_text), | 616 nullptr, new CountedBrowserAccessibilityFactory())); |
603 NULL, new CountedBrowserAccessibilityFactory())); | 617 ASSERT_EQ(8, CountedBrowserAccessibility::num_instances()); |
604 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances()); | |
605 | 618 |
606 BrowserAccessibilityWin* root_obj = | 619 BrowserAccessibilityWin* root_obj = |
607 manager->GetRoot()->ToBrowserAccessibilityWin(); | 620 manager->GetRoot()->ToBrowserAccessibilityWin(); |
608 | 621 |
609 long text_len; | 622 long text_len; |
610 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); | 623 EXPECT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
| 624 EXPECT_EQ(root_hypertext_len, text_len); |
611 | 625 |
612 base::win::ScopedBstr text; | 626 base::win::ScopedBstr text; |
613 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); | 627 EXPECT_EQ(S_OK, root_obj->get_text(0, root_hypertext_len, text.Receive())); |
614 const std::string embed = base::UTF16ToUTF8( | 628 EXPECT_STREQ(root_hypertext.c_str(), text); |
615 base::string16(1, BrowserAccessibilityWin::kEmbeddedCharacter)); | |
616 EXPECT_EQ(text1_name + embed + text2_name + embed, | |
617 base::UTF16ToUTF8(base::string16(text))); | |
618 text.Reset(); | 629 text.Reset(); |
619 | 630 |
620 long hyperlink_count; | 631 long hyperlink_count; |
621 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); | 632 EXPECT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
622 EXPECT_EQ(2, hyperlink_count); | 633 EXPECT_EQ(3, hyperlink_count); |
623 | 634 |
624 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; | 635 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
625 base::win::ScopedComPtr<IAccessibleText> hypertext; | 636 base::win::ScopedComPtr<IAccessibleText> hypertext; |
626 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); | 637 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
627 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive())); | 638 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(3, hyperlink.Receive())); |
628 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); | |
629 | 639 |
| 640 // Get the text of the combo box. |
| 641 // It should be its value. |
630 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive())); | 642 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive())); |
| 643 EXPECT_EQ(S_OK, hyperlink.QueryInterface(hypertext.Receive())); |
631 EXPECT_EQ(S_OK, | 644 EXPECT_EQ(S_OK, |
632 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); | 645 hypertext->get_text(0, IA2_TEXT_OFFSET_LENGTH, text.Receive())); |
633 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, text.Receive())); | 646 EXPECT_STREQ(combo_box_value.c_str(), text); |
634 EXPECT_STREQ(button1_text_name.c_str(), | |
635 base::UTF16ToUTF8(base::string16(text)).c_str()); | |
636 text.Reset(); | 647 text.Reset(); |
637 hyperlink.Release(); | 648 hyperlink.Release(); |
638 hypertext.Release(); | 649 hypertext.Release(); |
639 | 650 |
| 651 // Get the text of the button. |
640 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive())); | 652 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive())); |
| 653 EXPECT_EQ(S_OK, hyperlink.QueryInterface(hypertext.Receive())); |
641 EXPECT_EQ(S_OK, | 654 EXPECT_EQ(S_OK, |
642 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); | 655 hypertext->get_text(0, IA2_TEXT_OFFSET_LENGTH, text.Receive())); |
643 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, text.Receive())); | 656 EXPECT_STREQ(button_text_name.c_str(), text); |
644 EXPECT_STREQ(link1_text_name.c_str(), | |
645 base::UTF16ToUTF8(base::string16(text)).c_str()); | |
646 text.Reset(); | 657 text.Reset(); |
647 hyperlink.Release(); | 658 hyperlink.Release(); |
648 hypertext.Release(); | 659 hypertext.Release(); |
| 660 |
| 661 // Get the text of the link. |
| 662 EXPECT_EQ(S_OK, root_obj->get_hyperlink(2, hyperlink.Receive())); |
| 663 EXPECT_EQ(S_OK, hyperlink.QueryInterface(hypertext.Receive())); |
| 664 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, text.Receive())); |
| 665 EXPECT_STREQ(link_text_name.c_str(), text); |
| 666 text.Reset(); |
| 667 hyperlink.Release(); |
| 668 hypertext.Release(); |
649 | 669 |
650 long hyperlink_index; | 670 long hyperlink_index; |
651 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); | 671 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
652 EXPECT_EQ(-1, hyperlink_index); | 672 EXPECT_EQ(-1, hyperlink_index); |
653 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); | 673 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
654 EXPECT_EQ(-1, hyperlink_index); | 674 EXPECT_EQ(-1, hyperlink_index); |
655 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); | 675 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); |
656 EXPECT_EQ(0, hyperlink_index); | 676 EXPECT_EQ(0, hyperlink_index); |
657 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index)); | 677 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index)); |
658 EXPECT_EQ(1, hyperlink_index); | 678 EXPECT_EQ(1, hyperlink_index); |
| 679 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(31, &hyperlink_index)); |
| 680 EXPECT_EQ(2, hyperlink_index); |
659 | 681 |
660 // Delete the manager and test that all BrowserAccessibility instances are | |
661 // deleted. | |
662 manager.reset(); | 682 manager.reset(); |
663 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 683 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
664 } | 684 } |
665 | 685 |
666 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) { | 686 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) { |
667 // Try creating an empty document with busy state. Readonly is | 687 // Try creating an empty document with busy state. Readonly is |
668 // set automatically. | 688 // set automatically. |
669 CountedBrowserAccessibility::reset(); | 689 CountedBrowserAccessibility::reset(); |
670 const int32 busy_state = 1 << ui::AX_STATE_BUSY; | 690 const int32 busy_state = 1 << ui::AX_STATE_BUSY; |
671 const int32 readonly_state = 1 << ui::AX_STATE_READ_ONLY; | 691 const int32 readonly_state = 1 << ui::AX_STATE_READ_ONLY; |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 } | 1442 } |
1423 | 1443 |
1424 TEST_F(BrowserAccessibilityTest, TestSanitizeStringAttributeForIA2) { | 1444 TEST_F(BrowserAccessibilityTest, TestSanitizeStringAttributeForIA2) { |
1425 base::string16 input(L"\\:=,;"); | 1445 base::string16 input(L"\\:=,;"); |
1426 base::string16 output; | 1446 base::string16 output; |
1427 BrowserAccessibilityWin::SanitizeStringAttributeForIA2(input, &output); | 1447 BrowserAccessibilityWin::SanitizeStringAttributeForIA2(input, &output); |
1428 EXPECT_EQ(L"\\\\\\:\\=\\,\\;", output); | 1448 EXPECT_EQ(L"\\\\\\:\\=\\,\\;", output); |
1429 } | 1449 } |
1430 | 1450 |
1431 } // namespace content | 1451 } // namespace content |
OLD | NEW |