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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/win/scoped_bstr.h" | 6 #include "base/win/scoped_bstr.h" |
7 #include "base/win/scoped_comptr.h" | 7 #include "base/win/scoped_comptr.h" |
8 #include "base/win/scoped_variant.h" | 8 #include "base/win/scoped_variant.h" |
9 #include "content/browser/accessibility/browser_accessibility_manager.h" | 9 #include "content/browser/accessibility/browser_accessibility_manager.h" |
10 #include "content/browser/accessibility/browser_accessibility_manager_win.h" | 10 #include "content/browser/accessibility/browser_accessibility_manager_win.h" |
11 #include "content/browser/accessibility/browser_accessibility_win.h" | 11 #include "content/browser/accessibility/browser_accessibility_win.h" |
12 #include "content/common/accessibility_messages.h" | 12 #include "content/common/accessibility_messages.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "ui/base/win/atl_module.h" | 14 #include "ui/base/win/atl_module.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 namespace { | 17 namespace { |
18 | 18 |
| 19 |
| 20 // CountedBrowserAccessibility ------------------------------------------------ |
| 21 |
19 // Subclass of BrowserAccessibilityWin that counts the number of instances. | 22 // Subclass of BrowserAccessibilityWin that counts the number of instances. |
20 class CountedBrowserAccessibility : public BrowserAccessibilityWin { | 23 class CountedBrowserAccessibility : public BrowserAccessibilityWin { |
21 public: | 24 public: |
22 CountedBrowserAccessibility() { global_obj_count_++; } | 25 CountedBrowserAccessibility(); |
23 virtual ~CountedBrowserAccessibility() { global_obj_count_--; } | 26 virtual ~CountedBrowserAccessibility(); |
24 static int global_obj_count_; | 27 |
| 28 static void reset() { num_instances_ = 0; } |
| 29 static int num_instances() { return num_instances_; } |
| 30 |
| 31 private: |
| 32 static int num_instances_; |
| 33 |
| 34 DISALLOW_COPY_AND_ASSIGN(CountedBrowserAccessibility); |
25 }; | 35 }; |
26 | 36 |
27 int CountedBrowserAccessibility::global_obj_count_ = 0; | 37 // static |
| 38 int CountedBrowserAccessibility::num_instances_ = 0; |
| 39 |
| 40 CountedBrowserAccessibility::CountedBrowserAccessibility() { |
| 41 ++num_instances_; |
| 42 } |
| 43 |
| 44 CountedBrowserAccessibility::~CountedBrowserAccessibility() { |
| 45 --num_instances_; |
| 46 } |
| 47 |
| 48 |
| 49 // CountedBrowserAccessibilityFactory ----------------------------------------- |
28 | 50 |
29 // Factory that creates a CountedBrowserAccessibility. | 51 // Factory that creates a CountedBrowserAccessibility. |
30 class CountedBrowserAccessibilityFactory | 52 class CountedBrowserAccessibilityFactory : public BrowserAccessibilityFactory { |
31 : public BrowserAccessibilityFactory { | |
32 public: | 53 public: |
33 virtual ~CountedBrowserAccessibilityFactory() {} | 54 CountedBrowserAccessibilityFactory(); |
34 virtual BrowserAccessibility* Create() { | 55 |
35 CComObject<CountedBrowserAccessibility>* instance; | 56 private: |
36 HRESULT hr = CComObject<CountedBrowserAccessibility>::CreateInstance( | 57 virtual ~CountedBrowserAccessibilityFactory(); |
37 &instance); | 58 |
38 DCHECK(SUCCEEDED(hr)); | 59 virtual BrowserAccessibility* Create() OVERRIDE; |
39 instance->AddRef(); | 60 |
40 return instance; | 61 DISALLOW_COPY_AND_ASSIGN(CountedBrowserAccessibilityFactory); |
41 } | |
42 }; | 62 }; |
43 | 63 |
44 } // anonymous namespace | 64 CountedBrowserAccessibilityFactory::CountedBrowserAccessibilityFactory() { |
| 65 } |
| 66 |
| 67 CountedBrowserAccessibilityFactory::~CountedBrowserAccessibilityFactory() { |
| 68 } |
| 69 |
| 70 BrowserAccessibility* CountedBrowserAccessibilityFactory::Create() { |
| 71 CComObject<CountedBrowserAccessibility>* instance; |
| 72 HRESULT hr = CComObject<CountedBrowserAccessibility>::CreateInstance( |
| 73 &instance); |
| 74 DCHECK(SUCCEEDED(hr)); |
| 75 instance->AddRef(); |
| 76 return instance; |
| 77 } |
| 78 |
| 79 } // namespace |
| 80 |
| 81 |
| 82 // BrowserAccessibilityTest --------------------------------------------------- |
45 | 83 |
46 class BrowserAccessibilityTest : public testing::Test { | 84 class BrowserAccessibilityTest : public testing::Test { |
47 public: | 85 public: |
48 BrowserAccessibilityTest() {} | 86 BrowserAccessibilityTest(); |
| 87 virtual ~BrowserAccessibilityTest(); |
49 | 88 |
50 private: | 89 private: |
51 virtual void SetUp() { | 90 virtual void SetUp() OVERRIDE; |
52 ui::win::CreateATLModuleIfNeeded(); | |
53 } | |
54 | 91 |
55 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityTest); | 92 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityTest); |
56 }; | 93 }; |
57 | 94 |
| 95 BrowserAccessibilityTest::BrowserAccessibilityTest() { |
| 96 } |
| 97 |
| 98 BrowserAccessibilityTest::~BrowserAccessibilityTest() { |
| 99 } |
| 100 |
| 101 void BrowserAccessibilityTest::SetUp() { |
| 102 ui::win::CreateATLModuleIfNeeded(); |
| 103 } |
| 104 |
| 105 |
| 106 // Actual tests --------------------------------------------------------------- |
| 107 |
58 // Test that BrowserAccessibilityManager correctly releases the tree of | 108 // Test that BrowserAccessibilityManager correctly releases the tree of |
59 // BrowserAccessibility instances upon delete. | 109 // BrowserAccessibility instances upon delete. |
60 TEST_F(BrowserAccessibilityTest, TestNoLeaks) { | 110 TEST_F(BrowserAccessibilityTest, TestNoLeaks) { |
61 // Create AccessibilityNodeData objects for a simple document tree, | 111 // Create AccessibilityNodeData objects for a simple document tree, |
62 // representing the accessibility information used to initialize | 112 // representing the accessibility information used to initialize |
63 // BrowserAccessibilityManager. | 113 // BrowserAccessibilityManager. |
64 AccessibilityNodeData button; | 114 AccessibilityNodeData button; |
65 button.id = 2; | 115 button.id = 2; |
66 button.name = L"Button"; | 116 button.name = L"Button"; |
67 button.role = AccessibilityNodeData::ROLE_BUTTON; | 117 button.role = AccessibilityNodeData::ROLE_BUTTON; |
(...skipping 10 matching lines...) Expand all Loading... |
78 root.name = L"Document"; | 128 root.name = L"Document"; |
79 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 129 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
80 root.state = 0; | 130 root.state = 0; |
81 root.child_ids.push_back(2); | 131 root.child_ids.push_back(2); |
82 root.child_ids.push_back(3); | 132 root.child_ids.push_back(3); |
83 | 133 |
84 // Construct a BrowserAccessibilityManager with this | 134 // Construct a BrowserAccessibilityManager with this |
85 // AccessibilityNodeData tree and a factory for an instance-counting | 135 // AccessibilityNodeData tree and a factory for an instance-counting |
86 // BrowserAccessibility, and ensure that exactly 3 instances were | 136 // BrowserAccessibility, and ensure that exactly 3 instances were |
87 // created. Note that the manager takes ownership of the factory. | 137 // created. Note that the manager takes ownership of the factory. |
88 CountedBrowserAccessibility::global_obj_count_ = 0; | 138 CountedBrowserAccessibility::reset(); |
89 BrowserAccessibilityManager* manager = | 139 scoped_ptr<BrowserAccessibilityManager> manager( |
90 BrowserAccessibilityManager::Create( | 140 BrowserAccessibilityManager::Create( |
91 root, | 141 root, NULL, new CountedBrowserAccessibilityFactory())); |
92 NULL, | |
93 new CountedBrowserAccessibilityFactory()); | |
94 manager->UpdateNodesForTesting(button, checkbox); | 142 manager->UpdateNodesForTesting(button, checkbox); |
95 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); | 143 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); |
96 | 144 |
97 // Delete the manager and test that all 3 instances are deleted. | 145 // Delete the manager and test that all 3 instances are deleted. |
98 delete manager; | 146 manager.reset(); |
99 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 147 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
100 | 148 |
101 // Construct a manager again, and this time use the IAccessible interface | 149 // Construct a manager again, and this time use the IAccessible interface |
102 // to get new references to two of the three nodes in the tree. | 150 // to get new references to two of the three nodes in the tree. |
103 manager = | 151 manager.reset(BrowserAccessibilityManager::Create( |
104 BrowserAccessibilityManager::Create( | 152 root, NULL, new CountedBrowserAccessibilityFactory())); |
105 root, | |
106 NULL, | |
107 new CountedBrowserAccessibilityFactory()); | |
108 manager->UpdateNodesForTesting(button, checkbox); | 153 manager->UpdateNodesForTesting(button, checkbox); |
109 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); | 154 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); |
110 IAccessible* root_accessible = | 155 IAccessible* root_accessible = |
111 manager->GetRoot()->ToBrowserAccessibilityWin(); | 156 manager->GetRoot()->ToBrowserAccessibilityWin(); |
112 IDispatch* root_iaccessible = NULL; | 157 IDispatch* root_iaccessible = NULL; |
113 IDispatch* child1_iaccessible = NULL; | 158 IDispatch* child1_iaccessible = NULL; |
114 base::win::ScopedVariant childid_self(CHILDID_SELF); | 159 base::win::ScopedVariant childid_self(CHILDID_SELF); |
115 HRESULT hr = root_accessible->get_accChild(childid_self, &root_iaccessible); | 160 HRESULT hr = root_accessible->get_accChild(childid_self, &root_iaccessible); |
116 ASSERT_EQ(S_OK, hr); | 161 ASSERT_EQ(S_OK, hr); |
117 base::win::ScopedVariant one(1); | 162 base::win::ScopedVariant one(1); |
118 hr = root_accessible->get_accChild(one, &child1_iaccessible); | 163 hr = root_accessible->get_accChild(one, &child1_iaccessible); |
119 ASSERT_EQ(S_OK, hr); | 164 ASSERT_EQ(S_OK, hr); |
120 | 165 |
121 // Now delete the manager, and only one of the three nodes in the tree | 166 // Now delete the manager, and only one of the three nodes in the tree |
122 // should be released. | 167 // should be released. |
123 delete manager; | 168 manager.reset(); |
124 ASSERT_EQ(2, CountedBrowserAccessibility::global_obj_count_); | 169 ASSERT_EQ(2, CountedBrowserAccessibility::num_instances()); |
125 | 170 |
126 // Release each of our references and make sure that each one results in | 171 // Release each of our references and make sure that each one results in |
127 // the instance being deleted as its reference count hits zero. | 172 // the instance being deleted as its reference count hits zero. |
128 root_iaccessible->Release(); | 173 root_iaccessible->Release(); |
129 ASSERT_EQ(1, CountedBrowserAccessibility::global_obj_count_); | 174 ASSERT_EQ(1, CountedBrowserAccessibility::num_instances()); |
130 child1_iaccessible->Release(); | 175 child1_iaccessible->Release(); |
131 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 176 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
132 } | 177 } |
133 | 178 |
134 TEST_F(BrowserAccessibilityTest, TestChildrenChange) { | 179 TEST_F(BrowserAccessibilityTest, TestChildrenChange) { |
135 // Create AccessibilityNodeData objects for a simple document tree, | 180 // Create AccessibilityNodeData objects for a simple document tree, |
136 // representing the accessibility information used to initialize | 181 // representing the accessibility information used to initialize |
137 // BrowserAccessibilityManager. | 182 // BrowserAccessibilityManager. |
138 AccessibilityNodeData text; | 183 AccessibilityNodeData text; |
139 text.id = 2; | 184 text.id = 2; |
140 text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 185 text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
141 text.name = L"old text"; | 186 text.name = L"old text"; |
142 text.state = 0; | 187 text.state = 0; |
143 | 188 |
144 AccessibilityNodeData root; | 189 AccessibilityNodeData root; |
145 root.id = 1; | 190 root.id = 1; |
146 root.name = L"Document"; | 191 root.name = L"Document"; |
147 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 192 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
148 root.state = 0; | 193 root.state = 0; |
149 root.child_ids.push_back(2); | 194 root.child_ids.push_back(2); |
150 | 195 |
151 // Construct a BrowserAccessibilityManager with this | 196 // Construct a BrowserAccessibilityManager with this |
152 // AccessibilityNodeData tree and a factory for an instance-counting | 197 // AccessibilityNodeData tree and a factory for an instance-counting |
153 // BrowserAccessibility. | 198 // BrowserAccessibility. |
154 CountedBrowserAccessibility::global_obj_count_ = 0; | 199 CountedBrowserAccessibility::reset(); |
155 BrowserAccessibilityManager* manager = | 200 scoped_ptr<BrowserAccessibilityManager> manager( |
156 BrowserAccessibilityManager::Create( | 201 BrowserAccessibilityManager::Create( |
157 root, | 202 root, NULL, new CountedBrowserAccessibilityFactory())); |
158 NULL, | |
159 new CountedBrowserAccessibilityFactory()); | |
160 manager->UpdateNodesForTesting(text); | 203 manager->UpdateNodesForTesting(text); |
161 | 204 |
162 // Query for the text IAccessible and verify that it returns "old text" as its | 205 // Query for the text IAccessible and verify that it returns "old text" as its |
163 // value. | 206 // value. |
164 base::win::ScopedVariant one(1); | 207 base::win::ScopedVariant one(1); |
165 base::win::ScopedComPtr<IDispatch> text_dispatch; | 208 base::win::ScopedComPtr<IDispatch> text_dispatch; |
166 HRESULT hr = manager->GetRoot()->ToBrowserAccessibilityWin()->get_accChild( | 209 HRESULT hr = manager->GetRoot()->ToBrowserAccessibilityWin()->get_accChild( |
167 one, text_dispatch.Receive()); | 210 one, text_dispatch.Receive()); |
168 ASSERT_EQ(S_OK, hr); | 211 ASSERT_EQ(S_OK, hr); |
169 | 212 |
(...skipping 17 matching lines...) Expand all Loading... |
187 param.notification_type = AccessibilityNotificationChildrenChanged; | 230 param.notification_type = AccessibilityNotificationChildrenChanged; |
188 param.nodes.push_back(text); | 231 param.nodes.push_back(text); |
189 param.id = text.id; | 232 param.id = text.id; |
190 std::vector<AccessibilityHostMsg_NotificationParams> notifications; | 233 std::vector<AccessibilityHostMsg_NotificationParams> notifications; |
191 notifications.push_back(param); | 234 notifications.push_back(param); |
192 manager->OnAccessibilityNotifications(notifications); | 235 manager->OnAccessibilityNotifications(notifications); |
193 | 236 |
194 // Query for the text IAccessible and verify that it now returns "new text" | 237 // Query for the text IAccessible and verify that it now returns "new text" |
195 // as its value. | 238 // as its value. |
196 hr = manager->GetRoot()->ToBrowserAccessibilityWin()->get_accChild( | 239 hr = manager->GetRoot()->ToBrowserAccessibilityWin()->get_accChild( |
197 one, | 240 one, text_dispatch.Receive()); |
198 text_dispatch.Receive()); | |
199 ASSERT_EQ(S_OK, hr); | 241 ASSERT_EQ(S_OK, hr); |
200 | 242 |
201 hr = text_dispatch.QueryInterface(text_accessible.Receive()); | 243 hr = text_dispatch.QueryInterface(text_accessible.Receive()); |
202 ASSERT_EQ(S_OK, hr); | 244 ASSERT_EQ(S_OK, hr); |
203 | 245 |
204 hr = text_accessible->get_accName(childid_self, name.Receive()); | 246 hr = text_accessible->get_accName(childid_self, name.Receive()); |
205 ASSERT_EQ(S_OK, hr); | 247 ASSERT_EQ(S_OK, hr); |
206 EXPECT_EQ(L"new text", string16(name)); | 248 EXPECT_EQ(L"new text", string16(name)); |
207 | 249 |
208 text_dispatch.Release(); | 250 text_dispatch.Release(); |
209 text_accessible.Release(); | 251 text_accessible.Release(); |
210 | 252 |
211 // Delete the manager and test that all BrowserAccessibility instances are | 253 // Delete the manager and test that all BrowserAccessibility instances are |
212 // deleted. | 254 // deleted. |
213 delete manager; | 255 manager.reset(); |
214 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 256 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
215 } | 257 } |
216 | 258 |
217 TEST_F(BrowserAccessibilityTest, TestChildrenChangeNoLeaks) { | 259 TEST_F(BrowserAccessibilityTest, TestChildrenChangeNoLeaks) { |
218 // Create AccessibilityNodeData objects for a simple document tree, | 260 // Create AccessibilityNodeData objects for a simple document tree, |
219 // representing the accessibility information used to initialize | 261 // representing the accessibility information used to initialize |
220 // BrowserAccessibilityManager. | 262 // BrowserAccessibilityManager. |
221 AccessibilityNodeData div; | 263 AccessibilityNodeData div; |
222 div.id = 2; | 264 div.id = 2; |
223 div.role = AccessibilityNodeData::ROLE_GROUP; | 265 div.role = AccessibilityNodeData::ROLE_GROUP; |
224 div.state = 0; | 266 div.state = 0; |
(...skipping 14 matching lines...) Expand all Loading... |
239 AccessibilityNodeData root; | 281 AccessibilityNodeData root; |
240 root.id = 1; | 282 root.id = 1; |
241 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 283 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
242 root.state = 0; | 284 root.state = 0; |
243 root.child_ids.push_back(2); | 285 root.child_ids.push_back(2); |
244 | 286 |
245 // Construct a BrowserAccessibilityManager with this | 287 // Construct a BrowserAccessibilityManager with this |
246 // AccessibilityNodeData tree and a factory for an instance-counting | 288 // AccessibilityNodeData tree and a factory for an instance-counting |
247 // BrowserAccessibility and ensure that exactly 4 instances were | 289 // BrowserAccessibility and ensure that exactly 4 instances were |
248 // created. Note that the manager takes ownership of the factory. | 290 // created. Note that the manager takes ownership of the factory. |
249 CountedBrowserAccessibility::global_obj_count_ = 0; | 291 CountedBrowserAccessibility::reset(); |
250 BrowserAccessibilityManager* manager = | 292 scoped_ptr<BrowserAccessibilityManager> manager( |
251 BrowserAccessibilityManager::Create( | 293 BrowserAccessibilityManager::Create( |
252 root, | 294 root, NULL, new CountedBrowserAccessibilityFactory())); |
253 NULL, | |
254 new CountedBrowserAccessibilityFactory()); | |
255 manager->UpdateNodesForTesting(div, text3, text4); | 295 manager->UpdateNodesForTesting(div, text3, text4); |
256 ASSERT_EQ(4, CountedBrowserAccessibility::global_obj_count_); | 296 ASSERT_EQ(4, CountedBrowserAccessibility::num_instances()); |
257 | 297 |
258 // Notify the BrowserAccessibilityManager that the div node and its children | 298 // Notify the BrowserAccessibilityManager that the div node and its children |
259 // were removed and ensure that only one BrowserAccessibility instance exists. | 299 // were removed and ensure that only one BrowserAccessibility instance exists. |
260 root.child_ids.clear(); | 300 root.child_ids.clear(); |
261 AccessibilityHostMsg_NotificationParams param; | 301 AccessibilityHostMsg_NotificationParams param; |
262 param.notification_type = AccessibilityNotificationChildrenChanged; | 302 param.notification_type = AccessibilityNotificationChildrenChanged; |
263 param.nodes.push_back(root); | 303 param.nodes.push_back(root); |
264 param.id = root.id; | 304 param.id = root.id; |
265 std::vector<AccessibilityHostMsg_NotificationParams> notifications; | 305 std::vector<AccessibilityHostMsg_NotificationParams> notifications; |
266 notifications.push_back(param); | 306 notifications.push_back(param); |
267 manager->OnAccessibilityNotifications(notifications); | 307 manager->OnAccessibilityNotifications(notifications); |
268 ASSERT_EQ(1, CountedBrowserAccessibility::global_obj_count_); | 308 ASSERT_EQ(1, CountedBrowserAccessibility::num_instances()); |
269 | 309 |
270 // Delete the manager and test that all BrowserAccessibility instances are | 310 // Delete the manager and test that all BrowserAccessibility instances are |
271 // deleted. | 311 // deleted. |
272 delete manager; | 312 manager.reset(); |
273 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 313 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
274 } | 314 } |
275 | 315 |
276 TEST_F(BrowserAccessibilityTest, TestTextBoundaries) { | 316 TEST_F(BrowserAccessibilityTest, TestTextBoundaries) { |
277 AccessibilityNodeData text1; | 317 AccessibilityNodeData text1; |
278 text1.id = 11; | 318 text1.id = 11; |
279 text1.role = AccessibilityNodeData::ROLE_TEXT_FIELD; | 319 text1.role = AccessibilityNodeData::ROLE_TEXT_FIELD; |
280 text1.state = 0; | 320 text1.state = 0; |
281 text1.value = L"One two three.\nFour five six."; | 321 text1.value = L"One two three.\nFour five six."; |
282 text1.line_breaks.push_back(15); | 322 text1.line_breaks.push_back(15); |
283 | 323 |
284 AccessibilityNodeData root; | 324 AccessibilityNodeData root; |
285 root.id = 1; | 325 root.id = 1; |
286 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 326 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
287 root.state = 0; | 327 root.state = 0; |
288 root.child_ids.push_back(11); | 328 root.child_ids.push_back(11); |
289 | 329 |
290 CountedBrowserAccessibility::global_obj_count_ = 0; | 330 CountedBrowserAccessibility::reset(); |
291 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( | 331 scoped_ptr<BrowserAccessibilityManager> manager( |
292 root, NULL, | 332 BrowserAccessibilityManager::Create( |
293 new CountedBrowserAccessibilityFactory()); | 333 root, NULL, new CountedBrowserAccessibilityFactory())); |
294 manager->UpdateNodesForTesting(text1); | 334 manager->UpdateNodesForTesting(text1); |
295 ASSERT_EQ(2, CountedBrowserAccessibility::global_obj_count_); | 335 ASSERT_EQ(2, CountedBrowserAccessibility::num_instances()); |
296 | 336 |
297 BrowserAccessibilityWin* root_obj = | 337 BrowserAccessibilityWin* root_obj = |
298 manager->GetRoot()->ToBrowserAccessibilityWin(); | 338 manager->GetRoot()->ToBrowserAccessibilityWin(); |
299 BrowserAccessibilityWin* text1_obj = | 339 BrowserAccessibilityWin* text1_obj = |
300 root_obj->GetChild(0)->ToBrowserAccessibilityWin(); | 340 root_obj->GetChild(0)->ToBrowserAccessibilityWin(); |
301 | 341 |
302 base::win::ScopedBstr text; | |
303 long start; | |
304 long end; | |
305 | |
306 long text1_len; | 342 long text1_len; |
307 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len)); | 343 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len)); |
308 | 344 |
| 345 base::win::ScopedBstr text; |
309 ASSERT_EQ(S_OK, text1_obj->get_text(0, text1_len, text.Receive())); | 346 ASSERT_EQ(S_OK, text1_obj->get_text(0, text1_len, text.Receive())); |
310 ASSERT_EQ(string16(text), text1.value); | 347 ASSERT_EQ(text1.value, string16(text)); |
311 text.Reset(); | 348 text.Reset(); |
312 | 349 |
313 ASSERT_EQ(S_OK, text1_obj->get_text(0, 4, text.Receive())); | 350 ASSERT_EQ(S_OK, text1_obj->get_text(0, 4, text.Receive())); |
314 ASSERT_STREQ(text, L"One "); | 351 ASSERT_STREQ(L"One ", text); |
315 text.Reset(); | 352 text.Reset(); |
316 | 353 |
| 354 long start; |
| 355 long end; |
317 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( | 356 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( |
318 1, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive())); | 357 1, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive())); |
319 ASSERT_EQ(start, 1); | 358 ASSERT_EQ(1, start); |
320 ASSERT_EQ(end, 2); | 359 ASSERT_EQ(2, end); |
321 ASSERT_STREQ(text, L"n"); | 360 ASSERT_STREQ(L"n", text); |
322 text.Reset(); | 361 text.Reset(); |
323 | 362 |
324 ASSERT_EQ(S_FALSE, text1_obj->get_textAtOffset( | 363 ASSERT_EQ(S_FALSE, text1_obj->get_textAtOffset( |
325 text1_len, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive())); | 364 text1_len, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive())); |
326 ASSERT_EQ(start, text1_len); | 365 ASSERT_EQ(text1_len, start); |
327 ASSERT_EQ(end, text1_len); | 366 ASSERT_EQ(text1_len, end); |
328 text.Reset(); | 367 text.Reset(); |
329 | 368 |
330 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( | 369 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( |
331 1, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive())); | 370 1, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive())); |
332 ASSERT_EQ(start, 0); | 371 ASSERT_EQ(0, start); |
333 ASSERT_EQ(end, 3); | 372 ASSERT_EQ(3, end); |
334 ASSERT_STREQ(text, L"One"); | 373 ASSERT_STREQ(L"One", text); |
335 text.Reset(); | 374 text.Reset(); |
336 | 375 |
337 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( | 376 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( |
338 6, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive())); | 377 6, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive())); |
339 ASSERT_EQ(start, 4); | 378 ASSERT_EQ(4, start); |
340 ASSERT_EQ(end, 7); | 379 ASSERT_EQ(7, end); |
341 ASSERT_STREQ(text, L"two"); | 380 ASSERT_STREQ(L"two", text); |
342 text.Reset(); | 381 text.Reset(); |
343 | 382 |
344 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( | 383 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( |
345 text1_len, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive())); | 384 text1_len, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive())); |
346 ASSERT_EQ(start, 25); | 385 ASSERT_EQ(25, start); |
347 ASSERT_EQ(end, 29); | 386 ASSERT_EQ(29, end); |
348 ASSERT_STREQ(text, L"six."); | 387 ASSERT_STREQ(L"six.", text); |
349 text.Reset(); | 388 text.Reset(); |
350 | 389 |
351 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( | 390 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( |
352 1, IA2_TEXT_BOUNDARY_LINE, &start, &end, text.Receive())); | 391 1, IA2_TEXT_BOUNDARY_LINE, &start, &end, text.Receive())); |
353 ASSERT_EQ(start, 0); | 392 ASSERT_EQ(0, start); |
354 ASSERT_EQ(end, 15); | 393 ASSERT_EQ(15, end); |
355 ASSERT_STREQ(text, L"One two three.\n"); | 394 ASSERT_STREQ(L"One two three.\n", text); |
356 text.Reset(); | 395 text.Reset(); |
357 | 396 |
358 ASSERT_EQ(S_OK, | 397 ASSERT_EQ(S_OK, |
359 text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, text.Receive())); | 398 text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, text.Receive())); |
360 ASSERT_STREQ(text, L"One two three.\nFour five six."); | 399 ASSERT_STREQ(L"One two three.\nFour five six.", text); |
361 | 400 |
362 // Delete the manager and test that all BrowserAccessibility instances are | 401 // Delete the manager and test that all BrowserAccessibility instances are |
363 // deleted. | 402 // deleted. |
364 delete manager; | 403 manager.reset(); |
365 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 404 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
366 } | 405 } |
367 | 406 |
368 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { | 407 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { |
369 AccessibilityNodeData text1; | 408 AccessibilityNodeData text1; |
370 text1.id = 11; | 409 text1.id = 11; |
371 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 410 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
372 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; | 411 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; |
373 text1.name = L"One two three."; | 412 text1.name = L"One two three."; |
374 | 413 |
375 AccessibilityNodeData text2; | 414 AccessibilityNodeData text2; |
376 text2.id = 12; | 415 text2.id = 12; |
377 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 416 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
378 text2.state = 1 << AccessibilityNodeData::STATE_READONLY; | 417 text2.state = 1 << AccessibilityNodeData::STATE_READONLY; |
379 text2.name = L" Four five six."; | 418 text2.name = L" Four five six."; |
380 | 419 |
381 AccessibilityNodeData root; | 420 AccessibilityNodeData root; |
382 root.id = 1; | 421 root.id = 1; |
383 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 422 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
384 root.state = 1 << AccessibilityNodeData::STATE_READONLY; | 423 root.state = 1 << AccessibilityNodeData::STATE_READONLY; |
385 root.child_ids.push_back(11); | 424 root.child_ids.push_back(11); |
386 root.child_ids.push_back(12); | 425 root.child_ids.push_back(12); |
387 | 426 |
388 CountedBrowserAccessibility::global_obj_count_ = 0; | 427 CountedBrowserAccessibility::reset(); |
389 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( | 428 scoped_ptr<BrowserAccessibilityManager> manager( |
390 root, NULL, | 429 BrowserAccessibilityManager::Create( |
391 new CountedBrowserAccessibilityFactory()); | 430 root, NULL, new CountedBrowserAccessibilityFactory())); |
392 manager->UpdateNodesForTesting(root, text1, text2); | 431 manager->UpdateNodesForTesting(root, text1, text2); |
393 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); | 432 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); |
394 | 433 |
395 BrowserAccessibilityWin* root_obj = | 434 BrowserAccessibilityWin* root_obj = |
396 manager->GetRoot()->ToBrowserAccessibilityWin(); | 435 manager->GetRoot()->ToBrowserAccessibilityWin(); |
397 | 436 |
398 base::win::ScopedBstr text; | |
399 | |
400 long text_len; | 437 long text_len; |
401 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); | 438 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
402 | 439 |
| 440 base::win::ScopedBstr text; |
403 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); | 441 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); |
404 EXPECT_EQ(string16(text), text1.name + text2.name); | 442 EXPECT_EQ(text1.name + text2.name, string16(text)); |
405 | 443 |
406 long hyperlink_count; | 444 long hyperlink_count; |
407 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); | 445 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
408 EXPECT_EQ(0, hyperlink_count); | 446 EXPECT_EQ(0, hyperlink_count); |
409 | 447 |
410 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; | 448 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
411 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); | 449 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
412 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive())); | 450 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive())); |
413 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); | 451 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
414 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive())); | 452 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive())); |
415 | 453 |
416 long hyperlink_index; | 454 long hyperlink_index; |
417 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); | 455 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
418 EXPECT_EQ(-1, hyperlink_index); | 456 EXPECT_EQ(-1, hyperlink_index); |
419 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); | 457 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
420 EXPECT_EQ(-1, hyperlink_index); | 458 EXPECT_EQ(-1, hyperlink_index); |
421 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); | 459 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); |
422 EXPECT_EQ(-1, hyperlink_index); | 460 EXPECT_EQ(-1, hyperlink_index); |
423 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); | 461 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); |
424 EXPECT_EQ(-1, hyperlink_index); | 462 EXPECT_EQ(-1, hyperlink_index); |
425 | 463 |
426 // Delete the manager and test that all BrowserAccessibility instances are | 464 // Delete the manager and test that all BrowserAccessibility instances are |
427 // deleted. | 465 // deleted. |
428 delete manager; | 466 manager.reset(); |
429 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 467 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
430 } | 468 } |
431 | 469 |
432 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { | 470 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { |
433 AccessibilityNodeData text1; | 471 AccessibilityNodeData text1; |
434 text1.id = 11; | 472 text1.id = 11; |
435 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 473 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
436 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; | 474 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; |
437 text1.name = L"One two three."; | 475 text1.name = L"One two three."; |
438 | 476 |
439 AccessibilityNodeData text2; | 477 AccessibilityNodeData text2; |
(...skipping 24 matching lines...) Expand all Loading... |
464 | 502 |
465 AccessibilityNodeData root; | 503 AccessibilityNodeData root; |
466 root.id = 1; | 504 root.id = 1; |
467 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 505 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
468 root.state = 1 << AccessibilityNodeData::STATE_READONLY; | 506 root.state = 1 << AccessibilityNodeData::STATE_READONLY; |
469 root.child_ids.push_back(11); | 507 root.child_ids.push_back(11); |
470 root.child_ids.push_back(13); | 508 root.child_ids.push_back(13); |
471 root.child_ids.push_back(12); | 509 root.child_ids.push_back(12); |
472 root.child_ids.push_back(14); | 510 root.child_ids.push_back(14); |
473 | 511 |
474 CountedBrowserAccessibility::global_obj_count_ = 0; | 512 CountedBrowserAccessibility::reset(); |
475 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( | 513 scoped_ptr<BrowserAccessibilityManager> manager( |
476 root, NULL, | 514 BrowserAccessibilityManager::Create( |
477 new CountedBrowserAccessibilityFactory()); | 515 root, NULL, new CountedBrowserAccessibilityFactory())); |
478 manager->UpdateNodesForTesting(root, | 516 manager->UpdateNodesForTesting(root, |
479 text1, button1, button1_text, | 517 text1, button1, button1_text, |
480 text2, link1, link1_text); | 518 text2, link1, link1_text); |
481 | 519 |
482 ASSERT_EQ(7, CountedBrowserAccessibility::global_obj_count_); | 520 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances()); |
483 | 521 |
484 BrowserAccessibilityWin* root_obj = | 522 BrowserAccessibilityWin* root_obj = |
485 manager->GetRoot()->ToBrowserAccessibilityWin(); | 523 manager->GetRoot()->ToBrowserAccessibilityWin(); |
486 | 524 |
487 base::win::ScopedBstr text; | |
488 | |
489 long text_len; | 525 long text_len; |
490 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); | 526 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
491 | 527 |
| 528 base::win::ScopedBstr text; |
492 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); | 529 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); |
493 const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter; | 530 const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter; |
494 EXPECT_EQ(string16(text), text1.name + embed + text2.name + embed); | 531 EXPECT_EQ(text1.name + embed + text2.name + embed, string16(text)); |
495 text.Reset(); | 532 text.Reset(); |
496 | 533 |
497 long hyperlink_count; | 534 long hyperlink_count; |
498 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); | 535 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
499 EXPECT_EQ(2, hyperlink_count); | 536 EXPECT_EQ(2, hyperlink_count); |
500 | 537 |
501 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; | 538 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
502 base::win::ScopedComPtr<IAccessibleText> hypertext; | 539 base::win::ScopedComPtr<IAccessibleText> hypertext; |
503 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); | 540 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
504 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive())); | 541 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive())); |
505 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); | 542 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
506 | 543 |
507 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive())); | 544 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive())); |
508 EXPECT_EQ(S_OK, | 545 EXPECT_EQ(S_OK, |
509 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); | 546 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); |
510 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, text.Receive())); | 547 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, text.Receive())); |
511 EXPECT_STREQ(text, L"red"); | 548 EXPECT_STREQ(L"red", text); |
512 text.Reset(); | 549 text.Reset(); |
513 hyperlink.Release(); | 550 hyperlink.Release(); |
514 hypertext.Release(); | 551 hypertext.Release(); |
515 | 552 |
516 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive())); | 553 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive())); |
517 EXPECT_EQ(S_OK, | 554 EXPECT_EQ(S_OK, |
518 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); | 555 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); |
519 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, text.Receive())); | 556 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, text.Receive())); |
520 EXPECT_STREQ(text, L"blue"); | 557 EXPECT_STREQ(L"blue", text); |
521 text.Reset(); | 558 text.Reset(); |
522 hyperlink.Release(); | 559 hyperlink.Release(); |
523 hypertext.Release(); | 560 hypertext.Release(); |
524 | 561 |
525 long hyperlink_index; | 562 long hyperlink_index; |
526 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); | 563 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
527 EXPECT_EQ(-1, hyperlink_index); | 564 EXPECT_EQ(-1, hyperlink_index); |
528 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); | 565 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
529 EXPECT_EQ(-1, hyperlink_index); | 566 EXPECT_EQ(-1, hyperlink_index); |
530 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); | 567 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); |
531 EXPECT_EQ(0, hyperlink_index); | 568 EXPECT_EQ(0, hyperlink_index); |
532 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index)); | 569 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index)); |
533 EXPECT_EQ(1, hyperlink_index); | 570 EXPECT_EQ(1, hyperlink_index); |
534 | 571 |
535 // Delete the manager and test that all BrowserAccessibility instances are | 572 // Delete the manager and test that all BrowserAccessibility instances are |
536 // deleted. | 573 // deleted. |
537 delete manager; | 574 manager.reset(); |
538 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 575 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
539 } | 576 } |
540 | 577 |
541 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) { | 578 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) { |
542 // Try creating an empty document with busy state. Readonly is | 579 // Try creating an empty document with busy state. Readonly is |
543 // set automatically. | 580 // set automatically. |
| 581 CountedBrowserAccessibility::reset(); |
544 const int32 busy_state = 1 << AccessibilityNodeData::STATE_BUSY; | 582 const int32 busy_state = 1 << AccessibilityNodeData::STATE_BUSY; |
545 const int32 readonly_state = 1 << AccessibilityNodeData::STATE_READONLY; | 583 const int32 readonly_state = 1 << AccessibilityNodeData::STATE_READONLY; |
546 scoped_ptr<BrowserAccessibilityManager> manager; | 584 scoped_ptr<BrowserAccessibilityManager> manager( |
547 manager.reset(new BrowserAccessibilityManagerWin( | 585 new BrowserAccessibilityManagerWin( |
548 GetDesktopWindow(), | 586 GetDesktopWindow(), |
549 NULL, | 587 NULL, |
550 BrowserAccessibilityManagerWin::GetEmptyDocument(), | 588 BrowserAccessibilityManagerWin::GetEmptyDocument(), |
551 NULL, | 589 NULL, |
552 new CountedBrowserAccessibilityFactory())); | 590 new CountedBrowserAccessibilityFactory())); |
553 | 591 |
554 // Verify the root is as we expect by default. | 592 // Verify the root is as we expect by default. |
555 BrowserAccessibility* root = manager->GetRoot(); | 593 BrowserAccessibility* root = manager->GetRoot(); |
556 EXPECT_EQ(0, root->renderer_id()); | 594 EXPECT_EQ(0, root->renderer_id()); |
557 EXPECT_EQ(AccessibilityNodeData::ROLE_ROOT_WEB_AREA, root->role()); | 595 EXPECT_EQ(AccessibilityNodeData::ROLE_ROOT_WEB_AREA, root->role()); |
558 EXPECT_EQ(busy_state | readonly_state, root->state()); | 596 EXPECT_EQ(busy_state | readonly_state, root->state()); |
559 | 597 |
560 // Tree with a child textfield. | 598 // Tree with a child textfield. |
561 AccessibilityNodeData tree1_1; | 599 AccessibilityNodeData tree1_1; |
562 tree1_1.id = 1; | 600 tree1_1.id = 1; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 | 647 |
610 // Verify the root has changed. | 648 // Verify the root has changed. |
611 EXPECT_NE(root, manager->GetRoot()); | 649 EXPECT_NE(root, manager->GetRoot()); |
612 | 650 |
613 // And the new child exists. | 651 // And the new child exists. |
614 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, acc2_2->role()); | 652 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, acc2_2->role()); |
615 EXPECT_EQ(3, acc2_2->renderer_id()); | 653 EXPECT_EQ(3, acc2_2->renderer_id()); |
616 | 654 |
617 // Ensure we properly cleaned up. | 655 // Ensure we properly cleaned up. |
618 manager.reset(); | 656 manager.reset(); |
619 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 657 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
620 } | 658 } |
621 | 659 |
622 } // namespace content | 660 } // namespace content |
OLD | NEW |