Title: [256635] branches/safari-609-branch/Tools
Revision
256635
Author
ryanhad...@apple.com
Date
2020-02-14 13:13:36 -0800 (Fri, 14 Feb 2020)

Log Message

Cherry-pick r256297. rdar://problem/59442308

    [iOS] Non-internal API test runners frequently crash due to Objective-C exceptions
    https://bugs.webkit.org/show_bug.cgi?id=207525
    <rdar://problem/59110543>

    Reviewed by Tim Horton.

    After the fix for <rdar://problem/56301207>, some scroll view content offset changes will attempt to call into
    CoreAnalytics API to try and report data about scrolling velocities. In the iOS 13.3 simulator, this involves
    creating a dictionary, of which one of the keys is the bundle identifier of the application. The value is
    unconditionally inserted into the dictionary. Since TestWebKitAPI does not run in the context of a
    UIApplication, the bundle identifier (that is, `NSBundle.mainBundle.bundleIdentifier`) ends up being nil,
    causing us to crash upon trying to create the dictionary.

    While it would make things easier, we can't just swizzle -bundleIdentifier for the entirely of every test, since
    some tests expect the bundle identifier to be nil (or call into system frameworks that expect the bundle
    identifier to be nil). These tests fail or time out when -bundleIdentifier is unconditionally swizzled
    throughout the test run. To work around this bug for the time being, simply pretend that we have a bundle
    identifier when running API tests on iOS, by swizzling `-[NSBundle bundleIdentifier]` to return a string at the
    beginning of each API test.

    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
    * TestWebKitAPI/cocoa/TestWKWebView.mm:
    (overrideBundleIdentifier):

    Move this to the top of the file, so it can be shared.

    (+[WKWebView initialize]):

    At the start of each test, force UIKit to cache a fake value for `_UIMainBundleIdentifier()` by invoking an
    internal class method that calls into the internal helper function, with no other side effects.

    * TestWebKitAPI/ios/UIKitSPI.h:

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256297 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-609-branch/Tools/ChangeLog (256634 => 256635)


--- branches/safari-609-branch/Tools/ChangeLog	2020-02-14 21:09:02 UTC (rev 256634)
+++ branches/safari-609-branch/Tools/ChangeLog	2020-02-14 21:13:36 UTC (rev 256635)
@@ -1,5 +1,79 @@
 2020-02-13  Ryan Haddad  <ryanhad...@apple.com>
 
+        Cherry-pick r256297. rdar://problem/59442308
+
+    [iOS] Non-internal API test runners frequently crash due to Objective-C exceptions
+    https://bugs.webkit.org/show_bug.cgi?id=207525
+    <rdar://problem/59110543>
+    
+    Reviewed by Tim Horton.
+    
+    After the fix for <rdar://problem/56301207>, some scroll view content offset changes will attempt to call into
+    CoreAnalytics API to try and report data about scrolling velocities. In the iOS 13.3 simulator, this involves
+    creating a dictionary, of which one of the keys is the bundle identifier of the application. The value is
+    unconditionally inserted into the dictionary. Since TestWebKitAPI does not run in the context of a
+    UIApplication, the bundle identifier (that is, `NSBundle.mainBundle.bundleIdentifier`) ends up being nil,
+    causing us to crash upon trying to create the dictionary.
+    
+    While it would make things easier, we can't just swizzle -bundleIdentifier for the entirely of every test, since
+    some tests expect the bundle identifier to be nil (or call into system frameworks that expect the bundle
+    identifier to be nil). These tests fail or time out when -bundleIdentifier is unconditionally swizzled
+    throughout the test run. To work around this bug for the time being, simply pretend that we have a bundle
+    identifier when running API tests on iOS, by swizzling `-[NSBundle bundleIdentifier]` to return a string at the
+    beginning of each API test.
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/cocoa/TestWKWebView.mm:
+    (overrideBundleIdentifier):
+    
+    Move this to the top of the file, so it can be shared.
+    
+    (+[WKWebView initialize]):
+    
+    At the start of each test, force UIKit to cache a fake value for `_UIMainBundleIdentifier()` by invoking an
+    internal class method that calls into the internal helper function, with no other side effects.
+    
+    * TestWebKitAPI/ios/UIKitSPI.h:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256297 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-02-11  Wenson Hsieh  <wenson_hs...@apple.com>
+
+            [iOS] Non-internal API test runners frequently crash due to Objective-C exceptions
+            https://bugs.webkit.org/show_bug.cgi?id=207525
+            <rdar://problem/59110543>
+
+            Reviewed by Tim Horton.
+
+            After the fix for <rdar://problem/56301207>, some scroll view content offset changes will attempt to call into
+            CoreAnalytics API to try and report data about scrolling velocities. In the iOS 13.3 simulator, this involves
+            creating a dictionary, of which one of the keys is the bundle identifier of the application. The value is
+            unconditionally inserted into the dictionary. Since TestWebKitAPI does not run in the context of a
+            UIApplication, the bundle identifier (that is, `NSBundle.mainBundle.bundleIdentifier`) ends up being nil,
+            causing us to crash upon trying to create the dictionary.
+
+            While it would make things easier, we can't just swizzle -bundleIdentifier for the entirely of every test, since
+            some tests expect the bundle identifier to be nil (or call into system frameworks that expect the bundle
+            identifier to be nil). These tests fail or time out when -bundleIdentifier is unconditionally swizzled
+            throughout the test run. To work around this bug for the time being, simply pretend that we have a bundle
+            identifier when running API tests on iOS, by swizzling `-[NSBundle bundleIdentifier]` to return a string at the
+            beginning of each API test.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/cocoa/TestWKWebView.mm:
+            (overrideBundleIdentifier):
+
+            Move this to the top of the file, so it can be shared.
+
+            (+[WKWebView initialize]):
+
+            At the start of each test, force UIKit to cache a fake value for `_UIMainBundleIdentifier()` by invoking an
+            internal class method that calls into the internal helper function, with no other side effects.
+
+            * TestWebKitAPI/ios/UIKitSPI.h:
+
+2020-02-13  Ryan Haddad  <ryanhad...@apple.com>
+
         Unreviewed attempt to fix the TestWebKitAPI build.
 
         * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEvaluateJavaScript.mm:

Modified: branches/safari-609-branch/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm (256634 => 256635)


--- branches/safari-609-branch/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm	2020-02-14 21:09:02 UTC (rev 256634)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm	2020-02-14 21:13:36 UTC (rev 256635)
@@ -27,6 +27,7 @@
 #import "TestWKWebView.h"
 
 #import "ClassMethodSwizzler.h"
+#import "InstanceMethodSwizzler.h"
 #import "TestNavigationDelegate.h"
 #import "Utilities.h"
 
@@ -49,6 +50,11 @@
 SOFT_LINK_FRAMEWORK(UIKit)
 SOFT_LINK_CLASS(UIKit, UIWindow)
 
+static NSString *overrideBundleIdentifier(id, SEL)
+{
+    return @"com.apple.TestWebKitAPI";
+}
+
 @implementation WKWebView (WKWebViewTestingQuirks)
 
 // TestWebKitAPI is currently not a UIApplication so we are unable to track if it is in
@@ -64,6 +70,22 @@
 
 @implementation WKWebView (TestWebKitAPI)
 
+#if PLATFORM(IOS_FAMILY)
+
++ (void)initialize
+{
+    // FIXME: This hack should no longer be necessary on builds that have the fix for <rdar://problem/56790195>.
+    // Calling +displayIdentifier will guarantee a call to an internal UIKit helper method that caches the fake
+    // bundle name "com.apple.TestWebKitAPI" for the rest of the process' lifetime. This allows us to avoid crashing
+    // under -[UIScrollView setContentOffset:animated:] due to telemetry code that requires a bundle identifier.
+    // Note that this swizzling is temporary, since unconditionally swizzling -[NSBundle bundleIdentifier] for the
+    // entirely of the test causes other tests to fail or time out.
+    InstanceMethodSwizzler bundleIdentifierSwizzler(NSBundle.class, @selector(bundleIdentifier), reinterpret_cast<IMP>(overrideBundleIdentifier));
+    [UIApplication displayIdentifier];
+}
+
+#endif // PLATFORM(IOS_FAMILY)
+
 - (void)loadTestPageNamed:(NSString *)pageName
 {
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:pageName withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];

Modified: branches/safari-609-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h (256634 => 256635)


--- branches/safari-609-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h	2020-02-14 21:09:02 UTC (rev 256634)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h	2020-02-14 21:13:36 UTC (rev 256635)
@@ -252,4 +252,8 @@
 - (void)_share:(id)sender;
 @end
 
+@interface UIApplication (Internal)
++ (NSString *)displayIdentifier;
+@end
+
 #endif // PLATFORM(IOS_FAMILY)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to