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;
34 - (void)testSearchWebInvokedWithEscapedTerm {
35 id mockApplication = OCMClassMock([UIApplication
class]);
36 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
41 XCTestExpectation* invokeExpectation =
42 [
self expectationWithDescription:@"Web search launched with escaped search term"];
51 OCMVerify([mockPlugin searchWeb:
@"Testing Word!"]);
52 #if not APPLICATION_EXTENSION_API_ONLY
53 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Testing%20Word!"]
55 completionHandler:nil]);
57 [invokeExpectation fulfill];
61 [
self waitForExpectationsWithTimeout:1 handler:nil];
62 [mockApplication stopMocking];
65 - (void)testSearchWebInvokedWithNonEscapedTerm {
66 id mockApplication = OCMClassMock([UIApplication
class]);
67 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
72 XCTestExpectation* invokeExpectation =
73 [
self expectationWithDescription:@"Web search launched with non escaped search term"];
82 OCMVerify([mockPlugin searchWeb:
@"Test"]);
83 #if not APPLICATION_EXTENSION_API_ONLY
84 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Test"]
86 completionHandler:nil]);
88 [invokeExpectation fulfill];
92 [
self waitForExpectationsWithTimeout:1 handler:nil];
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* enableSystemUIOverlaysCalled =
396 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
398 [enableSystemUIOverlaysCalled fulfill];
402 arguments:@[ @"SystemUiOverlay.bottom" ]];
404 [
self waitForExpectationsWithTimeout:1 handler:nil];
405 #if not APPLICATION_EXTENSION_API_ONLY
406 OCMVerify([mockApplication setStatusBarHidden:YES]);
410 XCTestExpectation* enableSystemUIOverlaysCalled2 =
411 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
413 [enableSystemUIOverlaysCalled2 fulfill];
419 [
self waitForExpectationsWithTimeout:1 handler:nil];
420 #if not APPLICATION_EXTENSION_API_ONLY
421 OCMVerify([mockApplication setStatusBarHidden:NO]);
424 [flutterViewController deregisterNotifications];
425 [mockApplication stopMocking];
426 [bundleMock stopMocking];
429 - (void)testStatusBarStyle {
430 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
431 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
433 id mockApplication = OCMClassMock([UIApplication
class]);
434 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
440 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
444 XCTestExpectation* enableSystemUIModeCalled =
445 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
447 [enableSystemUIModeCalled fulfill];
451 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
453 [
self waitForExpectationsWithTimeout:1 handler:nil];
455 #if not APPLICATION_EXTENSION_API_ONLY
456 OCMVerify([mockApplication setStatusBarStyle:UIStatusBarStyleLightContent]);
459 [flutterViewController deregisterNotifications];
460 [mockApplication stopMocking];
461 [bundleMock stopMocking];