ns_ax_tree_validator.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_BASE_TEST_NS_AX_TREE_VALIDATOR_H_
  5. #define UI_BASE_TEST_NS_AX_TREE_VALIDATOR_H_
  6. #include "third_party/abseil-cpp/absl/types/optional.h"
  7. @protocol NSAccessibility;
  8. namespace ui {
  9. struct NSAXTreeProblemDetails {
  10. enum ProblemType {
  11. // |node_a| (the child node) is not a child of |node_b| (its parent).
  12. NSAX_NOT_CHILD_OF_PARENT,
  13. // |node_a| (the child node) is a child of |node_b|, but |node_a|'s parent
  14. // is |node_c| instead.
  15. NSAX_CHILD_PARENT_NOT_THIS,
  16. // |node_a| (a supplied root node) is non-nil but does not conform to
  17. // NSAccessibility.
  18. NSAX_NOT_NSACCESSIBILITY,
  19. // |node_a| (the child node)'s parent |node_b| is non-nil but does not
  20. // conform to NSAccessibility.
  21. NSAX_PARENT_NOT_NSACCESSIBILITY,
  22. };
  23. NSAXTreeProblemDetails(ProblemType type, id node_a, id node_b, id node_c);
  24. ProblemType type;
  25. // These aren't id<NSAccessibility> because some kinds of problem are caused
  26. // by them not conforming to NSAccessibility.
  27. id node_a;
  28. id node_b;
  29. id node_c;
  30. std::string ToString();
  31. };
  32. // Validates the accessibility tree rooted at |root|. If at least one problem is
  33. // found, returns an |AXTreeProblemDetails| as described above; if not, returns
  34. // absl::nullopt.
  35. absl::optional<NSAXTreeProblemDetails> ValidateNSAXTree(
  36. id<NSAccessibility> root,
  37. size_t* nodes_visited);
  38. // Prints the accessibility tree rooted at |root|. This function is useful for
  39. // debugging failures of ValidateNSAXTree tests.
  40. void PrintNSAXTree(id<NSAccessibility> root);
  41. } // ui
  42. #endif // UI_BASE_TEST_NS_AX_TREE_VALIDATOR_H_