Skip to content

Commit 1a86d22

Browse files
committed
REGRESSION (299884@main): [macOS] Safari AutoFill filling unit tests are hanging
https://bugs.webkit.org/show_bug.cgi?id=299379 rdar://160980482 Reviewed by Richard Robinson and Abrar Rahman Protyasha. Partially revert logic introduced in 299884@main, which observes changes to all user defaults in order to update smart lists enablement. This was only necessary for the scenario where the user default is modified by the user or app, through the command line or `NSUserDefaults` API. Importantly, these user defaults still persist across app launches, and also update correctly as the user uses the context menu or other UI that's integrated with `-[WKWebView _toggleSmartLists:]`. Test: Tools/TestWebKitAPI/Tests/WebKitCocoa/SmartLists.mm * Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm: (WebKit::WebProcessPool::registerNotificationObservers): (WebKit::WebProcessPool::unregisterNotificationObservers): * Tools/TestWebKitAPI/Tests/WebKitCocoa/SmartLists.mm: (TEST(SmartLists, EnablementIsLogicallyConsistentWhenInterfacedThroughResponder)): Adjust an API test by moving the `user default => nil, preference => true` test case up to the start, when the user default is (initially) set to `nil`. Canonical link: https://commits.webkit.org/300414@main
1 parent 045c46c commit 1a86d22

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -854,17 +854,6 @@ static void logProcessPoolState(const WebProcessPool& pool)
854854
textCheckerStateChanged();
855855
}];
856856

857-
// FIXME: This isn't that ideal since it listens to every user default change and not just the smart lists default.
858-
m_smartListsNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSUserDefaultsDidChangeNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
859-
TextChecker::didChangeSmartListsEnabled();
860-
861-
auto newValue = TextChecker::state().contains(TextCheckerState::SmartListsEnabled);
862-
if (std::exchange(m_smartListsEnabled, newValue) == newValue)
863-
return;
864-
865-
textCheckerStateChanged();
866-
}];
867-
868857
m_accessibilityDisplayOptionsNotificationObserver = [[NSWorkspace.sharedWorkspace notificationCenter] addObserverForName:NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
869858
screenPropertiesChanged();
870859
}];
@@ -1023,7 +1012,6 @@ static void logProcessPoolState(const WebProcessPool& pool)
10231012
[[NSNotificationCenter defaultCenter] removeObserver:m_automaticSpellingCorrectionNotificationObserver.get()];
10241013
[[NSNotificationCenter defaultCenter] removeObserver:m_automaticQuoteSubstitutionNotificationObserver.get()];
10251014
[[NSNotificationCenter defaultCenter] removeObserver:m_automaticDashSubstitutionNotificationObserver.get()];
1026-
[[NSNotificationCenter defaultCenter] removeObserver:m_smartListsNotificationObserver.get()];
10271015
[[NSWorkspace.sharedWorkspace notificationCenter] removeObserver:m_accessibilityDisplayOptionsNotificationObserver.get()];
10281016
[[NSNotificationCenter defaultCenter] removeObserver:m_scrollerStyleNotificationObserver.get()];
10291017
[[NSNotificationCenter defaultCenter] removeObserver:m_deactivationObserver.get()];

Tools/TestWebKitAPI/Tests/WebKitCocoa/SmartLists.mm

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ static void runTest(NSString *input, NSString *expectedHTML, NSString *expectedS
126126

127127
TEST(SmartLists, EnablementIsLogicallyConsistentWhenInterfacedThroughResponder)
128128
{
129+
resetUserDefaults();
130+
129131
RetainPtr configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
130132
RetainPtr webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
131133
[webView synchronouslyLoadHTMLString:@"<div>hi</div>"];
@@ -134,7 +136,6 @@ static void runTest(NSString *input, NSString *expectedHTML, NSString *expectedS
134136
// Case 1: user default => nil, preference => false
135137

136138
setSmartListsPreference(configuration.get(), NO);
137-
resetUserDefaults();
138139

139140
EXPECT_FALSE([webView _isSmartListsEnabled]);
140141
EXPECT_NULL(userDefaultsValue());
@@ -143,22 +144,9 @@ static void runTest(NSString *input, NSString *expectedHTML, NSString *expectedS
143144
EXPECT_FALSE([webView _isSmartListsEnabled]);
144145
EXPECT_NULL(userDefaultsValue());
145146

146-
// Case 2: user default => true, preference => false
147-
148-
setSmartListsPreference(configuration.get(), NO);
149-
setUserDefaultsValue(YES);
150-
151-
EXPECT_FALSE([webView _isSmartListsEnabled]);
152-
EXPECT_TRUE([userDefaultsValue() boolValue]);
153-
154-
[webView _setSmartListsEnabled:YES];
155-
EXPECT_FALSE([webView _isSmartListsEnabled]);
156-
EXPECT_TRUE([userDefaultsValue() boolValue]);
157-
158-
// Case 3: user default => nil, preference => true
147+
// Case 2: user default => nil, preference => true
159148

160149
setSmartListsPreference(configuration.get(), YES);
161-
resetUserDefaults();
162150

163151
EXPECT_TRUE([webView _isSmartListsEnabled]);
164152
EXPECT_NULL(userDefaultsValue());
@@ -171,6 +159,18 @@ static void runTest(NSString *input, NSString *expectedHTML, NSString *expectedS
171159
EXPECT_TRUE([webView _isSmartListsEnabled]);
172160
EXPECT_TRUE([userDefaultsValue() boolValue]);
173161

162+
// Case 3: user default => true, preference => false
163+
164+
setSmartListsPreference(configuration.get(), NO);
165+
setUserDefaultsValue(YES);
166+
167+
EXPECT_FALSE([webView _isSmartListsEnabled]);
168+
EXPECT_TRUE([userDefaultsValue() boolValue]);
169+
170+
[webView _setSmartListsEnabled:YES];
171+
EXPECT_FALSE([webView _isSmartListsEnabled]);
172+
EXPECT_TRUE([userDefaultsValue() boolValue]);
173+
174174
// Case 4: user default => true, preference => true
175175

176176
setSmartListsPreference(configuration.get(), YES);

0 commit comments

Comments
 (0)