diff options
author | dmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-20 21:16:34 +0000 |
---|---|---|
committer | dmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-20 21:16:34 +0000 |
commit | 1b12b23d8f4652d4579f2202c7431843d2d67bb2 (patch) | |
tree | fde2bc3969b5fb279dfef97300a429c606944d62 /chrome/browser/accessibility | |
parent | 6bec74ff29932a85fa2c62d1225ad09473963d84 (diff) | |
download | chromium_src-1b12b23d8f4652d4579f2202c7431843d2d67bb2.zip chromium_src-1b12b23d8f4652d4579f2202c7431843d2d67bb2.tar.gz chromium_src-1b12b23d8f4652d4579f2202c7431843d2d67bb2.tar.bz2 |
Implement IAccessibleTable and IAccessibleTableCell so that screen
readers can access HTML tables.
BUG=66874,89220,89221
TEST=Adds new tests.
Review URL: http://codereview.chromium.org/7358004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93249 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/accessibility')
-rw-r--r-- | chrome/browser/accessibility/browser_accessibility_mac_unittest.mm | 3 | ||||
-rw-r--r-- | chrome/browser/accessibility/renderer_accessibility_browsertest.cc | 106 |
2 files changed, 96 insertions, 13 deletions
diff --git a/chrome/browser/accessibility/browser_accessibility_mac_unittest.mm b/chrome/browser/accessibility/browser_accessibility_mac_unittest.mm index 595fb33..fee3fd7 100644 --- a/chrome/browser/accessibility/browser_accessibility_mac_unittest.mm +++ b/chrome/browser/accessibility/browser_accessibility_mac_unittest.mm @@ -53,7 +53,8 @@ class BrowserAccessibilityTest : public CocoaTest { root.location.set_width(500); root.location.set_height(100); root.role = WebAccessibility::ROLE_WEB_AREA; - root.attributes[WebAccessibility::ATTR_HELP] = ASCIIToUTF16("HelpText"); + root.string_attributes[WebAccessibility::ATTR_HELP] = + ASCIIToUTF16("HelpText"); WebAccessibility child1; child1.name = ASCIIToUTF16("Child1"); diff --git a/chrome/browser/accessibility/renderer_accessibility_browsertest.cc b/chrome/browser/accessibility/renderer_accessibility_browsertest.cc index 123e559..980588a 100644 --- a/chrome/browser/accessibility/renderer_accessibility_browsertest.cc +++ b/chrome/browser/accessibility/renderer_accessibility_browsertest.cc @@ -59,7 +59,9 @@ class RendererAccessibilityBrowserTest : public InProcessBrowserTest { protected: std::string GetAttr(const WebAccessibility& node, - const WebAccessibility::Attribute attr); + const WebAccessibility::StringAttribute attr); + int GetIntAttr(const WebAccessibility& node, + const WebAccessibility::IntAttribute attr); }; void RendererAccessibilityBrowserTest::SetUpInProcessBrowserTestFixture() { @@ -82,14 +84,29 @@ void RendererAccessibilityBrowserTest::TearDownInProcessBrowserTestFixture() { // Convenience method to get the value of a particular WebAccessibility // node attribute as a UTF-8 const char*. std::string RendererAccessibilityBrowserTest::GetAttr( - const WebAccessibility& node, const WebAccessibility::Attribute attr) { - std::map<int32, string16>::const_iterator iter = node.attributes.find(attr); - if (iter != node.attributes.end()) + const WebAccessibility& node, + const WebAccessibility::StringAttribute attr) { + std::map<WebAccessibility::StringAttribute, string16>::const_iterator iter = + node.string_attributes.find(attr); + if (iter != node.string_attributes.end()) return UTF16ToUTF8(iter->second); else return ""; } +// Convenience method to get the value of a particular WebAccessibility +// node integer attribute. +int RendererAccessibilityBrowserTest::GetIntAttr( + const WebAccessibility& node, + const WebAccessibility::IntAttribute attr) { + std::map<WebAccessibility::IntAttribute, int32>::const_iterator iter = + node.int_attributes.find(attr); + if (iter != node.int_attributes.end()) + return iter->second; + else + return -1; +} + IN_PROC_BROWSER_TEST_F(RendererAccessibilityBrowserTest, CrossPlatformWebpageAccessibility) { // Create a data url and load it. @@ -172,10 +189,8 @@ IN_PROC_BROWSER_TEST_F(RendererAccessibilityBrowserTest, EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text.role); EXPECT_STREQ( "input", GetAttr(text, WebAccessibility::ATTR_HTML_TAG).c_str()); - EXPECT_STREQ( - "0", GetAttr(text, WebAccessibility::ATTR_TEXT_SEL_START).c_str()); - EXPECT_STREQ( - "0", GetAttr(text, WebAccessibility::ATTR_TEXT_SEL_END).c_str()); + EXPECT_EQ(0, GetIntAttr(text, WebAccessibility::ATTR_TEXT_SEL_START)); + EXPECT_EQ(0, GetIntAttr(text, WebAccessibility::ATTR_TEXT_SEL_END)); EXPECT_STREQ("Hello, world.", UTF16ToUTF8(text.value).c_str()); // TODO(dmazzoni): as soon as more accessibility code is cross-platform, @@ -203,10 +218,8 @@ IN_PROC_BROWSER_TEST_F(RendererAccessibilityBrowserTest, EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text.role); EXPECT_STREQ( "input", GetAttr(text, WebAccessibility::ATTR_HTML_TAG).c_str()); - EXPECT_STREQ( - "0", GetAttr(text, WebAccessibility::ATTR_TEXT_SEL_START).c_str()); - EXPECT_STREQ( - "13", GetAttr(text, WebAccessibility::ATTR_TEXT_SEL_END).c_str()); + EXPECT_EQ(0, GetIntAttr(text, WebAccessibility::ATTR_TEXT_SEL_START)); + EXPECT_EQ(13, GetIntAttr(text, WebAccessibility::ATTR_TEXT_SEL_END)); EXPECT_STREQ("Hello, world.", UTF16ToUTF8(text.value).c_str()); } @@ -334,4 +347,73 @@ IN_PROC_BROWSER_TEST_F(RendererAccessibilityBrowserTest, RecursiveAssertUniqueIds(tree, &ids); } +IN_PROC_BROWSER_TEST_F(RendererAccessibilityBrowserTest, + CrossPlatformTableSpan) { + // +---+---+---+ + // | 1 | 2 | + // +---+---+---+ + // | 3 | 4 | + // +---+---+---+ + + const char url_str[] = + "data:text/html," + "<!doctype html>" + "<table border=1>" + " <tr>" + " <td colspan=2>1</td><td>2</td>" + " </tr>" + " <tr>" + " <td>3</td><td colspan=2>4</td>" + " </tr>" + "</table>"; + GURL url(url_str); + browser()->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); + + const WebAccessibility& tree = GetWebAccessibilityTree(); + const WebAccessibility& table = tree.children[0]; + EXPECT_EQ(WebAccessibility::ROLE_TABLE, table.role); + ASSERT_GE(table.children.size(), 5U); + EXPECT_EQ(WebAccessibility::ROLE_ROW, table.children[0].role); + EXPECT_EQ(WebAccessibility::ROLE_ROW, table.children[1].role); + EXPECT_EQ(WebAccessibility::ROLE_COLUMN, table.children[2].role); + EXPECT_EQ(WebAccessibility::ROLE_COLUMN, table.children[3].role); + EXPECT_EQ(WebAccessibility::ROLE_COLUMN, table.children[4].role); + EXPECT_EQ(3, GetIntAttr(table, WebAccessibility::ATTR_TABLE_COLUMN_COUNT)); + EXPECT_EQ(2, GetIntAttr(table, WebAccessibility::ATTR_TABLE_ROW_COUNT)); + + const WebAccessibility& cell1 = table.children[0].children[0]; + const WebAccessibility& cell2 = table.children[0].children[1]; + const WebAccessibility& cell3 = table.children[1].children[0]; + const WebAccessibility& cell4 = table.children[1].children[1]; + + ASSERT_EQ(6U, table.cell_ids.size()); + EXPECT_EQ(cell1.id, table.cell_ids[0]); + EXPECT_EQ(cell1.id, table.cell_ids[1]); + EXPECT_EQ(cell2.id, table.cell_ids[2]); + EXPECT_EQ(cell3.id, table.cell_ids[3]); + EXPECT_EQ(cell4.id, table.cell_ids[4]); + EXPECT_EQ(cell4.id, table.cell_ids[5]); + + EXPECT_EQ(0, GetIntAttr(cell1, + WebAccessibility::ATTR_TABLE_CELL_COLUMN_INDEX)); + EXPECT_EQ(0, GetIntAttr(cell1, + WebAccessibility::ATTR_TABLE_CELL_ROW_INDEX)); + EXPECT_EQ(2, GetIntAttr(cell1, + WebAccessibility::ATTR_TABLE_CELL_COLUMN_SPAN)); + EXPECT_EQ(1, GetIntAttr(cell1, + WebAccessibility::ATTR_TABLE_CELL_ROW_SPAN)); + EXPECT_EQ(2, GetIntAttr(cell2, + WebAccessibility::ATTR_TABLE_CELL_COLUMN_INDEX)); + EXPECT_EQ(1, GetIntAttr(cell2, + WebAccessibility::ATTR_TABLE_CELL_COLUMN_SPAN)); + EXPECT_EQ(0, GetIntAttr(cell3, + WebAccessibility::ATTR_TABLE_CELL_COLUMN_INDEX)); + EXPECT_EQ(1, GetIntAttr(cell3, + WebAccessibility::ATTR_TABLE_CELL_COLUMN_SPAN)); + EXPECT_EQ(1, GetIntAttr(cell4, + WebAccessibility::ATTR_TABLE_CELL_COLUMN_INDEX)); + EXPECT_EQ(2, GetIntAttr(cell4, + WebAccessibility::ATTR_TABLE_CELL_COLUMN_SPAN)); +} + } // namespace |