Commit 65fe3d5a authored by Hiroki Sato's avatar Hiroki Sato Committed by Commit Bot

arc-a11y: Add AccessibilityNodeInfoDataWrapperTest

Current AXTreeSourceArcTest is large, and some of them tests
only the serialization of some nodes and don't need to interact with
AXTreeSourceArc.

This CL adds AccessibilityNodeInfoDataWrapperTest and moves some unit
tests from AXTreeSourceArcTest.

AX-Relnotes: n/a.
Bug: b:158141903
Test: AXTreeSourceArcTest, AccessibilityNodeInfoDataWrapperTest
Change-Id: I7505078b2df463a99dcbe20fa62ce3ca1f0a391c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2241092
Commit-Queue: Hiroki Sato <hirokisato@chromium.org>
Reviewed-by: default avatarSara Kato <sarakato@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781657}
parent b296cab9
......@@ -2876,6 +2876,7 @@ source_set("unit_tests") {
"apps/apk_web_app_installer_unittest.cc",
"apps/intent_helper/chromeos_apps_navigation_throttle_unittest.cc",
"apps/metrics/intent_handling_metrics_unittest.cc",
"arc/accessibility/accessibility_node_info_data_wrapper_unittest.cc",
"arc/accessibility/arc_accessibility_helper_bridge_unittest.cc",
"arc/accessibility/arc_accessibility_util_unittest.cc",
"arc/accessibility/ax_tree_source_arc_unittest.cc",
......
......@@ -176,8 +176,8 @@ void AccessibilityNodeInfoDataWrapper::PopulateAXRole(
// need additional information contained only in the CollectionInfo. The
// CollectionInfo should be an ancestor of this node.
AXCollectionInfoData* collection_info = nullptr;
for (const AccessibilityInfoDataWrapper* container =
static_cast<const AccessibilityInfoDataWrapper*>(this);
for (AccessibilityInfoDataWrapper* container =
const_cast<AccessibilityNodeInfoDataWrapper*>(this);
container;) {
if (!container || !container->IsNode())
break;
......@@ -186,8 +186,7 @@ void AccessibilityNodeInfoDataWrapper::PopulateAXRole(
break;
}
container =
tree_source_->GetParent(tree_source_->GetFromId(container->GetId()));
container = tree_source_->GetParent(container);
}
if (collection_info) {
......
......@@ -7,10 +7,12 @@
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/optional.h"
#include "base/stl_util.h"
#include "components/arc/mojom/accessibility_helper.mojom-forward.h"
#include "ui/accessibility/ax_enum_util.h"
......@@ -88,6 +90,20 @@ bool HasNonEmptyStringProperty(InfoDataType* node, PropType prop) {
return !it->second.empty();
}
// Sets property to mojom struct. Used in test.
template <class PropType, class ValueType>
void SetProperty(
base::Optional<base::flat_map<PropType, ValueType>>& properties,
PropType prop,
const ValueType& value) {
if (!properties.has_value())
properties = base::flat_map<PropType, ValueType>();
auto& prop_map = properties.value();
base::EraseIf(prop_map, [prop](auto it) { return it.first == prop; });
prop_map.insert(std::make_pair(prop, value));
}
} // namespace arc
#endif // CHROME_BROWSER_CHROMEOS_ARC_ACCESSIBILITY_ARC_ACCESSIBILITY_UTIL_H_
......@@ -68,7 +68,8 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*,
// Returns true if the node id is the root of the node tree (which can have a
// parent window).
bool IsRootOfNodeTree(int32_t id) const;
// virtual for testing.
virtual bool IsRootOfNodeTree(int32_t id) const;
AccessibilityInfoDataWrapper* GetFirstImportantAncestor(
AccessibilityInfoDataWrapper* info_data) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment