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 
16 @implementation FakePlugin
17 @end
18 
20 @end
21 
23 
24 - (void)testCreate {
26  XCTAssertNotNil(delegate);
27 }
28 
29 #if not APPLICATION_EXTENSION_API_ONLY
30 - (void)testDidEnterBackground {
31  XCTNSNotificationExpectation* expectation = [[XCTNSNotificationExpectation alloc]
32  initWithName:UIApplicationDidEnterBackgroundNotification];
34  id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
35  [delegate addDelegate:plugin];
36  [[NSNotificationCenter defaultCenter]
37  postNotificationName:UIApplicationDidEnterBackgroundNotification
38  object:nil];
39 
40  [self waitForExpectations:@[ expectation ] timeout:5.0];
41  OCMVerify([plugin applicationDidEnterBackground:[UIApplication sharedApplication]]);
42 }
43 
44 - (void)testWillEnterForeground {
45  XCTNSNotificationExpectation* expectation = [[XCTNSNotificationExpectation alloc]
46  initWithName:UIApplicationWillEnterForegroundNotification];
47 
49  id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
50  [delegate addDelegate:plugin];
51  [[NSNotificationCenter defaultCenter]
52  postNotificationName:UIApplicationWillEnterForegroundNotification
53  object:nil];
54  [self waitForExpectations:@[ expectation ] timeout:5.0];
55  OCMVerify([plugin applicationWillEnterForeground:[UIApplication sharedApplication]]);
56 }
57 
58 - (void)testWillResignActive {
59  XCTNSNotificationExpectation* expectation =
60  [[XCTNSNotificationExpectation alloc] initWithName:UIApplicationWillResignActiveNotification];
61 
63  id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
64  [delegate addDelegate:plugin];
65  [[NSNotificationCenter defaultCenter]
66  postNotificationName:UIApplicationWillResignActiveNotification
67  object:nil];
68  [self waitForExpectations:@[ expectation ] timeout:5.0];
69  OCMVerify([plugin applicationWillResignActive:[UIApplication sharedApplication]]);
70 }
71 
72 - (void)testDidBecomeActive {
73  XCTNSNotificationExpectation* expectation =
74  [[XCTNSNotificationExpectation alloc] initWithName:UIApplicationDidBecomeActiveNotification];
75 
77  id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
78  [delegate addDelegate:plugin];
79  [[NSNotificationCenter defaultCenter]
80  postNotificationName:UIApplicationDidBecomeActiveNotification
81  object:nil];
82  [self waitForExpectations:@[ expectation ] timeout:5.0];
83  OCMVerify([plugin applicationDidBecomeActive:[UIApplication sharedApplication]]);
84 }
85 
86 - (void)testWillTerminate {
87  XCTNSNotificationExpectation* expectation =
88  [[XCTNSNotificationExpectation alloc] initWithName:UIApplicationWillTerminateNotification];
89 
91  id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
92  [delegate addDelegate:plugin];
93  [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillTerminateNotification
94  object:nil];
95  [self waitForExpectations:@[ expectation ] timeout:5.0];
96  OCMVerify([plugin applicationWillTerminate:[UIApplication sharedApplication]]);
97 }
98 
99 - (void)testReleasesPluginOnDealloc {
100  __weak id<FlutterApplicationLifeCycleDelegate> weakPlugin;
101  __weak FlutterPluginAppLifeCycleDelegate* weakDelegate;
102  @autoreleasepool {
103  FakePlugin* fakePlugin = [[FakePlugin alloc] init];
104  weakPlugin = fakePlugin;
106  [delegate addDelegate:fakePlugin];
107  weakDelegate = delegate;
108  }
109  XCTAssertNil(weakPlugin);
110  XCTAssertNil(weakDelegate);
111 }
112 
113 #endif
114 
115 @end
FlutterPlugin-p
Definition: FlutterPlugin.h:189
FlutterMacros.h
FlutterPluginAppLifeCycleDelegate.h
FlutterPluginAppLifeCycleDelegate
Definition: FlutterPluginAppLifeCycleDelegate.h:16
FlutterPluginAppLifeCycleDelegateTest
Definition: FlutterPluginAppLifeCycleDelegateTest.mm:19
FlutterApplicationLifeCycleDelegate-p
Definition: FlutterPlugin.h:25
-[FlutterPluginAppLifeCycleDelegate addDelegate:]
void addDelegate:(NSObject< FlutterApplicationLifeCycleDelegate > *delegate)
Definition: FlutterPluginAppLifeCycleDelegate.mm:91
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13
FakePlugin
Definition: FlutterPluginAppLifeCycleDelegateTest.mm:13