| 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 "chrome/browser/accessibility/browser_accessibility.h" | 7 #include "chrome/browser/accessibility/browser_accessibility.h" |
| 8 #include "chrome/browser/accessibility/browser_accessibility_manager.h" | 8 #include "chrome/browser/accessibility/browser_accessibility_manager.h" |
| 9 #include "chrome/common/render_messages_params.h" | 9 #include "content/common/view_messages.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "webkit/glue/webaccessibility.h" | 11 #include "webkit/glue/webaccessibility.h" |
| 12 | 12 |
| 13 using webkit_glue::WebAccessibility; | 13 using webkit_glue::WebAccessibility; |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Subclass of BrowserAccessibility that counts the number of instances. | 17 // Subclass of BrowserAccessibility that counts the number of instances. |
| 18 class CountedBrowserAccessibility : public BrowserAccessibility { | 18 class CountedBrowserAccessibility : public BrowserAccessibility { |
| 19 public: | 19 public: |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 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_AccessibilityNotification_Params:: | 233 msg->notification_type = ViewHostMsg_AccessibilityNotification_Type:: |
| 234 NOTIFICATION_TYPE_CHILDREN_CHANGED; | 234 NOTIFICATION_TYPE_CHILDREN_CHANGED; |
| 235 msg->acc_obj = tree2_root; | 235 msg->acc_obj = tree2_root; |
| 236 manager->OnAccessibilityNotifications(params); | 236 manager->OnAccessibilityNotifications(params); |
| 237 | 237 |
| 238 // There should be 5 objects now: the 4 from the new tree, plus the | 238 // There should be 5 objects now: the 4 from the new tree, plus the |
| 239 // reference to child3 we kept. | 239 // reference to child3 we kept. |
| 240 EXPECT_EQ(5, CountedBrowserAccessibility::global_obj_count_); | 240 EXPECT_EQ(5, CountedBrowserAccessibility::global_obj_count_); |
| 241 | 241 |
| 242 // Check that our references to the root, child1, and child2 are still valid, | 242 // Check that our references to the root, child1, and child2 are still valid, |
| 243 // but that the reference to child3 is now invalid. | 243 // but that the reference to child3 is now invalid. |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 428 |
| 429 // Check the index in parent. | 429 // Check the index in parent. |
| 430 EXPECT_EQ(1, child2_accessible->index_in_parent()); | 430 EXPECT_EQ(1, child2_accessible->index_in_parent()); |
| 431 EXPECT_EQ(2, child3_accessible->index_in_parent()); | 431 EXPECT_EQ(2, child3_accessible->index_in_parent()); |
| 432 | 432 |
| 433 // Process a notification containing the changed subtree rooted at | 433 // Process a notification containing the changed subtree rooted at |
| 434 // the container. | 434 // the container. |
| 435 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; | 435 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; |
| 436 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); | 436 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); |
| 437 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; | 437 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; |
| 438 msg->notification_type = ViewHostMsg_AccessibilityNotification_Params:: | 438 msg->notification_type = ViewHostMsg_AccessibilityNotification_Type:: |
| 439 NOTIFICATION_TYPE_CHILDREN_CHANGED; | 439 NOTIFICATION_TYPE_CHILDREN_CHANGED; |
| 440 msg->acc_obj = tree2_container; | 440 msg->acc_obj = tree2_container; |
| 441 manager->OnAccessibilityNotifications(params); | 441 manager->OnAccessibilityNotifications(params); |
| 442 | 442 |
| 443 // There should be 9 objects now: the 8 from the new tree, plus the | 443 // There should be 9 objects now: the 8 from the new tree, plus the |
| 444 // reference to child3 we kept. | 444 // reference to child3 we kept. |
| 445 EXPECT_EQ(9, CountedBrowserAccessibility::global_obj_count_); | 445 EXPECT_EQ(9, CountedBrowserAccessibility::global_obj_count_); |
| 446 | 446 |
| 447 // Check that our references to the root and container and child2 are | 447 // Check that our references to the root and container and child2 are |
| 448 // still valid, but that the reference to child3 is now invalid. | 448 // still valid, but that the reference to child3 is now invalid. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 NULL, | 528 NULL, |
| 529 tree1_1, | 529 tree1_1, |
| 530 NULL, | 530 NULL, |
| 531 new CountedBrowserAccessibilityFactory()); | 531 new CountedBrowserAccessibilityFactory()); |
| 532 ASSERT_EQ(4, CountedBrowserAccessibility::global_obj_count_); | 532 ASSERT_EQ(4, CountedBrowserAccessibility::global_obj_count_); |
| 533 | 533 |
| 534 // Process a notification containing the changed subtree. | 534 // Process a notification containing the changed subtree. |
| 535 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; | 535 std::vector<ViewHostMsg_AccessibilityNotification_Params> params; |
| 536 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); | 536 params.push_back(ViewHostMsg_AccessibilityNotification_Params()); |
| 537 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; | 537 ViewHostMsg_AccessibilityNotification_Params* msg = ¶ms[0]; |
| 538 msg->notification_type = ViewHostMsg_AccessibilityNotification_Params:: | 538 msg->notification_type = ViewHostMsg_AccessibilityNotification_Type:: |
| 539 NOTIFICATION_TYPE_CHILDREN_CHANGED; | 539 NOTIFICATION_TYPE_CHILDREN_CHANGED; |
| 540 msg->acc_obj = tree2_1; | 540 msg->acc_obj = tree2_1; |
| 541 manager->OnAccessibilityNotifications(params); | 541 manager->OnAccessibilityNotifications(params); |
| 542 | 542 |
| 543 // There should be 4 objects now. | 543 // There should be 4 objects now. |
| 544 EXPECT_EQ(4, CountedBrowserAccessibility::global_obj_count_); | 544 EXPECT_EQ(4, CountedBrowserAccessibility::global_obj_count_); |
| 545 | 545 |
| 546 // Delete the manager and make sure all memory is cleaned up. | 546 // Delete the manager and make sure all memory is cleaned up. |
| 547 delete manager; | 547 delete manager; |
| 548 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 548 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
| 549 } | 549 } |
| OLD | NEW |