5#import <OCMock/OCMock.h>
6#import <XCTest/XCTest.h>
8#import "flutter/fml/platform/darwin/weak_nsobject.h"
9#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
10#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
11#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
12#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
13#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h"
14#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
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;
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];
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];
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];
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];
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];
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];
222 [plugin handleMethodCall:methodCallSet result:resultSet];
223 [
self waitForExpectationsWithTimeout:1 handler:nil];
225 XCTestExpectation* hasStringsExpectation = [
self expectationWithDescription:@"hasStrings"];
227 XCTAssertTrue([
result[
@"value"] boolValue]);
228 [hasStringsExpectation fulfill];
232 [plugin handleMethodCall:methodCall result:result];
233 [
self waitForExpectationsWithTimeout:1 handler:nil];
235 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
237 XCTAssertEqualObjects(
result[
@"text"],
@"some string");
238 [getDataExpectation fulfill];
242 [plugin handleMethodCall:methodCallGetData result:getDataResult];
243 [
self waitForExpectationsWithTimeout:1 handler:nil];
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];
261 [plugin handleMethodCall:methodCallSet result:resultSet];
263 XCTestExpectation* getDataExpectation = [
self expectationWithDescription:@"getData"];
265 XCTAssertEqualObjects(
result[
@"text"],
@"null");
266 [getDataExpectation fulfill];
270 [plugin handleMethodCall:methodCall result:result];
271 [
self waitForExpectationsWithTimeout:1 handler:nil];
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];
297 [plugin handleMethodCall:methodCallSet result:resultSet];
298 [
self waitForExpectationsWithTimeout:1 handler:nil];
299 OCMVerify([navigationControllerMock popViewControllerAnimated:YES]);
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];
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);
341 XCTestExpectation* enableSystemUIOverlaysCalled =
342 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
344 [enableSystemUIOverlaysCalled fulfill];
348 arguments:@[ @"SystemUiOverlay.bottom" ]];
350 [
self waitForExpectationsWithTimeout:1 handler:nil];
354 XCTestExpectation* enableSystemUIOverlaysCalled2 =
355 [
self expectationWithDescription:@"setEnabledSystemUIOverlays"];
357 [enableSystemUIOverlaysCalled2 fulfill];
363 [
self waitForExpectationsWithTimeout:1 handler:nil];
374 std::unique_ptr<fml::WeakNSObjectFactory<FlutterEngine>>
_weakFactory =
375 std::make_unique<fml::WeakNSObjectFactory<FlutterEngine>>(
engine);
381 XCTestExpectation* enableSystemUIModeCalled =
382 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
384 [enableSystemUIModeCalled fulfill];
390 [
self waitForExpectationsWithTimeout:1 handler:nil];
394 XCTestExpectation* enableSystemUIModeCalled2 =
395 [
self expectationWithDescription:@"setEnabledSystemUIMode"];
397 [enableSystemUIModeCalled2 fulfill];
403 [
self waitForExpectationsWithTimeout:1 handler:nil];
408 [bundleMock stopMocking];
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]);
459 [mockApplication stopMocking];
460 [bundleMock stopMocking];
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);
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]);
496 [mockApplication stopMocking];
497 [bundleMock stopMocking];
void(^ FlutterResult)(id _Nullable result)
FlutterSemanticsFlag flag
BOOL runWithEntrypoint:(nullable NSString *entrypoint)
FlutterPlatformPlugin * platformPlugin()
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
void deregisterNotifications()
BOOL prefersStatusBarHidden()
Whether the status bar is preferred hidden.
std::unique_ptr< fml::WeakNSObjectFactory< FlutterEngine > > _weakFactory
union flutter::testing::@2836::KeyboardChange::@76 content