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;
25- (void)playSystemSound:(NSString*)soundType;
26- (void)vibrateHapticFeedback:(NSString*)feedbackType;
29@interface UIViewController ()
30- (void)presentViewController:(UIViewController*)viewControllerToPresent
32 completion:(
void (^)(
void))completion;
37- (void)testSearchWebInvokedWithEscapedTerm {
38 id mockApplication = OCMClassMock([UIApplication
class]);
39 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
44 XCTestExpectation* invokeExpectation =
45 [
self expectationWithDescription:@"Web search launched with escaped search term"];
54 OCMVerify([mockPlugin searchWeb:
@"Testing Word!"]);
55 OCMVerify([mockApplication openURL:[NSURL URLWithString:@"x-web-search://?Testing%20Word!"]
57 completionHandler:nil]);
58 [invokeExpectation fulfill];
62 [
self waitForExpectationsWithTimeout:1 handler:nil];
63 [mockApplication stopMocking];
66- (void)testSearchWebSkippedIfAppExtension {
67 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
68 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
69 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
71 id mockApplication = OCMClassMock([UIApplication
class]);
72 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
73 OCMReject([mockApplication openURL:OCMOCK_ANY options:OCMOCK_ANY completionHandler:OCMOCK_ANY]);
77 XCTestExpectation* invokeExpectation =
78 [
self expectationWithDescription:@"Web search launched with non escaped search term"];
87 OCMVerify([mockPlugin searchWeb:
@"Test"]);
89 [invokeExpectation fulfill];
93 [
self waitForExpectationsWithTimeout:1 handler:nil];
94 [mockBundle stopMocking];
95 [mockApplication stopMocking];
98- (void)testLookUpCallInitiated {
102 XCTestExpectation* presentExpectation =
103 [
self expectationWithDescription:@"Look Up view controller presented"];
116 OCMVerify([mockEngineViewController
117 presentViewController:[OCMArg isKindOfClass:[UIReferenceLibraryViewController class]]
120 [presentExpectation fulfill];
123 [
self waitForExpectationsWithTimeout:2 handler:nil];
126- (void)testShareScreenInvoked {
130 XCTestExpectation* presentExpectation =
131 [
self expectationWithDescription:@"Share view controller presented"];
137 OCMStub([mockEngineViewController
138 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController class]]
148 OCMVerify([mockEngineViewController
149 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController class]]
152 [presentExpectation fulfill];
155 [
self waitForExpectationsWithTimeout:1 handler:nil];
158- (void)testShareScreenInvokedOnIPad {
162 XCTestExpectation* presentExpectation =
163 [
self expectationWithDescription:@"Share view controller presented on iPad"];
169 OCMStub([mockEngineViewController
170 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController class]]
174 id mockTraitCollection = OCMClassMock([UITraitCollection
class]);
175 OCMStub([mockTraitCollection userInterfaceIdiom]).andReturn(UIUserInterfaceIdiomPad);
183 OCMVerify([mockEngineViewController
184 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController class]]
187 [presentExpectation fulfill];
190 [
self waitForExpectationsWithTimeout:1 handler:nil];
193- (void)testClipboardHasCorrectStrings {
194 [UIPasteboard generalPasteboard].string = nil;
198 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setString"];
200 [setStringExpectation fulfill];
206 [
self waitForExpectationsWithTimeout:1 handler:nil];
208 XCTestExpectation* hasStringsExpectation = [
self expectationWithDescription:@"hasStrings"];
210 XCTAssertTrue([result[
@"value"] boolValue]);
211 [hasStringsExpectation fulfill];
216 [
self waitForExpectationsWithTimeout:1 handler:nil];
218 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
220 XCTAssertEqualObjects(result[
@"text"],
@"some string");
221 [getDataExpectation fulfill];
226 [
self waitForExpectationsWithTimeout:1 handler:nil];
229- (void)testClipboardSetDataToNullDoNotCrash {
230 [UIPasteboard generalPasteboard].string = nil;
234 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setData"];
236 [setStringExpectation fulfill];
243 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
245 XCTAssertEqualObjects(result[
@"text"],
@"null");
246 [getDataExpectation fulfill];
251 [
self waitForExpectationsWithTimeout:1 handler:nil];
254- (void)testPopSystemNavigator {
259 UINavigationController* navigationController =
260 [[UINavigationController alloc] initWithRootViewController:flutterViewController];
261 UITabBarController* tabBarController = [[UITabBarController alloc] init];
262 tabBarController.viewControllers = @[ navigationController ];
265 id navigationControllerMock = OCMPartialMock(navigationController);
266 OCMStub([navigationControllerMock popViewControllerAnimated:YES]);
268 XCTestExpectation* navigationPopCalled = [
self expectationWithDescription:@"SystemNavigator.pop"];
270 [navigationPopCalled fulfill];
275 [
self waitForExpectationsWithTimeout:1 handler:nil];
276 OCMVerify([navigationControllerMock popViewControllerAnimated:YES]);
278 [flutterViewController deregisterNotifications];
281- (void)testWhetherDeviceHasLiveTextInputInvokeCorrectly {
283 XCTestExpectation* invokeExpectation =
284 [
self expectationWithDescription:@"isLiveTextInputAvailableInvoke"];
291 OCMVerify([mockPlugin isLiveTextInputAvailable]);
292 [invokeExpectation fulfill];
295 [
self waitForExpectationsWithTimeout:1 handler:nil];
298- (void)testSystemSoundPlay {
300 XCTestExpectation* invokeExpectation =
301 [
self expectationWithDescription:@"SystemSound.play invoked"];
309 OCMVerify([mockPlugin playSystemSound:
@"SystemSoundType.click"]);
310 [invokeExpectation fulfill];
313 [
self waitForExpectationsWithTimeout:1 handler:nil];
316- (void)testHapticFeedbackVibrate {
318 XCTestExpectation* invokeExpectation =
319 [
self expectationWithDescription:@"HapticFeedback.vibrate invoked"];
325 arguments:@"HapticFeedbackType.lightImpact"];
327 OCMVerify([mockPlugin vibrateHapticFeedback:
@"HapticFeedbackType.lightImpact"]);
328 [invokeExpectation fulfill];
331 [
self waitForExpectationsWithTimeout:1 handler:nil];
334- (void)testViewControllerBasedStatusBarHiddenUpdate {
335 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
336 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
344 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
349 XCTestExpectation* enableSystemUIOverlaysCalled =
350 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
352 [enableSystemUIOverlaysCalled fulfill];
356 arguments:@[ @"SystemUiOverlay.bottom" ]];
358 [
self waitForExpectationsWithTimeout:1 handler:nil];
359 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
362 XCTestExpectation* enableSystemUIOverlaysCalled2 =
363 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
365 [enableSystemUIOverlaysCalled2 fulfill];
371 [
self waitForExpectationsWithTimeout:1 handler:nil];
372 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
374 [flutterViewController deregisterNotifications];
382 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
387 XCTestExpectation* enableSystemUIModeCalled =
388 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
390 [enableSystemUIModeCalled fulfill];
396 [
self waitForExpectationsWithTimeout:1 handler:nil];
397 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
400 XCTestExpectation* enableSystemUIModeCalled2 =
401 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
403 [enableSystemUIModeCalled2 fulfill];
409 [
self waitForExpectationsWithTimeout:1 handler:nil];
410 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
412 [flutterViewController deregisterNotifications];
414 [bundleMock stopMocking];
417- (void)testStatusBarHiddenUpdate {
418 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
419 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
421 id mockApplication = OCMClassMock([UIApplication
class]);
422 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
433 XCTestExpectation* systemOverlaysBottomExpectation =
434 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
436 [systemOverlaysBottomExpectation fulfill];
440 arguments:@[ @"SystemUiOverlay.bottom" ]];
442 [
self waitForExpectationsWithTimeout:1 handler:nil];
443 OCMVerify([mockApplication setStatusBarHidden:YES]);
446 XCTestExpectation* systemOverlaysTopExpectation =
447 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
449 [systemOverlaysTopExpectation fulfill];
455 [
self waitForExpectationsWithTimeout:1 handler:nil];
456 OCMVerify([mockApplication setStatusBarHidden:NO]);
458 [flutterViewController deregisterNotifications];
459 [mockApplication stopMocking];
460 [bundleMock stopMocking];
463- (void)testStatusBarHiddenNotUpdatedInAppExtension {
464 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
465 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
467 OCMStub([bundleMock objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
468 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
470 id mockApplication = OCMClassMock([UIApplication
class]);
471 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
472 OCMReject([mockApplication setStatusBarHidden:OCMOCK_ANY]);
483 XCTestExpectation* systemOverlaysBottomExpectation =
484 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
486 [systemOverlaysBottomExpectation fulfill];
490 arguments:@[ @"SystemUiOverlay.bottom" ]];
492 [
self waitForExpectationsWithTimeout:1 handler:nil];
493 OCMReject([mockApplication setStatusBarHidden:YES]);
496 XCTestExpectation* systemOverlaysTopExpectation =
497 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
499 [systemOverlaysTopExpectation fulfill];
505 [
self waitForExpectationsWithTimeout:1 handler:nil];
506 OCMReject([mockApplication setStatusBarHidden:NO]);
508 [flutterViewController deregisterNotifications];
509 [mockApplication stopMocking];
510 [bundleMock stopMocking];
513- (void)testStatusBarStyle {
514 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
515 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
517 id mockApplication = OCMClassMock([UIApplication
class]);
518 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
524 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
528 XCTestExpectation* enableSystemUIModeCalled =
529 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
531 [enableSystemUIModeCalled fulfill];
535 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
537 [
self waitForExpectationsWithTimeout:1 handler:nil];
539 OCMVerify([mockApplication setStatusBarStyle:UIStatusBarStyleLightContent]);
541 [flutterViewController deregisterNotifications];
542 [mockApplication stopMocking];
543 [bundleMock stopMocking];
546- (void)testStatusBarStyleNotUpdatedInAppExtension {
547 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
548 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
550 OCMStub([bundleMock objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
551 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
553 id mockApplication = OCMClassMock([UIApplication
class]);
554 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
555 OCMReject([mockApplication setStatusBarHidden:OCMOCK_ANY]);
561 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
565 XCTestExpectation* enableSystemUIModeCalled =
566 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
568 [enableSystemUIModeCalled fulfill];
572 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
574 [
self waitForExpectationsWithTimeout:1 handler:nil];
576 [flutterViewController deregisterNotifications];
577 [mockApplication stopMocking];
578 [bundleMock stopMocking];
void(^ FlutterResult)(id _Nullable result)
BOOL runWithEntrypoint:(nullable NSString *entrypoint)
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
union flutter::testing::@2827::KeyboardChange::@78 content