| 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/string16.h" | 5 #include "base/string16.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/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 "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "webkit/glue/webaccessibility.h" | |
| 12 | 12 |
| 13 using webkit_glue::WebAccessibility; | 13 using content::AccessibilityNodeData; |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Subclass of BrowserAccessibility that counts the number of instances. | 17 // Subclass of BrowserAccessibility that counts the number of instances. |
| 18 class CountedBrowserAccessibility : public BrowserAccessibility { | 18 class CountedBrowserAccessibility : public BrowserAccessibility { |
| 19 public: | 19 public: |
| 20 CountedBrowserAccessibility() { | 20 CountedBrowserAccessibility() { |
| 21 global_obj_count_++; | 21 global_obj_count_++; |
| 22 native_ref_count_ = 1; | 22 native_ref_count_ = 1; |
| 23 } | 23 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 47 public: | 47 public: |
| 48 virtual ~CountedBrowserAccessibilityFactory() {} | 48 virtual ~CountedBrowserAccessibilityFactory() {} |
| 49 virtual BrowserAccessibility* Create() { | 49 virtual BrowserAccessibility* Create() { |
| 50 return new CountedBrowserAccessibility(); | 50 return new CountedBrowserAccessibility(); |
| 51 } | 51 } |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 } // anonymous namespace | 54 } // anonymous namespace |
| 55 | 55 |
| 56 TEST(BrowserAccessibilityManagerTest, TestNoLeaks) { | 56 TEST(BrowserAccessibilityManagerTest, TestNoLeaks) { |
| 57 // Create WebAccessibility objects for a simple document tree, | 57 // Create AccessibilityNodeData objects for a simple document tree, |
| 58 // representing the accessibility information used to initialize | 58 // representing the accessibility information used to initialize |
| 59 // BrowserAccessibilityManager. | 59 // BrowserAccessibilityManager. |
| 60 WebAccessibility button; | 60 AccessibilityNodeData button; |
| 61 button.id = 2; | 61 button.id = 2; |
| 62 button.name = UTF8ToUTF16("Button"); | 62 button.name = UTF8ToUTF16("Button"); |
| 63 button.role = WebAccessibility::ROLE_BUTTON; | 63 button.role = AccessibilityNodeData::ROLE_BUTTON; |
| 64 button.state = 0; | 64 button.state = 0; |
| 65 | 65 |
| 66 WebAccessibility checkbox; | 66 AccessibilityNodeData checkbox; |
| 67 checkbox.id = 3; | 67 checkbox.id = 3; |
| 68 checkbox.name = UTF8ToUTF16("Checkbox"); | 68 checkbox.name = UTF8ToUTF16("Checkbox"); |
| 69 checkbox.role = WebAccessibility::ROLE_CHECKBOX; | 69 checkbox.role = AccessibilityNodeData::ROLE_CHECKBOX; |
| 70 checkbox.state = 0; | 70 checkbox.state = 0; |
| 71 | 71 |
| 72 WebAccessibility root; | 72 AccessibilityNodeData root; |
| 73 root.id = 1; | 73 root.id = 1; |
| 74 root.name = UTF8ToUTF16("Document"); | 74 root.name = UTF8ToUTF16("Document"); |
| 75 root.role = WebAccessibility::ROLE_DOCUMENT; | 75 root.role = AccessibilityNodeData::ROLE_DOCUMENT; |
| 76 root.state = 0; | 76 root.state = 0; |
| 77 root.children.push_back(button); | 77 root.children.push_back(button); |
| 78 root.children.push_back(checkbox); | 78 root.children.push_back(checkbox); |
| 79 | 79 |
| 80 // Construct a BrowserAccessibilityManager with this WebAccessibility tree | 80 // Construct a BrowserAccessibilityManager with this |
| 81 // and a factory for an instance-counting BrowserAccessibility, and ensure | 81 // AccessibilityNodeData tree and a factory for an instance-counting |
| 82 // that exactly 3 instances were created. Note that the manager takes | 82 // BrowserAccessibility, and ensure that exactly 3 instances were |
| 83 // ownership of the factory. | 83 // created. Note that the manager takes ownership of the factory. |
| 84 CountedBrowserAccessibility::global_obj_count_ = 0; | 84 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 85 BrowserAccessibilityManager* manager = | 85 BrowserAccessibilityManager* manager = |
| 86 BrowserAccessibilityManager::Create( | 86 BrowserAccessibilityManager::Create( |
| 87 NULL, | 87 NULL, |
| 88 root, | 88 root, |
| 89 NULL, | 89 NULL, |
| 90 new CountedBrowserAccessibilityFactory()); | 90 new CountedBrowserAccessibilityFactory()); |
| 91 | 91 |
| 92 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); | 92 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); |
| 93 | 93 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 TEST(BrowserAccessibilityManagerTest, TestReuseBrowserAccessibilityObjects) { | 128 TEST(BrowserAccessibilityManagerTest, TestReuseBrowserAccessibilityObjects) { |
| 129 // Make sure that changes to a subtree reuse as many objects as possible. | 129 // Make sure that changes to a subtree reuse as many objects as possible. |
| 130 | 130 |
| 131 // Tree 1: | 131 // Tree 1: |
| 132 // | 132 // |
| 133 // root | 133 // root |
| 134 // child1 | 134 // child1 |
| 135 // child2 | 135 // child2 |
| 136 // child3 | 136 // child3 |
| 137 | 137 |
| 138 WebAccessibility tree1_child1; | 138 AccessibilityNodeData tree1_child1; |
| 139 tree1_child1.id = 2; | 139 tree1_child1.id = 2; |
| 140 tree1_child1.name = UTF8ToUTF16("Child1"); | 140 tree1_child1.name = UTF8ToUTF16("Child1"); |
| 141 tree1_child1.role = WebAccessibility::ROLE_BUTTON; | 141 tree1_child1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 142 tree1_child1.state = 0; | 142 tree1_child1.state = 0; |
| 143 | 143 |
| 144 WebAccessibility tree1_child2; | 144 AccessibilityNodeData tree1_child2; |
| 145 tree1_child2.id = 3; | 145 tree1_child2.id = 3; |
| 146 tree1_child2.name = UTF8ToUTF16("Child2"); | 146 tree1_child2.name = UTF8ToUTF16("Child2"); |
| 147 tree1_child2.role = WebAccessibility::ROLE_BUTTON; | 147 tree1_child2.role = AccessibilityNodeData::ROLE_BUTTON; |
| 148 tree1_child2.state = 0; | 148 tree1_child2.state = 0; |
| 149 | 149 |
| 150 WebAccessibility tree1_child3; | 150 AccessibilityNodeData tree1_child3; |
| 151 tree1_child3.id = 4; | 151 tree1_child3.id = 4; |
| 152 tree1_child3.name = UTF8ToUTF16("Child3"); | 152 tree1_child3.name = UTF8ToUTF16("Child3"); |
| 153 tree1_child3.role = WebAccessibility::ROLE_BUTTON; | 153 tree1_child3.role = AccessibilityNodeData::ROLE_BUTTON; |
| 154 tree1_child3.state = 0; | 154 tree1_child3.state = 0; |
| 155 | 155 |
| 156 WebAccessibility tree1_root; | 156 AccessibilityNodeData tree1_root; |
| 157 tree1_root.id = 1; | 157 tree1_root.id = 1; |
| 158 tree1_root.name = UTF8ToUTF16("Document"); | 158 tree1_root.name = UTF8ToUTF16("Document"); |
| 159 tree1_root.role = WebAccessibility::ROLE_DOCUMENT; | 159 tree1_root.role = AccessibilityNodeData::ROLE_DOCUMENT; |
| 160 tree1_root.state = 0; | 160 tree1_root.state = 0; |
| 161 tree1_root.children.push_back(tree1_child1); | 161 tree1_root.children.push_back(tree1_child1); |
| 162 tree1_root.children.push_back(tree1_child2); | 162 tree1_root.children.push_back(tree1_child2); |
| 163 tree1_root.children.push_back(tree1_child3); | 163 tree1_root.children.push_back(tree1_child3); |
| 164 | 164 |
| 165 // Tree 2: | 165 // Tree 2: |
| 166 // | 166 // |
| 167 // root | 167 // root |
| 168 // child0 <-- inserted | 168 // child0 <-- inserted |
| 169 // child1 | 169 // child1 |
| 170 // child2 | 170 // child2 |
| 171 // <-- child3 deleted | 171 // <-- child3 deleted |
| 172 | 172 |
| 173 WebAccessibility tree2_child0; | 173 AccessibilityNodeData tree2_child0; |
| 174 tree2_child0.id = 5; | 174 tree2_child0.id = 5; |
| 175 tree2_child0.name = UTF8ToUTF16("Child0"); | 175 tree2_child0.name = UTF8ToUTF16("Child0"); |
| 176 tree2_child0.role = WebAccessibility::ROLE_BUTTON; | 176 tree2_child0.role = AccessibilityNodeData::ROLE_BUTTON; |
| 177 tree2_child0.state = 0; | 177 tree2_child0.state = 0; |
| 178 | 178 |
| 179 WebAccessibility tree2_child1; | 179 AccessibilityNodeData tree2_child1; |
| 180 tree2_child1.id = 2; | 180 tree2_child1.id = 2; |
| 181 tree2_child1.name = UTF8ToUTF16("Child1"); | 181 tree2_child1.name = UTF8ToUTF16("Child1"); |
| 182 tree2_child1.role = WebAccessibility::ROLE_BUTTON; | 182 tree2_child1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 183 tree2_child1.state = 0; | 183 tree2_child1.state = 0; |
| 184 | 184 |
| 185 WebAccessibility tree2_child2; | 185 AccessibilityNodeData tree2_child2; |
| 186 tree2_child2.id = 3; | 186 tree2_child2.id = 3; |
| 187 tree2_child2.name = UTF8ToUTF16("Child2"); | 187 tree2_child2.name = UTF8ToUTF16("Child2"); |
| 188 tree2_child2.role = WebAccessibility::ROLE_BUTTON; | 188 tree2_child2.role = AccessibilityNodeData::ROLE_BUTTON; |
| 189 tree2_child2.state = 0; | 189 tree2_child2.state = 0; |
| 190 | 190 |
| 191 WebAccessibility tree2_root; | 191 AccessibilityNodeData tree2_root; |
| 192 tree2_root.id = 1; | 192 tree2_root.id = 1; |
| 193 tree2_root.name = UTF8ToUTF16("DocumentChanged"); | 193 tree2_root.name = UTF8ToUTF16("DocumentChanged"); |
| 194 tree2_root.role = WebAccessibility::ROLE_DOCUMENT; | 194 tree2_root.role = AccessibilityNodeData::ROLE_DOCUMENT; |
| 195 tree2_root.state = 0; | 195 tree2_root.state = 0; |
| 196 tree2_root.children.push_back(tree2_child0); | 196 tree2_root.children.push_back(tree2_child0); |
| 197 tree2_root.children.push_back(tree2_child1); | 197 tree2_root.children.push_back(tree2_child1); |
| 198 tree2_root.children.push_back(tree2_child2); | 198 tree2_root.children.push_back(tree2_child2); |
| 199 | 199 |
| 200 // Construct a BrowserAccessibilityManager with tree1. | 200 // Construct a BrowserAccessibilityManager with tree1. |
| 201 CountedBrowserAccessibility::global_obj_count_ = 0; | 201 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 202 BrowserAccessibilityManager* manager = | 202 BrowserAccessibilityManager* manager = |
| 203 BrowserAccessibilityManager::Create( | 203 BrowserAccessibilityManager::Create( |
| 204 NULL, | 204 NULL, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // | 272 // |
| 273 // root | 273 // root |
| 274 // container | 274 // container |
| 275 // child1 | 275 // child1 |
| 276 // grandchild1 | 276 // grandchild1 |
| 277 // child2 | 277 // child2 |
| 278 // grandchild2 | 278 // grandchild2 |
| 279 // child3 | 279 // child3 |
| 280 // grandchild3 | 280 // grandchild3 |
| 281 | 281 |
| 282 WebAccessibility tree1_grandchild1; | 282 AccessibilityNodeData tree1_grandchild1; |
| 283 tree1_grandchild1.id = 4; | 283 tree1_grandchild1.id = 4; |
| 284 tree1_grandchild1.name = UTF8ToUTF16("GrandChild1"); | 284 tree1_grandchild1.name = UTF8ToUTF16("GrandChild1"); |
| 285 tree1_grandchild1.role = WebAccessibility::ROLE_BUTTON; | 285 tree1_grandchild1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 286 tree1_grandchild1.state = 0; | 286 tree1_grandchild1.state = 0; |
| 287 | 287 |
| 288 WebAccessibility tree1_child1; | 288 AccessibilityNodeData tree1_child1; |
| 289 tree1_child1.id = 3; | 289 tree1_child1.id = 3; |
| 290 tree1_child1.name = UTF8ToUTF16("Child1"); | 290 tree1_child1.name = UTF8ToUTF16("Child1"); |
| 291 tree1_child1.role = WebAccessibility::ROLE_BUTTON; | 291 tree1_child1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 292 tree1_child1.state = 0; | 292 tree1_child1.state = 0; |
| 293 tree1_child1.children.push_back(tree1_grandchild1); | 293 tree1_child1.children.push_back(tree1_grandchild1); |
| 294 | 294 |
| 295 WebAccessibility tree1_grandchild2; | 295 AccessibilityNodeData tree1_grandchild2; |
| 296 tree1_grandchild2.id = 6; | 296 tree1_grandchild2.id = 6; |
| 297 tree1_grandchild2.name = UTF8ToUTF16("GrandChild1"); | 297 tree1_grandchild2.name = UTF8ToUTF16("GrandChild1"); |
| 298 tree1_grandchild2.role = WebAccessibility::ROLE_BUTTON; | 298 tree1_grandchild2.role = AccessibilityNodeData::ROLE_BUTTON; |
| 299 tree1_grandchild2.state = 0; | 299 tree1_grandchild2.state = 0; |
| 300 | 300 |
| 301 WebAccessibility tree1_child2; | 301 AccessibilityNodeData tree1_child2; |
| 302 tree1_child2.id = 5; | 302 tree1_child2.id = 5; |
| 303 tree1_child2.name = UTF8ToUTF16("Child2"); | 303 tree1_child2.name = UTF8ToUTF16("Child2"); |
| 304 tree1_child2.role = WebAccessibility::ROLE_BUTTON; | 304 tree1_child2.role = AccessibilityNodeData::ROLE_BUTTON; |
| 305 tree1_child2.state = 0; | 305 tree1_child2.state = 0; |
| 306 tree1_child2.children.push_back(tree1_grandchild2); | 306 tree1_child2.children.push_back(tree1_grandchild2); |
| 307 | 307 |
| 308 WebAccessibility tree1_grandchild3; | 308 AccessibilityNodeData tree1_grandchild3; |
| 309 tree1_grandchild3.id = 8; | 309 tree1_grandchild3.id = 8; |
| 310 tree1_grandchild3.name = UTF8ToUTF16("GrandChild3"); | 310 tree1_grandchild3.name = UTF8ToUTF16("GrandChild3"); |
| 311 tree1_grandchild3.role = WebAccessibility::ROLE_BUTTON; | 311 tree1_grandchild3.role = AccessibilityNodeData::ROLE_BUTTON; |
| 312 tree1_grandchild3.state = 0; | 312 tree1_grandchild3.state = 0; |
| 313 | 313 |
| 314 WebAccessibility tree1_child3; | 314 AccessibilityNodeData tree1_child3; |
| 315 tree1_child3.id = 7; | 315 tree1_child3.id = 7; |
| 316 tree1_child3.name = UTF8ToUTF16("Child3"); | 316 tree1_child3.name = UTF8ToUTF16("Child3"); |
| 317 tree1_child3.role = WebAccessibility::ROLE_BUTTON; | 317 tree1_child3.role = AccessibilityNodeData::ROLE_BUTTON; |
| 318 tree1_child3.state = 0; | 318 tree1_child3.state = 0; |
| 319 tree1_child3.children.push_back(tree1_grandchild3); | 319 tree1_child3.children.push_back(tree1_grandchild3); |
| 320 | 320 |
| 321 WebAccessibility tree1_container; | 321 AccessibilityNodeData tree1_container; |
| 322 tree1_container.id = 2; | 322 tree1_container.id = 2; |
| 323 tree1_container.name = UTF8ToUTF16("Container"); | 323 tree1_container.name = UTF8ToUTF16("Container"); |
| 324 tree1_container.role = WebAccessibility::ROLE_GROUP; | 324 tree1_container.role = AccessibilityNodeData::ROLE_GROUP; |
| 325 tree1_container.state = 0; | 325 tree1_container.state = 0; |
| 326 tree1_container.children.push_back(tree1_child1); | 326 tree1_container.children.push_back(tree1_child1); |
| 327 tree1_container.children.push_back(tree1_child2); | 327 tree1_container.children.push_back(tree1_child2); |
| 328 tree1_container.children.push_back(tree1_child3); | 328 tree1_container.children.push_back(tree1_child3); |
| 329 | 329 |
| 330 WebAccessibility tree1_root; | 330 AccessibilityNodeData tree1_root; |
| 331 tree1_root.id = 1; | 331 tree1_root.id = 1; |
| 332 tree1_root.name = UTF8ToUTF16("Document"); | 332 tree1_root.name = UTF8ToUTF16("Document"); |
| 333 tree1_root.role = WebAccessibility::ROLE_DOCUMENT; | 333 tree1_root.role = AccessibilityNodeData::ROLE_DOCUMENT; |
| 334 tree1_root.state = 0; | 334 tree1_root.state = 0; |
| 335 tree1_root.children.push_back(tree1_container); | 335 tree1_root.children.push_back(tree1_container); |
| 336 | 336 |
| 337 // Tree 2: | 337 // Tree 2: |
| 338 // | 338 // |
| 339 // root | 339 // root |
| 340 // container | 340 // container |
| 341 // child0 <-- inserted | 341 // child0 <-- inserted |
| 342 // grandchild0 <-- | 342 // grandchild0 <-- |
| 343 // child1 | 343 // child1 |
| 344 // grandchild1 | 344 // grandchild1 |
| 345 // child2 | 345 // child2 |
| 346 // grandchild2 | 346 // grandchild2 |
| 347 // <-- child3 (and grandchild3) deleted | 347 // <-- child3 (and grandchild3) deleted |
| 348 | 348 |
| 349 WebAccessibility tree2_grandchild0; | 349 AccessibilityNodeData tree2_grandchild0; |
| 350 tree2_grandchild0.id = 9; | 350 tree2_grandchild0.id = 9; |
| 351 tree2_grandchild0.name = UTF8ToUTF16("GrandChild0"); | 351 tree2_grandchild0.name = UTF8ToUTF16("GrandChild0"); |
| 352 tree2_grandchild0.role = WebAccessibility::ROLE_BUTTON; | 352 tree2_grandchild0.role = AccessibilityNodeData::ROLE_BUTTON; |
| 353 tree2_grandchild0.state = 0; | 353 tree2_grandchild0.state = 0; |
| 354 | 354 |
| 355 WebAccessibility tree2_child0; | 355 AccessibilityNodeData tree2_child0; |
| 356 tree2_child0.id = 10; | 356 tree2_child0.id = 10; |
| 357 tree2_child0.name = UTF8ToUTF16("Child0"); | 357 tree2_child0.name = UTF8ToUTF16("Child0"); |
| 358 tree2_child0.role = WebAccessibility::ROLE_BUTTON; | 358 tree2_child0.role = AccessibilityNodeData::ROLE_BUTTON; |
| 359 tree2_child0.state = 0; | 359 tree2_child0.state = 0; |
| 360 tree2_child0.children.push_back(tree2_grandchild0); | 360 tree2_child0.children.push_back(tree2_grandchild0); |
| 361 | 361 |
| 362 WebAccessibility tree2_grandchild1; | 362 AccessibilityNodeData tree2_grandchild1; |
| 363 tree2_grandchild1.id = 4; | 363 tree2_grandchild1.id = 4; |
| 364 tree2_grandchild1.name = UTF8ToUTF16("GrandChild1"); | 364 tree2_grandchild1.name = UTF8ToUTF16("GrandChild1"); |
| 365 tree2_grandchild1.role = WebAccessibility::ROLE_BUTTON; | 365 tree2_grandchild1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 366 tree2_grandchild1.state = 0; | 366 tree2_grandchild1.state = 0; |
| 367 | 367 |
| 368 WebAccessibility tree2_child1; | 368 AccessibilityNodeData tree2_child1; |
| 369 tree2_child1.id = 3; | 369 tree2_child1.id = 3; |
| 370 tree2_child1.name = UTF8ToUTF16("Child1"); | 370 tree2_child1.name = UTF8ToUTF16("Child1"); |
| 371 tree2_child1.role = WebAccessibility::ROLE_BUTTON; | 371 tree2_child1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 372 tree2_child1.state = 0; | 372 tree2_child1.state = 0; |
| 373 tree2_child1.children.push_back(tree2_grandchild1); | 373 tree2_child1.children.push_back(tree2_grandchild1); |
| 374 | 374 |
| 375 WebAccessibility tree2_grandchild2; | 375 AccessibilityNodeData tree2_grandchild2; |
| 376 tree2_grandchild2.id = 6; | 376 tree2_grandchild2.id = 6; |
| 377 tree2_grandchild2.name = UTF8ToUTF16("GrandChild1"); | 377 tree2_grandchild2.name = UTF8ToUTF16("GrandChild1"); |
| 378 tree2_grandchild2.role = WebAccessibility::ROLE_BUTTON; | 378 tree2_grandchild2.role = AccessibilityNodeData::ROLE_BUTTON; |
| 379 tree2_grandchild2.state = 0; | 379 tree2_grandchild2.state = 0; |
| 380 | 380 |
| 381 WebAccessibility tree2_child2; | 381 AccessibilityNodeData tree2_child2; |
| 382 tree2_child2.id = 5; | 382 tree2_child2.id = 5; |
| 383 tree2_child2.name = UTF8ToUTF16("Child2"); | 383 tree2_child2.name = UTF8ToUTF16("Child2"); |
| 384 tree2_child2.role = WebAccessibility::ROLE_BUTTON; | 384 tree2_child2.role = AccessibilityNodeData::ROLE_BUTTON; |
| 385 tree2_child2.state = 0; | 385 tree2_child2.state = 0; |
| 386 tree2_child2.children.push_back(tree2_grandchild2); | 386 tree2_child2.children.push_back(tree2_grandchild2); |
| 387 | 387 |
| 388 WebAccessibility tree2_container; | 388 AccessibilityNodeData tree2_container; |
| 389 tree2_container.id = 2; | 389 tree2_container.id = 2; |
| 390 tree2_container.name = UTF8ToUTF16("Container"); | 390 tree2_container.name = UTF8ToUTF16("Container"); |
| 391 tree2_container.role = WebAccessibility::ROLE_GROUP; | 391 tree2_container.role = AccessibilityNodeData::ROLE_GROUP; |
| 392 tree2_container.state = 0; | 392 tree2_container.state = 0; |
| 393 tree2_container.children.push_back(tree2_child0); | 393 tree2_container.children.push_back(tree2_child0); |
| 394 tree2_container.children.push_back(tree2_child1); | 394 tree2_container.children.push_back(tree2_child1); |
| 395 tree2_container.children.push_back(tree2_child2); | 395 tree2_container.children.push_back(tree2_child2); |
| 396 | 396 |
| 397 WebAccessibility tree2_root; | 397 AccessibilityNodeData tree2_root; |
| 398 tree2_root.id = 1; | 398 tree2_root.id = 1; |
| 399 tree2_root.name = UTF8ToUTF16("Document"); | 399 tree2_root.name = UTF8ToUTF16("Document"); |
| 400 tree2_root.role = WebAccessibility::ROLE_DOCUMENT; | 400 tree2_root.role = AccessibilityNodeData::ROLE_DOCUMENT; |
| 401 tree2_root.state = 0; | 401 tree2_root.state = 0; |
| 402 tree2_root.children.push_back(tree2_container); | 402 tree2_root.children.push_back(tree2_container); |
| 403 | 403 |
| 404 // Construct a BrowserAccessibilityManager with tree1. | 404 // Construct a BrowserAccessibilityManager with tree1. |
| 405 CountedBrowserAccessibility::global_obj_count_ = 0; | 405 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 406 BrowserAccessibilityManager* manager = | 406 BrowserAccessibilityManager* manager = |
| 407 BrowserAccessibilityManager::Create( | 407 BrowserAccessibilityManager::Create( |
| 408 NULL, | 408 NULL, |
| 409 tree1_root, | 409 tree1_root, |
| 410 NULL, | 410 NULL, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 } | 475 } |
| 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 WebAccessibility tree1_4; | 485 AccessibilityNodeData tree1_4; |
| 486 tree1_4.id = 4; | 486 tree1_4.id = 4; |
| 487 tree1_4.state = 0; | 487 tree1_4.state = 0; |
| 488 | 488 |
| 489 WebAccessibility tree1_3; | 489 AccessibilityNodeData tree1_3; |
| 490 tree1_3.id = 3; | 490 tree1_3.id = 3; |
| 491 tree1_3.state = 0; | 491 tree1_3.state = 0; |
| 492 tree1_3.children.push_back(tree1_4); | 492 tree1_3.children.push_back(tree1_4); |
| 493 | 493 |
| 494 WebAccessibility tree1_2; | 494 AccessibilityNodeData tree1_2; |
| 495 tree1_2.id = 2; | 495 tree1_2.id = 2; |
| 496 tree1_2.state = 0; | 496 tree1_2.state = 0; |
| 497 | 497 |
| 498 WebAccessibility tree1_1; | 498 AccessibilityNodeData tree1_1; |
| 499 tree1_1.id = 1; | 499 tree1_1.id = 1; |
| 500 tree1_1.state = 0; | 500 tree1_1.state = 0; |
| 501 tree1_1.children.push_back(tree1_2); | 501 tree1_1.children.push_back(tree1_2); |
| 502 tree1_1.children.push_back(tree1_3); | 502 tree1_1.children.push_back(tree1_3); |
| 503 | 503 |
| 504 // Tree 2: | 504 // Tree 2: |
| 505 // | 505 // |
| 506 // 1 | 506 // 1 |
| 507 // 4 <-- moves up a level and gains child | 507 // 4 <-- moves up a level and gains child |
| 508 // 6 <-- new | 508 // 6 <-- new |
| 509 // 5 <-- new | 509 // 5 <-- new |
| 510 | 510 |
| 511 WebAccessibility tree2_6; | 511 AccessibilityNodeData tree2_6; |
| 512 tree2_6.id = 6; | 512 tree2_6.id = 6; |
| 513 tree2_6.state = 0; | 513 tree2_6.state = 0; |
| 514 | 514 |
| 515 WebAccessibility tree2_5; | 515 AccessibilityNodeData tree2_5; |
| 516 tree2_5.id = 5; | 516 tree2_5.id = 5; |
| 517 tree2_5.state = 0; | 517 tree2_5.state = 0; |
| 518 | 518 |
| 519 WebAccessibility tree2_4; | 519 AccessibilityNodeData tree2_4; |
| 520 tree2_4.id = 4; | 520 tree2_4.id = 4; |
| 521 tree2_4.state = 0; | 521 tree2_4.state = 0; |
| 522 tree2_4.children.push_back(tree2_6); | 522 tree2_4.children.push_back(tree2_6); |
| 523 | 523 |
| 524 WebAccessibility tree2_1; | 524 AccessibilityNodeData tree2_1; |
| 525 tree2_1.id = 1; | 525 tree2_1.id = 1; |
| 526 tree2_1.state = 0; | 526 tree2_1.state = 0; |
| 527 tree2_1.children.push_back(tree2_4); | 527 tree2_1.children.push_back(tree2_4); |
| 528 tree2_1.children.push_back(tree2_5); | 528 tree2_1.children.push_back(tree2_5); |
| 529 | 529 |
| 530 // Construct a BrowserAccessibilityManager with tree1. | 530 // Construct a BrowserAccessibilityManager with tree1. |
| 531 CountedBrowserAccessibility::global_obj_count_ = 0; | 531 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 532 BrowserAccessibilityManager* manager = | 532 BrowserAccessibilityManager* manager = |
| 533 BrowserAccessibilityManager::Create( | 533 BrowserAccessibilityManager::Create( |
| 534 NULL, | 534 NULL, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 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 TEST(BrowserAccessibilityManagerTest, TestCreateEmptyDocument) { | 558 TEST(BrowserAccessibilityManagerTest, TestCreateEmptyDocument) { |
| 559 // Try creating an empty document with busy state. Readonly is | 559 // Try creating an empty document with busy state. Readonly is |
| 560 // set automatically. | 560 // set automatically. |
| 561 const int32 busy_state = 1 << WebAccessibility::STATE_BUSY; | 561 const int32 busy_state = 1 << AccessibilityNodeData::STATE_BUSY; |
| 562 const int32 readonly_state = 1 << WebAccessibility::STATE_READONLY; | 562 const int32 readonly_state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 563 scoped_ptr<BrowserAccessibilityManager> manager; | 563 scoped_ptr<BrowserAccessibilityManager> manager; |
| 564 manager.reset(BrowserAccessibilityManager::CreateEmptyDocument( | 564 manager.reset(BrowserAccessibilityManager::CreateEmptyDocument( |
| 565 NULL, | 565 NULL, |
| 566 static_cast<WebAccessibility::State>(busy_state), | 566 static_cast<AccessibilityNodeData::State>(busy_state), |
| 567 NULL, | 567 NULL, |
| 568 new CountedBrowserAccessibilityFactory())); | 568 new CountedBrowserAccessibilityFactory())); |
| 569 | 569 |
| 570 // Verify the root is as we expect by default. | 570 // Verify the root is as we expect by default. |
| 571 BrowserAccessibility* root = manager->GetRoot(); | 571 BrowserAccessibility* root = manager->GetRoot(); |
| 572 EXPECT_EQ(0, root->renderer_id()); | 572 EXPECT_EQ(0, root->renderer_id()); |
| 573 EXPECT_EQ(WebAccessibility::ROLE_ROOT_WEB_AREA, root->role()); | 573 EXPECT_EQ(AccessibilityNodeData::ROLE_ROOT_WEB_AREA, root->role()); |
| 574 EXPECT_EQ(busy_state | readonly_state, root->state()); | 574 EXPECT_EQ(busy_state | readonly_state, root->state()); |
| 575 | 575 |
| 576 // Tree with a child textfield. | 576 // Tree with a child textfield. |
| 577 WebAccessibility tree1_1; | 577 AccessibilityNodeData tree1_1; |
| 578 tree1_1.id = 1; | 578 tree1_1.id = 1; |
| 579 tree1_1.role = WebAccessibility::ROLE_ROOT_WEB_AREA; | 579 tree1_1.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 580 | 580 |
| 581 WebAccessibility tree1_2; | 581 AccessibilityNodeData tree1_2; |
| 582 tree1_2.id = 2; | 582 tree1_2.id = 2; |
| 583 tree1_2.role = WebAccessibility::ROLE_TEXT_FIELD; | 583 tree1_2.role = AccessibilityNodeData::ROLE_TEXT_FIELD; |
| 584 | 584 |
| 585 tree1_1.children.push_back(tree1_2); | 585 tree1_1.children.push_back(tree1_2); |
| 586 | 586 |
| 587 // Process a load complete. | 587 // Process a load complete. |
| 588 std::vector<AccessibilityHostMsg_NotificationParams> params; | 588 std::vector<AccessibilityHostMsg_NotificationParams> params; |
| 589 params.push_back(AccessibilityHostMsg_NotificationParams()); | 589 params.push_back(AccessibilityHostMsg_NotificationParams()); |
| 590 AccessibilityHostMsg_NotificationParams* msg = ¶ms[0]; | 590 AccessibilityHostMsg_NotificationParams* msg = ¶ms[0]; |
| 591 msg->notification_type = AccessibilityNotificationLoadComplete; | 591 msg->notification_type = AccessibilityNotificationLoadComplete; |
| 592 msg->acc_tree = tree1_1; | 592 msg->acc_tree = tree1_1; |
| 593 msg->includes_children = true; | 593 msg->includes_children = true; |
| 594 msg->id = tree1_1.id; | 594 msg->id = tree1_1.id; |
| 595 manager->OnAccessibilityNotifications(params); | 595 manager->OnAccessibilityNotifications(params); |
| 596 | 596 |
| 597 // Save for later comparison. | 597 // Save for later comparison. |
| 598 BrowserAccessibility* acc1_2 = manager->GetFromRendererID(2); | 598 BrowserAccessibility* acc1_2 = manager->GetFromRendererID(2); |
| 599 | 599 |
| 600 // Verify the root has changed. | 600 // Verify the root has changed. |
| 601 EXPECT_NE(root, manager->GetRoot()); | 601 EXPECT_NE(root, manager->GetRoot()); |
| 602 | 602 |
| 603 // And the proper child remains. | 603 // And the proper child remains. |
| 604 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, acc1_2->role()); | 604 EXPECT_EQ(AccessibilityNodeData::ROLE_TEXT_FIELD, acc1_2->role()); |
| 605 EXPECT_EQ(2, acc1_2->renderer_id()); | 605 EXPECT_EQ(2, acc1_2->renderer_id()); |
| 606 | 606 |
| 607 // Tree with a child button. | 607 // Tree with a child button. |
| 608 WebAccessibility tree2_1; | 608 AccessibilityNodeData tree2_1; |
| 609 tree2_1.id = 1; | 609 tree2_1.id = 1; |
| 610 tree2_1.role = WebAccessibility::ROLE_ROOT_WEB_AREA; | 610 tree2_1.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 611 | 611 |
| 612 WebAccessibility tree2_2; | 612 AccessibilityNodeData tree2_2; |
| 613 tree2_2.id = 3; | 613 tree2_2.id = 3; |
| 614 tree2_2.role = WebAccessibility::ROLE_BUTTON; | 614 tree2_2.role = AccessibilityNodeData::ROLE_BUTTON; |
| 615 | 615 |
| 616 tree2_1.children.push_back(tree2_2); | 616 tree2_1.children.push_back(tree2_2); |
| 617 | 617 |
| 618 msg->acc_tree = tree2_1; | 618 msg->acc_tree = tree2_1; |
| 619 msg->includes_children = true; | 619 msg->includes_children = true; |
| 620 msg->id = tree2_1.id; | 620 msg->id = tree2_1.id; |
| 621 | 621 |
| 622 // Fire another load complete. | 622 // Fire another load complete. |
| 623 manager->OnAccessibilityNotifications(params); | 623 manager->OnAccessibilityNotifications(params); |
| 624 | 624 |
| 625 BrowserAccessibility* acc2_2 = manager->GetFromRendererID(3); | 625 BrowserAccessibility* acc2_2 = manager->GetFromRendererID(3); |
| 626 | 626 |
| 627 // Verify the root has changed. | 627 // Verify the root has changed. |
| 628 EXPECT_NE(root, manager->GetRoot()); | 628 EXPECT_NE(root, manager->GetRoot()); |
| 629 | 629 |
| 630 // And the new child exists. | 630 // And the new child exists. |
| 631 EXPECT_EQ(WebAccessibility::ROLE_BUTTON, acc2_2->role()); | 631 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, acc2_2->role()); |
| 632 EXPECT_EQ(3, acc2_2->renderer_id()); | 632 EXPECT_EQ(3, acc2_2->renderer_id()); |
| 633 | 633 |
| 634 // Ensure we properly cleaned up. | 634 // Ensure we properly cleaned up. |
| 635 manager.reset(); | 635 manager.reset(); |
| 636 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 636 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
| 637 } | 637 } |
| OLD | NEW |