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"])
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);
85 - (void)testLaunchUrlWithDeepLinkingNotSet {
86 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
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);
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);
115 - (void)testLaunchUrlWithQueryParameterAndFragment {
116 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
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);
130 - (void)testLaunchUrlWithFragmentNoQueryParameter {
131 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
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);
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]);
171 - (void)testGrabLaunchEngineWithoutPlugins {
175 #pragma mark - Deep linking
177 - (void)testUniversalLinkPushRouteInformation {
178 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
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);
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) {
202 void (^handler)(BOOL success);
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 {
221 self.appDelegate.pluginRegistrant = mockRegistrant;
225 - (void)testSetGetPluginRegistrantSelf {
229 self.appDelegate = nil;
FlutterAppLifeCycleProvider UIWindow * window
NSObject< FlutterPluginRegistrant > * pluginRegistrant
FlutterViewController *(^ rootFlutterViewControllerGetter)(void)
id mockEngineFirstFrameCallback
FlutterAppDelegate * appDelegate
FlutterViewController * viewController