File: test_ax_tree_update.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (90 lines) | stat: -rw-r--r-- 3,377 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_ACCESSIBILITY_TEST_AX_TREE_UPDATE_H_
#define UI_ACCESSIBILITY_TEST_AX_TREE_UPDATE_H_

#include <set>
#include <unordered_map>

#include "ui/accessibility/ax_enum_util.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_tree_update.h"

namespace ui {

struct AXNodeData;
struct AXTreeData;
class AXTreeID;

// These utility classes, help construct an AXTreeUpdate  together with all of
// the updated nodes more easily. Only for use in tests for constructing /
// updating simple accessibility trees.

// Used to construct AXTreeUpdate node.
struct TestAXTreeUpdateNode final {
  TestAXTreeUpdateNode() = delete;
  ~TestAXTreeUpdateNode();

  TestAXTreeUpdateNode(const TestAXTreeUpdateNode&);
  TestAXTreeUpdateNode(TestAXTreeUpdateNode&&);

  TestAXTreeUpdateNode(ax::mojom::Role role,
                       const std::vector<TestAXTreeUpdateNode>& children);
  TestAXTreeUpdateNode(ax::mojom::Role role,
                       ax::mojom::State state,
                       const std::vector<TestAXTreeUpdateNode>& children);
  explicit TestAXTreeUpdateNode(const std::string& text);

  AXNodeData data;
  std::vector<TestAXTreeUpdateNode> children;
};

// Used to construct an accessible tree from a hierarchical list of nodes
// {<node_properties>, {<node_children>}}. For example,
// {Role::kRootWebArea, {"text"}} will create the following tree:
// kRootWebArea
// ++kStaticText "text"
class TestAXTreeUpdate final : public AXTreeUpdate {
 public:
  explicit TestAXTreeUpdate(const TestAXTreeUpdateNode& root);

  // Returns an `AXTreeUpdate` from a tree structure string of the format:
  // ++<id> <role> <name?>="<name>" <state?>=<state_value>,<state_value>
  // Where the properties denoted with a `?` are optional.
  // For example:
  // ++++4 kTextField name="placeholder" state=kEditable,kFocusable 
  //
  // Other supported properties are:
  // * intAttribute=<intAttributeType>,<intAttributeValue>
  // * stringAttribute=<stringAttributeType>,<stringAttributeValue>
  // * boolAttribute=<boolAttributeType>,<boolAttributeValue>
  //
  // Some of the expectations this function makes are:
  // * Roles and states are always valid.
  // * Roles and states are prefixed by a 'k'.
  // * The `name` property value passed in is surrounded by double quotes.
  // * Properties that may have multiple possible values passed in have those
  // values separated ONLY by a comma.
  // * There is always a newline separating each node of the tree.
  // 
  // LIMITATIONS:
  // - Because the parsing uses newline characters to distinguish between lines
  // (where each line is one node), names for nodes can't be newline characters.
  // - For similar reasons, spaces, '+', '=', commas, and double quotes can't be
  // used as or within node names.
  // Follow up CLs will be made so alleviate these limitations.
  explicit TestAXTreeUpdate(const std::string& tree_structure);

  TestAXTreeUpdate(const TestAXTreeUpdate&) = delete;
  TestAXTreeUpdate& operator=(const TestAXTreeUpdate&) = delete;

 private:
  // Recursively creates the tree update structure.
  AXNodeID SetSubtree(const TestAXTreeUpdateNode& node);

};
}  // namespace ui

#endif  // UI_ACCESSIBILITY_TEST_AX_TREE_UPDATE_H_