Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5441cec

Browse files
committed
added test for openURL
1 parent 51e56d6 commit 5441cec

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ shared_library("ios_test_flutter") {
206206
"//build/config:symbol_visibility_hidden",
207207
]
208208
sources = [
209+
"framework/Source/FlutterAppDelegateTest.mm",
209210
"framework/Source/FlutterBinaryMessengerRelayTest.mm",
210211
"framework/Source/FlutterDartProjectTest.mm",
211212
"framework/Source/FlutterEngineTest.mm",

shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
#import "flutter/fml/logging.h"
88
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h"
99
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
10+
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate_Test.h"
1011
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
1112
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate_internal.h"
1213

1314
static NSString* kUIBackgroundMode = @"UIBackgroundModes";
1415
static NSString* kRemoteNotificationCapabitiliy = @"remote-notification";
1516
static NSString* kBackgroundFetchCapatibility = @"fetch";
1617

18+
@interface FlutterAppDelegate ()
19+
@property(nonatomic, copy) FlutterViewController* (^rootFlutterViewControllerGetter)(void);
20+
@end
21+
1722
@implementation FlutterAppDelegate {
1823
FlutterPluginAppLifeCycleDelegate* _lifeCycleDelegate;
1924
}
@@ -27,6 +32,7 @@ - (instancetype)init {
2732

2833
- (void)dealloc {
2934
[_lifeCycleDelegate release];
35+
[_rootFlutterViewControllerGetter release];
3036
[super dealloc];
3137
}
3238

@@ -43,6 +49,9 @@ - (BOOL)application:(UIApplication*)application
4349
// Returns the key window's rootViewController, if it's a FlutterViewController.
4450
// Otherwise, returns nil.
4551
- (FlutterViewController*)rootFlutterViewController {
52+
if (_rootFlutterViewControllerGetter != nil) {
53+
return _rootFlutterViewControllerGetter();
54+
}
4655
UIViewController* rootViewController = _window.rootViewController;
4756
if ([rootViewController isKindOfClass:[FlutterViewController class]]) {
4857
return (FlutterViewController*)rootViewController;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
8+
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h"
9+
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h"
10+
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
11+
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate_Test.h"
12+
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h"
13+
14+
FLUTTER_ASSERT_ARC
15+
16+
@interface FlutterAppDelegateTest : XCTestCase
17+
@end
18+
19+
@implementation FlutterAppDelegateTest
20+
21+
- (void)testLaunchUrl {
22+
FlutterAppDelegate* appDelegate = [[FlutterAppDelegate alloc] init];
23+
FlutterViewController* viewController = OCMClassMock([FlutterViewController class]);
24+
FlutterEngine* engine = OCMClassMock([FlutterEngine class]);
25+
FlutterMethodChannel* navigationChannel = OCMClassMock([FlutterMethodChannel class]);
26+
OCMStub([engine navigationChannel]).andReturn(navigationChannel);
27+
OCMStub([viewController engine]).andReturn(engine);
28+
OCMStub([engine waitForFirstFrame:3.0 callback:([OCMArg invokeBlockWithArgs:@(NO), nil])]);
29+
appDelegate.rootFlutterViewControllerGetter = ^{
30+
return viewController;
31+
};
32+
NSURL* url = [NSURL URLWithString:@"http://example.com"];
33+
NSDictionary<UIApplicationOpenURLOptionsKey, id>* options = @{};
34+
BOOL result = [appDelegate application:[UIApplication sharedApplication]
35+
openURL:url
36+
options:options];
37+
XCTAssertTrue(result);
38+
OCMVerify([navigationChannel invokeMethod:@"pushRoute" arguments:url.path]);
39+
}
40+
41+
@end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
@class FlutterViewController;
3+
4+
@interface FlutterAppDelegate (Test)
5+
@property(nonatomic, copy) FlutterViewController* (^rootFlutterViewControllerGetter)(void);
6+
@end

shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h"
66

7+
@class FlutterBinaryMessengerRelay;
8+
79
// Category to add test-only visibility.
810
@interface FlutterEngine (Test) <FlutterBinaryMessenger>
911
- (void)setBinaryMessenger:(FlutterBinaryMessengerRelay*)binaryMessenger;

0 commit comments

Comments
 (0)