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/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
6 #include "chrome/browser/browser_accessibility_manager.h" | 6 #include "chrome/browser/browser_accessibility_manager.h" |
7 #include "chrome/browser/browser_accessibility.h" | 7 #include "chrome/browser/browser_accessibility.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 using webkit_glue::WebAccessibility; | 10 using webkit_glue::WebAccessibility; |
(...skipping 29 matching lines...) Expand all Loading... |
40 _pAtlModule = &module; | 40 _pAtlModule = &module; |
41 // Make sure COM is initialized for this thread; it's safe to call twice. | 41 // Make sure COM is initialized for this thread; it's safe to call twice. |
42 ::CoInitialize(NULL); | 42 ::CoInitialize(NULL); |
43 | 43 |
44 // Create WebAccessibility objects for a simple document tree, | 44 // Create WebAccessibility objects for a simple document tree, |
45 // representing the accessibility information used to initialize | 45 // representing the accessibility information used to initialize |
46 // BrowserAccessibilityManager. | 46 // BrowserAccessibilityManager. |
47 WebAccessibility button; | 47 WebAccessibility button; |
48 button.id = 2; | 48 button.id = 2; |
49 button.name = L"Button"; | 49 button.name = L"Button"; |
50 button.role = WebAccessibility::ROLE_PUSHBUTTON; | 50 button.role = WebAccessibility::ROLE_BUTTON; |
51 button.state = 0; | 51 button.state = 0; |
52 | 52 |
53 WebAccessibility checkbox; | 53 WebAccessibility checkbox; |
54 checkbox.id = 3; | 54 checkbox.id = 3; |
55 checkbox.name = L"Checkbox"; | 55 checkbox.name = L"Checkbox"; |
56 checkbox.role = WebAccessibility::ROLE_CHECKBUTTON; | 56 checkbox.role = WebAccessibility::ROLE_CHECKBOX; |
57 checkbox.state = 0; | 57 checkbox.state = 0; |
58 | 58 |
59 WebAccessibility root; | 59 WebAccessibility root; |
60 root.id = 1; | 60 root.id = 1; |
61 root.name = L"Document"; | 61 root.name = L"Document"; |
62 root.role = WebAccessibility::ROLE_DOCUMENT; | 62 root.role = WebAccessibility::ROLE_DOCUMENT; |
63 root.state = 0; | 63 root.state = 0; |
64 root.children.push_back(button); | 64 root.children.push_back(button); |
65 root.children.push_back(checkbox); | 65 root.children.push_back(checkbox); |
66 | 66 |
67 // Construct a BrowserAccessibilityManager with this WebAccessibility tree | 67 // Construct a BrowserAccessibilityManager with this WebAccessibility tree |
68 // and a factory for an instance-counting BrowserAccessibility, and ensure | 68 // and a factory for an instance-counting BrowserAccessibility, and ensure |
69 // that exactly 3 instances were created. Note that the manager takes | 69 // that exactly 3 instances were created. Note that the manager takes |
70 // ownership of the factory. | 70 // ownership of the factory. |
71 CountedBrowserAccessibility::global_obj_count_ = 0; | 71 CountedBrowserAccessibility::global_obj_count_ = 0; |
72 BrowserAccessibilityManager* manager = | 72 BrowserAccessibilityManager* manager = |
73 new BrowserAccessibilityManager( | 73 new BrowserAccessibilityManager( |
74 GetDesktopWindow(), root, new CountedBrowserAccessibilityFactory()); | 74 GetDesktopWindow(), root, NULL, |
| 75 new CountedBrowserAccessibilityFactory()); |
75 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); | 76 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); |
76 | 77 |
77 // Delete the manager and test that all 3 instances are deleted. | 78 // Delete the manager and test that all 3 instances are deleted. |
78 delete manager; | 79 delete manager; |
79 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 80 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
80 | 81 |
81 // Construct a manager again, and this time use the IAccessible interface | 82 // Construct a manager again, and this time use the IAccessible interface |
82 // to get new references to two of the three nodes in the tree. | 83 // to get new references to two of the three nodes in the tree. |
83 manager = new BrowserAccessibilityManager( | 84 manager = new BrowserAccessibilityManager( |
84 GetDesktopWindow(), root, new CountedBrowserAccessibilityFactory()); | 85 GetDesktopWindow(), root, NULL, |
| 86 new CountedBrowserAccessibilityFactory()); |
85 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); | 87 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); |
86 BrowserAccessibility* root_accessible = manager->GetRoot(); | 88 BrowserAccessibility* root_accessible = manager->GetRoot(); |
87 IDispatch* root_iaccessible = NULL; | 89 IDispatch* root_iaccessible = NULL; |
88 IDispatch* child1_iaccessible = NULL; | 90 IDispatch* child1_iaccessible = NULL; |
89 VARIANT var_child; | 91 VARIANT var_child; |
90 var_child.vt = VT_I4; | 92 var_child.vt = VT_I4; |
91 var_child.lVal = CHILDID_SELF; | 93 var_child.lVal = CHILDID_SELF; |
92 HRESULT hr = root_accessible->get_accChild(var_child, &root_iaccessible); | 94 HRESULT hr = root_accessible->get_accChild(var_child, &root_iaccessible); |
93 ASSERT_EQ(S_OK, hr); | 95 ASSERT_EQ(S_OK, hr); |
94 var_child.lVal = 1; | 96 var_child.lVal = 1; |
95 hr = root_accessible->get_accChild(var_child, &child1_iaccessible); | 97 hr = root_accessible->get_accChild(var_child, &child1_iaccessible); |
96 ASSERT_EQ(S_OK, hr); | 98 ASSERT_EQ(S_OK, hr); |
97 | 99 |
98 // Now delete the manager, and only one of the three nodes in the tree | 100 // Now delete the manager, and only one of the three nodes in the tree |
99 // should be released. | 101 // should be released. |
100 delete manager; | 102 delete manager; |
101 ASSERT_EQ(2, CountedBrowserAccessibility::global_obj_count_); | 103 ASSERT_EQ(2, CountedBrowserAccessibility::global_obj_count_); |
102 | 104 |
103 // Release each of our references and make sure that each one results in | 105 // Release each of our references and make sure that each one results in |
104 // the instance being deleted as its reference count hits zero. | 106 // the instance being deleted as its reference count hits zero. |
105 root_iaccessible->Release(); | 107 root_iaccessible->Release(); |
106 ASSERT_EQ(1, CountedBrowserAccessibility::global_obj_count_); | 108 ASSERT_EQ(1, CountedBrowserAccessibility::global_obj_count_); |
107 child1_iaccessible->Release(); | 109 child1_iaccessible->Release(); |
108 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 110 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
109 } | 111 } |
OLD | NEW |