Flutter Engine
FlutterDartProjectTest.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
7 
8 #include "flutter/common/constants.h"
9 #include "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
10 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"
11 
13 
14 @interface FlutterDartProjectTest : XCTestCase
15 @end
16 
17 @implementation FlutterDartProjectTest
18 
19 - (void)setUp {
20 }
21 
22 - (void)tearDown {
23 }
24 
25 - (void)testOldGenHeapSizeSetting {
26  FlutterDartProject* project = [[FlutterDartProject alloc] init];
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);
30 }
31 
32 - (void)testMainBundleSettingsAreCorrectlyParsed {
33  NSBundle* mainBundle = [NSBundle mainBundle];
34  NSDictionary* appTransportSecurity =
35  [mainBundle objectForInfoDictionaryKey:@"NSAppTransportSecurity"];
36  XCTAssertTrue([FlutterDartProject allowsArbitraryLoads:appTransportSecurity]);
37  XCTAssertEqualObjects(
38  @"[[\"invalid-site.com\",true,false],[\"sub.invalid-site.com\",false,false]]",
39  [FlutterDartProject domainNetworkPolicy:appTransportSecurity]);
40 }
41 
42 - (void)testEmptySettingsAreCorrect {
43  XCTAssertFalse([FlutterDartProject allowsArbitraryLoads:[[NSDictionary alloc] init]]);
44  XCTAssertEqualObjects(@"", [FlutterDartProject domainNetworkPolicy:[[NSDictionary alloc] init]]);
45 }
46 
47 - (void)testAllowsArbitraryLoads {
48  XCTAssertFalse([FlutterDartProject allowsArbitraryLoads:@{@"NSAllowsArbitraryLoads" : @false}]);
49  XCTAssertTrue([FlutterDartProject allowsArbitraryLoads:@{@"NSAllowsArbitraryLoads" : @true}]);
50 }
51 
52 - (void)testProperlyFormedExceptionDomains {
53  NSDictionary* domainInfoOne = @{
54  @"NSIncludesSubdomains" : @false,
55  @"NSExceptionAllowsInsecureHTTPLoads" : @true,
56  @"NSExceptionMinimumTLSVersion" : @"4.0"
57  };
58  NSDictionary* domainInfoTwo = @{
59  @"NSIncludesSubdomains" : @true,
60  @"NSExceptionAllowsInsecureHTTPLoads" : @false,
61  @"NSExceptionMinimumTLSVersion" : @"4.0"
62  };
63  NSDictionary* domainInfoThree = @{
64  @"NSIncludesSubdomains" : @false,
65  @"NSExceptionAllowsInsecureHTTPLoads" : @true,
66  @"NSExceptionMinimumTLSVersion" : @"4.0"
67  };
68  NSDictionary* exceptionDomains = @{
69  @"domain.name" : domainInfoOne,
70  @"sub.domain.name" : domainInfoTwo,
71  @"sub.two.domain.name" : domainInfoThree
72  };
73  NSDictionary* appTransportSecurity = @{@"NSExceptionDomains" : exceptionDomains};
74  XCTAssertEqualObjects(@"[[\"domain.name\",false,true],[\"sub.domain.name\",true,false],"
75  @"[\"sub.two.domain.name\",false,true]]",
76  [FlutterDartProject domainNetworkPolicy:appTransportSecurity]);
77 }
78 
79 - (void)testExceptionDomainsWithMissingInfo {
80  NSDictionary* domainInfoOne = @{@"NSExceptionMinimumTLSVersion" : @"4.0"};
81  NSDictionary* domainInfoTwo = @{
82  @"NSIncludesSubdomains" : @true,
83  };
84  NSDictionary* domainInfoThree = @{};
85  NSDictionary* exceptionDomains = @{
86  @"domain.name" : domainInfoOne,
87  @"sub.domain.name" : domainInfoTwo,
88  @"sub.two.domain.name" : domainInfoThree
89  };
90  NSDictionary* appTransportSecurity = @{@"NSExceptionDomains" : exceptionDomains};
91  XCTAssertEqualObjects(@"[[\"domain.name\",false,false],[\"sub.domain.name\",true,false],"
92  @"[\"sub.two.domain.name\",false,false]]",
93  [FlutterDartProject domainNetworkPolicy:appTransportSecurity]);
94 }
95 
96 @end
constexpr double kMegaByteSizeInBytes
Definition: constants.h:6
int64_t old_gen_heap_size
Definition: settings.h:236
const flutter::Settings & settings()
#define FLUTTER_ASSERT_ARC
Definition: FlutterMacros.h:44