5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
43 self.mockNavigationChannel = navigationChannel;
46 OCMStub([
engine navigationChannel]).andReturn(navigationChannel);
59 [
self.mockMainBundle stopMocking];
63 - (void)testLaunchUrl {
64 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
68 invokeMethod:
@"pushRouteInformation"
69 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test"}])
73 [
self.appDelegate application:[UIApplication sharedApplication]
74 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
77 XCTAssertTrue(result);
81 - (void)testLaunchUrlWithDeepLinkingNotSet {
82 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
86 invokeMethod:
@"pushRouteInformation"
87 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test"}])
91 [
self.appDelegate application:[UIApplication sharedApplication]
92 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
95 XCTAssertTrue(result);
99 - (void)testLaunchUrlWithDeepLinkingDisabled {
100 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
104 [
self.appDelegate application:[UIApplication sharedApplication]
105 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
107 XCTAssertFalse(result);
111 - (void)testLaunchUrlWithQueryParameterAndFragment {
112 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
115 invokeMethod:
@"pushRouteInformation"
116 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test#fragment"}])
118 BOOL result = [
self.appDelegate
119 application:[UIApplication sharedApplication]
120 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test#fragment"]
122 XCTAssertTrue(result);
126 - (void)testLaunchUrlWithFragmentNoQueryParameter {
127 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
130 invokeMethod:
@"pushRouteInformation"
131 arguments:@{
@"location" :
@"http://myApp/custom/route#fragment"}])
134 [
self.appDelegate application:[UIApplication sharedApplication]
135 openURL:[NSURL URLWithString:@"http://myApp/custom/route#fragment"]
137 XCTAssertTrue(result);
141 - (void)testReleasesWindowOnDealloc {
142 __weak UIWindow* weakWindow;
144 id mockWindow = OCMClassMock([UIWindow
class]);
147 weakWindow = mockWindow;
148 XCTAssertNotNil(weakWindow);
149 [mockWindow stopMocking];
154 XCTAssertNil(weakWindow);
157 #pragma mark - Deep linking
159 - (void)testUniversalLinkPushRouteInformation {
160 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
163 invokeMethod:
@"pushRouteInformation"
164 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test"}])
166 NSUserActivity* userActivity = [[NSUserActivity alloc] initWithActivityType:@"com.example.test"];
167 userActivity.webpageURL = [NSURL URLWithString:@"http://myApp/custom/route?query=test"];
168 BOOL result = [
self.appDelegate
169 application:[UIApplication sharedApplication]
170 continueUserActivity:userActivity
171 restorationHandler:^(NSArray<id<UIUserActivityRestoring>>* __nullable restorableObjects){
173 XCTAssertTrue(result);
177 - (void)testUseNonDeprecatedOpenURLAPI {
178 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
180 NSUserActivity* userActivity = [[NSUserActivity alloc] initWithActivityType:@"com.example.test"];
181 userActivity.webpageURL = [NSURL URLWithString:@"http://myApp/custom/route?query=nonexist"];
182 OCMStub([
self.
viewController sendDeepLinkToFramework:[OCMArg any] completionHandler:[OCMArg any]])
183 .andDo(^(NSInvocation* invocation) {
184 void (^handler)(BOOL success);
185 [invocation getArgument:&handler atIndex:3];
188 id mockApplication = OCMClassMock([UIApplication
class]);
189 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
190 BOOL result = [
self.appDelegate
191 application:[UIApplication sharedApplication]
192 continueUserActivity:userActivity
193 restorationHandler:^(NSArray<id<UIUserActivityRestoring>>* __nullable restorableObjects){
195 XCTAssertTrue(result);
196 OCMVerify([mockApplication openURL:[OCMArg any]
198 completionHandler:[OCMArg any]]);
FlutterAppLifeCycleProvider UIWindow * window
FlutterViewController *(^ rootFlutterViewControllerGetter)(void)
id mockEngineFirstFrameCallback
FlutterAppDelegate * appDelegate
FlutterViewController * viewController