summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authordtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-02 00:41:04 +0000
committerdtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-02 00:41:04 +0000
commitaeecb37796eb049b1bc35fabf641ff1a0bb32e06 (patch)
treef8a334ec62fa4fc4326c695f5f046ca82edde44a /chrome/browser
parent053ec8f550db4fb9fcae72ea6de0970d9440e125 (diff)
downloadchromium_src-aeecb37796eb049b1bc35fabf641ff1a0bb32e06.zip
chromium_src-aeecb37796eb049b1bc35fabf641ff1a0bb32e06.tar.gz
chromium_src-aeecb37796eb049b1bc35fabf641ff1a0bb32e06.tar.bz2
Support IAccessibleHypertext.
- This modifies the way we build the browser accessibility tree in CreateAccessibilityTree. We still build the parent child links while recursing depth first through the WebAccessibility structure, but this patch changes the initialization of a node to occur *after* the children have been fully populated into the subtree of any given node. - implements IAccessibleHypertext on a BrowserAccessibilityWin. Adds: -- a string for the hypertext which contains the text of the static text children concatinated together along with the embedded characters for the non-text children. -- map from the character offset within the hypertext to a hyperlink index. -- a collection of children that are hyperlinks (basically nodes that are not static texts). - adds no-op implementations of IAccessibleHyperlink and IAccessibleAction as required by the usage and interface inheritance of IAccessibleHyperlink. BUG=99629 TEST=manually tested with NVDA. Review URL: http://codereview.chromium.org/8416034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/accessibility/browser_accessibility_win_unittest.cc167
1 files changed, 167 insertions, 0 deletions
diff --git a/chrome/browser/accessibility/browser_accessibility_win_unittest.cc b/chrome/browser/accessibility/browser_accessibility_win_unittest.cc
index fc76332..9b8820f 100644
--- a/chrome/browser/accessibility/browser_accessibility_win_unittest.cc
+++ b/chrome/browser/accessibility/browser_accessibility_win_unittest.cc
@@ -368,3 +368,170 @@ TEST_F(BrowserAccessibilityTest, TestTextBoundaries) {
delete manager;
ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
}
+
+TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) {
+ WebAccessibility text1;
+ text1.id = 11;
+ text1.role = WebAccessibility::ROLE_STATIC_TEXT;
+ text1.state = 0;
+ text1.name = L"One two three.";
+
+ WebAccessibility text2;
+ text2.id = 12;
+ text2.role = WebAccessibility::ROLE_STATIC_TEXT;
+ text2.state = 0;
+ text2.name = L" Four five six.";
+
+ WebAccessibility root;
+ root.id = 1;
+ root.role = WebAccessibility::ROLE_DOCUMENT;
+ root.state = 0;
+ root.children.push_back(text1);
+ root.children.push_back(text2);
+
+ CountedBrowserAccessibility::global_obj_count_ = 0;
+ BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create(
+ GetDesktopWindow(), root, NULL,
+ new CountedBrowserAccessibilityFactory());
+ ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_);
+
+ BrowserAccessibilityWin* root_obj =
+ manager->GetRoot()->toBrowserAccessibilityWin();
+
+ BSTR text;
+
+ long text_len;
+ ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len));
+
+ ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text));
+ EXPECT_EQ(text, text1.name + text2.name);
+ SysFreeString(text);
+
+ long hyperlink_count;
+ ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count));
+ EXPECT_EQ(0, hyperlink_count);
+
+ base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink;
+ EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive()));
+ EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive()));
+ EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive()));
+ EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive()));
+
+ long hyperlink_index;
+ EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index));
+ EXPECT_EQ(-1, hyperlink_index);
+ EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index));
+ EXPECT_EQ(-1, hyperlink_index);
+ EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index));
+ EXPECT_EQ(-1, hyperlink_index);
+ EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index));
+ EXPECT_EQ(-1, hyperlink_index);
+
+ // Delete the manager and test that all BrowserAccessibility instances are
+ // deleted.
+ delete manager;
+ ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
+}
+
+TEST_F(BrowserAccessibilityTest, TestComplexHypertext) {
+ WebAccessibility text1;
+ text1.id = 11;
+ text1.role = WebAccessibility::ROLE_STATIC_TEXT;
+ text1.state = 0;
+ text1.name = L"One two three.";
+
+ WebAccessibility text2;
+ text2.id = 12;
+ text2.role = WebAccessibility::ROLE_STATIC_TEXT;
+ text2.state = 0;
+ text2.name = L" Four five six.";
+
+ WebAccessibility button1, button1_text;
+ button1.id = 13;
+ button1_text.id = 15;
+ button1_text.name = L"red";
+ button1.role = WebAccessibility::ROLE_BUTTON;
+ button1_text.role = WebAccessibility::ROLE_STATIC_TEXT;
+ button1.state = 0;
+ button1.children.push_back(button1_text);
+
+ WebAccessibility link1, link1_text;
+ link1.id = 14;
+ link1_text.id = 16;
+ link1_text.name = L"blue";
+ link1.role = WebAccessibility::ROLE_LINK;
+ link1_text.role = WebAccessibility::ROLE_STATIC_TEXT;
+ link1.state = 0;
+ link1.children.push_back(link1_text);
+
+ WebAccessibility root;
+ root.id = 1;
+ root.role = WebAccessibility::ROLE_DOCUMENT;
+ root.state = 0;
+ root.children.push_back(text1);
+ root.children.push_back(button1);
+ root.children.push_back(text2);
+ root.children.push_back(link1);
+
+ CountedBrowserAccessibility::global_obj_count_ = 0;
+ BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create(
+ GetDesktopWindow(), root, NULL,
+ new CountedBrowserAccessibilityFactory());
+ ASSERT_EQ(7, CountedBrowserAccessibility::global_obj_count_);
+
+ BrowserAccessibilityWin* root_obj =
+ manager->GetRoot()->toBrowserAccessibilityWin();
+
+ BSTR text;
+
+ long text_len;
+ ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len));
+
+ ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text));
+ const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter;
+ EXPECT_EQ(text, text1.name + embed + text2.name + embed);
+ SysFreeString(text);
+
+ long hyperlink_count;
+ ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count));
+ EXPECT_EQ(2, hyperlink_count);
+
+ base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink;
+ base::win::ScopedComPtr<IAccessibleText> hypertext;
+ EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive()));
+ EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive()));
+ EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive()));
+
+ EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive()));
+ EXPECT_EQ(S_OK,
+ hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive()));
+ EXPECT_EQ(S_OK, hypertext->get_text(0, 3, &text));
+ EXPECT_EQ(text, string16(L"red"));
+ SysFreeString(text);
+ hyperlink.Release();
+ hypertext.Release();
+
+ EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive()));
+ EXPECT_EQ(S_OK,
+ hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive()));
+ EXPECT_EQ(S_OK, hypertext->get_text(0, 4, &text));
+ EXPECT_EQ(text, string16(L"blue"));
+ SysFreeString(text);
+ hyperlink.Release();
+ hypertext.Release();
+
+ long hyperlink_index;
+ EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index));
+ EXPECT_EQ(-1, hyperlink_index);
+ EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index));
+ EXPECT_EQ(-1, hyperlink_index);
+ EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index));
+ EXPECT_EQ(0, hyperlink_index);
+ EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index));
+ EXPECT_EQ(1, hyperlink_index);
+
+ // Delete the manager and test that all BrowserAccessibility instances are
+ // deleted.
+ delete manager;
+ ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
+}