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 
5 #include <unordered_set>
6 
7 #include "testing/gtest/include/gtest/gtest.h"
8 
9 #include "ui/accessibility/ax_enum_util.h"
10 #include "ui/accessibility/ax_enums.mojom.h"
11 #include "ui/accessibility/ax_role_properties.h"
12 
13 namespace ui {
14 
TEST(AXRolePropertiesTest,TestSupportsHierarchicalLevel)15 TEST(AXRolePropertiesTest, TestSupportsHierarchicalLevel) {
16   // Test for iterating through all roles and validate if a role supports
17   // hierarchical level.
18   std::unordered_set<ax::mojom::Role>
19       roles_expected_supports_hierarchical_level = {
20           ax::mojom::Role::kComment, ax::mojom::Role::kListItem,
21           ax::mojom::Role::kRow, ax::mojom::Role::kTabList,
22           ax::mojom::Role::kTreeItem};
23 
24   for (int role_idx = static_cast<int>(ax::mojom::Role::kMinValue);
25        role_idx <= static_cast<int>(ax::mojom::Role::kMaxValue); role_idx++) {
26     ax::mojom::Role role = static_cast<ax::mojom::Role>(role_idx);
27     bool supports_hierarchical_level = SupportsHierarchicalLevel(role);
28 
29     SCOPED_TRACE(testing::Message() << "ax::mojom::Role=" << ToString(role)
30                                     << ", Actual: supportsHierarchicalLevel="
31                                     << supports_hierarchical_level
32                                     << ", Expected: supportsHierarchicalLevel="
33                                     << !supports_hierarchical_level);
34 
35     if (roles_expected_supports_hierarchical_level.find(role) !=
36         roles_expected_supports_hierarchical_level.end())
37       EXPECT_TRUE(supports_hierarchical_level);
38     else
39       EXPECT_FALSE(supports_hierarchical_level);
40   }
41 }
42 
TEST(AXRolePropertiesTest,TestSupportsToggle)43 TEST(AXRolePropertiesTest, TestSupportsToggle) {
44   // Test for iterating through all roles and validate if a role supports
45   // toggle.
46   std::unordered_set<ax::mojom::Role> roles_expected_supports_toggle = {
47       ax::mojom::Role::kCheckBox, ax::mojom::Role::kMenuItemCheckBox,
48       ax::mojom::Role::kSwitch, ax::mojom::Role::kToggleButton};
49 
50   for (int role_idx = static_cast<int>(ax::mojom::Role::kMinValue);
51        role_idx <= static_cast<int>(ax::mojom::Role::kMaxValue); role_idx++) {
52     ax::mojom::Role role = static_cast<ax::mojom::Role>(role_idx);
53     bool supports_toggle = SupportsToggle(role);
54 
55     SCOPED_TRACE(testing::Message()
56                  << "ax::mojom::Role=" << ToString(role)
57                  << ", Actual: supportsToggle=" << supports_toggle
58                  << ", Expected: supportsToggle=" << !supports_toggle);
59 
60     if (roles_expected_supports_toggle.find(role) !=
61         roles_expected_supports_toggle.end())
62       EXPECT_TRUE(supports_toggle);
63     else
64       EXPECT_FALSE(supports_toggle);
65   }
66 }
67 }  // namespace ui
68