5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
8 #include "flutter/common/constants.h"
25 - (void)testOldGenHeapSizeSetting {
27 int64_t old_gen_heap_size =
28 std::round([NSProcessInfo processInfo].physicalMemory * .48 / flutter::kMegaByteSizeInBytes);
29 XCTAssertEqual(project.
settings.old_gen_heap_size, old_gen_heap_size);
32 - (void)testResourceCacheMaxBytesThresholdSetting {
34 CGFloat scale = [UIScreen mainScreen].scale;
35 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width * scale;
36 CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height * scale;
37 size_t resource_cache_max_bytes_threshold = screenWidth * screenHeight * 12 * 4;
38 XCTAssertEqual(project.
settings.resource_cache_max_bytes_threshold,
39 resource_cache_max_bytes_threshold);
42 - (void)testMainBundleSettingsAreCorrectlyParsed {
43 NSBundle* mainBundle = [NSBundle mainBundle];
44 NSDictionary* appTransportSecurity =
45 [mainBundle objectForInfoDictionaryKey:@"NSAppTransportSecurity"];
47 XCTAssertEqualObjects(
48 @"[[\"invalid-site.com\
",true,false],[\"sub.invalid-site.com\",false,false]]",
52 - (void)testLeakDartVMSettingsAreCorrectlyParsed {
54 NSBundle* mainBundle = [NSBundle mainBundle];
55 NSNumber* leakDartVM = [mainBundle objectForInfoDictionaryKey:@"FLTLeakDartVM"];
56 XCTAssertEqual(leakDartVM.boolValue, NO);
60 XCTAssertEqual(settings.leak_vm, NO);
63 - (void)testFLTFrameworkBundleInternalWhenBundleIsNotPresent {
69 - (void)testFLTFrameworkBundleInternalWhenBundleIsPresent {
70 NSString* presentBundleID =
@"io.flutter.flutter";
73 XCTAssertNotNil(found);
76 - (void)testFLTGetApplicationBundleWhenCurrentTargetIsNotExtension {
78 XCTAssertEqual(bundle, [NSBundle mainBundle]);
81 - (void)testFLTGetApplicationBundleWhenCurrentTargetIsExtension {
82 id mockMainBundle = OCMPartialMock([NSBundle mainBundle]);
83 NSURL* url = [[NSBundle mainBundle].bundleURL URLByAppendingPathComponent:@"foo/ext.appex"];
84 OCMStub([mockMainBundle bundleURL]).andReturn(url);
86 [mockMainBundle stopMocking];
87 XCTAssertEqualObjects(bundle.bundleURL, [NSBundle mainBundle].bundleURL);
90 - (void)testFLTAssetsURLFromBundle {
93 id mockBundle = OCMClassMock([NSBundle
class]);
94 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(
@"foo/assets");
95 NSString* resultAssetsPath =
@"path/to/foo/assets";
96 OCMStub([mockBundle pathForResource:
@"foo/assets" ofType:nil]).andReturn(resultAssetsPath);
98 XCTAssertEqualObjects(path,
@"path/to/foo/assets");
102 id mockBundle = OCMClassMock([NSBundle
class]);
103 id mockMainBundle = OCMPartialMock(NSBundle.mainBundle);
104 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(
@"foo/assets");
105 OCMStub([mockMainBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(nil);
106 NSString* resultAssetsPath =
@"path/to/foo/assets";
107 OCMStub([mockBundle pathForResource:
@"foo/assets" ofType:nil]).andReturn(resultAssetsPath);
109 XCTAssertEqualObjects(path,
@"path/to/foo/assets");
110 [mockMainBundle stopMocking];
114 id mockBundle = OCMClassMock([NSBundle
class]);
115 id mockMainBundle = OCMPartialMock([NSBundle mainBundle]);
116 NSString* resultAssetsPath =
@"path/to/foo/assets";
117 OCMStub([mockBundle pathForResource:
@"Frameworks/App.framework/flutter_assets" ofType:nil])
119 OCMStub([mockMainBundle pathForResource:
@"Frameworks/App.framework/flutter_assets" ofType:nil])
120 .andReturn(resultAssetsPath);
122 XCTAssertEqualObjects(path,
@"path/to/foo/assets");
123 [mockMainBundle stopMocking];
127 - (void)testFLTAssetPathReturnsTheCorrectValue {
130 id mockBundle = OCMClassMock([NSBundle
class]);
131 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(
@"foo/assets");
132 XCTAssertEqualObjects(
FLTAssetPath(mockBundle),
@"foo/assets");
136 id mockBundle = OCMClassMock([NSBundle
class]);
137 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(nil);
142 - (void)testLookUpForAssets {
144 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
146 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(
@"foo/assets");
149 XCTAssertEqualObjects(assetsPath,
@"foo/assets/bar");
150 [mockBundle stopMocking];
153 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
155 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(nil);
158 XCTAssertEqualObjects(assetsPath,
@"Frameworks/App.framework/flutter_assets/bar");
159 [mockBundle stopMocking];
163 - (void)testLookUpForAssetsFromBundle {
165 id mockBundle = OCMClassMock([NSBundle
class]);
167 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(
@"foo/assets");
170 XCTAssertEqualObjects(assetsPath,
@"foo/assets/bar");
174 id mockBundle = OCMClassMock([NSBundle
class]);
175 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(nil);
178 XCTAssertEqualObjects(assetsPath,
@"Frameworks/App.framework/flutter_assets/bar");
182 - (void)testLookUpForAssetsFromPackage {
184 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
186 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(
@"foo/assets");
189 XCTAssertEqualObjects(assetsPath,
@"foo/assets/packages/bar_package/bar");
190 [mockBundle stopMocking];
193 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
195 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(nil);
198 XCTAssertEqualObjects(assetsPath,
199 @"Frameworks/App.framework/flutter_assets/packages/bar_package/bar");
200 [mockBundle stopMocking];
204 - (void)testLookUpForAssetsFromPackageFromBundle {
206 id mockBundle = OCMClassMock([NSBundle
class]);
208 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(
@"foo/assets");
213 XCTAssertEqualObjects(assetsPath,
@"foo/assets/packages/bar_package/bar");
216 id mockBundle = OCMClassMock([NSBundle
class]);
218 OCMStub([mockBundle objectForInfoDictionaryKey:
@"FLTAssetsPath"]).andReturn(nil);
223 XCTAssertEqualObjects(assetsPath,
224 @"Frameworks/App.framework/flutter_assets/packages/bar_package/bar");
228 - (void)testEnableDartAssertsCommandLineArgument {
229 id mockMainBundle = OCMPartialMock([NSBundle mainBundle]);
230 OCMStub([mockMainBundle objectForInfoDictionaryKey:
@"FLTEnableDartAsserts"]).andReturn(
@"YES");
231 id mockProcessInfo = OCMPartialMock([NSProcessInfo processInfo]);
232 NSArray* arguments = @[ @"process_name" ];
233 OCMStub([mockProcessInfo arguments]).andReturn(arguments);
237 XCTAssertEqual(settings.dart_flags.size(), 1u);
238 XCTAssertEqual(settings.dart_flags[0],
"--enable-asserts");
239 [mockMainBundle stopMocking];
242 - (void)testEnableTraceSystraceSettingIsCorrectlyParsed {
243 NSBundle* mainBundle = [NSBundle mainBundle];
244 NSNumber* enableTraceSystrace = [mainBundle objectForInfoDictionaryKey:@"FLTTraceSystrace"];
245 XCTAssertNotNil(enableTraceSystrace);
246 XCTAssertEqual(enableTraceSystrace.boolValue, NO);
248 XCTAssertEqual(settings.trace_systrace, NO);
251 - (void)testEnableDartProflingSettingIsCorrectlyParsed {
252 NSBundle* mainBundle = [NSBundle mainBundle];
253 NSNumber* enableTraceSystrace = [mainBundle objectForInfoDictionaryKey:@"FLTEnableDartProfiling"];
254 XCTAssertNotNil(enableTraceSystrace);
255 XCTAssertEqual(enableTraceSystrace.boolValue, NO);
257 XCTAssertEqual(settings.trace_systrace, NO);
260 - (void)testEmptySettingsAreCorrect {
261 XCTAssertFalse([
FlutterDartProject allowsArbitraryLoads:[[NSDictionary alloc] init]]);
262 XCTAssertEqualObjects(
@"", [
FlutterDartProject domainNetworkPolicy:[[NSDictionary alloc] init]]);
265 - (void)testAllowsArbitraryLoads {
266 XCTAssertFalse([
FlutterDartProject allowsArbitraryLoads:@{
@"NSAllowsArbitraryLoads" : @
false}]);
267 XCTAssertTrue([
FlutterDartProject allowsArbitraryLoads:@{
@"NSAllowsArbitraryLoads" : @
true}]);
270 - (void)testProperlyFormedExceptionDomains {
271 NSDictionary* domainInfoOne = @{
272 @"NSIncludesSubdomains" : @
false,
273 @"NSExceptionAllowsInsecureHTTPLoads" : @
true,
274 @"NSExceptionMinimumTLSVersion" :
@"4.0"
276 NSDictionary* domainInfoTwo = @{
277 @"NSIncludesSubdomains" : @
true,
278 @"NSExceptionAllowsInsecureHTTPLoads" : @
false,
279 @"NSExceptionMinimumTLSVersion" :
@"4.0"
281 NSDictionary* domainInfoThree = @{
282 @"NSIncludesSubdomains" : @
false,
283 @"NSExceptionAllowsInsecureHTTPLoads" : @
true,
284 @"NSExceptionMinimumTLSVersion" :
@"4.0"
286 NSDictionary* exceptionDomains = @{
287 @"domain.name" : domainInfoOne,
288 @"sub.domain.name" : domainInfoTwo,
289 @"sub.two.domain.name" : domainInfoThree
291 NSDictionary* appTransportSecurity = @{
@"NSExceptionDomains" : exceptionDomains};
292 XCTAssertEqualObjects(
@"[[\"domain.name\
",false,true],[\"sub.domain.name\",true,false],"
293 @"[\"sub.two.domain.name\
",false,true]]",
297 - (void)testExceptionDomainsWithMissingInfo {
298 NSDictionary* domainInfoOne = @{
@"NSExceptionMinimumTLSVersion" :
@"4.0"};
299 NSDictionary* domainInfoTwo = @{
300 @"NSIncludesSubdomains" : @
true,
302 NSDictionary* domainInfoThree = @{};
303 NSDictionary* exceptionDomains = @{
304 @"domain.name" : domainInfoOne,
305 @"sub.domain.name" : domainInfoTwo,
306 @"sub.two.domain.name" : domainInfoThree
308 NSDictionary* appTransportSecurity = @{
@"NSExceptionDomains" : exceptionDomains};
309 XCTAssertEqualObjects(
@"[[\"domain.name\
",false,false],[\"sub.domain.name\",true,false],"
310 @"[\"sub.two.domain.name\
",false,false]]",