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

Commit 8726c78

Browse files
authored
Started waiting for the notifications locally before asserting side effects (#25226)
1 parent 015c211 commit 8726c78

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,24 @@ - (void)testCallsNotifyLowMemory {
8787
OCMVerify([mockEngine notifyLowMemory]);
8888
OCMReject([mockEngine notifyLowMemory]);
8989

90+
XCTNSNotificationExpectation* memoryExpectation = [[XCTNSNotificationExpectation alloc]
91+
initWithName:UIApplicationDidReceiveMemoryWarningNotification];
9092
[[NSNotificationCenter defaultCenter]
9193
postNotificationName:UIApplicationDidReceiveMemoryWarningNotification
9294
object:nil];
95+
[self waitForExpectations:@[ memoryExpectation ] timeout:5.0];
9396
OCMVerify([mockEngine notifyLowMemory]);
9497
OCMReject([mockEngine notifyLowMemory]);
9598

99+
XCTNSNotificationExpectation* backgroundExpectation = [[XCTNSNotificationExpectation alloc]
100+
initWithName:UIApplicationDidEnterBackgroundNotification];
96101
[[NSNotificationCenter defaultCenter]
97102
postNotificationName:UIApplicationDidEnterBackgroundNotification
98103
object:nil];
104+
[self waitForExpectations:@[ backgroundExpectation ] timeout:5.0];
99105

100106
OCMVerify([mockEngine notifyLowMemory]);
107+
[mockEngine stopMocking];
101108
}
102109

103110
@end

shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegateTest.m

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
FLUTTER_ASSERT_ARC
1212

1313
@interface FlutterPluginAppLifeCycleDelegateTest : XCTestCase
14-
1514
@end
1615

1716
@implementation FlutterPluginAppLifeCycleDelegateTest
@@ -22,51 +21,71 @@ - (void)testCreate {
2221
}
2322

2423
- (void)testDidEnterBackground {
24+
XCTNSNotificationExpectation* expectation = [[XCTNSNotificationExpectation alloc]
25+
initWithName:UIApplicationDidEnterBackgroundNotification];
2526
FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init];
2627
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
2728
[delegate addDelegate:plugin];
2829
[[NSNotificationCenter defaultCenter]
2930
postNotificationName:UIApplicationDidEnterBackgroundNotification
3031
object:nil];
32+
33+
[self waitForExpectations:@[ expectation ] timeout:5.0];
3134
OCMVerify([plugin applicationDidEnterBackground:[UIApplication sharedApplication]]);
3235
}
3336

3437
- (void)testWillEnterForeground {
38+
XCTNSNotificationExpectation* expectation = [[XCTNSNotificationExpectation alloc]
39+
initWithName:UIApplicationWillEnterForegroundNotification];
40+
3541
FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init];
3642
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
3743
[delegate addDelegate:plugin];
3844
[[NSNotificationCenter defaultCenter]
3945
postNotificationName:UIApplicationWillEnterForegroundNotification
4046
object:nil];
47+
[self waitForExpectations:@[ expectation ] timeout:5.0];
4148
OCMVerify([plugin applicationWillEnterForeground:[UIApplication sharedApplication]]);
4249
}
4350

44-
- (void)skip_testWillResignActive {
51+
- (void)testWillResignActive {
52+
XCTNSNotificationExpectation* expectation =
53+
[[XCTNSNotificationExpectation alloc] initWithName:UIApplicationWillResignActiveNotification];
54+
4555
FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init];
4656
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
4757
[delegate addDelegate:plugin];
4858
[[NSNotificationCenter defaultCenter]
4959
postNotificationName:UIApplicationWillResignActiveNotification
5060
object:nil];
61+
[self waitForExpectations:@[ expectation ] timeout:5.0];
5162
OCMVerify([plugin applicationWillResignActive:[UIApplication sharedApplication]]);
5263
}
5364

54-
- (void)skip_testDidBecomeActive {
65+
- (void)testDidBecomeActive {
66+
XCTNSNotificationExpectation* expectation =
67+
[[XCTNSNotificationExpectation alloc] initWithName:UIApplicationDidBecomeActiveNotification];
68+
5569
FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init];
5670
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
5771
[delegate addDelegate:plugin];
5872
[[NSNotificationCenter defaultCenter]
5973
postNotificationName:UIApplicationDidBecomeActiveNotification
6074
object:nil];
75+
[self waitForExpectations:@[ expectation ] timeout:5.0];
6176
OCMVerify([plugin applicationDidBecomeActive:[UIApplication sharedApplication]]);
6277
}
6378

6479
- (void)testWillTerminate {
80+
XCTNSNotificationExpectation* expectation =
81+
[[XCTNSNotificationExpectation alloc] initWithName:UIApplicationWillTerminateNotification];
82+
6583
FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init];
6684
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
6785
[delegate addDelegate:plugin];
6886
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillTerminateNotification
6987
object:nil];
88+
[self waitForExpectations:@[ expectation ] timeout:5.0];
7089
OCMVerify([plugin applicationWillTerminate:[UIApplication sharedApplication]]);
7190
}
7291

shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,9 +885,8 @@ - (void)testFlutterTokenizerCanParseLines {
885885

886886
- (void)testFlutterTextInputPluginRetainsFlutterTextInputView {
887887
FlutterTextInputPlugin* myInputPlugin;
888-
id myEngine = OCMClassMock([FlutterEngine class]);
889888
myInputPlugin = [[FlutterTextInputPlugin alloc] init];
890-
myInputPlugin.textInputDelegate = myEngine;
889+
myInputPlugin.textInputDelegate = engine;
891890
__weak UIView* activeView;
892891
@autoreleasepool {
893892
FlutterMethodCall* setClientCall = [FlutterMethodCall

shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,5 +970,6 @@ - (void)testAccessibilityMessageAfterDeletion {
970970
});
971971
latch.Wait();
972972
OCMVerify([messenger cleanupConnection:connection]);
973+
[engine stopMocking];
973974
}
974975
@end

0 commit comments

Comments
 (0)