diff options
author | ctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-06 23:58:42 +0000 |
---|---|---|
committer | ctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-06 23:58:42 +0000 |
commit | 54b254841cd7c8054821f7e43f14b1847f9d0b7d (patch) | |
tree | df5a1d503167d238696ad327fb4caa90dcacbd20 /chrome/browser/accessibility/browser_accessibility_win_unittest.cc | |
parent | b03a138eb0c4d308dc0ac31e252debba26da17cf (diff) | |
download | chromium_src-54b254841cd7c8054821f7e43f14b1847f9d0b7d.zip chromium_src-54b254841cd7c8054821f7e43f14b1847f9d0b7d.tar.gz chromium_src-54b254841cd7c8054821f7e43f14b1847f9d0b7d.tar.bz2 |
Make BrowserAccessibilityManager cross platform. Step 2.
1. Move common logic and fields from BrowserAccessibilityMangerWin to BrowserAccessibilityManager.
2. Move common logic and fields from BrowserAccessibilityWin to BrowserAccessibility.
BUG=55264
TEST=interactive_ui_tests:AccessibilityWinBrowserTest.*
TEST=unit_tests:BrowserAccessibilityTest.*
Review URL: http://codereview.chromium.org/3551015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/accessibility/browser_accessibility_win_unittest.cc')
-rw-r--r-- | chrome/browser/accessibility/browser_accessibility_win_unittest.cc | 96 |
1 files changed, 53 insertions, 43 deletions
diff --git a/chrome/browser/accessibility/browser_accessibility_win_unittest.cc b/chrome/browser/accessibility/browser_accessibility_win_unittest.cc index abcb388..549700a 100644 --- a/chrome/browser/accessibility/browser_accessibility_win_unittest.cc +++ b/chrome/browser/accessibility/browser_accessibility_win_unittest.cc @@ -4,34 +4,35 @@ #include "base/scoped_ptr.h" #include "base/scoped_comptr_win.h" -#include "chrome/browser/accessibility/browser_accessibility_manager_win.h" +#include "chrome/browser/accessibility/browser_accessibility_manager.h" #include "chrome/browser/accessibility/browser_accessibility_win.h" #include "chrome/common/render_messages_params.h" #include "testing/gtest/include/gtest/gtest.h" using webkit_glue::WebAccessibility; -// Subclass of BrowserAccessibility that counts the number of instances. -class CountedBrowserAccessibilityWin : public BrowserAccessibilityWin { +// Subclass of BrowserAccessibilityWin that counts the number of instances. +class CountedBrowserAccessibility : public BrowserAccessibilityWin { public: - CountedBrowserAccessibilityWin() { global_obj_count_++; } - virtual ~CountedBrowserAccessibilityWin() { global_obj_count_--; } + CountedBrowserAccessibility() { global_obj_count_++; } + virtual ~CountedBrowserAccessibility() { global_obj_count_--; } static int global_obj_count_; }; -int CountedBrowserAccessibilityWin::global_obj_count_ = 0; +int CountedBrowserAccessibility::global_obj_count_ = 0; -// Factory that creates a CountedBrowserAccessibilityWin. -class CountedBrowserAccessibilityWinFactory - : public BrowserAccessibilityWinFactory { +// Factory that creates a CountedBrowserAccessibility. +class CountedBrowserAccessibilityFactory + : public BrowserAccessibilityFactory { public: - virtual ~CountedBrowserAccessibilityWinFactory() {} - virtual BrowserAccessibilityWin* Create() { - CComObject<CountedBrowserAccessibilityWin>* instance; - HRESULT hr = CComObject<CountedBrowserAccessibilityWin>::CreateInstance( + virtual ~CountedBrowserAccessibilityFactory() {} + virtual BrowserAccessibility* Create() { + CComObject<CountedBrowserAccessibility>* instance; + HRESULT hr = CComObject<CountedBrowserAccessibility>::CreateInstance( &instance); DCHECK(SUCCEEDED(hr)); - return instance->NewReference(); + instance->AddRef(); + return instance; } }; @@ -90,25 +91,30 @@ TEST_F(BrowserAccessibilityTest, TestNoLeaks) { // and a factory for an instance-counting BrowserAccessibility, and ensure // that exactly 3 instances were created. Note that the manager takes // ownership of the factory. - CountedBrowserAccessibilityWin::global_obj_count_ = 0; - // TODO: Use BrowserAccessibilityManager::Create instead of new below. + CountedBrowserAccessibility::global_obj_count_ = 0; BrowserAccessibilityManager* manager = - new BrowserAccessibilityManagerWin( - GetDesktopWindow(), root, NULL, - new CountedBrowserAccessibilityWinFactory()); - ASSERT_EQ(3, CountedBrowserAccessibilityWin::global_obj_count_); + BrowserAccessibilityManager::Create( + GetDesktopWindow(), + root, + NULL, + new CountedBrowserAccessibilityFactory()); + ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); // Delete the manager and test that all 3 instances are deleted. delete manager; - ASSERT_EQ(0, CountedBrowserAccessibilityWin::global_obj_count_); + ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); // Construct a manager again, and this time use the IAccessible interface // to get new references to two of the three nodes in the tree. - manager = new BrowserAccessibilityManagerWin( - GetDesktopWindow(), root, NULL, - new CountedBrowserAccessibilityWinFactory()); - ASSERT_EQ(3, CountedBrowserAccessibilityWin::global_obj_count_); - IAccessible* root_accessible = manager->GetRootAccessible(); + manager = + BrowserAccessibilityManager::Create( + GetDesktopWindow(), + root, + NULL, + new CountedBrowserAccessibilityFactory()); + ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); + IAccessible* root_accessible = + manager->GetRoot()->toBrowserAccessibilityWin(); IDispatch* root_iaccessible = NULL; IDispatch* child1_iaccessible = NULL; VARIANT var_child; @@ -123,14 +129,14 @@ TEST_F(BrowserAccessibilityTest, TestNoLeaks) { // Now delete the manager, and only one of the three nodes in the tree // should be released. delete manager; - ASSERT_EQ(2, CountedBrowserAccessibilityWin::global_obj_count_); + ASSERT_EQ(2, CountedBrowserAccessibility::global_obj_count_); // Release each of our references and make sure that each one results in // the instance being deleted as its reference count hits zero. root_iaccessible->Release(); - ASSERT_EQ(1, CountedBrowserAccessibilityWin::global_obj_count_); + ASSERT_EQ(1, CountedBrowserAccessibility::global_obj_count_); child1_iaccessible->Release(); - ASSERT_EQ(0, CountedBrowserAccessibilityWin::global_obj_count_); + ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); } TEST_F(BrowserAccessibilityTest, TestChildrenChange) { @@ -152,16 +158,18 @@ TEST_F(BrowserAccessibilityTest, TestChildrenChange) { // Construct a BrowserAccessibilityManager with this WebAccessibility tree // and a factory for an instance-counting BrowserAccessibility. - CountedBrowserAccessibilityWin::global_obj_count_ = 0; + CountedBrowserAccessibility::global_obj_count_ = 0; BrowserAccessibilityManager* manager = - new BrowserAccessibilityManagerWin( - GetDesktopWindow(), root, NULL, - new CountedBrowserAccessibilityWinFactory()); + BrowserAccessibilityManager::Create( + GetDesktopWindow(), + root, + NULL, + new CountedBrowserAccessibilityFactory()); // Query for the text IAccessible and verify that it returns "old text" as its // value. ScopedComPtr<IDispatch> text_dispatch; - HRESULT hr = manager->GetRootAccessible()->get_accChild( + HRESULT hr = manager->GetRoot()->toBrowserAccessibilityWin()->get_accChild( CreateI4Variant(1), text_dispatch.Receive()); ASSERT_EQ(S_OK, hr); @@ -190,7 +198,7 @@ TEST_F(BrowserAccessibilityTest, TestChildrenChange) { // Query for the text IAccessible and verify that it now returns "new text" // as its value. - hr = manager->GetRootAccessible()->get_accChild( + hr = manager->GetRoot()->toBrowserAccessibilityWin()->get_accChild( CreateI4Variant(1), text_dispatch.Receive()); ASSERT_EQ(S_OK, hr); @@ -208,7 +216,7 @@ TEST_F(BrowserAccessibilityTest, TestChildrenChange) { // Delete the manager and test that all BrowserAccessibility instances are // deleted. delete manager; - ASSERT_EQ(0, CountedBrowserAccessibilityWin::global_obj_count_); + ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); } TEST_F(BrowserAccessibilityTest, TestChildrenChangeNoLeaks) { @@ -239,12 +247,14 @@ TEST_F(BrowserAccessibilityTest, TestChildrenChangeNoLeaks) { // and a factory for an instance-counting BrowserAccessibility and ensure // that exactly 4 instances were created. Note that the manager takes // ownership of the factory. - CountedBrowserAccessibilityWin::global_obj_count_ = 0; + CountedBrowserAccessibility::global_obj_count_ = 0; BrowserAccessibilityManager* manager = - new BrowserAccessibilityManagerWin( - GetDesktopWindow(), root, NULL, - new CountedBrowserAccessibilityWinFactory()); - ASSERT_EQ(4, CountedBrowserAccessibilityWin::global_obj_count_); + BrowserAccessibilityManager::Create( + GetDesktopWindow(), + root, + NULL, + new CountedBrowserAccessibilityFactory()); + ASSERT_EQ(4, CountedBrowserAccessibility::global_obj_count_); // Notify the BrowserAccessibilityManager that the div node and its children // were removed and ensure that only one BrowserAccessibility instance exists. @@ -257,10 +267,10 @@ TEST_F(BrowserAccessibilityTest, TestChildrenChangeNoLeaks) { std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications; notifications.push_back(param); manager->OnAccessibilityNotifications(notifications); - ASSERT_EQ(1, CountedBrowserAccessibilityWin::global_obj_count_); + ASSERT_EQ(1, CountedBrowserAccessibility::global_obj_count_); // Delete the manager and test that all BrowserAccessibility instances are // deleted. delete manager; - ASSERT_EQ(0, CountedBrowserAccessibilityWin::global_obj_count_); + ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); } |