| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash) { | 1095 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash) { |
| 1096 // Create a really simple tree with one root node and one focused child. | 1096 // Create a really simple tree with one root node and one focused child. |
| 1097 ui::AXNodeData root; | 1097 ui::AXNodeData root; |
| 1098 root.id = 1; | 1098 root.id = 1; |
| 1099 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1099 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1100 root.state = 0; | 1100 root.state = 0; |
| 1101 root.child_ids.push_back(2); | 1101 root.child_ids.push_back(2); |
| 1102 | 1102 |
| 1103 ui::AXNodeData node2; | 1103 ui::AXNodeData node2; |
| 1104 node2.id = 2; | 1104 node2.id = 2; |
| 1105 node2.state = 1 << ui::AX_STATE_FOCUSED; | |
| 1106 | 1105 |
| 1106 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2); |
| 1107 initial_state.has_tree_data = true; |
| 1108 initial_state.tree_data.focus_id = 2; |
| 1107 scoped_ptr<BrowserAccessibilityManager> manager( | 1109 scoped_ptr<BrowserAccessibilityManager> manager( |
| 1108 BrowserAccessibilityManager::Create( | 1110 BrowserAccessibilityManager::Create( |
| 1109 MakeAXTreeUpdate(root, node2), | 1111 initial_state, |
| 1110 nullptr, | 1112 nullptr, |
| 1111 new CountedBrowserAccessibilityFactory())); | 1113 new CountedBrowserAccessibilityFactory())); |
| 1112 | 1114 |
| 1113 ASSERT_EQ(1, manager->GetRoot()->GetId()); | 1115 ASSERT_EQ(1, manager->GetRoot()->GetId()); |
| 1114 ASSERT_EQ(1, manager->GetFocus(manager->GetRoot())->GetId()); | 1116 ASSERT_EQ(2, manager->GetFocus()->GetId()); |
| 1115 | |
| 1116 // Send the focus event for node 2. | |
| 1117 std::vector<AXEventNotificationDetails> events; | |
| 1118 events.push_back(AXEventNotificationDetails()); | |
| 1119 events[0].update = MakeAXTreeUpdate(node2); | |
| 1120 events[0].id = 2; | |
| 1121 events[0].event_type = ui::AX_EVENT_FOCUS; | |
| 1122 manager->OnAccessibilityEvents(events); | |
| 1123 | |
| 1124 ASSERT_EQ(1, manager->GetRoot()->GetId()); | |
| 1125 ASSERT_EQ(2, manager->GetFocus(manager->GetRoot())->GetId()); | |
| 1126 | 1117 |
| 1127 // Now replace the tree with a new tree consisting of a single root. | 1118 // Now replace the tree with a new tree consisting of a single root. |
| 1128 ui::AXNodeData root2; | 1119 ui::AXNodeData root2; |
| 1129 root2.id = 3; | 1120 root2.id = 3; |
| 1130 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1121 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1131 root2.state = 0; | 1122 root2.state = 0; |
| 1132 | 1123 |
| 1133 std::vector<AXEventNotificationDetails> events2; | 1124 std::vector<AXEventNotificationDetails> events2; |
| 1134 events2.push_back(AXEventNotificationDetails()); | 1125 events2.push_back(AXEventNotificationDetails()); |
| 1135 events2[0].update = MakeAXTreeUpdate(root2); | 1126 events2[0].update = MakeAXTreeUpdate(root2); |
| 1136 events2[0].id = -1; | 1127 events2[0].id = -1; |
| 1137 events2[0].event_type = ui::AX_EVENT_NONE; | 1128 events2[0].event_type = ui::AX_EVENT_NONE; |
| 1138 manager->OnAccessibilityEvents(events2); | 1129 manager->OnAccessibilityEvents(events2); |
| 1139 | 1130 |
| 1140 // Make sure that the focused node was updated to the new root and | 1131 // Make sure that the focused node was updated to the new root and |
| 1141 // that this doesn't crash. | 1132 // that this doesn't crash. |
| 1142 ASSERT_EQ(3, manager->GetRoot()->GetId()); | 1133 ASSERT_EQ(3, manager->GetRoot()->GetId()); |
| 1143 ASSERT_EQ(3, manager->GetFocus(manager->GetRoot())->GetId()); | 1134 ASSERT_EQ(3, manager->GetFocus()->GetId()); |
| 1144 } | 1135 } |
| 1145 | 1136 |
| 1146 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash2) { | 1137 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash2) { |
| 1147 // Create a really simple tree with one root node and one focused child. | 1138 // Create a really simple tree with one root node and one focused child. |
| 1148 ui::AXNodeData root; | 1139 ui::AXNodeData root; |
| 1149 root.id = 1; | 1140 root.id = 1; |
| 1150 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1141 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1151 root.state = 0; | 1142 root.state = 0; |
| 1152 root.child_ids.push_back(2); | 1143 root.child_ids.push_back(2); |
| 1153 root.child_ids.push_back(3); | 1144 root.child_ids.push_back(3); |
| 1154 root.child_ids.push_back(4); | 1145 root.child_ids.push_back(4); |
| 1155 | 1146 |
| 1156 ui::AXNodeData node2; | 1147 ui::AXNodeData node2; |
| 1157 node2.id = 2; | 1148 node2.id = 2; |
| 1158 node2.state = 1 << ui::AX_STATE_FOCUSED; | |
| 1159 | 1149 |
| 1160 ui::AXNodeData node3; | 1150 ui::AXNodeData node3; |
| 1161 node3.id = 3; | 1151 node3.id = 3; |
| 1162 node3.state = 0; | 1152 node3.state = 0; |
| 1163 | 1153 |
| 1164 ui::AXNodeData node4; | 1154 ui::AXNodeData node4; |
| 1165 node4.id = 4; | 1155 node4.id = 4; |
| 1166 node4.state = 0; | 1156 node4.state = 0; |
| 1167 | 1157 |
| 1158 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2, node3, node4); |
| 1159 initial_state.has_tree_data = true; |
| 1160 initial_state.tree_data.focus_id = 2; |
| 1168 scoped_ptr<BrowserAccessibilityManager> manager( | 1161 scoped_ptr<BrowserAccessibilityManager> manager( |
| 1169 BrowserAccessibilityManager::Create( | 1162 BrowserAccessibilityManager::Create( |
| 1170 MakeAXTreeUpdate(root, node2, node3, node4), | 1163 initial_state, |
| 1171 nullptr, | 1164 nullptr, |
| 1172 new CountedBrowserAccessibilityFactory())); | 1165 new CountedBrowserAccessibilityFactory())); |
| 1173 | 1166 |
| 1174 ASSERT_EQ(1, manager->GetRoot()->GetId()); | 1167 ASSERT_EQ(1, manager->GetRoot()->GetId()); |
| 1175 ASSERT_EQ(1, manager->GetFocus(manager->GetRoot())->GetId()); | 1168 ASSERT_EQ(2, manager->GetFocus()->GetId()); |
| 1176 | |
| 1177 // Send the focus event for node 2. | |
| 1178 std::vector<AXEventNotificationDetails> events; | |
| 1179 events.push_back(AXEventNotificationDetails()); | |
| 1180 events[0].update = MakeAXTreeUpdate(node2); | |
| 1181 events[0].id = 2; | |
| 1182 events[0].event_type = ui::AX_EVENT_FOCUS; | |
| 1183 manager->OnAccessibilityEvents(events); | |
| 1184 | |
| 1185 ASSERT_EQ(1, manager->GetRoot()->GetId()); | |
| 1186 ASSERT_EQ(2, manager->GetFocus(manager->GetRoot())->GetId()); | |
| 1187 | 1169 |
| 1188 // Now replace the tree with a new tree consisting of a single root. | 1170 // Now replace the tree with a new tree consisting of a single root. |
| 1189 ui::AXNodeData root2; | 1171 ui::AXNodeData root2; |
| 1190 root2.id = 3; | 1172 root2.id = 3; |
| 1191 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1173 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1192 root2.state = 0; | 1174 root2.state = 0; |
| 1193 | 1175 |
| 1194 // Make an update the explicitly clears the previous root. | 1176 // Make an update the explicitly clears the previous root. |
| 1195 std::vector<AXEventNotificationDetails> events2; | 1177 std::vector<AXEventNotificationDetails> events2; |
| 1196 events2.push_back(AXEventNotificationDetails()); | 1178 events2.push_back(AXEventNotificationDetails()); |
| 1197 events2[0].update = MakeAXTreeUpdate(root2); | 1179 events2[0].update = MakeAXTreeUpdate(root2); |
| 1198 events2[0].update.node_id_to_clear = 1; | 1180 events2[0].update.node_id_to_clear = 1; |
| 1199 events2[0].id = -1; | 1181 events2[0].id = -1; |
| 1200 events2[0].event_type = ui::AX_EVENT_NONE; | 1182 events2[0].event_type = ui::AX_EVENT_NONE; |
| 1201 manager->OnAccessibilityEvents(events2); | 1183 manager->OnAccessibilityEvents(events2); |
| 1202 | 1184 |
| 1203 // Make sure that the focused node was updated to the new root and | 1185 // Make sure that the focused node was updated to the new root and |
| 1204 // that this doesn't crash. | 1186 // that this doesn't crash. |
| 1205 ASSERT_EQ(3, manager->GetRoot()->GetId()); | 1187 ASSERT_EQ(3, manager->GetRoot()->GetId()); |
| 1206 ASSERT_EQ(3, manager->GetFocus(manager->GetRoot())->GetId()); | 1188 ASSERT_EQ(3, manager->GetFocus()->GetId()); |
| 1207 } | 1189 } |
| 1208 | 1190 |
| 1209 } // namespace content | 1191 } // namespace content |
| OLD | NEW |