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

Commit 4394e2d

Browse files
committed
Started waiting for the notifications locally before asserting they
were called for plugin lifecycle tests.
1 parent 480cfa4 commit 4394e2d

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,21 @@ - (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]);
101107
}

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 = [[XCTNSNotificationExpectation alloc]
53+
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 = [[XCTNSNotificationExpectation alloc]
67+
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 = [[XCTNSNotificationExpectation alloc]
81+
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

0 commit comments

Comments
 (0)