Skip to content

Commit 7d8c6d9

Browse files
authored
Reland add some AppLifecycleTests
1 parent 1b63444 commit 7d8c6d9

File tree

13 files changed

+434
-10
lines changed

13 files changed

+434
-10
lines changed

testing/scenario_app/ios/Scenarios/Scenarios.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
0A57B3BD2323C4BD00DD9521 /* ScreenBeforeFlutter.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A57B3BC2323C4BD00DD9521 /* ScreenBeforeFlutter.m */; };
11+
0A57B3BF2323C74200DD9521 /* FlutterEngine+ScenariosTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A57B3BE2323C74200DD9521 /* FlutterEngine+ScenariosTest.m */; };
12+
0A57B3C22323D2D700DD9521 /* AppLifecycleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A57B3C12323D2D700DD9521 /* AppLifecycleTests.m */; };
1013
0DB781EF22E931BE00E9B371 /* Flutter.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1114
0DB781F122E933E800E9B371 /* Flutter.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1215
0DB781FE22EA2C6D00E9B371 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.framework */; };
@@ -84,6 +87,11 @@
8487
/* End PBXCopyFilesBuildPhase section */
8588

8689
/* Begin PBXFileReference section */
90+
0A57B3BB2323C4BD00DD9521 /* ScreenBeforeFlutter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScreenBeforeFlutter.h; sourceTree = "<group>"; };
91+
0A57B3BC2323C4BD00DD9521 /* ScreenBeforeFlutter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScreenBeforeFlutter.m; sourceTree = "<group>"; };
92+
0A57B3BE2323C74200DD9521 /* FlutterEngine+ScenariosTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "FlutterEngine+ScenariosTest.m"; sourceTree = "<group>"; };
93+
0A57B3C02323C74D00DD9521 /* FlutterEngine+ScenariosTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FlutterEngine+ScenariosTest.h"; sourceTree = "<group>"; };
94+
0A57B3C12323D2D700DD9521 /* AppLifecycleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppLifecycleTests.m; sourceTree = "<group>"; };
8795
0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlutterViewControllerTest.m; sourceTree = "<group>"; };
8896
244EA6CF230DBE8900B2D26E /* golden_platform_view_D21AP.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = golden_platform_view_D21AP.png; sourceTree = "<group>"; };
8997
246B4E4122E3B5F700073EBF /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = App.framework; sourceTree = "<group>"; };
@@ -167,6 +175,10 @@
167175
248D76D322E388380012F0C1 /* Assets.xcassets */,
168176
248D76D822E388380012F0C1 /* Info.plist */,
169177
248D76D922E388380012F0C1 /* main.m */,
178+
0A57B3BB2323C4BD00DD9521 /* ScreenBeforeFlutter.h */,
179+
0A57B3BC2323C4BD00DD9521 /* ScreenBeforeFlutter.m */,
180+
0A57B3BE2323C74200DD9521 /* FlutterEngine+ScenariosTest.m */,
181+
0A57B3C02323C74D00DD9521 /* FlutterEngine+ScenariosTest.h */,
170182
);
171183
path = Scenarios;
172184
sourceTree = "<group>";
@@ -177,6 +189,7 @@
177189
248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */,
178190
0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */,
179191
248D76E522E388380012F0C1 /* Info.plist */,
192+
0A57B3C12323D2D700DD9521 /* AppLifecycleTests.m */,
180193
);
181194
path = ScenariosTests;
182195
sourceTree = "<group>";
@@ -273,13 +286,16 @@
273286
TargetAttributes = {
274287
248D76C622E388370012F0C1 = {
275288
CreatedOnToolsVersion = 10.2.1;
289+
LastSwiftMigration = 1030;
276290
};
277291
248D76DE22E388380012F0C1 = {
278292
CreatedOnToolsVersion = 10.2.1;
293+
LastSwiftMigration = 1030;
279294
TestTargetID = 248D76C622E388370012F0C1;
280295
};
281296
248D76E922E388380012F0C1 = {
282297
CreatedOnToolsVersion = 10.2.1;
298+
LastSwiftMigration = 1030;
283299
TestTargetID = 248D76C622E388370012F0C1;
284300
};
285301
};
@@ -340,6 +356,8 @@
340356
248D76DA22E388380012F0C1 /* main.m in Sources */,
341357
24F1FB89230B4579005ACE7C /* TextPlatformView.m in Sources */,
342358
248D76CC22E388370012F0C1 /* AppDelegate.m in Sources */,
359+
0A57B3BF2323C74200DD9521 /* FlutterEngine+ScenariosTest.m in Sources */,
360+
0A57B3BD2323C4BD00DD9521 /* ScreenBeforeFlutter.m in Sources */,
343361
);
344362
runOnlyForDeploymentPostprocessing = 0;
345363
};
@@ -348,6 +366,7 @@
348366
buildActionMask = 2147483647;
349367
files = (
350368
0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */,
369+
0A57B3C22323D2D700DD9521 /* AppLifecycleTests.m in Sources */,
351370
248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */,
352371
);
353372
runOnlyForDeploymentPostprocessing = 0;
@@ -492,6 +511,7 @@
492511
isa = XCBuildConfiguration;
493512
buildSettings = {
494513
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
514+
CLANG_ENABLE_MODULES = YES;
495515
CODE_SIGN_IDENTITY = "iPhone Developer";
496516
CODE_SIGN_STYLE = Automatic;
497517
DEVELOPMENT_TEAM = S8QB4VV633;

testing/scenario_app/ios/Scenarios/Scenarios.xcodeproj/xcshareddata/xcschemes/Scenarios.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@
8383
ReferencedContainer = "container:Scenarios.xcodeproj">
8484
</BuildableReference>
8585
</BuildableProductRunnable>
86+
<CommandLineArguments>
87+
<CommandLineArgument
88+
argument = "--screen-before-flutter"
89+
isEnabled = "NO">
90+
</CommandLineArgument>
91+
<CommandLineArgument
92+
argument = "--platform-view"
93+
isEnabled = "NO">
94+
</CommandLineArgument>
95+
</CommandLineArguments>
8696
<AdditionalOptions>
8797
</AdditionalOptions>
8898
</LaunchAction>

testing/scenario_app/ios/Scenarios/Scenarios/AppDelegate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2019 The Chromium 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+
15
#import <Flutter/Flutter.h>
26
#import <UIKit/UIKit.h>
37

testing/scenario_app/ios/Scenarios/Scenarios/AppDelegate.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
// Copyright 2019 The Chromium 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+
15
#include "AppDelegate.h"
6+
#import "FlutterEngine+ScenariosTest.h"
7+
#import "ScreenBeforeFlutter.h"
28
#import "TextPlatformView.h"
39

410
@interface NoStatusBarFlutterViewController : FlutterViewController
@@ -20,24 +26,20 @@ - (BOOL)application:(UIApplication*)application
2026
// This argument is used by the XCUITest for Platform Views so that the app
2127
// under test will create platform views.
2228
if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--platform-view"]) {
23-
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"PlatformViewTest" project:nil];
29+
FlutterEngine* engine = [[FlutterEngine alloc] initWithScenario:@"text_platform_view"
30+
withCompletion:nil];
2431
[engine runWithEntrypoint:nil];
2532

2633
FlutterViewController* flutterViewController =
2734
[[NoStatusBarFlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
28-
[engine.binaryMessenger
29-
setMessageHandlerOnChannel:@"scenario_status"
30-
binaryMessageHandler:^(NSData* _Nullable message, FlutterBinaryReply _Nonnull reply) {
31-
[engine.binaryMessenger
32-
sendOnChannel:@"set_scenario"
33-
message:[@"text_platform_view" dataUsingEncoding:NSUTF8StringEncoding]];
34-
}];
3535
TextPlatformViewFactory* textPlatformViewFactory =
3636
[[TextPlatformViewFactory alloc] initWithMessenger:flutterViewController.binaryMessenger];
3737
NSObject<FlutterPluginRegistrar>* registrar =
3838
[flutterViewController.engine registrarForPlugin:@"scenarios/TextPlatformViewPlugin"];
3939
[registrar registerViewFactory:textPlatformViewFactory withId:@"scenarios/textPlatformView"];
4040
self.window.rootViewController = flutterViewController;
41+
} else if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--screen-before-flutter"]) {
42+
self.window.rootViewController = [[ScreenBeforeFlutter alloc] initWithEngineRunCompletion:nil];
4143
} else {
4244
self.window.rootViewController = [[UIViewController alloc] init];
4345
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2019 The Chromium 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 <Flutter/Flutter.h>
6+
7+
NS_ASSUME_NONNULL_BEGIN
8+
@interface FlutterEngine (ScenariosTest)
9+
- (instancetype)initWithScenario:(NSString*)scenario
10+
withCompletion:(nullable void (^)(void))engineRunCompletion;
11+
@end
12+
NS_ASSUME_NONNULL_END
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2019 The Chromium 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 "FlutterEngine+ScenariosTest.h"
6+
7+
@implementation FlutterEngine (ScenariosTest)
8+
9+
- (instancetype)initWithScenario:(NSString*)scenario
10+
withCompletion:(nullable void (^)(void))engineRunCompletion {
11+
NSAssert([scenario length] != 0, @"You need to provide a scenario");
12+
self = [self initWithName:[NSString stringWithFormat:@"Test engine for %@", scenario]
13+
project:nil];
14+
[self runWithEntrypoint:nil];
15+
[self.binaryMessenger
16+
setMessageHandlerOnChannel:@"scenario_status"
17+
binaryMessageHandler:^(NSData* message, FlutterBinaryReply reply) {
18+
[self.binaryMessenger
19+
sendOnChannel:@"set_scenario"
20+
message:[scenario dataUsingEncoding:NSUTF8StringEncoding]];
21+
if (engineRunCompletion != nil) {
22+
engineRunCompletion();
23+
}
24+
}];
25+
return self;
26+
}
27+
28+
@end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2019 The Chromium 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 <Flutter/Flutter.h>
6+
7+
@interface ScreenBeforeFlutter : UIViewController
8+
9+
- (id)initWithEngineRunCompletion:(void (^)(void))engineRunCompletion;
10+
- (FlutterViewController*)showFlutter;
11+
12+
@property(nonatomic, readonly) FlutterEngine* engine;
13+
14+
@end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2019 The Chromium 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 "ScreenBeforeFlutter.h"
6+
#import "FlutterEngine+ScenariosTest.h"
7+
8+
@implementation ScreenBeforeFlutter
9+
10+
FlutterEngine* _engine;
11+
12+
- (id)initWithEngineRunCompletion:(void (^)(void))engineRunCompletion {
13+
self = [super init];
14+
_engine = [[FlutterEngine alloc] initWithScenario:@"poppable_screen"
15+
withCompletion:engineRunCompletion];
16+
return self;
17+
}
18+
19+
- (void)viewDidLoad {
20+
[super viewDidLoad];
21+
self.view.backgroundColor = UIColor.grayColor;
22+
23+
UIButton* showFlutterButton = [UIButton buttonWithType:UIButtonTypeSystem];
24+
showFlutterButton.translatesAutoresizingMaskIntoConstraints = NO;
25+
showFlutterButton.backgroundColor = UIColor.blueColor;
26+
[showFlutterButton setTitle:@"Show Flutter" forState:UIControlStateNormal];
27+
showFlutterButton.tintColor = UIColor.whiteColor;
28+
showFlutterButton.clipsToBounds = YES;
29+
[showFlutterButton addTarget:self
30+
action:@selector(showFlutter)
31+
forControlEvents:UIControlEventTouchUpInside];
32+
33+
[self.view addSubview:showFlutterButton];
34+
[[showFlutterButton.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor] setActive:YES];
35+
[[showFlutterButton.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor] setActive:YES];
36+
[[showFlutterButton.heightAnchor constraintEqualToConstant:50] setActive:YES];
37+
[[showFlutterButton.widthAnchor constraintEqualToConstant:150] setActive:YES];
38+
39+
[_engine runWithEntrypoint:nil];
40+
}
41+
42+
- (FlutterViewController*)showFlutter {
43+
FlutterViewController* flutterVC = [[FlutterViewController alloc] initWithEngine:_engine
44+
nibName:nil
45+
bundle:nil];
46+
[self presentViewController:flutterVC animated:NO completion:nil];
47+
return flutterVC;
48+
}
49+
50+
- (FlutterEngine*)engine {
51+
return _engine;
52+
}
53+
54+
@end

0 commit comments

Comments
 (0)