Title: [277201] trunk
Revision
277201
Author
bfulg...@apple.com
Date
2021-05-07 14:42:28 -0700 (Fri, 07 May 2021)

Log Message

[iOS] Make AccessibilityReduceMotion test case work on iOS
https://bugs.webkit.org/show_bug.cgi?id=225244
<rdar://problem/77589455>

New tests for Accessibility-related features were added in Bug 215664, but only for macOS.
We support these same features on iOS, and should have test coverage.

Reviewed by Per Arne Vollan.

Source/WebKit:

Tested by AccessibilityReduceMotion.mm.

* Platform/spi/Cocoa/AccessibilitySupportSPI.h:

Tools:

* TestWebKitAPI/Tests/WebKit/AccessibilityReduceMotion.mm:
(notificationCallback):
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (277200 => 277201)


--- trunk/Source/WebKit/ChangeLog	2021-05-07 21:40:16 UTC (rev 277200)
+++ trunk/Source/WebKit/ChangeLog	2021-05-07 21:42:28 UTC (rev 277201)
@@ -1,3 +1,18 @@
+2021-05-07  Brent Fulgham  <bfulg...@apple.com>
+
+        [iOS] Make AccessibilityReduceMotion test case work on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=225244
+        <rdar://problem/77589455>
+
+        New tests for Accessibility-related features were added in Bug 215664, but only for macOS.
+        We support these same features on iOS, and should have test coverage.
+
+        Reviewed by Per Arne Vollan.
+
+        Tested by AccessibilityReduceMotion.mm.
+
+        * Platform/spi/Cocoa/AccessibilitySupportSPI.h:
+
 2021-05-07  Ryosuke Niwa  <rn...@webkit.org>
 
         IPC testing API should have the ability to create and receive IPC::Semaphore

Modified: trunk/Source/WebKit/Platform/spi/Cocoa/AccessibilitySupportSPI.h (277200 => 277201)


--- trunk/Source/WebKit/Platform/spi/Cocoa/AccessibilitySupportSPI.h	2021-05-07 21:40:16 UTC (rev 277200)
+++ trunk/Source/WebKit/Platform/spi/Cocoa/AccessibilitySupportSPI.h	2021-05-07 21:42:28 UTC (rev 277201)
@@ -40,6 +40,11 @@
 extern CFStringRef _AXSCopyPathForAccessibilityBundle(CFStringRef bundle);
 #endif
 
+#if PLATFORM(IOS_FAMILY)
+extern CFStringRef kAXSReduceMotionPreference;
+extern CFStringRef kAXSReduceMotionChangedNotification;
+#endif
+
 #if PLATFORM(IOS_FAMILY) && ENABLE(FULL_KEYBOARD_ACCESS)
 extern CFStringRef kAXSFullKeyboardAccessEnabledNotification;
 extern Boolean _AXSFullKeyboardAccessEnabled();

Modified: trunk/Tools/ChangeLog (277200 => 277201)


--- trunk/Tools/ChangeLog	2021-05-07 21:40:16 UTC (rev 277200)
+++ trunk/Tools/ChangeLog	2021-05-07 21:42:28 UTC (rev 277201)
@@ -1,3 +1,18 @@
+2021-05-07  Brent Fulgham  <bfulg...@apple.com>
+
+        [iOS] Make AccessibilityReduceMotion test case work on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=225244
+        <rdar://problem/77589455>
+
+        New tests for Accessibility-related features were added in Bug 215664, but only for macOS.
+        We support these same features on iOS, and should have test coverage.
+
+        Reviewed by Per Arne Vollan.
+
+        * TestWebKitAPI/Tests/WebKit/AccessibilityReduceMotion.mm:
+        (notificationCallback):
+        (TEST):
+
 2021-05-07  Ryosuke Niwa  <rn...@webkit.org>
 
         IPC testing API should have the ability to create and receive IPC::Semaphore

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/xcshareddata/xcschemes/TestWebKitAPI.xcscheme (277200 => 277201)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/xcshareddata/xcschemes/TestWebKitAPI.xcscheme	2021-05-07 21:40:16 UTC (rev 277200)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/xcshareddata/xcschemes/TestWebKitAPI.xcscheme	2021-05-07 21:42:28 UTC (rev 277201)
@@ -50,6 +50,12 @@
             ReferencedContainer = "container:TestWebKitAPI.xcodeproj">
          </BuildableReference>
       </BuildableProductRunnable>
+      <CommandLineArguments>
+         <CommandLineArgument
+            argument = "--gtest_filter=WebKit.AccessibilityReduceMotion"
+            isEnabled = "YES">
+         </CommandLineArgument>
+      </CommandLineArguments>
    </LaunchAction>
    <ProfileAction
       buildConfiguration = "Release"

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit/AccessibilityReduceMotion.mm (277200 => 277201)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/AccessibilityReduceMotion.mm	2021-05-07 21:40:16 UTC (rev 277200)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/AccessibilityReduceMotion.mm	2021-05-07 21:42:28 UTC (rev 277201)
@@ -25,16 +25,38 @@
 
 #import "config.h"
 
-#if WK_HAVE_C_SPI && ENABLE(CFPREFS_DIRECT_MODE)
+#if ENABLE(CFPREFS_DIRECT_MODE)
 
 #import "PlatformUtilities.h"
 #import "TestWKWebView.h"
+#import "WKWebViewConfigurationExtras.h"
 #import <WebKit/PreferenceObserver.h>
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
 
+#if PLATFORM(MAC)
 #import <pal/spi/mac/HIServicesSPI.h>
+#endif
 
+#if PLATFORM(IOS_FAMILY)
+#include <pal/spi/cocoa/AccessibilitySupportSPI.h>
+#include <wtf/SoftLinking.h>
+
+SOFT_LINK_LIBRARY(libAccessibility)
+SOFT_LINK_CONSTANT(libAccessibility, kAXSReduceMotionPreference, CFStringRef);
+SOFT_LINK_CONSTANT(libAccessibility, kAXSReduceMotionChangedNotification, CFStringRef);
+
+#define NOTIFICATION_CENTER CFNotificationCenterGetDarwinNotifyCenter()
+#define REDUCED_MOTION_PREFERENCE getkAXSReduceMotionPreference()
+#define REDUCED_MOTION_CHANGED_NOTIFICATION getkAXSReduceMotionChangedNotification()
+#define ACCESSIBILITY_DOMAIN CFSTR("com.apple.Accessibility")
+#else
+#define NOTIFICATION_CENTER CFNotificationCenterGetDistributedCenter()
+#define REDUCED_MOTION_PREFERENCE kAXInterfaceReduceMotionKey
+#define REDUCED_MOTION_CHANGED_NOTIFICATION kAXInterfaceReduceMotionStatusDidChangeNotification
+#define ACCESSIBILITY_DOMAIN CFSTR("com.apple.universalaccess")
+#endif
+
 static bool reduceMotionNotificationReceived = false;
 static bool receivedPreferenceNotification = false;
 
@@ -50,40 +72,44 @@
 }
 @end
 
+static void notificationCallback(CFNotificationCenterRef center, void *observer, CFNotificationName name, const void *object, CFDictionaryRef userInfo)
+{
+    reduceMotionNotificationReceived = true;
+}
+
 TEST(WebKit, AccessibilityReduceMotion)
 {
-    RetainPtr<NSObject> accessibilityObserver = [[NSDistributedNotificationCenter defaultCenter] addObserverForName:(__bridge id)kAXInterfaceReduceMotionStatusDidChangeNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *note) {
-        reduceMotionNotificationReceived = true;
-    }];
+    CFNotificationCenterAddObserver(NOTIFICATION_CENTER, nullptr, &notificationCallback, REDUCED_MOTION_CHANGED_NOTIFICATION, nullptr, CFNotificationSuspensionBehaviorDeliverImmediately);
 
-    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
-    WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
-    configuration.get().processPool = (WKProcessPool *)context.get();
-    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
+    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration addToWindow:YES]);
 
-    CFPreferencesSetAppValue(kAXInterfaceReduceMotionKey, kCFBooleanFalse, CFSTR("com.apple.universalaccess"));
+    CFPreferencesSetAppValue(REDUCED_MOTION_PREFERENCE, kCFBooleanFalse, ACCESSIBILITY_DOMAIN);
 
     auto observer = adoptNS([[WKPreferenceObserverForTesting alloc] init]);
 
     [webView synchronouslyLoadTestPageNamed:@"simple"];
 
-    CFPreferencesSetAppValue(kAXInterfaceReduceMotionKey, kCFBooleanTrue, CFSTR("com.apple.universalaccess"));
-
-    TestWebKitAPI::Util::run(&receivedPreferenceNotification);
-
     auto reduceMotion = [&] {
         return [webView stringByEvaluatingJavaScript:@"window.internals.userPrefersReducedMotion()"].boolValue;
     };
-    
-    [webView synchronouslyLoadTestPageNamed:@"simple"];
 
+    ASSERT_FALSE(reduceMotion());
+
+    reduceMotionNotificationReceived = false;
+
+    CFPreferencesSetAppValue(REDUCED_MOTION_PREFERENCE, kCFBooleanTrue, ACCESSIBILITY_DOMAIN);
+
+    TestWebKitAPI::Util::run(&receivedPreferenceNotification);
     TestWebKitAPI::Util::run(&reduceMotionNotificationReceived);
 
+    [webView synchronouslyLoadTestPageNamed:@"simple"];
+
     ASSERT_TRUE(reduceMotion());
 
-    CFPreferencesSetAppValue(kAXInterfaceReduceMotionKey, nullptr, CFSTR("com.apple.universalaccess"));
+    CFPreferencesSetAppValue(REDUCED_MOTION_PREFERENCE, nullptr, ACCESSIBILITY_DOMAIN);
 
-    [[NSNotificationCenter defaultCenter] removeObserver:accessibilityObserver.get()];
+    CFNotificationCenterRemoveObserver(NOTIFICATION_CENTER, nullptr, REDUCED_MOTION_CHANGED_NOTIFICATION, nullptr);
 }
 
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to