Commit bc69fe57 authored by thakis@chromium.org's avatar thakis@chromium.org

mac: Remove two static initializers/destructors in TestInitialPageNotifications

Without this change, I would get a DCHECK when running just this test with
--gtest_filter, due to the arrays being destroyed too late.

BUG=none
TEST=none


Review URL: http://codereview.chromium.org/7694021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97721 0039d316-1c4b-4281-b951-d872f2087c98
parent dd74ac41
...@@ -31,7 +31,7 @@ class AccessibilityMacUITest : public UITest { ...@@ -31,7 +31,7 @@ class AccessibilityMacUITest : public UITest {
// Called to insert an event for validation. // Called to insert an event for validation.
// This is a order sensitive expectation. // This is a order sensitive expectation.
void AddExpectedEvent(NSString* notificationName) { void AddExpectedEvent(NSString* notificationName) {
[AccessibilityMacUITest::expectedEvents addObject:notificationName]; [expectedEvents_ addObject:notificationName];
} }
// Assert that there are no remaining expected events. // Assert that there are no remaining expected events.
...@@ -39,11 +39,11 @@ class AccessibilityMacUITest : public UITest { ...@@ -39,11 +39,11 @@ class AccessibilityMacUITest : public UITest {
// Assumes that there is at least one expected event. // Assumes that there is at least one expected event.
// The runloop stops only if we receive all expected notifications. // The runloop stops only if we receive all expected notifications.
void WaitAndAssertAllEventsObserved() { void WaitAndAssertAllEventsObserved() {
ASSERT_GE([expectedEvents count], 1U); ASSERT_GE([expectedEvents_ count], 1U);
CFRunLoopRunInMode( CFRunLoopRunInMode(
kCFRunLoopDefaultMode, kCFRunLoopDefaultMode,
TestTimeouts::action_max_timeout_ms() / 1000, false); TestTimeouts::action_max_timeout_ms() / 1000, false);
ASSERT_EQ(0U, [AccessibilityMacUITest::expectedEvents count]); ASSERT_EQ(0U, [expectedEvents_ count]);
} }
// The Callback handler added to each AXUIElement. // The Callback handler added to each AXUIElement.
...@@ -52,24 +52,25 @@ class AccessibilityMacUITest : public UITest { ...@@ -52,24 +52,25 @@ class AccessibilityMacUITest : public UITest {
AXUIElementRef element, AXUIElementRef element,
CFStringRef notificationName, CFStringRef notificationName,
void *refcon) { void *refcon) {
if ([[AccessibilityMacUITest::expectedEvents objectAtIndex:0] AccessibilityMacUITest* this_pointer =
reinterpret_cast<AccessibilityMacUITest*>(refcon);
if ([[this_pointer->expectedEvents_ objectAtIndex:0]
isEqualToString:(NSString*)notificationName]) { isEqualToString:(NSString*)notificationName]) {
[AccessibilityMacUITest::expectedEvents removeObjectAtIndex:0]; [this_pointer->expectedEvents_ removeObjectAtIndex:0];
} }
if ([AccessibilityMacUITest::expectedEvents count] == 0) { if ([this_pointer->expectedEvents_ count] == 0) {
CFRunLoopStop(CFRunLoopGetCurrent()); CFRunLoopStop(CFRunLoopGetCurrent());
} }
// TODO(dtseng): currently refreshing on all notifications; scope later. // TODO(dtseng): currently refreshing on all notifications; scope later.
AccessibilityMacUITest::SetAllObserversOnDescendants( this_pointer->SetAllObserversOnDescendants(element, observerRef);
element, observerRef);
} }
private: private:
// Perform AX setup. // Perform AX setup.
void Initialize() { void Initialize() {
AccessibilityMacUITest::expectedEvents.reset([[NSMutableArray alloc] init]); expectedEvents_.reset([[NSMutableArray alloc] init]);
// Construct the Chrome AXUIElementRef. // Construct the Chrome AXUIElementRef.
ASSERT_NE(-1, browser_process_id()); ASSERT_NE(-1, browser_process_id());
...@@ -94,8 +95,8 @@ class AccessibilityMacUITest : public UITest { ...@@ -94,8 +95,8 @@ class AccessibilityMacUITest : public UITest {
// Taken largely from AXNotificationConstants.h // Taken largely from AXNotificationConstants.h
// (substituted NSAccessibility* to avoid casting). // (substituted NSAccessibility* to avoid casting).
static void SetupObservedNotifications() { void SetupObservedNotifications() {
AccessibilityMacUITest::observedNotifications.reset( observedNotifications_.reset(
[[NSArray alloc] initWithObjects: [[NSArray alloc] initWithObjects:
// focus notifications // focus notifications
...@@ -149,7 +150,7 @@ class AccessibilityMacUITest : public UITest { ...@@ -149,7 +150,7 @@ class AccessibilityMacUITest : public UITest {
} }
// Observe AX notifications on element and all descendants. // Observe AX notifications on element and all descendants.
static void SetAllObserversOnDescendants( void SetAllObserversOnDescendants(
AXUIElementRef element, AXUIElementRef element,
AXObserverRef observerRef) { AXObserverRef observerRef) {
SetAllObservers(element, observerRef); SetAllObservers(element, observerRef);
...@@ -165,25 +166,21 @@ class AccessibilityMacUITest : public UITest { ...@@ -165,25 +166,21 @@ class AccessibilityMacUITest : public UITest {
} }
// Add observers for all notifications we know about. // Add observers for all notifications we know about.
static void SetAllObservers( void SetAllObservers(
AXUIElementRef element, AXUIElementRef element,
AXObserverRef observerRef) { AXObserverRef observerRef) {
for (NSString* notification in for (NSString* notification in observedNotifications_.get()) {
AccessibilityMacUITest::observedNotifications.get()) {
AXObserverAddNotification( AXObserverAddNotification(
observerRef, element, (CFStringRef)notification, nil); observerRef, element, (CFStringRef)notification, this);
} }
} }
// Used to keep track of events received during the lifetime of the tests. // Used to keep track of events received during the lifetime of the tests.
static scoped_nsobject<NSMutableArray> expectedEvents; scoped_nsobject<NSMutableArray> expectedEvents_;
// NSString collection of all AX notifications. // NSString collection of all AX notifications.
static scoped_nsobject<NSArray> observedNotifications; scoped_nsobject<NSArray> observedNotifications_;
}; };
scoped_nsobject<NSMutableArray> AccessibilityMacUITest::expectedEvents;
scoped_nsobject<NSArray> AccessibilityMacUITest::observedNotifications;
TEST_F(AccessibilityMacUITest, TestInitialPageNotifications) { TEST_F(AccessibilityMacUITest, TestInitialPageNotifications) {
// Browse to a new page. // Browse to a new page.
GURL tree_url( GURL tree_url(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment