OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 msg->acc_obj = tree2_1; | 544 msg->acc_obj = tree2_1; |
545 manager->OnAccessibilityNotifications(params); | 545 manager->OnAccessibilityNotifications(params); |
546 | 546 |
547 // There should be 4 objects now. | 547 // There should be 4 objects now. |
548 EXPECT_EQ(4, CountedBrowserAccessibility::global_obj_count_); | 548 EXPECT_EQ(4, CountedBrowserAccessibility::global_obj_count_); |
549 | 549 |
550 // Delete the manager and make sure all memory is cleaned up. | 550 // Delete the manager and make sure all memory is cleaned up. |
551 delete manager; | 551 delete manager; |
552 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 552 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
553 } | 553 } |
554 | |
555 TEST(BrowserAccessibilityManagerTest, TestCreateEmptyDocument) { | |
556 // Try creating an empty document with busy state. | |
557 BrowserAccessibilityManager* manager = | |
558 BrowserAccessibilityManager::CreateEmptyDocument( | |
559 NULL, | |
560 WebAccessibility::STATE_BUSY, | |
561 NULL, | |
562 new CountedBrowserAccessibilityFactory()); | |
563 | |
564 // Verify the root is as we expect by default. | |
dmazzoni
2011/08/04 16:29:07
Indent comment
David Tseng
2011/08/04 16:41:58
Done.
| |
565 BrowserAccessibility* root = manager->GetRoot(); | |
566 EXPECT_EQ(1000, root->renderer_id()); | |
567 EXPECT_EQ(WebAccessibility::ROLE_WEB_AREA, root->role()); | |
568 EXPECT_EQ(WebAccessibility::STATE_BUSY, root->state()); | |
569 | |
570 // Tree with a child textfield. | |
571 WebAccessibility tree1_1; | |
572 tree1_1.id = 1000; | |
573 tree1_1.role = WebAccessibility::ROLE_WEB_AREA; | |
574 | |
575 WebAccessibility tree1_2; | |
576 tree1_2.id = 1001; | |
577 tree1_2.role = WebAccessibility::ROLE_TEXT_FIELD; | |
578 | |
579 tree1_1.children.push_back(tree1_2); | |
580 | |
581 // Process a load complete. | |
582 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; | |
583 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); | |
584 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; | |
585 msg->notification_type = ViewHostMsg_AccessibilityNotification_Type:: | |
586 NOTIFICATION_TYPE_LOAD_COMPLETE; | |
587 msg->acc_obj = tree1_1; | |
588 | |
589 manager->OnAccessibilityNotifications(params); | |
590 | |
591 // Save for later comparison. | |
592 BrowserAccessibility* acc1_2 = manager->GetFromRendererID(1001); | |
593 | |
594 // Verify the root has not changed. | |
595 EXPECT_EQ(root, manager->GetRoot()); | |
596 | |
597 // And the proper child remains. | |
598 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, acc1_2->role()); | |
599 EXPECT_EQ(1001, acc1_2->renderer_id()); | |
600 | |
601 // Tree with a child button. | |
602 WebAccessibility tree2_1; | |
603 tree2_1.id = 1000; | |
604 tree2_1.role = WebAccessibility::ROLE_WEB_AREA; | |
605 | |
606 WebAccessibility tree2_2; | |
607 tree2_2.id = 1001; | |
608 tree2_2.role = WebAccessibility::ROLE_BUTTON; | |
609 | |
610 tree2_1.children.push_back(tree2_2); | |
611 | |
612 msg->acc_obj = tree2_1; | |
613 | |
614 // Fire another load complete. | |
615 manager->OnAccessibilityNotifications(params); | |
616 | |
617 BrowserAccessibility* acc2_2 = manager->GetFromRendererID(1001); | |
618 | |
619 // Verify the root has not changed. | |
620 EXPECT_EQ(root, manager->GetRoot()); | |
621 | |
622 // And the proper child remains. | |
623 EXPECT_EQ(WebAccessibility::ROLE_BUTTON, acc2_2->role()); | |
624 EXPECT_EQ(1001, acc2_2->renderer_id()); | |
625 | |
626 // Verify we don't reuse objects that have changed roles. | |
627 EXPECT_NE(acc1_2, acc2_2); | |
628 } | |
OLD | NEW |