Skip to content

Commit cb4ca39

Browse files
fleizachryanhaddad
authored andcommitted
AX: TestWebKitAPI.WebKit.AccessibilityReduceMotion failing on iOS
https://bugs.webkit.org/show_bug.cgi?id=226758 <rdar://problem/78984253> Patch by Chris Fleizach <[email protected]> on 2021-06-10 Reviewed by Alex Christensen. Source/WebKit: For releases that don't have the accessibility update method, the direct setters need to be called in order to update the cache. * Platform/spi/Cocoa/AccessibilitySupportSPI.h: * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::increaseContrastPreferenceKey): (WebKit::setPreferenceValue): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebKit/AccessibilityIncreaseContrast.mm: Added. (-[WKPreferenceObserverForTestingIncreaseContrast preferenceDidChange:key:encodedValue:]): (TEST): Canonical link: https://commits.webkit.org/238698@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278736 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent ad78c42 commit cb4ca39

7 files changed

Lines changed: 155 additions & 1 deletion

File tree

Source/WTF/wtf/PlatformHave.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,11 @@
10061006
#define HAVE_UIDATEPICKER_INSETS 1
10071007
#endif
10081008

1009+
#if (((PLATFORM(IOS) || PLATFORM(MACCATALYST)) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 150000) \
1010+
|| (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000))
1011+
#define UPDATE_WEB_ACCESSIBILITY_SETTINGS 1
1012+
#endif
1013+
10091014
#if PLATFORM(IOS) || PLATFORM(MACCATALYST)
10101015
#define HAVE_UIBLUREFFECT_STYLE_SYSTEM_MATERIAL 1
10111016
#endif

Source/WebKit/ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2021-06-10 Chris Fleizach <[email protected]>
2+
3+
AX: TestWebKitAPI.WebKit.AccessibilityReduceMotion failing on iOS
4+
https://bugs.webkit.org/show_bug.cgi?id=226758
5+
<rdar://problem/78984253>
6+
7+
Reviewed by Alex Christensen.
8+
9+
For releases that don't have the accessibility update method, the direct setters need to be called
10+
in order to update the cache.
11+
12+
* Platform/spi/Cocoa/AccessibilitySupportSPI.h:
13+
* WebProcess/cocoa/WebProcessCocoa.mm:
14+
(WebKit::increaseContrastPreferenceKey):
15+
(WebKit::setPreferenceValue):
16+
117
2021-06-10 Aditya Keerthi <[email protected]>
218

319
[iOS] VinylWall app crashes when tapping on 'format' dropdown menu in 'Add Record' menu

Source/WebKit/Platform/spi/Cocoa/AccessibilitySupportSPI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
WTF_EXTERN_C_BEGIN
3535

36+
extern void _AXSSetReduceMotionEnabled(Boolean enabled);
37+
extern void _AXSSetDarkenSystemColors(Boolean enabled);
3638
extern Boolean _AXSKeyRepeatEnabled();
3739
extern Boolean _AXSApplicationAccessibilityEnabled();
3840
extern CFStringRef kAXSApplicationAccessibilityEnabledNotification;

Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#import <pal/spi/cf/CFUtilitiesSPI.h>
8787
#import <pal/spi/cg/CoreGraphicsSPI.h>
8888
#import <pal/spi/cocoa/AVFoundationSPI.h>
89+
#import <pal/spi/cocoa/AccessibilitySupportSPI.h>
8990
#import <pal/spi/cocoa/CoreServicesSPI.h>
9091
#import <pal/spi/cocoa/LaunchServicesSPI.h>
9192
#import <pal/spi/cocoa/NSAccessibilitySPI.h>
@@ -173,7 +174,7 @@
173174
SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(WebKit, HIServices, _AXSetAuditTokenIsAuthenticatedCallback, void, (AXAuditTokenIsAuthenticatedCallback callback), (callback))
174175
#endif
175176

176-
#if ENABLE(CFPREFS_DIRECT_MODE)
177+
#if HAVE(UPDATE_WEB_ACCESSIBILITY_SETTINGS) && ENABLE(CFPREFS_DIRECT_MODE)
177178
SOFT_LINK_LIBRARY(libAccessibility)
178179
SOFT_LINK_OPTIONAL(libAccessibility, _AXSUpdateWebAccessibilitySettings, void, (), ());
179180
#endif
@@ -1078,6 +1079,14 @@ static float currentBacklightLevel()
10781079
}
10791080
#endif
10801081

1082+
#if PLATFORM(IOS_FAMILY)
1083+
static const WTF::String& increaseContrastPreferenceKey()
1084+
{
1085+
static NeverDestroyed<WTF::String> key(MAKE_STATIC_STRING_IMPL("DarkenSystemColors"));
1086+
return key;
1087+
}
1088+
#endif
1089+
10811090
static const WTF::String& captionProfilePreferenceKey()
10821091
{
10831092
static NeverDestroyed<WTF::String> key(MAKE_STATIC_STRING_IMPL("MACaptionActiveProfile"));
@@ -1130,8 +1139,17 @@ static void setPreferenceValue(const String& domain, const String& key, id value
11301139
}
11311140

11321141
if (domain == String(kAXSAccessibilityPreferenceDomain)) {
1142+
#if HAVE(UPDATE_WEB_ACCESSIBILITY_SETTINGS) && ENABLE(CFPREFS_DIRECT_MODE)
11331143
if (_AXSUpdateWebAccessibilitySettingsPtr())
11341144
_AXSUpdateWebAccessibilitySettingsPtr()();
1145+
#elif PLATFORM(IOS_FAMILY)
1146+
// If the update method is not available, to update the cache inside AccessibilitySupport,
1147+
// these methods need to be called directly.
1148+
if (CFEqual(key.createCFString().get(), kAXSReduceMotionPreference) && [value isKindOfClass:[NSNumber class]])
1149+
_AXSSetReduceMotionEnabled([(NSNumber *)value boolValue]);
1150+
else if (CFEqual(key.createCFString().get(), increaseContrastPreferenceKey()) && [value isKindOfClass:[NSNumber class]])
1151+
_AXSSetDarkenSystemColors([(NSNumber *)value boolValue]);
1152+
#endif
11351153
}
11361154

11371155
#if USE(APPKIT)

Tools/ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2021-06-10 Chris Fleizach <[email protected]>
2+
3+
AX: TestWebKitAPI.WebKit.AccessibilityReduceMotion failing on iOS
4+
https://bugs.webkit.org/show_bug.cgi?id=226758
5+
<rdar://problem/78984253>
6+
7+
Reviewed by Alex Christensen.
8+
9+
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
10+
* TestWebKitAPI/Tests/WebKit/AccessibilityIncreaseContrast.mm: Added.
11+
(-[WKPreferenceObserverForTestingIncreaseContrast preferenceDidChange:key:encodedValue:]):
12+
(TEST):
13+
114
2021-06-10 Jonathan Bedard <[email protected]>
215

316
[webkitcorepy] 6x performance improvement in Memoized

Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
290A9BB91735F63800D71BBC /* OpenNewWindow.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 290A9BB81735F42300D71BBC /* OpenNewWindow.html */; };
144144
290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */; };
145145
297234B7173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 297234B5173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp */; };
146+
29E06E5E266F3C0600F1A707 /* AccessibilityIncreaseContrast.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29E06E5D266F3C0600F1A707 /* AccessibilityIncreaseContrast.mm */; };
146147
2D00065F1C1F589A0088E6A7 /* WKPDFView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D00065D1C1F58940088E6A7 /* WKPDFView.mm */; };
147148
2D01D06E23218FEE0039AA3A /* WKWebViewPrintFormatter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D01D06D23218FEE0039AA3A /* WKWebViewPrintFormatter.mm */; };
148149
2D08E9372267D0F4002518DA /* ReparentWebViewTimeout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D08E9362267D0F3002518DA /* ReparentWebViewTimeout.mm */; };
@@ -1921,6 +1922,7 @@
19211922
29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CustomProtocolsTest.mm; path = WebKitObjC/CustomProtocolsTest.mm; sourceTree = "<group>"; };
19221923
29AB8AA2164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestBrowsingContextLoadDelegate.mm; sourceTree = "<group>"; };
19231924
29AB8AA3164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestBrowsingContextLoadDelegate.h; sourceTree = "<group>"; };
1925+
29E06E5D266F3C0600F1A707 /* AccessibilityIncreaseContrast.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AccessibilityIncreaseContrast.mm; sourceTree = "<group>"; };
19241926
2D00065D1C1F58940088E6A7 /* WKPDFView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPDFView.mm; sourceTree = "<group>"; };
19251927
2D01D06D23218FEE0039AA3A /* WKWebViewPrintFormatter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewPrintFormatter.mm; sourceTree = "<group>"; };
19261928
2D08E9362267D0F3002518DA /* ReparentWebViewTimeout.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ReparentWebViewTimeout.mm; sourceTree = "<group>"; };
@@ -3307,6 +3309,7 @@
33073309
0F139E741A423A4600F590F5 /* cocoa */ = {
33083310
isa = PBXGroup;
33093311
children = (
3312+
29E06E5D266F3C0600F1A707 /* AccessibilityIncreaseContrast.mm */,
33103313
C1F4840624EDDB400053ECB8 /* AccessibilityReduceMotion.mm */,
33113314
E3F8AB91241AB9CE003E2A7E /* AccessibilityRemoteUIApp.mm */,
33123315
C1F7B7382449083F00124557 /* AGXCompilerService.mm */,
@@ -5723,6 +5726,7 @@
57235726
5CCB10E4213457E000AC5AF0 /* ShouldGoToBackForwardListItem.mm in Sources */,
57245727
7CCE7F141A411AE600447C4C /* ShouldKeepCurrentBackForwardListItemInList.cpp in Sources */,
57255728
37BCA61C1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm in Sources */,
5729+
29E06E5E266F3C0600F1A707 /* AccessibilityIncreaseContrast.mm in Sources */,
57265730
7C83E0C51D0A654600FEBCF3 /* ShrinkToFit.mm in Sources */,
57275731
7CCE7ECD1A411A7E00447C4C /* SimplifyMarkup.mm in Sources */,
57285732
C149D550242E98DF003EBB12 /* SleepDisabler.mm in Sources */,
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (C) 2021 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#import "config.h"
27+
28+
#if ENABLE(CFPREFS_DIRECT_MODE)
29+
30+
#import "PlatformUtilities.h"
31+
#import "TestWKWebView.h"
32+
#import "WKWebViewConfigurationExtras.h"
33+
#import <WebKit/PreferenceObserver.h>
34+
#import <WebKit/WKProcessPoolPrivate.h>
35+
#import <WebKit/_WKProcessPoolConfiguration.h>
36+
37+
#if PLATFORM(MAC)
38+
#import <pal/spi/mac/HIServicesSPI.h>
39+
#endif
40+
41+
#if PLATFORM(IOS_FAMILY)
42+
#include <pal/spi/cocoa/AccessibilitySupportSPI.h>
43+
#include <wtf/SoftLinking.h>
44+
45+
#define NOTIFICATION_CENTER CFNotificationCenterGetDarwinNotifyCenter()
46+
#define INCREASE_CONTRAST_PREFERENCE CFSTR("DarkenSystemColors")
47+
#define ACCESSIBILITY_DOMAIN CFSTR("com.apple.Accessibility")
48+
#else
49+
#define NOTIFICATION_CENTER CFNotificationCenterGetDistributedCenter()
50+
#define INCREASE_CONTRAST_PREFERENCE kAXInterfaceIncreaseContrastKey
51+
#define ACCESSIBILITY_DOMAIN CFSTR("com.apple.universalaccess")
52+
#endif
53+
54+
static bool receivedPreferenceNotification = false;
55+
56+
@interface WKPreferenceObserverForTestingIncreaseContrast : WKPreferenceObserver
57+
- (void)preferenceDidChange:(NSString *)domain key:(NSString *)key encodedValue:(NSString *)encodedValue;
58+
@end
59+
60+
@implementation WKPreferenceObserverForTestingIncreaseContrast
61+
- (void)preferenceDidChange:(NSString *)domain key:(NSString *)key encodedValue:(NSString *)encodedValue
62+
{
63+
receivedPreferenceNotification = true;
64+
[super preferenceDidChange:domain key:key encodedValue:encodedValue];
65+
}
66+
@end
67+
68+
TEST(WebKit, AccessibilityIncreaseContrast)
69+
{
70+
WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
71+
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration addToWindow:YES]);
72+
73+
CFPreferencesSetAppValue(INCREASE_CONTRAST_PREFERENCE, kCFBooleanFalse, ACCESSIBILITY_DOMAIN);
74+
75+
auto observer = adoptNS([[WKPreferenceObserverForTestingIncreaseContrast alloc] init]);
76+
77+
[webView synchronouslyLoadTestPageNamed:@"simple"];
78+
79+
auto contrastCheck = [&] {
80+
return [webView stringByEvaluatingJavaScript:@"window.internals.userPrefersContrast()"].boolValue;
81+
};
82+
83+
ASSERT_FALSE(contrastCheck());
84+
85+
CFPreferencesSetAppValue(INCREASE_CONTRAST_PREFERENCE, kCFBooleanTrue, ACCESSIBILITY_DOMAIN);
86+
87+
TestWebKitAPI::Util::run(&receivedPreferenceNotification);
88+
89+
[webView synchronouslyLoadTestPageNamed:@"simple"];
90+
91+
ASSERT_TRUE(contrastCheck());
92+
93+
CFPreferencesSetAppValue(INCREASE_CONTRAST_PREFERENCE, nullptr, ACCESSIBILITY_DOMAIN);
94+
}
95+
96+
#endif

0 commit comments

Comments
 (0)