Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1059)

Unified Diff: chrome/browser/accessibility/browser_accessibility_win_unittest.cc

Issue 8416034: Support IAccessibleHypertext. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Update another comment. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/accessibility/browser_accessibility_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/accessibility/browser_accessibility_win_unittest.cc
diff --git a/chrome/browser/accessibility/browser_accessibility_win_unittest.cc b/chrome/browser/accessibility/browser_accessibility_win_unittest.cc
index fc7633219f22144a54791d39ba3ef879b9e52fb5..5b599831316e11e67b2cf403a801d3e6a38bb0f9 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_);
+}
« no previous file with comments | « no previous file | content/browser/accessibility/browser_accessibility_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698