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

Side by Side Diff: third_party/WebKit/Source/web/tests/AccessibilityObjectModelTest.cpp

Issue 2945773002: Relation properties for Accessibility Object Model phase 1 (Closed)
Patch Set: Add tests for details and error message too Created 3 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "core/dom/AccessibleNode.h" 5 #include "core/dom/AccessibleNode.h"
6 #include "core/html/HTMLBodyElement.h" 6 #include "core/html/HTMLBodyElement.h"
7 #include "core/testing/sim/SimRequest.h" 7 #include "core/testing/sim/SimRequest.h"
8 #include "core/testing/sim/SimTest.h" 8 #include "core/testing/sim/SimTest.h"
9 #include "modules/accessibility/AXObjectCacheImpl.h" 9 #include "modules/accessibility/AXObjectCacheImpl.h"
10 #include "modules/accessibility/AXTable.h" 10 #include "modules/accessibility/AXTable.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 EXPECT_TRUE(ax_cell->IsTableCell()); 225 EXPECT_TRUE(ax_cell->IsTableCell());
226 EXPECT_EQ(8U, ax_cell->AriaColumnIndex()); 226 EXPECT_EQ(8U, ax_cell->AriaColumnIndex());
227 EXPECT_EQ(5U, ax_cell->AriaRowIndex()); 227 EXPECT_EQ(5U, ax_cell->AriaRowIndex());
228 228
229 auto* ax_cell2 = static_cast<AXTableCell*>(cache->GetOrCreate(cell2)); 229 auto* ax_cell2 = static_cast<AXTableCell*>(cache->GetOrCreate(cell2));
230 EXPECT_TRUE(ax_cell2->IsTableCell()); 230 EXPECT_TRUE(ax_cell2->IsTableCell());
231 EXPECT_EQ(10U, ax_cell2->AriaColumnIndex()); 231 EXPECT_EQ(10U, ax_cell2->AriaColumnIndex());
232 EXPECT_EQ(7U, ax_cell2->AriaRowIndex()); 232 EXPECT_EQ(7U, ax_cell2->AriaRowIndex());
233 } 233 }
234 234
235 class SparseAttributeAdapter : public AXSparseAttributeClient {
236 public:
237 SparseAttributeAdapter() {}
238
239 std::map<AXBoolAttribute, bool> bool_attributes;
240 std::map<AXStringAttribute, String> string_attributes;
241 std::map<AXObjectAttribute, Persistent<AXObjectImpl>> object_attributes;
242 std::map<AXObjectVectorAttribute, HeapVector<Member<AXObjectImpl>>>
243 object_vector_attributes;
244
245 private:
246 void AddBoolAttribute(AXBoolAttribute attribute, bool value) override {
247 ASSERT_TRUE(bool_attributes.find(attribute) == bool_attributes.end());
248 bool_attributes[attribute] = value;
249 }
250
251 void AddStringAttribute(AXStringAttribute attribute,
252 const String& value) override {
253 ASSERT_TRUE(string_attributes.find(attribute) == string_attributes.end());
254 string_attributes[attribute] = value;
255 }
256
257 void AddObjectAttribute(AXObjectAttribute attribute,
258 AXObjectImpl& value) override {
259 ASSERT_TRUE(object_attributes.find(attribute) == object_attributes.end());
260 object_attributes[attribute] = value;
261 }
262
263 void AddObjectVectorAttribute(
264 AXObjectVectorAttribute attribute,
265 HeapVector<Member<AXObjectImpl>>& value) override {
266 ASSERT_TRUE(object_vector_attributes.find(attribute) ==
267 object_vector_attributes.end());
268 object_vector_attributes[attribute] = value;
269 }
270 };
271
272 TEST_F(AccessibilityObjectModelTest, SparseAttributes) {
273 SimRequest main_resource("https://example.com/", "text/html");
274 LoadURL("https://example.com/");
275 main_resource.Complete(
276 "<input id=target"
277 " aria-keyshortcuts=Ctrl+K"
278 " aria-roledescription=Widget"
279 " aria-activedescendant=active"
280 " aria-details=details"
281 " aria-errormessage=error>"
282 "<div id=active role=option></div>"
283 "<div id=active2 role=gridcell></div>"
284 "<div id=details role=contentinfo></div>"
285 "<div id=details2 role=form></div>"
286 "<div id=error role=article>Error</div>"
287 "<div id=error2 role=banner>Error 2</div>");
288
289 auto* target = GetDocument().getElementById("target");
290 auto* cache = AXObjectCache();
291 ASSERT_NE(nullptr, cache);
292 auto* ax_target = cache->GetOrCreate(target);
293 SparseAttributeAdapter sparse_attributes;
294 ax_target->GetSparseAXAttributes(sparse_attributes);
295
296 ASSERT_EQ("Ctrl+K",
297 sparse_attributes
298 .string_attributes[AXStringAttribute::kAriaKeyShortcuts]);
299 ASSERT_EQ("Widget",
300 sparse_attributes
301 .string_attributes[AXStringAttribute::kAriaRoleDescription]);
302 ASSERT_EQ(kListBoxOptionRole,
303 sparse_attributes
304 .object_attributes[AXObjectAttribute::kAriaActiveDescendant]
305 ->RoleValue());
306 ASSERT_EQ(
307 kContentInfoRole,
308 sparse_attributes.object_attributes[AXObjectAttribute::kAriaDetails]
309 ->RoleValue());
310 ASSERT_EQ(
311 kArticleRole,
312 sparse_attributes.object_attributes[AXObjectAttribute::kAriaErrorMessage]
313 ->RoleValue());
314
315 target->accessibleNode()->setKeyShortcuts("Ctrl+L");
316 target->accessibleNode()->setRoleDescription("Object");
317 target->accessibleNode()->setActiveDescendant(
318 GetDocument().getElementById("active2")->accessibleNode());
319 target->accessibleNode()->setDetails(
320 GetDocument().getElementById("details2")->accessibleNode());
321 target->accessibleNode()->setErrorMessage(
322 GetDocument().getElementById("error2")->accessibleNode());
323
324 SparseAttributeAdapter sparse_attributes2;
325 ax_target->GetSparseAXAttributes(sparse_attributes2);
326
327 ASSERT_EQ("Ctrl+L",
328 sparse_attributes2
329 .string_attributes[AXStringAttribute::kAriaKeyShortcuts]);
330 ASSERT_EQ("Object",
331 sparse_attributes2
332 .string_attributes[AXStringAttribute::kAriaRoleDescription]);
333 ASSERT_EQ(kCellRole,
334 sparse_attributes2
335 .object_attributes[AXObjectAttribute::kAriaActiveDescendant]
336 ->RoleValue());
337 ASSERT_EQ(kFormRole, sparse_attributes2
338 .object_attributes[AXObjectAttribute::kAriaDetails]
339 ->RoleValue());
340 ASSERT_EQ(kBannerRole,
341 sparse_attributes2
342 .object_attributes[AXObjectAttribute::kAriaErrorMessage]
343 ->RoleValue());
344 }
345
235 } // namespace 346 } // namespace
236 347
237 } // namespace blink 348 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698