From c889e14d4c53bdaa6f0cc41f8fc23cc4fed57a4d Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Sat, 23 Sep 2023 04:43:21 -0700 Subject: [PATCH] [ios] Fix default assets url (flutter/engine#46214) When reverting the default asset url code, the old "flutter_assets" path was also copied in https://github.com/flutter/engine/pull/46073 This PR uses the correct URL. Although I'm unsure why the video player test passed before my change for the asset urls. I'm going to take another look at it but meanwhile this PR can unblock the roll once rolled into the framework. fixes of https://github.com/flutter/flutter/issues/135323 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../framework/Source/FlutterNSBundleUtils.mm | 2 +- .../Source/FlutterDartProjectTest.mm | 106 +++++++++++++++++- 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm b/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm index 4198fd33e02..9582f94e266 100644 --- a/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm +++ b/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm @@ -54,7 +54,7 @@ NSBundle* FLTFrameworkBundleWithIdentifier(NSString* flutterFrameworkBundleID) { } NSString* FLTAssetPath(NSBundle* bundle) { - return [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"] ?: @"flutter_assets"; + return [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"] ?: kDefaultAssetPath; } NSString* FLTAssetsPathFromBundle(NSBundle* bundle) { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm index 19774d21bc5..aecab91f005 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm @@ -102,14 +102,116 @@ FLUTTER_ASSERT_ARC id mockBundle = OCMClassMock([NSBundle class]); id mockMainBundle = OCMPartialMock([NSBundle mainBundle]); NSString* resultAssetsPath = @"path/to/foo/assets"; - OCMStub([mockBundle pathForResource:@"flutter_assets" ofType:@""]).andReturn(nil); - OCMStub([mockMainBundle pathForResource:@"flutter_assets" ofType:@""]) + OCMStub([mockBundle pathForResource:@"Frameworks/App.framework/flutter_assets" ofType:@""]) + .andReturn(nil); + OCMStub([mockMainBundle pathForResource:@"Frameworks/App.framework/flutter_assets" ofType:@""]) .andReturn(resultAssetsPath); NSString* path = FLTAssetsPathFromBundle(mockBundle); XCTAssertEqualObjects(path, @"path/to/foo/assets"); } } +- (void)testFLTAssetPathReturnsTheCorrectValue { + { + // Found assets path in info.plist + id mockBundle = OCMClassMock([NSBundle class]); + OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(@"foo/assets"); + XCTAssertEqualObjects(FLTAssetPath(mockBundle), @"foo/assets"); + } + { + // No assets path in info.plist, use default value + id mockBundle = OCMClassMock([NSBundle class]); + OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(nil); + XCTAssertEqualObjects(FLTAssetPath(mockBundle), kDefaultAssetPath); + } +} + +- (void)testLookUpForAssets { + { + id mockBundle = OCMPartialMock([NSBundle mainBundle]); + // Found assets path in info.plist + OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(@"foo/assets"); + NSString* assetsPath = [FlutterDartProject lookupKeyForAsset:@"bar"]; + // This is testing public API, changing this assert is likely to break plugins. + XCTAssertEqualObjects(assetsPath, @"foo/assets/bar"); + [mockBundle stopMocking]; + } + { + id mockBundle = OCMPartialMock([NSBundle mainBundle]); + // No assets path in info.plist, use default value + OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(nil); + NSString* assetsPath = [FlutterDartProject lookupKeyForAsset:@"bar"]; + // This is testing public API, changing this assert is likely to break plugins. + XCTAssertEqualObjects(assetsPath, @"Frameworks/App.framework/flutter_assets/bar"); + [mockBundle stopMocking]; + } +} + +- (void)testLookUpForAssetsFromBundle { + { + id mockBundle = OCMClassMock([NSBundle class]); + // Found assets path in info.plist + OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(@"foo/assets"); + NSString* assetsPath = [FlutterDartProject lookupKeyForAsset:@"bar" fromBundle:mockBundle]; + // This is testing public API, changing this assert is likely to break plugins. + XCTAssertEqualObjects(assetsPath, @"foo/assets/bar"); + } + { + // No assets path in info.plist, use default value + id mockBundle = OCMClassMock([NSBundle class]); + OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(nil); + NSString* assetsPath = [FlutterDartProject lookupKeyForAsset:@"bar" fromBundle:mockBundle]; + // This is testing public API, changing this assert is likely to break plugins. + XCTAssertEqualObjects(assetsPath, @"Frameworks/App.framework/flutter_assets/bar"); + } +} + +- (void)testLookUpForAssetsFromPackage { + { + id mockBundle = OCMPartialMock([NSBundle mainBundle]); + // Found assets path in info.plist + OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(@"foo/assets"); + NSString* assetsPath = [FlutterDartProject lookupKeyForAsset:@"bar" fromPackage:@"bar_package"]; + // This is testing public API, changing this assert is likely to break plugins. + XCTAssertEqualObjects(assetsPath, @"foo/assets/packages/bar_package/bar"); + [mockBundle stopMocking]; + } + { + id mockBundle = OCMPartialMock([NSBundle mainBundle]); + // No assets path in info.plist, use default value + OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(nil); + NSString* assetsPath = [FlutterDartProject lookupKeyForAsset:@"bar" fromPackage:@"bar_package"]; + // This is testing public API, changing this assert is likely to break plugins. + XCTAssertEqualObjects(assetsPath, + @"Frameworks/App.framework/flutter_assets/packages/bar_package/bar"); + [mockBundle stopMocking]; + } +} + +- (void)testLookUpForAssetsFromPackageFromBundle { + { + id mockBundle = OCMClassMock([NSBundle class]); + // Found assets path in info.plist + OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(@"foo/assets"); + NSString* assetsPath = [FlutterDartProject lookupKeyForAsset:@"bar" + fromPackage:@"bar_package" + fromBundle:mockBundle]; + // This is testing public API, changing this assert is likely to break plugins. + XCTAssertEqualObjects(assetsPath, @"foo/assets/packages/bar_package/bar"); + } + { + id mockBundle = OCMClassMock([NSBundle class]); + // No assets path in info.plist, use default value + OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(nil); + NSString* assetsPath = [FlutterDartProject lookupKeyForAsset:@"bar" + fromPackage:@"bar_package" + fromBundle:mockBundle]; + // This is testing public API, changing this assert is likely to break plugins. + XCTAssertEqualObjects(assetsPath, + @"Frameworks/App.framework/flutter_assets/packages/bar_package/bar"); + } +} + - (void)testDisableImpellerSettingIsCorrectlyParsed { id mockMainBundle = OCMPartialMock([NSBundle mainBundle]); OCMStub([mockMainBundle objectForInfoDictionaryKey:@"FLTEnableImpeller"]).andReturn(@"NO");