Skip to content

Commit

Permalink
Reland add some AppLifecycleTests
Browse files Browse the repository at this point in the history
  • Loading branch information
xster committed Sep 13, 2019
1 parent 1b63444 commit 7d8c6d9
Show file tree
Hide file tree
Showing 13 changed files with 434 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

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

/* Begin PBXFileReference section */
0A57B3BB2323C4BD00DD9521 /* ScreenBeforeFlutter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScreenBeforeFlutter.h; sourceTree = "<group>"; };
0A57B3BC2323C4BD00DD9521 /* ScreenBeforeFlutter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScreenBeforeFlutter.m; sourceTree = "<group>"; };
0A57B3BE2323C74200DD9521 /* FlutterEngine+ScenariosTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "FlutterEngine+ScenariosTest.m"; sourceTree = "<group>"; };
0A57B3C02323C74D00DD9521 /* FlutterEngine+ScenariosTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FlutterEngine+ScenariosTest.h"; sourceTree = "<group>"; };
0A57B3C12323D2D700DD9521 /* AppLifecycleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppLifecycleTests.m; sourceTree = "<group>"; };
0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlutterViewControllerTest.m; sourceTree = "<group>"; };
244EA6CF230DBE8900B2D26E /* golden_platform_view_D21AP.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = golden_platform_view_D21AP.png; sourceTree = "<group>"; };
246B4E4122E3B5F700073EBF /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = App.framework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -167,6 +175,10 @@
248D76D322E388380012F0C1 /* Assets.xcassets */,
248D76D822E388380012F0C1 /* Info.plist */,
248D76D922E388380012F0C1 /* main.m */,
0A57B3BB2323C4BD00DD9521 /* ScreenBeforeFlutter.h */,
0A57B3BC2323C4BD00DD9521 /* ScreenBeforeFlutter.m */,
0A57B3BE2323C74200DD9521 /* FlutterEngine+ScenariosTest.m */,
0A57B3C02323C74D00DD9521 /* FlutterEngine+ScenariosTest.h */,
);
path = Scenarios;
sourceTree = "<group>";
Expand All @@ -177,6 +189,7 @@
248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */,
0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */,
248D76E522E388380012F0C1 /* Info.plist */,
0A57B3C12323D2D700DD9521 /* AppLifecycleTests.m */,
);
path = ScenariosTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -273,13 +286,16 @@
TargetAttributes = {
248D76C622E388370012F0C1 = {
CreatedOnToolsVersion = 10.2.1;
LastSwiftMigration = 1030;
};
248D76DE22E388380012F0C1 = {
CreatedOnToolsVersion = 10.2.1;
LastSwiftMigration = 1030;
TestTargetID = 248D76C622E388370012F0C1;
};
248D76E922E388380012F0C1 = {
CreatedOnToolsVersion = 10.2.1;
LastSwiftMigration = 1030;
TestTargetID = 248D76C622E388370012F0C1;
};
};
Expand Down Expand Up @@ -340,6 +356,8 @@
248D76DA22E388380012F0C1 /* main.m in Sources */,
24F1FB89230B4579005ACE7C /* TextPlatformView.m in Sources */,
248D76CC22E388370012F0C1 /* AppDelegate.m in Sources */,
0A57B3BF2323C74200DD9521 /* FlutterEngine+ScenariosTest.m in Sources */,
0A57B3BD2323C4BD00DD9521 /* ScreenBeforeFlutter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -348,6 +366,7 @@
buildActionMask = 2147483647;
files = (
0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */,
0A57B3C22323D2D700DD9521 /* AppLifecycleTests.m in Sources */,
248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -492,6 +511,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = S8QB4VV633;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@
ReferencedContainer = "container:Scenarios.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "--screen-before-flutter"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--platform-view"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand Down
4 changes: 4 additions & 0 deletions testing/scenario_app/ios/Scenarios/Scenarios/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Flutter/Flutter.h>
#import <UIKit/UIKit.h>

Expand Down
18 changes: 10 additions & 8 deletions testing/scenario_app/ios/Scenarios/Scenarios/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "AppDelegate.h"
#import "FlutterEngine+ScenariosTest.h"
#import "ScreenBeforeFlutter.h"
#import "TextPlatformView.h"

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

FlutterViewController* flutterViewController =
[[NoStatusBarFlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
[engine.binaryMessenger
setMessageHandlerOnChannel:@"scenario_status"
binaryMessageHandler:^(NSData* _Nullable message, FlutterBinaryReply _Nonnull reply) {
[engine.binaryMessenger
sendOnChannel:@"set_scenario"
message:[@"text_platform_view" dataUsingEncoding:NSUTF8StringEncoding]];
}];
TextPlatformViewFactory* textPlatformViewFactory =
[[TextPlatformViewFactory alloc] initWithMessenger:flutterViewController.binaryMessenger];
NSObject<FlutterPluginRegistrar>* registrar =
[flutterViewController.engine registrarForPlugin:@"scenarios/TextPlatformViewPlugin"];
[registrar registerViewFactory:textPlatformViewFactory withId:@"scenarios/textPlatformView"];
self.window.rootViewController = flutterViewController;
} else if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--screen-before-flutter"]) {
self.window.rootViewController = [[ScreenBeforeFlutter alloc] initWithEngineRunCompletion:nil];
} else {
self.window.rootViewController = [[UIViewController alloc] init];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Flutter/Flutter.h>

NS_ASSUME_NONNULL_BEGIN
@interface FlutterEngine (ScenariosTest)
- (instancetype)initWithScenario:(NSString*)scenario
withCompletion:(nullable void (^)(void))engineRunCompletion;
@end
NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "FlutterEngine+ScenariosTest.h"

@implementation FlutterEngine (ScenariosTest)

- (instancetype)initWithScenario:(NSString*)scenario
withCompletion:(nullable void (^)(void))engineRunCompletion {
NSAssert([scenario length] != 0, @"You need to provide a scenario");
self = [self initWithName:[NSString stringWithFormat:@"Test engine for %@", scenario]
project:nil];
[self runWithEntrypoint:nil];
[self.binaryMessenger
setMessageHandlerOnChannel:@"scenario_status"
binaryMessageHandler:^(NSData* message, FlutterBinaryReply reply) {
[self.binaryMessenger
sendOnChannel:@"set_scenario"
message:[scenario dataUsingEncoding:NSUTF8StringEncoding]];
if (engineRunCompletion != nil) {
engineRunCompletion();
}
}];
return self;
}

@end
14 changes: 14 additions & 0 deletions testing/scenario_app/ios/Scenarios/Scenarios/ScreenBeforeFlutter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Flutter/Flutter.h>

@interface ScreenBeforeFlutter : UIViewController

- (id)initWithEngineRunCompletion:(void (^)(void))engineRunCompletion;
- (FlutterViewController*)showFlutter;

@property(nonatomic, readonly) FlutterEngine* engine;

@end
54 changes: 54 additions & 0 deletions testing/scenario_app/ios/Scenarios/Scenarios/ScreenBeforeFlutter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ScreenBeforeFlutter.h"
#import "FlutterEngine+ScenariosTest.h"

@implementation ScreenBeforeFlutter

FlutterEngine* _engine;

- (id)initWithEngineRunCompletion:(void (^)(void))engineRunCompletion {
self = [super init];
_engine = [[FlutterEngine alloc] initWithScenario:@"poppable_screen"
withCompletion:engineRunCompletion];
return self;
}

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = UIColor.grayColor;

UIButton* showFlutterButton = [UIButton buttonWithType:UIButtonTypeSystem];
showFlutterButton.translatesAutoresizingMaskIntoConstraints = NO;
showFlutterButton.backgroundColor = UIColor.blueColor;
[showFlutterButton setTitle:@"Show Flutter" forState:UIControlStateNormal];
showFlutterButton.tintColor = UIColor.whiteColor;
showFlutterButton.clipsToBounds = YES;
[showFlutterButton addTarget:self
action:@selector(showFlutter)
forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:showFlutterButton];
[[showFlutterButton.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor] setActive:YES];
[[showFlutterButton.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor] setActive:YES];
[[showFlutterButton.heightAnchor constraintEqualToConstant:50] setActive:YES];
[[showFlutterButton.widthAnchor constraintEqualToConstant:150] setActive:YES];

[_engine runWithEntrypoint:nil];
}

- (FlutterViewController*)showFlutter {
FlutterViewController* flutterVC = [[FlutterViewController alloc] initWithEngine:_engine
nibName:nil
bundle:nil];
[self presentViewController:flutterVC animated:NO completion:nil];
return flutterVC;
}

- (FlutterEngine*)engine {
return _engine;
}

@end
Loading

0 comments on commit 7d8c6d9

Please sign in to comment.