Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/accessibility/browser_accessibility_win_unittest.cc

Issue 8775059: Relanding http://codereview.chromium.org/8416034 (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Windows mucking up line endings for Mac file. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/accessibility/browser_accessibility.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 358
359 ASSERT_EQ(S_OK, text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, &text)); 359 ASSERT_EQ(S_OK, text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, &text));
360 ASSERT_EQ(text, string16(L"One two three.\nFour five six.")); 360 ASSERT_EQ(text, string16(L"One two three.\nFour five six."));
361 SysFreeString(text); 361 SysFreeString(text);
362 362
363 // Delete the manager and test that all BrowserAccessibility instances are 363 // Delete the manager and test that all BrowserAccessibility instances are
364 // deleted. 364 // deleted.
365 delete manager; 365 delete manager;
366 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); 366 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
367 } 367 }
368
369 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) {
370 WebAccessibility text1;
371 text1.id = 11;
372 text1.role = WebAccessibility::ROLE_STATIC_TEXT;
373 text1.state = 0;
374 text1.name = L"One two three.";
375
376 WebAccessibility text2;
377 text2.id = 12;
378 text2.role = WebAccessibility::ROLE_STATIC_TEXT;
379 text2.state = 0;
380 text2.name = L" Four five six.";
381
382 WebAccessibility root;
383 root.id = 1;
384 root.role = WebAccessibility::ROLE_DOCUMENT;
385 root.state = 0;
386 root.children.push_back(text1);
387 root.children.push_back(text2);
388
389 CountedBrowserAccessibility::global_obj_count_ = 0;
390 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create(
391 GetDesktopWindow(), root, NULL,
392 new CountedBrowserAccessibilityFactory());
393 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_);
394
395 BrowserAccessibilityWin* root_obj =
396 manager->GetRoot()->toBrowserAccessibilityWin();
397
398 BSTR text;
399
400 long text_len;
401 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len));
402
403 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text));
404 EXPECT_EQ(text, text1.name + text2.name);
405 SysFreeString(text);
406
407 long hyperlink_count;
408 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count));
409 EXPECT_EQ(0, hyperlink_count);
410
411 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink;
412 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive()));
413 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(0, hyperlink.Receive()));
414 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive()));
415 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(29, hyperlink.Receive()));
416
417 long hyperlink_index;
418 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index));
419 EXPECT_EQ(-1, hyperlink_index);
420 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index));
421 EXPECT_EQ(-1, hyperlink_index);
422 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index));
423 EXPECT_EQ(-1, hyperlink_index);
424 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index));
425 EXPECT_EQ(-1, hyperlink_index);
426
427 // Delete the manager and test that all BrowserAccessibility instances are
428 // deleted.
429 delete manager;
430 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
431 }
432
433 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) {
434 WebAccessibility text1;
435 text1.id = 11;
436 text1.role = WebAccessibility::ROLE_STATIC_TEXT;
437 text1.state = 0;
438 text1.name = L"One two three.";
439
440 WebAccessibility text2;
441 text2.id = 12;
442 text2.role = WebAccessibility::ROLE_STATIC_TEXT;
443 text2.state = 0;
444 text2.name = L" Four five six.";
445
446 WebAccessibility button1, button1_text;
447 button1.id = 13;
448 button1_text.id = 15;
449 button1_text.name = L"red";
450 button1.role = WebAccessibility::ROLE_BUTTON;
451 button1_text.role = WebAccessibility::ROLE_STATIC_TEXT;
452 button1.state = 0;
453 button1.children.push_back(button1_text);
454
455 WebAccessibility link1, link1_text;
456 link1.id = 14;
457 link1_text.id = 16;
458 link1_text.name = L"blue";
459 link1.role = WebAccessibility::ROLE_LINK;
460 link1_text.role = WebAccessibility::ROLE_STATIC_TEXT;
461 link1.state = 0;
462 link1.children.push_back(link1_text);
463
464 WebAccessibility root;
465 root.id = 1;
466 root.role = WebAccessibility::ROLE_DOCUMENT;
467 root.state = 0;
468 root.children.push_back(text1);
469 root.children.push_back(button1);
470 root.children.push_back(text2);
471 root.children.push_back(link1);
472
473 CountedBrowserAccessibility::global_obj_count_ = 0;
474 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create(
475 GetDesktopWindow(), root, NULL,
476 new CountedBrowserAccessibilityFactory());
477 ASSERT_EQ(7, CountedBrowserAccessibility::global_obj_count_);
478
479 BrowserAccessibilityWin* root_obj =
480 manager->GetRoot()->toBrowserAccessibilityWin();
481
482 BSTR text;
483
484 long text_len;
485 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len));
486
487 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text));
488 const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter;
489 EXPECT_EQ(text, text1.name + embed + text2.name + embed);
490 SysFreeString(text);
491
492 long hyperlink_count;
493 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count));
494 EXPECT_EQ(2, hyperlink_count);
495
496 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink;
497 base::win::ScopedComPtr<IAccessibleText> hypertext;
498 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(-1, hyperlink.Receive()));
499 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(2, hyperlink.Receive()));
500 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlink(28, hyperlink.Receive()));
501
502 EXPECT_EQ(S_OK, root_obj->get_hyperlink(0, hyperlink.Receive()));
503 EXPECT_EQ(S_OK,
504 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive()));
505 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, &text));
506 EXPECT_EQ(text, string16(L"red"));
507 SysFreeString(text);
508 hyperlink.Release();
509 hypertext.Release();
510
511 EXPECT_EQ(S_OK, root_obj->get_hyperlink(1, hyperlink.Receive()));
512 EXPECT_EQ(S_OK,
513 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive()));
514 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, &text));
515 EXPECT_EQ(text, string16(L"blue"));
516 SysFreeString(text);
517 hyperlink.Release();
518 hypertext.Release();
519
520 long hyperlink_index;
521 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index));
522 EXPECT_EQ(-1, hyperlink_index);
523 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index));
524 EXPECT_EQ(-1, hyperlink_index);
525 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index));
526 EXPECT_EQ(0, hyperlink_index);
527 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index));
528 EXPECT_EQ(1, hyperlink_index);
529
530 // Delete the manager and test that all BrowserAccessibility instances are
531 // deleted.
532 delete manager;
533 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
534 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/accessibility/browser_accessibility.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698