Flutter Engine
The Flutter Engine
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
11@property(nonatomic, copy, nullable) NSArray<NSURL*>* receivedURLs;
12@end
13
15@end
16
18@property(nonatomic, copy, nullable) NSArray<NSURL*>* receivedURLs;
19@end
20
22
23- (BOOL)handleOpenURLs:(NSArray<NSURL*>*)urls {
24 self.receivedURLs = [urls copy];
25 return YES;
26}
27
28@end
29
30namespace flutter::testing {
31
32TEST(FlutterAppDelegateTest, DoesNotCallDelegatesWithoutHandler) {
33 FlutterAppDelegate* appDelegate = [[FlutterAppDelegate 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
43TEST(FlutterAppDelegateTest, ReceivesOpenURLs) {
44 FlutterAppDelegate* appDelegate = [[FlutterAppDelegate 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
57TEST(FlutterAppDelegateTest, OperURLsStopsAfterHandled) {
58 FlutterAppDelegate* appDelegate = [[FlutterAppDelegate 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
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
Definition: SkSwizzler.cpp:31
void application:openURLs:(NSApplication *application, [openURLs] NSArray< NSURL * > *urls)
void addApplicationLifecycleDelegate:(NSObject< FlutterAppLifecycleDelegate > *delegate)
Definition: dart.idl:68
TEST(FlutterAppDelegateTest, OperURLsStopsAfterHandled)
int BOOL
Definition: windows_types.h:37