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;
28 @interface UIViewController ()
29 - (void)presentViewController:(UIViewController*)viewControllerToPresent
31 completion:(
void (^)(
void))completion;
36 - (void)testSearchWebInvokedWithEscapedTerm {
37 id mockApplication = OCMClassMock([UIApplication
class]);
38 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
43 XCTestExpectation* invokeExpectation =
44 [
self expectationWithDescription:@"Web search launched with escaped search term"];
53 OCMVerify([mockPlugin searchWeb:
@"Testing Word!"]);
54 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Testing%20Word!"]
56 completionHandler:nil]);
57 [invokeExpectation fulfill];
61 [
self waitForExpectationsWithTimeout:1 handler:nil];
62 [mockApplication stopMocking];
65 - (void)testSearchWebSkippedIfAppExtension {
66 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
67 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
68 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
70 id mockApplication = OCMClassMock([UIApplication
class]);
71 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
72 OCMReject([mockApplication openURL:OCMOCK_ANY options:OCMOCK_ANY completionHandler:OCMOCK_ANY]);
76 XCTestExpectation* invokeExpectation =
77 [
self expectationWithDescription:@"Web search launched with non escaped search term"];
86 OCMVerify([mockPlugin searchWeb:
@"Test"]);
88 [invokeExpectation fulfill];
92 [
self waitForExpectationsWithTimeout:1 handler:nil];
93 [mockBundle stopMocking];
94 [mockApplication stopMocking];
97 - (void)testLookUpCallInitiated {
101 XCTestExpectation* presentExpectation =
102 [
self expectationWithDescription:@"Look Up view controller presented"];
115 OCMVerify([mockEngineViewController
116 presentViewController:[OCMArg isKindOfClass:[UIReferenceLibraryViewController
class]]
119 [presentExpectation fulfill];
122 [
self waitForExpectationsWithTimeout:2 handler:nil];
125 - (void)testShareScreenInvoked {
129 XCTestExpectation* presentExpectation =
130 [
self expectationWithDescription:@"Share view controller presented"];
136 OCMStub([mockEngineViewController
137 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
147 OCMVerify([mockEngineViewController
148 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
151 [presentExpectation fulfill];
154 [
self waitForExpectationsWithTimeout:1 handler:nil];
157 - (void)testShareScreenInvokedOnIPad {
161 XCTestExpectation* presentExpectation =
162 [
self expectationWithDescription:@"Share view controller presented on iPad"];
168 OCMStub([mockEngineViewController
169 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
173 id mockTraitCollection = OCMClassMock([UITraitCollection
class]);
174 OCMStub([mockTraitCollection userInterfaceIdiom]).andReturn(UIUserInterfaceIdiomPad);
182 OCMVerify([mockEngineViewController
183 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
186 [presentExpectation fulfill];
189 [
self waitForExpectationsWithTimeout:1 handler:nil];
192 - (void)testClipboardHasCorrectStrings {
193 [UIPasteboard generalPasteboard].string = nil;
197 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setString"];
199 [setStringExpectation fulfill];
205 [
self waitForExpectationsWithTimeout:1 handler:nil];
207 XCTestExpectation* hasStringsExpectation = [
self expectationWithDescription:@"hasStrings"];
209 XCTAssertTrue([result[
@"value"] boolValue]);
210 [hasStringsExpectation fulfill];
215 [
self waitForExpectationsWithTimeout:1 handler:nil];
217 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
219 XCTAssertEqualObjects(result[
@"text"],
@"some string");
220 [getDataExpectation fulfill];
225 [
self waitForExpectationsWithTimeout:1 handler:nil];
228 - (void)testClipboardSetDataToNullDoNotCrash {
229 [UIPasteboard generalPasteboard].string = nil;
233 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setData"];
235 [setStringExpectation fulfill];
242 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
244 XCTAssertEqualObjects(result[
@"text"],
@"null");
245 [getDataExpectation fulfill];
250 [
self waitForExpectationsWithTimeout:1 handler:nil];
253 - (void)testPopSystemNavigator {
258 UINavigationController* navigationController =
259 [[UINavigationController alloc] initWithRootViewController:flutterViewController];
260 UITabBarController* tabBarController = [[UITabBarController alloc] init];
261 tabBarController.viewControllers = @[ navigationController ];
264 id navigationControllerMock = OCMPartialMock(navigationController);
265 OCMStub([navigationControllerMock popViewControllerAnimated:YES]);
267 XCTestExpectation* navigationPopCalled = [
self expectationWithDescription:@"SystemNavigator.pop"];
269 [navigationPopCalled fulfill];
274 [
self waitForExpectationsWithTimeout:1 handler:nil];
275 OCMVerify([navigationControllerMock popViewControllerAnimated:YES]);
277 [flutterViewController deregisterNotifications];
280 - (void)testWhetherDeviceHasLiveTextInputInvokeCorrectly {
282 XCTestExpectation* invokeExpectation =
283 [
self expectationWithDescription:@"isLiveTextInputAvailableInvoke"];
290 OCMVerify([mockPlugin isLiveTextInputAvailable]);
291 [invokeExpectation fulfill];
294 [
self waitForExpectationsWithTimeout:1 handler:nil];
297 - (void)testSystemSoundPlay {
299 XCTestExpectation* invokeExpectation =
300 [
self expectationWithDescription:@"SystemSound.play invoked"];
308 OCMVerify([mockPlugin playSystemSound:
@"SystemSoundType.click"]);
309 [invokeExpectation fulfill];
312 [
self waitForExpectationsWithTimeout:1 handler:nil];
315 - (void)testViewControllerBasedStatusBarHiddenUpdate {
316 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
317 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
325 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
330 XCTestExpectation* enableSystemUIOverlaysCalled =
331 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
333 [enableSystemUIOverlaysCalled fulfill];
337 arguments:@[ @"SystemUiOverlay.bottom" ]];
339 [
self waitForExpectationsWithTimeout:1 handler:nil];
340 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
343 XCTestExpectation* enableSystemUIOverlaysCalled2 =
344 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
346 [enableSystemUIOverlaysCalled2 fulfill];
352 [
self waitForExpectationsWithTimeout:1 handler:nil];
353 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
355 [flutterViewController deregisterNotifications];
363 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
368 XCTestExpectation* enableSystemUIModeCalled =
369 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
371 [enableSystemUIModeCalled fulfill];
377 [
self waitForExpectationsWithTimeout:1 handler:nil];
378 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
381 XCTestExpectation* enableSystemUIModeCalled2 =
382 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
384 [enableSystemUIModeCalled2 fulfill];
390 [
self waitForExpectationsWithTimeout:1 handler:nil];
391 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
393 [flutterViewController deregisterNotifications];
395 [bundleMock stopMocking];
398 - (void)testStatusBarHiddenUpdate {
399 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
400 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
402 id mockApplication = OCMClassMock([UIApplication
class]);
403 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
414 XCTestExpectation* systemOverlaysBottomExpectation =
415 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
417 [systemOverlaysBottomExpectation fulfill];
421 arguments:@[ @"SystemUiOverlay.bottom" ]];
423 [
self waitForExpectationsWithTimeout:1 handler:nil];
424 OCMVerify([mockApplication setStatusBarHidden:YES]);
427 XCTestExpectation* systemOverlaysTopExpectation =
428 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
430 [systemOverlaysTopExpectation fulfill];
436 [
self waitForExpectationsWithTimeout:1 handler:nil];
437 OCMVerify([mockApplication setStatusBarHidden:NO]);
439 [flutterViewController deregisterNotifications];
440 [mockApplication stopMocking];
441 [bundleMock stopMocking];
444 - (void)testStatusBarHiddenNotUpdatedInAppExtension {
445 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
446 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
448 OCMStub([bundleMock objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
449 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
451 id mockApplication = OCMClassMock([UIApplication
class]);
452 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
453 OCMReject([mockApplication setStatusBarHidden:OCMOCK_ANY]);
464 XCTestExpectation* systemOverlaysBottomExpectation =
465 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
467 [systemOverlaysBottomExpectation fulfill];
471 arguments:@[ @"SystemUiOverlay.bottom" ]];
473 [
self waitForExpectationsWithTimeout:1 handler:nil];
474 OCMReject([mockApplication setStatusBarHidden:YES]);
477 XCTestExpectation* systemOverlaysTopExpectation =
478 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
480 [systemOverlaysTopExpectation fulfill];
486 [
self waitForExpectationsWithTimeout:1 handler:nil];
487 OCMReject([mockApplication setStatusBarHidden:NO]);
489 [flutterViewController deregisterNotifications];
490 [mockApplication stopMocking];
491 [bundleMock stopMocking];
494 - (void)testStatusBarStyle {
495 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
496 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
498 id mockApplication = OCMClassMock([UIApplication
class]);
499 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
505 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
509 XCTestExpectation* enableSystemUIModeCalled =
510 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
512 [enableSystemUIModeCalled fulfill];
516 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
518 [
self waitForExpectationsWithTimeout:1 handler:nil];
520 OCMVerify([mockApplication setStatusBarStyle:UIStatusBarStyleLightContent]);
522 [flutterViewController deregisterNotifications];
523 [mockApplication stopMocking];
524 [bundleMock stopMocking];
527 - (void)testStatusBarStyleNotUpdatedInAppExtension {
528 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
529 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
531 OCMStub([bundleMock objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
532 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
534 id mockApplication = OCMClassMock([UIApplication
class]);
535 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
536 OCMReject([mockApplication setStatusBarHidden:OCMOCK_ANY]);
542 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
546 XCTestExpectation* enableSystemUIModeCalled =
547 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
549 [enableSystemUIModeCalled fulfill];
553 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
555 [
self waitForExpectationsWithTimeout:1 handler:nil];
557 [flutterViewController deregisterNotifications];
558 [mockApplication stopMocking];
559 [bundleMock stopMocking];
void(^ FlutterResult)(id _Nullable result)
BOOL runWithEntrypoint:(nullable NSString *entrypoint)
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)