OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/win/scoped_comptr.h" | 6 #include "base/win/scoped_comptr.h" |
7 #include "content/browser/accessibility/browser_accessibility_manager.h" | 7 #include "content/browser/accessibility/browser_accessibility_manager.h" |
8 #include "content/browser/accessibility/browser_accessibility_win.h" | 8 #include "content/browser/accessibility/browser_accessibility_win.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 361 |
362 ASSERT_EQ(S_OK, text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, &text)); | 362 ASSERT_EQ(S_OK, text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, &text)); |
363 ASSERT_EQ(text, string16(L"One two three.\nFour five six.")); | 363 ASSERT_EQ(text, string16(L"One two three.\nFour five six.")); |
364 SysFreeString(text); | 364 SysFreeString(text); |
365 | 365 |
366 // Delete the manager and test that all BrowserAccessibility instances are | 366 // Delete the manager and test that all BrowserAccessibility instances are |
367 // deleted. | 367 // deleted. |
368 delete manager; | 368 delete manager; |
369 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 369 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
370 } | 370 } |
| 371 |
| 372 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { |
| 373 WebAccessibility text1; |
| 374 text1.id = 11; |
| 375 text1.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 376 text1.state = 0; |
| 377 text1.name = L"One two three."; |
| 378 |
| 379 WebAccessibility text2; |
| 380 text2.id = 12; |
| 381 text2.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 382 text2.state = 0; |
| 383 text2.name = L" Four five six."; |
| 384 |
| 385 WebAccessibility root; |
| 386 root.id = 1; |
| 387 root.role = WebAccessibility::ROLE_DOCUMENT; |
| 388 root.state = 0; |
| 389 root.children.push_back(text1); |
| 390 root.children.push_back(text2); |
| 391 |
| 392 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 393 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( |
| 394 GetDesktopWindow(), root, NULL, |
| 395 new CountedBrowserAccessibilityFactory()); |
| 396 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); |
| 397 |
| 398 BrowserAccessibilityWin* root_obj = |
| 399 manager->GetRoot()->toBrowserAccessibilityWin(); |
| 400 |
| 401 BSTR text; |
| 402 |
| 403 long text_len; |
| 404 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
| 405 |
| 406 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text)); |
| 407 EXPECT_EQ(text, text1.name + text2.name); |
| 408 SysFreeString(text); |
| 409 |
| 410 long hyperlink_count; |
| 411 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
| 412 EXPECT_EQ(0, hyperlink_count); |
| 413 |
| 414 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
| 415 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
| 416 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive())); |
| 417 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
| 418 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive())); |
| 419 |
| 420 long hyperlink_index; |
| 421 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
| 422 EXPECT_EQ(-1, hyperlink_index); |
| 423 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
| 424 EXPECT_EQ(-1, hyperlink_index); |
| 425 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); |
| 426 EXPECT_EQ(-1, hyperlink_index); |
| 427 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); |
| 428 EXPECT_EQ(-1, hyperlink_index); |
| 429 |
| 430 // Delete the manager and test that all BrowserAccessibility instances are |
| 431 // deleted. |
| 432 delete manager; |
| 433 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
| 434 } |
| 435 |
| 436 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { |
| 437 WebAccessibility text1; |
| 438 text1.id = 11; |
| 439 text1.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 440 text1.state = 0; |
| 441 text1.name = L"One two three."; |
| 442 |
| 443 WebAccessibility text2; |
| 444 text2.id = 12; |
| 445 text2.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 446 text2.state = 0; |
| 447 text2.name = L" Four five six."; |
| 448 |
| 449 WebAccessibility button1, button1_text; |
| 450 button1.id = 13; |
| 451 button1_text.id = 15; |
| 452 button1_text.name = L"red"; |
| 453 button1.role = WebAccessibility::ROLE_BUTTON; |
| 454 button1_text.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 455 button1.state = 0; |
| 456 button1.children.push_back(button1_text); |
| 457 |
| 458 WebAccessibility link1, link1_text; |
| 459 link1.id = 14; |
| 460 link1_text.id = 16; |
| 461 link1_text.name = L"blue"; |
| 462 link1.role = WebAccessibility::ROLE_LINK; |
| 463 link1_text.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 464 link1.state = 0; |
| 465 link1.children.push_back(link1_text); |
| 466 |
| 467 WebAccessibility root; |
| 468 root.id = 1; |
| 469 root.role = WebAccessibility::ROLE_DOCUMENT; |
| 470 root.state = 0; |
| 471 root.children.push_back(text1); |
| 472 root.children.push_back(button1); |
| 473 root.children.push_back(text2); |
| 474 root.children.push_back(link1); |
| 475 |
| 476 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 477 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( |
| 478 GetDesktopWindow(), root, NULL, |
| 479 new CountedBrowserAccessibilityFactory()); |
| 480 ASSERT_EQ(7, CountedBrowserAccessibility::global_obj_count_); |
| 481 |
| 482 BrowserAccessibilityWin* root_obj = |
| 483 manager->GetRoot()->toBrowserAccessibilityWin(); |
| 484 |
| 485 BSTR text; |
| 486 |
| 487 long text_len; |
| 488 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
| 489 |
| 490 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text)); |
| 491 const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter; |
| 492 EXPECT_EQ(text, text1.name + embed + text2.name + embed); |
| 493 SysFreeString(text); |
| 494 |
| 495 long hyperlink_count; |
| 496 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
| 497 EXPECT_EQ(2, hyperlink_count); |
| 498 |
| 499 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
| 500 base::win::ScopedComPtr<IAccessibleText> hypertext; |
| 501 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
| 502 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive())); |
| 503 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
| 504 |
| 505 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive())); |
| 506 EXPECT_EQ(S_OK, |
| 507 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); |
| 508 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, &text)); |
| 509 EXPECT_EQ(text, string16(L"red")); |
| 510 SysFreeString(text); |
| 511 hyperlink.Release(); |
| 512 hypertext.Release(); |
| 513 |
| 514 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive())); |
| 515 EXPECT_EQ(S_OK, |
| 516 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); |
| 517 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, &text)); |
| 518 EXPECT_EQ(text, string16(L"blue")); |
| 519 SysFreeString(text); |
| 520 hyperlink.Release(); |
| 521 hypertext.Release(); |
| 522 |
| 523 long hyperlink_index; |
| 524 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
| 525 EXPECT_EQ(-1, hyperlink_index); |
| 526 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
| 527 EXPECT_EQ(-1, hyperlink_index); |
| 528 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); |
| 529 EXPECT_EQ(0, hyperlink_index); |
| 530 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index)); |
| 531 EXPECT_EQ(1, hyperlink_index); |
| 532 |
| 533 // Delete the manager and test that all BrowserAccessibility instances are |
| 534 // deleted. |
| 535 delete manager; |
| 536 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
| 537 } |
OLD | NEW |