5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
19 - (BOOL)isLiveTextInputAvailable;
20 - (void)searchWeb:(NSString*)searchTerm;
21 - (void)showLookUpViewController:(NSString*)term;
22 - (void)showShareViewController:(NSString*)content;
25 @interface UIViewController ()
26 - (void)presentViewController:(UIViewController*)viewControllerToPresent
28 completion:(
void (^)(
void))completion;
32 - (void)testSearchWebInvokedWithEscapedTerm {
33 id mockApplication = OCMClassMock([UIApplication
class]);
34 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
37 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
38 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
41 XCTestExpectation* invokeExpectation =
42 [
self expectationWithDescription:@"Web search launched with escaped search term"];
52 OCMVerify([mockPlugin searchWeb:
@"Testing Word!"]);
53 #if not APPLICATION_EXTENSION_API_ONLY
54 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Testing%20Word!"]
56 completionHandler:nil]);
58 [invokeExpectation fulfill];
62 [
self waitForExpectationsWithTimeout:1 handler:nil];
63 [mockApplication stopMocking];
66 - (void)testSearchWebInvokedWithNonEscapedTerm {
67 id mockApplication = OCMClassMock([UIApplication
class]);
68 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
71 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
72 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
75 XCTestExpectation* invokeExpectation =
76 [
self expectationWithDescription:@"Web search launched with non escaped search term"];
86 OCMVerify([mockPlugin searchWeb:
@"Test"]);
87 #if not APPLICATION_EXTENSION_API_ONLY
88 OCMVerify([mockApplication openURL:[NSURL URLWithString:
@"x-web-search://?Test"]
90 completionHandler:nil]);
92 [invokeExpectation fulfill];
96 [
self waitForExpectationsWithTimeout:1 handler:nil];
97 [mockApplication stopMocking];
100 - (void)testLookUpCallInitiated {
103 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
104 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
106 XCTestExpectation* presentExpectation =
107 [
self expectationWithDescription:@"Look Up view controller presented"];
120 OCMVerify([mockEngineViewController
121 presentViewController:[OCMArg isKindOfClass:[UIReferenceLibraryViewController
class]]
124 [presentExpectation fulfill];
127 [
self waitForExpectationsWithTimeout:2 handler:nil];
130 - (void)testShareScreenInvoked {
133 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
134 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
136 XCTestExpectation* presentExpectation =
137 [
self expectationWithDescription:@"Share view controller presented"];
142 OCMStub([mockEngineViewController
143 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
154 OCMVerify([mockEngineViewController
155 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
158 [presentExpectation fulfill];
161 [
self waitForExpectationsWithTimeout:1 handler:nil];
164 - (void)testShareScreenInvokedOnIPad {
167 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
168 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
170 XCTestExpectation* presentExpectation =
171 [
self expectationWithDescription:@"Share view controller presented on iPad"];
176 OCMStub([mockEngineViewController
177 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
181 id mockTraitCollection = OCMClassMock([UITraitCollection
class]);
182 OCMStub([mockTraitCollection userInterfaceIdiom]).andReturn(UIUserInterfaceIdiomPad);
191 OCMVerify([mockEngineViewController
192 presentViewController:[OCMArg isKindOfClass:[UIActivityViewController
class]]
195 [presentExpectation fulfill];
198 [
self waitForExpectationsWithTimeout:1 handler:nil];
201 - (void)testClipboardHasCorrectStrings {
202 [UIPasteboard generalPasteboard].string = nil;
204 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
205 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
209 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setString"];
211 [setStringExpectation fulfill];
217 [
self waitForExpectationsWithTimeout:1 handler:nil];
219 XCTestExpectation* hasStringsExpectation = [
self expectationWithDescription:@"hasStrings"];
221 XCTAssertTrue([result[
@"value"] boolValue]);
222 [hasStringsExpectation fulfill];
227 [
self waitForExpectationsWithTimeout:1 handler:nil];
229 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
231 XCTAssertEqualObjects(result[
@"text"],
@"some string");
232 [getDataExpectation fulfill];
237 [
self waitForExpectationsWithTimeout:1 handler:nil];
240 - (void)testClipboardSetDataToNullDoNotCrash {
241 [UIPasteboard generalPasteboard].string = nil;
243 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
244 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
248 XCTestExpectation* setStringExpectation = [
self expectationWithDescription:@"setData"];
250 [setStringExpectation fulfill];
257 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
259 XCTAssertEqualObjects(result[
@"text"],
@"null");
260 [getDataExpectation fulfill];
265 [
self waitForExpectationsWithTimeout:1 handler:nil];
268 - (void)testPopSystemNavigator {
273 UINavigationController* navigationController = [[[UINavigationController alloc]
274 initWithRootViewController:flutterViewController] autorelease];
275 UITabBarController* tabBarController = [[[UITabBarController alloc] init] autorelease];
276 tabBarController.viewControllers = @[ navigationController ];
277 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
278 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
282 id navigationControllerMock = OCMPartialMock(navigationController);
283 OCMStub([navigationControllerMock popViewControllerAnimated:YES]);
285 XCTestExpectation* navigationPopCalled = [
self expectationWithDescription:@"SystemNavigator.pop"];
287 [navigationPopCalled fulfill];
292 [
self waitForExpectationsWithTimeout:1 handler:nil];
293 OCMVerify([navigationControllerMock popViewControllerAnimated:YES]);
295 [flutterViewController deregisterNotifications];
296 [flutterViewController release];
299 - (void)testWhetherDeviceHasLiveTextInputInvokeCorrectly {
301 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
302 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
303 XCTestExpectation* invokeExpectation =
304 [
self expectationWithDescription:@"isLiveTextInputAvailableInvoke"];
312 OCMVerify([mockPlugin isLiveTextInputAvailable]);
313 [invokeExpectation fulfill];
316 [
self waitForExpectationsWithTimeout:1 handler:nil];
319 - (void)testViewControllerBasedStatusBarHiddenUpdate {
320 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
321 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
329 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
330 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
331 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
336 XCTestExpectation* enableSystemUIOverlaysCalled =
337 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
339 [enableSystemUIOverlaysCalled fulfill];
343 arguments:@[ @"SystemUiOverlay.bottom" ]];
345 [
self waitForExpectationsWithTimeout:1 handler:nil];
346 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
349 XCTestExpectation* enableSystemUIOverlaysCalled2 =
350 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
352 [enableSystemUIOverlaysCalled2 fulfill];
358 [
self waitForExpectationsWithTimeout:1 handler:nil];
359 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
361 [flutterViewController deregisterNotifications];
362 [flutterViewController release];
370 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
371 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
372 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
377 XCTestExpectation* enableSystemUIModeCalled =
378 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
380 [enableSystemUIModeCalled fulfill];
386 [
self waitForExpectationsWithTimeout:1 handler:nil];
387 XCTAssertTrue(flutterViewController.prefersStatusBarHidden);
390 XCTestExpectation* enableSystemUIModeCalled2 =
391 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
393 [enableSystemUIModeCalled2 fulfill];
399 [
self waitForExpectationsWithTimeout:1 handler:nil];
400 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
402 [flutterViewController deregisterNotifications];
403 [flutterViewController release];
405 [bundleMock stopMocking];
408 - (void)testStatusBarHiddenUpdate {
409 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
410 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
412 id mockApplication = OCMClassMock([UIApplication
class]);
413 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
420 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
421 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
426 XCTestExpectation* enableSystemUIOverlaysCalled =
427 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
429 [enableSystemUIOverlaysCalled fulfill];
433 arguments:@[ @"SystemUiOverlay.bottom" ]];
434 [plugin handleMethodCall:methodCallSet result:resultSet];
435 [
self waitForExpectationsWithTimeout:1 handler:nil];
436 #if not APPLICATION_EXTENSION_API_ONLY
437 OCMVerify([mockApplication setStatusBarHidden:YES]);
441 XCTestExpectation* enableSystemUIOverlaysCalled2 =
442 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
444 [enableSystemUIOverlaysCalled2 fulfill];
449 [plugin handleMethodCall:methodCallSet2 result:resultSet2];
450 [
self waitForExpectationsWithTimeout:1 handler:nil];
451 #if not APPLICATION_EXTENSION_API_ONLY
452 OCMVerify([mockApplication setStatusBarHidden:NO]);
455 [flutterViewController deregisterNotifications];
456 [mockApplication stopMocking];
457 [bundleMock stopMocking];
460 - (void)testStatusBarStyle {
461 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
462 OCMStub([bundleMock objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"])
464 id mockApplication = OCMClassMock([UIApplication
class]);
465 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
471 std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>>
_weakFactory =
472 std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(
engine);
473 XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
477 XCTestExpectation* enableSystemUIModeCalled =
478 [
self expectationWithDescription:@"setSystemUIOverlayStyle"];
480 [enableSystemUIModeCalled fulfill];
484 arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
486 [
self waitForExpectationsWithTimeout:1 handler:nil];
488 #if not APPLICATION_EXTENSION_API_ONLY
489 OCMVerify([mockApplication setStatusBarStyle:UIStatusBarStyleLightContent]);
492 [flutterViewController deregisterNotifications];
493 [mockApplication stopMocking];
494 [bundleMock stopMocking];