| 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 <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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 bool got_fatal_error_; | 90 bool got_fatal_error_; |
| 91 }; | 91 }; |
| 92 | 92 |
| 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.ClearBitfields(); |
| 100 button.id = 2; | 101 button.id = 2; |
| 101 button.SetName("Button"); | 102 button.SetName("Button"); |
| 102 button.role = ui::AX_ROLE_BUTTON; | 103 button.role = ui::AX_ROLE_BUTTON; |
| 103 button.state = 0; | |
| 104 | 104 |
| 105 ui::AXNodeData checkbox; | 105 ui::AXNodeData checkbox; |
| 106 checkbox.ClearBitfields(); |
| 106 checkbox.id = 3; | 107 checkbox.id = 3; |
| 107 checkbox.SetName("Checkbox"); | 108 checkbox.SetName("Checkbox"); |
| 108 checkbox.role = ui::AX_ROLE_CHECK_BOX; | 109 checkbox.role = ui::AX_ROLE_CHECK_BOX; |
| 109 checkbox.state = 0; | |
| 110 | 110 |
| 111 ui::AXNodeData root; | 111 ui::AXNodeData root; |
| 112 root.ClearBitfields(); |
| 112 root.id = 1; | 113 root.id = 1; |
| 113 root.SetName("Document"); | 114 root.SetName("Document"); |
| 114 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 115 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 115 root.state = 0; | |
| 116 root.child_ids.push_back(2); | 116 root.child_ids.push_back(2); |
| 117 root.child_ids.push_back(3); | 117 root.child_ids.push_back(3); |
| 118 | 118 |
| 119 // Construct a BrowserAccessibilityManager with this | 119 // Construct a BrowserAccessibilityManager with this |
| 120 // ui::AXNodeData tree and a factory for an instance-counting | 120 // ui::AXNodeData tree and a factory for an instance-counting |
| 121 // BrowserAccessibility, and ensure that exactly 3 instances were | 121 // BrowserAccessibility, and ensure that exactly 3 instances were |
| 122 // created. Note that the manager takes ownership of the factory. | 122 // created. Note that the manager takes ownership of the factory. |
| 123 CountedBrowserAccessibility::global_obj_count_ = 0; | 123 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 124 BrowserAccessibilityManager* manager = | 124 BrowserAccessibilityManager* manager = |
| 125 BrowserAccessibilityManager::Create( | 125 BrowserAccessibilityManager::Create( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // Make sure that changes to a subtree reuse as many objects as possible. | 167 // Make sure that changes to a subtree reuse as many objects as possible. |
| 168 | 168 |
| 169 // Tree 1: | 169 // Tree 1: |
| 170 // | 170 // |
| 171 // root | 171 // root |
| 172 // child1 | 172 // child1 |
| 173 // child2 | 173 // child2 |
| 174 // child3 | 174 // child3 |
| 175 | 175 |
| 176 ui::AXNodeData tree1_child1; | 176 ui::AXNodeData tree1_child1; |
| 177 tree1_child1.ClearBitfields(); |
| 177 tree1_child1.id = 2; | 178 tree1_child1.id = 2; |
| 178 tree1_child1.SetName("Child1"); | 179 tree1_child1.SetName("Child1"); |
| 179 tree1_child1.role = ui::AX_ROLE_BUTTON; | 180 tree1_child1.role = ui::AX_ROLE_BUTTON; |
| 180 tree1_child1.state = 0; | |
| 181 | 181 |
| 182 ui::AXNodeData tree1_child2; | 182 ui::AXNodeData tree1_child2; |
| 183 tree1_child2.ClearBitfields(); |
| 183 tree1_child2.id = 3; | 184 tree1_child2.id = 3; |
| 184 tree1_child2.SetName("Child2"); | 185 tree1_child2.SetName("Child2"); |
| 185 tree1_child2.role = ui::AX_ROLE_BUTTON; | 186 tree1_child2.role = ui::AX_ROLE_BUTTON; |
| 186 tree1_child2.state = 0; | |
| 187 | 187 |
| 188 ui::AXNodeData tree1_child3; | 188 ui::AXNodeData tree1_child3; |
| 189 tree1_child3.ClearBitfields(); |
| 189 tree1_child3.id = 4; | 190 tree1_child3.id = 4; |
| 190 tree1_child3.SetName("Child3"); | 191 tree1_child3.SetName("Child3"); |
| 191 tree1_child3.role = ui::AX_ROLE_BUTTON; | 192 tree1_child3.role = ui::AX_ROLE_BUTTON; |
| 192 tree1_child3.state = 0; | |
| 193 | 193 |
| 194 ui::AXNodeData tree1_root; | 194 ui::AXNodeData tree1_root; |
| 195 tree1_root.ClearBitfields(); |
| 195 tree1_root.id = 1; | 196 tree1_root.id = 1; |
| 196 tree1_root.SetName("Document"); | 197 tree1_root.SetName("Document"); |
| 197 tree1_root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 198 tree1_root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 198 tree1_root.state = 0; | |
| 199 tree1_root.child_ids.push_back(2); | 199 tree1_root.child_ids.push_back(2); |
| 200 tree1_root.child_ids.push_back(3); | 200 tree1_root.child_ids.push_back(3); |
| 201 tree1_root.child_ids.push_back(4); | 201 tree1_root.child_ids.push_back(4); |
| 202 | 202 |
| 203 // Tree 2: | 203 // Tree 2: |
| 204 // | 204 // |
| 205 // root | 205 // root |
| 206 // child0 <-- inserted | 206 // child0 <-- inserted |
| 207 // child1 | 207 // child1 |
| 208 // child2 | 208 // child2 |
| 209 // <-- child3 deleted | 209 // <-- child3 deleted |
| 210 | 210 |
| 211 ui::AXNodeData tree2_child0; | 211 ui::AXNodeData tree2_child0; |
| 212 tree2_child0.ClearBitfields(); |
| 212 tree2_child0.id = 5; | 213 tree2_child0.id = 5; |
| 213 tree2_child0.SetName("Child0"); | 214 tree2_child0.SetName("Child0"); |
| 214 tree2_child0.role = ui::AX_ROLE_BUTTON; | 215 tree2_child0.role = ui::AX_ROLE_BUTTON; |
| 215 tree2_child0.state = 0; | |
| 216 | 216 |
| 217 ui::AXNodeData tree2_root; | 217 ui::AXNodeData tree2_root; |
| 218 tree2_root.ClearBitfields(); |
| 218 tree2_root.id = 1; | 219 tree2_root.id = 1; |
| 219 tree2_root.SetName("DocumentChanged"); | 220 tree2_root.SetName("DocumentChanged"); |
| 220 tree2_root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 221 tree2_root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 221 tree2_root.state = 0; | |
| 222 tree2_root.child_ids.push_back(5); | 222 tree2_root.child_ids.push_back(5); |
| 223 tree2_root.child_ids.push_back(2); | 223 tree2_root.child_ids.push_back(2); |
| 224 tree2_root.child_ids.push_back(3); | 224 tree2_root.child_ids.push_back(3); |
| 225 | 225 |
| 226 // Construct a BrowserAccessibilityManager with tree1. | 226 // Construct a BrowserAccessibilityManager with tree1. |
| 227 CountedBrowserAccessibility::global_obj_count_ = 0; | 227 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 228 BrowserAccessibilityManager* manager = | 228 BrowserAccessibilityManager* manager = |
| 229 BrowserAccessibilityManager::Create( | 229 BrowserAccessibilityManager::Create( |
| 230 MakeAXTreeUpdate(tree1_root, | 230 MakeAXTreeUpdate(tree1_root, |
| 231 tree1_child1, tree1_child2, tree1_child3), | 231 tree1_child1, tree1_child2, tree1_child3), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 // root | 302 // root |
| 303 // container | 303 // container |
| 304 // child1 | 304 // child1 |
| 305 // grandchild1 | 305 // grandchild1 |
| 306 // child2 | 306 // child2 |
| 307 // grandchild2 | 307 // grandchild2 |
| 308 // child3 | 308 // child3 |
| 309 // grandchild3 | 309 // grandchild3 |
| 310 | 310 |
| 311 ui::AXNodeData tree1_grandchild1; | 311 ui::AXNodeData tree1_grandchild1; |
| 312 tree1_grandchild1.ClearBitfields(); |
| 312 tree1_grandchild1.id = 4; | 313 tree1_grandchild1.id = 4; |
| 313 tree1_grandchild1.SetName("GrandChild1"); | 314 tree1_grandchild1.SetName("GrandChild1"); |
| 314 tree1_grandchild1.role = ui::AX_ROLE_BUTTON; | 315 tree1_grandchild1.role = ui::AX_ROLE_BUTTON; |
| 315 tree1_grandchild1.state = 0; | |
| 316 | 316 |
| 317 ui::AXNodeData tree1_child1; | 317 ui::AXNodeData tree1_child1; |
| 318 tree1_child1.ClearBitfields(); |
| 318 tree1_child1.id = 3; | 319 tree1_child1.id = 3; |
| 319 tree1_child1.SetName("Child1"); | 320 tree1_child1.SetName("Child1"); |
| 320 tree1_child1.role = ui::AX_ROLE_BUTTON; | 321 tree1_child1.role = ui::AX_ROLE_BUTTON; |
| 321 tree1_child1.state = 0; | |
| 322 tree1_child1.child_ids.push_back(4); | 322 tree1_child1.child_ids.push_back(4); |
| 323 | 323 |
| 324 ui::AXNodeData tree1_grandchild2; | 324 ui::AXNodeData tree1_grandchild2; |
| 325 tree1_grandchild2.ClearBitfields(); |
| 325 tree1_grandchild2.id = 6; | 326 tree1_grandchild2.id = 6; |
| 326 tree1_grandchild2.SetName("GrandChild1"); | 327 tree1_grandchild2.SetName("GrandChild1"); |
| 327 tree1_grandchild2.role = ui::AX_ROLE_BUTTON; | 328 tree1_grandchild2.role = ui::AX_ROLE_BUTTON; |
| 328 tree1_grandchild2.state = 0; | |
| 329 | 329 |
| 330 ui::AXNodeData tree1_child2; | 330 ui::AXNodeData tree1_child2; |
| 331 tree1_child2.ClearBitfields(); |
| 331 tree1_child2.id = 5; | 332 tree1_child2.id = 5; |
| 332 tree1_child2.SetName("Child2"); | 333 tree1_child2.SetName("Child2"); |
| 333 tree1_child2.role = ui::AX_ROLE_BUTTON; | 334 tree1_child2.role = ui::AX_ROLE_BUTTON; |
| 334 tree1_child2.state = 0; | |
| 335 tree1_child2.child_ids.push_back(6); | 335 tree1_child2.child_ids.push_back(6); |
| 336 | 336 |
| 337 ui::AXNodeData tree1_grandchild3; | 337 ui::AXNodeData tree1_grandchild3; |
| 338 tree1_grandchild3.ClearBitfields(); |
| 338 tree1_grandchild3.id = 8; | 339 tree1_grandchild3.id = 8; |
| 339 tree1_grandchild3.SetName("GrandChild3"); | 340 tree1_grandchild3.SetName("GrandChild3"); |
| 340 tree1_grandchild3.role = ui::AX_ROLE_BUTTON; | 341 tree1_grandchild3.role = ui::AX_ROLE_BUTTON; |
| 341 tree1_grandchild3.state = 0; | |
| 342 | 342 |
| 343 ui::AXNodeData tree1_child3; | 343 ui::AXNodeData tree1_child3; |
| 344 tree1_child3.ClearBitfields(); |
| 344 tree1_child3.id = 7; | 345 tree1_child3.id = 7; |
| 345 tree1_child3.SetName("Child3"); | 346 tree1_child3.SetName("Child3"); |
| 346 tree1_child3.role = ui::AX_ROLE_BUTTON; | 347 tree1_child3.role = ui::AX_ROLE_BUTTON; |
| 347 tree1_child3.state = 0; | |
| 348 tree1_child3.child_ids.push_back(8); | 348 tree1_child3.child_ids.push_back(8); |
| 349 | 349 |
| 350 ui::AXNodeData tree1_container; | 350 ui::AXNodeData tree1_container; |
| 351 tree1_container.ClearBitfields(); |
| 351 tree1_container.id = 2; | 352 tree1_container.id = 2; |
| 352 tree1_container.SetName("Container"); | 353 tree1_container.SetName("Container"); |
| 353 tree1_container.role = ui::AX_ROLE_GROUP; | 354 tree1_container.role = ui::AX_ROLE_GROUP; |
| 354 tree1_container.state = 0; | |
| 355 tree1_container.child_ids.push_back(3); | 355 tree1_container.child_ids.push_back(3); |
| 356 tree1_container.child_ids.push_back(5); | 356 tree1_container.child_ids.push_back(5); |
| 357 tree1_container.child_ids.push_back(7); | 357 tree1_container.child_ids.push_back(7); |
| 358 | 358 |
| 359 ui::AXNodeData tree1_root; | 359 ui::AXNodeData tree1_root; |
| 360 tree1_root.ClearBitfields(); |
| 360 tree1_root.id = 1; | 361 tree1_root.id = 1; |
| 361 tree1_root.SetName("Document"); | 362 tree1_root.SetName("Document"); |
| 362 tree1_root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 363 tree1_root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 363 tree1_root.state = 0; | |
| 364 tree1_root.child_ids.push_back(2); | 364 tree1_root.child_ids.push_back(2); |
| 365 | 365 |
| 366 // Tree 2: | 366 // Tree 2: |
| 367 // | 367 // |
| 368 // root | 368 // root |
| 369 // container | 369 // container |
| 370 // child0 <-- inserted | 370 // child0 <-- inserted |
| 371 // grandchild0 <-- | 371 // grandchild0 <-- |
| 372 // child1 | 372 // child1 |
| 373 // grandchild1 | 373 // grandchild1 |
| 374 // child2 | 374 // child2 |
| 375 // grandchild2 | 375 // grandchild2 |
| 376 // <-- child3 (and grandchild3) deleted | 376 // <-- child3 (and grandchild3) deleted |
| 377 | 377 |
| 378 ui::AXNodeData tree2_grandchild0; | 378 ui::AXNodeData tree2_grandchild0; |
| 379 tree2_grandchild0.ClearBitfields(); |
| 379 tree2_grandchild0.id = 9; | 380 tree2_grandchild0.id = 9; |
| 380 tree2_grandchild0.SetName("GrandChild0"); | 381 tree2_grandchild0.SetName("GrandChild0"); |
| 381 tree2_grandchild0.role = ui::AX_ROLE_BUTTON; | 382 tree2_grandchild0.role = ui::AX_ROLE_BUTTON; |
| 382 tree2_grandchild0.state = 0; | |
| 383 | 383 |
| 384 ui::AXNodeData tree2_child0; | 384 ui::AXNodeData tree2_child0; |
| 385 tree2_child0.ClearBitfields(); |
| 385 tree2_child0.id = 10; | 386 tree2_child0.id = 10; |
| 386 tree2_child0.SetName("Child0"); | 387 tree2_child0.SetName("Child0"); |
| 387 tree2_child0.role = ui::AX_ROLE_BUTTON; | 388 tree2_child0.role = ui::AX_ROLE_BUTTON; |
| 388 tree2_child0.state = 0; | |
| 389 tree2_child0.child_ids.push_back(9); | 389 tree2_child0.child_ids.push_back(9); |
| 390 | 390 |
| 391 ui::AXNodeData tree2_container; | 391 ui::AXNodeData tree2_container; |
| 392 tree2_container.ClearBitfields(); |
| 392 tree2_container.id = 2; | 393 tree2_container.id = 2; |
| 393 tree2_container.SetName("Container"); | 394 tree2_container.SetName("Container"); |
| 394 tree2_container.role = ui::AX_ROLE_GROUP; | 395 tree2_container.role = ui::AX_ROLE_GROUP; |
| 395 tree2_container.state = 0; | |
| 396 tree2_container.child_ids.push_back(10); | 396 tree2_container.child_ids.push_back(10); |
| 397 tree2_container.child_ids.push_back(3); | 397 tree2_container.child_ids.push_back(3); |
| 398 tree2_container.child_ids.push_back(5); | 398 tree2_container.child_ids.push_back(5); |
| 399 | 399 |
| 400 // Construct a BrowserAccessibilityManager with tree1. | 400 // Construct a BrowserAccessibilityManager with tree1. |
| 401 CountedBrowserAccessibility::global_obj_count_ = 0; | 401 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 402 BrowserAccessibilityManager* manager = | 402 BrowserAccessibilityManager* manager = |
| 403 BrowserAccessibilityManager::Create( | 403 BrowserAccessibilityManager::Create( |
| 404 MakeAXTreeUpdate(tree1_root, tree1_container, | 404 MakeAXTreeUpdate(tree1_root, tree1_container, |
| 405 tree1_child1, tree1_grandchild1, | 405 tree1_child1, tree1_grandchild1, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 476 |
| 477 TEST(BrowserAccessibilityManagerTest, TestMoveChildUp) { | 477 TEST(BrowserAccessibilityManagerTest, TestMoveChildUp) { |
| 478 // Tree 1: | 478 // Tree 1: |
| 479 // | 479 // |
| 480 // 1 | 480 // 1 |
| 481 // 2 | 481 // 2 |
| 482 // 3 | 482 // 3 |
| 483 // 4 | 483 // 4 |
| 484 | 484 |
| 485 ui::AXNodeData tree1_4; | 485 ui::AXNodeData tree1_4; |
| 486 tree1_4.ClearBitfields(); |
| 486 tree1_4.id = 4; | 487 tree1_4.id = 4; |
| 487 tree1_4.state = 0; | |
| 488 | 488 |
| 489 ui::AXNodeData tree1_3; | 489 ui::AXNodeData tree1_3; |
| 490 tree1_3.ClearBitfields(); |
| 490 tree1_3.id = 3; | 491 tree1_3.id = 3; |
| 491 tree1_3.state = 0; | |
| 492 tree1_3.child_ids.push_back(4); | 492 tree1_3.child_ids.push_back(4); |
| 493 | 493 |
| 494 ui::AXNodeData tree1_2; | 494 ui::AXNodeData tree1_2; |
| 495 tree1_2.ClearBitfields(); |
| 495 tree1_2.id = 2; | 496 tree1_2.id = 2; |
| 496 tree1_2.state = 0; | |
| 497 | 497 |
| 498 ui::AXNodeData tree1_1; | 498 ui::AXNodeData tree1_1; |
| 499 tree1_1.ClearBitfields(); |
| 499 tree1_1.id = 1; | 500 tree1_1.id = 1; |
| 500 tree1_1.role = ui::AX_ROLE_ROOT_WEB_AREA; | 501 tree1_1.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 501 tree1_1.state = 0; | |
| 502 tree1_1.child_ids.push_back(2); | 502 tree1_1.child_ids.push_back(2); |
| 503 tree1_1.child_ids.push_back(3); | 503 tree1_1.child_ids.push_back(3); |
| 504 | 504 |
| 505 // Tree 2: | 505 // Tree 2: |
| 506 // | 506 // |
| 507 // 1 | 507 // 1 |
| 508 // 4 <-- moves up a level and gains child | 508 // 4 <-- moves up a level and gains child |
| 509 // 6 <-- new | 509 // 6 <-- new |
| 510 // 5 <-- new | 510 // 5 <-- new |
| 511 | 511 |
| 512 ui::AXNodeData tree2_6; | 512 ui::AXNodeData tree2_6; |
| 513 tree2_6.ClearBitfields(); |
| 513 tree2_6.id = 6; | 514 tree2_6.id = 6; |
| 514 tree2_6.state = 0; | |
| 515 | 515 |
| 516 ui::AXNodeData tree2_5; | 516 ui::AXNodeData tree2_5; |
| 517 tree2_5.ClearBitfields(); |
| 517 tree2_5.id = 5; | 518 tree2_5.id = 5; |
| 518 tree2_5.state = 0; | |
| 519 | 519 |
| 520 ui::AXNodeData tree2_4; | 520 ui::AXNodeData tree2_4; |
| 521 tree2_4.ClearBitfields(); |
| 521 tree2_4.id = 4; | 522 tree2_4.id = 4; |
| 522 tree2_4.state = 0; | |
| 523 tree2_4.child_ids.push_back(6); | 523 tree2_4.child_ids.push_back(6); |
| 524 | 524 |
| 525 ui::AXNodeData tree2_1; | 525 ui::AXNodeData tree2_1; |
| 526 tree2_1.ClearBitfields(); |
| 526 tree2_1.id = 1; | 527 tree2_1.id = 1; |
| 527 tree2_1.state = 0; | |
| 528 tree2_1.child_ids.push_back(4); | 528 tree2_1.child_ids.push_back(4); |
| 529 tree2_1.child_ids.push_back(5); | 529 tree2_1.child_ids.push_back(5); |
| 530 | 530 |
| 531 // Construct a BrowserAccessibilityManager with tree1. | 531 // Construct a BrowserAccessibilityManager with tree1. |
| 532 CountedBrowserAccessibility::global_obj_count_ = 0; | 532 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 533 BrowserAccessibilityManager* manager = | 533 BrowserAccessibilityManager* manager = |
| 534 BrowserAccessibilityManager::Create( | 534 BrowserAccessibilityManager::Create( |
| 535 MakeAXTreeUpdate(tree1_1, tree1_2, tree1_3, tree1_4), | 535 MakeAXTreeUpdate(tree1_1, tree1_2, tree1_3, tree1_4), |
| 536 nullptr, | 536 nullptr, |
| 537 new CountedBrowserAccessibilityFactory()); | 537 new CountedBrowserAccessibilityFactory()); |
| (...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1512 // Start and end positions could be reversed. | 1512 // Start and end positions could be reversed. |
| 1513 EXPECT_EQ( | 1513 EXPECT_EQ( |
| 1514 base::ASCIIToUTF16("Hello world."), | 1514 base::ASCIIToUTF16("Hello world."), |
| 1515 BrowserAccessibilityManager::GetTextForRange( | 1515 BrowserAccessibilityManager::GetTextForRange( |
| 1516 *paragraph_line2_accessible, 6, *paragraph_line1_accessible, 0)); | 1516 *paragraph_line2_accessible, 6, *paragraph_line1_accessible, 0)); |
| 1517 } | 1517 } |
| 1518 | 1518 |
| 1519 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash) { | 1519 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash) { |
| 1520 // Create a really simple tree with one root node and one focused child. | 1520 // Create a really simple tree with one root node and one focused child. |
| 1521 ui::AXNodeData root; | 1521 ui::AXNodeData root; |
| 1522 root.ClearBitfields(); |
| 1522 root.id = 1; | 1523 root.id = 1; |
| 1523 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1524 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1524 root.state = 0; | |
| 1525 root.child_ids.push_back(2); | 1525 root.child_ids.push_back(2); |
| 1526 | 1526 |
| 1527 ui::AXNodeData node2; | 1527 ui::AXNodeData node2; |
| 1528 node2.id = 2; | 1528 node2.id = 2; |
| 1529 | 1529 |
| 1530 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2); | 1530 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2); |
| 1531 initial_state.has_tree_data = true; | 1531 initial_state.has_tree_data = true; |
| 1532 initial_state.tree_data.focus_id = 2; | 1532 initial_state.tree_data.focus_id = 2; |
| 1533 std::unique_ptr<BrowserAccessibilityManager> manager( | 1533 std::unique_ptr<BrowserAccessibilityManager> manager( |
| 1534 BrowserAccessibilityManager::Create( | 1534 BrowserAccessibilityManager::Create( |
| 1535 initial_state, nullptr, new CountedBrowserAccessibilityFactory())); | 1535 initial_state, nullptr, new CountedBrowserAccessibilityFactory())); |
| 1536 | 1536 |
| 1537 ASSERT_EQ(1, manager->GetRoot()->GetId()); | 1537 ASSERT_EQ(1, manager->GetRoot()->GetId()); |
| 1538 ASSERT_EQ(2, manager->GetFocus()->GetId()); | 1538 ASSERT_EQ(2, manager->GetFocus()->GetId()); |
| 1539 | 1539 |
| 1540 // Now replace the tree with a new tree consisting of a single root. | 1540 // Now replace the tree with a new tree consisting of a single root. |
| 1541 ui::AXNodeData root2; | 1541 ui::AXNodeData root2; |
| 1542 root2.ClearBitfields(); |
| 1542 root2.id = 3; | 1543 root2.id = 3; |
| 1543 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1544 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1544 root2.state = 0; | |
| 1545 | 1545 |
| 1546 std::vector<AXEventNotificationDetails> events2; | 1546 std::vector<AXEventNotificationDetails> events2; |
| 1547 events2.push_back(AXEventNotificationDetails()); | 1547 events2.push_back(AXEventNotificationDetails()); |
| 1548 events2[0].update = MakeAXTreeUpdate(root2); | 1548 events2[0].update = MakeAXTreeUpdate(root2); |
| 1549 events2[0].id = -1; | 1549 events2[0].id = -1; |
| 1550 events2[0].event_type = ui::AX_EVENT_NONE; | 1550 events2[0].event_type = ui::AX_EVENT_NONE; |
| 1551 manager->OnAccessibilityEvents(events2); | 1551 manager->OnAccessibilityEvents(events2); |
| 1552 | 1552 |
| 1553 // Make sure that the focused node was updated to the new root and | 1553 // Make sure that the focused node was updated to the new root and |
| 1554 // that this doesn't crash. | 1554 // that this doesn't crash. |
| 1555 ASSERT_EQ(3, manager->GetRoot()->GetId()); | 1555 ASSERT_EQ(3, manager->GetRoot()->GetId()); |
| 1556 ASSERT_EQ(3, manager->GetFocus()->GetId()); | 1556 ASSERT_EQ(3, manager->GetFocus()->GetId()); |
| 1557 } | 1557 } |
| 1558 | 1558 |
| 1559 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash2) { | 1559 TEST(BrowserAccessibilityManagerTest, DeletingFocusedNodeDoesNotCrash2) { |
| 1560 // Create a really simple tree with one root node and one focused child. | 1560 // Create a really simple tree with one root node and one focused child. |
| 1561 ui::AXNodeData root; | 1561 ui::AXNodeData root; |
| 1562 root.ClearBitfields(); |
| 1562 root.id = 1; | 1563 root.id = 1; |
| 1563 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1564 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1564 root.state = 0; | |
| 1565 root.child_ids.push_back(2); | 1565 root.child_ids.push_back(2); |
| 1566 root.child_ids.push_back(3); | 1566 root.child_ids.push_back(3); |
| 1567 root.child_ids.push_back(4); | 1567 root.child_ids.push_back(4); |
| 1568 | 1568 |
| 1569 ui::AXNodeData node2; | 1569 ui::AXNodeData node2; |
| 1570 node2.ClearBitfields(); |
| 1570 node2.id = 2; | 1571 node2.id = 2; |
| 1571 | 1572 |
| 1572 ui::AXNodeData node3; | 1573 ui::AXNodeData node3; |
| 1574 node3.ClearBitfields(); |
| 1573 node3.id = 3; | 1575 node3.id = 3; |
| 1574 node3.state = 0; | |
| 1575 | 1576 |
| 1576 ui::AXNodeData node4; | 1577 ui::AXNodeData node4; |
| 1578 node4.ClearBitfields(); |
| 1577 node4.id = 4; | 1579 node4.id = 4; |
| 1578 node4.state = 0; | |
| 1579 | 1580 |
| 1580 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2, node3, node4); | 1581 ui::AXTreeUpdate initial_state = MakeAXTreeUpdate(root, node2, node3, node4); |
| 1581 initial_state.has_tree_data = true; | 1582 initial_state.has_tree_data = true; |
| 1582 initial_state.tree_data.focus_id = 2; | 1583 initial_state.tree_data.focus_id = 2; |
| 1583 std::unique_ptr<BrowserAccessibilityManager> manager( | 1584 std::unique_ptr<BrowserAccessibilityManager> manager( |
| 1584 BrowserAccessibilityManager::Create( | 1585 BrowserAccessibilityManager::Create( |
| 1585 initial_state, nullptr, new CountedBrowserAccessibilityFactory())); | 1586 initial_state, nullptr, new CountedBrowserAccessibilityFactory())); |
| 1586 | 1587 |
| 1587 ASSERT_EQ(1, manager->GetRoot()->GetId()); | 1588 ASSERT_EQ(1, manager->GetRoot()->GetId()); |
| 1588 ASSERT_EQ(2, manager->GetFocus()->GetId()); | 1589 ASSERT_EQ(2, manager->GetFocus()->GetId()); |
| 1589 | 1590 |
| 1590 // Now replace the tree with a new tree consisting of a single root. | 1591 // Now replace the tree with a new tree consisting of a single root. |
| 1591 ui::AXNodeData root2; | 1592 ui::AXNodeData root2; |
| 1593 root2.ClearBitfields(); |
| 1592 root2.id = 3; | 1594 root2.id = 3; |
| 1593 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1595 root2.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1594 root2.state = 0; | |
| 1595 | 1596 |
| 1596 // Make an update the explicitly clears the previous root. | 1597 // Make an update the explicitly clears the previous root. |
| 1597 std::vector<AXEventNotificationDetails> events2; | 1598 std::vector<AXEventNotificationDetails> events2; |
| 1598 events2.push_back(AXEventNotificationDetails()); | 1599 events2.push_back(AXEventNotificationDetails()); |
| 1599 events2[0].update = MakeAXTreeUpdate(root2); | 1600 events2[0].update = MakeAXTreeUpdate(root2); |
| 1600 events2[0].update.node_id_to_clear = 1; | 1601 events2[0].update.node_id_to_clear = 1; |
| 1601 events2[0].id = -1; | 1602 events2[0].id = -1; |
| 1602 events2[0].event_type = ui::AX_EVENT_NONE; | 1603 events2[0].event_type = ui::AX_EVENT_NONE; |
| 1603 manager->OnAccessibilityEvents(events2); | 1604 manager->OnAccessibilityEvents(events2); |
| 1604 | 1605 |
| 1605 // Make sure that the focused node was updated to the new root and | 1606 // Make sure that the focused node was updated to the new root and |
| 1606 // that this doesn't crash. | 1607 // that this doesn't crash. |
| 1607 ASSERT_EQ(3, manager->GetRoot()->GetId()); | 1608 ASSERT_EQ(3, manager->GetRoot()->GetId()); |
| 1608 ASSERT_EQ(3, manager->GetFocus()->GetId()); | 1609 ASSERT_EQ(3, manager->GetFocus()->GetId()); |
| 1609 } | 1610 } |
| 1610 | 1611 |
| 1611 } // namespace content | 1612 } // namespace content |
| OLD | NEW |