| Flutter macOS Embedder |

FlutterAppLifecycleDelegateTest.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 "flutter/shell/platform/darwin/macos/framework/Headers/FlutterAppLifecycleDelegate.h"
6
7 #import "flutter/testing/testing.h"
8 #include "third_party/googletest/googletest/include/gtest/gtest.h"
9
10 @interface TestFlutterAppLifecycleDelegate : NSObject <FlutterAppLifecycleDelegate>
11 @property(nonatomic, readwrite, nullable) NSNotification* lastNotification;
12 @end
13
14 @implementation TestFlutterAppLifecycleDelegate
15
16 - (void)setNotification:(NSNotification*)notification {
17 self.lastNotification = notification;
18 }
19
20 - (void)handleWillFinishLaunching:(NSNotification*)notification {
21 [self setNotification:notification];
22 }
23
24 - (void)handleDidFinishLaunching:(NSNotification*)notification {
25 [self setNotification:notification];
26 }
27
28 - (void)handleWillBecomeActive:(NSNotification*)notification {
29 [self setNotification:notification];
30 }
31
32 - (void)handleDidBecomeActive:(NSNotification*)notification {
33 [self setNotification:notification];
34 }
35
36 - (void)handleWillResignActive:(NSNotification*)notification {
37 [self setNotification:notification];
38 }
39
40 - (void)handleDidResignActive:(NSNotification*)notification {
41 [self setNotification:notification];
42 }
43
44 - (void)handleWillHide:(NSNotification*)notification {
45 [self setNotification:notification];
46 }
47
48 - (void)handleDidHide:(NSNotification*)notification {
49 [self setNotification:notification];
50 }
51
52 - (void)handleWillUnhide:(NSNotification*)notification {
53 [self setNotification:notification];
54 }
55
56 - (void)handleDidUnhide:(NSNotification*)notification {
57 [self setNotification:notification];
58 }
59
60 - (void)handleDidChangeScreenParameters:(NSNotification*)notification {
61 [self setNotification:notification];
62 }
63
64 - (void)handleDidChangeOcclusionState:(NSNotification*)notification API_AVAILABLE(macos(10.9)) {
65 [self setNotification:notification];
66 }
67
68 - (void)handleWillTerminate:(NSNotification*)notification {
69 [self setNotification:notification];
70 }
71
72 @end
73
74 namespace flutter::testing {
75
76 TEST(FlutterAppLifecycleDelegateTest, RespondsToWillFinishLaunching) {
77 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
78 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
79 [registrar addDelegate:delegate];
80
81 NSNotification* willFinishLaunching =
82 [NSNotification notificationWithName:NSApplicationWillFinishLaunchingNotification object:nil];
83 [registrar handleWillFinishLaunching:willFinishLaunching];
84 EXPECT_EQ([delegate lastNotification], willFinishLaunching);
85 }
86
87 TEST(FlutterAppLifecycleDelegateTest, RespondsToDidFinishLaunching) {
88 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
89 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
90 [registrar addDelegate:delegate];
91
92 NSNotification* didFinishLaunching =
93 [NSNotification notificationWithName:NSApplicationDidFinishLaunchingNotification object:nil];
94 [registrar handleDidFinishLaunching:didFinishLaunching];
95 EXPECT_EQ([delegate lastNotification], didFinishLaunching);
96 }
97
98 TEST(FlutterAppLifecycleDelegateTest, RespondsToWillBecomeActive) {
99 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
100 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
101 [registrar addDelegate:delegate];
102
103 NSNotification* willBecomeActive =
104 [NSNotification notificationWithName:NSApplicationWillBecomeActiveNotification object:nil];
105 [registrar handleWillBecomeActive:willBecomeActive];
106 EXPECT_EQ([delegate lastNotification], willBecomeActive);
107 }
108
109 TEST(FlutterAppLifecycleDelegateTest, RespondsToDidBecomeActive) {
110 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
111 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
112 [registrar addDelegate:delegate];
113
114 NSNotification* didBecomeActive =
115 [NSNotification notificationWithName:NSApplicationDidBecomeActiveNotification object:nil];
116 [registrar handleDidBecomeActive:didBecomeActive];
117 EXPECT_EQ([delegate lastNotification], didBecomeActive);
118 }
119
120 TEST(FlutterAppLifecycleDelegateTest, RespondsToWillResignActive) {
121 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
122 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
123 [registrar addDelegate:delegate];
124
125 NSNotification* willResignActive =
126 [NSNotification notificationWithName:NSApplicationWillResignActiveNotification object:nil];
127 [registrar handleWillResignActive:willResignActive];
128 EXPECT_EQ([delegate lastNotification], willResignActive);
129 }
130
131 TEST(FlutterAppLifecycleDelegateTest, RespondsToDidResignActive) {
132 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
133 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
134 [registrar addDelegate:delegate];
135
136 NSNotification* didResignActive =
137 [NSNotification notificationWithName:NSApplicationDidResignActiveNotification object:nil];
138 [registrar handleDidResignActive:didResignActive];
139 EXPECT_EQ([delegate lastNotification], didResignActive);
140 }
141
142 TEST(FlutterAppLifecycleDelegateTest, RespondsToWillTerminate) {
143 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
144 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
145 [registrar addDelegate:delegate];
146
147 NSNotification* applicationWillTerminate =
148 [NSNotification notificationWithName:NSApplicationWillTerminateNotification object:nil];
149 [registrar handleWillTerminate:applicationWillTerminate];
150 EXPECT_EQ([delegate lastNotification], applicationWillTerminate);
151 }
152
153 TEST(FlutterAppLifecycleDelegateTest, RespondsToWillHide) {
154 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
155 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
156 [registrar addDelegate:delegate];
157
158 NSNotification* willHide = [NSNotification notificationWithName:NSApplicationWillHideNotification
159 object:nil];
160 [registrar handleWillHide:willHide];
161 EXPECT_EQ([delegate lastNotification], willHide);
162 }
163
164 TEST(FlutterAppLifecycleDelegateTest, RespondsToWillUnhide) {
165 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
166 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
167 [registrar addDelegate:delegate];
168
169 NSNotification* willUnhide =
170 [NSNotification notificationWithName:NSApplicationWillUnhideNotification object:nil];
171 [registrar handleWillUnhide:willUnhide];
172 EXPECT_EQ([delegate lastNotification], willUnhide);
173 }
174
175 TEST(FlutterAppLifecycleDelegateTest, RespondsToDidHide) {
176 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
177 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
178 [registrar addDelegate:delegate];
179
180 NSNotification* didHide = [NSNotification notificationWithName:NSApplicationDidHideNotification
181 object:nil];
182 [registrar handleDidHide:didHide];
183 EXPECT_EQ([delegate lastNotification], didHide);
184 }
185
186 TEST(FlutterAppLifecycleDelegateTest, RespondsToDidUnhide) {
187 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
188 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
189 [registrar addDelegate:delegate];
190
191 NSNotification* didUnhide =
192 [NSNotification notificationWithName:NSApplicationDidUnhideNotification object:nil];
193 [registrar handleDidUnhide:didUnhide];
194 EXPECT_EQ([delegate lastNotification], didUnhide);
195 }
196
197 TEST(FlutterAppLifecycleDelegateTest, RespondsToDidChangeScreenParameters) {
198 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
199 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
200 [registrar addDelegate:delegate];
201
202 NSNotification* didChangeScreenParameters =
203 [NSNotification notificationWithName:NSApplicationDidChangeScreenParametersNotification
204 object:nil];
205 [registrar handleDidChangeScreenParameters:didChangeScreenParameters];
206 EXPECT_EQ([delegate lastNotification], didChangeScreenParameters);
207 }
208
209 TEST(FlutterAppLifecycleDelegateTest, RespondsToDidChangeOcclusionState) {
210 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
211 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
212 [registrar addDelegate:delegate];
213
214 NSNotification* didChangeOcclusionState =
215 [NSNotification notificationWithName:NSApplicationDidChangeOcclusionStateNotification
216 object:nil];
217 if ([registrar respondsToSelector:@selector(handleDidChangeOcclusionState:)]) {
218 [registrar handleDidChangeOcclusionState:didChangeOcclusionState];
219 EXPECT_EQ([delegate lastNotification], didChangeOcclusionState);
220 }
221 }
222
223 } // namespace flutter::testing
-[FlutterAppLifecycleDelegate-p handleDidHide:]
void handleDidHide:(NSNotification *notification)
-[FlutterAppLifecycleDelegate-p handleWillResignActive:]
void handleWillResignActive:(NSNotification *notification)
-[FlutterAppLifecycleDelegate-p handleDidChangeOcclusionState:]
void handleDidChangeOcclusionState:(NSNotification *notification)
FlutterAppLifecycleRegistrar
Definition: FlutterAppLifecycleDelegate.h:126
-[FlutterAppLifecycleRegistrar addDelegate:]
void addDelegate:(NSObject< FlutterAppLifecycleDelegate > *delegate)
Definition: FlutterAppLifecycleDelegate.mm:76
-[FlutterAppLifecycleDelegate-p handleWillHide:]
void handleWillHide:(NSNotification *notification)
flutter::testing
Definition: AccessibilityBridgeMacTest.mm:11
FlutterAppLifecycleDelegate-p
Definition: FlutterAppLifecycleDelegate.h:21
-[FlutterAppLifecycleDelegate-p handleDidUnhide:]
void handleDidUnhide:(NSNotification *notification)
-[FlutterAppLifecycleDelegate-p handleWillTerminate:]
void handleWillTerminate:(NSNotification *notification)
-[FlutterAppLifecycleDelegate-p handleDidChangeScreenParameters:]
void handleDidChangeScreenParameters:(NSNotification *notification)
-[FlutterAppLifecycleDelegate-p handleDidFinishLaunching:]
void handleDidFinishLaunching:(NSNotification *notification)
TestFlutterAppLifecycleDelegate::lastNotification
NSNotification * lastNotification
Definition: FlutterAppLifecycleDelegateTest.mm:11
-[FlutterAppLifecycleDelegate-p handleWillFinishLaunching:]
void handleWillFinishLaunching:(NSNotification *notification)
flutter::testing::TEST
TEST(FlutterAppLifecycleDelegateTest, RespondsToDidChangeOcclusionState)
Definition: FlutterAppLifecycleDelegateTest.mm:209
-[FlutterAppLifecycleDelegate-p handleWillBecomeActive:]
void handleWillBecomeActive:(NSNotification *notification)
-[FlutterAppLifecycleDelegate-p handleDidBecomeActive:]
void handleDidBecomeActive:(NSNotification *notification)
-[FlutterAppLifecycleDelegate-p handleWillUnhide:]
void handleWillUnhide:(NSNotification *notification)
FlutterAppLifecycleDelegate.h
-[FlutterAppLifecycleDelegate-p handleDidResignActive:]
void handleDidResignActive:(NSNotification *notification)
TestFlutterAppLifecycleDelegate
Definition: FlutterAppLifecycleDelegateTest.mm:10