Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
shell
platform
darwin
macos
framework
Source
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
TEST
#define TEST(S, s, D, expected)
Definition
FitsInTest.cpp:15
self
return self
Definition
FlutterTextureRegistryRelay.mm:19
AppDelegateNoopFlutterAppLifecycleDelegate
Definition
FlutterAppDelegateTest.mm:10
AppDelegateNoopFlutterAppLifecycleDelegate::receivedURLs
NSArray< NSURL * > * receivedURLs
Definition
FlutterAppDelegateTest.mm:11
AppDelegateTestFlutterAppLifecycleDelegate
Definition
FlutterAppDelegateTest.mm:17
FlutterAppDelegateTest
Definition
FlutterAppDelegateTest.mm:17
FlutterAppDelegate
Definition
FlutterAppDelegate.h:28
-[FlutterAppDelegate application:openURLs:]
void application:openURLs:(NSApplication *application, [openURLs] NSArray< NSURL * > *urls)
Definition
FlutterAppDelegate.mm:68
-[FlutterAppDelegate addApplicationLifecycleDelegate:]
void addApplicationLifecycleDelegate:(NSObject< FlutterAppLifecycleDelegate > *delegate)
Definition
FlutterAppDelegate.mm:47
URL
Definition
dart.idl:68
copy
Definition
copy.py:1
flutter::testing
Definition
persistent_cache.h:22
FlutterAppLifecycleDelegate-p
Definition
FlutterAppLifecycleDelegate.h:21
BOOL
int BOOL
Definition
windows_types.h:37
Generated on Fri Apr 26 2024 06:14:24 for Flutter Engine by
1.9.8