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/strings/string16.h" | 5 #include "base/strings/string16.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/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/accessibility_messages.h" | 9 #include "content/common/accessibility_messages.h" |
10 #include "content/common/accessibility_node_data.h" | 10 #include "content/common/accessibility_node_data.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 } // anonymous namespace | 87 } // anonymous namespace |
88 | 88 |
89 TEST(BrowserAccessibilityManagerTest, TestNoLeaks) { | 89 TEST(BrowserAccessibilityManagerTest, TestNoLeaks) { |
90 // Create AccessibilityNodeData objects for a simple document tree, | 90 // Create AccessibilityNodeData objects for a simple document tree, |
91 // representing the accessibility information used to initialize | 91 // representing the accessibility information used to initialize |
92 // BrowserAccessibilityManager. | 92 // BrowserAccessibilityManager. |
93 AccessibilityNodeData button; | 93 AccessibilityNodeData button; |
94 button.id = 2; | 94 button.id = 2; |
95 button.SetName("Button"); | 95 button.SetName("Button"); |
96 button.role = WebKit::WebAXRoleButton; | 96 button.role = blink::WebAXRoleButton; |
97 button.state = 0; | 97 button.state = 0; |
98 | 98 |
99 AccessibilityNodeData checkbox; | 99 AccessibilityNodeData checkbox; |
100 checkbox.id = 3; | 100 checkbox.id = 3; |
101 checkbox.SetName("Checkbox"); | 101 checkbox.SetName("Checkbox"); |
102 checkbox.role = WebKit::WebAXRoleCheckBox; | 102 checkbox.role = blink::WebAXRoleCheckBox; |
103 checkbox.state = 0; | 103 checkbox.state = 0; |
104 | 104 |
105 AccessibilityNodeData root; | 105 AccessibilityNodeData root; |
106 root.id = 1; | 106 root.id = 1; |
107 root.SetName("Document"); | 107 root.SetName("Document"); |
108 root.role = WebKit::WebAXRoleRootWebArea; | 108 root.role = blink::WebAXRoleRootWebArea; |
109 root.state = 0; | 109 root.state = 0; |
110 root.child_ids.push_back(2); | 110 root.child_ids.push_back(2); |
111 root.child_ids.push_back(3); | 111 root.child_ids.push_back(3); |
112 | 112 |
113 // Construct a BrowserAccessibilityManager with this | 113 // Construct a BrowserAccessibilityManager with this |
114 // AccessibilityNodeData tree and a factory for an instance-counting | 114 // AccessibilityNodeData tree and a factory for an instance-counting |
115 // BrowserAccessibility, and ensure that exactly 3 instances were | 115 // BrowserAccessibility, and ensure that exactly 3 instances were |
116 // created. Note that the manager takes ownership of the factory. | 116 // created. Note that the manager takes ownership of the factory. |
117 CountedBrowserAccessibility::global_obj_count_ = 0; | 117 CountedBrowserAccessibility::global_obj_count_ = 0; |
118 BrowserAccessibilityManager* manager = | 118 BrowserAccessibilityManager* manager = |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // Tree 1: | 165 // Tree 1: |
166 // | 166 // |
167 // root | 167 // root |
168 // child1 | 168 // child1 |
169 // child2 | 169 // child2 |
170 // child3 | 170 // child3 |
171 | 171 |
172 AccessibilityNodeData tree1_child1; | 172 AccessibilityNodeData tree1_child1; |
173 tree1_child1.id = 2; | 173 tree1_child1.id = 2; |
174 tree1_child1.SetName("Child1"); | 174 tree1_child1.SetName("Child1"); |
175 tree1_child1.role = WebKit::WebAXRoleButton; | 175 tree1_child1.role = blink::WebAXRoleButton; |
176 tree1_child1.state = 0; | 176 tree1_child1.state = 0; |
177 | 177 |
178 AccessibilityNodeData tree1_child2; | 178 AccessibilityNodeData tree1_child2; |
179 tree1_child2.id = 3; | 179 tree1_child2.id = 3; |
180 tree1_child2.SetName("Child2"); | 180 tree1_child2.SetName("Child2"); |
181 tree1_child2.role = WebKit::WebAXRoleButton; | 181 tree1_child2.role = blink::WebAXRoleButton; |
182 tree1_child2.state = 0; | 182 tree1_child2.state = 0; |
183 | 183 |
184 AccessibilityNodeData tree1_child3; | 184 AccessibilityNodeData tree1_child3; |
185 tree1_child3.id = 4; | 185 tree1_child3.id = 4; |
186 tree1_child3.SetName("Child3"); | 186 tree1_child3.SetName("Child3"); |
187 tree1_child3.role = WebKit::WebAXRoleButton; | 187 tree1_child3.role = blink::WebAXRoleButton; |
188 tree1_child3.state = 0; | 188 tree1_child3.state = 0; |
189 | 189 |
190 AccessibilityNodeData tree1_root; | 190 AccessibilityNodeData tree1_root; |
191 tree1_root.id = 1; | 191 tree1_root.id = 1; |
192 tree1_root.SetName("Document"); | 192 tree1_root.SetName("Document"); |
193 tree1_root.role = WebKit::WebAXRoleRootWebArea; | 193 tree1_root.role = blink::WebAXRoleRootWebArea; |
194 tree1_root.state = 0; | 194 tree1_root.state = 0; |
195 tree1_root.child_ids.push_back(2); | 195 tree1_root.child_ids.push_back(2); |
196 tree1_root.child_ids.push_back(3); | 196 tree1_root.child_ids.push_back(3); |
197 tree1_root.child_ids.push_back(4); | 197 tree1_root.child_ids.push_back(4); |
198 | 198 |
199 // Tree 2: | 199 // Tree 2: |
200 // | 200 // |
201 // root | 201 // root |
202 // child0 <-- inserted | 202 // child0 <-- inserted |
203 // child1 | 203 // child1 |
204 // child2 | 204 // child2 |
205 // <-- child3 deleted | 205 // <-- child3 deleted |
206 | 206 |
207 AccessibilityNodeData tree2_child0; | 207 AccessibilityNodeData tree2_child0; |
208 tree2_child0.id = 5; | 208 tree2_child0.id = 5; |
209 tree2_child0.SetName("Child0"); | 209 tree2_child0.SetName("Child0"); |
210 tree2_child0.role = WebKit::WebAXRoleButton; | 210 tree2_child0.role = blink::WebAXRoleButton; |
211 tree2_child0.state = 0; | 211 tree2_child0.state = 0; |
212 | 212 |
213 AccessibilityNodeData tree2_root; | 213 AccessibilityNodeData tree2_root; |
214 tree2_root.id = 1; | 214 tree2_root.id = 1; |
215 tree2_root.SetName("DocumentChanged"); | 215 tree2_root.SetName("DocumentChanged"); |
216 tree2_root.role = WebKit::WebAXRoleRootWebArea; | 216 tree2_root.role = blink::WebAXRoleRootWebArea; |
217 tree2_root.state = 0; | 217 tree2_root.state = 0; |
218 tree2_root.child_ids.push_back(5); | 218 tree2_root.child_ids.push_back(5); |
219 tree2_root.child_ids.push_back(2); | 219 tree2_root.child_ids.push_back(2); |
220 tree2_root.child_ids.push_back(3); | 220 tree2_root.child_ids.push_back(3); |
221 | 221 |
222 // Construct a BrowserAccessibilityManager with tree1. | 222 // Construct a BrowserAccessibilityManager with tree1. |
223 CountedBrowserAccessibility::global_obj_count_ = 0; | 223 CountedBrowserAccessibility::global_obj_count_ = 0; |
224 BrowserAccessibilityManager* manager = | 224 BrowserAccessibilityManager* manager = |
225 BrowserAccessibilityManager::Create( | 225 BrowserAccessibilityManager::Create( |
226 tree1_root, | 226 tree1_root, |
(...skipping 21 matching lines...) Expand all Loading... |
248 | 248 |
249 // Check the index in parent. | 249 // Check the index in parent. |
250 EXPECT_EQ(0, child1_accessible->index_in_parent()); | 250 EXPECT_EQ(0, child1_accessible->index_in_parent()); |
251 EXPECT_EQ(1, child2_accessible->index_in_parent()); | 251 EXPECT_EQ(1, child2_accessible->index_in_parent()); |
252 EXPECT_EQ(2, child3_accessible->index_in_parent()); | 252 EXPECT_EQ(2, child3_accessible->index_in_parent()); |
253 | 253 |
254 // Process a notification containing the changed subtree. | 254 // Process a notification containing the changed subtree. |
255 std::vector<AccessibilityHostMsg_EventParams> params; | 255 std::vector<AccessibilityHostMsg_EventParams> params; |
256 params.push_back(AccessibilityHostMsg_EventParams()); | 256 params.push_back(AccessibilityHostMsg_EventParams()); |
257 AccessibilityHostMsg_EventParams* msg = ¶ms[0]; | 257 AccessibilityHostMsg_EventParams* msg = ¶ms[0]; |
258 msg->event_type = WebKit::WebAXEventChildrenChanged; | 258 msg->event_type = blink::WebAXEventChildrenChanged; |
259 msg->nodes.push_back(tree2_root); | 259 msg->nodes.push_back(tree2_root); |
260 msg->nodes.push_back(tree2_child0); | 260 msg->nodes.push_back(tree2_child0); |
261 msg->id = tree2_root.id; | 261 msg->id = tree2_root.id; |
262 manager->OnAccessibilityEvents(params); | 262 manager->OnAccessibilityEvents(params); |
263 | 263 |
264 // There should be 5 objects now: the 4 from the new tree, plus the | 264 // There should be 5 objects now: the 4 from the new tree, plus the |
265 // reference to child3 we kept. | 265 // reference to child3 we kept. |
266 EXPECT_EQ(5, CountedBrowserAccessibility::global_obj_count_); | 266 EXPECT_EQ(5, CountedBrowserAccessibility::global_obj_count_); |
267 | 267 |
268 // Check that our references to the root, child1, and child2 are still valid, | 268 // Check that our references to the root, child1, and child2 are still valid, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // child1 | 300 // child1 |
301 // grandchild1 | 301 // grandchild1 |
302 // child2 | 302 // child2 |
303 // grandchild2 | 303 // grandchild2 |
304 // child3 | 304 // child3 |
305 // grandchild3 | 305 // grandchild3 |
306 | 306 |
307 AccessibilityNodeData tree1_grandchild1; | 307 AccessibilityNodeData tree1_grandchild1; |
308 tree1_grandchild1.id = 4; | 308 tree1_grandchild1.id = 4; |
309 tree1_grandchild1.SetName("GrandChild1"); | 309 tree1_grandchild1.SetName("GrandChild1"); |
310 tree1_grandchild1.role = WebKit::WebAXRoleButton; | 310 tree1_grandchild1.role = blink::WebAXRoleButton; |
311 tree1_grandchild1.state = 0; | 311 tree1_grandchild1.state = 0; |
312 | 312 |
313 AccessibilityNodeData tree1_child1; | 313 AccessibilityNodeData tree1_child1; |
314 tree1_child1.id = 3; | 314 tree1_child1.id = 3; |
315 tree1_child1.SetName("Child1"); | 315 tree1_child1.SetName("Child1"); |
316 tree1_child1.role = WebKit::WebAXRoleButton; | 316 tree1_child1.role = blink::WebAXRoleButton; |
317 tree1_child1.state = 0; | 317 tree1_child1.state = 0; |
318 tree1_child1.child_ids.push_back(4); | 318 tree1_child1.child_ids.push_back(4); |
319 | 319 |
320 AccessibilityNodeData tree1_grandchild2; | 320 AccessibilityNodeData tree1_grandchild2; |
321 tree1_grandchild2.id = 6; | 321 tree1_grandchild2.id = 6; |
322 tree1_grandchild2.SetName("GrandChild1"); | 322 tree1_grandchild2.SetName("GrandChild1"); |
323 tree1_grandchild2.role = WebKit::WebAXRoleButton; | 323 tree1_grandchild2.role = blink::WebAXRoleButton; |
324 tree1_grandchild2.state = 0; | 324 tree1_grandchild2.state = 0; |
325 | 325 |
326 AccessibilityNodeData tree1_child2; | 326 AccessibilityNodeData tree1_child2; |
327 tree1_child2.id = 5; | 327 tree1_child2.id = 5; |
328 tree1_child2.SetName("Child2"); | 328 tree1_child2.SetName("Child2"); |
329 tree1_child2.role = WebKit::WebAXRoleButton; | 329 tree1_child2.role = blink::WebAXRoleButton; |
330 tree1_child2.state = 0; | 330 tree1_child2.state = 0; |
331 tree1_child2.child_ids.push_back(6); | 331 tree1_child2.child_ids.push_back(6); |
332 | 332 |
333 AccessibilityNodeData tree1_grandchild3; | 333 AccessibilityNodeData tree1_grandchild3; |
334 tree1_grandchild3.id = 8; | 334 tree1_grandchild3.id = 8; |
335 tree1_grandchild3.SetName("GrandChild3"); | 335 tree1_grandchild3.SetName("GrandChild3"); |
336 tree1_grandchild3.role = WebKit::WebAXRoleButton; | 336 tree1_grandchild3.role = blink::WebAXRoleButton; |
337 tree1_grandchild3.state = 0; | 337 tree1_grandchild3.state = 0; |
338 | 338 |
339 AccessibilityNodeData tree1_child3; | 339 AccessibilityNodeData tree1_child3; |
340 tree1_child3.id = 7; | 340 tree1_child3.id = 7; |
341 tree1_child3.SetName("Child3"); | 341 tree1_child3.SetName("Child3"); |
342 tree1_child3.role = WebKit::WebAXRoleButton; | 342 tree1_child3.role = blink::WebAXRoleButton; |
343 tree1_child3.state = 0; | 343 tree1_child3.state = 0; |
344 tree1_child3.child_ids.push_back(8); | 344 tree1_child3.child_ids.push_back(8); |
345 | 345 |
346 AccessibilityNodeData tree1_container; | 346 AccessibilityNodeData tree1_container; |
347 tree1_container.id = 2; | 347 tree1_container.id = 2; |
348 tree1_container.SetName("Container"); | 348 tree1_container.SetName("Container"); |
349 tree1_container.role = WebKit::WebAXRoleGroup; | 349 tree1_container.role = blink::WebAXRoleGroup; |
350 tree1_container.state = 0; | 350 tree1_container.state = 0; |
351 tree1_container.child_ids.push_back(3); | 351 tree1_container.child_ids.push_back(3); |
352 tree1_container.child_ids.push_back(5); | 352 tree1_container.child_ids.push_back(5); |
353 tree1_container.child_ids.push_back(7); | 353 tree1_container.child_ids.push_back(7); |
354 | 354 |
355 AccessibilityNodeData tree1_root; | 355 AccessibilityNodeData tree1_root; |
356 tree1_root.id = 1; | 356 tree1_root.id = 1; |
357 tree1_root.SetName("Document"); | 357 tree1_root.SetName("Document"); |
358 tree1_root.role = WebKit::WebAXRoleRootWebArea; | 358 tree1_root.role = blink::WebAXRoleRootWebArea; |
359 tree1_root.state = 0; | 359 tree1_root.state = 0; |
360 tree1_root.child_ids.push_back(2); | 360 tree1_root.child_ids.push_back(2); |
361 | 361 |
362 // Tree 2: | 362 // Tree 2: |
363 // | 363 // |
364 // root | 364 // root |
365 // container | 365 // container |
366 // child0 <-- inserted | 366 // child0 <-- inserted |
367 // grandchild0 <-- | 367 // grandchild0 <-- |
368 // child1 | 368 // child1 |
369 // grandchild1 | 369 // grandchild1 |
370 // child2 | 370 // child2 |
371 // grandchild2 | 371 // grandchild2 |
372 // <-- child3 (and grandchild3) deleted | 372 // <-- child3 (and grandchild3) deleted |
373 | 373 |
374 AccessibilityNodeData tree2_grandchild0; | 374 AccessibilityNodeData tree2_grandchild0; |
375 tree2_grandchild0.id = 9; | 375 tree2_grandchild0.id = 9; |
376 tree2_grandchild0.SetName("GrandChild0"); | 376 tree2_grandchild0.SetName("GrandChild0"); |
377 tree2_grandchild0.role = WebKit::WebAXRoleButton; | 377 tree2_grandchild0.role = blink::WebAXRoleButton; |
378 tree2_grandchild0.state = 0; | 378 tree2_grandchild0.state = 0; |
379 | 379 |
380 AccessibilityNodeData tree2_child0; | 380 AccessibilityNodeData tree2_child0; |
381 tree2_child0.id = 10; | 381 tree2_child0.id = 10; |
382 tree2_child0.SetName("Child0"); | 382 tree2_child0.SetName("Child0"); |
383 tree2_child0.role = WebKit::WebAXRoleButton; | 383 tree2_child0.role = blink::WebAXRoleButton; |
384 tree2_child0.state = 0; | 384 tree2_child0.state = 0; |
385 tree2_child0.child_ids.push_back(9); | 385 tree2_child0.child_ids.push_back(9); |
386 | 386 |
387 AccessibilityNodeData tree2_container; | 387 AccessibilityNodeData tree2_container; |
388 tree2_container.id = 2; | 388 tree2_container.id = 2; |
389 tree2_container.SetName("Container"); | 389 tree2_container.SetName("Container"); |
390 tree2_container.role = WebKit::WebAXRoleGroup; | 390 tree2_container.role = blink::WebAXRoleGroup; |
391 tree2_container.state = 0; | 391 tree2_container.state = 0; |
392 tree2_container.child_ids.push_back(10); | 392 tree2_container.child_ids.push_back(10); |
393 tree2_container.child_ids.push_back(3); | 393 tree2_container.child_ids.push_back(3); |
394 tree2_container.child_ids.push_back(5); | 394 tree2_container.child_ids.push_back(5); |
395 | 395 |
396 // Construct a BrowserAccessibilityManager with tree1. | 396 // Construct a BrowserAccessibilityManager with tree1. |
397 CountedBrowserAccessibility::global_obj_count_ = 0; | 397 CountedBrowserAccessibility::global_obj_count_ = 0; |
398 BrowserAccessibilityManager* manager = | 398 BrowserAccessibilityManager* manager = |
399 BrowserAccessibilityManager::Create( | 399 BrowserAccessibilityManager::Create( |
400 tree1_root, | 400 tree1_root, |
(...skipping 24 matching lines...) Expand all Loading... |
425 | 425 |
426 // Check the index in parent. | 426 // Check the index in parent. |
427 EXPECT_EQ(1, child2_accessible->index_in_parent()); | 427 EXPECT_EQ(1, child2_accessible->index_in_parent()); |
428 EXPECT_EQ(2, child3_accessible->index_in_parent()); | 428 EXPECT_EQ(2, child3_accessible->index_in_parent()); |
429 | 429 |
430 // Process a notification containing the changed subtree rooted at | 430 // Process a notification containing the changed subtree rooted at |
431 // the container. | 431 // the container. |
432 std::vector<AccessibilityHostMsg_EventParams> params; | 432 std::vector<AccessibilityHostMsg_EventParams> params; |
433 params.push_back(AccessibilityHostMsg_EventParams()); | 433 params.push_back(AccessibilityHostMsg_EventParams()); |
434 AccessibilityHostMsg_EventParams* msg = ¶ms[0]; | 434 AccessibilityHostMsg_EventParams* msg = ¶ms[0]; |
435 msg->event_type = WebKit::WebAXEventChildrenChanged; | 435 msg->event_type = blink::WebAXEventChildrenChanged; |
436 msg->nodes.push_back(tree2_container); | 436 msg->nodes.push_back(tree2_container); |
437 msg->nodes.push_back(tree2_child0); | 437 msg->nodes.push_back(tree2_child0); |
438 msg->nodes.push_back(tree2_grandchild0); | 438 msg->nodes.push_back(tree2_grandchild0); |
439 msg->id = tree2_container.id; | 439 msg->id = tree2_container.id; |
440 manager->OnAccessibilityEvents(params); | 440 manager->OnAccessibilityEvents(params); |
441 | 441 |
442 // There should be 9 objects now: the 8 from the new tree, plus the | 442 // There should be 9 objects now: the 8 from the new tree, plus the |
443 // reference to child3 we kept. | 443 // reference to child3 we kept. |
444 EXPECT_EQ(9, CountedBrowserAccessibility::global_obj_count_); | 444 EXPECT_EQ(9, CountedBrowserAccessibility::global_obj_count_); |
445 | 445 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 tree1_3.id = 3; | 487 tree1_3.id = 3; |
488 tree1_3.state = 0; | 488 tree1_3.state = 0; |
489 tree1_3.child_ids.push_back(4); | 489 tree1_3.child_ids.push_back(4); |
490 | 490 |
491 AccessibilityNodeData tree1_2; | 491 AccessibilityNodeData tree1_2; |
492 tree1_2.id = 2; | 492 tree1_2.id = 2; |
493 tree1_2.state = 0; | 493 tree1_2.state = 0; |
494 | 494 |
495 AccessibilityNodeData tree1_1; | 495 AccessibilityNodeData tree1_1; |
496 tree1_1.id = 1; | 496 tree1_1.id = 1; |
497 tree1_1.role = WebKit::WebAXRoleRootWebArea; | 497 tree1_1.role = blink::WebAXRoleRootWebArea; |
498 tree1_1.state = 0; | 498 tree1_1.state = 0; |
499 tree1_1.child_ids.push_back(2); | 499 tree1_1.child_ids.push_back(2); |
500 tree1_1.child_ids.push_back(3); | 500 tree1_1.child_ids.push_back(3); |
501 | 501 |
502 // Tree 2: | 502 // Tree 2: |
503 // | 503 // |
504 // 1 | 504 // 1 |
505 // 4 <-- moves up a level and gains child | 505 // 4 <-- moves up a level and gains child |
506 // 6 <-- new | 506 // 6 <-- new |
507 // 5 <-- new | 507 // 5 <-- new |
(...skipping 24 matching lines...) Expand all Loading... |
532 tree1_1, | 532 tree1_1, |
533 NULL, | 533 NULL, |
534 new CountedBrowserAccessibilityFactory()); | 534 new CountedBrowserAccessibilityFactory()); |
535 manager->UpdateNodesForTesting(tree1_2, tree1_3, tree1_4); | 535 manager->UpdateNodesForTesting(tree1_2, tree1_3, tree1_4); |
536 ASSERT_EQ(4, CountedBrowserAccessibility::global_obj_count_); | 536 ASSERT_EQ(4, CountedBrowserAccessibility::global_obj_count_); |
537 | 537 |
538 // Process a notification containing the changed subtree. | 538 // Process a notification containing the changed subtree. |
539 std::vector<AccessibilityHostMsg_EventParams> params; | 539 std::vector<AccessibilityHostMsg_EventParams> params; |
540 params.push_back(AccessibilityHostMsg_EventParams()); | 540 params.push_back(AccessibilityHostMsg_EventParams()); |
541 AccessibilityHostMsg_EventParams* msg = ¶ms[0]; | 541 AccessibilityHostMsg_EventParams* msg = ¶ms[0]; |
542 msg->event_type = WebKit::WebAXEventChildrenChanged; | 542 msg->event_type = blink::WebAXEventChildrenChanged; |
543 msg->nodes.push_back(tree2_1); | 543 msg->nodes.push_back(tree2_1); |
544 msg->nodes.push_back(tree2_4); | 544 msg->nodes.push_back(tree2_4); |
545 msg->nodes.push_back(tree2_5); | 545 msg->nodes.push_back(tree2_5); |
546 msg->nodes.push_back(tree2_6); | 546 msg->nodes.push_back(tree2_6); |
547 msg->id = tree2_1.id; | 547 msg->id = tree2_1.id; |
548 manager->OnAccessibilityEvents(params); | 548 manager->OnAccessibilityEvents(params); |
549 | 549 |
550 // There should be 4 objects now. | 550 // There should be 4 objects now. |
551 EXPECT_EQ(4, CountedBrowserAccessibility::global_obj_count_); | 551 EXPECT_EQ(4, CountedBrowserAccessibility::global_obj_count_); |
552 | 552 |
553 // Delete the manager and make sure all memory is cleaned up. | 553 // Delete the manager and make sure all memory is cleaned up. |
554 delete manager; | 554 delete manager; |
555 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 555 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
556 } | 556 } |
557 | 557 |
558 // Crashes on Windows. http://crbug.com/304130 | 558 // Crashes on Windows. http://crbug.com/304130 |
559 #if defined(OS_WIN) | 559 #if defined(OS_WIN) |
560 #define MAYBE_TestFatalError DISABLED_TestFatalError | 560 #define MAYBE_TestFatalError DISABLED_TestFatalError |
561 #else | 561 #else |
562 #define MAYBE_TestFatalError TestFatalError | 562 #define MAYBE_TestFatalError TestFatalError |
563 #endif | 563 #endif |
564 TEST(BrowserAccessibilityManagerTest, TestFatalError) { | 564 TEST(BrowserAccessibilityManagerTest, TestFatalError) { |
565 // Test that BrowserAccessibilityManager raises a fatal error | 565 // Test that BrowserAccessibilityManager raises a fatal error |
566 // (which will crash the renderer) if the same id is used in | 566 // (which will crash the renderer) if the same id is used in |
567 // two places in the tree. | 567 // two places in the tree. |
568 | 568 |
569 AccessibilityNodeData root; | 569 AccessibilityNodeData root; |
570 root.id = 1; | 570 root.id = 1; |
571 root.role = WebKit::WebAXRoleRootWebArea; | 571 root.role = blink::WebAXRoleRootWebArea; |
572 root.child_ids.push_back(2); | 572 root.child_ids.push_back(2); |
573 root.child_ids.push_back(2); | 573 root.child_ids.push_back(2); |
574 | 574 |
575 CountedBrowserAccessibilityFactory* factory = | 575 CountedBrowserAccessibilityFactory* factory = |
576 new CountedBrowserAccessibilityFactory(); | 576 new CountedBrowserAccessibilityFactory(); |
577 scoped_ptr<TestBrowserAccessibilityDelegate> delegate( | 577 scoped_ptr<TestBrowserAccessibilityDelegate> delegate( |
578 new TestBrowserAccessibilityDelegate()); | 578 new TestBrowserAccessibilityDelegate()); |
579 scoped_ptr<BrowserAccessibilityManager> manager; | 579 scoped_ptr<BrowserAccessibilityManager> manager; |
580 ASSERT_FALSE(delegate->got_fatal_error()); | 580 ASSERT_FALSE(delegate->got_fatal_error()); |
581 manager.reset(BrowserAccessibilityManager::Create( | 581 manager.reset(BrowserAccessibilityManager::Create( |
582 root, | 582 root, |
583 delegate.get(), | 583 delegate.get(), |
584 factory)); | 584 factory)); |
585 ASSERT_TRUE(delegate->got_fatal_error()); | 585 ASSERT_TRUE(delegate->got_fatal_error()); |
586 | 586 |
587 AccessibilityNodeData root2; | 587 AccessibilityNodeData root2; |
588 root2.id = 1; | 588 root2.id = 1; |
589 root2.role = WebKit::WebAXRoleRootWebArea; | 589 root2.role = blink::WebAXRoleRootWebArea; |
590 root2.child_ids.push_back(2); | 590 root2.child_ids.push_back(2); |
591 root2.child_ids.push_back(3); | 591 root2.child_ids.push_back(3); |
592 | 592 |
593 AccessibilityNodeData child1; | 593 AccessibilityNodeData child1; |
594 child1.id = 2; | 594 child1.id = 2; |
595 child1.child_ids.push_back(4); | 595 child1.child_ids.push_back(4); |
596 child1.child_ids.push_back(5); | 596 child1.child_ids.push_back(5); |
597 | 597 |
598 AccessibilityNodeData child2; | 598 AccessibilityNodeData child2; |
599 child2.id = 3; | 599 child2.id = 3; |
600 child2.child_ids.push_back(6); | 600 child2.child_ids.push_back(6); |
601 child2.child_ids.push_back(5); // Duplicate | 601 child2.child_ids.push_back(5); // Duplicate |
602 | 602 |
603 delegate->reset_got_fatal_error(); | 603 delegate->reset_got_fatal_error(); |
604 factory = new CountedBrowserAccessibilityFactory(); | 604 factory = new CountedBrowserAccessibilityFactory(); |
605 manager.reset(BrowserAccessibilityManager::Create( | 605 manager.reset(BrowserAccessibilityManager::Create( |
606 root2, | 606 root2, |
607 delegate.get(), | 607 delegate.get(), |
608 factory)); | 608 factory)); |
609 ASSERT_FALSE(delegate->got_fatal_error()); | 609 ASSERT_FALSE(delegate->got_fatal_error()); |
610 manager->UpdateNodesForTesting(child1, child2); | 610 manager->UpdateNodesForTesting(child1, child2); |
611 ASSERT_TRUE(delegate->got_fatal_error()); | 611 ASSERT_TRUE(delegate->got_fatal_error()); |
612 } | 612 } |
613 | 613 |
614 TEST(BrowserAccessibilityManagerTest, BoundsForRange) { | 614 TEST(BrowserAccessibilityManagerTest, BoundsForRange) { |
615 AccessibilityNodeData root; | 615 AccessibilityNodeData root; |
616 root.id = 1; | 616 root.id = 1; |
617 root.role = WebKit::WebAXRoleRootWebArea; | 617 root.role = blink::WebAXRoleRootWebArea; |
618 | 618 |
619 AccessibilityNodeData static_text; | 619 AccessibilityNodeData static_text; |
620 static_text.id = 2; | 620 static_text.id = 2; |
621 static_text.SetValue("Hello, world."); | 621 static_text.SetValue("Hello, world."); |
622 static_text.role = WebKit::WebAXRoleStaticText; | 622 static_text.role = blink::WebAXRoleStaticText; |
623 static_text.location = gfx::Rect(100, 100, 29, 18); | 623 static_text.location = gfx::Rect(100, 100, 29, 18); |
624 root.child_ids.push_back(2); | 624 root.child_ids.push_back(2); |
625 | 625 |
626 AccessibilityNodeData inline_text1; | 626 AccessibilityNodeData inline_text1; |
627 inline_text1.id = 3; | 627 inline_text1.id = 3; |
628 inline_text1.SetValue("Hello, "); | 628 inline_text1.SetValue("Hello, "); |
629 inline_text1.role = WebKit::WebAXRoleInlineTextBox; | 629 inline_text1.role = blink::WebAXRoleInlineTextBox; |
630 inline_text1.location = gfx::Rect(100, 100, 29, 9); | 630 inline_text1.location = gfx::Rect(100, 100, 29, 9); |
631 inline_text1.AddIntAttribute(AccessibilityNodeData::ATTR_TEXT_DIRECTION, | 631 inline_text1.AddIntAttribute(AccessibilityNodeData::ATTR_TEXT_DIRECTION, |
632 WebKit::WebAXTextDirectionLR); | 632 blink::WebAXTextDirectionLR); |
633 std::vector<int32> character_offsets1; | 633 std::vector<int32> character_offsets1; |
634 character_offsets1.push_back(6); // 0 | 634 character_offsets1.push_back(6); // 0 |
635 character_offsets1.push_back(11); // 1 | 635 character_offsets1.push_back(11); // 1 |
636 character_offsets1.push_back(16); // 2 | 636 character_offsets1.push_back(16); // 2 |
637 character_offsets1.push_back(21); // 3 | 637 character_offsets1.push_back(21); // 3 |
638 character_offsets1.push_back(26); // 4 | 638 character_offsets1.push_back(26); // 4 |
639 character_offsets1.push_back(29); // 5 | 639 character_offsets1.push_back(29); // 5 |
640 character_offsets1.push_back(29); // 6 (note that the space has no width) | 640 character_offsets1.push_back(29); // 6 (note that the space has no width) |
641 inline_text1.AddIntListAttribute( | 641 inline_text1.AddIntListAttribute( |
642 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS, character_offsets1); | 642 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS, character_offsets1); |
643 static_text.child_ids.push_back(3); | 643 static_text.child_ids.push_back(3); |
644 | 644 |
645 AccessibilityNodeData inline_text2; | 645 AccessibilityNodeData inline_text2; |
646 inline_text2.id = 4; | 646 inline_text2.id = 4; |
647 inline_text2.SetValue("world."); | 647 inline_text2.SetValue("world."); |
648 inline_text2.role = WebKit::WebAXRoleInlineTextBox; | 648 inline_text2.role = blink::WebAXRoleInlineTextBox; |
649 inline_text2.location = gfx::Rect(100, 109, 28, 9); | 649 inline_text2.location = gfx::Rect(100, 109, 28, 9); |
650 inline_text2.AddIntAttribute(AccessibilityNodeData::ATTR_TEXT_DIRECTION, | 650 inline_text2.AddIntAttribute(AccessibilityNodeData::ATTR_TEXT_DIRECTION, |
651 WebKit::WebAXTextDirectionLR); | 651 blink::WebAXTextDirectionLR); |
652 std::vector<int32> character_offsets2; | 652 std::vector<int32> character_offsets2; |
653 character_offsets2.push_back(5); | 653 character_offsets2.push_back(5); |
654 character_offsets2.push_back(10); | 654 character_offsets2.push_back(10); |
655 character_offsets2.push_back(15); | 655 character_offsets2.push_back(15); |
656 character_offsets2.push_back(20); | 656 character_offsets2.push_back(20); |
657 character_offsets2.push_back(25); | 657 character_offsets2.push_back(25); |
658 character_offsets2.push_back(28); | 658 character_offsets2.push_back(28); |
659 inline_text2.AddIntListAttribute( | 659 inline_text2.AddIntListAttribute( |
660 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS, character_offsets2); | 660 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS, character_offsets2); |
661 static_text.child_ids.push_back(4); | 661 static_text.child_ids.push_back(4); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 // In this example, we assume that the string "123abc" is rendered with | 698 // In this example, we assume that the string "123abc" is rendered with |
699 // "123" going left-to-right and "abc" going right-to-left. In other | 699 // "123" going left-to-right and "abc" going right-to-left. In other |
700 // words, on-screen it would look like "123cba". This is possible to | 700 // words, on-screen it would look like "123cba". This is possible to |
701 // acheive if the source string had unicode control characters | 701 // acheive if the source string had unicode control characters |
702 // to switch directions. This test doesn't worry about how, though - it just | 702 // to switch directions. This test doesn't worry about how, though - it just |
703 // tests that if something like that were to occur, GetLocalBoundsForRange | 703 // tests that if something like that were to occur, GetLocalBoundsForRange |
704 // returns the correct bounds for different ranges. | 704 // returns the correct bounds for different ranges. |
705 | 705 |
706 AccessibilityNodeData root; | 706 AccessibilityNodeData root; |
707 root.id = 1; | 707 root.id = 1; |
708 root.role = WebKit::WebAXRoleRootWebArea; | 708 root.role = blink::WebAXRoleRootWebArea; |
709 | 709 |
710 AccessibilityNodeData static_text; | 710 AccessibilityNodeData static_text; |
711 static_text.id = 2; | 711 static_text.id = 2; |
712 static_text.SetValue("123abc"); | 712 static_text.SetValue("123abc"); |
713 static_text.role = WebKit::WebAXRoleStaticText; | 713 static_text.role = blink::WebAXRoleStaticText; |
714 static_text.location = gfx::Rect(100, 100, 60, 20); | 714 static_text.location = gfx::Rect(100, 100, 60, 20); |
715 root.child_ids.push_back(2); | 715 root.child_ids.push_back(2); |
716 | 716 |
717 AccessibilityNodeData inline_text1; | 717 AccessibilityNodeData inline_text1; |
718 inline_text1.id = 3; | 718 inline_text1.id = 3; |
719 inline_text1.SetValue("123"); | 719 inline_text1.SetValue("123"); |
720 inline_text1.role = WebKit::WebAXRoleInlineTextBox; | 720 inline_text1.role = blink::WebAXRoleInlineTextBox; |
721 inline_text1.location = gfx::Rect(100, 100, 30, 20); | 721 inline_text1.location = gfx::Rect(100, 100, 30, 20); |
722 inline_text1.AddIntAttribute(AccessibilityNodeData::ATTR_TEXT_DIRECTION, | 722 inline_text1.AddIntAttribute(AccessibilityNodeData::ATTR_TEXT_DIRECTION, |
723 WebKit::WebAXTextDirectionLR); | 723 blink::WebAXTextDirectionLR); |
724 std::vector<int32> character_offsets1; | 724 std::vector<int32> character_offsets1; |
725 character_offsets1.push_back(10); // 0 | 725 character_offsets1.push_back(10); // 0 |
726 character_offsets1.push_back(20); // 1 | 726 character_offsets1.push_back(20); // 1 |
727 character_offsets1.push_back(30); // 2 | 727 character_offsets1.push_back(30); // 2 |
728 inline_text1.AddIntListAttribute( | 728 inline_text1.AddIntListAttribute( |
729 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS, character_offsets1); | 729 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS, character_offsets1); |
730 static_text.child_ids.push_back(3); | 730 static_text.child_ids.push_back(3); |
731 | 731 |
732 AccessibilityNodeData inline_text2; | 732 AccessibilityNodeData inline_text2; |
733 inline_text2.id = 4; | 733 inline_text2.id = 4; |
734 inline_text2.SetValue("abc"); | 734 inline_text2.SetValue("abc"); |
735 inline_text2.role = WebKit::WebAXRoleInlineTextBox; | 735 inline_text2.role = blink::WebAXRoleInlineTextBox; |
736 inline_text2.location = gfx::Rect(130, 100, 30, 20); | 736 inline_text2.location = gfx::Rect(130, 100, 30, 20); |
737 inline_text2.AddIntAttribute(AccessibilityNodeData::ATTR_TEXT_DIRECTION, | 737 inline_text2.AddIntAttribute(AccessibilityNodeData::ATTR_TEXT_DIRECTION, |
738 WebKit::WebAXTextDirectionRL); | 738 blink::WebAXTextDirectionRL); |
739 std::vector<int32> character_offsets2; | 739 std::vector<int32> character_offsets2; |
740 character_offsets2.push_back(10); | 740 character_offsets2.push_back(10); |
741 character_offsets2.push_back(20); | 741 character_offsets2.push_back(20); |
742 character_offsets2.push_back(30); | 742 character_offsets2.push_back(30); |
743 inline_text2.AddIntListAttribute( | 743 inline_text2.AddIntListAttribute( |
744 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS, character_offsets2); | 744 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS, character_offsets2); |
745 static_text.child_ids.push_back(4); | 745 static_text.child_ids.push_back(4); |
746 | 746 |
747 scoped_ptr<BrowserAccessibilityManager> manager( | 747 scoped_ptr<BrowserAccessibilityManager> manager( |
748 BrowserAccessibilityManager::Create( | 748 BrowserAccessibilityManager::Create( |
(...skipping 21 matching lines...) Expand all Loading... |
770 EXPECT_EQ(gfx::Rect(130, 100, 30, 20).ToString(), | 770 EXPECT_EQ(gfx::Rect(130, 100, 30, 20).ToString(), |
771 static_text_accessible->GetLocalBoundsForRange(3, 3).ToString()); | 771 static_text_accessible->GetLocalBoundsForRange(3, 3).ToString()); |
772 | 772 |
773 // This range is only two characters, but because of the direction switch | 773 // This range is only two characters, but because of the direction switch |
774 // the bounds are as wide as four characters. | 774 // the bounds are as wide as four characters. |
775 EXPECT_EQ(gfx::Rect(120, 100, 40, 20).ToString(), | 775 EXPECT_EQ(gfx::Rect(120, 100, 40, 20).ToString(), |
776 static_text_accessible->GetLocalBoundsForRange(2, 2).ToString()); | 776 static_text_accessible->GetLocalBoundsForRange(2, 2).ToString()); |
777 } | 777 } |
778 | 778 |
779 } // namespace content | 779 } // namespace content |
OLD | NEW |