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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/tests/AccessibilityObjectModelTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/AccessibilityObjectModelTest.cpp b/third_party/WebKit/Source/web/tests/AccessibilityObjectModelTest.cpp
index 69a91540114130dd147039b1ec860fdaa77cf5ac..61af0b27ca47d38033b948a54d1a42bb3d19e685 100644
--- a/third_party/WebKit/Source/web/tests/AccessibilityObjectModelTest.cpp
+++ b/third_party/WebKit/Source/web/tests/AccessibilityObjectModelTest.cpp
@@ -232,6 +232,117 @@ TEST_F(AccessibilityObjectModelTest, Grid) {
EXPECT_EQ(7U, ax_cell2->AriaRowIndex());
}
+class SparseAttributeAdapter : public AXSparseAttributeClient {
+ public:
+ SparseAttributeAdapter() {}
+
+ std::map<AXBoolAttribute, bool> bool_attributes;
+ std::map<AXStringAttribute, String> string_attributes;
+ std::map<AXObjectAttribute, Persistent<AXObjectImpl>> object_attributes;
+ std::map<AXObjectVectorAttribute, HeapVector<Member<AXObjectImpl>>>
+ object_vector_attributes;
+
+ private:
+ void AddBoolAttribute(AXBoolAttribute attribute, bool value) override {
+ ASSERT_TRUE(bool_attributes.find(attribute) == bool_attributes.end());
+ bool_attributes[attribute] = value;
+ }
+
+ void AddStringAttribute(AXStringAttribute attribute,
+ const String& value) override {
+ ASSERT_TRUE(string_attributes.find(attribute) == string_attributes.end());
+ string_attributes[attribute] = value;
+ }
+
+ void AddObjectAttribute(AXObjectAttribute attribute,
+ AXObjectImpl& value) override {
+ ASSERT_TRUE(object_attributes.find(attribute) == object_attributes.end());
+ object_attributes[attribute] = value;
+ }
+
+ void AddObjectVectorAttribute(
+ AXObjectVectorAttribute attribute,
+ HeapVector<Member<AXObjectImpl>>& value) override {
+ ASSERT_TRUE(object_vector_attributes.find(attribute) ==
+ object_vector_attributes.end());
+ object_vector_attributes[attribute] = value;
+ }
+};
+
+TEST_F(AccessibilityObjectModelTest, SparseAttributes) {
+ SimRequest main_resource("https://example.com/", "text/html");
+ LoadURL("https://example.com/");
+ main_resource.Complete(
+ "<input id=target"
+ " aria-keyshortcuts=Ctrl+K"
+ " aria-roledescription=Widget"
+ " aria-activedescendant=active"
+ " aria-details=details"
+ " aria-errormessage=error>"
+ "<div id=active role=option></div>"
+ "<div id=active2 role=gridcell></div>"
+ "<div id=details role=contentinfo></div>"
+ "<div id=details2 role=form></div>"
+ "<div id=error role=article>Error</div>"
+ "<div id=error2 role=banner>Error 2</div>");
+
+ auto* target = GetDocument().getElementById("target");
+ auto* cache = AXObjectCache();
+ ASSERT_NE(nullptr, cache);
+ auto* ax_target = cache->GetOrCreate(target);
+ SparseAttributeAdapter sparse_attributes;
+ ax_target->GetSparseAXAttributes(sparse_attributes);
+
+ ASSERT_EQ("Ctrl+K",
+ sparse_attributes
+ .string_attributes[AXStringAttribute::kAriaKeyShortcuts]);
+ ASSERT_EQ("Widget",
+ sparse_attributes
+ .string_attributes[AXStringAttribute::kAriaRoleDescription]);
+ ASSERT_EQ(kListBoxOptionRole,
+ sparse_attributes
+ .object_attributes[AXObjectAttribute::kAriaActiveDescendant]
+ ->RoleValue());
+ ASSERT_EQ(
+ kContentInfoRole,
+ sparse_attributes.object_attributes[AXObjectAttribute::kAriaDetails]
+ ->RoleValue());
+ ASSERT_EQ(
+ kArticleRole,
+ sparse_attributes.object_attributes[AXObjectAttribute::kAriaErrorMessage]
+ ->RoleValue());
+
+ target->accessibleNode()->setKeyShortcuts("Ctrl+L");
+ target->accessibleNode()->setRoleDescription("Object");
+ target->accessibleNode()->setActiveDescendant(
+ GetDocument().getElementById("active2")->accessibleNode());
+ target->accessibleNode()->setDetails(
+ GetDocument().getElementById("details2")->accessibleNode());
+ target->accessibleNode()->setErrorMessage(
+ GetDocument().getElementById("error2")->accessibleNode());
+
+ SparseAttributeAdapter sparse_attributes2;
+ ax_target->GetSparseAXAttributes(sparse_attributes2);
+
+ ASSERT_EQ("Ctrl+L",
+ sparse_attributes2
+ .string_attributes[AXStringAttribute::kAriaKeyShortcuts]);
+ ASSERT_EQ("Object",
+ sparse_attributes2
+ .string_attributes[AXStringAttribute::kAriaRoleDescription]);
+ ASSERT_EQ(kCellRole,
+ sparse_attributes2
+ .object_attributes[AXObjectAttribute::kAriaActiveDescendant]
+ ->RoleValue());
+ ASSERT_EQ(kFormRole, sparse_attributes2
+ .object_attributes[AXObjectAttribute::kAriaDetails]
+ ->RoleValue());
+ ASSERT_EQ(kBannerRole,
+ sparse_attributes2
+ .object_attributes[AXObjectAttribute::kAriaErrorMessage]
+ ->RoleValue());
+}
+
} // namespace
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698