summaryrefslogtreecommitdiffstats
path: root/chrome/browser/accessibility/browser_accessibility_win_unittest.cc
diff options
context:
space:
mode:
authorctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-07 00:52:54 +0000
committerctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-07 00:52:54 +0000
commitb798cd7259be41c0163ef34d6df19a9aa93e0dda (patch)
treebf3d98fd53609b85c5a861b80bf17cb198823c51 /chrome/browser/accessibility/browser_accessibility_win_unittest.cc
parent84e1472c2c3c19df36ca784c959c5310e2472ede (diff)
downloadchromium_src-b798cd7259be41c0163ef34d6df19a9aa93e0dda.zip
chromium_src-b798cd7259be41c0163ef34d6df19a9aa93e0dda.tar.gz
chromium_src-b798cd7259be41c0163ef34d6df19a9aa93e0dda.tar.bz2
Revert 61740 - 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. Linux errors. BUG=55264 TEST=interactive_ui_tests:AccessibilityWinBrowserTest.* TEST=unit_tests:BrowserAccessibilityTest.* Review URL: http://codereview.chromium.org/3551015 TBR=ctguil@chromium.org Review URL: http://codereview.chromium.org/3562011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61749 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.cc96
1 files changed, 43 insertions, 53 deletions
diff --git a/chrome/browser/accessibility/browser_accessibility_win_unittest.cc b/chrome/browser/accessibility/browser_accessibility_win_unittest.cc
index 549700a..abcb388 100644
--- a/chrome/browser/accessibility/browser_accessibility_win_unittest.cc
+++ b/chrome/browser/accessibility/browser_accessibility_win_unittest.cc
@@ -4,35 +4,34 @@
#include "base/scoped_ptr.h"
#include "base/scoped_comptr_win.h"
-#include "chrome/browser/accessibility/browser_accessibility_manager.h"
+#include "chrome/browser/accessibility/browser_accessibility_manager_win.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 BrowserAccessibilityWin that counts the number of instances.
-class CountedBrowserAccessibility : public BrowserAccessibilityWin {
+// Subclass of BrowserAccessibility that counts the number of instances.
+class CountedBrowserAccessibilityWin : public BrowserAccessibilityWin {
public:
- CountedBrowserAccessibility() { global_obj_count_++; }
- virtual ~CountedBrowserAccessibility() { global_obj_count_--; }
+ CountedBrowserAccessibilityWin() { global_obj_count_++; }
+ virtual ~CountedBrowserAccessibilityWin() { global_obj_count_--; }
static int global_obj_count_;
};
-int CountedBrowserAccessibility::global_obj_count_ = 0;
+int CountedBrowserAccessibilityWin::global_obj_count_ = 0;
-// Factory that creates a CountedBrowserAccessibility.
-class CountedBrowserAccessibilityFactory
- : public BrowserAccessibilityFactory {
+// Factory that creates a CountedBrowserAccessibilityWin.
+class CountedBrowserAccessibilityWinFactory
+ : public BrowserAccessibilityWinFactory {
public:
- virtual ~CountedBrowserAccessibilityFactory() {}
- virtual BrowserAccessibility* Create() {
- CComObject<CountedBrowserAccessibility>* instance;
- HRESULT hr = CComObject<CountedBrowserAccessibility>::CreateInstance(
+ virtual ~CountedBrowserAccessibilityWinFactory() {}
+ virtual BrowserAccessibilityWin* Create() {
+ CComObject<CountedBrowserAccessibilityWin>* instance;
+ HRESULT hr = CComObject<CountedBrowserAccessibilityWin>::CreateInstance(
&instance);
DCHECK(SUCCEEDED(hr));
- instance->AddRef();
- return instance;
+ return instance->NewReference();
}
};
@@ -91,30 +90,25 @@ 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.
- CountedBrowserAccessibility::global_obj_count_ = 0;
+ CountedBrowserAccessibilityWin::global_obj_count_ = 0;
+ // TODO: Use BrowserAccessibilityManager::Create instead of new below.
BrowserAccessibilityManager* manager =
- BrowserAccessibilityManager::Create(
- GetDesktopWindow(),
- root,
- NULL,
- new CountedBrowserAccessibilityFactory());
- ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_);
+ new BrowserAccessibilityManagerWin(
+ GetDesktopWindow(), root, NULL,
+ new CountedBrowserAccessibilityWinFactory());
+ ASSERT_EQ(3, CountedBrowserAccessibilityWin::global_obj_count_);
// Delete the manager and test that all 3 instances are deleted.
delete manager;
- ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
+ ASSERT_EQ(0, CountedBrowserAccessibilityWin::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 =
- BrowserAccessibilityManager::Create(
- GetDesktopWindow(),
- root,
- NULL,
- new CountedBrowserAccessibilityFactory());
- ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_);
- IAccessible* root_accessible =
- manager->GetRoot()->toBrowserAccessibilityWin();
+ manager = new BrowserAccessibilityManagerWin(
+ GetDesktopWindow(), root, NULL,
+ new CountedBrowserAccessibilityWinFactory());
+ ASSERT_EQ(3, CountedBrowserAccessibilityWin::global_obj_count_);
+ IAccessible* root_accessible = manager->GetRootAccessible();
IDispatch* root_iaccessible = NULL;
IDispatch* child1_iaccessible = NULL;
VARIANT var_child;
@@ -129,14 +123,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, CountedBrowserAccessibility::global_obj_count_);
+ ASSERT_EQ(2, CountedBrowserAccessibilityWin::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, CountedBrowserAccessibility::global_obj_count_);
+ ASSERT_EQ(1, CountedBrowserAccessibilityWin::global_obj_count_);
child1_iaccessible->Release();
- ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
+ ASSERT_EQ(0, CountedBrowserAccessibilityWin::global_obj_count_);
}
TEST_F(BrowserAccessibilityTest, TestChildrenChange) {
@@ -158,18 +152,16 @@ TEST_F(BrowserAccessibilityTest, TestChildrenChange) {
// Construct a BrowserAccessibilityManager with this WebAccessibility tree
// and a factory for an instance-counting BrowserAccessibility.
- CountedBrowserAccessibility::global_obj_count_ = 0;
+ CountedBrowserAccessibilityWin::global_obj_count_ = 0;
BrowserAccessibilityManager* manager =
- BrowserAccessibilityManager::Create(
- GetDesktopWindow(),
- root,
- NULL,
- new CountedBrowserAccessibilityFactory());
+ new BrowserAccessibilityManagerWin(
+ GetDesktopWindow(), root, NULL,
+ new CountedBrowserAccessibilityWinFactory());
// Query for the text IAccessible and verify that it returns "old text" as its
// value.
ScopedComPtr<IDispatch> text_dispatch;
- HRESULT hr = manager->GetRoot()->toBrowserAccessibilityWin()->get_accChild(
+ HRESULT hr = manager->GetRootAccessible()->get_accChild(
CreateI4Variant(1), text_dispatch.Receive());
ASSERT_EQ(S_OK, hr);
@@ -198,7 +190,7 @@ TEST_F(BrowserAccessibilityTest, TestChildrenChange) {
// Query for the text IAccessible and verify that it now returns "new text"
// as its value.
- hr = manager->GetRoot()->toBrowserAccessibilityWin()->get_accChild(
+ hr = manager->GetRootAccessible()->get_accChild(
CreateI4Variant(1),
text_dispatch.Receive());
ASSERT_EQ(S_OK, hr);
@@ -216,7 +208,7 @@ TEST_F(BrowserAccessibilityTest, TestChildrenChange) {
// Delete the manager and test that all BrowserAccessibility instances are
// deleted.
delete manager;
- ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
+ ASSERT_EQ(0, CountedBrowserAccessibilityWin::global_obj_count_);
}
TEST_F(BrowserAccessibilityTest, TestChildrenChangeNoLeaks) {
@@ -247,14 +239,12 @@ 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.
- CountedBrowserAccessibility::global_obj_count_ = 0;
+ CountedBrowserAccessibilityWin::global_obj_count_ = 0;
BrowserAccessibilityManager* manager =
- BrowserAccessibilityManager::Create(
- GetDesktopWindow(),
- root,
- NULL,
- new CountedBrowserAccessibilityFactory());
- ASSERT_EQ(4, CountedBrowserAccessibility::global_obj_count_);
+ new BrowserAccessibilityManagerWin(
+ GetDesktopWindow(), root, NULL,
+ new CountedBrowserAccessibilityWinFactory());
+ ASSERT_EQ(4, CountedBrowserAccessibilityWin::global_obj_count_);
// Notify the BrowserAccessibilityManager that the div node and its children
// were removed and ensure that only one BrowserAccessibility instance exists.
@@ -267,10 +257,10 @@ TEST_F(BrowserAccessibilityTest, TestChildrenChangeNoLeaks) {
std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
notifications.push_back(param);
manager->OnAccessibilityNotifications(notifications);
- ASSERT_EQ(1, CountedBrowserAccessibility::global_obj_count_);
+ ASSERT_EQ(1, CountedBrowserAccessibilityWin::global_obj_count_);
// Delete the manager and test that all BrowserAccessibility instances are
// deleted.
delete manager;
- ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
+ ASSERT_EQ(0, CountedBrowserAccessibilityWin::global_obj_count_);
}