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

Side by Side Diff: content/browser/accessibility/cross_platform_accessibility_browsertest.cc

Issue 10544099: Refactor all accessibility code out of webkit/glue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More Mac compile errors Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/test/base/in_process_browser_test.h" 10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h" 11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/browser/renderer_host/render_view_host_impl.h" 12 #include "content/browser/renderer_host/render_view_host_impl.h"
13 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/notification_types.h" 14 #include "content/public/browser/notification_types.h"
15 #include "content/public/browser/render_widget_host_view.h" 15 #include "content/public/browser/render_widget_host_view.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 17
18 #if defined(OS_WIN) 18 #if defined(OS_WIN)
19 #include <atlbase.h> 19 #include <atlbase.h>
20 #include <atlcom.h> 20 #include <atlcom.h>
21 #include "ui/base/win/atl_module.h" 21 #include "ui/base/win/atl_module.h"
22 #endif 22 #endif
23 23
24 using content::AccessibilityNodeData;
24 using content::OpenURLParams; 25 using content::OpenURLParams;
25 using content::RenderViewHostImpl; 26 using content::RenderViewHostImpl;
26 using content::RenderWidgetHostImpl; 27 using content::RenderWidgetHostImpl;
27 using content::Referrer; 28 using content::Referrer;
28 using webkit_glue::WebAccessibility;
29 29
30 namespace { 30 namespace {
31 31
32 class CrossPlatformAccessibilityBrowserTest : public InProcessBrowserTest { 32 class CrossPlatformAccessibilityBrowserTest : public InProcessBrowserTest {
33 public: 33 public:
34 CrossPlatformAccessibilityBrowserTest() {} 34 CrossPlatformAccessibilityBrowserTest() {}
35 35
36 // Tell the renderer to send an accessibility tree, then wait for the 36 // Tell the renderer to send an accessibility tree, then wait for the
37 // notification that it's been received. 37 // notification that it's been received.
38 const WebAccessibility& GetWebAccessibilityTree( 38 const AccessibilityNodeData& GetAccessibilityNodeDataTree(
39 AccessibilityMode accessibility_mode = AccessibilityModeComplete) { 39 AccessibilityMode accessibility_mode = AccessibilityModeComplete) {
40 ui_test_utils::WindowedNotificationObserver tree_updated_observer( 40 ui_test_utils::WindowedNotificationObserver tree_updated_observer(
41 content::NOTIFICATION_RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED, 41 content::NOTIFICATION_RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED,
42 content::NotificationService::AllSources()); 42 content::NotificationService::AllSources());
43 content::RenderWidgetHostView* host_view = 43 content::RenderWidgetHostView* host_view =
44 browser()->GetSelectedWebContents()->GetRenderWidgetHostView(); 44 browser()->GetSelectedWebContents()->GetRenderWidgetHostView();
45 RenderWidgetHostImpl* host = 45 RenderWidgetHostImpl* host =
46 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost()); 46 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost());
47 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>(host); 47 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>(host);
48 view_host->set_save_accessibility_tree_for_testing(true); 48 view_host->set_save_accessibility_tree_for_testing(true);
49 view_host->SetAccessibilityMode(accessibility_mode); 49 view_host->SetAccessibilityMode(accessibility_mode);
50 tree_updated_observer.Wait(); 50 tree_updated_observer.Wait();
51 return view_host->accessibility_tree_for_testing(); 51 return view_host->accessibility_tree_for_testing();
52 } 52 }
53 53
54 // Make sure each node in the tree has an unique id. 54 // Make sure each node in the tree has an unique id.
55 void RecursiveAssertUniqueIds( 55 void RecursiveAssertUniqueIds(
56 const WebAccessibility& node, base::hash_set<int>* ids) { 56 const AccessibilityNodeData& node, base::hash_set<int>* ids) {
57 ASSERT_TRUE(ids->find(node.id) == ids->end()); 57 ASSERT_TRUE(ids->find(node.id) == ids->end());
58 ids->insert(node.id); 58 ids->insert(node.id);
59 for (size_t i = 0; i < node.children.size(); i++) 59 for (size_t i = 0; i < node.children.size(); i++)
60 RecursiveAssertUniqueIds(node.children[i], ids); 60 RecursiveAssertUniqueIds(node.children[i], ids);
61 } 61 }
62 62
63 // InProcessBrowserTest 63 // InProcessBrowserTest
64 void SetUpInProcessBrowserTestFixture(); 64 void SetUpInProcessBrowserTestFixture();
65 void TearDownInProcessBrowserTestFixture(); 65 void TearDownInProcessBrowserTestFixture();
66 66
67 protected: 67 protected:
68 std::string GetAttr(const WebAccessibility& node, 68 std::string GetAttr(const AccessibilityNodeData& node,
69 const WebAccessibility::StringAttribute attr); 69 const AccessibilityNodeData::StringAttribute attr);
70 int GetIntAttr(const WebAccessibility& node, 70 int GetIntAttr(const AccessibilityNodeData& node,
71 const WebAccessibility::IntAttribute attr); 71 const AccessibilityNodeData::IntAttribute attr);
72 bool GetBoolAttr(const WebAccessibility& node, 72 bool GetBoolAttr(const AccessibilityNodeData& node,
73 const WebAccessibility::BoolAttribute attr); 73 const AccessibilityNodeData::BoolAttribute attr);
74 }; 74 };
75 75
76 void CrossPlatformAccessibilityBrowserTest::SetUpInProcessBrowserTestFixture() { 76 void CrossPlatformAccessibilityBrowserTest::SetUpInProcessBrowserTestFixture() {
77 #if defined(OS_WIN) 77 #if defined(OS_WIN)
78 ui::win::CreateATLModuleIfNeeded(); 78 ui::win::CreateATLModuleIfNeeded();
79 ::CoInitialize(NULL); 79 ::CoInitialize(NULL);
80 #endif 80 #endif
81 } 81 }
82 82
83 void 83 void
84 CrossPlatformAccessibilityBrowserTest::TearDownInProcessBrowserTestFixture() { 84 CrossPlatformAccessibilityBrowserTest::TearDownInProcessBrowserTestFixture() {
85 #if defined(OS_WIN) 85 #if defined(OS_WIN)
86 ::CoUninitialize(); 86 ::CoUninitialize();
87 #endif 87 #endif
88 } 88 }
89 89
90 // Convenience method to get the value of a particular WebAccessibility 90 // Convenience method to get the value of a particular AccessibilityNodeData
91 // node attribute as a UTF-8 const char*. 91 // node attribute as a UTF-8 const char*.
92 std::string CrossPlatformAccessibilityBrowserTest::GetAttr( 92 std::string CrossPlatformAccessibilityBrowserTest::GetAttr(
93 const WebAccessibility& node, 93 const AccessibilityNodeData& node,
94 const WebAccessibility::StringAttribute attr) { 94 const AccessibilityNodeData::StringAttribute attr) {
95 std::map<WebAccessibility::StringAttribute, string16>::const_iterator iter = 95 std::map<AccessibilityNodeData::StringAttribute, string16>::const_iterator
96 node.string_attributes.find(attr); 96 iter = node.string_attributes.find(attr);
97 if (iter != node.string_attributes.end()) 97 if (iter != node.string_attributes.end())
98 return UTF16ToUTF8(iter->second); 98 return UTF16ToUTF8(iter->second);
99 else 99 else
100 return ""; 100 return "";
101 } 101 }
102 102
103 // Convenience method to get the value of a particular WebAccessibility 103 // Convenience method to get the value of a particular AccessibilityNodeData
104 // node integer attribute. 104 // node integer attribute.
105 int CrossPlatformAccessibilityBrowserTest::GetIntAttr( 105 int CrossPlatformAccessibilityBrowserTest::GetIntAttr(
106 const WebAccessibility& node, 106 const AccessibilityNodeData& node,
107 const WebAccessibility::IntAttribute attr) { 107 const AccessibilityNodeData::IntAttribute attr) {
108 std::map<WebAccessibility::IntAttribute, int32>::const_iterator iter = 108 std::map<AccessibilityNodeData::IntAttribute, int32>::const_iterator iter =
109 node.int_attributes.find(attr); 109 node.int_attributes.find(attr);
110 if (iter != node.int_attributes.end()) 110 if (iter != node.int_attributes.end())
111 return iter->second; 111 return iter->second;
112 else 112 else
113 return -1; 113 return -1;
114 } 114 }
115 115
116 // Convenience method to get the value of a particular WebAccessibility 116 // Convenience method to get the value of a particular AccessibilityNodeData
117 // node boolean attribute. 117 // node boolean attribute.
118 bool CrossPlatformAccessibilityBrowserTest::GetBoolAttr( 118 bool CrossPlatformAccessibilityBrowserTest::GetBoolAttr(
119 const WebAccessibility& node, 119 const AccessibilityNodeData& node,
120 const WebAccessibility::BoolAttribute attr) { 120 const AccessibilityNodeData::BoolAttribute attr) {
121 std::map<WebAccessibility::BoolAttribute, bool>::const_iterator iter = 121 std::map<AccessibilityNodeData::BoolAttribute, bool>::const_iterator iter =
122 node.bool_attributes.find(attr); 122 node.bool_attributes.find(attr);
123 if (iter != node.bool_attributes.end()) 123 if (iter != node.bool_attributes.end())
124 return iter->second; 124 return iter->second;
125 else 125 else
126 return false; 126 return false;
127 } 127 }
128 128
129 // Marked flaky per http://crbug.com/101984 129 // Marked flaky per http://crbug.com/101984
130 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, 130 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
131 DISABLED_WebpageAccessibility) { 131 DISABLED_WebpageAccessibility) {
132 // Create a data url and load it. 132 // Create a data url and load it.
133 const char url_str[] = 133 const char url_str[] =
134 "data:text/html," 134 "data:text/html,"
135 "<!doctype html>" 135 "<!doctype html>"
136 "<html><head><title>Accessibility Test</title></head>" 136 "<html><head><title>Accessibility Test</title></head>"
137 "<body><input type='button' value='push' /><input type='checkbox' />" 137 "<body><input type='button' value='push' /><input type='checkbox' />"
138 "</body></html>"; 138 "</body></html>";
139 GURL url(url_str); 139 GURL url(url_str);
140 browser()->OpenURL(OpenURLParams( 140 browser()->OpenURL(OpenURLParams(
141 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 141 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
142 const WebAccessibility& tree = GetWebAccessibilityTree(); 142 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree();
143 143
144 // Check properties of the root element of the tree. 144 // Check properties of the root element of the tree.
145 EXPECT_STREQ(url_str, GetAttr(tree, WebAccessibility::ATTR_DOC_URL).c_str()); 145 EXPECT_STREQ(url_str,
146 GetAttr(tree, AccessibilityNodeData::ATTR_DOC_URL).c_str());
146 EXPECT_STREQ( 147 EXPECT_STREQ(
147 "Accessibility Test", 148 "Accessibility Test",
148 GetAttr(tree, WebAccessibility::ATTR_DOC_TITLE).c_str()); 149 GetAttr(tree, AccessibilityNodeData::ATTR_DOC_TITLE).c_str());
149 EXPECT_STREQ( 150 EXPECT_STREQ(
150 "html", GetAttr(tree, WebAccessibility::ATTR_DOC_DOCTYPE).c_str()); 151 "html", GetAttr(tree, AccessibilityNodeData::ATTR_DOC_DOCTYPE).c_str());
151 EXPECT_STREQ( 152 EXPECT_STREQ(
152 "text/html", GetAttr(tree, WebAccessibility::ATTR_DOC_MIMETYPE).c_str()); 153 "text/html",
154 GetAttr(tree, AccessibilityNodeData::ATTR_DOC_MIMETYPE).c_str());
153 EXPECT_STREQ("Accessibility Test", UTF16ToUTF8(tree.name).c_str()); 155 EXPECT_STREQ("Accessibility Test", UTF16ToUTF8(tree.name).c_str());
154 EXPECT_EQ(WebAccessibility::ROLE_ROOT_WEB_AREA, tree.role); 156 EXPECT_EQ(AccessibilityNodeData::ROLE_ROOT_WEB_AREA, tree.role);
155 157
156 // Check properites of the BODY element. 158 // Check properites of the BODY element.
157 ASSERT_EQ(1U, tree.children.size()); 159 ASSERT_EQ(1U, tree.children.size());
158 const WebAccessibility& body = tree.children[0]; 160 const AccessibilityNodeData& body = tree.children[0];
159 EXPECT_EQ(WebAccessibility::ROLE_GROUP, body.role); 161 EXPECT_EQ(AccessibilityNodeData::ROLE_GROUP, body.role);
160 EXPECT_STREQ("body", GetAttr(body, WebAccessibility::ATTR_HTML_TAG).c_str()); 162 EXPECT_STREQ("body",
161 EXPECT_STREQ("block", GetAttr(body, WebAccessibility::ATTR_DISPLAY).c_str()); 163 GetAttr(body, AccessibilityNodeData::ATTR_HTML_TAG).c_str());
164 EXPECT_STREQ("block",
165 GetAttr(body, AccessibilityNodeData::ATTR_DISPLAY).c_str());
162 166
163 // Check properties of the two children of the BODY element. 167 // Check properties of the two children of the BODY element.
164 ASSERT_EQ(2U, body.children.size()); 168 ASSERT_EQ(2U, body.children.size());
165 169
166 const WebAccessibility& button = body.children[0]; 170 const AccessibilityNodeData& button = body.children[0];
167 EXPECT_EQ(WebAccessibility::ROLE_BUTTON, button.role); 171 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, button.role);
168 EXPECT_STREQ( 172 EXPECT_STREQ(
169 "input", GetAttr(button, WebAccessibility::ATTR_HTML_TAG).c_str()); 173 "input", GetAttr(button, AccessibilityNodeData::ATTR_HTML_TAG).c_str());
170 EXPECT_STREQ("push", UTF16ToUTF8(button.name).c_str()); 174 EXPECT_STREQ("push", UTF16ToUTF8(button.name).c_str());
171 EXPECT_STREQ( 175 EXPECT_STREQ(
172 "inline-block", GetAttr(button, WebAccessibility::ATTR_DISPLAY).c_str()); 176 "inline-block",
177 GetAttr(button, AccessibilityNodeData::ATTR_DISPLAY).c_str());
173 ASSERT_EQ(2U, button.html_attributes.size()); 178 ASSERT_EQ(2U, button.html_attributes.size());
174 EXPECT_STREQ("type", UTF16ToUTF8(button.html_attributes[0].first).c_str()); 179 EXPECT_STREQ("type", UTF16ToUTF8(button.html_attributes[0].first).c_str());
175 EXPECT_STREQ("button", UTF16ToUTF8(button.html_attributes[0].second).c_str()); 180 EXPECT_STREQ("button", UTF16ToUTF8(button.html_attributes[0].second).c_str());
176 EXPECT_STREQ("value", UTF16ToUTF8(button.html_attributes[1].first).c_str()); 181 EXPECT_STREQ("value", UTF16ToUTF8(button.html_attributes[1].first).c_str());
177 EXPECT_STREQ("push", UTF16ToUTF8(button.html_attributes[1].second).c_str()); 182 EXPECT_STREQ("push", UTF16ToUTF8(button.html_attributes[1].second).c_str());
178 183
179 const WebAccessibility& checkbox = body.children[1]; 184 const AccessibilityNodeData& checkbox = body.children[1];
180 EXPECT_EQ(WebAccessibility::ROLE_CHECKBOX, checkbox.role); 185 EXPECT_EQ(AccessibilityNodeData::ROLE_CHECKBOX, checkbox.role);
181 EXPECT_STREQ( 186 EXPECT_STREQ(
182 "input", GetAttr(checkbox, WebAccessibility::ATTR_HTML_TAG).c_str()); 187 "input", GetAttr(checkbox, AccessibilityNodeData::ATTR_HTML_TAG).c_str());
183 EXPECT_STREQ( 188 EXPECT_STREQ(
184 "inline-block", 189 "inline-block",
185 GetAttr(checkbox, WebAccessibility::ATTR_DISPLAY).c_str()); 190 GetAttr(checkbox, AccessibilityNodeData::ATTR_DISPLAY).c_str());
186 ASSERT_EQ(1U, checkbox.html_attributes.size()); 191 ASSERT_EQ(1U, checkbox.html_attributes.size());
187 EXPECT_STREQ( 192 EXPECT_STREQ(
188 "type", UTF16ToUTF8(checkbox.html_attributes[0].first).c_str()); 193 "type", UTF16ToUTF8(checkbox.html_attributes[0].first).c_str());
189 EXPECT_STREQ( 194 EXPECT_STREQ(
190 "checkbox", UTF16ToUTF8(checkbox.html_attributes[0].second).c_str()); 195 "checkbox", UTF16ToUTF8(checkbox.html_attributes[0].second).c_str());
191 } 196 }
192 197
193 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, 198 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
194 UnselectedEditableTextAccessibility) { 199 UnselectedEditableTextAccessibility) {
195 // Create a data url and load it. 200 // Create a data url and load it.
196 const char url_str[] = 201 const char url_str[] =
197 "data:text/html," 202 "data:text/html,"
198 "<!doctype html>" 203 "<!doctype html>"
199 "<body>" 204 "<body>"
200 "<input value=\"Hello, world.\"/>" 205 "<input value=\"Hello, world.\"/>"
201 "</body></html>"; 206 "</body></html>";
202 GURL url(url_str); 207 GURL url(url_str);
203 browser()->OpenURL(OpenURLParams( 208 browser()->OpenURL(OpenURLParams(
204 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 209 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
205 210
206 const WebAccessibility& tree = GetWebAccessibilityTree(); 211 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree();
207 ASSERT_EQ(1U, tree.children.size()); 212 ASSERT_EQ(1U, tree.children.size());
208 const WebAccessibility& body = tree.children[0]; 213 const AccessibilityNodeData& body = tree.children[0];
209 ASSERT_EQ(1U, body.children.size()); 214 ASSERT_EQ(1U, body.children.size());
210 const WebAccessibility& text = body.children[0]; 215 const AccessibilityNodeData& text = body.children[0];
211 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text.role); 216 EXPECT_EQ(AccessibilityNodeData::ROLE_TEXT_FIELD, text.role);
212 EXPECT_STREQ( 217 EXPECT_STREQ(
213 "input", GetAttr(text, WebAccessibility::ATTR_HTML_TAG).c_str()); 218 "input", GetAttr(text, AccessibilityNodeData::ATTR_HTML_TAG).c_str());
214 EXPECT_EQ(0, GetIntAttr(text, WebAccessibility::ATTR_TEXT_SEL_START)); 219 EXPECT_EQ(0, GetIntAttr(text, AccessibilityNodeData::ATTR_TEXT_SEL_START));
215 EXPECT_EQ(0, GetIntAttr(text, WebAccessibility::ATTR_TEXT_SEL_END)); 220 EXPECT_EQ(0, GetIntAttr(text, AccessibilityNodeData::ATTR_TEXT_SEL_END));
216 EXPECT_STREQ("Hello, world.", UTF16ToUTF8(text.value).c_str()); 221 EXPECT_STREQ("Hello, world.", UTF16ToUTF8(text.value).c_str());
217 222
218 // TODO(dmazzoni): as soon as more accessibility code is cross-platform, 223 // TODO(dmazzoni): as soon as more accessibility code is cross-platform,
219 // this code should test that the accessible info is dynamically updated 224 // this code should test that the accessible info is dynamically updated
220 // if the selection or value changes. 225 // if the selection or value changes.
221 } 226 }
222 227
223 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, 228 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
224 SelectedEditableTextAccessibility) { 229 SelectedEditableTextAccessibility) {
225 // Create a data url and load it. 230 // Create a data url and load it.
226 const char url_str[] = 231 const char url_str[] =
227 "data:text/html," 232 "data:text/html,"
228 "<!doctype html>" 233 "<!doctype html>"
229 "<body onload=\"document.body.children[0].select();\">" 234 "<body onload=\"document.body.children[0].select();\">"
230 "<input value=\"Hello, world.\"/>" 235 "<input value=\"Hello, world.\"/>"
231 "</body></html>"; 236 "</body></html>";
232 GURL url(url_str); 237 GURL url(url_str);
233 browser()->OpenURL(OpenURLParams( 238 browser()->OpenURL(OpenURLParams(
234 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 239 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
235 240
236 const WebAccessibility& tree = GetWebAccessibilityTree(); 241 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree();
237 ASSERT_EQ(1U, tree.children.size()); 242 ASSERT_EQ(1U, tree.children.size());
238 const WebAccessibility& body = tree.children[0]; 243 const AccessibilityNodeData& body = tree.children[0];
239 ASSERT_EQ(1U, body.children.size()); 244 ASSERT_EQ(1U, body.children.size());
240 const WebAccessibility& text = body.children[0]; 245 const AccessibilityNodeData& text = body.children[0];
241 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text.role); 246 EXPECT_EQ(AccessibilityNodeData::ROLE_TEXT_FIELD, text.role);
242 EXPECT_STREQ( 247 EXPECT_STREQ(
243 "input", GetAttr(text, WebAccessibility::ATTR_HTML_TAG).c_str()); 248 "input", GetAttr(text, AccessibilityNodeData::ATTR_HTML_TAG).c_str());
244 EXPECT_EQ(0, GetIntAttr(text, WebAccessibility::ATTR_TEXT_SEL_START)); 249 EXPECT_EQ(0, GetIntAttr(text, AccessibilityNodeData::ATTR_TEXT_SEL_START));
245 EXPECT_EQ(13, GetIntAttr(text, WebAccessibility::ATTR_TEXT_SEL_END)); 250 EXPECT_EQ(13, GetIntAttr(text, AccessibilityNodeData::ATTR_TEXT_SEL_END));
246 EXPECT_STREQ("Hello, world.", UTF16ToUTF8(text.value).c_str()); 251 EXPECT_STREQ("Hello, world.", UTF16ToUTF8(text.value).c_str());
247 } 252 }
248 253
249 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, 254 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
250 MultipleInheritanceAccessibility) { 255 MultipleInheritanceAccessibility) {
251 // In a WebKit accessibility render tree for a table, each cell is a 256 // In a WebKit accessibility render tree for a table, each cell is a
252 // child of both a row and a column, so it appears to use multiple 257 // child of both a row and a column, so it appears to use multiple
253 // inheritance. Make sure that the WebAccessibilityObject tree only 258 // inheritance. Make sure that the AccessibilityNodeDataObject tree only
254 // keeps one copy of each cell, and uses an indirect child id for the 259 // keeps one copy of each cell, and uses an indirect child id for the
255 // additional reference to it. 260 // additional reference to it.
256 const char url_str[] = 261 const char url_str[] =
257 "data:text/html," 262 "data:text/html,"
258 "<!doctype html>" 263 "<!doctype html>"
259 "<table border=1><tr><td>1</td><td>2</td></tr></table>"; 264 "<table border=1><tr><td>1</td><td>2</td></tr></table>";
260 GURL url(url_str); 265 GURL url(url_str);
261 browser()->OpenURL(OpenURLParams( 266 browser()->OpenURL(OpenURLParams(
262 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 267 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
263 268
264 const WebAccessibility& tree = GetWebAccessibilityTree(); 269 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree();
265 ASSERT_EQ(1U, tree.children.size()); 270 ASSERT_EQ(1U, tree.children.size());
266 const WebAccessibility& table = tree.children[0]; 271 const AccessibilityNodeData& table = tree.children[0];
267 EXPECT_EQ(WebAccessibility::ROLE_TABLE, table.role); 272 EXPECT_EQ(AccessibilityNodeData::ROLE_TABLE, table.role);
268 const WebAccessibility& row = table.children[0]; 273 const AccessibilityNodeData& row = table.children[0];
269 EXPECT_EQ(WebAccessibility::ROLE_ROW, row.role); 274 EXPECT_EQ(AccessibilityNodeData::ROLE_ROW, row.role);
270 const WebAccessibility& cell1 = row.children[0]; 275 const AccessibilityNodeData& cell1 = row.children[0];
271 EXPECT_EQ(WebAccessibility::ROLE_CELL, cell1.role); 276 EXPECT_EQ(AccessibilityNodeData::ROLE_CELL, cell1.role);
272 const WebAccessibility& cell2 = row.children[1]; 277 const AccessibilityNodeData& cell2 = row.children[1];
273 EXPECT_EQ(WebAccessibility::ROLE_CELL, cell2.role); 278 EXPECT_EQ(AccessibilityNodeData::ROLE_CELL, cell2.role);
274 const WebAccessibility& column1 = table.children[1]; 279 const AccessibilityNodeData& column1 = table.children[1];
275 EXPECT_EQ(WebAccessibility::ROLE_COLUMN, column1.role); 280 EXPECT_EQ(AccessibilityNodeData::ROLE_COLUMN, column1.role);
276 EXPECT_EQ(0U, column1.children.size()); 281 EXPECT_EQ(0U, column1.children.size());
277 EXPECT_EQ(1U, column1.indirect_child_ids.size()); 282 EXPECT_EQ(1U, column1.indirect_child_ids.size());
278 EXPECT_EQ(cell1.id, column1.indirect_child_ids[0]); 283 EXPECT_EQ(cell1.id, column1.indirect_child_ids[0]);
279 const WebAccessibility& column2 = table.children[2]; 284 const AccessibilityNodeData& column2 = table.children[2];
280 EXPECT_EQ(WebAccessibility::ROLE_COLUMN, column2.role); 285 EXPECT_EQ(AccessibilityNodeData::ROLE_COLUMN, column2.role);
281 EXPECT_EQ(0U, column2.children.size()); 286 EXPECT_EQ(0U, column2.children.size());
282 EXPECT_EQ(1U, column2.indirect_child_ids.size()); 287 EXPECT_EQ(1U, column2.indirect_child_ids.size());
283 EXPECT_EQ(cell2.id, column2.indirect_child_ids[0]); 288 EXPECT_EQ(cell2.id, column2.indirect_child_ids[0]);
284 } 289 }
285 290
286 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, 291 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
287 MultipleInheritanceAccessibility2) { 292 MultipleInheritanceAccessibility2) {
288 // Here's another html snippet where WebKit puts the same node as a child 293 // Here's another html snippet where WebKit puts the same node as a child
289 // of two different parents. Instead of checking the exact output, just 294 // of two different parents. Instead of checking the exact output, just
290 // make sure that no id is reused in the resulting tree. 295 // make sure that no id is reused in the resulting tree.
291 const char url_str[] = 296 const char url_str[] =
292 "data:text/html," 297 "data:text/html,"
293 "<!doctype html>" 298 "<!doctype html>"
294 "<script>\n" 299 "<script>\n"
295 " document.writeln('<q><section></section></q><q><li>');\n" 300 " document.writeln('<q><section></section></q><q><li>');\n"
296 " setTimeout(function() {\n" 301 " setTimeout(function() {\n"
297 " document.close();\n" 302 " document.close();\n"
298 " }, 1);\n" 303 " }, 1);\n"
299 "</script>"; 304 "</script>";
300 GURL url(url_str); 305 GURL url(url_str);
301 browser()->OpenURL(OpenURLParams( 306 browser()->OpenURL(OpenURLParams(
302 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 307 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
303 308
304 const WebAccessibility& tree = GetWebAccessibilityTree(); 309 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree();
305 base::hash_set<int> ids; 310 base::hash_set<int> ids;
306 RecursiveAssertUniqueIds(tree, &ids); 311 RecursiveAssertUniqueIds(tree, &ids);
307 } 312 }
308 313
309 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, 314 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
310 IframeAccessibility) { 315 IframeAccessibility) {
311 // Create a data url and load it. 316 // Create a data url and load it.
312 const char url_str[] = 317 const char url_str[] =
313 "data:text/html," 318 "data:text/html,"
314 "<!doctype html><html><body>" 319 "<!doctype html><html><body>"
315 "<button>Button 1</button>" 320 "<button>Button 1</button>"
316 "<iframe src='data:text/html," 321 "<iframe src='data:text/html,"
317 "<!doctype html><html><body><button>Button 2</button></body></html>" 322 "<!doctype html><html><body><button>Button 2</button></body></html>"
318 "'></iframe>" 323 "'></iframe>"
319 "<button>Button 3</button>" 324 "<button>Button 3</button>"
320 "</body></html>"; 325 "</body></html>";
321 GURL url(url_str); 326 GURL url(url_str);
322 browser()->OpenURL(OpenURLParams( 327 browser()->OpenURL(OpenURLParams(
323 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 328 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
324 329
325 const WebAccessibility& tree = GetWebAccessibilityTree(); 330 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree();
326 ASSERT_EQ(1U, tree.children.size()); 331 ASSERT_EQ(1U, tree.children.size());
327 const WebAccessibility& body = tree.children[0]; 332 const AccessibilityNodeData& body = tree.children[0];
328 ASSERT_EQ(3U, body.children.size()); 333 ASSERT_EQ(3U, body.children.size());
329 334
330 const WebAccessibility& button1 = body.children[0]; 335 const AccessibilityNodeData& button1 = body.children[0];
331 EXPECT_EQ(WebAccessibility::ROLE_BUTTON, button1.role); 336 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, button1.role);
332 EXPECT_STREQ("Button 1", UTF16ToUTF8(button1.name).c_str()); 337 EXPECT_STREQ("Button 1", UTF16ToUTF8(button1.name).c_str());
333 338
334 const WebAccessibility& iframe = body.children[1]; 339 const AccessibilityNodeData& iframe = body.children[1];
335 EXPECT_STREQ("iframe", 340 EXPECT_STREQ("iframe",
336 GetAttr(iframe, WebAccessibility::ATTR_HTML_TAG).c_str()); 341 GetAttr(iframe, AccessibilityNodeData::ATTR_HTML_TAG).c_str());
337 ASSERT_EQ(1U, iframe.children.size()); 342 ASSERT_EQ(1U, iframe.children.size());
338 343
339 const WebAccessibility& scroll_area = iframe.children[0]; 344 const AccessibilityNodeData& scroll_area = iframe.children[0];
340 EXPECT_EQ(WebAccessibility::ROLE_SCROLLAREA, scroll_area.role); 345 EXPECT_EQ(AccessibilityNodeData::ROLE_SCROLLAREA, scroll_area.role);
341 ASSERT_EQ(1U, scroll_area.children.size()); 346 ASSERT_EQ(1U, scroll_area.children.size());
342 347
343 const WebAccessibility& sub_document = scroll_area.children[0]; 348 const AccessibilityNodeData& sub_document = scroll_area.children[0];
344 EXPECT_EQ(WebAccessibility::ROLE_WEB_AREA, sub_document.role); 349 EXPECT_EQ(AccessibilityNodeData::ROLE_WEB_AREA, sub_document.role);
345 ASSERT_EQ(1U, sub_document.children.size()); 350 ASSERT_EQ(1U, sub_document.children.size());
346 351
347 const WebAccessibility& sub_body = sub_document.children[0]; 352 const AccessibilityNodeData& sub_body = sub_document.children[0];
348 ASSERT_EQ(1U, sub_body.children.size()); 353 ASSERT_EQ(1U, sub_body.children.size());
349 354
350 const WebAccessibility& button2 = sub_body.children[0]; 355 const AccessibilityNodeData& button2 = sub_body.children[0];
351 EXPECT_EQ(WebAccessibility::ROLE_BUTTON, button2.role); 356 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, button2.role);
352 EXPECT_STREQ("Button 2", UTF16ToUTF8(button2.name).c_str()); 357 EXPECT_STREQ("Button 2", UTF16ToUTF8(button2.name).c_str());
353 358
354 const WebAccessibility& button3 = body.children[2]; 359 const AccessibilityNodeData& button3 = body.children[2];
355 EXPECT_EQ(WebAccessibility::ROLE_BUTTON, button3.role); 360 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, button3.role);
356 EXPECT_STREQ("Button 3", UTF16ToUTF8(button3.name).c_str()); 361 EXPECT_STREQ("Button 3", UTF16ToUTF8(button3.name).c_str());
357 } 362 }
358 363
359 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, 364 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
360 DuplicateChildrenAccessibility) { 365 DuplicateChildrenAccessibility) {
361 // Here's another html snippet where WebKit has a parent node containing 366 // Here's another html snippet where WebKit has a parent node containing
362 // two duplicate child nodes. Instead of checking the exact output, just 367 // two duplicate child nodes. Instead of checking the exact output, just
363 // make sure that no id is reused in the resulting tree. 368 // make sure that no id is reused in the resulting tree.
364 const char url_str[] = 369 const char url_str[] =
365 "data:text/html," 370 "data:text/html,"
366 "<!doctype html>" 371 "<!doctype html>"
367 "<em><code ><h4 ></em>"; 372 "<em><code ><h4 ></em>";
368 GURL url(url_str); 373 GURL url(url_str);
369 browser()->OpenURL(OpenURLParams( 374 browser()->OpenURL(OpenURLParams(
370 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 375 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
371 376
372 const WebAccessibility& tree = GetWebAccessibilityTree(); 377 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree();
373 base::hash_set<int> ids; 378 base::hash_set<int> ids;
374 RecursiveAssertUniqueIds(tree, &ids); 379 RecursiveAssertUniqueIds(tree, &ids);
375 } 380 }
376 381
377 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, 382 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
378 TableSpan) { 383 TableSpan) {
379 // +---+---+---+ 384 // +---+---+---+
380 // | 1 | 2 | 385 // | 1 | 2 |
381 // +---+---+---+ 386 // +---+---+---+
382 // | 3 | 4 | 387 // | 3 | 4 |
383 // +---+---+---+ 388 // +---+---+---+
384 389
385 const char url_str[] = 390 const char url_str[] =
386 "data:text/html," 391 "data:text/html,"
387 "<!doctype html>" 392 "<!doctype html>"
388 "<table border=1>" 393 "<table border=1>"
389 " <tr>" 394 " <tr>"
390 " <td colspan=2>1</td><td>2</td>" 395 " <td colspan=2>1</td><td>2</td>"
391 " </tr>" 396 " </tr>"
392 " <tr>" 397 " <tr>"
393 " <td>3</td><td colspan=2>4</td>" 398 " <td>3</td><td colspan=2>4</td>"
394 " </tr>" 399 " </tr>"
395 "</table>"; 400 "</table>";
396 GURL url(url_str); 401 GURL url(url_str);
397 browser()->OpenURL(OpenURLParams( 402 browser()->OpenURL(OpenURLParams(
398 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 403 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
399 404
400 const WebAccessibility& tree = GetWebAccessibilityTree(); 405 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree();
401 const WebAccessibility& table = tree.children[0]; 406 const AccessibilityNodeData& table = tree.children[0];
402 EXPECT_EQ(WebAccessibility::ROLE_TABLE, table.role); 407 EXPECT_EQ(AccessibilityNodeData::ROLE_TABLE, table.role);
403 ASSERT_GE(table.children.size(), 5U); 408 ASSERT_GE(table.children.size(), 5U);
404 EXPECT_EQ(WebAccessibility::ROLE_ROW, table.children[0].role); 409 EXPECT_EQ(AccessibilityNodeData::ROLE_ROW, table.children[0].role);
405 EXPECT_EQ(WebAccessibility::ROLE_ROW, table.children[1].role); 410 EXPECT_EQ(AccessibilityNodeData::ROLE_ROW, table.children[1].role);
406 EXPECT_EQ(WebAccessibility::ROLE_COLUMN, table.children[2].role); 411 EXPECT_EQ(AccessibilityNodeData::ROLE_COLUMN, table.children[2].role);
407 EXPECT_EQ(WebAccessibility::ROLE_COLUMN, table.children[3].role); 412 EXPECT_EQ(AccessibilityNodeData::ROLE_COLUMN, table.children[3].role);
408 EXPECT_EQ(WebAccessibility::ROLE_COLUMN, table.children[4].role); 413 EXPECT_EQ(AccessibilityNodeData::ROLE_COLUMN, table.children[4].role);
409 EXPECT_EQ(3, GetIntAttr(table, WebAccessibility::ATTR_TABLE_COLUMN_COUNT)); 414 EXPECT_EQ(3,
410 EXPECT_EQ(2, GetIntAttr(table, WebAccessibility::ATTR_TABLE_ROW_COUNT)); 415 GetIntAttr(table, AccessibilityNodeData::ATTR_TABLE_COLUMN_COUNT));
416 EXPECT_EQ(2, GetIntAttr(table, AccessibilityNodeData::ATTR_TABLE_ROW_COUNT));
411 417
412 const WebAccessibility& cell1 = table.children[0].children[0]; 418 const AccessibilityNodeData& cell1 = table.children[0].children[0];
413 const WebAccessibility& cell2 = table.children[0].children[1]; 419 const AccessibilityNodeData& cell2 = table.children[0].children[1];
414 const WebAccessibility& cell3 = table.children[1].children[0]; 420 const AccessibilityNodeData& cell3 = table.children[1].children[0];
415 const WebAccessibility& cell4 = table.children[1].children[1]; 421 const AccessibilityNodeData& cell4 = table.children[1].children[1];
416 422
417 ASSERT_EQ(6U, table.cell_ids.size()); 423 ASSERT_EQ(6U, table.cell_ids.size());
418 EXPECT_EQ(cell1.id, table.cell_ids[0]); 424 EXPECT_EQ(cell1.id, table.cell_ids[0]);
419 EXPECT_EQ(cell1.id, table.cell_ids[1]); 425 EXPECT_EQ(cell1.id, table.cell_ids[1]);
420 EXPECT_EQ(cell2.id, table.cell_ids[2]); 426 EXPECT_EQ(cell2.id, table.cell_ids[2]);
421 EXPECT_EQ(cell3.id, table.cell_ids[3]); 427 EXPECT_EQ(cell3.id, table.cell_ids[3]);
422 EXPECT_EQ(cell4.id, table.cell_ids[4]); 428 EXPECT_EQ(cell4.id, table.cell_ids[4]);
423 EXPECT_EQ(cell4.id, table.cell_ids[5]); 429 EXPECT_EQ(cell4.id, table.cell_ids[5]);
424 430
425 EXPECT_EQ(0, GetIntAttr(cell1, 431 EXPECT_EQ(0, GetIntAttr(cell1,
426 WebAccessibility::ATTR_TABLE_CELL_COLUMN_INDEX)); 432 AccessibilityNodeData::ATTR_TABLE_CELL_COLUMN_INDEX));
427 EXPECT_EQ(0, GetIntAttr(cell1, 433 EXPECT_EQ(0, GetIntAttr(cell1,
428 WebAccessibility::ATTR_TABLE_CELL_ROW_INDEX)); 434 AccessibilityNodeData::ATTR_TABLE_CELL_ROW_INDEX));
429 EXPECT_EQ(2, GetIntAttr(cell1, 435 EXPECT_EQ(2, GetIntAttr(cell1,
430 WebAccessibility::ATTR_TABLE_CELL_COLUMN_SPAN)); 436 AccessibilityNodeData::ATTR_TABLE_CELL_COLUMN_SPAN));
431 EXPECT_EQ(1, GetIntAttr(cell1, 437 EXPECT_EQ(1, GetIntAttr(cell1,
432 WebAccessibility::ATTR_TABLE_CELL_ROW_SPAN)); 438 AccessibilityNodeData::ATTR_TABLE_CELL_ROW_SPAN));
433 EXPECT_EQ(2, GetIntAttr(cell2, 439 EXPECT_EQ(2, GetIntAttr(cell2,
434 WebAccessibility::ATTR_TABLE_CELL_COLUMN_INDEX)); 440 AccessibilityNodeData::ATTR_TABLE_CELL_COLUMN_INDEX));
435 EXPECT_EQ(1, GetIntAttr(cell2, 441 EXPECT_EQ(1, GetIntAttr(cell2,
436 WebAccessibility::ATTR_TABLE_CELL_COLUMN_SPAN)); 442 AccessibilityNodeData::ATTR_TABLE_CELL_COLUMN_SPAN));
437 EXPECT_EQ(0, GetIntAttr(cell3, 443 EXPECT_EQ(0, GetIntAttr(cell3,
438 WebAccessibility::ATTR_TABLE_CELL_COLUMN_INDEX)); 444 AccessibilityNodeData::ATTR_TABLE_CELL_COLUMN_INDEX));
439 EXPECT_EQ(1, GetIntAttr(cell3, 445 EXPECT_EQ(1, GetIntAttr(cell3,
440 WebAccessibility::ATTR_TABLE_CELL_COLUMN_SPAN)); 446 AccessibilityNodeData::ATTR_TABLE_CELL_COLUMN_SPAN));
441 EXPECT_EQ(1, GetIntAttr(cell4, 447 EXPECT_EQ(1, GetIntAttr(cell4,
442 WebAccessibility::ATTR_TABLE_CELL_COLUMN_INDEX)); 448 AccessibilityNodeData::ATTR_TABLE_CELL_COLUMN_INDEX));
443 EXPECT_EQ(2, GetIntAttr(cell4, 449 EXPECT_EQ(2, GetIntAttr(cell4,
444 WebAccessibility::ATTR_TABLE_CELL_COLUMN_SPAN)); 450 AccessibilityNodeData::ATTR_TABLE_CELL_COLUMN_SPAN));
445 } 451 }
446 452
447 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest, 453 IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
448 WritableElement) { 454 WritableElement) {
449 const char url_str[] = 455 const char url_str[] =
450 "data:text/html," 456 "data:text/html,"
451 "<!doctype html>" 457 "<!doctype html>"
452 "<div role='textbox' tabindex=0>" 458 "<div role='textbox' tabindex=0>"
453 " Some text" 459 " Some text"
454 "</div>"; 460 "</div>";
455 GURL url(url_str); 461 GURL url(url_str);
456 browser()->OpenURL(OpenURLParams( 462 browser()->OpenURL(OpenURLParams(
457 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 463 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
458 const WebAccessibility& tree = GetWebAccessibilityTree(); 464 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree();
459 465
460 ASSERT_EQ(1U, tree.children.size()); 466 ASSERT_EQ(1U, tree.children.size());
461 const WebAccessibility& textbox = tree.children[0]; 467 const AccessibilityNodeData& textbox = tree.children[0];
462 468
463 EXPECT_EQ( 469 EXPECT_EQ(
464 true, GetBoolAttr(textbox, WebAccessibility::ATTR_CAN_SET_VALUE)); 470 true, GetBoolAttr(textbox, AccessibilityNodeData::ATTR_CAN_SET_VALUE));
465 } 471 }
466 472
467 } // namespace 473 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698