5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
8 #import "flutter/fml/platform/darwin/weak_nsobject.h"
22 - (BOOL)isLiveTextInputAvailable;
23 - (void)searchWeb:(NSString*)searchTerm;
24 - (void)showLookUpViewController:(NSString*)term;
25 - (void)showShareViewController:(NSString*)content;
28 @interface UIViewController ()
29 - (void)presentViewController:(UIViewController*)viewControllerToPresent
31 completion:(
void (^)(
void))completion;
35 - (void)testSearchWebInvokedWithEscapedTerm {
36 id mockApplication = OCMClassMock([UIApplication
class]);
37 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
40 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
41 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
44 XCTestExpectation* invokeExpectation =
45 [
self expectationWithDescription:@"Web search launched with escaped search term"];
55 OCMVerify([mockPlugin searchWeb:
@"Testing Word!"]);
56 #if not APPLICATION_EXTENSION_API_ONLY
57 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Testing%20Word!"]
59 completionHandler:nil]);
61 [invokeExpectation fulfill];
65 [
self waitForExpectationsWithTimeout:1 handler:nil];
66 [mockApplication stopMocking];
69 - (void)testSearchWebInvokedWithNonEscapedTerm {
70 id mockApplication = OCMClassMock([UIApplication
class]);
71 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
74 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
75 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
78 XCTestExpectation* invokeExpectation =
79 [
self expectationWithDescription:@"Web search launched with non escaped search term"];
89 OCMVerify([mockPlugin searchWeb:
@"Test"]);
90 #if not APPLICATION_EXTENSION_API_ONLY
91 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Test"]
93 completionHandler:nil]);
95 [invokeExpectation fulfill];
99 [
self waitForExpectationsWithTimeout:1 handler:nil];
100 [mockApplication stopMocking];
103 - (void)testLookUpCallInitiated {
106 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
107 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
109 XCTestExpectation* presentExpectation =
110 [
self expectationWithDescription:@"Look Up view controller presented"];
124 OCMVerify([mockEngineViewController
125 presentViewController:[OCMArg isKindOfClass:[UIReferenceLibraryViewController
class]]
128 [presentExpectation fulfill];
131 [
self waitForExpectationsWithTimeout:2 handler:nil];
134 - (void)testShareScreenInvoked {
137 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
138 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
140 XCTestExpectation* presentExpectation =
141 [
self expectationWithDescription:@"Share view controller presented"];
147 OCMStub([mockEngineViewController
148 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
159 OCMVerify([mockEngineViewController
160 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
163 [presentExpectation fulfill];
166 [
self waitForExpectationsWithTimeout:1 handler:nil];
169 - (void)testShareScreenInvokedOnIPad {
172 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
173 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
175 XCTestExpectation* presentExpectation =
176 [
self expectationWithDescription:@"Share view controller presented on iPad"];
182 OCMStub([mockEngineViewController
183 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
187 id mockTraitCollection = OCMClassMock([UITraitCollection
class]);
188 OCMStub([mockTraitCollection userInterfaceIdiom]).andReturn(UIUserInterfaceIdiomPad);
197 OCMVerify([mockEngineViewController
198 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
201 [presentExpectation fulfill];
204 [
self waitForExpectationsWithTimeout:1 handler:nil];
207 - (void)testClipboardHasCorrectStrings {
208 [UIPasteboard generalPasteboard].string = nil;
210 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
211 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
215 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setString"];
217 [setStringExpectation fulfill];
223 [
self waitForExpectationsWithTimeout:1 handler:nil];
225 XCTestExpectation* hasStringsExpectation = [
self expectationWithDescription:@"hasStrings"];
227 XCTAssertTrue([result[
@"value"] boolValue]);
228 [hasStringsExpectation fulfill];
233 [
self waitForExpectationsWithTimeout:1 handler:nil];
235 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
237 XCTAssertEqualObjects(result[
@"text"],
@"some string");
238 [getDataExpectation fulfill];
243 [
self waitForExpectationsWithTimeout:1 handler:nil];
246 - (void)testClipboardSetDataToNullDoNotCrash {
247 [UIPasteboard generalPasteboard].string = nil;
249 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
250 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
254 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setData"];
256 [setStringExpectation fulfill];
263 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
265 XCTAssertEqualObjects(result[
@"text"],
@"null");
266 [getDataExpectation fulfill];
271 [
self waitForExpectationsWithTimeout:1 handler:nil];
274 - (void)testPopSystemNavigator {
279 UINavigationController* navigationController =
280 [[UINavigationController alloc] initWithRootViewController:flutterViewController];
281 UITabBarController* tabBarController = [[UITabBarController alloc] init];
282 tabBarController.viewControllers = @[ navigationController ];
283 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
284 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
288 id navigationControllerMock = OCMPartialMock(navigationController);
289 OCMStub([navigationControllerMock popViewControllerAnimated:YES]);
291 XCTestExpectation* navigationPopCalled = [
self expectationWithDescription:@"SystemNavigator.pop"];
293 [navigationPopCalled fulfill];
298 [
self waitForExpectationsWithTimeout:1 handler:nil];
299 OCMVerify([navigationControllerMock popViewControllerAnimated:YES]);
301 [flutterViewController deregisterNotifications];
304 - (void)testWhetherDeviceHasLiveTextInputInvokeCorrectly {
306 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
307 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
308 XCTestExpectation* invokeExpectation =
309 [
self expectationWithDescription:@"isLiveTextInputAvailableInvoke"];
317 OCMVerify([mockPlugin isLiveTextInputAvailable]);
318 [invokeExpectation fulfill];
321 [
self waitForExpectationsWithTimeout:1 handler:nil];
324 - (void)testViewControllerBasedStatusBarHiddenUpdate {
325 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
326 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
334 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
335 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
336 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
341 XCTestExpectation* enableSystemUIOverlaysCalled =
342 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
344 [enableSystemUIOverlaysCalled fulfill];
348 arguments:@[ @"SystemUiOverlay.bottom" ]];
350 [
self waitForExpectationsWithTimeout:1 handler:nil];
351 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
354 XCTestExpectation* enableSystemUIOverlaysCalled2 =
355 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
357 [enableSystemUIOverlaysCalled2 fulfill];
363 [
self waitForExpectationsWithTimeout:1 handler:nil];
364 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
366 [flutterViewController deregisterNotifications];
374 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
375 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
376 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
381 XCTestExpectation* enableSystemUIModeCalled =
382 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
384 [enableSystemUIModeCalled fulfill];
390 [
self waitForExpectationsWithTimeout:1 handler:nil];
391 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
394 XCTestExpectation* enableSystemUIModeCalled2 =
395 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
397 [enableSystemUIModeCalled2 fulfill];
403 [
self waitForExpectationsWithTimeout:1 handler:nil];
404 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
406 [flutterViewController deregisterNotifications];
408 [bundleMock stopMocking];
411 - (void)testStatusBarHiddenUpdate {
412 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
413 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
415 id mockApplication = OCMClassMock([UIApplication
class]);
416 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
423 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
424 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
429 XCTestExpectation* enableSystemUIOverlaysCalled =
430 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
432 [enableSystemUIOverlaysCalled fulfill];
436 arguments:@[ @"SystemUiOverlay.bottom" ]];
437 [plugin handleMethodCall:methodCallSet result:resultSet];
438 [
self waitForExpectationsWithTimeout:1 handler:nil];
439 #if not APPLICATION_EXTENSION_API_ONLY
440 OCMVerify([mockApplication setStatusBarHidden:YES]);
444 XCTestExpectation* enableSystemUIOverlaysCalled2 =
445 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
447 [enableSystemUIOverlaysCalled2 fulfill];
452 [plugin handleMethodCall:methodCallSet2 result:resultSet2];
453 [
self waitForExpectationsWithTimeout:1 handler:nil];
454 #if not APPLICATION_EXTENSION_API_ONLY
455 OCMVerify([mockApplication setStatusBarHidden:NO]);
458 [flutterViewController deregisterNotifications];
459 [mockApplication stopMocking];
460 [bundleMock stopMocking];
463 - (void)testStatusBarStyle {
464 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
465 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
467 id mockApplication = OCMClassMock([UIApplication
class]);
468 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
474 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
475 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
476 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
480 XCTestExpectation* enableSystemUIModeCalled =
481 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
483 [enableSystemUIModeCalled fulfill];
487 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
489 [
self waitForExpectationsWithTimeout:1 handler:nil];
491 #if not APPLICATION_EXTENSION_API_ONLY
492 OCMVerify([mockApplication setStatusBarStyle:UIStatusBarStyleLightContent]);
495 [flutterViewController deregisterNotifications];
496 [mockApplication stopMocking];
497 [bundleMock stopMocking];