| 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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/strings/utf_string_conversions.h" |
| 6 #include "base/win/scoped_bstr.h" | 7 #include "base/win/scoped_bstr.h" |
| 7 #include "base/win/scoped_comptr.h" | 8 #include "base/win/scoped_comptr.h" |
| 8 #include "base/win/scoped_variant.h" | 9 #include "base/win/scoped_variant.h" |
| 9 #include "content/browser/accessibility/browser_accessibility_manager.h" | 10 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 10 #include "content/browser/accessibility/browser_accessibility_manager_win.h" | 11 #include "content/browser/accessibility/browser_accessibility_manager_win.h" |
| 11 #include "content/browser/accessibility/browser_accessibility_win.h" | 12 #include "content/browser/accessibility/browser_accessibility_win.h" |
| 12 #include "content/common/accessibility_messages.h" | 13 #include "content/common/accessibility_messages.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/base/win/atl_module.h" | 15 #include "ui/base/win/atl_module.h" |
| 15 | 16 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Actual tests --------------------------------------------------------------- | 107 // Actual tests --------------------------------------------------------------- |
| 107 | 108 |
| 108 // Test that BrowserAccessibilityManager correctly releases the tree of | 109 // Test that BrowserAccessibilityManager correctly releases the tree of |
| 109 // BrowserAccessibility instances upon delete. | 110 // BrowserAccessibility instances upon delete. |
| 110 TEST_F(BrowserAccessibilityTest, TestNoLeaks) { | 111 TEST_F(BrowserAccessibilityTest, TestNoLeaks) { |
| 111 // Create AccessibilityNodeData objects for a simple document tree, | 112 // Create AccessibilityNodeData objects for a simple document tree, |
| 112 // representing the accessibility information used to initialize | 113 // representing the accessibility information used to initialize |
| 113 // BrowserAccessibilityManager. | 114 // BrowserAccessibilityManager. |
| 114 AccessibilityNodeData button; | 115 AccessibilityNodeData button; |
| 115 button.id = 2; | 116 button.id = 2; |
| 116 button.name = L"Button"; | 117 button.SetName("Button"); |
| 117 button.role = AccessibilityNodeData::ROLE_BUTTON; | 118 button.role = AccessibilityNodeData::ROLE_BUTTON; |
| 118 button.state = 0; | 119 button.state = 0; |
| 119 | 120 |
| 120 AccessibilityNodeData checkbox; | 121 AccessibilityNodeData checkbox; |
| 121 checkbox.id = 3; | 122 checkbox.id = 3; |
| 122 checkbox.name = L"Checkbox"; | 123 checkbox.SetName("Checkbox"); |
| 123 checkbox.role = AccessibilityNodeData::ROLE_CHECKBOX; | 124 checkbox.role = AccessibilityNodeData::ROLE_CHECKBOX; |
| 124 checkbox.state = 0; | 125 checkbox.state = 0; |
| 125 | 126 |
| 126 AccessibilityNodeData root; | 127 AccessibilityNodeData root; |
| 127 root.id = 1; | 128 root.id = 1; |
| 128 root.name = L"Document"; | 129 root.SetName("Document"); |
| 129 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 130 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 130 root.state = 0; | 131 root.state = 0; |
| 131 root.child_ids.push_back(2); | 132 root.child_ids.push_back(2); |
| 132 root.child_ids.push_back(3); | 133 root.child_ids.push_back(3); |
| 133 | 134 |
| 134 // Construct a BrowserAccessibilityManager with this | 135 // Construct a BrowserAccessibilityManager with this |
| 135 // AccessibilityNodeData tree and a factory for an instance-counting | 136 // AccessibilityNodeData tree and a factory for an instance-counting |
| 136 // BrowserAccessibility, and ensure that exactly 3 instances were | 137 // BrowserAccessibility, and ensure that exactly 3 instances were |
| 137 // created. Note that the manager takes ownership of the factory. | 138 // created. Note that the manager takes ownership of the factory. |
| 138 CountedBrowserAccessibility::reset(); | 139 CountedBrowserAccessibility::reset(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 177 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 177 } | 178 } |
| 178 | 179 |
| 179 TEST_F(BrowserAccessibilityTest, TestChildrenChange) { | 180 TEST_F(BrowserAccessibilityTest, TestChildrenChange) { |
| 180 // Create AccessibilityNodeData objects for a simple document tree, | 181 // Create AccessibilityNodeData objects for a simple document tree, |
| 181 // representing the accessibility information used to initialize | 182 // representing the accessibility information used to initialize |
| 182 // BrowserAccessibilityManager. | 183 // BrowserAccessibilityManager. |
| 183 AccessibilityNodeData text; | 184 AccessibilityNodeData text; |
| 184 text.id = 2; | 185 text.id = 2; |
| 185 text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 186 text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 186 text.name = L"old text"; | 187 text.SetName("old text"); |
| 187 text.state = 0; | 188 text.state = 0; |
| 188 | 189 |
| 189 AccessibilityNodeData root; | 190 AccessibilityNodeData root; |
| 190 root.id = 1; | 191 root.id = 1; |
| 191 root.name = L"Document"; | 192 root.SetName("Document"); |
| 192 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 193 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 193 root.state = 0; | 194 root.state = 0; |
| 194 root.child_ids.push_back(2); | 195 root.child_ids.push_back(2); |
| 195 | 196 |
| 196 // Construct a BrowserAccessibilityManager with this | 197 // Construct a BrowserAccessibilityManager with this |
| 197 // AccessibilityNodeData tree and a factory for an instance-counting | 198 // AccessibilityNodeData tree and a factory for an instance-counting |
| 198 // BrowserAccessibility. | 199 // BrowserAccessibility. |
| 199 CountedBrowserAccessibility::reset(); | 200 CountedBrowserAccessibility::reset(); |
| 200 scoped_ptr<BrowserAccessibilityManager> manager( | 201 scoped_ptr<BrowserAccessibilityManager> manager( |
| 201 BrowserAccessibilityManager::Create( | 202 BrowserAccessibilityManager::Create( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 218 base::win::ScopedBstr name; | 219 base::win::ScopedBstr name; |
| 219 hr = text_accessible->get_accName(childid_self, name.Receive()); | 220 hr = text_accessible->get_accName(childid_self, name.Receive()); |
| 220 ASSERT_EQ(S_OK, hr); | 221 ASSERT_EQ(S_OK, hr); |
| 221 EXPECT_EQ(L"old text", string16(name)); | 222 EXPECT_EQ(L"old text", string16(name)); |
| 222 name.Reset(); | 223 name.Reset(); |
| 223 | 224 |
| 224 text_dispatch.Release(); | 225 text_dispatch.Release(); |
| 225 text_accessible.Release(); | 226 text_accessible.Release(); |
| 226 | 227 |
| 227 // Notify the BrowserAccessibilityManager that the text child has changed. | 228 // Notify the BrowserAccessibilityManager that the text child has changed. |
| 228 text.name = L"new text"; | 229 AccessibilityNodeData text2; |
| 230 text2.id = 2; |
| 231 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 232 text2.SetName("new text"); |
| 233 text2.SetName("old text"); |
| 229 AccessibilityHostMsg_NotificationParams param; | 234 AccessibilityHostMsg_NotificationParams param; |
| 230 param.notification_type = AccessibilityNotificationChildrenChanged; | 235 param.notification_type = AccessibilityNotificationChildrenChanged; |
| 231 param.nodes.push_back(text); | 236 param.nodes.push_back(text2); |
| 232 param.id = text.id; | 237 param.id = text2.id; |
| 233 std::vector<AccessibilityHostMsg_NotificationParams> notifications; | 238 std::vector<AccessibilityHostMsg_NotificationParams> notifications; |
| 234 notifications.push_back(param); | 239 notifications.push_back(param); |
| 235 manager->OnAccessibilityNotifications(notifications); | 240 manager->OnAccessibilityNotifications(notifications); |
| 236 | 241 |
| 237 // Query for the text IAccessible and verify that it now returns "new text" | 242 // Query for the text IAccessible and verify that it now returns "new text" |
| 238 // as its value. | 243 // as its value. |
| 239 hr = manager->GetRoot()->ToBrowserAccessibilityWin()->get_accChild( | 244 hr = manager->GetRoot()->ToBrowserAccessibilityWin()->get_accChild( |
| 240 one, text_dispatch.Receive()); | 245 one, text_dispatch.Receive()); |
| 241 ASSERT_EQ(S_OK, hr); | 246 ASSERT_EQ(S_OK, hr); |
| 242 | 247 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 manager->OnAccessibilityNotifications(notifications); | 312 manager->OnAccessibilityNotifications(notifications); |
| 308 ASSERT_EQ(1, CountedBrowserAccessibility::num_instances()); | 313 ASSERT_EQ(1, CountedBrowserAccessibility::num_instances()); |
| 309 | 314 |
| 310 // Delete the manager and test that all BrowserAccessibility instances are | 315 // Delete the manager and test that all BrowserAccessibility instances are |
| 311 // deleted. | 316 // deleted. |
| 312 manager.reset(); | 317 manager.reset(); |
| 313 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 318 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 314 } | 319 } |
| 315 | 320 |
| 316 TEST_F(BrowserAccessibilityTest, TestTextBoundaries) { | 321 TEST_F(BrowserAccessibilityTest, TestTextBoundaries) { |
| 322 std::string text1_value = "One two three.\nFour five six."; |
| 323 |
| 317 AccessibilityNodeData text1; | 324 AccessibilityNodeData text1; |
| 318 text1.id = 11; | 325 text1.id = 11; |
| 319 text1.role = AccessibilityNodeData::ROLE_TEXT_FIELD; | 326 text1.role = AccessibilityNodeData::ROLE_TEXT_FIELD; |
| 320 text1.state = 0; | 327 text1.state = 0; |
| 321 text1.value = L"One two three.\nFour five six."; | 328 text1.AddStringAttribute(AccessibilityNodeData::ATTR_VALUE, text1_value); |
| 322 text1.line_breaks.push_back(15); | 329 std::vector<int32> line_breaks; |
| 330 line_breaks.push_back(15); |
| 331 text1.AddIntListAttribute( |
| 332 AccessibilityNodeData::ATTR_LINE_BREAKS, line_breaks); |
| 323 | 333 |
| 324 AccessibilityNodeData root; | 334 AccessibilityNodeData root; |
| 325 root.id = 1; | 335 root.id = 1; |
| 326 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 336 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 327 root.state = 0; | 337 root.state = 0; |
| 328 root.child_ids.push_back(11); | 338 root.child_ids.push_back(11); |
| 329 | 339 |
| 330 CountedBrowserAccessibility::reset(); | 340 CountedBrowserAccessibility::reset(); |
| 331 scoped_ptr<BrowserAccessibilityManager> manager( | 341 scoped_ptr<BrowserAccessibilityManager> manager( |
| 332 BrowserAccessibilityManager::Create( | 342 BrowserAccessibilityManager::Create( |
| 333 root, NULL, new CountedBrowserAccessibilityFactory())); | 343 root, NULL, new CountedBrowserAccessibilityFactory())); |
| 334 manager->UpdateNodesForTesting(text1); | 344 manager->UpdateNodesForTesting(text1); |
| 335 ASSERT_EQ(2, CountedBrowserAccessibility::num_instances()); | 345 ASSERT_EQ(2, CountedBrowserAccessibility::num_instances()); |
| 336 | 346 |
| 337 BrowserAccessibilityWin* root_obj = | 347 BrowserAccessibilityWin* root_obj = |
| 338 manager->GetRoot()->ToBrowserAccessibilityWin(); | 348 manager->GetRoot()->ToBrowserAccessibilityWin(); |
| 339 BrowserAccessibilityWin* text1_obj = | 349 BrowserAccessibilityWin* text1_obj = |
| 340 root_obj->GetChild(0)->ToBrowserAccessibilityWin(); | 350 root_obj->GetChild(0)->ToBrowserAccessibilityWin(); |
| 341 | 351 |
| 342 long text1_len; | 352 long text1_len; |
| 343 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len)); | 353 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len)); |
| 344 | 354 |
| 345 base::win::ScopedBstr text; | 355 base::win::ScopedBstr text; |
| 346 ASSERT_EQ(S_OK, text1_obj->get_text(0, text1_len, text.Receive())); | 356 ASSERT_EQ(S_OK, text1_obj->get_text(0, text1_len, text.Receive())); |
| 347 ASSERT_EQ(text1.value, string16(text)); | 357 ASSERT_EQ(text1_value, base::UTF16ToUTF8(string16(text))); |
| 348 text.Reset(); | 358 text.Reset(); |
| 349 | 359 |
| 350 ASSERT_EQ(S_OK, text1_obj->get_text(0, 4, text.Receive())); | 360 ASSERT_EQ(S_OK, text1_obj->get_text(0, 4, text.Receive())); |
| 351 ASSERT_STREQ(L"One ", text); | 361 ASSERT_STREQ(L"One ", text); |
| 352 text.Reset(); | 362 text.Reset(); |
| 353 | 363 |
| 354 long start; | 364 long start; |
| 355 long end; | 365 long end; |
| 356 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( | 366 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( |
| 357 1, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive())); | 367 1, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive())); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, text.Receive())); | 408 text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, text.Receive())); |
| 399 ASSERT_STREQ(L"One two three.\nFour five six.", text); | 409 ASSERT_STREQ(L"One two three.\nFour five six.", text); |
| 400 | 410 |
| 401 // Delete the manager and test that all BrowserAccessibility instances are | 411 // Delete the manager and test that all BrowserAccessibility instances are |
| 402 // deleted. | 412 // deleted. |
| 403 manager.reset(); | 413 manager.reset(); |
| 404 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 414 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 405 } | 415 } |
| 406 | 416 |
| 407 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { | 417 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { |
| 418 const std::string text1_name = "One two three."; |
| 419 const std::string text2_name = " Four five six."; |
| 420 |
| 408 AccessibilityNodeData text1; | 421 AccessibilityNodeData text1; |
| 409 text1.id = 11; | 422 text1.id = 11; |
| 410 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 423 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 411 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; | 424 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 412 text1.name = L"One two three."; | 425 text1.SetName(text1_name); |
| 413 | 426 |
| 414 AccessibilityNodeData text2; | 427 AccessibilityNodeData text2; |
| 415 text2.id = 12; | 428 text2.id = 12; |
| 416 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 429 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 417 text2.state = 1 << AccessibilityNodeData::STATE_READONLY; | 430 text2.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 418 text2.name = L" Four five six."; | 431 text2.SetName(text2_name); |
| 419 | 432 |
| 420 AccessibilityNodeData root; | 433 AccessibilityNodeData root; |
| 421 root.id = 1; | 434 root.id = 1; |
| 422 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 435 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 423 root.state = 1 << AccessibilityNodeData::STATE_READONLY; | 436 root.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 424 root.child_ids.push_back(11); | 437 root.child_ids.push_back(11); |
| 425 root.child_ids.push_back(12); | 438 root.child_ids.push_back(12); |
| 426 | 439 |
| 427 CountedBrowserAccessibility::reset(); | 440 CountedBrowserAccessibility::reset(); |
| 428 scoped_ptr<BrowserAccessibilityManager> manager( | 441 scoped_ptr<BrowserAccessibilityManager> manager( |
| 429 BrowserAccessibilityManager::Create( | 442 BrowserAccessibilityManager::Create( |
| 430 root, NULL, new CountedBrowserAccessibilityFactory())); | 443 root, NULL, new CountedBrowserAccessibilityFactory())); |
| 431 manager->UpdateNodesForTesting(root, text1, text2); | 444 manager->UpdateNodesForTesting(root, text1, text2); |
| 432 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); | 445 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); |
| 433 | 446 |
| 434 BrowserAccessibilityWin* root_obj = | 447 BrowserAccessibilityWin* root_obj = |
| 435 manager->GetRoot()->ToBrowserAccessibilityWin(); | 448 manager->GetRoot()->ToBrowserAccessibilityWin(); |
| 436 | 449 |
| 437 long text_len; | 450 long text_len; |
| 438 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); | 451 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
| 439 | 452 |
| 440 base::win::ScopedBstr text; | 453 base::win::ScopedBstr text; |
| 441 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); | 454 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); |
| 442 EXPECT_EQ(text1.name + text2.name, string16(text)); | 455 EXPECT_EQ(text1_name + text2_name, base::UTF16ToUTF8(string16(text))); |
| 443 | 456 |
| 444 long hyperlink_count; | 457 long hyperlink_count; |
| 445 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); | 458 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
| 446 EXPECT_EQ(0, hyperlink_count); | 459 EXPECT_EQ(0, hyperlink_count); |
| 447 | 460 |
| 448 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; | 461 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
| 449 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); | 462 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
| 450 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive())); | 463 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive())); |
| 451 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); | 464 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
| 452 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive())); | 465 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive())); |
| 453 | 466 |
| 454 long hyperlink_index; | 467 long hyperlink_index; |
| 455 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); | 468 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
| 456 EXPECT_EQ(-1, hyperlink_index); | 469 EXPECT_EQ(-1, hyperlink_index); |
| 457 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); | 470 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
| 458 EXPECT_EQ(-1, hyperlink_index); | 471 EXPECT_EQ(-1, hyperlink_index); |
| 459 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); | 472 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); |
| 460 EXPECT_EQ(-1, hyperlink_index); | 473 EXPECT_EQ(-1, hyperlink_index); |
| 461 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); | 474 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); |
| 462 EXPECT_EQ(-1, hyperlink_index); | 475 EXPECT_EQ(-1, hyperlink_index); |
| 463 | 476 |
| 464 // Delete the manager and test that all BrowserAccessibility instances are | 477 // Delete the manager and test that all BrowserAccessibility instances are |
| 465 // deleted. | 478 // deleted. |
| 466 manager.reset(); | 479 manager.reset(); |
| 467 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 480 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 468 } | 481 } |
| 469 | 482 |
| 470 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { | 483 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { |
| 484 const std::string text1_name = "One two three."; |
| 485 const std::string text2_name = " Four five six."; |
| 486 const std::string button1_text_name = "red"; |
| 487 const std::string link1_text_name = "blue"; |
| 488 |
| 471 AccessibilityNodeData text1; | 489 AccessibilityNodeData text1; |
| 472 text1.id = 11; | 490 text1.id = 11; |
| 473 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 491 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 474 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; | 492 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 475 text1.name = L"One two three."; | 493 text1.SetName(text1_name); |
| 476 | 494 |
| 477 AccessibilityNodeData text2; | 495 AccessibilityNodeData text2; |
| 478 text2.id = 12; | 496 text2.id = 12; |
| 479 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 497 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 480 text2.state = 1 << AccessibilityNodeData::STATE_READONLY; | 498 text2.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 481 text2.name = L" Four five six."; | 499 text2.SetName(text2_name); |
| 482 | 500 |
| 483 AccessibilityNodeData button1, button1_text; | 501 AccessibilityNodeData button1, button1_text; |
| 484 button1.id = 13; | 502 button1.id = 13; |
| 485 button1_text.id = 15; | 503 button1_text.id = 15; |
| 486 button1_text.name = L"red"; | 504 button1_text.SetName(button1_text_name); |
| 487 button1.role = AccessibilityNodeData::ROLE_BUTTON; | 505 button1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 488 button1_text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 506 button1_text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 489 button1.state = 1 << AccessibilityNodeData::STATE_READONLY; | 507 button1.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 490 button1_text.state = 1 << AccessibilityNodeData::STATE_READONLY; | 508 button1_text.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 491 button1.child_ids.push_back(15); | 509 button1.child_ids.push_back(15); |
| 492 | 510 |
| 493 AccessibilityNodeData link1, link1_text; | 511 AccessibilityNodeData link1, link1_text; |
| 494 link1.id = 14; | 512 link1.id = 14; |
| 495 link1_text.id = 16; | 513 link1_text.id = 16; |
| 496 link1_text.name = L"blue"; | 514 link1_text.SetName(link1_text_name); |
| 497 link1.role = AccessibilityNodeData::ROLE_LINK; | 515 link1.role = AccessibilityNodeData::ROLE_LINK; |
| 498 link1_text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 516 link1_text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 499 link1.state = 1 << AccessibilityNodeData::STATE_READONLY; | 517 link1.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 500 link1_text.state = 1 << AccessibilityNodeData::STATE_READONLY; | 518 link1_text.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 501 link1.child_ids.push_back(16); | 519 link1.child_ids.push_back(16); |
| 502 | 520 |
| 503 AccessibilityNodeData root; | 521 AccessibilityNodeData root; |
| 504 root.id = 1; | 522 root.id = 1; |
| 505 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 523 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 506 root.state = 1 << AccessibilityNodeData::STATE_READONLY; | 524 root.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 520 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances()); | 538 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances()); |
| 521 | 539 |
| 522 BrowserAccessibilityWin* root_obj = | 540 BrowserAccessibilityWin* root_obj = |
| 523 manager->GetRoot()->ToBrowserAccessibilityWin(); | 541 manager->GetRoot()->ToBrowserAccessibilityWin(); |
| 524 | 542 |
| 525 long text_len; | 543 long text_len; |
| 526 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); | 544 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
| 527 | 545 |
| 528 base::win::ScopedBstr text; | 546 base::win::ScopedBstr text; |
| 529 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); | 547 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); |
| 530 const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter; | 548 const std::string embed = base::UTF16ToUTF8( |
| 531 EXPECT_EQ(text1.name + embed + text2.name + embed, string16(text)); | 549 BrowserAccessibilityWin::kEmbeddedCharacter); |
| 550 EXPECT_EQ(text1_name + embed + text2_name + embed, |
| 551 UTF16ToUTF8(string16(text))); |
| 532 text.Reset(); | 552 text.Reset(); |
| 533 | 553 |
| 534 long hyperlink_count; | 554 long hyperlink_count; |
| 535 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); | 555 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
| 536 EXPECT_EQ(2, hyperlink_count); | 556 EXPECT_EQ(2, hyperlink_count); |
| 537 | 557 |
| 538 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; | 558 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
| 539 base::win::ScopedComPtr<IAccessibleText> hypertext; | 559 base::win::ScopedComPtr<IAccessibleText> hypertext; |
| 540 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); | 560 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
| 541 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive())); | 561 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive())); |
| 542 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); | 562 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
| 543 | 563 |
| 544 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive())); | 564 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive())); |
| 545 EXPECT_EQ(S_OK, | 565 EXPECT_EQ(S_OK, |
| 546 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); | 566 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); |
| 547 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, text.Receive())); | 567 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, text.Receive())); |
| 548 EXPECT_STREQ(L"red", text); | 568 EXPECT_STREQ(button1_text_name.c_str(), |
| 569 base::UTF16ToUTF8(string16(text)).c_str()); |
| 549 text.Reset(); | 570 text.Reset(); |
| 550 hyperlink.Release(); | 571 hyperlink.Release(); |
| 551 hypertext.Release(); | 572 hypertext.Release(); |
| 552 | 573 |
| 553 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive())); | 574 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive())); |
| 554 EXPECT_EQ(S_OK, | 575 EXPECT_EQ(S_OK, |
| 555 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); | 576 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); |
| 556 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, text.Receive())); | 577 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, text.Receive())); |
| 557 EXPECT_STREQ(L"blue", text); | 578 EXPECT_STREQ(link1_text_name.c_str(), |
| 579 base::UTF16ToUTF8(string16(text)).c_str()); |
| 558 text.Reset(); | 580 text.Reset(); |
| 559 hyperlink.Release(); | 581 hyperlink.Release(); |
| 560 hypertext.Release(); | 582 hypertext.Release(); |
| 561 | 583 |
| 562 long hyperlink_index; | 584 long hyperlink_index; |
| 563 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); | 585 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
| 564 EXPECT_EQ(-1, hyperlink_index); | 586 EXPECT_EQ(-1, hyperlink_index); |
| 565 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); | 587 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
| 566 EXPECT_EQ(-1, hyperlink_index); | 588 EXPECT_EQ(-1, hyperlink_index); |
| 567 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); | 589 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 // And the new child exists. | 673 // And the new child exists. |
| 652 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, acc2_2->role()); | 674 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, acc2_2->role()); |
| 653 EXPECT_EQ(3, acc2_2->renderer_id()); | 675 EXPECT_EQ(3, acc2_2->renderer_id()); |
| 654 | 676 |
| 655 // Ensure we properly cleaned up. | 677 // Ensure we properly cleaned up. |
| 656 manager.reset(); | 678 manager.reset(); |
| 657 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 679 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 658 } | 680 } |
| 659 | 681 |
| 660 } // namespace content | 682 } // namespace content |
| OLD | NEW |