| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 }; | 85 }; |
| 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.name = UTF8ToUTF16("Button"); | 95 button.SetName("Button"); |
| 96 button.role = AccessibilityNodeData::ROLE_BUTTON; | 96 button.role = AccessibilityNodeData::ROLE_BUTTON; |
| 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.name = UTF8ToUTF16("Checkbox"); | 101 checkbox.SetName("Checkbox"); |
| 102 checkbox.role = AccessibilityNodeData::ROLE_CHECKBOX; | 102 checkbox.role = AccessibilityNodeData::ROLE_CHECKBOX; |
| 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.name = UTF8ToUTF16("Document"); | 107 root.SetName("Document"); |
| 108 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 108 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 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; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 163 |
| 164 // Tree 1: | 164 // Tree 1: |
| 165 // | 165 // |
| 166 // root | 166 // root |
| 167 // child1 | 167 // child1 |
| 168 // child2 | 168 // child2 |
| 169 // child3 | 169 // child3 |
| 170 | 170 |
| 171 AccessibilityNodeData tree1_child1; | 171 AccessibilityNodeData tree1_child1; |
| 172 tree1_child1.id = 2; | 172 tree1_child1.id = 2; |
| 173 tree1_child1.name = UTF8ToUTF16("Child1"); | 173 tree1_child1.SetName("Child1"); |
| 174 tree1_child1.role = AccessibilityNodeData::ROLE_BUTTON; | 174 tree1_child1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 175 tree1_child1.state = 0; | 175 tree1_child1.state = 0; |
| 176 | 176 |
| 177 AccessibilityNodeData tree1_child2; | 177 AccessibilityNodeData tree1_child2; |
| 178 tree1_child2.id = 3; | 178 tree1_child2.id = 3; |
| 179 tree1_child2.name = UTF8ToUTF16("Child2"); | 179 tree1_child2.SetName("Child2"); |
| 180 tree1_child2.role = AccessibilityNodeData::ROLE_BUTTON; | 180 tree1_child2.role = AccessibilityNodeData::ROLE_BUTTON; |
| 181 tree1_child2.state = 0; | 181 tree1_child2.state = 0; |
| 182 | 182 |
| 183 AccessibilityNodeData tree1_child3; | 183 AccessibilityNodeData tree1_child3; |
| 184 tree1_child3.id = 4; | 184 tree1_child3.id = 4; |
| 185 tree1_child3.name = UTF8ToUTF16("Child3"); | 185 tree1_child3.SetName("Child3"); |
| 186 tree1_child3.role = AccessibilityNodeData::ROLE_BUTTON; | 186 tree1_child3.role = AccessibilityNodeData::ROLE_BUTTON; |
| 187 tree1_child3.state = 0; | 187 tree1_child3.state = 0; |
| 188 | 188 |
| 189 AccessibilityNodeData tree1_root; | 189 AccessibilityNodeData tree1_root; |
| 190 tree1_root.id = 1; | 190 tree1_root.id = 1; |
| 191 tree1_root.name = UTF8ToUTF16("Document"); | 191 tree1_root.SetName("Document"); |
| 192 tree1_root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 192 tree1_root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 193 tree1_root.state = 0; | 193 tree1_root.state = 0; |
| 194 tree1_root.child_ids.push_back(2); | 194 tree1_root.child_ids.push_back(2); |
| 195 tree1_root.child_ids.push_back(3); | 195 tree1_root.child_ids.push_back(3); |
| 196 tree1_root.child_ids.push_back(4); | 196 tree1_root.child_ids.push_back(4); |
| 197 | 197 |
| 198 // Tree 2: | 198 // Tree 2: |
| 199 // | 199 // |
| 200 // root | 200 // root |
| 201 // child0 <-- inserted | 201 // child0 <-- inserted |
| 202 // child1 | 202 // child1 |
| 203 // child2 | 203 // child2 |
| 204 // <-- child3 deleted | 204 // <-- child3 deleted |
| 205 | 205 |
| 206 AccessibilityNodeData tree2_child0; | 206 AccessibilityNodeData tree2_child0; |
| 207 tree2_child0.id = 5; | 207 tree2_child0.id = 5; |
| 208 tree2_child0.name = UTF8ToUTF16("Child0"); | 208 tree2_child0.SetName("Child0"); |
| 209 tree2_child0.role = AccessibilityNodeData::ROLE_BUTTON; | 209 tree2_child0.role = AccessibilityNodeData::ROLE_BUTTON; |
| 210 tree2_child0.state = 0; | 210 tree2_child0.state = 0; |
| 211 | 211 |
| 212 AccessibilityNodeData tree2_root; | 212 AccessibilityNodeData tree2_root; |
| 213 tree2_root.id = 1; | 213 tree2_root.id = 1; |
| 214 tree2_root.name = UTF8ToUTF16("DocumentChanged"); | 214 tree2_root.SetName("DocumentChanged"); |
| 215 tree2_root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 215 tree2_root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 216 tree2_root.state = 0; | 216 tree2_root.state = 0; |
| 217 tree2_root.child_ids.push_back(5); | 217 tree2_root.child_ids.push_back(5); |
| 218 tree2_root.child_ids.push_back(2); | 218 tree2_root.child_ids.push_back(2); |
| 219 tree2_root.child_ids.push_back(3); | 219 tree2_root.child_ids.push_back(3); |
| 220 | 220 |
| 221 // Construct a BrowserAccessibilityManager with tree1. | 221 // Construct a BrowserAccessibilityManager with tree1. |
| 222 CountedBrowserAccessibility::global_obj_count_ = 0; | 222 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 223 BrowserAccessibilityManager* manager = | 223 BrowserAccessibilityManager* manager = |
| 224 BrowserAccessibilityManager::Create( | 224 BrowserAccessibilityManager::Create( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 // container | 295 // container |
| 296 // child1 | 296 // child1 |
| 297 // grandchild1 | 297 // grandchild1 |
| 298 // child2 | 298 // child2 |
| 299 // grandchild2 | 299 // grandchild2 |
| 300 // child3 | 300 // child3 |
| 301 // grandchild3 | 301 // grandchild3 |
| 302 | 302 |
| 303 AccessibilityNodeData tree1_grandchild1; | 303 AccessibilityNodeData tree1_grandchild1; |
| 304 tree1_grandchild1.id = 4; | 304 tree1_grandchild1.id = 4; |
| 305 tree1_grandchild1.name = UTF8ToUTF16("GrandChild1"); | 305 tree1_grandchild1.SetName("GrandChild1"); |
| 306 tree1_grandchild1.role = AccessibilityNodeData::ROLE_BUTTON; | 306 tree1_grandchild1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 307 tree1_grandchild1.state = 0; | 307 tree1_grandchild1.state = 0; |
| 308 | 308 |
| 309 AccessibilityNodeData tree1_child1; | 309 AccessibilityNodeData tree1_child1; |
| 310 tree1_child1.id = 3; | 310 tree1_child1.id = 3; |
| 311 tree1_child1.name = UTF8ToUTF16("Child1"); | 311 tree1_child1.SetName("Child1"); |
| 312 tree1_child1.role = AccessibilityNodeData::ROLE_BUTTON; | 312 tree1_child1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 313 tree1_child1.state = 0; | 313 tree1_child1.state = 0; |
| 314 tree1_child1.child_ids.push_back(4); | 314 tree1_child1.child_ids.push_back(4); |
| 315 | 315 |
| 316 AccessibilityNodeData tree1_grandchild2; | 316 AccessibilityNodeData tree1_grandchild2; |
| 317 tree1_grandchild2.id = 6; | 317 tree1_grandchild2.id = 6; |
| 318 tree1_grandchild2.name = UTF8ToUTF16("GrandChild1"); | 318 tree1_grandchild2.SetName("GrandChild1"); |
| 319 tree1_grandchild2.role = AccessibilityNodeData::ROLE_BUTTON; | 319 tree1_grandchild2.role = AccessibilityNodeData::ROLE_BUTTON; |
| 320 tree1_grandchild2.state = 0; | 320 tree1_grandchild2.state = 0; |
| 321 | 321 |
| 322 AccessibilityNodeData tree1_child2; | 322 AccessibilityNodeData tree1_child2; |
| 323 tree1_child2.id = 5; | 323 tree1_child2.id = 5; |
| 324 tree1_child2.name = UTF8ToUTF16("Child2"); | 324 tree1_child2.SetName("Child2"); |
| 325 tree1_child2.role = AccessibilityNodeData::ROLE_BUTTON; | 325 tree1_child2.role = AccessibilityNodeData::ROLE_BUTTON; |
| 326 tree1_child2.state = 0; | 326 tree1_child2.state = 0; |
| 327 tree1_child2.child_ids.push_back(6); | 327 tree1_child2.child_ids.push_back(6); |
| 328 | 328 |
| 329 AccessibilityNodeData tree1_grandchild3; | 329 AccessibilityNodeData tree1_grandchild3; |
| 330 tree1_grandchild3.id = 8; | 330 tree1_grandchild3.id = 8; |
| 331 tree1_grandchild3.name = UTF8ToUTF16("GrandChild3"); | 331 tree1_grandchild3.SetName("GrandChild3"); |
| 332 tree1_grandchild3.role = AccessibilityNodeData::ROLE_BUTTON; | 332 tree1_grandchild3.role = AccessibilityNodeData::ROLE_BUTTON; |
| 333 tree1_grandchild3.state = 0; | 333 tree1_grandchild3.state = 0; |
| 334 | 334 |
| 335 AccessibilityNodeData tree1_child3; | 335 AccessibilityNodeData tree1_child3; |
| 336 tree1_child3.id = 7; | 336 tree1_child3.id = 7; |
| 337 tree1_child3.name = UTF8ToUTF16("Child3"); | 337 tree1_child3.SetName("Child3"); |
| 338 tree1_child3.role = AccessibilityNodeData::ROLE_BUTTON; | 338 tree1_child3.role = AccessibilityNodeData::ROLE_BUTTON; |
| 339 tree1_child3.state = 0; | 339 tree1_child3.state = 0; |
| 340 tree1_child3.child_ids.push_back(8); | 340 tree1_child3.child_ids.push_back(8); |
| 341 | 341 |
| 342 AccessibilityNodeData tree1_container; | 342 AccessibilityNodeData tree1_container; |
| 343 tree1_container.id = 2; | 343 tree1_container.id = 2; |
| 344 tree1_container.name = UTF8ToUTF16("Container"); | 344 tree1_container.SetName("Container"); |
| 345 tree1_container.role = AccessibilityNodeData::ROLE_GROUP; | 345 tree1_container.role = AccessibilityNodeData::ROLE_GROUP; |
| 346 tree1_container.state = 0; | 346 tree1_container.state = 0; |
| 347 tree1_container.child_ids.push_back(3); | 347 tree1_container.child_ids.push_back(3); |
| 348 tree1_container.child_ids.push_back(5); | 348 tree1_container.child_ids.push_back(5); |
| 349 tree1_container.child_ids.push_back(7); | 349 tree1_container.child_ids.push_back(7); |
| 350 | 350 |
| 351 AccessibilityNodeData tree1_root; | 351 AccessibilityNodeData tree1_root; |
| 352 tree1_root.id = 1; | 352 tree1_root.id = 1; |
| 353 tree1_root.name = UTF8ToUTF16("Document"); | 353 tree1_root.SetName("Document"); |
| 354 tree1_root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 354 tree1_root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 355 tree1_root.state = 0; | 355 tree1_root.state = 0; |
| 356 tree1_root.child_ids.push_back(2); | 356 tree1_root.child_ids.push_back(2); |
| 357 | 357 |
| 358 // Tree 2: | 358 // Tree 2: |
| 359 // | 359 // |
| 360 // root | 360 // root |
| 361 // container | 361 // container |
| 362 // child0 <-- inserted | 362 // child0 <-- inserted |
| 363 // grandchild0 <-- | 363 // grandchild0 <-- |
| 364 // child1 | 364 // child1 |
| 365 // grandchild1 | 365 // grandchild1 |
| 366 // child2 | 366 // child2 |
| 367 // grandchild2 | 367 // grandchild2 |
| 368 // <-- child3 (and grandchild3) deleted | 368 // <-- child3 (and grandchild3) deleted |
| 369 | 369 |
| 370 AccessibilityNodeData tree2_grandchild0; | 370 AccessibilityNodeData tree2_grandchild0; |
| 371 tree2_grandchild0.id = 9; | 371 tree2_grandchild0.id = 9; |
| 372 tree2_grandchild0.name = UTF8ToUTF16("GrandChild0"); | 372 tree2_grandchild0.SetName("GrandChild0"); |
| 373 tree2_grandchild0.role = AccessibilityNodeData::ROLE_BUTTON; | 373 tree2_grandchild0.role = AccessibilityNodeData::ROLE_BUTTON; |
| 374 tree2_grandchild0.state = 0; | 374 tree2_grandchild0.state = 0; |
| 375 | 375 |
| 376 AccessibilityNodeData tree2_child0; | 376 AccessibilityNodeData tree2_child0; |
| 377 tree2_child0.id = 10; | 377 tree2_child0.id = 10; |
| 378 tree2_child0.name = UTF8ToUTF16("Child0"); | 378 tree2_child0.SetName("Child0"); |
| 379 tree2_child0.role = AccessibilityNodeData::ROLE_BUTTON; | 379 tree2_child0.role = AccessibilityNodeData::ROLE_BUTTON; |
| 380 tree2_child0.state = 0; | 380 tree2_child0.state = 0; |
| 381 tree2_child0.child_ids.push_back(9); | 381 tree2_child0.child_ids.push_back(9); |
| 382 | 382 |
| 383 AccessibilityNodeData tree2_container; | 383 AccessibilityNodeData tree2_container; |
| 384 tree2_container.id = 2; | 384 tree2_container.id = 2; |
| 385 tree2_container.name = UTF8ToUTF16("Container"); | 385 tree2_container.SetName("Container"); |
| 386 tree2_container.role = AccessibilityNodeData::ROLE_GROUP; | 386 tree2_container.role = AccessibilityNodeData::ROLE_GROUP; |
| 387 tree2_container.state = 0; | 387 tree2_container.state = 0; |
| 388 tree2_container.child_ids.push_back(10); | 388 tree2_container.child_ids.push_back(10); |
| 389 tree2_container.child_ids.push_back(3); | 389 tree2_container.child_ids.push_back(3); |
| 390 tree2_container.child_ids.push_back(5); | 390 tree2_container.child_ids.push_back(5); |
| 391 | 391 |
| 392 // Construct a BrowserAccessibilityManager with tree1. | 392 // Construct a BrowserAccessibilityManager with tree1. |
| 393 CountedBrowserAccessibility::global_obj_count_ = 0; | 393 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 394 BrowserAccessibilityManager* manager = | 394 BrowserAccessibilityManager* manager = |
| 395 BrowserAccessibilityManager::Create( | 395 BrowserAccessibilityManager::Create( |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 manager.reset(BrowserAccessibilityManager::Create( | 594 manager.reset(BrowserAccessibilityManager::Create( |
| 595 root2, | 595 root2, |
| 596 delegate.get(), | 596 delegate.get(), |
| 597 factory)); | 597 factory)); |
| 598 ASSERT_FALSE(delegate->got_fatal_error()); | 598 ASSERT_FALSE(delegate->got_fatal_error()); |
| 599 manager->UpdateNodesForTesting(child1, child2); | 599 manager->UpdateNodesForTesting(child1, child2); |
| 600 ASSERT_TRUE(delegate->got_fatal_error()); | 600 ASSERT_TRUE(delegate->got_fatal_error()); |
| 601 } | 601 } |
| 602 | 602 |
| 603 } // namespace content | 603 } // namespace content |
| OLD | NEW |