Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: content/browser/accessibility/browser_accessibility_manager_unittest.cc

Issue 2860883003: A11y: Add/refactor methods for manipulating bitfields on AXNodeData. (Closed)
Patch Set: Delete AXNodeData::Init() and clear bitfields in AXNodeData() instead. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } // anonymous namespace 93 } // anonymous namespace
94 94
95 TEST(BrowserAccessibilityManagerTest, TestNoLeaks) { 95 TEST(BrowserAccessibilityManagerTest, TestNoLeaks) {
96 // Create ui::AXNodeData objects for a simple document tree, 96 // Create ui::AXNodeData objects for a simple document tree,
97 // representing the accessibility information used to initialize 97 // representing the accessibility information used to initialize
98 // BrowserAccessibilityManager. 98 // BrowserAccessibilityManager.
99 ui::AXNodeData button; 99 ui::AXNodeData button;
100 button.id = 2; 100 button.id = 2;
101 button.SetName("Button"); 101 button.SetName("Button");
102 button.role = ui::AX_ROLE_BUTTON; 102 button.role = ui::AX_ROLE_BUTTON;
103 button.state = 0;
104 103
105 ui::AXNodeData checkbox; 104 ui::AXNodeData checkbox;
106 checkbox.id = 3; 105 checkbox.id = 3;
107 checkbox.SetName("Checkbox"); 106 checkbox.SetName("Checkbox");
108 checkbox.role = ui::AX_ROLE_CHECK_BOX; 107 checkbox.role = ui::AX_ROLE_CHECK_BOX;
109 checkbox.state = 0;
110 108
111 ui::AXNodeData root; 109 ui::AXNodeData root;
112 root.id = 1; 110 root.id = 1;
113 root.SetName("Document"); 111 root.SetName("Document");
114 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 112 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
115 root.state = 0;
116 root.child_ids.push_back(2); 113 root.child_ids.push_back(2);
117 root.child_ids.push_back(3); 114 root.child_ids.push_back(3);
118 115
119 // Construct a BrowserAccessibilityManager with this 116 // Construct a BrowserAccessibilityManager with this
120 // ui::AXNodeData tree and a factory for an instance-counting 117 // ui::AXNodeData tree and a factory for an instance-counting
121 // BrowserAccessibility, and ensure that exactly 3 instances were 118 // BrowserAccessibility, and ensure that exactly 3 instances were
122 // created. Note that the manager takes ownership of the factory. 119 // created. Note that the manager takes ownership of the factory.
123 CountedBrowserAccessibility::global_obj_count_ = 0; 120 CountedBrowserAccessibility::global_obj_count_ = 0;
124 BrowserAccessibilityManager* manager = 121 BrowserAccessibilityManager* manager =
125 BrowserAccessibilityManager::Create( 122 BrowserAccessibilityManager::Create(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // 167 //
171 // root 168 // root
172 // child1 169 // child1
173 // child2 170 // child2
174 // child3 171 // child3
175 172
176 ui::AXNodeData tree1_child1; 173 ui::AXNodeData tree1_child1;
177 tree1_child1.id = 2; 174 tree1_child1.id = 2;
178 tree1_child1.SetName("Child1"); 175 tree1_child1.SetName("Child1");
179 tree1_child1.role = ui::AX_ROLE_BUTTON; 176 tree1_child1.role = ui::AX_ROLE_BUTTON;
180 tree1_child1.state = 0;
181 177
182 ui::AXNodeData tree1_child2; 178 ui::AXNodeData tree1_child2;
183 tree1_child2.id = 3; 179 tree1_child2.id = 3;
184 tree1_child2.SetName("Child2"); 180 tree1_child2.SetName("Child2");
185 tree1_child2.role = ui::AX_ROLE_BUTTON; 181 tree1_child2.role = ui::AX_ROLE_BUTTON;
186 tree1_child2.state = 0;
187 182
188 ui::AXNodeData tree1_child3; 183 ui::AXNodeData tree1_child3;
189 tree1_child3.id = 4; 184 tree1_child3.id = 4;
190 tree1_child3.SetName("Child3"); 185 tree1_child3.SetName("Child3");
191 tree1_child3.role = ui::AX_ROLE_BUTTON; 186 tree1_child3.role = ui::AX_ROLE_BUTTON;
192 tree1_child3.state = 0;
193 187
194 ui::AXNodeData tree1_root; 188 ui::AXNodeData tree1_root;
195 tree1_root.id = 1; 189 tree1_root.id = 1;
196 tree1_root.SetName("Document"); 190 tree1_root.SetName("Document");
197 tree1_root.role = ui::AX_ROLE_ROOT_WEB_AREA; 191 tree1_root.role = ui::AX_ROLE_ROOT_WEB_AREA;
198 tree1_root.state = 0;
199 tree1_root.child_ids.push_back(2); 192 tree1_root.child_ids.push_back(2);
200 tree1_root.child_ids.push_back(3); 193 tree1_root.child_ids.push_back(3);
201 tree1_root.child_ids.push_back(4); 194 tree1_root.child_ids.push_back(4);
202 195
203 // Tree 2: 196 // Tree 2:
204 // 197 //
205 // root 198 // root
206 // child0 <-- inserted 199 // child0 <-- inserted
207 // child1 200 // child1
208 // child2 201 // child2
209 // <-- child3 deleted 202 // <-- child3 deleted
210 203
211 ui::AXNodeData tree2_child0; 204 ui::AXNodeData tree2_child0;
212 tree2_child0.id = 5; 205 tree2_child0.id = 5;
213 tree2_child0.SetName("Child0"); 206 tree2_child0.SetName("Child0");
214 tree2_child0.role = ui::AX_ROLE_BUTTON; 207 tree2_child0.role = ui::AX_ROLE_BUTTON;
215 tree2_child0.state = 0;
216 208
217 ui::AXNodeData tree2_root; 209 ui::AXNodeData tree2_root;
218 tree2_root.id = 1; 210 tree2_root.id = 1;
219 tree2_root.SetName("DocumentChanged"); 211 tree2_root.SetName("DocumentChanged");
220 tree2_root.role = ui::AX_ROLE_ROOT_WEB_AREA; 212 tree2_root.role = ui::AX_ROLE_ROOT_WEB_AREA;
221 tree2_root.state = 0;
222 tree2_root.child_ids.push_back(5); 213 tree2_root.child_ids.push_back(5);
223 tree2_root.child_ids.push_back(2); 214 tree2_root.child_ids.push_back(2);
224 tree2_root.child_ids.push_back(3); 215 tree2_root.child_ids.push_back(3);
225 216
226 // Construct a BrowserAccessibilityManager with tree1. 217 // Construct a BrowserAccessibilityManager with tree1.
227 CountedBrowserAccessibility::global_obj_count_ = 0; 218 CountedBrowserAccessibility::global_obj_count_ = 0;
228 BrowserAccessibilityManager* manager = 219 BrowserAccessibilityManager* manager =
229 BrowserAccessibilityManager::Create( 220 BrowserAccessibilityManager::Create(
230 MakeAXTreeUpdate(tree1_root, 221 MakeAXTreeUpdate(tree1_root,
231 tree1_child1, tree1_child2, tree1_child3), 222 tree1_child1, tree1_child2, tree1_child3),
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // grandchild1 296 // grandchild1
306 // child2 297 // child2
307 // grandchild2 298 // grandchild2
308 // child3 299 // child3
309 // grandchild3 300 // grandchild3
310 301
311 ui::AXNodeData tree1_grandchild1; 302 ui::AXNodeData tree1_grandchild1;
312 tree1_grandchild1.id = 4; 303 tree1_grandchild1.id = 4;
313 tree1_grandchild1.SetName("GrandChild1"); 304 tree1_grandchild1.SetName("GrandChild1");
314 tree1_grandchild1.role = ui::AX_ROLE_BUTTON; 305 tree1_grandchild1.role = ui::AX_ROLE_BUTTON;
315 tree1_grandchild1.state = 0;
316 306
317 ui::AXNodeData tree1_child1; 307 ui::AXNodeData tree1_child1;
318 tree1_child1.id = 3; 308 tree1_child1.id = 3;
319 tree1_child1.SetName("Child1"); 309 tree1_child1.SetName("Child1");
320 tree1_child1.role = ui::AX_ROLE_BUTTON; 310 tree1_child1.role = ui::AX_ROLE_BUTTON;
321 tree1_child1.state = 0;
322 tree1_child1.child_ids.push_back(4); 311 tree1_child1.child_ids.push_back(4);
323 312
324 ui::AXNodeData tree1_grandchild2; 313 ui::AXNodeData tree1_grandchild2;
325 tree1_grandchild2.id = 6; 314 tree1_grandchild2.id = 6;
326 tree1_grandchild2.SetName("GrandChild1"); 315 tree1_grandchild2.SetName("GrandChild1");
327 tree1_grandchild2.role = ui::AX_ROLE_BUTTON; 316 tree1_grandchild2.role = ui::AX_ROLE_BUTTON;
328 tree1_grandchild2.state = 0;
329 317
330 ui::AXNodeData tree1_child2; 318 ui::AXNodeData tree1_child2;
331 tree1_child2.id = 5; 319 tree1_child2.id = 5;
332 tree1_child2.SetName("Child2"); 320 tree1_child2.SetName("Child2");
333 tree1_child2.role = ui::AX_ROLE_BUTTON; 321 tree1_child2.role = ui::AX_ROLE_BUTTON;
334 tree1_child2.state = 0;
335 tree1_child2.child_ids.push_back(6); 322 tree1_child2.child_ids.push_back(6);
336 323
337 ui::AXNodeData tree1_grandchild3; 324 ui::AXNodeData tree1_grandchild3;
338 tree1_grandchild3.id = 8; 325 tree1_grandchild3.id = 8;
339 tree1_grandchild3.SetName("GrandChild3"); 326 tree1_grandchild3.SetName("GrandChild3");
340 tree1_grandchild3.role = ui::AX_ROLE_BUTTON; 327 tree1_grandchild3.role = ui::AX_ROLE_BUTTON;
341 tree1_grandchild3.state = 0;
342 328
343 ui::AXNodeData tree1_child3; 329 ui::AXNodeData tree1_child3;
344 tree1_child3.id = 7; 330 tree1_child3.id = 7;
345 tree1_child3.SetName("Child3"); 331 tree1_child3.SetName("Child3");
346 tree1_child3.role = ui::AX_ROLE_BUTTON; 332 tree1_child3.role = ui::AX_ROLE_BUTTON;
347 tree1_child3.state = 0;
348 tree1_child3.child_ids.push_back(8); 333 tree1_child3.child_ids.push_back(8);
349 334
350 ui::AXNodeData tree1_container; 335 ui::AXNodeData tree1_container;
351 tree1_container.id = 2; 336 tree1_container.id = 2;
352 tree1_container.SetName("Container"); 337 tree1_container.SetName("Container");
353 tree1_container.role = ui::AX_ROLE_GROUP; 338 tree1_container.role = ui::AX_ROLE_GROUP;
354 tree1_container.state = 0;
355 tree1_container.child_ids.push_back(3); 339 tree1_container.child_ids.push_back(3);
356 tree1_container.child_ids.push_back(5); 340 tree1_container.child_ids.push_back(5);
357 tree1_container.child_ids.push_back(7); 341 tree1_container.child_ids.push_back(7);
358 342
359 ui::AXNodeData tree1_root; 343 ui::AXNodeData tree1_root;
360 tree1_root.id = 1; 344 tree1_root.id = 1;
361 tree1_root.SetName("Document"); 345 tree1_root.SetName("Document");
362 tree1_root.role = ui::AX_ROLE_ROOT_WEB_AREA; 346 tree1_root.role = ui::AX_ROLE_ROOT_WEB_AREA;
363 tree1_root.state = 0;
364 tree1_root.child_ids.push_back(2); 347 tree1_root.child_ids.push_back(2);
365 348
366 // Tree 2: 349 // Tree 2:
367 // 350 //
368 // root 351 // root
369 // container 352 // container
370 // child0 <-- inserted 353 // child0 <-- inserted
371 // grandchild0 <-- 354 // grandchild0 <--
372 // child1 355 // child1
373 // grandchild1 356 // grandchild1
374 // child2 357 // child2
375 // grandchild2 358 // grandchild2
376 // <-- child3 (and grandchild3) deleted 359 // <-- child3 (and grandchild3) deleted
377 360
378 ui::AXNodeData tree2_grandchild0; 361 ui::AXNodeData tree2_grandchild0;
379 tree2_grandchild0.id = 9; 362 tree2_grandchild0.id = 9;
380 tree2_grandchild0.SetName("GrandChild0"); 363 tree2_grandchild0.SetName("GrandChild0");
381 tree2_grandchild0.role = ui::AX_ROLE_BUTTON; 364 tree2_grandchild0.role = ui::AX_ROLE_BUTTON;
382 tree2_grandchild0.state = 0;
383 365
384 ui::AXNodeData tree2_child0; 366 ui::AXNodeData tree2_child0;
385 tree2_child0.id = 10; 367 tree2_child0.id = 10;
386 tree2_child0.SetName("Child0"); 368 tree2_child0.SetName("Child0");
387 tree2_child0.role = ui::AX_ROLE_BUTTON; 369 tree2_child0.role = ui::AX_ROLE_BUTTON;
388 tree2_child0.state = 0;
389 tree2_child0.child_ids.push_back(9); 370 tree2_child0.child_ids.push_back(9);
390 371
391 ui::AXNodeData tree2_container; 372 ui::AXNodeData tree2_container;
392 tree2_container.id = 2; 373 tree2_container.id = 2;
393 tree2_container.SetName("Container"); 374 tree2_container.SetName("Container");
394 tree2_container.role = ui::AX_ROLE_GROUP; 375 tree2_container.role = ui::AX_ROLE_GROUP;
395 tree2_container.state = 0;
396 tree2_container.child_ids.push_back(10); 376 tree2_container.child_ids.push_back(10);
397 tree2_container.child_ids.push_back(3); 377 tree2_container.child_ids.push_back(3);
398 tree2_container.child_ids.push_back(5); 378 tree2_container.child_ids.push_back(5);
399 379
400 // Construct a BrowserAccessibilityManager with tree1. 380 // Construct a BrowserAccessibilityManager with tree1.
401 CountedBrowserAccessibility::global_obj_count_ = 0; 381 CountedBrowserAccessibility::global_obj_count_ = 0;
402 BrowserAccessibilityManager* manager = 382 BrowserAccessibilityManager* manager =
403 BrowserAccessibilityManager::Create( 383 BrowserAccessibilityManager::Create(
404 MakeAXTreeUpdate(tree1_root, tree1_container, 384 MakeAXTreeUpdate(tree1_root, tree1_container,
405 tree1_child1, tree1_grandchild1, 385 tree1_child1, tree1_grandchild1,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 TEST(BrowserAccessibilityManagerTest, TestMoveChildUp) { 457 TEST(BrowserAccessibilityManagerTest, TestMoveChildUp) {
478 // Tree 1: 458 // Tree 1:
479 // 459 //
480 // 1 460 // 1
481 // 2 461 // 2
482 // 3 462 // 3
483 // 4 463 // 4
484 464
485 ui::AXNodeData tree1_4; 465 ui::AXNodeData tree1_4;
486 tree1_4.id = 4; 466 tree1_4.id = 4;
487 tree1_4.state = 0;
488 467
489 ui::AXNodeData tree1_3; 468 ui::AXNodeData tree1_3;
490 tree1_3.id = 3; 469 tree1_3.id = 3;
491 tree1_3.state = 0;
492 tree1_3.child_ids.push_back(4); 470 tree1_3.child_ids.push_back(4);
493 471
494 ui::AXNodeData tree1_2; 472 ui::AXNodeData tree1_2;
495 tree1_2.id = 2; 473 tree1_2.id = 2;
496 tree1_2.state = 0;
497 474
498 ui::AXNodeData tree1_1; 475 ui::AXNodeData tree1_1;
499 tree1_1.id = 1; 476 tree1_1.id = 1;
500 tree1_1.role = ui::AX_ROLE_ROOT_WEB_AREA; 477 tree1_1.role = ui::AX_ROLE_ROOT_WEB_AREA;
501 tree1_1.state = 0;
502 tree1_1.child_ids.push_back(2); 478 tree1_1.child_ids.push_back(2);
503 tree1_1.child_ids.push_back(3); 479 tree1_1.child_ids.push_back(3);
504 480
505 // Tree 2: 481 // Tree 2:
506 // 482 //
507 // 1 483 // 1
508 // 4 <-- moves up a level and gains child 484 // 4 <-- moves up a level and gains child
509 // 6 <-- new 485 // 6 <-- new
510 // 5 <-- new 486 // 5 <-- new
511 487
512 ui::AXNodeData tree2_6; 488 ui::AXNodeData tree2_6;
513 tree2_6.id = 6; 489 tree2_6.id = 6;
514 tree2_6.state = 0;
515 490
516 ui::AXNodeData tree2_5; 491 ui::AXNodeData tree2_5;
517 tree2_5.id = 5; 492 tree2_5.id = 5;
518 tree2_5.state = 0;
519 493
520 ui::AXNodeData tree2_4; 494 ui::AXNodeData tree2_4;
521 tree2_4.id = 4; 495 tree2_4.id = 4;
522 tree2_4.state = 0;
523 tree2_4.child_ids.push_back(6); 496 tree2_4.child_ids.push_back(6);
524 497
525 ui::AXNodeData tree2_1; 498 ui::AXNodeData tree2_1;
526 tree2_1.id = 1; 499 tree2_1.id = 1;
527 tree2_1.state = 0;
528 tree2_1.child_ids.push_back(4); 500 tree2_1.child_ids.push_back(4);
529 tree2_1.child_ids.push_back(5); 501 tree2_1.child_ids.push_back(5);
530 502
531 // Construct a BrowserAccessibilityManager with tree1. 503 // Construct a BrowserAccessibilityManager with tree1.
532 CountedBrowserAccessibility::global_obj_count_ = 0; 504 CountedBrowserAccessibility::global_obj_count_ = 0;
533 BrowserAccessibilityManager* manager = 505 BrowserAccessibilityManager* manager =
534 BrowserAccessibilityManager::Create( 506 BrowserAccessibilityManager::Create(
535 MakeAXTreeUpdate(tree1_1, tree1_2, tree1_3, tree1_4), 507 MakeAXTreeUpdate(tree1_1, tree1_2, tree1_3, tree1_4),
536 nullptr, 508 nullptr,
537 new CountedBrowserAccessibilityFactory()); 509 new CountedBrowserAccessibilityFactory());
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 base::ASCIIToUTF16("Hello world."), 1486 base::ASCIIToUTF16("Hello world."),
1515 BrowserAccessibilityManager::GetTextForRange( 1487 BrowserAccessibilityManager::GetTextForRange(
1516 *paragraph_line2_accessible, 6, *paragraph_line1_accessible, 0)); 1488 *paragraph_line2_accessible, 6, *paragraph_line1_accessible, 0));
1517 } 1489 }
1518 1490
1519 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash) { 1491 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash) {
1520 // Create a really simple tree with one root node and one focused child. 1492 // Create a really simple tree with one root node and one focused child.
1521 ui::AXNodeData root; 1493 ui::AXNodeData root;
1522 root.id = 1; 1494 root.id = 1;
1523 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 1495 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
1524 root.state = 0;
1525 root.child_ids.push_back(2); 1496 root.child_ids.push_back(2);
1526 1497
1527 ui::AXNodeData node2; 1498 ui::AXNodeData node2;
1528 node2.id = 2; 1499 node2.id = 2;
1529 1500
1530 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2); 1501 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2);
1531 initial_state.has_tree_data = true; 1502 initial_state.has_tree_data = true;
1532 initial_state.tree_data.focus_id = 2; 1503 initial_state.tree_data.focus_id = 2;
1533 std::unique_ptr<BrowserAccessibilityManager> manager( 1504 std::unique_ptr<BrowserAccessibilityManager> manager(
1534 BrowserAccessibilityManager::Create( 1505 BrowserAccessibilityManager::Create(
1535 initial_state, nullptr, new CountedBrowserAccessibilityFactory())); 1506 initial_state, nullptr, new CountedBrowserAccessibilityFactory()));
1536 1507
1537 ASSERT_EQ(1, manager->GetRoot()->GetId()); 1508 ASSERT_EQ(1, manager->GetRoot()->GetId());
1538 ASSERT_EQ(2, manager->GetFocus()->GetId()); 1509 ASSERT_EQ(2, manager->GetFocus()->GetId());
1539 1510
1540 // Now replace the tree with a new tree consisting of a single root. 1511 // Now replace the tree with a new tree consisting of a single root.
1541 ui::AXNodeData root2; 1512 ui::AXNodeData root2;
1542 root2.id = 3; 1513 root2.id = 3;
1543 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; 1514 root2.role = ui::AX_ROLE_ROOT_WEB_AREA;
1544 root2.state = 0;
1545 1515
1546 std::vector<AXEventNotificationDetails> events2; 1516 std::vector<AXEventNotificationDetails> events2;
1547 events2.push_back(AXEventNotificationDetails()); 1517 events2.push_back(AXEventNotificationDetails());
1548 events2[0].update = MakeAXTreeUpdate(root2); 1518 events2[0].update = MakeAXTreeUpdate(root2);
1549 events2[0].id = -1; 1519 events2[0].id = -1;
1550 events2[0].event_type = ui::AX_EVENT_NONE; 1520 events2[0].event_type = ui::AX_EVENT_NONE;
1551 manager->OnAccessibilityEvents(events2); 1521 manager->OnAccessibilityEvents(events2);
1552 1522
1553 // Make sure that the focused node was updated to the new root and 1523 // Make sure that the focused node was updated to the new root and
1554 // that this doesn't crash. 1524 // that this doesn't crash.
1555 ASSERT_EQ(3, manager->GetRoot()->GetId()); 1525 ASSERT_EQ(3, manager->GetRoot()->GetId());
1556 ASSERT_EQ(3, manager->GetFocus()->GetId()); 1526 ASSERT_EQ(3, manager->GetFocus()->GetId());
1557 } 1527 }
1558 1528
1559 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash2) { 1529 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash2) {
1560 // Create a really simple tree with one root node and one focused child. 1530 // Create a really simple tree with one root node and one focused child.
1561 ui::AXNodeData root; 1531 ui::AXNodeData root;
1562 root.id = 1; 1532 root.id = 1;
1563 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 1533 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
1564 root.state = 0;
1565 root.child_ids.push_back(2); 1534 root.child_ids.push_back(2);
1566 root.child_ids.push_back(3); 1535 root.child_ids.push_back(3);
1567 root.child_ids.push_back(4); 1536 root.child_ids.push_back(4);
1568 1537
1569 ui::AXNodeData node2; 1538 ui::AXNodeData node2;
1570 node2.id = 2; 1539 node2.id = 2;
1571 1540
1572 ui::AXNodeData node3; 1541 ui::AXNodeData node3;
1573 node3.id = 3; 1542 node3.id = 3;
1574 node3.state = 0;
1575 1543
1576 ui::AXNodeData node4; 1544 ui::AXNodeData node4;
1577 node4.id = 4; 1545 node4.id = 4;
1578 node4.state = 0;
1579 1546
1580 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2, node3, node4); 1547 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2, node3, node4);
1581 initial_state.has_tree_data = true; 1548 initial_state.has_tree_data = true;
1582 initial_state.tree_data.focus_id = 2; 1549 initial_state.tree_data.focus_id = 2;
1583 std::unique_ptr<BrowserAccessibilityManager> manager( 1550 std::unique_ptr<BrowserAccessibilityManager> manager(
1584 BrowserAccessibilityManager::Create( 1551 BrowserAccessibilityManager::Create(
1585 initial_state, nullptr, new CountedBrowserAccessibilityFactory())); 1552 initial_state, nullptr, new CountedBrowserAccessibilityFactory()));
1586 1553
1587 ASSERT_EQ(1, manager->GetRoot()->GetId()); 1554 ASSERT_EQ(1, manager->GetRoot()->GetId());
1588 ASSERT_EQ(2, manager->GetFocus()->GetId()); 1555 ASSERT_EQ(2, manager->GetFocus()->GetId());
1589 1556
1590 // Now replace the tree with a new tree consisting of a single root. 1557 // Now replace the tree with a new tree consisting of a single root.
1591 ui::AXNodeData root2; 1558 ui::AXNodeData root2;
1592 root2.id = 3; 1559 root2.id = 3;
1593 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; 1560 root2.role = ui::AX_ROLE_ROOT_WEB_AREA;
1594 root2.state = 0;
1595 1561
1596 // Make an update the explicitly clears the previous root. 1562 // Make an update the explicitly clears the previous root.
1597 std::vector<AXEventNotificationDetails> events2; 1563 std::vector<AXEventNotificationDetails> events2;
1598 events2.push_back(AXEventNotificationDetails()); 1564 events2.push_back(AXEventNotificationDetails());
1599 events2[0].update = MakeAXTreeUpdate(root2); 1565 events2[0].update = MakeAXTreeUpdate(root2);
1600 events2[0].update.node_id_to_clear = 1; 1566 events2[0].update.node_id_to_clear = 1;
1601 events2[0].id = -1; 1567 events2[0].id = -1;
1602 events2[0].event_type = ui::AX_EVENT_NONE; 1568 events2[0].event_type = ui::AX_EVENT_NONE;
1603 manager->OnAccessibilityEvents(events2); 1569 manager->OnAccessibilityEvents(events2);
1604 1570
1605 // Make sure that the focused node was updated to the new root and 1571 // Make sure that the focused node was updated to the new root and
1606 // that this doesn't crash. 1572 // that this doesn't crash.
1607 ASSERT_EQ(3, manager->GetRoot()->GetId()); 1573 ASSERT_EQ(3, manager->GetRoot()->GetId());
1608 ASSERT_EQ(3, manager->GetFocus()->GetId()); 1574 ASSERT_EQ(3, manager->GetFocus()->GetId());
1609 } 1575 }
1610 1576
1611 } // namespace content 1577 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698