| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 CountedBrowserAccessibility* child2_accessible = | 251 CountedBrowserAccessibility* child2_accessible = |
| 252 static_cast<CountedBrowserAccessibility*>( | 252 static_cast<CountedBrowserAccessibility*>( |
| 253 root_accessible->PlatformGetChild(1)); | 253 root_accessible->PlatformGetChild(1)); |
| 254 child2_accessible->NativeAddReference(); | 254 child2_accessible->NativeAddReference(); |
| 255 CountedBrowserAccessibility* child3_accessible = | 255 CountedBrowserAccessibility* child3_accessible = |
| 256 static_cast<CountedBrowserAccessibility*>( | 256 static_cast<CountedBrowserAccessibility*>( |
| 257 root_accessible->PlatformGetChild(2)); | 257 root_accessible->PlatformGetChild(2)); |
| 258 child3_accessible->NativeAddReference(); | 258 child3_accessible->NativeAddReference(); |
| 259 | 259 |
| 260 // Check the index in parent. | 260 // Check the index in parent. |
| 261 EXPECT_EQ(0, child1_accessible->index_in_parent()); | 261 EXPECT_EQ(0, child1_accessible->GetIndexInParent()); |
| 262 EXPECT_EQ(1, child2_accessible->index_in_parent()); | 262 EXPECT_EQ(1, child2_accessible->GetIndexInParent()); |
| 263 EXPECT_EQ(2, child3_accessible->index_in_parent()); | 263 EXPECT_EQ(2, child3_accessible->GetIndexInParent()); |
| 264 | 264 |
| 265 // Process a notification containing the changed subtree. | 265 // Process a notification containing the changed subtree. |
| 266 std::vector<AccessibilityHostMsg_EventParams> params; | 266 std::vector<AccessibilityHostMsg_EventParams> params; |
| 267 params.push_back(AccessibilityHostMsg_EventParams()); | 267 params.push_back(AccessibilityHostMsg_EventParams()); |
| 268 AccessibilityHostMsg_EventParams* msg = ¶ms[0]; | 268 AccessibilityHostMsg_EventParams* msg = ¶ms[0]; |
| 269 msg->event_type = ui::AX_EVENT_CHILDREN_CHANGED; | 269 msg->event_type = ui::AX_EVENT_CHILDREN_CHANGED; |
| 270 msg->update.nodes.push_back(tree2_root); | 270 msg->update.nodes.push_back(tree2_root); |
| 271 msg->update.nodes.push_back(tree2_child0); | 271 msg->update.nodes.push_back(tree2_child0); |
| 272 msg->id = tree2_root.id; | 272 msg->id = tree2_root.id; |
| 273 manager->OnAccessibilityEvents(params); | 273 manager->OnAccessibilityEvents(params); |
| 274 | 274 |
| 275 // There should be 5 objects now: the 4 from the new tree, plus the | 275 // There should be 5 objects now: the 4 from the new tree, plus the |
| 276 // reference to child3 we kept. | 276 // reference to child3 we kept. |
| 277 EXPECT_EQ(5, CountedBrowserAccessibility::global_obj_count_); | 277 EXPECT_EQ(5, CountedBrowserAccessibility::global_obj_count_); |
| 278 | 278 |
| 279 // Check that our references to the root, child1, and child2 are still valid, | 279 // Check that our references to the root, child1, and child2 are still valid, |
| 280 // but that the reference to child3 is now invalid. | 280 // but that the reference to child3 is now invalid. |
| 281 EXPECT_TRUE(root_accessible->instance_active()); | 281 EXPECT_TRUE(root_accessible->instance_active()); |
| 282 EXPECT_TRUE(child1_accessible->instance_active()); | 282 EXPECT_TRUE(child1_accessible->instance_active()); |
| 283 EXPECT_TRUE(child2_accessible->instance_active()); | 283 EXPECT_TRUE(child2_accessible->instance_active()); |
| 284 EXPECT_FALSE(child3_accessible->instance_active()); | 284 EXPECT_FALSE(child3_accessible->instance_active()); |
| 285 | 285 |
| 286 // Check that the index in parent has been updated. | 286 // Check that the index in parent has been updated. |
| 287 EXPECT_EQ(1, child1_accessible->index_in_parent()); | 287 EXPECT_EQ(1, child1_accessible->GetIndexInParent()); |
| 288 EXPECT_EQ(2, child2_accessible->index_in_parent()); | 288 EXPECT_EQ(2, child2_accessible->GetIndexInParent()); |
| 289 | 289 |
| 290 // Release our references. The object count should only decrease by 1 | 290 // Release our references. The object count should only decrease by 1 |
| 291 // for child3. | 291 // for child3. |
| 292 root_accessible->NativeReleaseReference(); | 292 root_accessible->NativeReleaseReference(); |
| 293 child1_accessible->NativeReleaseReference(); | 293 child1_accessible->NativeReleaseReference(); |
| 294 child2_accessible->NativeReleaseReference(); | 294 child2_accessible->NativeReleaseReference(); |
| 295 child3_accessible->NativeReleaseReference(); | 295 child3_accessible->NativeReleaseReference(); |
| 296 | 296 |
| 297 EXPECT_EQ(4, CountedBrowserAccessibility::global_obj_count_); | 297 EXPECT_EQ(4, CountedBrowserAccessibility::global_obj_count_); |
| 298 | 298 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 CountedBrowserAccessibility* child2_accessible = | 428 CountedBrowserAccessibility* child2_accessible = |
| 429 static_cast<CountedBrowserAccessibility*>( | 429 static_cast<CountedBrowserAccessibility*>( |
| 430 container_accessible->PlatformGetChild(1)); | 430 container_accessible->PlatformGetChild(1)); |
| 431 child2_accessible->NativeAddReference(); | 431 child2_accessible->NativeAddReference(); |
| 432 CountedBrowserAccessibility* child3_accessible = | 432 CountedBrowserAccessibility* child3_accessible = |
| 433 static_cast<CountedBrowserAccessibility*>( | 433 static_cast<CountedBrowserAccessibility*>( |
| 434 container_accessible->PlatformGetChild(2)); | 434 container_accessible->PlatformGetChild(2)); |
| 435 child3_accessible->NativeAddReference(); | 435 child3_accessible->NativeAddReference(); |
| 436 | 436 |
| 437 // Check the index in parent. | 437 // Check the index in parent. |
| 438 EXPECT_EQ(1, child2_accessible->index_in_parent()); | 438 EXPECT_EQ(1, child2_accessible->GetIndexInParent()); |
| 439 EXPECT_EQ(2, child3_accessible->index_in_parent()); | 439 EXPECT_EQ(2, child3_accessible->GetIndexInParent()); |
| 440 | 440 |
| 441 // Process a notification containing the changed subtree rooted at | 441 // Process a notification containing the changed subtree rooted at |
| 442 // the container. | 442 // the container. |
| 443 std::vector<AccessibilityHostMsg_EventParams> params; | 443 std::vector<AccessibilityHostMsg_EventParams> params; |
| 444 params.push_back(AccessibilityHostMsg_EventParams()); | 444 params.push_back(AccessibilityHostMsg_EventParams()); |
| 445 AccessibilityHostMsg_EventParams* msg = ¶ms[0]; | 445 AccessibilityHostMsg_EventParams* msg = ¶ms[0]; |
| 446 msg->event_type = ui::AX_EVENT_CHILDREN_CHANGED; | 446 msg->event_type = ui::AX_EVENT_CHILDREN_CHANGED; |
| 447 msg->update.nodes.push_back(tree2_container); | 447 msg->update.nodes.push_back(tree2_container); |
| 448 msg->update.nodes.push_back(tree2_child0); | 448 msg->update.nodes.push_back(tree2_child0); |
| 449 msg->update.nodes.push_back(tree2_grandchild0); | 449 msg->update.nodes.push_back(tree2_grandchild0); |
| 450 msg->id = tree2_container.id; | 450 msg->id = tree2_container.id; |
| 451 manager->OnAccessibilityEvents(params); | 451 manager->OnAccessibilityEvents(params); |
| 452 | 452 |
| 453 // There should be 9 objects now: the 8 from the new tree, plus the | 453 // There should be 9 objects now: the 8 from the new tree, plus the |
| 454 // reference to child3 we kept. | 454 // reference to child3 we kept. |
| 455 EXPECT_EQ(9, CountedBrowserAccessibility::global_obj_count_); | 455 EXPECT_EQ(9, CountedBrowserAccessibility::global_obj_count_); |
| 456 | 456 |
| 457 // Check that our references to the root and container and child2 are | 457 // Check that our references to the root and container and child2 are |
| 458 // still valid, but that the reference to child3 is now invalid. | 458 // still valid, but that the reference to child3 is now invalid. |
| 459 EXPECT_TRUE(root_accessible->instance_active()); | 459 EXPECT_TRUE(root_accessible->instance_active()); |
| 460 EXPECT_TRUE(container_accessible->instance_active()); | 460 EXPECT_TRUE(container_accessible->instance_active()); |
| 461 EXPECT_TRUE(child2_accessible->instance_active()); | 461 EXPECT_TRUE(child2_accessible->instance_active()); |
| 462 EXPECT_FALSE(child3_accessible->instance_active()); | 462 EXPECT_FALSE(child3_accessible->instance_active()); |
| 463 | 463 |
| 464 // Ensure that we retain the parent of the detached subtree. | 464 // Ensure that we retain the parent of the detached subtree. |
| 465 EXPECT_EQ(root_accessible, container_accessible->parent()); | 465 EXPECT_EQ(root_accessible, container_accessible->GetParent()); |
| 466 EXPECT_EQ(0, container_accessible->index_in_parent()); | 466 EXPECT_EQ(0, container_accessible->GetIndexInParent()); |
| 467 | 467 |
| 468 // Check that the index in parent has been updated. | 468 // Check that the index in parent has been updated. |
| 469 EXPECT_EQ(2, child2_accessible->index_in_parent()); | 469 EXPECT_EQ(2, child2_accessible->GetIndexInParent()); |
| 470 | 470 |
| 471 // Release our references. The object count should only decrease by 1 | 471 // Release our references. The object count should only decrease by 1 |
| 472 // for child3. | 472 // for child3. |
| 473 root_accessible->NativeReleaseReference(); | 473 root_accessible->NativeReleaseReference(); |
| 474 container_accessible->NativeReleaseReference(); | 474 container_accessible->NativeReleaseReference(); |
| 475 child2_accessible->NativeReleaseReference(); | 475 child2_accessible->NativeReleaseReference(); |
| 476 child3_accessible->NativeReleaseReference(); | 476 child3_accessible->NativeReleaseReference(); |
| 477 | 477 |
| 478 EXPECT_EQ(8, CountedBrowserAccessibility::global_obj_count_); | 478 EXPECT_EQ(8, CountedBrowserAccessibility::global_obj_count_); |
| 479 | 479 |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 ASSERT_EQ(NULL, manager->NextInTreeOrder(node5_accessible)); | 929 ASSERT_EQ(NULL, manager->NextInTreeOrder(node5_accessible)); |
| 930 | 930 |
| 931 ASSERT_EQ(NULL, manager->PreviousInTreeOrder(NULL)); | 931 ASSERT_EQ(NULL, manager->PreviousInTreeOrder(NULL)); |
| 932 ASSERT_EQ(node4_accessible, manager->PreviousInTreeOrder(node5_accessible)); | 932 ASSERT_EQ(node4_accessible, manager->PreviousInTreeOrder(node5_accessible)); |
| 933 ASSERT_EQ(node3_accessible, manager->PreviousInTreeOrder(node4_accessible)); | 933 ASSERT_EQ(node3_accessible, manager->PreviousInTreeOrder(node4_accessible)); |
| 934 ASSERT_EQ(node2_accessible, manager->PreviousInTreeOrder(node3_accessible)); | 934 ASSERT_EQ(node2_accessible, manager->PreviousInTreeOrder(node3_accessible)); |
| 935 ASSERT_EQ(root_accessible, manager->PreviousInTreeOrder(node2_accessible)); | 935 ASSERT_EQ(root_accessible, manager->PreviousInTreeOrder(node2_accessible)); |
| 936 } | 936 } |
| 937 | 937 |
| 938 } // namespace content | 938 } // namespace content |
| OLD | NEW |