| Flutter macOS Embedder |

FlutterAppDelegateTest.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/FlutterAppDelegate.h"
6
7 #import "flutter/testing/testing.h"
8 #include "third_party/googletest/googletest/include/gtest/gtest.h"
9
10 @interface AppDelegateNoopFlutterAppLifecycleDelegate : NSObject <FlutterAppLifecycleDelegate>
11 @property(nonatomic, copy, nullable) NSArray<NSURL*>* receivedURLs;
12 @end
13
14 @implementation AppDelegateNoopFlutterAppLifecycleDelegate
15 @end
16
17 @interface AppDelegateTestFlutterAppLifecycleDelegate : NSObject <FlutterAppLifecycleDelegate>
18 @property(nonatomic, copy, nullable) NSArray<NSURL*>* receivedURLs;
19 @end
20
21 @implementation AppDelegateTestFlutterAppLifecycleDelegate
22
23 - (BOOL)handleOpenURLs:(NSArray<NSURL*>*)urls {
24 self.receivedURLs = [urls copy];
25 return YES;
26 }
27
28 @end
29
30 namespace flutter::testing {
31
32 TEST(FlutterAppDelegateTest, DoesNotCallDelegatesWithoutHandler) {
33 FlutterAppDelegate* appDelegate = [[FlutterAppDelegate alloc] init];
34 AppDelegateNoopFlutterAppLifecycleDelegate* noopDelegate =
35 [[AppDelegateNoopFlutterAppLifecycleDelegate alloc] init];
36 [appDelegate addApplicationLifecycleDelegate:noopDelegate];
37
38 [appDelegate application:NSApplication.sharedApplication openURLs:@[]];
39 // No EXPECT, since the test is that the call doesn't throw due to calling without checking that
40 // the method is implemented.
41 }
42
43 TEST(FlutterAppDelegateTest, ReceivesOpenURLs) {
44 FlutterAppDelegate* appDelegate = [[FlutterAppDelegate alloc] init];
45 AppDelegateTestFlutterAppLifecycleDelegate* delegate =
46 [[AppDelegateTestFlutterAppLifecycleDelegate alloc] init];
47 [appDelegate addApplicationLifecycleDelegate:delegate];
48
49 NSURL* URL = [NSURL URLWithString:@"https://flutter.dev"];
50 EXPECT_NE(URL, nil);
51 NSArray<NSURL*>* URLs = @[ URL ];
52 [appDelegate application:NSApplication.sharedApplication openURLs:URLs];
53
54 EXPECT_EQ([delegate receivedURLs], URLs);
55 }
56
57 TEST(FlutterAppDelegateTest, OperURLsStopsAfterHandled) {
58 FlutterAppDelegate* appDelegate = [[FlutterAppDelegate alloc] init];
59 AppDelegateTestFlutterAppLifecycleDelegate* firstDelegate =
60 [[AppDelegateTestFlutterAppLifecycleDelegate alloc] init];
61 AppDelegateTestFlutterAppLifecycleDelegate* secondDelegate =
62 [[AppDelegateTestFlutterAppLifecycleDelegate alloc] init];
63 [appDelegate addApplicationLifecycleDelegate:firstDelegate];
64 [appDelegate addApplicationLifecycleDelegate:secondDelegate];
65
66 NSURL* URL = [NSURL URLWithString:@"https://flutter.dev"];
67 EXPECT_NE(URL, nil);
68 NSArray<NSURL*>* URLs = @[ URL ];
69 [appDelegate application:NSApplication.sharedApplication openURLs:URLs];
70
71 EXPECT_EQ([firstDelegate receivedURLs], URLs);
72 EXPECT_EQ([secondDelegate receivedURLs], nil);
73 }
74
75 } // namespace flutter::testing
AppDelegateNoopFlutterAppLifecycleDelegate::receivedURLs
NSArray< NSURL * > * receivedURLs
Definition: FlutterAppDelegateTest.mm:11
flutter::testing
Definition: AccessibilityBridgeMacTest.mm:13
-[FlutterAppLifecycleProvider-p addApplicationLifecycleDelegate:]
void addApplicationLifecycleDelegate:(nonnull NSObject< FlutterAppLifecycleDelegate > *delegate)
FlutterAppLifecycleDelegate-p
Definition: FlutterAppLifecycleDelegate.h:21
AppDelegateNoopFlutterAppLifecycleDelegate
Definition: FlutterAppDelegateTest.mm:10
AppDelegateTestFlutterAppLifecycleDelegate
Definition: FlutterAppDelegateTest.mm:17
FlutterAppDelegate
Definition: FlutterAppDelegate.h:54
AppDelegateTestFlutterAppLifecycleDelegate::receivedURLs
NSArray< NSURL * > * receivedURLs
Definition: FlutterAppDelegateTest.mm:18
FlutterAppDelegate.h
flutter::testing::TEST
TEST(FlutterAppDelegateTest, OperURLsStopsAfterHandled)
Definition: FlutterAppDelegateTest.mm:57