Bug 1572519 - Log all element attributes in accessibility logging. r=Jamie
authorEitan Isaacson <eitan@monotonous.org>
Fri, 09 Aug 2019 00:02:51 +0000
changeset 550973 44677a227173f811473b8bc3079cd92566f88e97
parent 550972 f2f738d7b414c2338155c73fa46ac3c25b6aea1e
child 550974 4c86b78c1ce2ae3190678ecf7dcaafa4e989c84f
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1572519
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1572519 - Log all element attributes in accessibility logging. r=Jamie Differential Revision: https://phabricator.services.mozilla.com/D41265
accessible/base/Logging.cpp
--- a/accessible/base/Logging.cpp
+++ b/accessible/base/Logging.cpp
@@ -347,16 +347,75 @@ static void GetDocLoadEventType(AccEvent
       if (event->IsStateEnabled())
         aEventType.AppendLiteral("true");
       else
         aEventType.AppendLiteral("false");
     }
   }
 }
 
+static void DescribeNode(nsINode* aNode, nsAString& aOutDescription) {
+  if (!aNode) {
+    aOutDescription.AppendLiteral("null");
+    return;
+  }
+
+  aOutDescription.AppendPrintf("%p, ", (void*)aNode);
+  aOutDescription.Append(aNode->NodeInfo()->QualifiedName());
+
+  if (!aNode->IsElement()) {
+    return;
+  }
+
+  dom::Element* elm = aNode->AsElement();
+
+  nsAtom* idAtom = elm->GetID();
+  if (idAtom) {
+    nsAutoCString id;
+    idAtom->ToUTF8String(id);
+    aOutDescription.AppendPrintf("@id=\"%s\" ", id.get());
+  } else {
+    aOutDescription.Append(' ');
+  }
+
+  uint32_t attrCount = elm->GetAttrCount();
+  if (!attrCount || (idAtom && attrCount == 1)) {
+    return;
+  }
+
+  aOutDescription.AppendLiteral("[ ");
+
+  for (uint32_t index = 0; index < attrCount; index++) {
+    BorrowedAttrInfo info = elm->GetAttrInfoAt(index);
+
+    // Skip redundant display of id attribute.
+    if (info.mName->Equals(nsGkAtoms::id)) {
+      continue;
+    }
+
+    // name
+    nsAutoString name;
+    info.mName->GetQualifiedName(name);
+    aOutDescription.Append(name);
+
+    aOutDescription.AppendLiteral("=\"");
+
+    // value
+    nsAutoString value;
+    info.mValue->ToString(value);
+    for (uint32_t i = value.Length(); i > 0; --i) {
+      if (value[i - 1] == char16_t('"')) value.Insert(char16_t('\\'), i - 1);
+    }
+    aOutDescription.Append(value);
+    aOutDescription.AppendLiteral("\" ");
+  }
+
+  aOutDescription.Append(']');
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // namespace logging:: document life cycle logging methods
 
 static const char* sDocLoadTitle = "DOCLOAD";
 static const char* sDocCreateTitle = "DOCCREATE";
 static const char* sDocDestroyTitle = "DOCDESTROY";
 static const char* sDocEventTitle = "DOCEVENT";
 static const char* sFocusTitle = "FOCUS";
@@ -721,54 +780,23 @@ void logging::Address(const char* aDescr
          static_cast<void*>(docNode));
 
   printf("    ");
   LogDocURI(docNode);
   printf("\n");
 }
 
 void logging::Node(const char* aDescr, nsINode* aNode) {
-  printf("    ");
-
-  if (!aNode) {
-    printf("%s: null\n", aDescr);
-    return;
-  }
-
-  if (aNode->IsDocument()) {
-    printf("%s: %p, document\n", aDescr, static_cast<void*>(aNode));
-    return;
-  }
-
-  nsINode* parentNode = aNode->GetParentNode();
+  nsINode* parentNode = aNode ? aNode->GetParentNode() : nullptr;
   int32_t idxInParent = parentNode ? parentNode->ComputeIndexOf(aNode) : -1;
 
-  if (aNode->IsText()) {
-    printf("%s: %p, text node, idx in parent: %d\n", aDescr,
-           static_cast<void*>(aNode), idxInParent);
-    return;
-  }
-
-  if (!aNode->IsElement()) {
-    printf("%s: %p, not accessible node type, idx in parent: %d\n", aDescr,
-           static_cast<void*>(aNode), idxInParent);
-    return;
-  }
-
-  dom::Element* elm = aNode->AsElement();
-
-  nsAutoCString tag;
-  elm->NodeInfo()->NameAtom()->ToUTF8String(tag);
-
-  nsAtom* idAtom = elm->GetID();
-  nsAutoCString id;
-  if (idAtom) idAtom->ToUTF8String(id);
-
-  printf("%s: %p, %s@id='%s', idx in parent: %d\n", aDescr,
-         static_cast<void*>(elm), tag.get(), id.get(), idxInParent);
+  nsAutoString nodeDesc;
+  DescribeNode(aNode, nodeDesc);
+  printf("    %s: %s, idx in parent %d\n", aDescr,
+         NS_ConvertUTF16toUTF8(nodeDesc).get(), idxInParent);
 }
 
 void logging::Document(DocAccessible* aDocument) {
   printf("    Document: %p, document node: %p\n", static_cast<void*>(aDocument),
          static_cast<void*>(aDocument->DocumentNode()));
 
   printf("    Document ");
   LogDocURI(aDocument->DocumentNode());
@@ -797,38 +825,19 @@ void logging::AccessibleInfo(const char*
   nsAutoString name;
   aAccessible->Name(name);
   if (!name.IsEmpty()) {
     printf(", name: '%s'", NS_ConvertUTF16toUTF8(name).get());
   }
 
   printf(", idx: %d", aAccessible->IndexInParent());
 
-  nsINode* node = aAccessible->GetNode();
-  if (!node) {
-    printf(", node: null\n");
-  } else if (node->IsDocument()) {
-    printf(", document node: %p\n", static_cast<void*>(node));
-  } else if (node->IsText()) {
-    printf(", text node: %p\n", static_cast<void*>(node));
-  } else if (node->IsElement()) {
-    dom::Element* el = node->AsElement();
-
-    nsAutoCString tag;
-    el->NodeInfo()->NameAtom()->ToUTF8String(tag);
-
-    nsAtom* idAtom = el->GetID();
-    nsAutoCString id;
-    if (idAtom) {
-      idAtom->ToUTF8String(id);
-    }
-
-    printf(", element node: %p, %s@id='%s'\n", static_cast<void*>(el),
-           tag.get(), id.get());
-  }
+  nsAutoString nodeDesc;
+  DescribeNode(aAccessible->GetNode(), nodeDesc);
+  printf(", node: %s\n", NS_ConvertUTF16toUTF8(nodeDesc).get());
 }
 
 void logging::AccessibleNNode(const char* aDescr, Accessible* aAccessible) {
   printf("    %s: %p; ", aDescr, static_cast<void*>(aAccessible));
   if (!aAccessible) return;
 
   nsAutoString role;
   GetAccService()->GetStringRole(aAccessible->Role(), role);