5#import <OCMock/OCMock.h>
6#import <XCTest/XCTest.h>
46 self.mockNavigationChannel = navigationChannel;
49 OCMStub([
engine navigationChannel]).andReturn(navigationChannel);
63 [
self.mockMainBundle stopMocking];
67- (void)testLaunchUrl {
68 OCMStub([
self.mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
71 OCMStub([
self.mockNavigationChannel
72 invokeMethod:
@"pushRouteInformation"
73 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test"}])
77 [
self.appDelegate application:[UIApplication sharedApplication]
78 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
81 XCTAssertTrue(result);
82 OCMVerifyAll(
self.mockNavigationChannel);
85- (void)testLaunchUrlWithDeepLinkingNotSet {
86 OCMStub([
self.mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
89 OCMStub([
self.mockNavigationChannel
90 invokeMethod:
@"pushRouteInformation"
91 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test"}])
95 [
self.appDelegate application:[UIApplication sharedApplication]
96 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
99 XCTAssertTrue(result);
100 OCMVerifyAll(
self.mockNavigationChannel);
103- (void)testLaunchUrlWithDeepLinkingDisabled {
104 OCMStub([
self.mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
108 [
self.appDelegate application:[UIApplication sharedApplication]
109 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
111 XCTAssertFalse(result);
112 OCMReject([
self.mockNavigationChannel invokeMethod:OCMOCK_ANY arguments:OCMOCK_ANY]);
115- (void)testLaunchUrlWithQueryParameterAndFragment {
116 OCMStub([
self.mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
118 OCMStub([
self.mockNavigationChannel
119 invokeMethod:
@"pushRouteInformation"
120 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test#fragment"}])
122 BOOL result = [
self.appDelegate
123 application:[UIApplication sharedApplication]
124 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test#fragment"]
126 XCTAssertTrue(result);
127 OCMVerifyAll(
self.mockNavigationChannel);
130- (void)testLaunchUrlWithFragmentNoQueryParameter {
131 OCMStub([
self.mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
133 OCMStub([
self.mockNavigationChannel
134 invokeMethod:
@"pushRouteInformation"
135 arguments:@{
@"location" :
@"http://myApp/custom/route#fragment"}])
138 [
self.appDelegate application:[UIApplication sharedApplication]
139 openURL:[NSURL URLWithString:@"http://myApp/custom/route#fragment"]
141 XCTAssertTrue(result);
142 OCMVerifyAll(
self.mockNavigationChannel);
145- (void)testReleasesWindowOnDealloc {
146 __weak UIWindow* weakWindow;
148 id mockWindow = OCMClassMock([UIWindow
class]);
151 weakWindow = mockWindow;
152 XCTAssertNotNil(weakWindow);
153 [mockWindow stopMocking];
158 XCTAssertNil(weakWindow);
161- (void)testGrabLaunchEngine {
163 [
self.mockMainBundle stopMocking];
164 self.appDelegate.rootFlutterViewControllerGetter = nil;
166 XCTAssertFalse([
self.appDelegate hasPlugin:
@"hello"]);
167 XCTAssertNotNil([
self.appDelegate takeLaunchEngine]);
168 XCTAssertNil([
self.appDelegate takeLaunchEngine]);
171- (void)testGrabLaunchEngineWithoutPlugins {
172 XCTAssertNil([
self.appDelegate takeLaunchEngine]);
175#pragma mark - Deep linking
177- (void)testUniversalLinkPushRouteInformation {
178 OCMStub([
self.mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
180 OCMStub([
self.mockNavigationChannel
181 invokeMethod:
@"pushRouteInformation"
182 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test"}])
184 NSUserActivity* userActivity = [[NSUserActivity alloc] initWithActivityType:@"com.example.test"];
185 userActivity.webpageURL = [NSURL URLWithString:@"http://myApp/custom/route?query=test"];
186 BOOL result = [
self.appDelegate
187 application:[UIApplication sharedApplication]
188 continueUserActivity:userActivity
189 restorationHandler:^(NSArray<id<UIUserActivityRestoring>>* __nullable restorableObjects){
191 XCTAssertTrue(result);
192 OCMVerifyAll(
self.mockNavigationChannel);
195- (void)testUseNonDeprecatedOpenURLAPI {
196 OCMStub([
self.mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
198 NSUserActivity* userActivity = [[NSUserActivity alloc] initWithActivityType:@"com.example.test"];
199 userActivity.webpageURL = [NSURL URLWithString:@"http://myApp/custom/route?query=nonexist"];
200 OCMStub([
self.engine sendDeepLinkToFramework:[OCMArg any] completionHandler:[OCMArg any]])
201 .andDo(^(NSInvocation* invocation) {
203 [invocation getArgument:&handler atIndex:3];
206 id mockApplication = OCMClassMock([UIApplication
class]);
207 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
208 BOOL result = [
self.appDelegate
209 application:[UIApplication sharedApplication]
210 continueUserActivity:userActivity
211 restorationHandler:^(NSArray<id<UIUserActivityRestoring>>* __nullable restorableObjects){
213 XCTAssertTrue(result);
214 OCMVerify([mockApplication openURL:[OCMArg any]
216 completionHandler:[OCMArg any]]);
219- (void)testSetGetPluginRegistrant {
220 id mockRegistrant = OCMProtocolMock(
@protocol(FlutterPluginRegistrant));
221 self.appDelegate.pluginRegistrant = mockRegistrant;
222 XCTAssertEqual(
self.appDelegate.pluginRegistrant, mockRegistrant);
225- (void)testSetGetPluginRegistrantSelf {
229 self.appDelegate = nil;
const gchar FlBinaryMessengerMessageHandler handler
FlutterDesktopBinaryReply callback
FlutterAppLifeCycleProvider UIWindow * window
NSObject< FlutterPluginRegistrant > * pluginRegistrant
FlutterViewController *(^ rootFlutterViewControllerGetter)(void)
id mockEngineFirstFrameCallback
FlutterAppDelegate * appDelegate
FlutterViewController * viewController