Changeset 256635 in webkit


Ignore:
Timestamp:
Feb 14, 2020 1:13:36 PM (4 years ago)
Author:
Ryan Haddad
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

Location:
branches/safari-609-branch/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-609-branch/Tools/ChangeLog

    r256565 r256635  
     12020-02-13  Ryan Haddad  <ryanhaddad@apple.com>
     2
     3        Cherry-pick r256297. rdar://problem/59442308
     4
     5    [iOS] Non-internal API test runners frequently crash due to Objective-C exceptions
     6    https://bugs.webkit.org/show_bug.cgi?id=207525
     7    <rdar://problem/59110543>
     8   
     9    Reviewed by Tim Horton.
     10   
     11    After the fix for <rdar://problem/56301207>, some scroll view content offset changes will attempt to call into
     12    CoreAnalytics API to try and report data about scrolling velocities. In the iOS 13.3 simulator, this involves
     13    creating a dictionary, of which one of the keys is the bundle identifier of the application. The value is
     14    unconditionally inserted into the dictionary. Since TestWebKitAPI does not run in the context of a
     15    UIApplication, the bundle identifier (that is, `NSBundle.mainBundle.bundleIdentifier`) ends up being nil,
     16    causing us to crash upon trying to create the dictionary.
     17   
     18    While it would make things easier, we can't just swizzle -bundleIdentifier for the entirely of every test, since
     19    some tests expect the bundle identifier to be nil (or call into system frameworks that expect the bundle
     20    identifier to be nil). These tests fail or time out when -bundleIdentifier is unconditionally swizzled
     21    throughout the test run. To work around this bug for the time being, simply pretend that we have a bundle
     22    identifier when running API tests on iOS, by swizzling `-[NSBundle bundleIdentifier]` to return a string at the
     23    beginning of each API test.
     24   
     25    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     26    * TestWebKitAPI/cocoa/TestWKWebView.mm:
     27    (overrideBundleIdentifier):
     28   
     29    Move this to the top of the file, so it can be shared.
     30   
     31    (+[WKWebView initialize]):
     32   
     33    At the start of each test, force UIKit to cache a fake value for `_UIMainBundleIdentifier()` by invoking an
     34    internal class method that calls into the internal helper function, with no other side effects.
     35   
     36    * TestWebKitAPI/ios/UIKitSPI.h:
     37   
     38    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256297 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     39
     40    2020-02-11  Wenson Hsieh  <wenson_hsieh@apple.com>
     41
     42            [iOS] Non-internal API test runners frequently crash due to Objective-C exceptions
     43            https://bugs.webkit.org/show_bug.cgi?id=207525
     44            <rdar://problem/59110543>
     45
     46            Reviewed by Tim Horton.
     47
     48            After the fix for <rdar://problem/56301207>, some scroll view content offset changes will attempt to call into
     49            CoreAnalytics API to try and report data about scrolling velocities. In the iOS 13.3 simulator, this involves
     50            creating a dictionary, of which one of the keys is the bundle identifier of the application. The value is
     51            unconditionally inserted into the dictionary. Since TestWebKitAPI does not run in the context of a
     52            UIApplication, the bundle identifier (that is, `NSBundle.mainBundle.bundleIdentifier`) ends up being nil,
     53            causing us to crash upon trying to create the dictionary.
     54
     55            While it would make things easier, we can't just swizzle -bundleIdentifier for the entirely of every test, since
     56            some tests expect the bundle identifier to be nil (or call into system frameworks that expect the bundle
     57            identifier to be nil). These tests fail or time out when -bundleIdentifier is unconditionally swizzled
     58            throughout the test run. To work around this bug for the time being, simply pretend that we have a bundle
     59            identifier when running API tests on iOS, by swizzling `-[NSBundle bundleIdentifier]` to return a string at the
     60            beginning of each API test.
     61
     62            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     63            * TestWebKitAPI/cocoa/TestWKWebView.mm:
     64            (overrideBundleIdentifier):
     65
     66            Move this to the top of the file, so it can be shared.
     67
     68            (+[WKWebView initialize]):
     69
     70            At the start of each test, force UIKit to cache a fake value for `_UIMainBundleIdentifier()` by invoking an
     71            internal class method that calls into the internal helper function, with no other side effects.
     72
     73            * TestWebKitAPI/ios/UIKitSPI.h:
     74
    1752020-02-13  Ryan Haddad  <ryanhaddad@apple.com>
    276
  • branches/safari-609-branch/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

    r253950 r256635  
    2828
    2929#import "ClassMethodSwizzler.h"
     30#import "InstanceMethodSwizzler.h"
    3031#import "TestNavigationDelegate.h"
    3132#import "Utilities.h"
     
    5051SOFT_LINK_CLASS(UIKit, UIWindow)
    5152
     53static NSString *overrideBundleIdentifier(id, SEL)
     54{
     55    return @"com.apple.TestWebKitAPI";
     56}
     57
    5258@implementation WKWebView (WKWebViewTestingQuirks)
    5359
     
    6470
    6571@implementation WKWebView (TestWebKitAPI)
     72
     73#if PLATFORM(IOS_FAMILY)
     74
     75+ (void)initialize
     76{
     77    // FIXME: This hack should no longer be necessary on builds that have the fix for <rdar://problem/56790195>.
     78    // Calling +displayIdentifier will guarantee a call to an internal UIKit helper method that caches the fake
     79    // bundle name "com.apple.TestWebKitAPI" for the rest of the process' lifetime. This allows us to avoid crashing
     80    // under -[UIScrollView setContentOffset:animated:] due to telemetry code that requires a bundle identifier.
     81    // Note that this swizzling is temporary, since unconditionally swizzling -[NSBundle bundleIdentifier] for the
     82    // entirely of the test causes other tests to fail or time out.
     83    InstanceMethodSwizzler bundleIdentifierSwizzler(NSBundle.class, @selector(bundleIdentifier), reinterpret_cast<IMP>(overrideBundleIdentifier));
     84    [UIApplication displayIdentifier];
     85}
     86
     87#endif // PLATFORM(IOS_FAMILY)
    6688
    6789- (void)loadTestPageNamed:(NSString *)pageName
  • branches/safari-609-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h

    r256559 r256635  
    253253@end
    254254
     255@interface UIApplication (Internal)
     256+ (NSString *)displayIdentifier;
     257@end
     258
    255259#endif // PLATFORM(IOS_FAMILY)
Note: See TracChangeset for help on using the changeset viewer.