| 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 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1389 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash) { | 1389 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash) { |
| 1390 // Create a really simple tree with one root node and one focused child. | 1390 // Create a really simple tree with one root node and one focused child. |
| 1391 ui::AXNodeData root; | 1391 ui::AXNodeData root; |
| 1392 root.id = 1; | 1392 root.id = 1; |
| 1393 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1393 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1394 root.state = 0; | 1394 root.state = 0; |
| 1395 root.child_ids.push_back(2); | 1395 root.child_ids.push_back(2); |
| 1396 | 1396 |
| 1397 ui::AXNodeData node2; | 1397 ui::AXNodeData node2; |
| 1398 node2.id = 2; | 1398 node2.id = 2; |
| 1399 node2.state = 1 << ui::AX_STATE_FOCUSED; | |
| 1400 | 1399 |
| 1400 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2); |
| 1401 initial_state.has_tree_data = true; |
| 1402 initial_state.tree_data.focus_id = 2; |
| 1401 scoped_ptr<BrowserAccessibilityManager> manager( | 1403 scoped_ptr<BrowserAccessibilityManager> manager( |
| 1402 BrowserAccessibilityManager::Create( | 1404 BrowserAccessibilityManager::Create( |
| 1403 MakeAXTreeUpdate(root, node2), | 1405 initial_state, |
| 1404 nullptr, | 1406 nullptr, |
| 1405 new CountedBrowserAccessibilityFactory())); | 1407 new CountedBrowserAccessibilityFactory())); |
| 1406 | 1408 |
| 1407 ASSERT_EQ(1, manager->GetRoot()->GetId()); | 1409 ASSERT_EQ(1, manager->GetRoot()->GetId()); |
| 1408 ASSERT_EQ(1, manager->GetFocus(manager->GetRoot())->GetId()); | 1410 ASSERT_EQ(2, manager->GetFocus()->GetId()); |
| 1409 | |
| 1410 // Send the focus event for node 2. | |
| 1411 std::vector<AXEventNotificationDetails> events; | |
| 1412 events.push_back(AXEventNotificationDetails()); | |
| 1413 events[0].update = MakeAXTreeUpdate(node2); | |
| 1414 events[0].id = 2; | |
| 1415 events[0].event_type = ui::AX_EVENT_FOCUS; | |
| 1416 manager->OnAccessibilityEvents(events); | |
| 1417 | |
| 1418 ASSERT_EQ(1, manager->GetRoot()->GetId()); | |
| 1419 ASSERT_EQ(2, manager->GetFocus(manager->GetRoot())->GetId()); | |
| 1420 | 1411 |
| 1421 // Now replace the tree with a new tree consisting of a single root. | 1412 // Now replace the tree with a new tree consisting of a single root. |
| 1422 ui::AXNodeData root2; | 1413 ui::AXNodeData root2; |
| 1423 root2.id = 3; | 1414 root2.id = 3; |
| 1424 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1415 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1425 root2.state = 0; | 1416 root2.state = 0; |
| 1426 | 1417 |
| 1427 std::vector<AXEventNotificationDetails> events2; | 1418 std::vector<AXEventNotificationDetails> events2; |
| 1428 events2.push_back(AXEventNotificationDetails()); | 1419 events2.push_back(AXEventNotificationDetails()); |
| 1429 events2[0].update = MakeAXTreeUpdate(root2); | 1420 events2[0].update = MakeAXTreeUpdate(root2); |
| 1430 events2[0].id = -1; | 1421 events2[0].id = -1; |
| 1431 events2[0].event_type = ui::AX_EVENT_NONE; | 1422 events2[0].event_type = ui::AX_EVENT_NONE; |
| 1432 manager->OnAccessibilityEvents(events2); | 1423 manager->OnAccessibilityEvents(events2); |
| 1433 | 1424 |
| 1434 // Make sure that the focused node was updated to the new root and | 1425 // Make sure that the focused node was updated to the new root and |
| 1435 // that this doesn't crash. | 1426 // that this doesn't crash. |
| 1436 ASSERT_EQ(3, manager->GetRoot()->GetId()); | 1427 ASSERT_EQ(3, manager->GetRoot()->GetId()); |
| 1437 ASSERT_EQ(3, manager->GetFocus(manager->GetRoot())->GetId()); | 1428 ASSERT_EQ(3, manager->GetFocus()->GetId()); |
| 1438 } | 1429 } |
| 1439 | 1430 |
| 1440 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash2) { | 1431 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash2) { |
| 1441 // Create a really simple tree with one root node and one focused child. | 1432 // Create a really simple tree with one root node and one focused child. |
| 1442 ui::AXNodeData root; | 1433 ui::AXNodeData root; |
| 1443 root.id = 1; | 1434 root.id = 1; |
| 1444 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1435 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1445 root.state = 0; | 1436 root.state = 0; |
| 1446 root.child_ids.push_back(2); | 1437 root.child_ids.push_back(2); |
| 1447 root.child_ids.push_back(3); | 1438 root.child_ids.push_back(3); |
| 1448 root.child_ids.push_back(4); | 1439 root.child_ids.push_back(4); |
| 1449 | 1440 |
| 1450 ui::AXNodeData node2; | 1441 ui::AXNodeData node2; |
| 1451 node2.id = 2; | 1442 node2.id = 2; |
| 1452 node2.state = 1 << ui::AX_STATE_FOCUSED; | |
| 1453 | 1443 |
| 1454 ui::AXNodeData node3; | 1444 ui::AXNodeData node3; |
| 1455 node3.id = 3; | 1445 node3.id = 3; |
| 1456 node3.state = 0; | 1446 node3.state = 0; |
| 1457 | 1447 |
| 1458 ui::AXNodeData node4; | 1448 ui::AXNodeData node4; |
| 1459 node4.id = 4; | 1449 node4.id = 4; |
| 1460 node4.state = 0; | 1450 node4.state = 0; |
| 1461 | 1451 |
| 1452 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2, node3, node4); |
| 1453 initial_state.has_tree_data = true; |
| 1454 initial_state.tree_data.focus_id = 2; |
| 1462 scoped_ptr<BrowserAccessibilityManager> manager( | 1455 scoped_ptr<BrowserAccessibilityManager> manager( |
| 1463 BrowserAccessibilityManager::Create( | 1456 BrowserAccessibilityManager::Create( |
| 1464 MakeAXTreeUpdate(root, node2, node3, node4), | 1457 initial_state, |
| 1465 nullptr, | 1458 nullptr, |
| 1466 new CountedBrowserAccessibilityFactory())); | 1459 new CountedBrowserAccessibilityFactory())); |
| 1467 | 1460 |
| 1468 ASSERT_EQ(1, manager->GetRoot()->GetId()); | 1461 ASSERT_EQ(1, manager->GetRoot()->GetId()); |
| 1469 ASSERT_EQ(1, manager->GetFocus(manager->GetRoot())->GetId()); | 1462 ASSERT_EQ(2, manager->GetFocus()->GetId()); |
| 1470 | |
| 1471 // Send the focus event for node 2. | |
| 1472 std::vector<AXEventNotificationDetails> events; | |
| 1473 events.push_back(AXEventNotificationDetails()); | |
| 1474 events[0].update = MakeAXTreeUpdate(node2); | |
| 1475 events[0].id = 2; | |
| 1476 events[0].event_type = ui::AX_EVENT_FOCUS; | |
| 1477 manager->OnAccessibilityEvents(events); | |
| 1478 | |
| 1479 ASSERT_EQ(1, manager->GetRoot()->GetId()); | |
| 1480 ASSERT_EQ(2, manager->GetFocus(manager->GetRoot())->GetId()); | |
| 1481 | 1463 |
| 1482 // Now replace the tree with a new tree consisting of a single root. | 1464 // Now replace the tree with a new tree consisting of a single root. |
| 1483 ui::AXNodeData root2; | 1465 ui::AXNodeData root2; |
| 1484 root2.id = 3; | 1466 root2.id = 3; |
| 1485 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1467 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1486 root2.state = 0; | 1468 root2.state = 0; |
| 1487 | 1469 |
| 1488 // Make an update the explicitly clears the previous root. | 1470 // Make an update the explicitly clears the previous root. |
| 1489 std::vector<AXEventNotificationDetails> events2; | 1471 std::vector<AXEventNotificationDetails> events2; |
| 1490 events2.push_back(AXEventNotificationDetails()); | 1472 events2.push_back(AXEventNotificationDetails()); |
| 1491 events2[0].update = MakeAXTreeUpdate(root2); | 1473 events2[0].update = MakeAXTreeUpdate(root2); |
| 1492 events2[0].update.node_id_to_clear = 1; | 1474 events2[0].update.node_id_to_clear = 1; |
| 1493 events2[0].id = -1; | 1475 events2[0].id = -1; |
| 1494 events2[0].event_type = ui::AX_EVENT_NONE; | 1476 events2[0].event_type = ui::AX_EVENT_NONE; |
| 1495 manager->OnAccessibilityEvents(events2); | 1477 manager->OnAccessibilityEvents(events2); |
| 1496 | 1478 |
| 1497 // Make sure that the focused node was updated to the new root and | 1479 // Make sure that the focused node was updated to the new root and |
| 1498 // that this doesn't crash. | 1480 // that this doesn't crash. |
| 1499 ASSERT_EQ(3, manager->GetRoot()->GetId()); | 1481 ASSERT_EQ(3, manager->GetRoot()->GetId()); |
| 1500 ASSERT_EQ(3, manager->GetFocus(manager->GetRoot())->GetId()); | 1482 ASSERT_EQ(3, manager->GetFocus()->GetId()); |
| 1501 } | 1483 } |
| 1502 | 1484 |
| 1503 } // namespace content | 1485 } // namespace content |
| OLD | NEW |