Skip to content

Commit

Permalink
Started waiting for the notifications locally before asserting side e…
Browse files Browse the repository at this point in the history
…ffects (flutter#25226)
  • Loading branch information
gaaclarke authored Mar 25, 2021
1 parent 015c211 commit 8726c78
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,24 @@ - (void)testCallsNotifyLowMemory {
OCMVerify([mockEngine notifyLowMemory]);
OCMReject([mockEngine notifyLowMemory]);

XCTNSNotificationExpectation* memoryExpectation = [[XCTNSNotificationExpectation alloc]
initWithName:UIApplicationDidReceiveMemoryWarningNotification];
[[NSNotificationCenter defaultCenter]
postNotificationName:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
[self waitForExpectations:@[ memoryExpectation ] timeout:5.0];
OCMVerify([mockEngine notifyLowMemory]);
OCMReject([mockEngine notifyLowMemory]);

XCTNSNotificationExpectation* backgroundExpectation = [[XCTNSNotificationExpectation alloc]
initWithName:UIApplicationDidEnterBackgroundNotification];
[[NSNotificationCenter defaultCenter]
postNotificationName:UIApplicationDidEnterBackgroundNotification
object:nil];
[self waitForExpectations:@[ backgroundExpectation ] timeout:5.0];

OCMVerify([mockEngine notifyLowMemory]);
[mockEngine stopMocking];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
FLUTTER_ASSERT_ARC

@interface FlutterPluginAppLifeCycleDelegateTest : XCTestCase

@end

@implementation FlutterPluginAppLifeCycleDelegateTest
Expand All @@ -22,51 +21,71 @@ - (void)testCreate {
}

- (void)testDidEnterBackground {
XCTNSNotificationExpectation* expectation = [[XCTNSNotificationExpectation alloc]
initWithName:UIApplicationDidEnterBackgroundNotification];
FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init];
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
[delegate addDelegate:plugin];
[[NSNotificationCenter defaultCenter]
postNotificationName:UIApplicationDidEnterBackgroundNotification
object:nil];

[self waitForExpectations:@[ expectation ] timeout:5.0];
OCMVerify([plugin applicationDidEnterBackground:[UIApplication sharedApplication]]);
}

- (void)testWillEnterForeground {
XCTNSNotificationExpectation* expectation = [[XCTNSNotificationExpectation alloc]
initWithName:UIApplicationWillEnterForegroundNotification];

FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init];
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
[delegate addDelegate:plugin];
[[NSNotificationCenter defaultCenter]
postNotificationName:UIApplicationWillEnterForegroundNotification
object:nil];
[self waitForExpectations:@[ expectation ] timeout:5.0];
OCMVerify([plugin applicationWillEnterForeground:[UIApplication sharedApplication]]);
}

- (void)skip_testWillResignActive {
- (void)testWillResignActive {
XCTNSNotificationExpectation* expectation =
[[XCTNSNotificationExpectation alloc] initWithName:UIApplicationWillResignActiveNotification];

FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init];
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
[delegate addDelegate:plugin];
[[NSNotificationCenter defaultCenter]
postNotificationName:UIApplicationWillResignActiveNotification
object:nil];
[self waitForExpectations:@[ expectation ] timeout:5.0];
OCMVerify([plugin applicationWillResignActive:[UIApplication sharedApplication]]);
}

- (void)skip_testDidBecomeActive {
- (void)testDidBecomeActive {
XCTNSNotificationExpectation* expectation =
[[XCTNSNotificationExpectation alloc] initWithName:UIApplicationDidBecomeActiveNotification];

FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init];
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
[delegate addDelegate:plugin];
[[NSNotificationCenter defaultCenter]
postNotificationName:UIApplicationDidBecomeActiveNotification
object:nil];
[self waitForExpectations:@[ expectation ] timeout:5.0];
OCMVerify([plugin applicationDidBecomeActive:[UIApplication sharedApplication]]);
}

- (void)testWillTerminate {
XCTNSNotificationExpectation* expectation =
[[XCTNSNotificationExpectation alloc] initWithName:UIApplicationWillTerminateNotification];

FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init];
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
[delegate addDelegate:plugin];
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillTerminateNotification
object:nil];
[self waitForExpectations:@[ expectation ] timeout:5.0];
OCMVerify([plugin applicationWillTerminate:[UIApplication sharedApplication]]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,9 +885,8 @@ - (void)testFlutterTokenizerCanParseLines {

- (void)testFlutterTextInputPluginRetainsFlutterTextInputView {
FlutterTextInputPlugin* myInputPlugin;
id myEngine = OCMClassMock([FlutterEngine class]);
myInputPlugin = [[FlutterTextInputPlugin alloc] init];
myInputPlugin.textInputDelegate = myEngine;
myInputPlugin.textInputDelegate = engine;
__weak UIView* activeView;
@autoreleasepool {
FlutterMethodCall* setClientCall = [FlutterMethodCall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,5 +970,6 @@ - (void)testAccessibilityMessageAfterDeletion {
});
latch.Wait();
OCMVerify([messenger cleanupConnection:connection]);
[engine stopMocking];
}
@end

0 comments on commit 8726c78

Please sign in to comment.