5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
8 #import "flutter/shell/platform/darwin/common/InternalFlutterSwiftCommon/InternalFlutterSwiftCommon.h"
22 - (BOOL)isLiveTextInputAvailable;
23 - (void)searchWeb:(NSString*)searchTerm;
24 - (void)showLookUpViewController:(NSString*)term;
25 - (void)showShareViewController:(NSString*)content;
26 - (void)playSystemSound:(NSString*)soundType;
27 - (void)vibrateHapticFeedback:(NSString*)feedbackType;
28 - (void)showTranslateViewControllerForTerm:(NSString*)term;
31 @interface UIViewController ()
32 - (void)presentViewController:(UIViewController*)viewControllerToPresent
34 completion:(
void (^)(
void))completion;
39 - (void)testTranslateInvoked {
40 if (@available(iOS 17.4, *)) {
52 __block BOOL resultCalled = NO;
57 XCTAssertTrue(resultCalled);
58 OCMVerify([mockEngineViewController
59 addChildViewController:[OCMArg isKindOfClass:[FlutterTranslateViewController
class]]]);
63 - (void)testTranslateNotInvokedWhenUnavailable {
64 if (!@available(iOS 17.4, *)) {
72 __block BOOL resultCalled = NO;
75 XCTAssertEqualObjects(result, FlutterMethodNotImplemented);
78 XCTAssertTrue(resultCalled);
82 - (void)testTranslateInvokedWithEmptyTermDoesNotAddChildViewController {
83 if (@available(iOS 17.4, *)) {
93 OCMReject([mockEngineViewController
94 addChildViewController:[OCMArg isKindOfClass:[FlutterTranslateViewController
class]]]);
98 __block BOOL resultCalled = NO;
103 XCTAssertTrue(resultCalled);
107 - (void)testSearchWebInvokedWithEscapedTerm {
108 id mockApplication = OCMClassMock([UIApplication
class]);
109 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
114 XCTestExpectation* invokeExpectation =
115 [
self expectationWithDescription:@"Web search launched with escaped search term"];
124 OCMVerify([mockPlugin searchWeb:
@"Testing Word!"]);
125 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Testing%20Word!"]
127 completionHandler:nil]);
128 [invokeExpectation fulfill];
132 [
self waitForExpectationsWithTimeout:1 handler:nil];
133 [mockApplication stopMocking];
136 - (void)testSearchWebSkippedIfAppExtension {
137 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
138 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
139 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
141 id mockApplication = OCMClassMock([UIApplication
class]);
142 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
143 OCMReject([mockApplication openURL:OCMOCK_ANY options:OCMOCK_ANY completionHandler:OCMOCK_ANY]);
147 XCTestExpectation* invokeExpectation =
148 [
self expectationWithDescription:@"Web search launched with non escaped search term"];
157 OCMVerify([mockPlugin searchWeb:
@"Test"]);
159 [invokeExpectation fulfill];
163 [
self waitForExpectationsWithTimeout:1 handler:nil];
164 [mockBundle stopMocking];
165 [mockApplication stopMocking];
168 - (void)testLookUpCallInitiated {
172 XCTestExpectation* presentExpectation =
173 [
self expectationWithDescription:@"Look Up view controller presented"];
186 OCMVerify([mockEngineViewController
187 presentViewController:[OCMArg isKindOfClass:[UIReferenceLibraryViewController
class]]
190 [presentExpectation fulfill];
193 [
self waitForExpectationsWithTimeout:2 handler:nil];
196 - (void)testShareScreenInvoked {
200 XCTestExpectation* presentExpectation =
201 [
self expectationWithDescription:@"Share view controller presented"];
207 OCMStub([mockEngineViewController
208 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
218 OCMVerify([mockEngineViewController
219 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
222 [presentExpectation fulfill];
225 [
self waitForExpectationsWithTimeout:1 handler:nil];
228 - (void)testShareScreenInvokedOnIPad {
232 XCTestExpectation* presentExpectation =
233 [
self expectationWithDescription:@"Share view controller presented on iPad"];
239 OCMStub([mockEngineViewController
240 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
244 id mockTraitCollection = OCMClassMock([UITraitCollection
class]);
245 OCMStub([mockTraitCollection userInterfaceIdiom]).andReturn(UIUserInterfaceIdiomPad);
253 OCMVerify([mockEngineViewController
254 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
257 [presentExpectation fulfill];
260 [
self waitForExpectationsWithTimeout:1 handler:nil];
263 - (void)testClipboardHasCorrectStrings {
264 [UIPasteboard generalPasteboard].string = nil;
268 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setString"];
270 [setStringExpectation fulfill];
276 [
self waitForExpectationsWithTimeout:1 handler:nil];
278 XCTestExpectation* hasStringsExpectation = [
self expectationWithDescription:@"hasStrings"];
280 XCTAssertTrue([result[
@"value"] boolValue]);
281 [hasStringsExpectation fulfill];
286 [
self waitForExpectationsWithTimeout:1 handler:nil];
288 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
290 XCTAssertEqualObjects(result[
@"text"],
@"some string");
291 [getDataExpectation fulfill];
296 [
self waitForExpectationsWithTimeout:1 handler:nil];
299 - (void)testClipboardSetDataToNullDoNotCrash {
300 [UIPasteboard generalPasteboard].string = nil;
304 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setData"];
306 [setStringExpectation fulfill];
313 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
315 XCTAssertEqualObjects(result[
@"text"],
@"null");
316 [getDataExpectation fulfill];
321 [
self waitForExpectationsWithTimeout:1 handler:nil];
324 - (void)testPopSystemNavigator {
329 UINavigationController* navigationController =
330 [[UINavigationController alloc] initWithRootViewController:flutterViewController];
331 UITabBarController* tabBarController = [[UITabBarController alloc] init];
332 tabBarController.viewControllers = @[ navigationController ];
335 id navigationControllerMock = OCMPartialMock(navigationController);
336 OCMStub([navigationControllerMock popViewControllerAnimated:YES]);
338 XCTestExpectation* navigationPopCalled = [
self expectationWithDescription:@"SystemNavigator.pop"];
340 [navigationPopCalled fulfill];
345 [
self waitForExpectationsWithTimeout:1 handler:nil];
346 OCMVerify([navigationControllerMock popViewControllerAnimated:YES]);
348 [flutterViewController deregisterNotifications];
351 - (void)testWhetherDeviceHasLiveTextInputInvokeCorrectly {
353 XCTestExpectation* invokeExpectation =
354 [
self expectationWithDescription:@"isLiveTextInputAvailableInvoke"];
361 OCMVerify([mockPlugin isLiveTextInputAvailable]);
362 [invokeExpectation fulfill];
365 [
self waitForExpectationsWithTimeout:1 handler:nil];
368 - (void)testSystemSoundPlay {
370 XCTestExpectation* invokeExpectation =
371 [
self expectationWithDescription:@"SystemSound.play invoked"];
379 OCMVerify([mockPlugin playSystemSound:
@"SystemSoundType.click"]);
380 [invokeExpectation fulfill];
383 [
self waitForExpectationsWithTimeout:1 handler:nil];
386 - (void)testHapticFeedbackVibrate {
388 XCTestExpectation* invokeExpectation =
389 [
self expectationWithDescription:@"HapticFeedback.vibrate invoked"];
395 arguments:@"HapticFeedbackType.lightImpact"];
397 OCMVerify([mockPlugin vibrateHapticFeedback:
@"HapticFeedbackType.lightImpact"]);
398 [invokeExpectation fulfill];
401 [
self waitForExpectationsWithTimeout:1 handler:nil];
404 - (void)testViewControllerBasedStatusBarHiddenUpdate {
405 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
406 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
414 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
419 XCTestExpectation* enableSystemUIOverlaysCalled =
420 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
422 [enableSystemUIOverlaysCalled fulfill];
426 arguments:@[ @"SystemUiOverlay.bottom" ]];
428 [
self waitForExpectationsWithTimeout:1 handler:nil];
429 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
432 XCTestExpectation* enableSystemUIOverlaysCalled2 =
433 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
435 [enableSystemUIOverlaysCalled2 fulfill];
441 [
self waitForExpectationsWithTimeout:1 handler:nil];
442 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
444 [flutterViewController deregisterNotifications];
452 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
457 XCTestExpectation* enableSystemUIModeCalled =
458 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
460 [enableSystemUIModeCalled fulfill];
466 [
self waitForExpectationsWithTimeout:1 handler:nil];
467 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
470 XCTestExpectation* enableSystemUIModeCalled2 =
471 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
473 [enableSystemUIModeCalled2 fulfill];
479 [
self waitForExpectationsWithTimeout:1 handler:nil];
480 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
482 [flutterViewController deregisterNotifications];
484 [bundleMock stopMocking];
487 - (void)testStatusBarHiddenUpdate {
488 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
489 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
491 id mockApplication = OCMClassMock([UIApplication
class]);
492 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
503 XCTestExpectation* systemOverlaysBottomExpectation =
504 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
506 [systemOverlaysBottomExpectation fulfill];
510 arguments:@[ @"SystemUiOverlay.bottom" ]];
512 [
self waitForExpectationsWithTimeout:1 handler:nil];
513 OCMVerify([mockApplication setStatusBarHidden:YES]);
516 XCTestExpectation* systemOverlaysTopExpectation =
517 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
519 [systemOverlaysTopExpectation fulfill];
525 [
self waitForExpectationsWithTimeout:1 handler:nil];
526 OCMVerify([mockApplication setStatusBarHidden:NO]);
528 [flutterViewController deregisterNotifications];
529 [mockApplication stopMocking];
530 [bundleMock stopMocking];
533 - (void)testStatusBarHiddenNotUpdatedInAppExtension {
534 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
535 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
537 OCMStub([bundleMock objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
538 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
540 id mockApplication = OCMClassMock([UIApplication
class]);
541 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
542 OCMReject([mockApplication setStatusBarHidden:OCMOCK_ANY]);
553 XCTestExpectation* systemOverlaysBottomExpectation =
554 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
556 [systemOverlaysBottomExpectation fulfill];
560 arguments:@[ @"SystemUiOverlay.bottom" ]];
562 [
self waitForExpectationsWithTimeout:1 handler:nil];
563 OCMReject([mockApplication setStatusBarHidden:YES]);
566 XCTestExpectation* systemOverlaysTopExpectation =
567 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
569 [systemOverlaysTopExpectation fulfill];
575 [
self waitForExpectationsWithTimeout:1 handler:nil];
576 OCMReject([mockApplication setStatusBarHidden:NO]);
578 [flutterViewController deregisterNotifications];
579 [mockApplication stopMocking];
580 [bundleMock stopMocking];
583 - (void)testStatusBarStyle {
584 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
585 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
587 id mockApplication = OCMClassMock([UIApplication
class]);
588 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
594 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
598 XCTestExpectation* enableSystemUIModeCalled =
599 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
601 [enableSystemUIModeCalled fulfill];
605 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
607 [
self waitForExpectationsWithTimeout:1 handler:nil];
609 OCMVerify([mockApplication setStatusBarStyle:UIStatusBarStyleLightContent]);
611 [flutterViewController deregisterNotifications];
612 [mockApplication stopMocking];
613 [bundleMock stopMocking];
616 - (void)testStatusBarStyleNotUpdatedInAppExtension {
617 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
618 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
620 OCMStub([bundleMock objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
621 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
623 id mockApplication = OCMClassMock([UIApplication
class]);
624 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
625 OCMReject([mockApplication setStatusBarHidden:OCMOCK_ANY]);
631 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
635 XCTestExpectation* enableSystemUIModeCalled =
636 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
638 [enableSystemUIModeCalled fulfill];
642 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
644 [
self waitForExpectationsWithTimeout:1 handler:nil];
646 [flutterViewController deregisterNotifications];
647 [mockApplication stopMocking];
648 [bundleMock stopMocking];
void(^ FlutterResult)(id _Nullable result)
BOOL runWithEntrypoint:(nullable NSString *NS_SWIFT_UI_ACTOR)
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)