OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string16.h" | 5 #include "base/string16.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/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 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // Check the index in parent. | 224 // Check the index in parent. |
225 EXPECT_EQ(0, child1_accessible->index_in_parent()); | 225 EXPECT_EQ(0, child1_accessible->index_in_parent()); |
226 EXPECT_EQ(1, child2_accessible->index_in_parent()); | 226 EXPECT_EQ(1, child2_accessible->index_in_parent()); |
227 EXPECT_EQ(2, child3_accessible->index_in_parent()); | 227 EXPECT_EQ(2, child3_accessible->index_in_parent()); |
228 | 228 |
229 // Process a notification containing the changed subtree. | 229 // Process a notification containing the changed subtree. |
230 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; | 230 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; |
231 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); | 231 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); |
232 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; | 232 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; |
233 msg->notification_type = ViewHostMsg_AccEvent::CHILDREN_CHANGED; | 233 msg->notification_type = ViewHostMsg_AccEvent::CHILDREN_CHANGED; |
234 msg->acc_obj = tree2_root; | 234 msg->acc_tree = tree2_root; |
| 235 msg->includes_children = true; |
| 236 msg->id = tree2_root.id; |
235 manager->OnAccessibilityNotifications(params); | 237 manager->OnAccessibilityNotifications(params); |
236 | 238 |
237 // There should be 5 objects now: the 4 from the new tree, plus the | 239 // There should be 5 objects now: the 4 from the new tree, plus the |
238 // reference to child3 we kept. | 240 // reference to child3 we kept. |
239 EXPECT_EQ(5, CountedBrowserAccessibility::global_obj_count_); | 241 EXPECT_EQ(5, CountedBrowserAccessibility::global_obj_count_); |
240 | 242 |
241 // Check that our references to the root, child1, and child2 are still valid, | 243 // Check that our references to the root, child1, and child2 are still valid, |
242 // but that the reference to child3 is now invalid. | 244 // but that the reference to child3 is now invalid. |
243 EXPECT_TRUE(root_accessible->instance_active()); | 245 EXPECT_TRUE(root_accessible->instance_active()); |
244 EXPECT_TRUE(child1_accessible->instance_active()); | 246 EXPECT_TRUE(child1_accessible->instance_active()); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 // Check the index in parent. | 430 // Check the index in parent. |
429 EXPECT_EQ(1, child2_accessible->index_in_parent()); | 431 EXPECT_EQ(1, child2_accessible->index_in_parent()); |
430 EXPECT_EQ(2, child3_accessible->index_in_parent()); | 432 EXPECT_EQ(2, child3_accessible->index_in_parent()); |
431 | 433 |
432 // Process a notification containing the changed subtree rooted at | 434 // Process a notification containing the changed subtree rooted at |
433 // the container. | 435 // the container. |
434 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; | 436 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; |
435 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); | 437 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); |
436 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; | 438 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; |
437 msg->notification_type = ViewHostMsg_AccEvent::CHILDREN_CHANGED; | 439 msg->notification_type = ViewHostMsg_AccEvent::CHILDREN_CHANGED; |
438 msg->acc_obj = tree2_container; | 440 msg->acc_tree = tree2_container; |
| 441 msg->includes_children = true; |
| 442 msg->id = tree2_container.id; |
439 manager->OnAccessibilityNotifications(params); | 443 manager->OnAccessibilityNotifications(params); |
440 | 444 |
441 // There should be 9 objects now: the 8 from the new tree, plus the | 445 // There should be 9 objects now: the 8 from the new tree, plus the |
442 // reference to child3 we kept. | 446 // reference to child3 we kept. |
443 EXPECT_EQ(9, CountedBrowserAccessibility::global_obj_count_); | 447 EXPECT_EQ(9, CountedBrowserAccessibility::global_obj_count_); |
444 | 448 |
445 // Check that our references to the root and container and child2 are | 449 // Check that our references to the root and container and child2 are |
446 // still valid, but that the reference to child3 is now invalid. | 450 // still valid, but that the reference to child3 is now invalid. |
447 EXPECT_TRUE(root_accessible->instance_active()); | 451 EXPECT_TRUE(root_accessible->instance_active()); |
448 EXPECT_TRUE(container_accessible->instance_active()); | 452 EXPECT_TRUE(container_accessible->instance_active()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 tree1_1, | 535 tree1_1, |
532 NULL, | 536 NULL, |
533 new CountedBrowserAccessibilityFactory()); | 537 new CountedBrowserAccessibilityFactory()); |
534 ASSERT_EQ(4, CountedBrowserAccessibility::global_obj_count_); | 538 ASSERT_EQ(4, CountedBrowserAccessibility::global_obj_count_); |
535 | 539 |
536 // Process a notification containing the changed subtree. | 540 // Process a notification containing the changed subtree. |
537 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; | 541 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; |
538 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); | 542 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); |
539 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; | 543 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; |
540 msg->notification_type = ViewHostMsg_AccEvent::CHILDREN_CHANGED; | 544 msg->notification_type = ViewHostMsg_AccEvent::CHILDREN_CHANGED; |
541 msg->acc_obj = tree2_1; | 545 msg->acc_tree = tree2_1; |
| 546 msg->includes_children = true; |
| 547 msg->id = tree2_1.id; |
542 manager->OnAccessibilityNotifications(params); | 548 manager->OnAccessibilityNotifications(params); |
543 | 549 |
544 // There should be 4 objects now. | 550 // There should be 4 objects now. |
545 EXPECT_EQ(4, CountedBrowserAccessibility::global_obj_count_); | 551 EXPECT_EQ(4, CountedBrowserAccessibility::global_obj_count_); |
546 | 552 |
547 // Delete the manager and make sure all memory is cleaned up. | 553 // Delete the manager and make sure all memory is cleaned up. |
548 delete manager; | 554 delete manager; |
549 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 555 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
550 } | 556 } |
551 | 557 |
552 TEST(BrowserAccessibilityManagerTest, TestCreateEmptyDocument) { | 558 TEST(BrowserAccessibilityManagerTest, TestCreateEmptyDocument) { |
553 // Try creating an empty document with busy state. | 559 // Try creating an empty document with busy state. |
554 scoped_ptr<BrowserAccessibilityManager> manager; | 560 scoped_ptr<BrowserAccessibilityManager> manager; |
555 manager.reset(BrowserAccessibilityManager::CreateEmptyDocument( | 561 manager.reset(BrowserAccessibilityManager::CreateEmptyDocument( |
556 NULL, | 562 NULL, |
557 WebAccessibility::STATE_BUSY, | 563 WebAccessibility::STATE_BUSY, |
558 NULL, | 564 NULL, |
559 new CountedBrowserAccessibilityFactory())); | 565 new CountedBrowserAccessibilityFactory())); |
560 | 566 |
561 // Verify the root is as we expect by default. | 567 // Verify the root is as we expect by default. |
562 BrowserAccessibility* root = manager->GetRoot(); | 568 BrowserAccessibility* root = manager->GetRoot(); |
563 EXPECT_EQ(1000, root->renderer_id()); | 569 EXPECT_EQ(0, root->renderer_id()); |
564 EXPECT_EQ(WebAccessibility::ROLE_WEB_AREA, root->role()); | 570 EXPECT_EQ(WebAccessibility::ROLE_ROOT_WEB_AREA, root->role()); |
565 EXPECT_EQ(WebAccessibility::STATE_BUSY, root->state()); | 571 EXPECT_EQ(WebAccessibility::STATE_BUSY, root->state()); |
566 | 572 |
567 // Tree with a child textfield. | 573 // Tree with a child textfield. |
568 WebAccessibility tree1_1; | 574 WebAccessibility tree1_1; |
569 tree1_1.id = 1000; | 575 tree1_1.id = 1; |
570 tree1_1.role = WebAccessibility::ROLE_WEB_AREA; | 576 tree1_1.role = WebAccessibility::ROLE_ROOT_WEB_AREA; |
571 | 577 |
572 WebAccessibility tree1_2; | 578 WebAccessibility tree1_2; |
573 tree1_2.id = 1001; | 579 tree1_2.id = 2; |
574 tree1_2.role = WebAccessibility::ROLE_TEXT_FIELD; | 580 tree1_2.role = WebAccessibility::ROLE_TEXT_FIELD; |
575 | 581 |
576 tree1_1.children.push_back(tree1_2); | 582 tree1_1.children.push_back(tree1_2); |
577 | 583 |
578 // Process a load complete. | 584 // Process a load complete. |
579 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; | 585 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; |
580 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); | 586 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); |
581 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; | 587 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; |
582 msg->notification_type = ViewHostMsg_AccEvent::LOAD_COMPLETE; | 588 msg->notification_type = ViewHostMsg_AccEvent::LOAD_COMPLETE; |
583 msg->acc_obj = tree1_1; | 589 msg->acc_tree = tree1_1; |
584 | 590 msg->includes_children = true; |
| 591 msg->id = tree1_1.id; |
585 manager->OnAccessibilityNotifications(params); | 592 manager->OnAccessibilityNotifications(params); |
586 | 593 |
587 // Save for later comparison. | 594 // Save for later comparison. |
588 BrowserAccessibility* acc1_2 = manager->GetFromRendererID(1001); | 595 BrowserAccessibility* acc1_2 = manager->GetFromRendererID(2); |
589 | 596 |
590 // Verify the root has not changed. | 597 // Verify the root has not changed. |
591 EXPECT_EQ(root, manager->GetRoot()); | 598 EXPECT_EQ(root, manager->GetRoot()); |
592 | 599 |
593 // And the proper child remains. | 600 // And the proper child remains. |
594 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, acc1_2->role()); | 601 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, acc1_2->role()); |
595 EXPECT_EQ(1001, acc1_2->renderer_id()); | 602 EXPECT_EQ(2, acc1_2->renderer_id()); |
596 | 603 |
597 // Tree with a child button. | 604 // Tree with a child button. |
598 WebAccessibility tree2_1; | 605 WebAccessibility tree2_1; |
599 tree2_1.id = 1000; | 606 tree2_1.id = 1; |
600 tree2_1.role = WebAccessibility::ROLE_WEB_AREA; | 607 tree2_1.role = WebAccessibility::ROLE_ROOT_WEB_AREA; |
601 | 608 |
602 WebAccessibility tree2_2; | 609 WebAccessibility tree2_2; |
603 tree2_2.id = 1002; | 610 tree2_2.id = 3; |
604 tree2_2.role = WebAccessibility::ROLE_BUTTON; | 611 tree2_2.role = WebAccessibility::ROLE_BUTTON; |
605 | 612 |
606 tree2_1.children.push_back(tree2_2); | 613 tree2_1.children.push_back(tree2_2); |
607 | 614 |
608 msg->acc_obj = tree2_1; | 615 msg->acc_tree = tree2_1; |
| 616 msg->includes_children = true; |
| 617 msg->id = tree2_1.id; |
609 | 618 |
610 // Fire another load complete. | 619 // Fire another load complete. |
611 manager->OnAccessibilityNotifications(params); | 620 manager->OnAccessibilityNotifications(params); |
612 | 621 |
613 BrowserAccessibility* acc2_2 = manager->GetFromRendererID(1002); | 622 BrowserAccessibility* acc2_2 = manager->GetFromRendererID(3); |
614 | 623 |
615 // Verify the root has not changed. | 624 // Verify the root has not changed. |
616 EXPECT_EQ(root, manager->GetRoot()); | 625 EXPECT_EQ(root, manager->GetRoot()); |
617 | 626 |
618 // And the new child exists. | 627 // And the new child exists. |
619 EXPECT_EQ(WebAccessibility::ROLE_BUTTON, acc2_2->role()); | 628 EXPECT_EQ(WebAccessibility::ROLE_BUTTON, acc2_2->role()); |
620 EXPECT_EQ(1002, acc2_2->renderer_id()); | 629 EXPECT_EQ(3, acc2_2->renderer_id()); |
621 | 630 |
622 // Ensure we properly cleaned up. | 631 // Ensure we properly cleaned up. |
623 manager.reset(); | 632 manager.reset(); |
624 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 633 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
625 } | 634 } |
OLD | NEW |