Disable accessibility notifications after each test
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Mar 2013 17:28:55 +0000 (17:28 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Mar 2013 17:28:55 +0000 (17:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112579

Reviewed by Tim Horton.

In WebKitTestRunner, if any tests triggered accessibility notifications,
the global notification handler would thereafter be active, and fire
notifications for all subsequent tests.

Fix by implementing AccessibilityController::resetToConsistentState() for
Mac, and using it to clear the global notification handler.

* WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
* WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm:
(WTR::AccessibilityController::addNotificationListener): Remove stupid comment.
(WTR::AccessibilityController::removeNotificationListener): Explicitly call
-stopObserving so that unregistering the observer doesn't rely on object lifetimes
(e.g. because of -autorelease).
(WTR::AccessibilityController::logAccessibilityEvents): Stub.
(WTR::AccessibilityController::resetToConsistentState): Remove the notification listener
if there is one.
* WebKitTestRunner/InjectedBundle/mac/AccessibilityNotificationHandler.h:
Add -stopObserving
* WebKitTestRunner/InjectedBundle/mac/AccessibilityNotificationHandler.mm:
(-[AccessibilityNotificationHandler dealloc]): Call -stopObserving
(-[AccessibilityNotificationHandler stopObserving]): Unregister from the notification
center.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@146081 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.cpp
Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm
Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityNotificationHandler.h
Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityNotificationHandler.mm

index ed74966..9aa99e0 100644 (file)
@@ -1,3 +1,33 @@
+2013-03-18  Simon Fraser  <simon.fraser@apple.com>
+
+        Disable accessibility notifications after each test
+        https://bugs.webkit.org/show_bug.cgi?id=112579
+
+        Reviewed by Tim Horton.
+        
+        In WebKitTestRunner, if any tests triggered accessibility notifications,
+        the global notification handler would thereafter be active, and fire
+        notifications for all subsequent tests.
+        
+        Fix by implementing AccessibilityController::resetToConsistentState() for
+        Mac, and using it to clear the global notification handler.
+
+        * WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
+        * WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm:
+        (WTR::AccessibilityController::addNotificationListener): Remove stupid comment.
+        (WTR::AccessibilityController::removeNotificationListener): Explicitly call
+        -stopObserving so that unregistering the observer doesn't rely on object lifetimes
+        (e.g. because of -autorelease).
+        (WTR::AccessibilityController::logAccessibilityEvents): Stub.
+        (WTR::AccessibilityController::resetToConsistentState): Remove the notification listener
+        if there is one.
+        * WebKitTestRunner/InjectedBundle/mac/AccessibilityNotificationHandler.h:
+        Add -stopObserving
+        * WebKitTestRunner/InjectedBundle/mac/AccessibilityNotificationHandler.mm:
+        (-[AccessibilityNotificationHandler dealloc]): Call -stopObserving
+        (-[AccessibilityNotificationHandler stopObserving]): Unregister from the notification
+        center.
+
 2013-03-18  Dana Jansens  <danakj@chromium.org>
 
         [chromium] Remove WebGraphicsContext3DInProcessImpl support from DRT.
index 6df0269..03ec650 100644 (file)
@@ -112,7 +112,7 @@ bool AccessibilityController::removeNotificationListener() { return false; }
 PassRefPtr<AccessibilityUIElement> AccessibilityController::accessibleElementById(JSStringRef attribute) { return 0; }
 #endif
 
-#if !PLATFORM(GTK) && !PLATFORM(EFL)
+#if !PLATFORM(GTK) && !PLATFORM(EFL) && !PLATFORM(MAC)
 void AccessibilityController::logAccessibilityEvents() { }
 void AccessibilityController::resetToConsistentState() { }
 #endif
index 9e54908..fefddc7 100644 (file)
@@ -49,8 +49,6 @@ bool AccessibilityController::addNotificationListener(JSValueRef functionCallbac
     if (!functionCallback)
         return false;
 
-    // Mac programmers should not be adding more than one global notification listener.
-    // Other platforms may be different.
     if (m_globalNotificationHandler)
         return false;
     m_globalNotificationHandler = [[AccessibilityNotificationHandler alloc] init];
@@ -62,13 +60,24 @@ bool AccessibilityController::addNotificationListener(JSValueRef functionCallbac
 
 bool AccessibilityController::removeNotificationListener()
 {
-    // Mac programmers should not be trying to remove a listener that's already removed.
     ASSERT(m_globalNotificationHandler);
+    
+    [m_globalNotificationHandler.get() stopObserving];
     m_globalNotificationHandler.clear();
 
     return true;
 }
 
+void AccessibilityController::logAccessibilityEvents()
+{
+}
+
+void AccessibilityController::resetToConsistentState()
+{
+    if (m_globalNotificationHandler)
+        removeNotificationListener();
+}
+
 static id findAccessibleObjectById(id obj, NSString *idAttribute)
 {
     BEGIN_AX_OBJC_EXCEPTIONS
index 1d85bca..a3a0233 100644 (file)
@@ -75,7 +75,7 @@
 
 - (void)dealloc
 {
-    [[NSNotificationCenter defaultCenter] removeObserver:self];
+    [self stopObserving];
 
     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(WTR::InjectedBundle::shared().page()->page());
     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_notificationReceived:) name:@"AXDRTNotification" object:nil];
 }
 
+- (void)stopObserving
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
 - (void)_notificationReceived:(NSNotification *)notification
 {
     NSString *notificationName = [[notification userInfo] objectForKey:@"notificationName"];