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/strings/string16.h" | 5 #include "base/strings/string16.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/browser/accessibility/browser_accessibility.h" | 7 #include "content/browser/accessibility/browser_accessibility.h" |
8 #include "content/browser/accessibility/browser_accessibility_manager.h" | 8 #include "content/browser/accessibility/browser_accessibility_manager.h" |
9 #include "content/common/accessibility_messages.h" | 9 #include "content/common/accessibility_messages.h" |
10 #include "content/common/accessibility_node_data.h" | 10 #include "content/common/accessibility_node_data.h" |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 factory = new CountedBrowserAccessibilityFactory(); | 593 factory = new CountedBrowserAccessibilityFactory(); |
594 manager.reset(BrowserAccessibilityManager::Create( | 594 manager.reset(BrowserAccessibilityManager::Create( |
595 root2, | 595 root2, |
596 delegate.get(), | 596 delegate.get(), |
597 factory)); | 597 factory)); |
598 ASSERT_FALSE(delegate->got_fatal_error()); | 598 ASSERT_FALSE(delegate->got_fatal_error()); |
599 manager->UpdateNodesForTesting(child1, child2); | 599 manager->UpdateNodesForTesting(child1, child2); |
600 ASSERT_TRUE(delegate->got_fatal_error()); | 600 ASSERT_TRUE(delegate->got_fatal_error()); |
601 } | 601 } |
602 | 602 |
603 TEST(BrowserAccessibilityManagerTest, BoundsFromRange) { | |
604 AccessibilityNodeData root; | |
605 root.id = 1; | |
606 root.role = WebKit::WebAXRoleRootWebArea; | |
607 root.child_ids.push_back(2); | |
aboxhall
2013/10/04 18:53:07
I know this will work fine, but could we do it aft
dmazzoni
2013/10/21 17:25:38
Done.
| |
608 | |
609 AccessibilityNodeData static_text; | |
610 static_text.id = 2; | |
611 static_text.SetValue("Hello, world."); | |
612 static_text.role = WebKit::WebAXRoleStaticText; | |
613 static_text.child_ids.push_back(3); | |
614 static_text.child_ids.push_back(4); | |
615 static_text.location = gfx::Rect(100, 100, 29, 18); | |
616 | |
617 AccessibilityNodeData inline_text1; | |
618 inline_text1.id = 3; | |
619 inline_text1.SetValue("Hello, "); | |
620 inline_text1.role = WebKit::WebAXRoleInlineTextBox; | |
621 inline_text1.location = gfx::Rect(100, 100, 29, 9); | |
622 inline_text1.AddIntAttribute(AccessibilityNodeData::ATTR_TEXT_DIRECTION, | |
623 WebKit::WebAXTextDirectionLR); | |
624 std::vector<int32> character_offsets1; | |
625 character_offsets1.push_back(6); | |
aboxhall
2013/10/04 18:53:07
It might be helpful to comment each of these with
dmazzoni
2013/10/21 17:25:38
Done.
aboxhall
2013/10/23 15:40:54
Looks good, thanks.
| |
626 character_offsets1.push_back(11); | |
627 character_offsets1.push_back(16); | |
628 character_offsets1.push_back(21); | |
629 character_offsets1.push_back(26); | |
630 character_offsets1.push_back(29); | |
631 character_offsets1.push_back(29); | |
aboxhall
2013/10/04 18:53:07
Is this meant to be the same as the previous one?
dmazzoni
2013/10/21 17:25:38
Yes. This is an example of a space character havin
| |
632 inline_text1.AddIntListAttribute( | |
633 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS, character_offsets1); | |
634 | |
635 AccessibilityNodeData inline_text2; | |
636 inline_text2.id = 4; | |
637 inline_text2.SetValue("world."); | |
638 inline_text2.role = WebKit::WebAXRoleInlineTextBox; | |
639 inline_text2.location = gfx::Rect(100, 109, 28, 9); | |
640 inline_text2.AddIntAttribute(AccessibilityNodeData::ATTR_TEXT_DIRECTION, | |
641 WebKit::WebAXTextDirectionLR); | |
642 std::vector<int32> character_offsets2; | |
643 character_offsets2.push_back(5); | |
644 character_offsets2.push_back(10); | |
645 character_offsets2.push_back(15); | |
646 character_offsets2.push_back(20); | |
647 character_offsets2.push_back(25); | |
648 character_offsets2.push_back(28); | |
649 inline_text2.AddIntListAttribute( | |
650 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS, character_offsets2); | |
651 | |
652 scoped_ptr<BrowserAccessibilityManager> manager( | |
653 BrowserAccessibilityManager::Create( | |
654 root, | |
655 NULL, | |
656 new CountedBrowserAccessibilityFactory())); | |
657 manager->UpdateNodesForTesting(static_text, inline_text1, inline_text2); | |
658 | |
659 BrowserAccessibility* root_accessible = manager->GetRoot(); | |
660 BrowserAccessibility* static_text_accessible = root_accessible->GetChild(0); | |
661 | |
662 EXPECT_EQ(gfx::Rect(100, 100, 6, 9).ToString(), | |
663 static_text_accessible->GetLocalBoundsForRange(0, 1).ToString()); | |
664 | |
665 EXPECT_EQ(gfx::Rect(100, 100, 26, 9).ToString(), | |
666 static_text_accessible->GetLocalBoundsForRange(0, 5).ToString()); | |
667 | |
668 EXPECT_EQ(gfx::Rect(100, 109, 5, 9).ToString(), | |
669 static_text_accessible->GetLocalBoundsForRange(7, 1).ToString()); | |
670 | |
671 EXPECT_EQ(gfx::Rect(100, 109, 25, 9).ToString(), | |
672 static_text_accessible->GetLocalBoundsForRange(7, 5).ToString()); | |
673 | |
674 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(), | |
675 static_text_accessible->GetLocalBoundsForRange(5, 3).ToString()); | |
David Tseng
2013/10/17 21:32:02
How about passing in lengths beyond the actual tex
dmazzoni
2013/10/21 17:25:38
Sure, I'll add a test for an extreme range.
| |
676 } | |
677 | |
603 } // namespace content | 678 } // namespace content |
OLD | NEW |