5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
19 - (BOOL)isLiveTextInputAvailable;
20 - (void)searchWeb:(NSString*)searchTerm;
21 - (void)showLookUpViewController:(NSString*)term;
22 - (void)showShareViewController:(NSString*)content;
25 @interface UIViewController ()
26 - (void)presentViewController:(UIViewController*)viewControllerToPresent
28 completion:(
void (^)(
void))completion;
32 - (void)testSearchWebInvokedWithEscapedTerm {
33 id mockApplication = OCMClassMock([UIApplication
class]);
34 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
37 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
38 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
41 XCTestExpectation* invokeExpectation =
42 [
self expectationWithDescription:@"Web search launched with escaped search term"];
52 OCMVerify([mockPlugin searchWeb:
@"Testing Word!"]);
53 #if not APPLICATION_EXTENSION_API_ONLY
54 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Testing%20Word!"]
56 completionHandler:nil]);
58 [invokeExpectation fulfill];
62 [
self waitForExpectationsWithTimeout:1 handler:nil];
63 [mockApplication stopMocking];
66 - (void)testSearchWebInvokedWithNonEscapedTerm {
67 id mockApplication = OCMClassMock([UIApplication
class]);
68 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
71 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
72 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
75 XCTestExpectation* invokeExpectation =
76 [
self expectationWithDescription:@"Web search launched with non escaped search term"];
86 OCMVerify([mockPlugin searchWeb:
@"Test"]);
87 #if not APPLICATION_EXTENSION_API_ONLY
88 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Test"]
90 completionHandler:nil]);
92 [invokeExpectation fulfill];
96 [
self waitForExpectationsWithTimeout:1 handler:nil];
97 [mockApplication stopMocking];
100 - (void)testLookUpCallInitiated {
103 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
104 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
106 XCTestExpectation* presentExpectation =
107 [
self expectationWithDescription:@"Look Up view controller presented"];
120 OCMVerify([mockEngineViewController
121 presentViewController:[OCMArg isKindOfClass:[UIReferenceLibraryViewController
class]]
124 [presentExpectation fulfill];
127 [
self waitForExpectationsWithTimeout:2 handler:nil];
130 - (void)testShareScreenInvoked {
133 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
134 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
136 XCTestExpectation* presentExpectation =
137 [
self expectationWithDescription:@"Share view controller presented"];
142 OCMStub([mockEngineViewController
143 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
154 OCMVerify([mockEngineViewController
155 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
158 [presentExpectation fulfill];
161 [
self waitForExpectationsWithTimeout:1 handler:nil];
164 - (void)testClipboardHasCorrectStrings {
165 [UIPasteboard generalPasteboard].string = nil;
167 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
168 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
172 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setString"];
174 [setStringExpectation fulfill];
180 [
self waitForExpectationsWithTimeout:1 handler:nil];
182 XCTestExpectation* hasStringsExpectation = [
self expectationWithDescription:@"hasStrings"];
184 XCTAssertTrue([result[
@"value"] boolValue]);
185 [hasStringsExpectation fulfill];
190 [
self waitForExpectationsWithTimeout:1 handler:nil];
192 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
194 XCTAssertEqualObjects(result[
@"text"],
@"some string");
195 [getDataExpectation fulfill];
200 [
self waitForExpectationsWithTimeout:1 handler:nil];
203 - (void)testClipboardSetDataToNullDoNotCrash {
204 [UIPasteboard generalPasteboard].string = nil;
206 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
207 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
211 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setData"];
213 [setStringExpectation fulfill];
220 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
222 XCTAssertEqualObjects(result[
@"text"],
@"null");
223 [getDataExpectation fulfill];
228 [
self waitForExpectationsWithTimeout:1 handler:nil];
231 - (void)testPopSystemNavigator {
236 UINavigationController* navigationController = [[[UINavigationController alloc]
237 initWithRootViewController:flutterViewController] autorelease];
238 UITabBarController* tabBarController = [[[UITabBarController alloc] init] autorelease];
239 tabBarController.viewControllers = @[ navigationController ];
240 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
241 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
245 id navigationControllerMock = OCMPartialMock(navigationController);
246 OCMStub([navigationControllerMock popViewControllerAnimated:YES]);
248 XCTestExpectation* navigationPopCalled = [
self expectationWithDescription:@"SystemNavigator.pop"];
250 [navigationPopCalled fulfill];
255 [
self waitForExpectationsWithTimeout:1 handler:nil];
256 OCMVerify([navigationControllerMock popViewControllerAnimated:YES]);
258 [flutterViewController deregisterNotifications];
259 [flutterViewController release];
262 - (void)testWhetherDeviceHasLiveTextInputInvokeCorrectly {
264 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
265 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
266 XCTestExpectation* invokeExpectation =
267 [
self expectationWithDescription:@"isLiveTextInputAvailableInvoke"];
275 OCMVerify([mockPlugin isLiveTextInputAvailable]);
276 [invokeExpectation fulfill];
279 [
self waitForExpectationsWithTimeout:1 handler:nil];
282 - (void)testViewControllerBasedStatusBarHiddenUpdate {
283 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
284 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
292 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
293 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
294 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
299 XCTestExpectation* enableSystemUIOverlaysCalled =
300 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
302 [enableSystemUIOverlaysCalled fulfill];
306 arguments:@[ @"SystemUiOverlay.bottom" ]];
308 [
self waitForExpectationsWithTimeout:1 handler:nil];
309 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
312 XCTestExpectation* enableSystemUIOverlaysCalled2 =
313 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
315 [enableSystemUIOverlaysCalled2 fulfill];
321 [
self waitForExpectationsWithTimeout:1 handler:nil];
322 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
324 [flutterViewController deregisterNotifications];
325 [flutterViewController release];
333 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
334 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
335 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
340 XCTestExpectation* enableSystemUIModeCalled =
341 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
343 [enableSystemUIModeCalled fulfill];
349 [
self waitForExpectationsWithTimeout:1 handler:nil];
350 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
353 XCTestExpectation* enableSystemUIModeCalled2 =
354 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
356 [enableSystemUIModeCalled2 fulfill];
362 [
self waitForExpectationsWithTimeout:1 handler:nil];
363 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
365 [flutterViewController deregisterNotifications];
366 [flutterViewController release];
368 [bundleMock stopMocking];