Title: [256079] trunk/Tools
Revision
256079
Author
wenson_hs...@apple.com
Date
2020-02-07 16:39:28 -0800 (Fri, 07 Feb 2020)

Log Message

Several iOS API tests that call -makeKeyWindow assert after r255907
https://bugs.webkit.org/show_bug.cgi?id=207411

Reviewed by Tim Horton.

r255907 asserted in -makeKeyWindow that the shared UIApplication exists. While this was guaranteed for all call
sites of -makeKeyWindow from API tests, -makeKeyWindow may also be invoked from within UIKit code; in this case,
nothing guarantees that the application has been initialized, and we end up hitting this assertion. To fix this,
replace the assertion with logic to bootstrap the shared UIApplication (if it didn't already exist).

* TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
(TestWebKitAPI::TEST):
(TestWebKitAPI::overrideBundleIdentifier): Deleted.
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(overrideBundleIdentifier):
(setOverriddenApplicationKeyWindow):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (256078 => 256079)


--- trunk/Tools/ChangeLog	2020-02-08 00:33:09 UTC (rev 256078)
+++ trunk/Tools/ChangeLog	2020-02-08 00:39:28 UTC (rev 256079)
@@ -1,3 +1,22 @@
+2020-02-07  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Several iOS API tests that call -makeKeyWindow assert after r255907
+        https://bugs.webkit.org/show_bug.cgi?id=207411
+
+        Reviewed by Tim Horton.
+
+        r255907 asserted in -makeKeyWindow that the shared UIApplication exists. While this was guaranteed for all call
+        sites of -makeKeyWindow from API tests, -makeKeyWindow may also be invoked from within UIKit code; in this case,
+        nothing guarantees that the application has been initialized, and we end up hitting this assertion. To fix this,
+        replace the assertion with logic to bootstrap the shared UIApplication (if it didn't already exist).
+
+        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
+        (TestWebKitAPI::TEST):
+        (TestWebKitAPI::overrideBundleIdentifier): Deleted.
+        * TestWebKitAPI/cocoa/TestWKWebView.mm:
+        (overrideBundleIdentifier):
+        (setOverriddenApplicationKeyWindow):
+
 2020-02-07  Jonathan Bedard  <jbed...@apple.com>
 
         TestWebKitAPI: Disable legacy ActionSheet tests on Catalyst

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm (256078 => 256079)


--- trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm	2020-02-08 00:33:09 UTC (rev 256078)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm	2020-02-08 00:39:28 UTC (rev 256079)
@@ -630,17 +630,8 @@
     EXPECT_TRUE(contentView.supportsImagePaste);
 }
 
-static NSString *overrideBundleIdentifier()
-{
-    return @"com.apple.TestWebKitAPI";
-}
-
 TEST(KeyboardInputTests, SuppressSoftwareKeyboard)
 {
-    InstanceMethodSwizzler bundleIdentifierSwizzler(NSBundle.class, @selector(bundleIdentifier), reinterpret_cast<IMP>(overrideBundleIdentifier));
-    UIApplicationInitialize();
-    UIApplicationInstantiateSingleton(UIApplication.class);
-
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     [webView _setSuppressSoftwareKeyboard:YES];
     [[webView window] makeKeyWindow];

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm (256078 => 256079)


--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm	2020-02-08 00:33:09 UTC (rev 256078)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm	2020-02-08 00:39:28 UTC (rev 256079)
@@ -312,12 +312,22 @@
 static NeverDestroyed<std::unique_ptr<InstanceMethodSwizzler>> gApplicationKeyWindowSwizzler;
 static NeverDestroyed<std::unique_ptr<InstanceMethodSwizzler>> gSharedApplicationSwizzler;
 
+static NSString *overrideBundleIdentifier()
+{
+    return @"com.apple.TestWebKitAPI";
+}
+
 static void setOverriddenApplicationKeyWindow(UIWindow *window)
 {
     if (gOverriddenApplicationKeyWindow.get() == window)
         return;
 
-    ASSERT(UIApplication.sharedApplication);
+    if (!UIApplication.sharedApplication) {
+        InstanceMethodSwizzler bundleIdentifierSwizzler(NSBundle.class, @selector(bundleIdentifier), reinterpret_cast<IMP>(overrideBundleIdentifier));
+        UIApplicationInitialize();
+        UIApplicationInstantiateSingleton(UIApplication.class);
+    }
+
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
         gApplicationKeyWindowSwizzler.get() = makeUnique<InstanceMethodSwizzler>(UIApplication.class, @selector(keyWindow), reinterpret_cast<IMP>(applicationKeyWindowOverride));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to