Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 074346f

Browse files
committed
Added golden test to make sure that spawn engines work.
1 parent b0c6686 commit 074346f

File tree

8 files changed

+98
-4
lines changed

8 files changed

+98
-4
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
0DB7820022EA2C9D00E9B371 /* App.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 246B4E4122E3B5F700073EBF /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2424
0DB7820122EA2CA500E9B371 /* App.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 246B4E4122E3B5F700073EBF /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2525
0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */; };
26+
0DDEBC89258830B40065D0E8 /* SpawnEngineTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DDEBC88258830B40065D0E8 /* SpawnEngineTest.m */; };
27+
0DDEBC8B258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 0DDEBC8A258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png */; };
2628
242F37A222E636DE001E83D4 /* Flutter.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2729
242F37A322E636DE001E83D4 /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4122E3B5F700073EBF /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2830
244EA6D0230DBE8900B2D26E /* golden_platform_view_D21AP.png in Resources */ = {isa = PBXBuildFile; fileRef = 244EA6CF230DBE8900B2D26E /* golden_platform_view_D21AP.png */; };
@@ -124,6 +126,9 @@
124126
0D8470A2240F0B1F0030B565 /* StatusBarTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StatusBarTest.h; sourceTree = "<group>"; };
125127
0D8470A3240F0B1F0030B565 /* StatusBarTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = StatusBarTest.m; sourceTree = "<group>"; };
126128
0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlutterViewControllerTest.m; sourceTree = "<group>"; };
129+
0DDEBC87258830B40065D0E8 /* SpawnEngineTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpawnEngineTest.h; sourceTree = "<group>"; };
130+
0DDEBC88258830B40065D0E8 /* SpawnEngineTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SpawnEngineTest.m; sourceTree = "<group>"; };
131+
0DDEBC8A258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_spawn_engine_works_iPhone 8_simulator.png"; sourceTree = "<group>"; };
127132
244EA6CF230DBE8900B2D26E /* golden_platform_view_D21AP.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = golden_platform_view_D21AP.png; sourceTree = "<group>"; };
128133
246A6610252E693A00EAB0F3 /* RenderingSelectionTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RenderingSelectionTest.m; sourceTree = "<group>"; };
129134
246B4E4122E3B5F700073EBF /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = App.framework; sourceTree = "<group>"; };
@@ -252,6 +257,7 @@
252257
248D76ED22E388380012F0C1 /* ScenariosUITests */ = {
253258
isa = PBXGroup;
254259
children = (
260+
0DDEBC8A258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png */,
255261
4F06F1B124731F66000AF246 /* LocalizationInitializationTest.m */,
256262
6402EBD024147BDA00987DCB /* UnobstructedPlatformViewTests.m */,
257263
0AC83145256E534E00DAE6BE /* golden_bogus_font_text_iPhone 8_simulator.png */,
@@ -284,6 +290,8 @@
284290
0A42BFB32447E179007E212E /* TextSemanticsFocusTest.m */,
285291
0A42BFB52447E19F007E212E /* TextSemanticsFocusTest.h */,
286292
246A6610252E693A00EAB0F3 /* RenderingSelectionTest.m */,
293+
0DDEBC87258830B40065D0E8 /* SpawnEngineTest.h */,
294+
0DDEBC88258830B40065D0E8 /* SpawnEngineTest.m */,
287295
);
288296
path = ScenariosUITests;
289297
sourceTree = "<group>";
@@ -433,6 +441,7 @@
433441
59A97FDA236B984300B4C066 /* golden_platform_view_multiple_background_foreground_iPhone SE_simulator.png in Resources */,
434442
3DEF491923C3BE6500184216 /* golden_platform_view_rotate_iPhone 8_simulator.png in Resources */,
435443
24D47D1B230C79840069DD5E /* golden_platform_view_D211AP.png in Resources */,
444+
0DDEBC8B258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png in Resources */,
436445
244EA6D0230DBE8900B2D26E /* golden_platform_view_D21AP.png in Resources */,
437446
3DEF491A23C3BE6500184216 /* golden_platform_view_transform_iPhone 8_simulator.png in Resources */,
438447
);
@@ -480,6 +489,7 @@
480489
246A6611252E693A00EAB0F3 /* RenderingSelectionTest.m in Sources */,
481490
4F06F1B32473296E000AF246 /* LocalizationInitializationTest.m in Sources */,
482491
0A42BFB42447E179007E212E /* TextSemanticsFocusTest.m in Sources */,
492+
0DDEBC89258830B40065D0E8 /* SpawnEngineTest.m in Sources */,
483493
);
484494
runOnlyForDeploymentPostprocessing = 0;
485495
};

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES"
3030
systemAttachmentLifetime = "keepNever">
31+
<AdditionalOptions>
32+
<AdditionalOption
33+
key = "NSZombieEnabled"
34+
value = "YES"
35+
isEnabled = "YES">
36+
</AdditionalOption>
37+
<AdditionalOption
38+
key = "MallocScribble"
39+
value = ""
40+
isEnabled = "YES">
41+
</AdditionalOption>
42+
</AdditionalOptions>
3143
<Testables>
3244
<TestableReference
3345
skipped = "NO"

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ - (BOOL)application:(UIApplication*)application
5454
@"--text-semantics-focus" : @"text_semantics_focus",
5555
@"--animated-color-square" : @"animated_color_square",
5656
@"--platform-view-with-continuous-texture" : @"platform_view_with_continuous_texture",
57-
@"--bogus-font-text" : @"bogus_font_text"
57+
@"--bogus-font-text" : @"bogus_font_text",
58+
@"--spawn-engine-works" : @"spawn_engine_works",
5859
};
5960
__block NSString* flutterViewControllerTestName = nil;
6061
[launchArgsMap
@@ -80,6 +81,25 @@ - (BOOL)application:(UIApplication*)application
8081
return [super application:application didFinishLaunchingWithOptions:launchOptions];
8182
}
8283

84+
// TODO(https://github.com/flutter/flutter/issues/72019) Sharing threads doesn't work correctly yet
85+
// so we need to keep the Spawning engine alive. Once this issue is fixed we can remove s_spawner.
86+
static FlutterEngine* s_spawner;
87+
88+
- (FlutterEngine*)engineForTest:(NSString*)scenarioIdentifier {
89+
if ([scenarioIdentifier isEqualToString:@"spawn_engine_works"]) {
90+
if (s_spawner == nil) {
91+
s_spawner = [[FlutterEngine alloc] initWithName:@"FlutterControllerTest" project:nil];
92+
[s_spawner run];
93+
}
94+
return [s_spawner spawnWithEntrypoint:nil libraryURI:nil];
95+
} else {
96+
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"FlutterControllerTest"
97+
project:nil];
98+
[engine run];
99+
return engine;
100+
}
101+
}
102+
83103
- (FlutterViewController*)flutterViewControllerForTest:(NSString*)scenarioIdentifier
84104
withEngine:(FlutterEngine*)engine {
85105
if ([scenarioIdentifier isEqualToString:@"tap_status_bar"]) {
@@ -90,9 +110,7 @@ - (FlutterViewController*)flutterViewControllerForTest:(NSString*)scenarioIdenti
90110
}
91111

92112
- (void)setupFlutterViewControllerTest:(NSString*)scenarioIdentifier {
93-
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"FlutterControllerTest" project:nil];
94-
[engine run];
95-
113+
FlutterEngine* engine = [self engineForTest:scenarioIdentifier];
96114
FlutterViewController* flutterViewController =
97115
[self flutterViewControllerForTest:scenarioIdentifier withEngine:engine];
98116

testing/scenario_app/ios/Scenarios/Scenarios/FlutterEngine+ScenariosTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
88
@interface FlutterEngine (ScenariosTest)
99
- (instancetype)initWithScenario:(NSString*)scenario
1010
withCompletion:(nullable void (^)(void))engineRunCompletion;
11+
- (FlutterEngine*)spawnWithEntrypoint:(nullable NSString*)entrypoint
12+
libraryURI:(nullable NSString*)libraryURI;
1113
@end
1214
NS_ASSUME_NONNULL_END
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2020 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 <XCTest/XCTest.h>
6+
7+
NS_ASSUME_NONNULL_BEGIN
8+
9+
@interface SpawnEngineTest : XCTestCase
10+
@property(nonatomic, strong) XCUIApplication* application;
11+
@end
12+
13+
NS_ASSUME_NONNULL_END
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2020 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 "SpawnEngineTest.h"
6+
#import "GoldenImage.h"
7+
8+
@implementation SpawnEngineTest
9+
10+
- (void)setUp {
11+
[super setUp];
12+
self.continueAfterFailure = NO;
13+
14+
self.application = [[XCUIApplication alloc] init];
15+
self.application.launchArguments = @[ @"--spawn-engine-works", @"--enable-software-rendering" ];
16+
[self.application launch];
17+
}
18+
19+
- (void)testSpawnEngineWorks {
20+
NSString* prefix = @"golden_spawn_engine_works_";
21+
GoldenImage* golden = [[GoldenImage alloc] initWithGoldenNamePrefix:prefix];
22+
if (!golden.image) {
23+
XCTFail(@"unable to find golden image for: %@", prefix);
24+
}
25+
XCUIScreenshot* screenshot = [[XCUIScreen mainScreen] screenshot];
26+
if (![golden compareGoldenToImage:screenshot.image]) {
27+
XCTAttachment* screenshotAttachment = [XCTAttachment attachmentWithImage:screenshot.image];
28+
screenshotAttachment.name = [golden.goldenName stringByAppendingString:@"_actual"];
29+
screenshotAttachment.lifetime = XCTAttachmentLifetimeKeepAlways;
30+
[self addAttachment:screenshotAttachment];
31+
32+
XCTFail(@"Goldens do not match. Follow the steps in the "
33+
@"README to update golden named %@ if needed.",
34+
golden.goldenName);
35+
}
36+
}
37+
38+
@end
22.7 KB
Loading

testing/scenario_app/lib/src/scenarios.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Map<String, ScenarioFactory> _scenarios = <String, ScenarioFactory>{
4646
'initial_route_reply': () => InitialRouteReply(PlatformDispatcher.instance),
4747
'platform_view_with_continuous_texture': () => PlatformViewWithContinuousTexture(PlatformDispatcher.instance, 'Platform View', id: _viewId++),
4848
'bogus_font_text': () => BogusFontText(PlatformDispatcher.instance),
49+
'spawn_engine_works' : () => BogusFontText(PlatformDispatcher.instance),
4950
};
5051

5152
Map<String, dynamic> _currentScenarioParams = <String, dynamic>{};

0 commit comments

Comments
 (0)