5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
44 self.mockNavigationChannel = navigationChannel;
47 OCMStub([
engine navigationChannel]).andReturn(navigationChannel);
60 [
self.mockMainBundle stopMocking];
64 - (void)testLaunchUrl {
65 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
69 invokeMethod:
@"pushRouteInformation"
70 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test"}])
74 [
self.appDelegate application:[UIApplication sharedApplication]
75 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
78 XCTAssertTrue(result);
82 - (void)testLaunchUrlWithDeepLinkingNotSet {
83 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
87 invokeMethod:
@"pushRouteInformation"
88 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test"}])
92 [
self.appDelegate application:[UIApplication sharedApplication]
93 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
96 XCTAssertTrue(result);
100 - (void)testLaunchUrlWithDeepLinkingDisabled {
101 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
105 [
self.appDelegate application:[UIApplication sharedApplication]
106 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
108 XCTAssertFalse(result);
112 - (void)testLaunchUrlWithQueryParameterAndFragment {
113 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
116 invokeMethod:
@"pushRouteInformation"
117 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test#fragment"}])
119 BOOL result = [
self.appDelegate
120 application:[UIApplication sharedApplication]
121 openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test#fragment"]
123 XCTAssertTrue(result);
127 - (void)testLaunchUrlWithFragmentNoQueryParameter {
128 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
131 invokeMethod:
@"pushRouteInformation"
132 arguments:@{
@"location" :
@"http://myApp/custom/route#fragment"}])
135 [
self.appDelegate application:[UIApplication sharedApplication]
136 openURL:[NSURL URLWithString:@"http://myApp/custom/route#fragment"]
138 XCTAssertTrue(result);
142 - (void)testReleasesWindowOnDealloc {
143 __weak UIWindow* weakWindow;
145 id mockWindow = OCMClassMock([UIWindow
class]);
148 weakWindow = mockWindow;
149 XCTAssertNotNil(weakWindow);
150 [mockWindow stopMocking];
155 XCTAssertNil(weakWindow);
158 - (void)testGrabLaunchEngine {
160 [
self.mockMainBundle stopMocking];
161 self.appDelegate.rootFlutterViewControllerGetter = nil;
163 XCTAssertFalse([
self.
appDelegate hasPlugin:
@"hello"]);
164 XCTAssertNotNil([
self.
appDelegate takeLaunchEngine]);
168 - (void)testGrabLaunchEngineWithoutPlugins {
172 #pragma mark - Deep linking
174 - (void)testUniversalLinkPushRouteInformation {
175 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
178 invokeMethod:
@"pushRouteInformation"
179 arguments:@{
@"location" :
@"http://myApp/custom/route?query=test"}])
181 NSUserActivity* userActivity = [[NSUserActivity alloc] initWithActivityType:@"com.example.test"];
182 userActivity.webpageURL = [NSURL URLWithString:@"http://myApp/custom/route?query=test"];
183 BOOL result = [
self.appDelegate
184 application:[UIApplication sharedApplication]
185 continueUserActivity:userActivity
186 restorationHandler:^(NSArray<id<UIUserActivityRestoring>>* __nullable restorableObjects){
188 XCTAssertTrue(result);
192 - (void)testUseNonDeprecatedOpenURLAPI {
193 OCMStub([
self.
mockMainBundle objectForInfoDictionaryKey:
@"FlutterDeepLinkingEnabled"])
195 NSUserActivity* userActivity = [[NSUserActivity alloc] initWithActivityType:@"com.example.test"];
196 userActivity.webpageURL = [NSURL URLWithString:@"http://myApp/custom/route?query=nonexist"];
197 OCMStub([
self.
viewController sendDeepLinkToFramework:[OCMArg any] completionHandler:[OCMArg any]])
198 .andDo(^(NSInvocation* invocation) {
199 void (^handler)(BOOL success);
200 [invocation getArgument:&handler atIndex:3];
203 id mockApplication = OCMClassMock([UIApplication
class]);
204 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
205 BOOL result = [
self.appDelegate
206 application:[UIApplication sharedApplication]
207 continueUserActivity:userActivity
208 restorationHandler:^(NSArray<id<UIUserActivityRestoring>>* __nullable restorableObjects){
210 XCTAssertTrue(result);
211 OCMVerify([mockApplication openURL:[OCMArg any]
213 completionHandler:[OCMArg any]]);
216 - (void)testSetGetPluginRegistrant {
218 self.appDelegate.pluginRegistrant = mockRegistrant;
222 - (void)testSetGetPluginRegistrantSelf {
226 self.appDelegate = nil;
FlutterAppLifeCycleProvider UIWindow * window
NSObject< FlutterPluginRegistrant > * pluginRegistrant
FlutterViewController *(^ rootFlutterViewControllerGetter)(void)
id mockEngineFirstFrameCallback
FlutterAppDelegate * appDelegate
FlutterViewController * viewController