| OLD | NEW |
| 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 Loading... |
| 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<AXObject>> object_attributes; |
| 242 std::map<AXObjectVectorAttribute, HeapVector<Member<AXObject>>> |
| 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 AXObject& value) override { |
| 259 ASSERT_TRUE(object_attributes.find(attribute) == object_attributes.end()); |
| 260 object_attributes[attribute] = value; |
| 261 } |
| 262 |
| 263 void AddObjectVectorAttribute(AXObjectVectorAttribute attribute, |
| 264 HeapVector<Member<AXObject>>& value) override { |
| 265 ASSERT_TRUE(object_vector_attributes.find(attribute) == |
| 266 object_vector_attributes.end()); |
| 267 object_vector_attributes[attribute] = value; |
| 268 } |
| 269 }; |
| 270 |
| 271 TEST_F(AccessibilityObjectModelTest, SparseAttributes) { |
| 272 SimRequest main_resource("https://example.com/", "text/html"); |
| 273 LoadURL("https://example.com/"); |
| 274 main_resource.Complete( |
| 275 "<input id=target" |
| 276 " aria-keyshortcuts=Ctrl+K" |
| 277 " aria-roledescription=Widget" |
| 278 " aria-activedescendant=active" |
| 279 " aria-details=details" |
| 280 " aria-errormessage=error>" |
| 281 "<div id=active role=option></div>" |
| 282 "<div id=active2 role=gridcell></div>" |
| 283 "<div id=details role=contentinfo></div>" |
| 284 "<div id=details2 role=form></div>" |
| 285 "<div id=error role=article>Error</div>" |
| 286 "<div id=error2 role=banner>Error 2</div>"); |
| 287 |
| 288 auto* target = GetDocument().getElementById("target"); |
| 289 auto* cache = AXObjectCache(); |
| 290 ASSERT_NE(nullptr, cache); |
| 291 auto* ax_target = cache->GetOrCreate(target); |
| 292 SparseAttributeAdapter sparse_attributes; |
| 293 ax_target->GetSparseAXAttributes(sparse_attributes); |
| 294 |
| 295 ASSERT_EQ("Ctrl+K", |
| 296 sparse_attributes |
| 297 .string_attributes[AXStringAttribute::kAriaKeyShortcuts]); |
| 298 ASSERT_EQ("Widget", |
| 299 sparse_attributes |
| 300 .string_attributes[AXStringAttribute::kAriaRoleDescription]); |
| 301 ASSERT_EQ(kListBoxOptionRole, |
| 302 sparse_attributes |
| 303 .object_attributes[AXObjectAttribute::kAriaActiveDescendant] |
| 304 ->RoleValue()); |
| 305 ASSERT_EQ( |
| 306 kContentInfoRole, |
| 307 sparse_attributes.object_attributes[AXObjectAttribute::kAriaDetails] |
| 308 ->RoleValue()); |
| 309 ASSERT_EQ( |
| 310 kArticleRole, |
| 311 sparse_attributes.object_attributes[AXObjectAttribute::kAriaErrorMessage] |
| 312 ->RoleValue()); |
| 313 |
| 314 target->accessibleNode()->setKeyShortcuts("Ctrl+L"); |
| 315 target->accessibleNode()->setRoleDescription("Object"); |
| 316 target->accessibleNode()->setActiveDescendant( |
| 317 GetDocument().getElementById("active2")->accessibleNode()); |
| 318 target->accessibleNode()->setDetails( |
| 319 GetDocument().getElementById("details2")->accessibleNode()); |
| 320 target->accessibleNode()->setErrorMessage( |
| 321 GetDocument().getElementById("error2")->accessibleNode()); |
| 322 |
| 323 SparseAttributeAdapter sparse_attributes2; |
| 324 ax_target->GetSparseAXAttributes(sparse_attributes2); |
| 325 |
| 326 ASSERT_EQ("Ctrl+L", |
| 327 sparse_attributes2 |
| 328 .string_attributes[AXStringAttribute::kAriaKeyShortcuts]); |
| 329 ASSERT_EQ("Object", |
| 330 sparse_attributes2 |
| 331 .string_attributes[AXStringAttribute::kAriaRoleDescription]); |
| 332 ASSERT_EQ(kCellRole, |
| 333 sparse_attributes2 |
| 334 .object_attributes[AXObjectAttribute::kAriaActiveDescendant] |
| 335 ->RoleValue()); |
| 336 ASSERT_EQ(kFormRole, sparse_attributes2 |
| 337 .object_attributes[AXObjectAttribute::kAriaDetails] |
| 338 ->RoleValue()); |
| 339 ASSERT_EQ(kBannerRole, |
| 340 sparse_attributes2 |
| 341 .object_attributes[AXObjectAttribute::kAriaErrorMessage] |
| 342 ->RoleValue()); |
| 343 } |
| 344 |
| 235 } // namespace | 345 } // namespace |
| 236 | 346 |
| 237 } // namespace blink | 347 } // namespace blink |
| OLD | NEW |