Several key event tests in fast/events/ios are failing after <rdar://problem/62197116>
https://bugs.webkit.org/show_bug.cgi?id=213821
<rdar://problem/64821309>

Reviewed by Megan Gardner.

Source/WebKit:

Add an SPI method declaration.

* Platform/spi/ios/UIKitSPI.h:

Tools:

After the UIKit changes in <rdar://problem/62197116>, double tapping the Option key now enters dictation mode
by default, and additionally displays a modal popup prompting the user to set up dictation. Both of these
behaviors interfere with layout tests that attempt to press the option key twice in rapid succession, causing
them to time out or fail.

Fix this by setting the default that determines the modifier key to use as the dictation shortcut to -1, which
disables the dictation keyboard shortcut altogether.

* WebKitTestRunner/ios/TestControllerIOS.mm:
(WTR::TestController::platformResetStateToConsistentValues):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@263784 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index d735739..a6198d1 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,3 +1,15 @@
+2020-06-30  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Several key event tests in fast/events/ios are failing after <rdar://problem/62197116>
+        https://bugs.webkit.org/show_bug.cgi?id=213821
+        <rdar://problem/64821309>
+
+        Reviewed by Megan Gardner.
+
+        Add an SPI method declaration.
+
+        * Platform/spi/ios/UIKitSPI.h:
+
 2020-06-30  Jiewen Tan  <jiewen_tan@apple.com>
 
         [WebAuthn] Remove whitelistedRpId
diff --git a/Source/WebKit/Platform/spi/ios/UIKitSPI.h b/Source/WebKit/Platform/spi/ios/UIKitSPI.h
index 0e41809..484bf89 100644
--- a/Source/WebKit/Platform/spi/ios/UIKitSPI.h
+++ b/Source/WebKit/Platform/spi/ios/UIKitSPI.h
@@ -1064,6 +1064,7 @@
 + (UIKeyboardPreferencesController *)sharedPreferencesController;
 - (void)setValue:(id)value forPreferenceKey:(NSString *)key;
 - (BOOL)boolForPreferenceKey:(NSString *)key;
+- (id)valueForPreferenceKey:(NSString *)key;
 @end
 
 @interface UIMenuItem (UIMenuController_SPI)
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index a6e1868..52b08a8 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,22 @@
+2020-06-30  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Several key event tests in fast/events/ios are failing after <rdar://problem/62197116>
+        https://bugs.webkit.org/show_bug.cgi?id=213821
+        <rdar://problem/64821309>
+
+        Reviewed by Megan Gardner.
+
+        After the UIKit changes in <rdar://problem/62197116>, double tapping the Option key now enters dictation mode
+        by default, and additionally displays a modal popup prompting the user to set up dictation. Both of these
+        behaviors interfere with layout tests that attempt to press the option key twice in rapid succession, causing
+        them to time out or fail.
+
+        Fix this by setting the default that determines the modifier key to use as the dictation shortcut to -1, which
+        disables the dictation keyboard shortcut altogether.
+
+        * WebKitTestRunner/ios/TestControllerIOS.mm:
+        (WTR::TestController::platformResetStateToConsistentValues):
+
 2020-06-30  Geoffrey Garen  <ggaren@apple.com>
 
         [Cocoa] [GTK] RunLoop::Timer::isActive() is incorrect for timers while they are firing
diff --git a/Tools/WebKitTestRunner/ios/TestControllerIOS.mm b/Tools/WebKitTestRunner/ios/TestControllerIOS.mm
index aac7a35..240f7a1 100644
--- a/Tools/WebKitTestRunner/ios/TestControllerIOS.mm
+++ b/Tools/WebKitTestRunner/ios/TestControllerIOS.mm
@@ -159,10 +159,19 @@
     [[UIApplication sharedApplication] _cancelAllTouches];
     [[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait animated:NO];
     UIKeyboardPreferencesController *keyboardPreferences = UIKeyboardPreferencesController.sharedPreferencesController;
-    NSString *automaticMinimizationEnabledPreferenceKey = @"AutomaticMinimizationEnabled";
+    auto globalPreferencesDomainName = CFSTR("com.apple.Preferences");
+    auto automaticMinimizationEnabledPreferenceKey = @"AutomaticMinimizationEnabled";
     if (![keyboardPreferences boolForPreferenceKey:automaticMinimizationEnabledPreferenceKey]) {
         [keyboardPreferences setValue:@YES forPreferenceKey:automaticMinimizationEnabledPreferenceKey];
-        CFPreferencesSetAppValue((__bridge CFStringRef)automaticMinimizationEnabledPreferenceKey, kCFBooleanTrue, CFSTR("com.apple.Preferences"));
+        CFPreferencesSetAppValue((__bridge CFStringRef)automaticMinimizationEnabledPreferenceKey, kCFBooleanTrue, globalPreferencesDomainName);
+    }
+
+    // Disables the dictation keyboard shortcut for testing.
+    auto dictationKeyboardShortcutPreferenceKey = @"HWKeyboardDictationShortcut";
+    auto dictationKeyboardShortcutValueForTesting = @(-1);
+    if (![dictationKeyboardShortcutValueForTesting isEqual:[keyboardPreferences valueForPreferenceKey:dictationKeyboardShortcutPreferenceKey]]) {
+        [keyboardPreferences setValue:dictationKeyboardShortcutValueForTesting forPreferenceKey:dictationKeyboardShortcutPreferenceKey];
+        CFPreferencesSetAppValue((__bridge CFStringRef)dictationKeyboardShortcutPreferenceKey, (__bridge CFNumberRef)dictationKeyboardShortcutValueForTesting, globalPreferencesDomainName);
     }
 
     GSEventSetHardwareKeyboardAttached(true, 0);