Flutter Engine
The Flutter Engine
ax_platform_node_unittest.cc
Go to the documentation of this file.
1// Copyright 2017 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
6
7#include "ax/ax_constants.h"
9
10namespace ui {
11
13
15
16void AXPlatformNodeTest::Init(const AXTreeUpdate& initial_state) {
17 SetTree(std::make_unique<AXTree>(initial_state));
18}
19
21 const ui::AXNodeData& node1,
22 const ui::AXNodeData& node2 /* = ui::AXNodeData() */,
23 const ui::AXNodeData& node3 /* = ui::AXNodeData() */,
24 const ui::AXNodeData& node4 /* = ui::AXNodeData() */,
25 const ui::AXNodeData& node5 /* = ui::AXNodeData() */,
26 const ui::AXNodeData& node6 /* = ui::AXNodeData() */,
27 const ui::AXNodeData& node7 /* = ui::AXNodeData() */,
28 const ui::AXNodeData& node8 /* = ui::AXNodeData() */,
29 const ui::AXNodeData& node9 /* = ui::AXNodeData() */,
30 const ui::AXNodeData& node10 /* = ui::AXNodeData() */,
31 const ui::AXNodeData& node11 /* = ui::AXNodeData() */,
32 const ui::AXNodeData& node12 /* = ui::AXNodeData() */) {
33 static ui::AXNodeData empty_data;
34 int32_t no_id = empty_data.id;
36 update.root_id = node1.id;
37 update.nodes.push_back(node1);
38 if (node2.id != no_id)
39 update.nodes.push_back(node2);
40 if (node3.id != no_id)
41 update.nodes.push_back(node3);
42 if (node4.id != no_id)
43 update.nodes.push_back(node4);
44 if (node5.id != no_id)
45 update.nodes.push_back(node5);
46 if (node6.id != no_id)
47 update.nodes.push_back(node6);
48 if (node7.id != no_id)
49 update.nodes.push_back(node7);
50 if (node8.id != no_id)
51 update.nodes.push_back(node8);
52 if (node9.id != no_id)
53 update.nodes.push_back(node9);
54 if (node10.id != no_id)
55 update.nodes.push_back(node10);
56 if (node11.id != no_id)
57 update.nodes.push_back(node11);
58 if (node12.id != no_id)
59 update.nodes.push_back(node12);
60 Init(update);
61}
62
64 AXNodeData text_field_node;
65 text_field_node.id = 1;
66 text_field_node.role = ax::mojom::Role::kTextField;
68 text_field_node.SetValue("How now brown cow.");
69
71 update.root_id = text_field_node.id;
72 update.nodes.push_back(text_field_node);
73 return update;
74}
75
77 int32_t start,
78 int32_t stop) {
79 AXNodeData text_field_node;
80 text_field_node.id = 1;
81 text_field_node.role = ax::mojom::Role::kTextField;
85 start);
87 text_field_node.SetValue("How now brown cow.");
88
90 update.root_id = text_field_node.id;
91 update.nodes.push_back(text_field_node);
92 return update;
93}
94
96 AXNodeData content_editable_node;
97 content_editable_node.id = 1;
98 content_editable_node.role = ax::mojom::Role::kGroup;
99 content_editable_node.AddState(ax::mojom::State::kRichlyEditable);
100 content_editable_node.AddBoolAttribute(
102 content_editable_node.SetValue("How now brown cow.");
103
105 update.root_id = content_editable_node.id;
106 update.nodes.push_back(content_editable_node);
107 return update;
108}
109
111 int32_t start,
112 int32_t end) {
113 AXNodeData content_editable_node;
114 content_editable_node.id = 1;
115 content_editable_node.role = ax::mojom::Role::kGroup;
116 content_editable_node.AddState(ax::mojom::State::kRichlyEditable);
118 true);
119 content_editable_node.AddBoolAttribute(
121 content_editable_node.SetValue("How now brown cow.");
122
124 update.root_id = content_editable_node.id;
125 update.nodes.push_back(content_editable_node);
126
127 update.has_tree_data = true;
128 update.tree_data.sel_anchor_object_id = content_editable_node.id;
129 update.tree_data.sel_focus_object_id = content_editable_node.id;
130 update.tree_data.sel_anchor_offset = start;
131 update.tree_data.sel_focus_offset = end;
132
133 return update;
134}
135
136AXTreeUpdate AXPlatformNodeTest::AXPlatformNodeTest::Build3X3Table() {
137 /*
138 Build a table that looks like:
139
140 ---------------------- (A) Column Header
141 | | (A) | (B) | (B) Column Header
142 ---------------------- (C) Row Header
143 | (C) | 1 | 2 | (D) Row Header
144 ----------------------
145 | (D) | 3 | 4 |
146 ----------------------
147 */
148
150 table.id = 1;
152
155
156 table.child_ids.push_back(50); // Header
157 table.child_ids.push_back(2); // Row 1
158 table.child_ids.push_back(10); // Row 2
159
160 // Table column header
161 AXNodeData table_row_header;
162 table_row_header.id = 50;
163 table_row_header.role = ax::mojom::Role::kRow;
164 table_row_header.child_ids.push_back(51);
165 table_row_header.child_ids.push_back(52);
166 table_row_header.child_ids.push_back(53);
167
168 AXNodeData table_column_header_1;
169 table_column_header_1.id = 51;
170 table_column_header_1.role = ax::mojom::Role::kColumnHeader;
171 table_column_header_1.AddIntAttribute(
173 table_column_header_1.AddIntAttribute(
175
176 AXNodeData table_column_header_2;
177 table_column_header_2.id = 52;
178 table_column_header_2.role = ax::mojom::Role::kColumnHeader;
179 table_column_header_2.SetName("column header 1");
180 table_column_header_2.AddIntAttribute(
182 table_column_header_2.AddIntAttribute(
184
185 AXNodeData table_column_header_3;
186 table_column_header_3.id = 53;
187 table_column_header_3.role = ax::mojom::Role::kColumnHeader;
188 // Either ax::mojom::StringAttribute::kName -or-
189 // ax::mojom::StringAttribute::kDescription is acceptable for a description
190 table_column_header_3.AddStringAttribute(
192 table_column_header_3.AddIntAttribute(
194 table_column_header_3.AddIntAttribute(
196
197 // Row 1
198 AXNodeData table_row_1;
199 table_row_1.id = 2;
200 table_row_1.role = ax::mojom::Role::kRow;
201
202 AXNodeData table_row_header_1;
203 table_row_header_1.id = 3;
204 table_row_header_1.role = ax::mojom::Role::kRowHeader;
205 table_row_header_1.SetName("row header 1");
206 table_row_header_1.AddIntAttribute(
208 table_row_header_1.AddIntAttribute(
210 table_row_1.child_ids.push_back(table_row_header_1.id);
211
212 AXNodeData table_cell_1;
213 table_cell_1.id = 4;
214 table_cell_1.role = ax::mojom::Role::kCell;
215 table_cell_1.SetName("1");
218 1);
219 table_row_1.child_ids.push_back(table_cell_1.id);
220
221 AXNodeData table_cell_2;
222 table_cell_2.id = 5;
223 table_cell_2.role = ax::mojom::Role::kCell;
224 table_cell_2.SetName("2");
227 2);
228 table_row_1.child_ids.push_back(table_cell_2.id);
229
230 // Row 2
231 AXNodeData table_row_2;
232 table_row_2.id = 10;
233 table_row_2.role = ax::mojom::Role::kRow;
234
235 AXNodeData table_row_header_2;
236 table_row_header_2.id = 11;
237 table_row_header_2.role = ax::mojom::Role::kRowHeader;
238 // Either ax::mojom::StringAttribute::kName -or-
239 // ax::mojom::StringAttribute::kDescription is acceptable for a description
240 table_row_header_2.AddStringAttribute(
242 table_row_header_2.AddIntAttribute(
244 table_row_header_2.AddIntAttribute(
246 table_row_2.child_ids.push_back(table_row_header_2.id);
247
248 AXNodeData table_cell_3;
249 table_cell_3.id = 12;
250 table_cell_3.role = ax::mojom::Role::kCell;
251 table_cell_3.SetName("3");
254 1);
255 table_row_2.child_ids.push_back(table_cell_3.id);
256
257 AXNodeData table_cell_4;
258 table_cell_4.id = 13;
259 table_cell_4.role = ax::mojom::Role::kCell;
260 table_cell_4.SetName("4");
263 2);
264 table_row_2.child_ids.push_back(table_cell_4.id);
265
267 update.root_id = table.id;
268
269 // Some of the table testing code will index into |nodes|
270 // and change the state of the given node. If you reorder
271 // these, you're going to need to update the tests.
272 update.nodes.push_back(table); // 0
273
274 update.nodes.push_back(table_row_header); // 1
275 update.nodes.push_back(table_column_header_1); // 2
276 update.nodes.push_back(table_column_header_2); // 3
277 update.nodes.push_back(table_column_header_3); // 4
278
279 update.nodes.push_back(table_row_1); // 5
280 update.nodes.push_back(table_row_header_1); // 6
281 update.nodes.push_back(table_cell_1); // 7
282 update.nodes.push_back(table_cell_2); // 8
283
284 update.nodes.push_back(table_row_2); // 9
285 update.nodes.push_back(table_row_header_2); // 10
286 update.nodes.push_back(table_cell_3); // 11
287 update.nodes.push_back(table_cell_4); // 12
288
289 return update;
290}
291
294 root.id = 1;
296
297 // Empty Grid
298 AXNodeData empty_grid;
299 empty_grid.id = 2;
300 empty_grid.role = ax::mojom::Role::kGrid;
301 root.child_ids.push_back(empty_grid.id);
302
303 // Grid with a cell that defines aria-rowindex (4) and aria-colindex (5)
304 AXNodeData rowcolindex_grid;
305 rowcolindex_grid.id = 3;
306 rowcolindex_grid.role = ax::mojom::Role::kGrid;
307 root.child_ids.push_back(rowcolindex_grid.id);
308
309 AXNodeData rowcolindex_row;
310 rowcolindex_row.id = 4;
311 rowcolindex_row.role = ax::mojom::Role::kRow;
312 rowcolindex_grid.child_ids.push_back(rowcolindex_row.id);
313
314 AXNodeData rowcolindex_cell;
315 rowcolindex_cell.id = 5;
316 rowcolindex_cell.role = ax::mojom::Role::kCell;
317 rowcolindex_cell.AddIntAttribute(
320 4);
321 rowcolindex_row.child_ids.push_back(rowcolindex_cell.id);
322
323 // Grid that specifies aria-rowcount (2) and aria-colcount (3)
324 AXNodeData rowcolcount_grid;
325 rowcolcount_grid.id = 6;
326 rowcolcount_grid.role = ax::mojom::Role::kGrid;
329 3);
330 root.child_ids.push_back(rowcolcount_grid.id);
331
332 // Grid that specifies aria-rowcount and aria-colcount are (-1)
333 // ax::mojom::kUnknownAriaColumnOrRowCount
334 AXNodeData unknown_grid;
335 unknown_grid.id = 7;
336 unknown_grid.role = ax::mojom::Role::kGrid;
341 root.child_ids.push_back(unknown_grid.id);
342
344 update.root_id = root.id;
345 update.nodes.push_back(root);
346 update.nodes.push_back(empty_grid);
347 update.nodes.push_back(rowcolindex_grid);
348 update.nodes.push_back(rowcolindex_row);
349 update.nodes.push_back(rowcolindex_cell);
350 update.nodes.push_back(rowcolcount_grid);
351 update.nodes.push_back(unknown_grid);
352 return update;
353}
354
356 bool option_1_is_selected,
357 bool option_2_is_selected,
358 bool option_3_is_selected,
359 const std::vector<ax::mojom::State>& additional_state) {
360 AXNodeData listbox;
361 listbox.id = 1;
363 listbox.SetName("ListBox");
364 for (auto state : additional_state)
365 listbox.AddState(state);
366
367 AXNodeData option_1;
368 option_1.id = 2;
370 option_1.SetName("Option1");
371 if (option_1_is_selected)
373 listbox.child_ids.push_back(option_1.id);
374
375 AXNodeData option_2;
376 option_2.id = 3;
378 option_2.SetName("Option2");
379 if (option_2_is_selected)
381 listbox.child_ids.push_back(option_2.id);
382
383 AXNodeData option_3;
384 option_3.id = 4;
386 option_3.SetName("Option3");
387 if (option_3_is_selected)
389 listbox.child_ids.push_back(option_3.id);
390
392 update.root_id = listbox.id;
393 update.nodes.push_back(listbox);
394 update.nodes.push_back(option_1);
395 update.nodes.push_back(option_2);
396 update.nodes.push_back(option_3);
397 return update;
398}
399
400} // namespace ui
SI F table(const skcms_Curve *curve, F v)
~AXPlatformNodeTest() override
AXTreeUpdate BuildTextFieldWithSelectionRange(int32_t start, int32_t stop)
AXTreeUpdate BuildContentEditableWithSelectionRange(int32_t start, int32_t end)
void Init(const AXTreeUpdate &initial_state)
AXTreeUpdate BuildListBox(bool option_1_is_selected, bool option_2_is_selected, bool option_3_is_selected, const std::vector< ax::mojom::State > &additional_state)
AXTreeUpdate BuildAriaColumnAndRowCountGrids()
void SetTree(std::unique_ptr< AXTree > tree)
AtkStateType state
glong glong end
const int32_t kUnknownAriaColumnOrRowCount
Definition: ax_constants.h:20
string root
Definition: scale_cpu.py:20
Definition: update.py:1
void AddState(ax::mojom::State state)
void AddIntAttribute(ax::mojom::IntAttribute attribute, int32_t value)
std::vector< int32_t > child_ids
Definition: ax_node_data.h:291
void SetValue(const std::string &value)
void SetName(const std::string &name)
void AddStringAttribute(ax::mojom::StringAttribute attribute, const std::string &value)
void AddBoolAttribute(ax::mojom::BoolAttribute attribute, bool value)
ax::mojom::Role role
Definition: ax_node_data.h:277