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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 399 |
400 // Test some cases where the viewport is a single point - which can be | 400 // Test some cases where the viewport is a single point - which can be |
401 // used to force an object to be scrolled to a specific location. | 401 // used to force an object to be scrolled to a specific location. |
402 EXPECT_EQ(50, SCROLL(0, 125, 175, 125, 175, 75, 75)); | 402 EXPECT_EQ(50, SCROLL(0, 125, 175, 125, 175, 75, 75)); |
403 EXPECT_EQ(25, SCROLL(0, 125, 175, 125, 175, 100, 100)); | 403 EXPECT_EQ(25, SCROLL(0, 125, 175, 125, 175, 100, 100)); |
404 EXPECT_EQ(0, SCROLL(0, 125, 175, 125, 175, 125, 125)); | 404 EXPECT_EQ(0, SCROLL(0, 125, 175, 125, 175, 125, 125)); |
405 | 405 |
406 #undef SCROLL | 406 #undef SCROLL |
407 } | 407 } |
408 | 408 |
| 409 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { |
| 410 WebAccessibility text1; |
| 411 text1.id = 11; |
| 412 text1.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 413 text1.state = 0; |
| 414 text1.name = L"One two three."; |
| 415 |
| 416 WebAccessibility text2; |
| 417 text2.id = 12; |
| 418 text2.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 419 text2.state = 0; |
| 420 text2.name = L" Four five six."; |
| 421 |
| 422 WebAccessibility root; |
| 423 root.id = 1; |
| 424 root.role = WebAccessibility::ROLE_DOCUMENT; |
| 425 root.state = 0; |
| 426 root.children.push_back(text1); |
| 427 root.children.push_back(text2); |
| 428 |
| 429 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 430 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( |
| 431 GetDesktopWindow(), root, NULL, |
| 432 new CountedBrowserAccessibilityFactory()); |
| 433 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); |
| 434 |
| 435 BrowserAccessibilityWin* root_obj = |
| 436 manager->GetRoot()->toBrowserAccessibilityWin(); |
| 437 |
| 438 BSTR text; |
| 439 |
| 440 long text_len; |
| 441 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
| 442 |
| 443 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text)); |
| 444 EXPECT_EQ(text, text1.name + text2.name); |
| 445 SysFreeString(text); |
| 446 |
| 447 long hyperlink_count; |
| 448 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
| 449 EXPECT_EQ(0, hyperlink_count); |
| 450 |
| 451 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
| 452 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
| 453 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive())); |
| 454 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
| 455 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive())); |
| 456 |
| 457 long hyperlink_index; |
| 458 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
| 459 EXPECT_EQ(-1, hyperlink_index); |
| 460 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
| 461 EXPECT_EQ(-1, hyperlink_index); |
| 462 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); |
| 463 EXPECT_EQ(-1, hyperlink_index); |
| 464 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); |
| 465 EXPECT_EQ(-1, hyperlink_index); |
| 466 |
| 467 // Delete the manager and test that all BrowserAccessibility instances are |
| 468 // deleted. |
| 469 delete manager; |
| 470 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
| 471 } |
| 472 |
| 473 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { |
| 474 WebAccessibility text1; |
| 475 text1.id = 11; |
| 476 text1.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 477 text1.state = 0; |
| 478 text1.name = L"One two three."; |
| 479 |
| 480 WebAccessibility text2; |
| 481 text2.id = 12; |
| 482 text2.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 483 text2.state = 0; |
| 484 text2.name = L" Four five six."; |
| 485 |
| 486 WebAccessibility button1, button1_text; |
| 487 button1.id = 13; |
| 488 button1_text.id = 15; |
| 489 button1_text.name = L"red"; |
| 490 button1.role = WebAccessibility::ROLE_BUTTON; |
| 491 button1_text.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 492 button1.state = 0; |
| 493 button1.children.push_back(button1_text); |
| 494 |
| 495 WebAccessibility link1, link1_text; |
| 496 link1.id = 14; |
| 497 link1_text.id = 16; |
| 498 link1_text.name = L"blue"; |
| 499 link1.role = WebAccessibility::ROLE_LINK; |
| 500 link1_text.role = WebAccessibility::ROLE_STATIC_TEXT; |
| 501 link1.state = 0; |
| 502 link1.children.push_back(link1_text); |
| 503 |
| 504 WebAccessibility root; |
| 505 root.id = 1; |
| 506 root.role = WebAccessibility::ROLE_DOCUMENT; |
| 507 root.state = 0; |
| 508 root.children.push_back(text1); |
| 509 root.children.push_back(button1); |
| 510 root.children.push_back(text2); |
| 511 root.children.push_back(link1); |
| 512 |
| 513 CountedBrowserAccessibility::global_obj_count_ = 0; |
| 514 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( |
| 515 GetDesktopWindow(), root, NULL, |
| 516 new CountedBrowserAccessibilityFactory()); |
| 517 ASSERT_EQ(7, CountedBrowserAccessibility::global_obj_count_); |
| 518 |
| 519 BrowserAccessibilityWin* root_obj = |
| 520 manager->GetRoot()->toBrowserAccessibilityWin(); |
| 521 |
| 522 BSTR text; |
| 523 |
| 524 long text_len; |
| 525 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); |
| 526 |
| 527 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text)); |
| 528 const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter; |
| 529 EXPECT_EQ(text, text1.name + embed + text2.name + embed); |
| 530 SysFreeString(text); |
| 531 |
| 532 long hyperlink_count; |
| 533 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); |
| 534 EXPECT_EQ(2, hyperlink_count); |
| 535 |
| 536 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; |
| 537 base::win::ScopedComPtr<IAccessibleText> hypertext; |
| 538 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive())); |
| 539 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive())); |
| 540 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive())); |
| 541 |
| 542 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive())); |
| 543 EXPECT_EQ(S_OK, |
| 544 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); |
| 545 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, &text)); |
| 546 EXPECT_EQ(text, string16(L"red")); |
| 547 SysFreeString(text); |
| 548 hyperlink.Release(); |
| 549 hypertext.Release(); |
| 550 |
| 551 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive())); |
| 552 EXPECT_EQ(S_OK, |
| 553 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); |
| 554 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, &text)); |
| 555 EXPECT_EQ(text, string16(L"blue")); |
| 556 SysFreeString(text); |
| 557 hyperlink.Release(); |
| 558 hypertext.Release(); |
| 559 |
| 560 long hyperlink_index; |
| 561 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); |
| 562 EXPECT_EQ(-1, hyperlink_index); |
| 563 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); |
| 564 EXPECT_EQ(-1, hyperlink_index); |
| 565 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); |
| 566 EXPECT_EQ(0, hyperlink_index); |
| 567 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index)); |
| 568 EXPECT_EQ(1, hyperlink_index); |
| 569 |
| 570 // Delete the manager and test that all BrowserAccessibility instances are |
| 571 // deleted. |
| 572 delete manager; |
| 573 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
| 574 } |
OLD | NEW |