5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
21 - (BOOL)isLiveTextInputAvailable;
22 - (void)searchWeb:(NSString*)searchTerm;
23 - (void)showLookUpViewController:(NSString*)term;
24 - (void)showShareViewController:(NSString*)content;
27 @interface UIViewController ()
28 - (void)presentViewController:(UIViewController*)viewControllerToPresent
30 completion:(
void (^)(
void))completion;
35 - (void)testSearchWebInvokedWithEscapedTerm {
36 id mockApplication = OCMClassMock([UIApplication
class]);
37 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
42 XCTestExpectation* invokeExpectation =
43 [
self expectationWithDescription:@"Web search launched with escaped search term"];
52 OCMVerify([mockPlugin searchWeb:
@"Testing Word!"]);
53 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Testing%20Word!"]
55 completionHandler:nil]);
56 [invokeExpectation fulfill];
60 [
self waitForExpectationsWithTimeout:1 handler:nil];
61 [mockApplication stopMocking];
64 - (void)testSearchWebSkippedIfAppExtension {
65 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
66 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
67 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
69 id mockApplication = OCMClassMock([UIApplication
class]);
70 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
71 OCMReject([mockApplication openURL:OCMOCK_ANY options:OCMOCK_ANY completionHandler:OCMOCK_ANY]);
75 XCTestExpectation* invokeExpectation =
76 [
self expectationWithDescription:@"Web search launched with non escaped search term"];
85 OCMVerify([mockPlugin searchWeb:
@"Test"]);
87 [invokeExpectation fulfill];
91 [
self waitForExpectationsWithTimeout:1 handler:nil];
92 [mockBundle stopMocking];
93 [mockApplication stopMocking];
96 - (void)testLookUpCallInitiated {
100 XCTestExpectation* presentExpectation =
101 [
self expectationWithDescription:@"Look Up view controller presented"];
114 OCMVerify([mockEngineViewController
115 presentViewController:[OCMArg isKindOfClass:[UIReferenceLibraryViewController
class]]
118 [presentExpectation fulfill];
121 [
self waitForExpectationsWithTimeout:2 handler:nil];
124 - (void)testShareScreenInvoked {
128 XCTestExpectation* presentExpectation =
129 [
self expectationWithDescription:@"Share view controller presented"];
135 OCMStub([mockEngineViewController
136 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
146 OCMVerify([mockEngineViewController
147 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
150 [presentExpectation fulfill];
153 [
self waitForExpectationsWithTimeout:1 handler:nil];
156 - (void)testShareScreenInvokedOnIPad {
160 XCTestExpectation* presentExpectation =
161 [
self expectationWithDescription:@"Share view controller presented on iPad"];
167 OCMStub([mockEngineViewController
168 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
172 id mockTraitCollection = OCMClassMock([UITraitCollection
class]);
173 OCMStub([mockTraitCollection userInterfaceIdiom]).andReturn(UIUserInterfaceIdiomPad);
181 OCMVerify([mockEngineViewController
182 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
185 [presentExpectation fulfill];
188 [
self waitForExpectationsWithTimeout:1 handler:nil];
191 - (void)testClipboardHasCorrectStrings {
192 [UIPasteboard generalPasteboard].string = nil;
196 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setString"];
198 [setStringExpectation fulfill];
204 [
self waitForExpectationsWithTimeout:1 handler:nil];
206 XCTestExpectation* hasStringsExpectation = [
self expectationWithDescription:@"hasStrings"];
208 XCTAssertTrue([result[
@"value"] boolValue]);
209 [hasStringsExpectation fulfill];
214 [
self waitForExpectationsWithTimeout:1 handler:nil];
216 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
218 XCTAssertEqualObjects(result[
@"text"],
@"some string");
219 [getDataExpectation fulfill];
224 [
self waitForExpectationsWithTimeout:1 handler:nil];
227 - (void)testClipboardSetDataToNullDoNotCrash {
228 [UIPasteboard generalPasteboard].string = nil;
232 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setData"];
234 [setStringExpectation fulfill];
241 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
243 XCTAssertEqualObjects(result[
@"text"],
@"null");
244 [getDataExpectation fulfill];
249 [
self waitForExpectationsWithTimeout:1 handler:nil];
252 - (void)testPopSystemNavigator {
257 UINavigationController* navigationController =
258 [[UINavigationController alloc] initWithRootViewController:flutterViewController];
259 UITabBarController* tabBarController = [[UITabBarController alloc] init];
260 tabBarController.viewControllers = @[ navigationController ];
263 id navigationControllerMock = OCMPartialMock(navigationController);
264 OCMStub([navigationControllerMock popViewControllerAnimated:YES]);
266 XCTestExpectation* navigationPopCalled = [
self expectationWithDescription:@"SystemNavigator.pop"];
268 [navigationPopCalled fulfill];
273 [
self waitForExpectationsWithTimeout:1 handler:nil];
274 OCMVerify([navigationControllerMock popViewControllerAnimated:YES]);
276 [flutterViewController deregisterNotifications];
279 - (void)testWhetherDeviceHasLiveTextInputInvokeCorrectly {
281 XCTestExpectation* invokeExpectation =
282 [
self expectationWithDescription:@"isLiveTextInputAvailableInvoke"];
289 OCMVerify([mockPlugin isLiveTextInputAvailable]);
290 [invokeExpectation fulfill];
293 [
self waitForExpectationsWithTimeout:1 handler:nil];
296 - (void)testViewControllerBasedStatusBarHiddenUpdate {
297 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
298 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
306 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
311 XCTestExpectation* enableSystemUIOverlaysCalled =
312 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
314 [enableSystemUIOverlaysCalled fulfill];
318 arguments:@[ @"SystemUiOverlay.bottom" ]];
320 [
self waitForExpectationsWithTimeout:1 handler:nil];
321 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
324 XCTestExpectation* enableSystemUIOverlaysCalled2 =
325 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
327 [enableSystemUIOverlaysCalled2 fulfill];
333 [
self waitForExpectationsWithTimeout:1 handler:nil];
334 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
336 [flutterViewController deregisterNotifications];
344 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
349 XCTestExpectation* enableSystemUIModeCalled =
350 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
352 [enableSystemUIModeCalled fulfill];
358 [
self waitForExpectationsWithTimeout:1 handler:nil];
359 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
362 XCTestExpectation* enableSystemUIModeCalled2 =
363 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
365 [enableSystemUIModeCalled2 fulfill];
371 [
self waitForExpectationsWithTimeout:1 handler:nil];
372 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
374 [flutterViewController deregisterNotifications];
376 [bundleMock stopMocking];
379 - (void)testStatusBarHiddenUpdate {
380 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
381 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
383 id mockApplication = OCMClassMock([UIApplication
class]);
384 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
395 XCTestExpectation* systemOverlaysBottomExpectation =
396 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
398 [systemOverlaysBottomExpectation fulfill];
402 arguments:@[ @"SystemUiOverlay.bottom" ]];
404 [
self waitForExpectationsWithTimeout:1 handler:nil];
405 OCMVerify([mockApplication setStatusBarHidden:YES]);
408 XCTestExpectation* systemOverlaysTopExpectation =
409 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
411 [systemOverlaysTopExpectation fulfill];
417 [
self waitForExpectationsWithTimeout:1 handler:nil];
418 OCMVerify([mockApplication setStatusBarHidden:NO]);
420 [flutterViewController deregisterNotifications];
421 [mockApplication stopMocking];
422 [bundleMock stopMocking];
425 - (void)testStatusBarHiddenNotUpdatedInAppExtension {
426 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
427 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
429 OCMStub([bundleMock objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
430 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
432 id mockApplication = OCMClassMock([UIApplication
class]);
433 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
434 OCMReject([mockApplication setStatusBarHidden:OCMOCK_ANY]);
445 XCTestExpectation* systemOverlaysBottomExpectation =
446 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
448 [systemOverlaysBottomExpectation fulfill];
452 arguments:@[ @"SystemUiOverlay.bottom" ]];
454 [
self waitForExpectationsWithTimeout:1 handler:nil];
455 OCMReject([mockApplication setStatusBarHidden:YES]);
458 XCTestExpectation* systemOverlaysTopExpectation =
459 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
461 [systemOverlaysTopExpectation fulfill];
467 [
self waitForExpectationsWithTimeout:1 handler:nil];
468 OCMReject([mockApplication setStatusBarHidden:NO]);
470 [flutterViewController deregisterNotifications];
471 [mockApplication stopMocking];
472 [bundleMock stopMocking];
475 - (void)testStatusBarStyle {
476 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
477 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
479 id mockApplication = OCMClassMock([UIApplication
class]);
480 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
486 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
490 XCTestExpectation* enableSystemUIModeCalled =
491 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
493 [enableSystemUIModeCalled fulfill];
497 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
499 [
self waitForExpectationsWithTimeout:1 handler:nil];
501 OCMVerify([mockApplication setStatusBarStyle:UIStatusBarStyleLightContent]);
503 [flutterViewController deregisterNotifications];
504 [mockApplication stopMocking];
505 [bundleMock stopMocking];
508 - (void)testStatusBarStyleNotUpdatedInAppExtension {
509 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
510 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
512 OCMStub([bundleMock objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
513 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
515 id mockApplication = OCMClassMock([UIApplication
class]);
516 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
517 OCMReject([mockApplication setStatusBarHidden:OCMOCK_ANY]);
523 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
527 XCTestExpectation* enableSystemUIModeCalled =
528 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
530 [enableSystemUIModeCalled fulfill];
534 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
536 [
self waitForExpectationsWithTimeout:1 handler:nil];
538 [flutterViewController deregisterNotifications];
539 [mockApplication stopMocking];
540 [bundleMock stopMocking];
void(^ FlutterResult)(id _Nullable result)
BOOL runWithEntrypoint:(nullable NSString *entrypoint)
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)