Chromium Code Reviews| 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 "base/strings/string16.h" | 5 #include "base/strings/string16.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "content/browser/accessibility/browser_accessibility.h" | 7 #include "content/browser/accessibility/browser_accessibility.h" |
| 8 #include "content/browser/accessibility/browser_accessibility_manager.h" | 8 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include "content/browser/accessibility/browser_accessibility_win.h" | 10 #include "content/browser/accessibility/browser_accessibility_win.h" |
| (...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 982 ASSERT_EQ(node5_accessible, manager->NextInTreeOrder(node4_accessible)); | 982 ASSERT_EQ(node5_accessible, manager->NextInTreeOrder(node4_accessible)); |
| 983 ASSERT_EQ(NULL, manager->NextInTreeOrder(node5_accessible)); | 983 ASSERT_EQ(NULL, manager->NextInTreeOrder(node5_accessible)); |
| 984 | 984 |
| 985 ASSERT_EQ(NULL, manager->PreviousInTreeOrder(NULL)); | 985 ASSERT_EQ(NULL, manager->PreviousInTreeOrder(NULL)); |
| 986 ASSERT_EQ(node4_accessible, manager->PreviousInTreeOrder(node5_accessible)); | 986 ASSERT_EQ(node4_accessible, manager->PreviousInTreeOrder(node5_accessible)); |
| 987 ASSERT_EQ(node3_accessible, manager->PreviousInTreeOrder(node4_accessible)); | 987 ASSERT_EQ(node3_accessible, manager->PreviousInTreeOrder(node4_accessible)); |
| 988 ASSERT_EQ(node2_accessible, manager->PreviousInTreeOrder(node3_accessible)); | 988 ASSERT_EQ(node2_accessible, manager->PreviousInTreeOrder(node3_accessible)); |
| 989 ASSERT_EQ(root_accessible, manager->PreviousInTreeOrder(node2_accessible)); | 989 ASSERT_EQ(root_accessible, manager->PreviousInTreeOrder(node2_accessible)); |
| 990 } | 990 } |
| 991 | 991 |
| 992 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash) { | |
| 993 // Create a really simple tree with one root node and one focused child. | |
| 994 ui::AXNodeData root; | |
| 995 root.id = 1; | |
| 996 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | |
| 997 root.state = 0; | |
| 998 root.child_ids.push_back(2); | |
| 999 | |
| 1000 ui::AXNodeData node2; | |
| 1001 node2.id = 2; | |
| 1002 node2.state = 1 << ui::AX_STATE_FOCUSED; | |
| 1003 | |
| 1004 scoped_ptr<BrowserAccessibilityManager> manager( | |
| 1005 BrowserAccessibilityManager::Create( | |
| 1006 MakeAXTreeUpdate(root, node2), | |
| 1007 NULL, | |
|
dcheng
2015/07/15 00:58:10
Nit: nullptr
dmazzoni
2015/07/22 18:44:26
Done throughout this file.
| |
| 1008 new CountedBrowserAccessibilityFactory())); | |
| 1009 | |
| 1010 ASSERT_EQ(1, manager->GetRoot()->GetId()); | |
| 1011 ASSERT_EQ(1, manager->GetFocus(manager->GetRoot())->GetId()); | |
| 1012 | |
| 1013 // Send the focus event for node 2. | |
| 1014 std::vector<AccessibilityHostMsg_EventParams> events; | |
| 1015 events.push_back(AccessibilityHostMsg_EventParams()); | |
| 1016 events[0].update = MakeAXTreeUpdate(node2); | |
| 1017 events[0].id = 2; | |
| 1018 events[0].event_type = ui::AX_EVENT_FOCUS; | |
| 1019 manager->OnAccessibilityEvents(events); | |
| 1020 | |
| 1021 ASSERT_EQ(1, manager->GetRoot()->GetId()); | |
| 1022 ASSERT_EQ(2, manager->GetFocus(manager->GetRoot())->GetId()); | |
| 1023 | |
| 1024 // Now replace the tree with a new tree consisting of a single root. | |
| 1025 ui::AXNodeData root2; | |
| 1026 root2.id = 3; | |
| 1027 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; | |
| 1028 root2.state = 0; | |
| 1029 | |
| 1030 std::vector<AccessibilityHostMsg_EventParams> events2; | |
| 1031 events2.push_back(AccessibilityHostMsg_EventParams()); | |
| 1032 events2[0].update = MakeAXTreeUpdate(root2); | |
| 1033 events2[0].id = -1; | |
| 1034 events2[0].event_type = ui::AX_EVENT_NONE; | |
| 1035 manager->OnAccessibilityEvents(events2); | |
| 1036 | |
| 1037 // Make sure that the focused node was updated to the new root and | |
| 1038 // that this doesn't crash. | |
| 1039 ASSERT_EQ(3, manager->GetRoot()->GetId()); | |
| 1040 ASSERT_EQ(3, manager->GetFocus(manager->GetRoot())->GetId()); | |
| 1041 } | |
| 1042 | |
| 992 } // namespace content | 1043 } // namespace content |
| OLD | NEW |