| 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 text.SetName("new text"); |
| 229 AccessibilityHostMsg_NotificationParams param; | 230 AccessibilityHostMsg_NotificationParams param; |
| 230 param.notification_type = AccessibilityNotificationChildrenChanged; | 231 param.notification_type = AccessibilityNotificationChildrenChanged; |
| 231 param.nodes.push_back(text); | 232 param.nodes.push_back(text); |
| 232 param.id = text.id; | 233 param.id = text.id; |
| 233 std::vector<AccessibilityHostMsg_NotificationParams> notifications; | 234 std::vector<AccessibilityHostMsg_NotificationParams> notifications; |
| 234 notifications.push_back(param); | 235 notifications.push_back(param); |
| 235 manager->OnAccessibilityNotifications(notifications); | 236 manager->OnAccessibilityNotifications(notifications); |
| 236 | 237 |
| 237 // Query for the text IAccessible and verify that it now returns "new text" | 238 // Query for the text IAccessible and verify that it now returns "new text" |
| 238 // as its value. | 239 // as its value. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 manager->OnAccessibilityNotifications(notifications); | 308 manager->OnAccessibilityNotifications(notifications); |
| 308 ASSERT_EQ(1, CountedBrowserAccessibility::num_instances()); | 309 ASSERT_EQ(1, CountedBrowserAccessibility::num_instances()); |
| 309 | 310 |
| 310 // Delete the manager and test that all BrowserAccessibility instances are | 311 // Delete the manager and test that all BrowserAccessibility instances are |
| 311 // deleted. | 312 // deleted. |
| 312 manager.reset(); | 313 manager.reset(); |
| 313 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 314 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 314 } | 315 } |
| 315 | 316 |
| 316 TEST_F(BrowserAccessibilityTest, TestTextBoundaries) { | 317 TEST_F(BrowserAccessibilityTest, TestTextBoundaries) { |
| 318 std::string text1_value = "One two three.\nFour five six."; |
| 319 |
| 317 AccessibilityNodeData text1; | 320 AccessibilityNodeData text1; |
| 318 text1.id = 11; | 321 text1.id = 11; |
| 319 text1.role = AccessibilityNodeData::ROLE_TEXT_FIELD; | 322 text1.role = AccessibilityNodeData::ROLE_TEXT_FIELD; |
| 320 text1.state = 0; | 323 text1.state = 0; |
| 321 text1.value = L"One two three.\nFour five six."; | 324 text1.AddStringAttribute(AccessibilityNodeData::ATTR_VALUE, text1_value); |
| 322 text1.line_breaks.push_back(15); | 325 std::vector<int32> line_breaks; |
| 326 line_breaks.push_back(15); |
| 327 text1.AddIntListAttribute( |
| 328 AccessibilityNodeData::ATTR_LINE_BREAKS, line_breaks); |
| 323 | 329 |
| 324 AccessibilityNodeData root; | 330 AccessibilityNodeData root; |
| 325 root.id = 1; | 331 root.id = 1; |
| 326 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 332 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 327 root.state = 0; | 333 root.state = 0; |
| 328 root.child_ids.push_back(11); | 334 root.child_ids.push_back(11); |
| 329 | 335 |
| 330 CountedBrowserAccessibility::reset(); | 336 CountedBrowserAccessibility::reset(); |
| 331 scoped_ptr<BrowserAccessibilityManager> manager( | 337 scoped_ptr<BrowserAccessibilityManager> manager( |
| 332 BrowserAccessibilityManager::Create( | 338 BrowserAccessibilityManager::Create( |
| 333 root, NULL, new CountedBrowserAccessibilityFactory())); | 339 root, NULL, new CountedBrowserAccessibilityFactory())); |
| 334 manager->UpdateNodesForTesting(text1); | 340 manager->UpdateNodesForTesting(text1); |
| 335 ASSERT_EQ(2, CountedBrowserAccessibility::num_instances()); | 341 ASSERT_EQ(2, CountedBrowserAccessibility::num_instances()); |
| 336 | 342 |
| 337 BrowserAccessibilityWin* root_obj = | 343 BrowserAccessibilityWin* root_obj = |
| 338 manager->GetRoot()->ToBrowserAccessibilityWin(); | 344 manager->GetRoot()->ToBrowserAccessibilityWin(); |
| 339 BrowserAccessibilityWin* text1_obj = | 345 BrowserAccessibilityWin* text1_obj = |
| 340 root_obj->GetChild(0)->ToBrowserAccessibilityWin(); | 346 root_obj->GetChild(0)->ToBrowserAccessibilityWin(); |
| 341 | 347 |
| 342 long text1_len; | 348 long text1_len; |
| 343 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len)); | 349 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len)); |
| 344 | 350 |
| 345 base::win::ScopedBstr text; | 351 base::win::ScopedBstr text; |
| 346 ASSERT_EQ(S_OK, text1_obj->get_text(0, text1_len, text.Receive())); | 352 ASSERT_EQ(S_OK, text1_obj->get_text(0, text1_len, text.Receive())); |
| 347 ASSERT_EQ(text1.value, string16(text)); | 353 ASSERT_EQ(text1_value, base::UTF16ToUTF8(string16(text))); |
| 348 text.Reset(); | 354 text.Reset(); |
| 349 | 355 |
| 350 ASSERT_EQ(S_OK, text1_obj->get_text(0, 4, text.Receive())); | 356 ASSERT_EQ(S_OK, text1_obj->get_text(0, 4, text.Receive())); |
| 351 ASSERT_STREQ(L"One ", text); | 357 ASSERT_STREQ(L"One ", text); |
| 352 text.Reset(); | 358 text.Reset(); |
| 353 | 359 |
| 354 long start; | 360 long start; |
| 355 long end; | 361 long end; |
| 356 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( | 362 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( |
| 357 1, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive())); | 363 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())); | 404 text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, text.Receive())); |
| 399 ASSERT_STREQ(L"One two three.\nFour five six.", text); | 405 ASSERT_STREQ(L"One two three.\nFour five six.", text); |
| 400 | 406 |
| 401 // Delete the manager and test that all BrowserAccessibility instances are | 407 // Delete the manager and test that all BrowserAccessibility instances are |
| 402 // deleted. | 408 // deleted. |
| 403 manager.reset(); | 409 manager.reset(); |
| 404 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 410 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 405 } | 411 } |
| 406 | 412 |
| 407 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { | 413 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { |
| 414 const std::string text1_name = "One two three."; |
| 415 const std::string text2_name = " Four five six."; |
| 416 |
| 408 AccessibilityNodeData text1; | 417 AccessibilityNodeData text1; |
| 409 text1.id = 11; | 418 text1.id = 11; |
| 410 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 419 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 411 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; | 420 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 412 text1.name = L"One two three."; | 421 text1.SetName(text1_name); |
| 413 | 422 |
| 414 AccessibilityNodeData text2; | 423 AccessibilityNodeData text2; |
| 415 text2.id = 12; | 424 text2.id = 12; |
| 416 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 425 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 417 text2.state = 1 << AccessibilityNodeData::STATE_READONLY; | 426 text2.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 418 text2.name = L" Four five six."; | 427 text2.SetName(text2_name); |
| 419 | 428 |
| 420 AccessibilityNodeData root; | 429 AccessibilityNodeData root; |
| 421 root.id = 1; | 430 root.id = 1; |
| 422 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 431 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 423 root.state = 1 << AccessibilityNodeData::STATE_READONLY; | 432 root.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 424 root.child_ids.push_back(11); | 433 root.child_ids.push_back(11); |
| 425 root.child_ids.push_back(12); | 434 root.child_ids.push_back(12); |
| 426 | 435 |
| 427 CountedBrowserAccessibility::reset(); | 436 CountedBrowserAccessibility::reset(); |
| 428 scoped_ptr<BrowserAccessibilityManager> manager( | 437 scoped_ptr<BrowserAccessibilityManager> manager( |
| 429 BrowserAccessibilityManager::Create( | 438 BrowserAccessibilityManager::Create( |
| 430 root, NULL, new CountedBrowserAccessibilityFactory())); | 439 root, NULL, new CountedBrowserAccessibilityFactory())); |
| 431 manager->UpdateNodesForTesting(root, text1, text2); | 440 manager->UpdateNodesForTesting(root, text1, text2); |
| 432 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); | 441 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); |
| 433 | 442 |
| 434 BrowserAccessibilityWin* root_obj = | 443 BrowserAccessibilityWin* root_obj = |
| 435 manager->GetRoot()->ToBrowserAccessibilityWin(); | 444 manager->GetRoot()->ToBrowserAccessibilityWin(); |
| 436 | 445 |
| 437 long text_len; | 446 long text_len; |
| 438 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); | 447 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
| 439 | 448 |
| 440 base::win::ScopedBstr text; | 449 base::win::ScopedBstr text; |
| 441 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); | 450 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); |
| 442 EXPECT_EQ(text1.name + text2.name, string16(text)); | 451 EXPECT_EQ(text1_name + text2_name, base::UTF16ToUTF8(string16(text))); |
| 443 | 452 |
| 444 long hyperlink_count; | 453 long hyperlink_count; |
| 445 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); | 454 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
| 446 EXPECT_EQ(0, hyperlink_count); | 455 EXPECT_EQ(0, hyperlink_count); |
| 447 | 456 |
| 448 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; | 457 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
| 449 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); | 458 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
| 450 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive())); | 459 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive())); |
| 451 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); | 460 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
| 452 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive())); | 461 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive())); |
| 453 | 462 |
| 454 long hyperlink_index; | 463 long hyperlink_index; |
| 455 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); | 464 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
| 456 EXPECT_EQ(-1, hyperlink_index); | 465 EXPECT_EQ(-1, hyperlink_index); |
| 457 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); | 466 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
| 458 EXPECT_EQ(-1, hyperlink_index); | 467 EXPECT_EQ(-1, hyperlink_index); |
| 459 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); | 468 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); |
| 460 EXPECT_EQ(-1, hyperlink_index); | 469 EXPECT_EQ(-1, hyperlink_index); |
| 461 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); | 470 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); |
| 462 EXPECT_EQ(-1, hyperlink_index); | 471 EXPECT_EQ(-1, hyperlink_index); |
| 463 | 472 |
| 464 // Delete the manager and test that all BrowserAccessibility instances are | 473 // Delete the manager and test that all BrowserAccessibility instances are |
| 465 // deleted. | 474 // deleted. |
| 466 manager.reset(); | 475 manager.reset(); |
| 467 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 476 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 468 } | 477 } |
| 469 | 478 |
| 470 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { | 479 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { |
| 480 const std::string text1_name = "One two three."; |
| 481 const std::string text2_name = " Four five six."; |
| 482 const std::string button1_text_name = "red"; |
| 483 const std::string link1_text_name = "blue"; |
| 484 |
| 471 AccessibilityNodeData text1; | 485 AccessibilityNodeData text1; |
| 472 text1.id = 11; | 486 text1.id = 11; |
| 473 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 487 text1.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 474 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; | 488 text1.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 475 text1.name = L"One two three."; | 489 text1.SetName(text1_name); |
| 476 | 490 |
| 477 AccessibilityNodeData text2; | 491 AccessibilityNodeData text2; |
| 478 text2.id = 12; | 492 text2.id = 12; |
| 479 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 493 text2.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 480 text2.state = 1 << AccessibilityNodeData::STATE_READONLY; | 494 text2.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 481 text2.name = L" Four five six."; | 495 text2.SetName(text2_name); |
| 482 | 496 |
| 483 AccessibilityNodeData button1, button1_text; | 497 AccessibilityNodeData button1, button1_text; |
| 484 button1.id = 13; | 498 button1.id = 13; |
| 485 button1_text.id = 15; | 499 button1_text.id = 15; |
| 486 button1_text.name = L"red"; | 500 button1_text.SetName(button1_text_name); |
| 487 button1.role = AccessibilityNodeData::ROLE_BUTTON; | 501 button1.role = AccessibilityNodeData::ROLE_BUTTON; |
| 488 button1_text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 502 button1_text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 489 button1.state = 1 << AccessibilityNodeData::STATE_READONLY; | 503 button1.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 490 button1_text.state = 1 << AccessibilityNodeData::STATE_READONLY; | 504 button1_text.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 491 button1.child_ids.push_back(15); | 505 button1.child_ids.push_back(15); |
| 492 | 506 |
| 493 AccessibilityNodeData link1, link1_text; | 507 AccessibilityNodeData link1, link1_text; |
| 494 link1.id = 14; | 508 link1.id = 14; |
| 495 link1_text.id = 16; | 509 link1_text.id = 16; |
| 496 link1_text.name = L"blue"; | 510 link1_text.SetName(link1_text_name); |
| 497 link1.role = AccessibilityNodeData::ROLE_LINK; | 511 link1.role = AccessibilityNodeData::ROLE_LINK; |
| 498 link1_text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; | 512 link1_text.role = AccessibilityNodeData::ROLE_STATIC_TEXT; |
| 499 link1.state = 1 << AccessibilityNodeData::STATE_READONLY; | 513 link1.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 500 link1_text.state = 1 << AccessibilityNodeData::STATE_READONLY; | 514 link1_text.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| 501 link1.child_ids.push_back(16); | 515 link1.child_ids.push_back(16); |
| 502 | 516 |
| 503 AccessibilityNodeData root; | 517 AccessibilityNodeData root; |
| 504 root.id = 1; | 518 root.id = 1; |
| 505 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; | 519 root.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 506 root.state = 1 << AccessibilityNodeData::STATE_READONLY; | 520 root.state = 1 << AccessibilityNodeData::STATE_READONLY; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 520 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances()); | 534 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances()); |
| 521 | 535 |
| 522 BrowserAccessibilityWin* root_obj = | 536 BrowserAccessibilityWin* root_obj = |
| 523 manager->GetRoot()->ToBrowserAccessibilityWin(); | 537 manager->GetRoot()->ToBrowserAccessibilityWin(); |
| 524 | 538 |
| 525 long text_len; | 539 long text_len; |
| 526 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); | 540 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
| 527 | 541 |
| 528 base::win::ScopedBstr text; | 542 base::win::ScopedBstr text; |
| 529 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); | 543 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); |
| 530 const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter; | 544 const std::string embed = base::UTF16ToUTF8( |
| 531 EXPECT_EQ(text1.name + embed + text2.name + embed, string16(text)); | 545 BrowserAccessibilityWin::kEmbeddedCharacter); |
| 546 EXPECT_EQ(text1_name + embed + text2_name + embed, |
| 547 UTF16ToUTF8(string16(text))); |
| 532 text.Reset(); | 548 text.Reset(); |
| 533 | 549 |
| 534 long hyperlink_count; | 550 long hyperlink_count; |
| 535 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); | 551 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
| 536 EXPECT_EQ(2, hyperlink_count); | 552 EXPECT_EQ(2, hyperlink_count); |
| 537 | 553 |
| 538 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; | 554 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
| 539 base::win::ScopedComPtr<IAccessibleText> hypertext; | 555 base::win::ScopedComPtr<IAccessibleText> hypertext; |
| 540 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); | 556 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
| 541 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive())); | 557 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive())); |
| 542 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); | 558 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
| 543 | 559 |
| 544 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive())); | 560 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive())); |
| 545 EXPECT_EQ(S_OK, | 561 EXPECT_EQ(S_OK, |
| 546 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); | 562 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); |
| 547 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, text.Receive())); | 563 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, text.Receive())); |
| 548 EXPECT_STREQ(L"red", text); | 564 EXPECT_STREQ(base::UTF8ToUTF16(button1_text_name), text); |
| 549 text.Reset(); | 565 text.Reset(); |
| 550 hyperlink.Release(); | 566 hyperlink.Release(); |
| 551 hypertext.Release(); | 567 hypertext.Release(); |
| 552 | 568 |
| 553 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive())); | 569 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive())); |
| 554 EXPECT_EQ(S_OK, | 570 EXPECT_EQ(S_OK, |
| 555 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); | 571 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); |
| 556 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, text.Receive())); | 572 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, text.Receive())); |
| 557 EXPECT_STREQ(L"blue", text); | 573 EXPECT_STREQ(base::UTF8ToUTF16(link1_text_name), text); |
| 558 text.Reset(); | 574 text.Reset(); |
| 559 hyperlink.Release(); | 575 hyperlink.Release(); |
| 560 hypertext.Release(); | 576 hypertext.Release(); |
| 561 | 577 |
| 562 long hyperlink_index; | 578 long hyperlink_index; |
| 563 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); | 579 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
| 564 EXPECT_EQ(-1, hyperlink_index); | 580 EXPECT_EQ(-1, hyperlink_index); |
| 565 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); | 581 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
| 566 EXPECT_EQ(-1, hyperlink_index); | 582 EXPECT_EQ(-1, hyperlink_index); |
| 567 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); | 583 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. | 667 // And the new child exists. |
| 652 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, acc2_2->role()); | 668 EXPECT_EQ(AccessibilityNodeData::ROLE_BUTTON, acc2_2->role()); |
| 653 EXPECT_EQ(3, acc2_2->renderer_id()); | 669 EXPECT_EQ(3, acc2_2->renderer_id()); |
| 654 | 670 |
| 655 // Ensure we properly cleaned up. | 671 // Ensure we properly cleaned up. |
| 656 manager.reset(); | 672 manager.reset(); |
| 657 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 673 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 658 } | 674 } |
| 659 | 675 |
| 660 } // namespace content | 676 } // namespace content |
| OLD | NEW |