Flutter iOS Embedder
FlutterPluginAppLifeCycleDelegateTest.mm
Go to the documentation of this file.
1 // Copyright 2013 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 <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
7 
10 
12 
14 @end
15 
17 
18 - (void)testCreate {
20  XCTAssertNotNil(delegate);
21 }
22 
23 #if not APPLICATION_EXTENSION_API_ONLY
24 - (void)testDidEnterBackground {
25  XCTNSNotificationExpectation* expectation = [[XCTNSNotificationExpectation alloc]
26  initWithName:UIApplicationDidEnterBackgroundNotification];
28  id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
29  [delegate addDelegate:plugin];
30  [[NSNotificationCenter defaultCenter]
31  postNotificationName:UIApplicationDidEnterBackgroundNotification
32  object:nil];
33 
34  [self waitForExpectations:@[ expectation ] timeout:5.0];
35  OCMVerify([plugin applicationDidEnterBackground:[UIApplication sharedApplication]]);
36 }
37 
38 - (void)testWillEnterForeground {
39  XCTNSNotificationExpectation* expectation = [[XCTNSNotificationExpectation alloc]
40  initWithName:UIApplicationWillEnterForegroundNotification];
41 
43  id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
44  [delegate addDelegate:plugin];
45  [[NSNotificationCenter defaultCenter]
46  postNotificationName:UIApplicationWillEnterForegroundNotification
47  object:nil];
48  [self waitForExpectations:@[ expectation ] timeout:5.0];
49  OCMVerify([plugin applicationWillEnterForeground:[UIApplication sharedApplication]]);
50 }
51 
52 - (void)testWillResignActive {
53  XCTNSNotificationExpectation* expectation =
54  [[XCTNSNotificationExpectation alloc] initWithName:UIApplicationWillResignActiveNotification];
55 
57  id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
58  [delegate addDelegate:plugin];
59  [[NSNotificationCenter defaultCenter]
60  postNotificationName:UIApplicationWillResignActiveNotification
61  object:nil];
62  [self waitForExpectations:@[ expectation ] timeout:5.0];
63  OCMVerify([plugin applicationWillResignActive:[UIApplication sharedApplication]]);
64 }
65 
66 - (void)testDidBecomeActive {
67  XCTNSNotificationExpectation* expectation =
68  [[XCTNSNotificationExpectation alloc] initWithName:UIApplicationDidBecomeActiveNotification];
69 
71  id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
72  [delegate addDelegate:plugin];
73  [[NSNotificationCenter defaultCenter]
74  postNotificationName:UIApplicationDidBecomeActiveNotification
75  object:nil];
76  [self waitForExpectations:@[ expectation ] timeout:5.0];
77  OCMVerify([plugin applicationDidBecomeActive:[UIApplication sharedApplication]]);
78 }
79 
80 - (void)testWillTerminate {
81  XCTNSNotificationExpectation* expectation =
82  [[XCTNSNotificationExpectation alloc] initWithName:UIApplicationWillTerminateNotification];
83 
85  id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
86  [delegate addDelegate:plugin];
87  [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillTerminateNotification
88  object:nil];
89  [self waitForExpectations:@[ expectation ] timeout:5.0];
90  OCMVerify([plugin applicationWillTerminate:[UIApplication sharedApplication]]);
91 }
92 #endif
93 
94 @end
FLUTTER_ASSERT_ARC
#define FLUTTER_ASSERT_ARC
Definition: FlutterMacros.h:44
FlutterPlugin-p
Definition: FlutterPlugin.h:189
FlutterMacros.h
FlutterPluginAppLifeCycleDelegate.h
FlutterPluginAppLifeCycleDelegate
Definition: FlutterPluginAppLifeCycleDelegate.h:16
FlutterPluginAppLifeCycleDelegateTest
Definition: FlutterPluginAppLifeCycleDelegateTest.mm:13
-[FlutterPluginAppLifeCycleDelegate addDelegate:]
void addDelegate:(NSObject< FlutterApplicationLifeCycleDelegate > *delegate)
Definition: FlutterPluginAppLifeCycleDelegate.mm:106