5 #import <OCMock/OCMock.h>
6 #import <UIKit/UIKit.h>
7 #import <WebKit/WebKit.h>
8 #import <XCTest/XCTest.h>
9 #include "fml/synchronization/count_down_latch.h"
12 #import "flutter/fml/thread.h"
31 - (instancetype)init {
46 @property(nonatomic, strong) UIView* view;
47 @property(nonatomic, assign) BOOL viewCreated;
52 - (instancetype)init {
53 if (
self = [super init]) {
61 [
self checkViewCreatedOnce];
65 - (void)checkViewCreatedOnce {
69 self.viewCreated = YES;
78 : NSObject <FlutterPlatformViewFactory>
83 viewIdentifier:(int64_t)viewId
84 arguments:(
id _Nullable)args {
91 @property(nonatomic, strong) UIView* view;
92 @property(nonatomic, assign) BOOL viewCreated;
96 - (instancetype)init {
97 if (
self = [super init]) {
98 _view = [[WKWebView alloc] init];
106 [
self checkViewCreatedOnce];
110 - (void)checkViewCreatedOnce {
114 self.viewCreated = YES;
126 - (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
127 viewIdentifier:(int64_t)viewId
128 arguments:(
id _Nullable)args {
137 - (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
138 viewIdentifier:(int64_t)viewId
139 arguments:(
id _Nullable)args {
146 @property(nonatomic, strong) UIView* view;
147 @property(nonatomic, assign) BOOL viewCreated;
151 - (instancetype)init {
152 if (
self = [super init]) {
153 _view = [[UIView alloc] init];
154 [_view addSubview:[[WKWebView alloc] init]];
162 [
self checkViewCreatedOnce];
166 - (void)checkViewCreatedOnce {
170 self.viewCreated = YES;
182 - (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
183 viewIdentifier:(int64_t)viewId
184 arguments:(
id _Nullable)args {
190 @property(nonatomic, strong) UIView* view;
191 @property(nonatomic, assign) BOOL viewCreated;
195 - (instancetype)init {
196 if (
self = [super init]) {
197 _view = [[UIView alloc] init];
198 UIView* childView = [[UIView alloc] init];
199 [_view addSubview:childView];
200 [childView addSubview:[[WKWebView alloc] init]];
208 [
self checkViewCreatedOnce];
212 - (void)checkViewCreatedOnce {
216 self.viewCreated = YES;
221 : NSObject <FlutterPlatformViewFactory>
226 viewIdentifier:(int64_t)viewId
227 arguments:(
id _Nullable)args {
234 class FlutterPlatformViewsTestMockPlatformViewDelegate :
public PlatformView::Delegate {
236 void OnPlatformViewCreated(std::unique_ptr<Surface> surface)
override {}
237 void OnPlatformViewDestroyed()
override {}
238 void OnPlatformViewScheduleFrame()
override {}
239 void OnPlatformViewAddView(int64_t view_id,
240 const ViewportMetrics& viewport_metrics,
241 AddViewCallback callback)
override {}
242 void OnPlatformViewRemoveView(int64_t view_id, RemoveViewCallback callback)
override {}
243 void OnPlatformViewSetNextFrameCallback(
const fml::closure& closure)
override {}
244 void OnPlatformViewSetViewportMetrics(int64_t view_id,
const ViewportMetrics& metrics)
override {}
245 const flutter::Settings& OnPlatformViewGetSettings()
const override {
return settings_; }
246 void OnPlatformViewDispatchPlatformMessage(std::unique_ptr<PlatformMessage> message)
override {}
247 void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet)
override {
249 void OnPlatformViewDispatchSemanticsAction(int32_t
id,
250 SemanticsAction action,
251 fml::MallocMapping args)
override {}
252 void OnPlatformViewSetSemanticsEnabled(
bool enabled)
override {}
253 void OnPlatformViewSetAccessibilityFeatures(int32_t flags)
override {}
254 void OnPlatformViewRegisterTexture(std::shared_ptr<Texture> texture)
override {}
255 void OnPlatformViewUnregisterTexture(int64_t
texture_id)
override {}
256 void OnPlatformViewMarkTextureFrameAvailable(int64_t
texture_id)
override {}
258 void LoadDartDeferredLibrary(intptr_t loading_unit_id,
259 std::unique_ptr<const fml::Mapping> snapshot_data,
260 std::unique_ptr<const fml::Mapping> snapshot_instructions)
override {
262 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
263 const std::string error_message,
264 bool transient)
override {}
265 void UpdateAssetResolverByType(std::unique_ptr<flutter::AssetResolver> updated_asset_resolver,
266 flutter::AssetResolver::AssetResolverType type)
override {}
271 BOOL BlurRadiusEqualToBlurRadius(CGFloat radius1, CGFloat radius2) {
272 const CGFloat epsilon = 0.01;
273 return std::abs(radius1 - radius2) < epsilon;
285 fml::RefPtr<fml::TaskRunner> GetDefaultTaskRunner() {
286 fml::MessageLoop::EnsureInitializedForCurrentThread();
287 return fml::MessageLoop::GetCurrent().GetTaskRunner();
291 - (void)testFlutterViewOnlyCreateOnceInOneFrame {
292 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
294 flutter::TaskRunners runners(
self.name.UTF8String,
295 GetDefaultTaskRunner(),
296 GetDefaultTaskRunner(),
297 GetDefaultTaskRunner(),
298 GetDefaultTaskRunner());
299 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
300 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
301 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
303 mock_delegate.settings_.enable_impeller
306 flutterPlatformViewsController,
309 std::make_shared<fml::SyncSwitch>());
313 flutterPlatformViewsController->RegisterViewFactory(
314 factory,
@"MockFlutterPlatformView",
318 flutterPlatformViewsController->OnMethodCall(
320 methodCallWithMethodName:
@"create"
321 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
323 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
324 flutterPlatformViewsController->SetFlutterView(flutterView);
326 flutter::MutatorsStack stack;
328 SkMatrix screenScaleMatrix =
329 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
330 stack.PushTransform(screenScaleMatrix);
332 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
333 stack.PushTransform(translateMatrix);
334 SkMatrix finalMatrix;
335 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
337 auto embeddedViewParams =
338 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
340 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
344 flutterPlatformViewsController->Reset();
347 - (void)testCanCreatePlatformViewWithoutFlutterView {
348 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
350 flutter::TaskRunners runners(
self.name.UTF8String,
351 GetDefaultTaskRunner(),
352 GetDefaultTaskRunner(),
353 GetDefaultTaskRunner(),
354 GetDefaultTaskRunner());
355 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
356 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
357 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
359 mock_delegate.settings_.enable_impeller
362 flutterPlatformViewsController,
365 std::make_shared<fml::SyncSwitch>());
369 flutterPlatformViewsController->RegisterViewFactory(
370 factory,
@"MockFlutterPlatformView",
374 flutterPlatformViewsController->OnMethodCall(
376 methodCallWithMethodName:
@"create"
377 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
383 - (void)testChildClippingViewHitTests {
386 UIView* childView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
387 [childClippingView addSubview:childView];
389 XCTAssertFalse([childClippingView pointInside:CGPointMake(50, 50) withEvent:nil]);
390 XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 100) withEvent:nil]);
391 XCTAssertFalse([childClippingView pointInside:CGPointMake(100, 99) withEvent:nil]);
392 XCTAssertFalse([childClippingView pointInside:CGPointMake(201, 200) withEvent:nil]);
393 XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 201) withEvent:nil]);
394 XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 200) withEvent:nil]);
395 XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 299) withEvent:nil]);
397 XCTAssertTrue([childClippingView pointInside:CGPointMake(150, 150) withEvent:nil]);
398 XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 100) withEvent:nil]);
399 XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 100) withEvent:nil]);
400 XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 199) withEvent:nil]);
401 XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 199) withEvent:nil]);
404 - (void)testReleasesBackdropFilterSubviewsOnChildClippingViewDealloc {
405 __weak NSMutableArray<UIVisualEffectView*>* weakBackdropFilterSubviews = nil;
406 __weak UIVisualEffectView* weakVisualEffectView1 = nil;
407 __weak UIVisualEffectView* weakVisualEffectView2 = nil;
411 UIVisualEffectView* visualEffectView1 = [[UIVisualEffectView alloc]
412 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
413 weakVisualEffectView1 = visualEffectView1;
417 visualEffectView:visualEffectView1];
422 UIVisualEffectView* visualEffectView2 = [[UIVisualEffectView alloc]
423 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
424 weakVisualEffectView2 = visualEffectView2;
428 visualEffectView:visualEffectView2];
432 XCTAssertNotNil(weakBackdropFilterSubviews);
435 XCTAssertNil(weakBackdropFilterSubviews);
436 XCTAssertNil(weakVisualEffectView1);
437 XCTAssertNil(weakVisualEffectView2);
440 - (void)testApplyBackdropFilter {
441 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
443 flutter::TaskRunners runners(
self.name.UTF8String,
444 GetDefaultTaskRunner(),
445 GetDefaultTaskRunner(),
446 GetDefaultTaskRunner(),
447 GetDefaultTaskRunner());
448 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
449 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
450 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
452 mock_delegate.settings_.enable_impeller
455 flutterPlatformViewsController,
458 std::make_shared<fml::SyncSwitch>());
462 flutterPlatformViewsController->RegisterViewFactory(
463 factory,
@"MockFlutterPlatformView",
467 flutterPlatformViewsController->OnMethodCall(
469 methodCallWithMethodName:
@"create"
470 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
475 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
476 flutterPlatformViewsController->SetFlutterView(flutterView);
478 flutter::MutatorsStack stack;
480 CGFloat screenScale = [UIScreen mainScreen].scale;
481 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
482 stack.PushTransform(screenScaleMatrix);
484 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
485 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
487 auto embeddedViewParams =
488 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
490 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
491 flutterPlatformViewsController->CompositeWithParams(
492 2, flutterPlatformViewsController->GetCompositionParams(2));
496 [flutterView addSubview:childClippingView];
498 [flutterView setNeedsLayout];
499 [flutterView layoutIfNeeded];
502 NSUInteger numberOfExpectedVisualEffectView = 0;
503 for (UIView* subview in childClippingView.subviews) {
504 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
507 XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u);
508 if ([
self validateOneVisualEffectView:subview
509 expectedFrame:CGRectMake(0, 0, 10, 10)
511 numberOfExpectedVisualEffectView++;
514 XCTAssertEqual(numberOfExpectedVisualEffectView, 1u);
517 - (void)testApplyBackdropFilterWithCorrectFrame {
518 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
520 flutter::TaskRunners runners(
self.name.UTF8String,
521 GetDefaultTaskRunner(),
522 GetDefaultTaskRunner(),
523 GetDefaultTaskRunner(),
524 GetDefaultTaskRunner());
525 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
526 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
527 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
529 mock_delegate.settings_.enable_impeller
532 flutterPlatformViewsController,
535 std::make_shared<fml::SyncSwitch>());
539 flutterPlatformViewsController->RegisterViewFactory(
540 factory,
@"MockFlutterPlatformView",
544 flutterPlatformViewsController->OnMethodCall(
546 methodCallWithMethodName:
@"create"
547 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
552 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
553 flutterPlatformViewsController->SetFlutterView(flutterView);
555 flutter::MutatorsStack stack;
557 CGFloat screenScale = [UIScreen mainScreen].scale;
558 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
559 stack.PushTransform(screenScaleMatrix);
561 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
562 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 8, screenScale * 8));
564 auto embeddedViewParams =
565 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(5, 10), stack);
567 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
568 flutterPlatformViewsController->CompositeWithParams(
569 2, flutterPlatformViewsController->GetCompositionParams(2));
573 [flutterView addSubview:childClippingView];
575 [flutterView setNeedsLayout];
576 [flutterView layoutIfNeeded];
579 NSUInteger numberOfExpectedVisualEffectView = 0;
580 for (UIView* subview in childClippingView.subviews) {
581 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
584 XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u);
585 if ([
self validateOneVisualEffectView:subview
586 expectedFrame:CGRectMake(0, 0, 5, 8)
588 numberOfExpectedVisualEffectView++;
591 XCTAssertEqual(numberOfExpectedVisualEffectView, 1u);
594 - (void)testApplyMultipleBackdropFilters {
595 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
597 flutter::TaskRunners runners(
self.name.UTF8String,
598 GetDefaultTaskRunner(),
599 GetDefaultTaskRunner(),
600 GetDefaultTaskRunner(),
601 GetDefaultTaskRunner());
602 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
603 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
604 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
606 mock_delegate.settings_.enable_impeller
609 flutterPlatformViewsController,
612 std::make_shared<fml::SyncSwitch>());
616 flutterPlatformViewsController->RegisterViewFactory(
617 factory,
@"MockFlutterPlatformView",
621 flutterPlatformViewsController->OnMethodCall(
623 methodCallWithMethodName:
@"create"
624 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
629 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
630 flutterPlatformViewsController->SetFlutterView(flutterView);
632 flutter::MutatorsStack stack;
634 CGFloat screenScale = [UIScreen mainScreen].scale;
635 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
636 stack.PushTransform(screenScaleMatrix);
638 for (
int i = 0; i < 50; i++) {
639 auto filter = std::make_shared<flutter::DlBlurImageFilter>(i, 2, flutter::DlTileMode::kClamp);
640 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
643 auto embeddedViewParams =
644 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(20, 20), stack);
646 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
647 flutterPlatformViewsController->CompositeWithParams(
648 2, flutterPlatformViewsController->GetCompositionParams(2));
652 [flutterView addSubview:childClippingView];
654 [flutterView setNeedsLayout];
655 [flutterView layoutIfNeeded];
657 NSUInteger numberOfExpectedVisualEffectView = 0;
658 for (UIView* subview in childClippingView.subviews) {
659 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
662 XCTAssertLessThan(numberOfExpectedVisualEffectView, 50u);
663 if ([
self validateOneVisualEffectView:subview
664 expectedFrame:CGRectMake(0, 0, 10, 10)
665 inputRadius:(CGFloat)numberOfExpectedVisualEffectView]) {
666 numberOfExpectedVisualEffectView++;
669 XCTAssertEqual(numberOfExpectedVisualEffectView, (NSUInteger)numberOfExpectedVisualEffectView);
672 - (void)testAddBackdropFilters {
673 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
675 flutter::TaskRunners runners(
self.name.UTF8String,
676 GetDefaultTaskRunner(),
677 GetDefaultTaskRunner(),
678 GetDefaultTaskRunner(),
679 GetDefaultTaskRunner());
680 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
681 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
682 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
684 mock_delegate.settings_.enable_impeller
687 flutterPlatformViewsController,
690 std::make_shared<fml::SyncSwitch>());
694 flutterPlatformViewsController->RegisterViewFactory(
695 factory,
@"MockFlutterPlatformView",
699 flutterPlatformViewsController->OnMethodCall(
701 methodCallWithMethodName:
@"create"
702 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
707 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
708 flutterPlatformViewsController->SetFlutterView(flutterView);
710 flutter::MutatorsStack stack;
712 CGFloat screenScale = [UIScreen mainScreen].scale;
713 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
714 stack.PushTransform(screenScaleMatrix);
716 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
717 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
719 auto embeddedViewParams =
720 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
722 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
723 flutterPlatformViewsController->CompositeWithParams(
724 2, flutterPlatformViewsController->GetCompositionParams(2));
728 [flutterView addSubview:childClippingView];
730 [flutterView setNeedsLayout];
731 [flutterView layoutIfNeeded];
733 NSMutableArray* originalVisualEffectViews = [[NSMutableArray alloc] init];
734 for (UIView* subview in childClippingView.subviews) {
735 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
738 XCTAssertLessThan(originalVisualEffectViews.count, 1u);
739 if ([
self validateOneVisualEffectView:subview
740 expectedFrame:CGRectMake(0, 0, 10, 10)
741 inputRadius:(CGFloat)5]) {
742 [originalVisualEffectViews addObject:subview];
745 XCTAssertEqual(originalVisualEffectViews.count, 1u);
750 flutter::MutatorsStack stack2;
752 stack2.PushTransform(screenScaleMatrix);
754 for (
int i = 0; i < 2; i++) {
755 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
758 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
759 SkSize::Make(10, 10), stack2);
761 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
762 flutterPlatformViewsController->CompositeWithParams(
763 2, flutterPlatformViewsController->GetCompositionParams(2));
765 [flutterView setNeedsLayout];
766 [flutterView layoutIfNeeded];
768 NSMutableArray* newVisualEffectViews = [[NSMutableArray alloc] init];
769 for (UIView* subview in childClippingView.subviews) {
770 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
773 XCTAssertLessThan(newVisualEffectViews.count, 2u);
775 if ([
self validateOneVisualEffectView:subview
776 expectedFrame:CGRectMake(0, 0, 10, 10)
777 inputRadius:(CGFloat)5]) {
778 [newVisualEffectViews addObject:subview];
781 XCTAssertEqual(newVisualEffectViews.count, 2u);
782 for (NSUInteger i = 0; i < originalVisualEffectViews.count; i++) {
783 UIView* originalView = originalVisualEffectViews[i];
784 UIView* newView = newVisualEffectViews[i];
786 XCTAssertEqual(originalView, newView);
787 id mockOrignalView = OCMPartialMock(originalView);
788 OCMReject([mockOrignalView removeFromSuperview]);
789 [mockOrignalView stopMocking];
793 - (void)testRemoveBackdropFilters {
794 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
796 flutter::TaskRunners runners(
self.name.UTF8String,
797 GetDefaultTaskRunner(),
798 GetDefaultTaskRunner(),
799 GetDefaultTaskRunner(),
800 GetDefaultTaskRunner());
801 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
802 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
803 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
805 mock_delegate.settings_.enable_impeller
808 flutterPlatformViewsController,
811 std::make_shared<fml::SyncSwitch>());
815 flutterPlatformViewsController->RegisterViewFactory(
816 factory,
@"MockFlutterPlatformView",
820 flutterPlatformViewsController->OnMethodCall(
822 methodCallWithMethodName:
@"create"
823 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
828 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
829 flutterPlatformViewsController->SetFlutterView(flutterView);
831 flutter::MutatorsStack stack;
833 CGFloat screenScale = [UIScreen mainScreen].scale;
834 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
835 stack.PushTransform(screenScaleMatrix);
837 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
838 for (
int i = 0; i < 5; i++) {
839 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
842 auto embeddedViewParams =
843 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
845 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
846 flutterPlatformViewsController->CompositeWithParams(
847 2, flutterPlatformViewsController->GetCompositionParams(2));
851 [flutterView addSubview:childClippingView];
853 [flutterView setNeedsLayout];
854 [flutterView layoutIfNeeded];
856 NSMutableArray* originalVisualEffectViews = [[NSMutableArray alloc] init];
857 for (UIView* subview in childClippingView.subviews) {
858 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
861 XCTAssertLessThan(originalVisualEffectViews.count, 5u);
862 if ([
self validateOneVisualEffectView:subview
863 expectedFrame:CGRectMake(0, 0, 10, 10)
864 inputRadius:(CGFloat)5]) {
865 [originalVisualEffectViews addObject:subview];
871 flutter::MutatorsStack stack2;
873 stack2.PushTransform(screenScaleMatrix);
875 for (
int i = 0; i < 4; i++) {
876 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
879 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
880 SkSize::Make(10, 10), stack2);
882 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
883 flutterPlatformViewsController->CompositeWithParams(
884 2, flutterPlatformViewsController->GetCompositionParams(2));
886 [flutterView setNeedsLayout];
887 [flutterView layoutIfNeeded];
889 NSMutableArray* newVisualEffectViews = [[NSMutableArray alloc] init];
890 for (UIView* subview in childClippingView.subviews) {
891 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
894 XCTAssertLessThan(newVisualEffectViews.count, 4u);
895 if ([
self validateOneVisualEffectView:subview
896 expectedFrame:CGRectMake(0, 0, 10, 10)
897 inputRadius:(CGFloat)5]) {
898 [newVisualEffectViews addObject:subview];
901 XCTAssertEqual(newVisualEffectViews.count, 4u);
903 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
904 UIView* newView = newVisualEffectViews[i];
905 id mockNewView = OCMPartialMock(newView);
906 UIView* originalView = originalVisualEffectViews[i];
908 XCTAssertEqual(originalView, newView);
909 OCMReject([mockNewView removeFromSuperview]);
910 [mockNewView stopMocking];
915 for (
int i = 0; i < 5; i++) {
920 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
921 SkSize::Make(10, 10), stack2);
923 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
924 flutterPlatformViewsController->CompositeWithParams(
925 2, flutterPlatformViewsController->GetCompositionParams(2));
927 [flutterView setNeedsLayout];
928 [flutterView layoutIfNeeded];
930 NSUInteger numberOfExpectedVisualEffectView = 0u;
931 for (UIView* subview in childClippingView.subviews) {
932 if ([subview isKindOfClass:[UIVisualEffectView
class]]) {
933 numberOfExpectedVisualEffectView++;
936 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
939 - (void)testEditBackdropFilters {
940 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
942 flutter::TaskRunners runners(
self.name.UTF8String,
943 GetDefaultTaskRunner(),
944 GetDefaultTaskRunner(),
945 GetDefaultTaskRunner(),
946 GetDefaultTaskRunner());
947 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
948 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
949 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
951 mock_delegate.settings_.enable_impeller
954 flutterPlatformViewsController,
957 std::make_shared<fml::SyncSwitch>());
961 flutterPlatformViewsController->RegisterViewFactory(
962 factory,
@"MockFlutterPlatformView",
966 flutterPlatformViewsController->OnMethodCall(
968 methodCallWithMethodName:
@"create"
969 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
974 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
975 flutterPlatformViewsController->SetFlutterView(flutterView);
977 flutter::MutatorsStack stack;
979 CGFloat screenScale = [UIScreen mainScreen].scale;
980 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
981 stack.PushTransform(screenScaleMatrix);
983 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
984 for (
int i = 0; i < 5; i++) {
985 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
988 auto embeddedViewParams =
989 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
991 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
992 flutterPlatformViewsController->CompositeWithParams(
993 2, flutterPlatformViewsController->GetCompositionParams(2));
997 [flutterView addSubview:childClippingView];
999 [flutterView setNeedsLayout];
1000 [flutterView layoutIfNeeded];
1002 NSMutableArray* originalVisualEffectViews = [[NSMutableArray alloc] init];
1003 for (UIView* subview in childClippingView.subviews) {
1004 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1007 XCTAssertLessThan(originalVisualEffectViews.count, 5u);
1008 if ([
self validateOneVisualEffectView:subview
1009 expectedFrame:CGRectMake(0, 0, 10, 10)
1010 inputRadius:(CGFloat)5]) {
1011 [originalVisualEffectViews addObject:subview];
1017 flutter::MutatorsStack stack2;
1019 stack2.PushTransform(screenScaleMatrix);
1021 for (
int i = 0; i < 5; i++) {
1024 std::make_shared<flutter::DlBlurImageFilter>(2, 5, flutter::DlTileMode::kClamp);
1026 stack2.PushBackdropFilter(filter2,
1027 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1031 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1034 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1035 SkSize::Make(10, 10), stack2);
1037 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1038 flutterPlatformViewsController->CompositeWithParams(
1039 2, flutterPlatformViewsController->GetCompositionParams(2));
1041 [flutterView setNeedsLayout];
1042 [flutterView layoutIfNeeded];
1044 NSMutableArray* newVisualEffectViews = [[NSMutableArray alloc] init];
1045 for (UIView* subview in childClippingView.subviews) {
1046 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1049 XCTAssertLessThan(newVisualEffectViews.count, 5u);
1050 CGFloat expectInputRadius = 5;
1051 if (newVisualEffectViews.count == 3) {
1052 expectInputRadius = 2;
1054 if ([
self validateOneVisualEffectView:subview
1055 expectedFrame:CGRectMake(0, 0, 10, 10)
1056 inputRadius:(CGFloat)expectInputRadius]) {
1057 [newVisualEffectViews addObject:subview];
1060 XCTAssertEqual(newVisualEffectViews.count, 5u);
1061 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
1062 UIView* newView = newVisualEffectViews[i];
1063 id mockNewView = OCMPartialMock(newView);
1064 UIView* originalView = originalVisualEffectViews[i];
1066 XCTAssertEqual(originalView, newView);
1067 OCMReject([mockNewView removeFromSuperview]);
1068 [mockNewView stopMocking];
1070 [newVisualEffectViews removeAllObjects];
1074 for (
int i = 0; i < 5; i++) {
1078 for (
int i = 0; i < 5; i++) {
1081 std::make_shared<flutter::DlBlurImageFilter>(2, 5, flutter::DlTileMode::kClamp);
1082 stack2.PushBackdropFilter(filter2,
1083 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1087 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1090 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1091 SkSize::Make(10, 10), stack2);
1093 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1094 flutterPlatformViewsController->CompositeWithParams(
1095 2, flutterPlatformViewsController->GetCompositionParams(2));
1097 [flutterView setNeedsLayout];
1098 [flutterView layoutIfNeeded];
1100 for (UIView* subview in childClippingView.subviews) {
1101 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1104 XCTAssertLessThan(newVisualEffectViews.count, 5u);
1105 CGFloat expectInputRadius = 5;
1106 if (newVisualEffectViews.count == 0) {
1107 expectInputRadius = 2;
1109 if ([
self validateOneVisualEffectView:subview
1110 expectedFrame:CGRectMake(0, 0, 10, 10)
1111 inputRadius:(CGFloat)expectInputRadius]) {
1112 [newVisualEffectViews addObject:subview];
1115 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
1116 UIView* newView = newVisualEffectViews[i];
1117 id mockNewView = OCMPartialMock(newView);
1118 UIView* originalView = originalVisualEffectViews[i];
1120 XCTAssertEqual(originalView, newView);
1121 OCMReject([mockNewView removeFromSuperview]);
1122 [mockNewView stopMocking];
1124 [newVisualEffectViews removeAllObjects];
1128 for (
int i = 0; i < 5; i++) {
1132 for (
int i = 0; i < 5; i++) {
1135 std::make_shared<flutter::DlBlurImageFilter>(2, 5, flutter::DlTileMode::kClamp);
1136 stack2.PushBackdropFilter(filter2,
1137 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1141 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1144 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1145 SkSize::Make(10, 10), stack2);
1147 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1148 flutterPlatformViewsController->CompositeWithParams(
1149 2, flutterPlatformViewsController->GetCompositionParams(2));
1151 [flutterView setNeedsLayout];
1152 [flutterView layoutIfNeeded];
1154 for (UIView* subview in childClippingView.subviews) {
1155 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1158 XCTAssertLessThan(newVisualEffectViews.count, 5u);
1159 CGFloat expectInputRadius = 5;
1160 if (newVisualEffectViews.count == 4) {
1161 expectInputRadius = 2;
1163 if ([
self validateOneVisualEffectView:subview
1164 expectedFrame:CGRectMake(0, 0, 10, 10)
1165 inputRadius:(CGFloat)expectInputRadius]) {
1166 [newVisualEffectViews addObject:subview];
1169 XCTAssertEqual(newVisualEffectViews.count, 5u);
1171 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
1172 UIView* newView = newVisualEffectViews[i];
1173 id mockNewView = OCMPartialMock(newView);
1174 UIView* originalView = originalVisualEffectViews[i];
1176 XCTAssertEqual(originalView, newView);
1177 OCMReject([mockNewView removeFromSuperview]);
1178 [mockNewView stopMocking];
1180 [newVisualEffectViews removeAllObjects];
1184 for (
int i = 0; i < 5; i++) {
1188 for (
int i = 0; i < 5; i++) {
1189 auto filter2 = std::make_shared<flutter::DlBlurImageFilter>(i, 2, flutter::DlTileMode::kClamp);
1191 stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1194 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1195 SkSize::Make(10, 10), stack2);
1197 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1198 flutterPlatformViewsController->CompositeWithParams(
1199 2, flutterPlatformViewsController->GetCompositionParams(2));
1201 [flutterView setNeedsLayout];
1202 [flutterView layoutIfNeeded];
1204 for (UIView* subview in childClippingView.subviews) {
1205 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1208 XCTAssertLessThan(newVisualEffectViews.count, 5u);
1209 if ([
self validateOneVisualEffectView:subview
1210 expectedFrame:CGRectMake(0, 0, 10, 10)
1211 inputRadius:(CGFloat)newVisualEffectViews.count]) {
1212 [newVisualEffectViews addObject:subview];
1215 XCTAssertEqual(newVisualEffectViews.count, 5u);
1217 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
1218 UIView* newView = newVisualEffectViews[i];
1219 id mockNewView = OCMPartialMock(newView);
1220 UIView* originalView = originalVisualEffectViews[i];
1222 XCTAssertEqual(originalView, newView);
1223 OCMReject([mockNewView removeFromSuperview]);
1224 [mockNewView stopMocking];
1226 [newVisualEffectViews removeAllObjects];
1229 - (void)testApplyBackdropFilterNotDlBlurImageFilter {
1230 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1232 flutter::TaskRunners runners(
self.name.UTF8String,
1233 GetDefaultTaskRunner(),
1234 GetDefaultTaskRunner(),
1235 GetDefaultTaskRunner(),
1236 GetDefaultTaskRunner());
1237 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1238 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1239 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1241 mock_delegate.settings_.enable_impeller
1244 flutterPlatformViewsController,
1247 std::make_shared<fml::SyncSwitch>());
1251 flutterPlatformViewsController->RegisterViewFactory(
1252 factory,
@"MockFlutterPlatformView",
1256 flutterPlatformViewsController->OnMethodCall(
1258 methodCallWithMethodName:
@"create"
1259 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1264 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1265 flutterPlatformViewsController->SetFlutterView(flutterView);
1267 flutter::MutatorsStack stack;
1269 CGFloat screenScale = [UIScreen mainScreen].scale;
1270 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
1271 stack.PushTransform(screenScaleMatrix);
1273 auto dilateFilter = std::make_shared<flutter::DlDilateImageFilter>(5, 2);
1274 stack.PushBackdropFilter(dilateFilter, SkRect::MakeEmpty());
1276 auto embeddedViewParams =
1277 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1279 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1280 flutterPlatformViewsController->CompositeWithParams(
1281 2, flutterPlatformViewsController->GetCompositionParams(2));
1286 [flutterView addSubview:childClippingView];
1288 [flutterView setNeedsLayout];
1289 [flutterView layoutIfNeeded];
1291 NSUInteger numberOfExpectedVisualEffectView = 0;
1292 for (UIView* subview in childClippingView.subviews) {
1293 if ([subview isKindOfClass:[UIVisualEffectView
class]]) {
1294 numberOfExpectedVisualEffectView++;
1297 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
1301 flutter::MutatorsStack stack2;
1303 stack2.PushTransform(screenScaleMatrix);
1305 auto blurFilter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
1307 for (
int i = 0; i < 5; i++) {
1309 stack2.PushBackdropFilter(dilateFilter,
1310 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1314 stack2.PushBackdropFilter(blurFilter,
1315 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1318 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1319 SkSize::Make(10, 10), stack2);
1321 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1322 flutterPlatformViewsController->CompositeWithParams(
1323 2, flutterPlatformViewsController->GetCompositionParams(2));
1325 [flutterView setNeedsLayout];
1326 [flutterView layoutIfNeeded];
1328 numberOfExpectedVisualEffectView = 0;
1329 for (UIView* subview in childClippingView.subviews) {
1330 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1333 XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u);
1334 if ([
self validateOneVisualEffectView:subview
1335 expectedFrame:CGRectMake(0, 0, 10, 10)
1336 inputRadius:(CGFloat)5]) {
1337 numberOfExpectedVisualEffectView++;
1340 XCTAssertEqual(numberOfExpectedVisualEffectView, 4u);
1344 for (
int i = 0; i < 5; i++) {
1348 for (
int i = 0; i < 5; i++) {
1350 stack2.PushBackdropFilter(dilateFilter,
1351 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1355 stack2.PushBackdropFilter(blurFilter,
1356 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1359 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1360 SkSize::Make(10, 10), stack2);
1362 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1363 flutterPlatformViewsController->CompositeWithParams(
1364 2, flutterPlatformViewsController->GetCompositionParams(2));
1366 [flutterView setNeedsLayout];
1367 [flutterView layoutIfNeeded];
1369 numberOfExpectedVisualEffectView = 0;
1370 for (UIView* subview in childClippingView.subviews) {
1371 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1374 XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u);
1375 if ([
self validateOneVisualEffectView:subview
1376 expectedFrame:CGRectMake(0, 0, 10, 10)
1377 inputRadius:(CGFloat)5]) {
1378 numberOfExpectedVisualEffectView++;
1381 XCTAssertEqual(numberOfExpectedVisualEffectView, 4u);
1385 for (
int i = 0; i < 5; i++) {
1389 for (
int i = 0; i < 5; i++) {
1391 stack2.PushBackdropFilter(dilateFilter,
1392 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1396 stack2.PushBackdropFilter(blurFilter,
1397 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1400 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1401 SkSize::Make(10, 10), stack2);
1403 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1404 flutterPlatformViewsController->CompositeWithParams(
1405 2, flutterPlatformViewsController->GetCompositionParams(2));
1407 [flutterView setNeedsLayout];
1408 [flutterView layoutIfNeeded];
1410 numberOfExpectedVisualEffectView = 0;
1411 for (UIView* subview in childClippingView.subviews) {
1412 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1415 XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u);
1416 if ([
self validateOneVisualEffectView:subview
1417 expectedFrame:CGRectMake(0, 0, 10, 10)
1418 inputRadius:(CGFloat)5]) {
1419 numberOfExpectedVisualEffectView++;
1422 XCTAssertEqual(numberOfExpectedVisualEffectView, 4u);
1426 for (
int i = 0; i < 5; i++) {
1430 for (
int i = 0; i < 5; i++) {
1431 stack2.PushBackdropFilter(dilateFilter,
1432 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1435 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1436 SkSize::Make(10, 10), stack2);
1438 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1439 flutterPlatformViewsController->CompositeWithParams(
1440 2, flutterPlatformViewsController->GetCompositionParams(2));
1442 [flutterView setNeedsLayout];
1443 [flutterView layoutIfNeeded];
1445 numberOfExpectedVisualEffectView = 0;
1446 for (UIView* subview in childClippingView.subviews) {
1447 if ([subview isKindOfClass:[UIVisualEffectView
class]]) {
1448 numberOfExpectedVisualEffectView++;
1451 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
1454 - (void)testApplyBackdropFilterCorrectAPI {
1459 UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc]
1460 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1464 visualEffectView:visualEffectView];
1465 XCTAssertNotNil(platformViewFilter);
1468 - (void)testApplyBackdropFilterAPIChangedInvalidUIVisualEffectView {
1470 UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] init];
1474 visualEffectView:visualEffectView];
1475 XCTAssertNil(platformViewFilter);
1478 - (void)testApplyBackdropFilterAPIChangedNoGaussianBlurFilter {
1480 UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc]
1481 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1482 NSArray* subviews = editedUIVisualEffectView.subviews;
1483 for (UIView* view in subviews) {
1484 if ([NSStringFromClass([view
class]) hasSuffix:
@"BackdropView"]) {
1485 for (CIFilter* filter in view.layer.filters) {
1486 if ([[filter valueForKey:
@"name"] isEqual:
@"gaussianBlur"]) {
1487 [filter setValue:@"notGaussianBlur" forKey:@"name"];
1497 visualEffectView:editedUIVisualEffectView];
1498 XCTAssertNil(platformViewFilter);
1501 - (void)testApplyBackdropFilterAPIChangedInvalidInputRadius {
1503 UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc]
1504 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1505 NSArray* subviews = editedUIVisualEffectView.subviews;
1506 for (UIView* view in subviews) {
1507 if ([NSStringFromClass([view
class]) hasSuffix:
@"BackdropView"]) {
1508 for (CIFilter* filter in view.layer.filters) {
1509 if ([[filter valueForKey:
@"name"] isEqual:
@"gaussianBlur"]) {
1510 [filter setValue:@"invalidInputRadius" forKey:@"inputRadius"];
1521 visualEffectView:editedUIVisualEffectView];
1522 XCTAssertNil(platformViewFilter);
1525 - (void)testBackdropFilterVisualEffectSubviewBackgroundColor {
1526 __weak UIVisualEffectView* weakVisualEffectView;
1529 UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc]
1530 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1531 weakVisualEffectView = visualEffectView;
1535 visualEffectView:visualEffectView];
1536 CGColorRef visualEffectSubviewBackgroundColor = nil;
1537 for (UIView* view in [platformViewFilter backdropFilterView].subviews) {
1538 if ([NSStringFromClass([view
class]) hasSuffix:
@"VisualEffectSubview"]) {
1539 visualEffectSubviewBackgroundColor = view.layer.backgroundColor;
1543 CGColorEqualToColor(visualEffectSubviewBackgroundColor, UIColor.clearColor.CGColor));
1545 XCTAssertNil(weakVisualEffectView);
1548 - (void)testCompositePlatformView {
1549 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1551 flutter::TaskRunners runners(
self.name.UTF8String,
1552 GetDefaultTaskRunner(),
1553 GetDefaultTaskRunner(),
1554 GetDefaultTaskRunner(),
1555 GetDefaultTaskRunner());
1556 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1557 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1558 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1560 mock_delegate.settings_.enable_impeller
1563 flutterPlatformViewsController,
1566 std::make_shared<fml::SyncSwitch>());
1570 flutterPlatformViewsController->RegisterViewFactory(
1571 factory,
@"MockFlutterPlatformView",
1575 flutterPlatformViewsController->OnMethodCall(
1577 methodCallWithMethodName:
@"create"
1578 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1583 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
1584 flutterPlatformViewsController->SetFlutterView(flutterView);
1586 flutter::MutatorsStack stack;
1588 SkMatrix screenScaleMatrix =
1589 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1590 stack.PushTransform(screenScaleMatrix);
1592 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
1593 stack.PushTransform(translateMatrix);
1594 SkMatrix finalMatrix;
1595 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
1597 auto embeddedViewParams =
1598 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
1600 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1601 flutterPlatformViewsController->CompositeWithParams(
1602 2, flutterPlatformViewsController->GetCompositionParams(2));
1604 CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds
1605 toView:flutterView];
1606 XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, 300)));
1609 - (void)testBackdropFilterCorrectlyPushedAndReset {
1610 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1612 flutter::TaskRunners runners(
self.name.UTF8String,
1613 GetDefaultTaskRunner(),
1614 GetDefaultTaskRunner(),
1615 GetDefaultTaskRunner(),
1616 GetDefaultTaskRunner());
1617 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1618 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1619 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1621 mock_delegate.settings_.enable_impeller
1624 flutterPlatformViewsController,
1627 std::make_shared<fml::SyncSwitch>());
1631 flutterPlatformViewsController->RegisterViewFactory(
1632 factory,
@"MockFlutterPlatformView",
1636 flutterPlatformViewsController->OnMethodCall(
1638 methodCallWithMethodName:
@"create"
1639 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1644 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1645 flutterPlatformViewsController->SetFlutterView(flutterView);
1647 flutter::MutatorsStack stack;
1649 CGFloat screenScale = [UIScreen mainScreen].scale;
1650 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
1651 stack.PushTransform(screenScaleMatrix);
1653 auto embeddedViewParams =
1654 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1656 flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0));
1657 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1658 flutterPlatformViewsController->PushVisitedPlatformView(2);
1659 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
1660 flutterPlatformViewsController->PushFilterToVisitedPlatformViews(
1661 filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1662 flutterPlatformViewsController->CompositeWithParams(
1663 2, flutterPlatformViewsController->GetCompositionParams(2));
1667 [flutterView addSubview:childClippingView];
1669 [flutterView setNeedsLayout];
1670 [flutterView layoutIfNeeded];
1673 NSUInteger numberOfExpectedVisualEffectView = 0;
1674 for (UIView* subview in childClippingView.subviews) {
1675 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1678 XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u);
1679 if ([
self validateOneVisualEffectView:subview
1680 expectedFrame:CGRectMake(0, 0, 10, 10)
1682 numberOfExpectedVisualEffectView++;
1685 XCTAssertEqual(numberOfExpectedVisualEffectView, 1u);
1688 auto embeddedViewParams2 =
1689 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1690 flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0));
1691 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2));
1692 flutterPlatformViewsController->CompositeWithParams(
1693 2, flutterPlatformViewsController->GetCompositionParams(2));
1697 [flutterView setNeedsLayout];
1698 [flutterView layoutIfNeeded];
1700 numberOfExpectedVisualEffectView = 0;
1701 for (UIView* subview in childClippingView.subviews) {
1702 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1705 numberOfExpectedVisualEffectView++;
1707 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
1710 - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView {
1711 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1713 flutter::TaskRunners runners(
self.name.UTF8String,
1714 GetDefaultTaskRunner(),
1715 GetDefaultTaskRunner(),
1716 GetDefaultTaskRunner(),
1717 GetDefaultTaskRunner());
1718 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1719 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1720 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1722 mock_delegate.settings_.enable_impeller
1725 flutterPlatformViewsController,
1728 std::make_shared<fml::SyncSwitch>());
1732 flutterPlatformViewsController->RegisterViewFactory(
1733 factory,
@"MockFlutterPlatformView",
1737 flutterPlatformViewsController->OnMethodCall(
1739 methodCallWithMethodName:
@"create"
1740 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1745 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
1746 flutterPlatformViewsController->SetFlutterView(flutterView);
1748 flutter::MutatorsStack stack;
1750 SkMatrix screenScaleMatrix =
1751 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1752 stack.PushTransform(screenScaleMatrix);
1754 SkMatrix rotateMatrix;
1755 rotateMatrix.setRotate(10);
1756 stack.PushTransform(rotateMatrix);
1757 SkMatrix finalMatrix;
1758 finalMatrix.setConcat(screenScaleMatrix, rotateMatrix);
1760 auto embeddedViewParams =
1761 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
1763 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1764 flutterPlatformViewsController->CompositeWithParams(
1765 2, flutterPlatformViewsController->GetCompositionParams(2));
1767 CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds
1768 toView:flutterView];
1774 XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - childClippingView.frame.origin.x),
1776 XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - childClippingView.frame.origin.y),
1779 fabs(platformViewRectInFlutterView.size.width - childClippingView.frame.size.width),
1782 fabs(platformViewRectInFlutterView.size.height - childClippingView.frame.size.height),
1786 - (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView {
1787 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1789 flutter::TaskRunners runners(
self.name.UTF8String,
1790 GetDefaultTaskRunner(),
1791 GetDefaultTaskRunner(),
1792 GetDefaultTaskRunner(),
1793 GetDefaultTaskRunner());
1794 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1795 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1796 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1798 mock_delegate.settings_.enable_impeller
1801 flutterPlatformViewsController,
1804 std::make_shared<fml::SyncSwitch>());
1808 flutterPlatformViewsController->RegisterViewFactory(
1809 factory,
@"MockFlutterPlatformView",
1813 flutterPlatformViewsController->OnMethodCall(
1815 methodCallWithMethodName:
@"create"
1816 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1821 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
1822 flutterPlatformViewsController->SetFlutterView(flutterView);
1824 flutter::MutatorsStack stack;
1826 SkMatrix screenScaleMatrix =
1827 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1828 stack.PushTransform(screenScaleMatrix);
1829 SkMatrix translateMatrix = SkMatrix::Translate(5, 5);
1831 stack.PushTransform(translateMatrix);
1833 SkRect rect = SkRect::MakeXYWH(0, 0, 25, 25);
1834 stack.PushClipRect(rect);
1837 SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25);
1838 SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1);
1839 stack.PushClipRRect(rrect);
1841 auto embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(
1842 SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack);
1844 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1845 flutterPlatformViewsController->CompositeWithParams(
1846 2, flutterPlatformViewsController->GetCompositionParams(2));
1851 [flutterView addSubview:childClippingView];
1853 [flutterView setNeedsLayout];
1854 [flutterView layoutIfNeeded];
1855 XCTAssertNil(childClippingView.maskView);
1858 - (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView {
1859 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1861 flutter::TaskRunners runners(
self.name.UTF8String,
1862 GetDefaultTaskRunner(),
1863 GetDefaultTaskRunner(),
1864 GetDefaultTaskRunner(),
1865 GetDefaultTaskRunner());
1866 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1867 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1868 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1870 mock_delegate.settings_.enable_impeller
1873 flutterPlatformViewsController,
1876 std::make_shared<fml::SyncSwitch>());
1880 flutterPlatformViewsController->RegisterViewFactory(
1881 factory,
@"MockFlutterPlatformView",
1885 flutterPlatformViewsController->OnMethodCall(
1887 methodCallWithMethodName:
@"create"
1888 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1893 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
1894 flutterPlatformViewsController->SetFlutterView(flutterView);
1896 flutter::MutatorsStack stack;
1898 SkMatrix screenScaleMatrix =
1899 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1900 stack.PushTransform(screenScaleMatrix);
1901 SkMatrix translateMatrix = SkMatrix::Translate(5, 5);
1903 stack.PushTransform(translateMatrix);
1907 SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10);
1908 SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1);
1909 stack.PushClipRRect(rrect);
1911 auto embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(
1912 SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack);
1914 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1915 flutterPlatformViewsController->CompositeWithParams(
1916 2, flutterPlatformViewsController->GetCompositionParams(2));
1921 [flutterView addSubview:childClippingView];
1923 [flutterView setNeedsLayout];
1924 [flutterView layoutIfNeeded];
1926 XCTAssertNotNil(childClippingView.maskView);
1929 - (void)testClipRect {
1930 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1932 flutter::TaskRunners runners(
self.name.UTF8String,
1933 GetDefaultTaskRunner(),
1934 GetDefaultTaskRunner(),
1935 GetDefaultTaskRunner(),
1936 GetDefaultTaskRunner());
1937 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1938 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1939 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1941 mock_delegate.settings_.enable_impeller
1944 flutterPlatformViewsController,
1947 std::make_shared<fml::SyncSwitch>());
1951 flutterPlatformViewsController->RegisterViewFactory(
1952 factory,
@"MockFlutterPlatformView",
1956 flutterPlatformViewsController->OnMethodCall(
1958 methodCallWithMethodName:
@"create"
1959 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1964 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1965 flutterPlatformViewsController->SetFlutterView(flutterView);
1967 flutter::MutatorsStack stack;
1969 SkMatrix screenScaleMatrix =
1970 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1971 stack.PushTransform(screenScaleMatrix);
1973 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
1974 stack.PushClipRect(rect);
1976 auto embeddedViewParams =
1977 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1979 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1980 flutterPlatformViewsController->CompositeWithParams(
1981 2, flutterPlatformViewsController->GetCompositionParams(2));
1986 [flutterView addSubview:childClippingView];
1988 [flutterView setNeedsLayout];
1989 [flutterView layoutIfNeeded];
1991 CGRect insideClipping = CGRectMake(2, 2, 3, 3);
1992 for (
int i = 0; i < 10; i++) {
1993 for (
int j = 0; j < 10; j++) {
1994 CGPoint point = CGPointMake(i, j);
1995 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
1996 if (CGRectContainsPoint(insideClipping, point)) {
1997 XCTAssertEqual(alpha, 255);
1999 XCTAssertEqual(alpha, 0);
2005 - (void)testClipRect_multipleClips {
2006 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2008 flutter::TaskRunners runners(
self.name.UTF8String,
2009 GetDefaultTaskRunner(),
2010 GetDefaultTaskRunner(),
2011 GetDefaultTaskRunner(),
2012 GetDefaultTaskRunner());
2013 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2014 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2015 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2017 mock_delegate.settings_.enable_impeller
2020 flutterPlatformViewsController,
2023 std::make_shared<fml::SyncSwitch>());
2027 flutterPlatformViewsController->RegisterViewFactory(
2028 factory,
@"MockFlutterPlatformView",
2032 flutterPlatformViewsController->OnMethodCall(
2034 methodCallWithMethodName:
@"create"
2035 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2040 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2041 flutterPlatformViewsController->SetFlutterView(flutterView);
2043 flutter::MutatorsStack stack;
2045 SkMatrix screenScaleMatrix =
2046 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2047 stack.PushTransform(screenScaleMatrix);
2049 SkRect rect1 = SkRect::MakeXYWH(2, 2, 3, 3);
2050 stack.PushClipRect(rect1);
2052 SkRect rect2 = SkRect::MakeXYWH(3, 3, 3, 3);
2053 stack.PushClipRect(rect2);
2055 auto embeddedViewParams =
2056 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2058 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2059 flutterPlatformViewsController->CompositeWithParams(
2060 2, flutterPlatformViewsController->GetCompositionParams(2));
2065 [flutterView addSubview:childClippingView];
2067 [flutterView setNeedsLayout];
2068 [flutterView layoutIfNeeded];
2087 CGRect insideClipping = CGRectMake(3, 3, 2, 2);
2088 for (
int i = 0; i < 10; i++) {
2089 for (
int j = 0; j < 10; j++) {
2090 CGPoint point = CGPointMake(i, j);
2091 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2092 if (CGRectContainsPoint(insideClipping, point)) {
2093 XCTAssertEqual(alpha, 255);
2095 XCTAssertEqual(alpha, 0);
2101 - (void)testClipRRect {
2102 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2104 flutter::TaskRunners runners(
self.name.UTF8String,
2105 GetDefaultTaskRunner(),
2106 GetDefaultTaskRunner(),
2107 GetDefaultTaskRunner(),
2108 GetDefaultTaskRunner());
2109 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2110 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2111 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2113 mock_delegate.settings_.enable_impeller
2116 flutterPlatformViewsController,
2119 std::make_shared<fml::SyncSwitch>());
2123 flutterPlatformViewsController->RegisterViewFactory(
2124 factory,
@"MockFlutterPlatformView",
2128 flutterPlatformViewsController->OnMethodCall(
2130 methodCallWithMethodName:
@"create"
2131 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2136 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2137 flutterPlatformViewsController->SetFlutterView(flutterView);
2139 flutter::MutatorsStack stack;
2141 SkMatrix screenScaleMatrix =
2142 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2143 stack.PushTransform(screenScaleMatrix);
2145 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2146 stack.PushClipRRect(rrect);
2148 auto embeddedViewParams =
2149 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2151 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2152 flutterPlatformViewsController->CompositeWithParams(
2153 2, flutterPlatformViewsController->GetCompositionParams(2));
2158 [flutterView addSubview:childClippingView];
2160 [flutterView setNeedsLayout];
2161 [flutterView layoutIfNeeded];
2182 CGRect innerClipping1 = CGRectMake(3, 2, 4, 6);
2183 CGRect innerClipping2 = CGRectMake(2, 3, 6, 4);
2184 CGRect outterClipping = CGRectMake(2, 2, 6, 6);
2185 for (
int i = 0; i < 10; i++) {
2186 for (
int j = 0; j < 10; j++) {
2187 CGPoint point = CGPointMake(i, j);
2188 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2189 if (CGRectContainsPoint(innerClipping1, point) ||
2190 CGRectContainsPoint(innerClipping2, point)) {
2192 XCTAssertEqual(alpha, 255);
2193 }
else if (CGRectContainsPoint(outterClipping, point)) {
2195 XCTAssert(0 < alpha && alpha < 255);
2198 XCTAssertEqual(alpha, 0);
2204 - (void)testClipRRect_multipleClips {
2205 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2207 flutter::TaskRunners runners(
self.name.UTF8String,
2208 GetDefaultTaskRunner(),
2209 GetDefaultTaskRunner(),
2210 GetDefaultTaskRunner(),
2211 GetDefaultTaskRunner());
2212 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2213 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2214 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2216 mock_delegate.settings_.enable_impeller
2219 flutterPlatformViewsController,
2222 std::make_shared<fml::SyncSwitch>());
2226 flutterPlatformViewsController->RegisterViewFactory(
2227 factory,
@"MockFlutterPlatformView",
2231 flutterPlatformViewsController->OnMethodCall(
2233 methodCallWithMethodName:
@"create"
2234 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2239 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2240 flutterPlatformViewsController->SetFlutterView(flutterView);
2242 flutter::MutatorsStack stack;
2244 SkMatrix screenScaleMatrix =
2245 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2246 stack.PushTransform(screenScaleMatrix);
2248 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2249 stack.PushClipRRect(rrect);
2251 SkRect rect = SkRect::MakeXYWH(4, 2, 6, 6);
2252 stack.PushClipRect(rect);
2254 auto embeddedViewParams =
2255 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2257 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2258 flutterPlatformViewsController->CompositeWithParams(
2259 2, flutterPlatformViewsController->GetCompositionParams(2));
2264 [flutterView addSubview:childClippingView];
2266 [flutterView setNeedsLayout];
2267 [flutterView layoutIfNeeded];
2288 CGRect clipping = CGRectMake(4, 2, 4, 6);
2289 for (
int i = 0; i < 10; i++) {
2290 for (
int j = 0; j < 10; j++) {
2291 CGPoint point = CGPointMake(i, j);
2292 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2293 if (i == 7 && (j == 2 || j == 7)) {
2295 XCTAssert(0 < alpha && alpha < 255);
2298 (i == 4 && j >= 2 && j <= 7) ||
2300 (i == 7 && j >= 2 && j <= 7) ||
2302 (j == 2 && i >= 4 && i <= 7) ||
2304 (j == 7 && i >= 4 && i <= 7)) {
2307 XCTAssert(alpha > 127);
2308 }
else if ((i == 3 && j >= 1 && j <= 8) || (i == 8 && j >= 1 && j <= 8) ||
2309 (j == 1 && i >= 3 && i <= 8) || (j == 8 && i >= 3 && i <= 8)) {
2312 XCTAssert(alpha < 127);
2313 }
else if (CGRectContainsPoint(clipping, point)) {
2315 XCTAssertEqual(alpha, 255);
2318 XCTAssertEqual(alpha, 0);
2324 - (void)testClipPath {
2325 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2327 flutter::TaskRunners runners(
self.name.UTF8String,
2328 GetDefaultTaskRunner(),
2329 GetDefaultTaskRunner(),
2330 GetDefaultTaskRunner(),
2331 GetDefaultTaskRunner());
2332 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2333 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2334 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2336 mock_delegate.settings_.enable_impeller
2339 flutterPlatformViewsController,
2342 std::make_shared<fml::SyncSwitch>());
2346 flutterPlatformViewsController->RegisterViewFactory(
2347 factory,
@"MockFlutterPlatformView",
2351 flutterPlatformViewsController->OnMethodCall(
2353 methodCallWithMethodName:
@"create"
2354 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2359 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2360 flutterPlatformViewsController->SetFlutterView(flutterView);
2362 flutter::MutatorsStack stack;
2364 SkMatrix screenScaleMatrix =
2365 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2366 stack.PushTransform(screenScaleMatrix);
2369 path.addRoundRect(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2370 stack.PushClipPath(path);
2372 auto embeddedViewParams =
2373 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2375 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2376 flutterPlatformViewsController->CompositeWithParams(
2377 2, flutterPlatformViewsController->GetCompositionParams(2));
2382 [flutterView addSubview:childClippingView];
2384 [flutterView setNeedsLayout];
2385 [flutterView layoutIfNeeded];
2406 CGRect innerClipping1 = CGRectMake(3, 2, 4, 6);
2407 CGRect innerClipping2 = CGRectMake(2, 3, 6, 4);
2408 CGRect outterClipping = CGRectMake(2, 2, 6, 6);
2409 for (
int i = 0; i < 10; i++) {
2410 for (
int j = 0; j < 10; j++) {
2411 CGPoint point = CGPointMake(i, j);
2412 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2413 if (CGRectContainsPoint(innerClipping1, point) ||
2414 CGRectContainsPoint(innerClipping2, point)) {
2416 XCTAssertEqual(alpha, 255);
2417 }
else if (CGRectContainsPoint(outterClipping, point)) {
2419 XCTAssert(0 < alpha && alpha < 255);
2422 XCTAssertEqual(alpha, 0);
2428 - (void)testClipPath_multipleClips {
2429 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2431 flutter::TaskRunners runners(
self.name.UTF8String,
2432 GetDefaultTaskRunner(),
2433 GetDefaultTaskRunner(),
2434 GetDefaultTaskRunner(),
2435 GetDefaultTaskRunner());
2436 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2437 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2438 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2440 mock_delegate.settings_.enable_impeller
2443 flutterPlatformViewsController,
2446 std::make_shared<fml::SyncSwitch>());
2450 flutterPlatformViewsController->RegisterViewFactory(
2451 factory,
@"MockFlutterPlatformView",
2455 flutterPlatformViewsController->OnMethodCall(
2457 methodCallWithMethodName:
@"create"
2458 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2463 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2464 flutterPlatformViewsController->SetFlutterView(flutterView);
2466 flutter::MutatorsStack stack;
2468 SkMatrix screenScaleMatrix =
2469 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2470 stack.PushTransform(screenScaleMatrix);
2473 path.addRoundRect(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2474 stack.PushClipPath(path);
2476 SkRect rect = SkRect::MakeXYWH(4, 2, 6, 6);
2477 stack.PushClipRect(rect);
2479 auto embeddedViewParams =
2480 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2482 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2483 flutterPlatformViewsController->CompositeWithParams(
2484 2, flutterPlatformViewsController->GetCompositionParams(2));
2489 [flutterView addSubview:childClippingView];
2491 [flutterView setNeedsLayout];
2492 [flutterView layoutIfNeeded];
2513 CGRect clipping = CGRectMake(4, 2, 4, 6);
2514 for (
int i = 0; i < 10; i++) {
2515 for (
int j = 0; j < 10; j++) {
2516 CGPoint point = CGPointMake(i, j);
2517 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2518 if (i == 7 && (j == 2 || j == 7)) {
2520 XCTAssert(0 < alpha && alpha < 255);
2523 (i == 4 && j >= 2 && j <= 7) ||
2525 (i == 7 && j >= 2 && j <= 7) ||
2527 (j == 2 && i >= 4 && i <= 7) ||
2529 (j == 7 && i >= 4 && i <= 7)) {
2532 XCTAssert(alpha > 127);
2533 }
else if ((i == 3 && j >= 1 && j <= 8) || (i == 8 && j >= 1 && j <= 8) ||
2534 (j == 1 && i >= 3 && i <= 8) || (j == 8 && i >= 3 && i <= 8)) {
2537 XCTAssert(alpha < 127);
2538 }
else if (CGRectContainsPoint(clipping, point)) {
2540 XCTAssertEqual(alpha, 255);
2543 XCTAssertEqual(alpha, 0);
2549 - (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents {
2550 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2552 flutter::TaskRunners runners(
self.name.UTF8String,
2553 GetDefaultTaskRunner(),
2554 GetDefaultTaskRunner(),
2555 GetDefaultTaskRunner(),
2556 GetDefaultTaskRunner());
2557 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2558 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2559 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2561 mock_delegate.settings_.enable_impeller
2564 flutterPlatformViewsController,
2567 std::make_shared<fml::SyncSwitch>());
2571 flutterPlatformViewsController->RegisterViewFactory(
2572 factory,
@"MockFlutterPlatformView",
2576 flutterPlatformViewsController->OnMethodCall(
2578 methodCallWithMethodName:
@"create"
2579 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2586 while (touchInteceptorView != nil &&
2588 touchInteceptorView = touchInteceptorView.superview;
2590 XCTAssertNotNil(touchInteceptorView);
2593 UIGestureRecognizer* forwardGectureRecognizer = nil;
2594 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2595 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2596 forwardGectureRecognizer = gestureRecognizer;
2602 NSSet* touches1 = [[NSSet alloc] init];
2603 id event1 = OCMClassMock([UIEvent
class]);
2605 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2606 OCMReject([flutterViewContoller touchesBegan:touches1 withEvent:event1]);
2609 NSSet* touches2 = [[NSSet alloc] init];
2610 id event2 = OCMClassMock([UIEvent
class]);
2611 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller);
2612 [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2];
2613 OCMVerify([flutterViewContoller touchesBegan:touches2 withEvent:event2]);
2616 - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGesturesToBeHandled {
2617 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2619 flutter::TaskRunners runners(
self.name.UTF8String,
2620 GetDefaultTaskRunner(),
2621 GetDefaultTaskRunner(),
2622 GetDefaultTaskRunner(),
2623 GetDefaultTaskRunner());
2624 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2625 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2626 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2628 mock_delegate.settings_.enable_impeller
2631 flutterPlatformViewsController,
2634 std::make_shared<fml::SyncSwitch>());
2638 flutterPlatformViewsController->RegisterViewFactory(
2639 factory,
@"MockFlutterPlatformView",
2643 flutterPlatformViewsController->OnMethodCall(
2645 methodCallWithMethodName:
@"create"
2646 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2653 while (touchInteceptorView != nil &&
2655 touchInteceptorView = touchInteceptorView.superview;
2657 XCTAssertNotNil(touchInteceptorView);
2660 UIGestureRecognizer* forwardGectureRecognizer = nil;
2661 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2662 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2663 forwardGectureRecognizer = gestureRecognizer;
2670 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller);
2672 NSSet* touches1 = [[NSSet alloc] init];
2673 id event1 = OCMClassMock([UIEvent
class]);
2674 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2675 OCMVerify([flutterViewContoller touchesBegan:touches1 withEvent:event1]);
2677 flutterPlatformViewsController->SetFlutterViewController(nil);
2680 NSSet* touches2 = [[NSSet alloc] init];
2681 id event2 = OCMClassMock([UIEvent
class]);
2682 [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2];
2683 OCMVerify([flutterViewContoller touchesMoved:touches2 withEvent:event2]);
2685 NSSet* touches3 = [[NSSet alloc] init];
2686 id event3 = OCMClassMock([UIEvent
class]);
2687 [forwardGectureRecognizer touchesEnded:touches3 withEvent:event3];
2688 OCMVerify([flutterViewContoller touchesEnded:touches3 withEvent:event3]);
2691 NSSet* touches4 = [[NSSet alloc] init];
2692 id event4 = OCMClassMock([UIEvent
class]);
2693 [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4];
2694 OCMReject([flutterViewContoller touchesBegan:touches4 withEvent:event4]);
2696 NSSet* touches5 = [[NSSet alloc] init];
2697 id event5 = OCMClassMock([UIEvent
class]);
2698 [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5];
2699 OCMReject([flutterViewContoller touchesEnded:touches5 withEvent:event5]);
2704 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller);
2706 NSSet* touches1 = [[NSSet alloc] init];
2707 id event1 = OCMClassMock([UIEvent
class]);
2708 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2709 OCMVerify([flutterViewContoller touchesBegan:touches1 withEvent:event1]);
2711 flutterPlatformViewsController->SetFlutterViewController(nil);
2714 NSSet* touches2 = [[NSSet alloc] init];
2715 id event2 = OCMClassMock([UIEvent
class]);
2716 [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2];
2717 OCMVerify([flutterViewContoller touchesMoved:touches2 withEvent:event2]);
2719 NSSet* touches3 = [[NSSet alloc] init];
2720 id event3 = OCMClassMock([UIEvent
class]);
2721 [forwardGectureRecognizer touchesCancelled:touches3 withEvent:event3];
2722 OCMVerify([flutterViewContoller forceTouchesCancelled:touches3]);
2725 NSSet* touches4 = [[NSSet alloc] init];
2726 id event4 = OCMClassMock([UIEvent
class]);
2727 [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4];
2728 OCMReject([flutterViewContoller touchesBegan:touches4 withEvent:event4]);
2730 NSSet* touches5 = [[NSSet alloc] init];
2731 id event5 = OCMClassMock([UIEvent
class]);
2732 [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5];
2733 OCMReject([flutterViewContoller touchesEnded:touches5 withEvent:event5]);
2736 flutterPlatformViewsController->Reset();
2740 testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence {
2741 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2743 flutter::TaskRunners runners(
self.name.UTF8String,
2744 GetDefaultTaskRunner(),
2745 GetDefaultTaskRunner(),
2746 GetDefaultTaskRunner(),
2747 GetDefaultTaskRunner());
2748 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2749 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2750 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2752 mock_delegate.settings_.enable_impeller
2755 flutterPlatformViewsController,
2758 std::make_shared<fml::SyncSwitch>());
2762 flutterPlatformViewsController->RegisterViewFactory(
2763 factory,
@"MockFlutterPlatformView",
2767 flutterPlatformViewsController->OnMethodCall(
2769 methodCallWithMethodName:
@"create"
2770 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2777 while (touchInteceptorView != nil &&
2779 touchInteceptorView = touchInteceptorView.superview;
2781 XCTAssertNotNil(touchInteceptorView);
2784 UIGestureRecognizer* forwardGectureRecognizer = nil;
2785 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2786 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2787 forwardGectureRecognizer = gestureRecognizer;
2793 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller);
2796 NSSet* touches1 = [NSSet setWithObject:@1];
2797 id event1 = OCMClassMock([UIEvent
class]);
2798 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2799 OCMVerify([flutterViewContoller touchesBegan:touches1 withEvent:event1]);
2802 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller2);
2806 NSSet* touches2 = [NSSet setWithObject:@1];
2807 id event2 = OCMClassMock([UIEvent
class]);
2808 [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2];
2809 OCMVerify([flutterViewContoller touchesBegan:touches2 withEvent:event2]);
2810 OCMReject([flutterViewContoller2 touchesBegan:touches2 withEvent:event2]);
2812 NSSet* touches3 = [NSSet setWithObject:@1];
2813 id event3 = OCMClassMock([UIEvent
class]);
2814 [forwardGectureRecognizer touchesMoved:touches3 withEvent:event3];
2815 OCMVerify([flutterViewContoller touchesMoved:touches3 withEvent:event3]);
2816 OCMReject([flutterViewContoller2 touchesMoved:touches3 withEvent:event3]);
2818 NSSet* touches4 = [NSSet setWithObject:@1];
2819 id event4 = OCMClassMock([UIEvent
class]);
2820 [forwardGectureRecognizer touchesEnded:touches4 withEvent:event4];
2821 OCMVerify([flutterViewContoller touchesEnded:touches4 withEvent:event4]);
2822 OCMReject([flutterViewContoller2 touchesEnded:touches4 withEvent:event4]);
2824 NSSet* touches5 = [NSSet setWithObject:@1];
2825 id event5 = OCMClassMock([UIEvent
class]);
2826 [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5];
2827 OCMVerify([flutterViewContoller touchesEnded:touches5 withEvent:event5]);
2828 OCMReject([flutterViewContoller2 touchesEnded:touches5 withEvent:event5]);
2832 NSSet* touches6 = [NSSet setWithObject:@1];
2833 id event6 = OCMClassMock([UIEvent
class]);
2834 [forwardGectureRecognizer touchesBegan:touches6 withEvent:event6];
2835 OCMVerify([flutterViewContoller2 touchesBegan:touches6 withEvent:event6]);
2836 OCMReject([flutterViewContoller touchesBegan:touches6 withEvent:event6]);
2839 NSSet* touches7 = [NSSet setWithObject:@1];
2840 id event7 = OCMClassMock([UIEvent
class]);
2841 [forwardGectureRecognizer touchesMoved:touches7 withEvent:event7];
2842 OCMVerify([flutterViewContoller2 touchesMoved:touches7 withEvent:event7]);
2843 OCMReject([flutterViewContoller touchesMoved:touches7 withEvent:event7]);
2845 NSSet* touches8 = [NSSet setWithObject:@1];
2846 id event8 = OCMClassMock([UIEvent
class]);
2847 [forwardGectureRecognizer touchesEnded:touches8 withEvent:event8];
2848 OCMVerify([flutterViewContoller2 touchesEnded:touches8 withEvent:event8]);
2849 OCMReject([flutterViewContoller touchesEnded:touches8 withEvent:event8]);
2851 flutterPlatformViewsController->Reset();
2854 - (void)testFlutterPlatformViewTouchesCancelledEventAreForcedToBeCancelled {
2855 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2857 flutter::TaskRunners runners(
self.name.UTF8String,
2858 GetDefaultTaskRunner(),
2859 GetDefaultTaskRunner(),
2860 GetDefaultTaskRunner(),
2861 GetDefaultTaskRunner());
2862 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2863 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2864 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2866 mock_delegate.settings_.enable_impeller
2869 flutterPlatformViewsController,
2872 std::make_shared<fml::SyncSwitch>());
2876 flutterPlatformViewsController->RegisterViewFactory(
2877 factory,
@"MockFlutterPlatformView",
2881 flutterPlatformViewsController->OnMethodCall(
2883 methodCallWithMethodName:
@"create"
2884 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2891 while (touchInteceptorView != nil &&
2893 touchInteceptorView = touchInteceptorView.superview;
2895 XCTAssertNotNil(touchInteceptorView);
2898 UIGestureRecognizer* forwardGectureRecognizer = nil;
2899 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2900 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2901 forwardGectureRecognizer = gestureRecognizer;
2907 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller);
2909 NSSet* touches1 = [NSSet setWithObject:@1];
2910 id event1 = OCMClassMock([UIEvent
class]);
2911 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2913 [forwardGectureRecognizer touchesCancelled:touches1 withEvent:event1];
2914 OCMVerify([flutterViewContoller forceTouchesCancelled:touches1]);
2916 flutterPlatformViewsController->Reset();
2920 testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldRemoveAndAddBackDelayingRecognizerForWebView {
2921 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2923 flutter::TaskRunners runners(
self.name.UTF8String,
2924 GetDefaultTaskRunner(),
2925 GetDefaultTaskRunner(),
2926 GetDefaultTaskRunner(),
2927 GetDefaultTaskRunner());
2928 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2929 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2930 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2932 mock_delegate.settings_.enable_impeller
2935 flutterPlatformViewsController,
2938 std::make_shared<fml::SyncSwitch>());
2942 flutterPlatformViewsController->RegisterViewFactory(
2946 flutterPlatformViewsController->OnMethodCall(
2948 arguments:@{
@"id" : @2,
@"viewType" :
@"MockWebView"}],
2955 while (touchInteceptorView != nil &&
2957 touchInteceptorView = touchInteceptorView.superview;
2959 XCTAssertNotNil(touchInteceptorView);
2961 XCTAssert(touchInteceptorView.gestureRecognizers.count == 2);
2962 UIGestureRecognizer* delayingRecognizer = touchInteceptorView.gestureRecognizers[0];
2963 UIGestureRecognizer* forwardingRecognizer = touchInteceptorView.gestureRecognizers[1];
2970 if (@available(iOS 18.2, *)) {
2972 XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], forwardingRecognizer);
2973 XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], delayingRecognizer);
2975 XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], delayingRecognizer);
2976 XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], forwardingRecognizer);
2981 testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldRemoveAndAddBackDelayingRecognizerForWrapperWebView {
2982 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2984 flutter::TaskRunners runners(
self.name.UTF8String,
2985 GetDefaultTaskRunner(),
2986 GetDefaultTaskRunner(),
2987 GetDefaultTaskRunner(),
2988 GetDefaultTaskRunner());
2989 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2990 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2991 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2993 mock_delegate.settings_.enable_impeller
2996 flutterPlatformViewsController,
2999 std::make_shared<fml::SyncSwitch>());
3003 flutterPlatformViewsController->RegisterViewFactory(
3007 flutterPlatformViewsController->OnMethodCall(
3009 methodCallWithMethodName:
@"create"
3010 arguments:@{
@"id" : @2,
@"viewType" :
@"MockWrapperWebView"}],
3017 while (touchInteceptorView != nil &&
3019 touchInteceptorView = touchInteceptorView.superview;
3021 XCTAssertNotNil(touchInteceptorView);
3023 XCTAssert(touchInteceptorView.gestureRecognizers.count == 2);
3024 UIGestureRecognizer* delayingRecognizer = touchInteceptorView.gestureRecognizers[0];
3025 UIGestureRecognizer* forwardingRecognizer = touchInteceptorView.gestureRecognizers[1];
3032 if (@available(iOS 18.2, *)) {
3034 XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], forwardingRecognizer);
3035 XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], delayingRecognizer);
3037 XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], delayingRecognizer);
3038 XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], forwardingRecognizer);
3043 testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldNotRemoveAndAddBackDelayingRecognizerForNestedWrapperWebView {
3044 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3046 flutter::TaskRunners runners(
self.name.UTF8String,
3047 GetDefaultTaskRunner(),
3048 GetDefaultTaskRunner(),
3049 GetDefaultTaskRunner(),
3050 GetDefaultTaskRunner());
3051 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3052 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3053 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3055 mock_delegate.settings_.enable_impeller
3058 flutterPlatformViewsController,
3061 std::make_shared<fml::SyncSwitch>());
3065 flutterPlatformViewsController->RegisterViewFactory(
3066 factory,
@"MockNestedWrapperWebView",
3070 flutterPlatformViewsController->OnMethodCall(
3072 methodCallWithMethodName:
@"create"
3073 arguments:@{
@"id" : @2,
@"viewType" :
@"MockNestedWrapperWebView"}],
3080 while (touchInteceptorView != nil &&
3082 touchInteceptorView = touchInteceptorView.superview;
3084 XCTAssertNotNil(touchInteceptorView);
3086 XCTAssert(touchInteceptorView.gestureRecognizers.count == 2);
3087 UIGestureRecognizer* delayingRecognizer = touchInteceptorView.gestureRecognizers[0];
3088 UIGestureRecognizer* forwardingRecognizer = touchInteceptorView.gestureRecognizers[1];
3095 XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], delayingRecognizer);
3096 XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], forwardingRecognizer);
3100 testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldNotRemoveAndAddBackDelayingRecognizerForNonWebView {
3101 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3103 flutter::TaskRunners runners(
self.name.UTF8String,
3104 GetDefaultTaskRunner(),
3105 GetDefaultTaskRunner(),
3106 GetDefaultTaskRunner(),
3107 GetDefaultTaskRunner());
3108 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3109 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3110 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3112 mock_delegate.settings_.enable_impeller
3115 flutterPlatformViewsController,
3118 std::make_shared<fml::SyncSwitch>());
3122 flutterPlatformViewsController->RegisterViewFactory(
3123 factory,
@"MockFlutterPlatformView",
3127 flutterPlatformViewsController->OnMethodCall(
3129 methodCallWithMethodName:
@"create"
3130 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3137 while (touchInteceptorView != nil &&
3139 touchInteceptorView = touchInteceptorView.superview;
3141 XCTAssertNotNil(touchInteceptorView);
3143 XCTAssert(touchInteceptorView.gestureRecognizers.count == 2);
3144 UIGestureRecognizer* delayingRecognizer = touchInteceptorView.gestureRecognizers[0];
3145 UIGestureRecognizer* forwardingRecognizer = touchInteceptorView.gestureRecognizers[1];
3152 XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], delayingRecognizer);
3153 XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], forwardingRecognizer);
3156 - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashing {
3157 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3159 flutter::TaskRunners runners(
self.name.UTF8String,
3160 GetDefaultTaskRunner(),
3161 GetDefaultTaskRunner(),
3162 GetDefaultTaskRunner(),
3163 GetDefaultTaskRunner());
3164 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3165 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3166 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3168 mock_delegate.settings_.enable_impeller
3171 flutterPlatformViewsController,
3174 std::make_shared<fml::SyncSwitch>());
3178 flutterPlatformViewsController->RegisterViewFactory(
3179 factory,
@"MockFlutterPlatformView",
3183 flutterPlatformViewsController->OnMethodCall(
3185 methodCallWithMethodName:
@"create"
3186 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3192 flutter::MutatorsStack stack;
3193 SkMatrix finalMatrix;
3195 auto embeddedViewParams_1 =
3196 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3198 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_1));
3199 flutterPlatformViewsController->CompositeWithParams(
3200 2, flutterPlatformViewsController->GetCompositionParams(2));
3202 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3203 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3204 nullptr, framebuffer_info,
3205 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return false; },
3206 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3207 SkISize::Make(800, 600));
3209 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3211 auto embeddedViewParams_2 =
3212 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3213 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_2));
3214 flutterPlatformViewsController->CompositeWithParams(
3215 2, flutterPlatformViewsController->GetCompositionParams(2));
3217 auto mock_surface_submit_true = std::make_unique<flutter::SurfaceFrame>(
3218 nullptr, framebuffer_info,
3219 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3220 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3221 SkISize::Make(800, 600));
3222 XCTAssertTrue(flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr,
3223 std::move(mock_surface_submit_true)));
3227 testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView {
3228 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3230 flutter::TaskRunners runners(
self.name.UTF8String,
3231 GetDefaultTaskRunner(),
3232 GetDefaultTaskRunner(),
3233 GetDefaultTaskRunner(),
3234 GetDefaultTaskRunner());
3235 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3236 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3237 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3239 mock_delegate.settings_.enable_impeller
3242 flutterPlatformViewsController,
3245 std::make_shared<fml::SyncSwitch>());
3247 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3248 flutterPlatformViewsController->SetFlutterView(flutterView);
3252 flutterPlatformViewsController->RegisterViewFactory(
3253 factory,
@"MockFlutterPlatformView",
3259 flutterPlatformViewsController->OnMethodCall(
3261 methodCallWithMethodName:
@"create"
3262 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3265 flutter::MutatorsStack stack;
3266 SkMatrix finalMatrix;
3267 auto embeddedViewParams =
3268 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3269 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
3275 flutterPlatformViewsController->Reset();
3280 - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
3281 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3283 flutter::TaskRunners runners(
self.name.UTF8String,
3284 GetDefaultTaskRunner(),
3285 GetDefaultTaskRunner(),
3286 GetDefaultTaskRunner(),
3287 GetDefaultTaskRunner());
3288 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3289 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3290 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3292 mock_delegate.settings_.enable_impeller
3295 flutterPlatformViewsController,
3298 std::make_shared<fml::SyncSwitch>());
3300 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3301 flutterPlatformViewsController->SetFlutterView(flutterView);
3305 flutterPlatformViewsController->RegisterViewFactory(
3306 factory,
@"MockFlutterPlatformView",
3311 flutterPlatformViewsController->OnMethodCall(
3313 methodCallWithMethodName:
@"create"
3314 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
3318 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3319 flutter::MutatorsStack stack;
3320 SkMatrix finalMatrix;
3321 auto embeddedViewParams1 =
3322 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3323 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3324 flutterPlatformViewsController->CompositeWithParams(
3325 0, flutterPlatformViewsController->GetCompositionParams(0));
3327 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL);
3330 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3331 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 0UL);
3333 auto embeddedViewParams2 =
3334 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3335 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams2));
3336 flutterPlatformViewsController->CompositeWithParams(
3337 0, flutterPlatformViewsController->GetCompositionParams(0));
3339 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL);
3343 testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy {
3344 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3346 flutter::TaskRunners runners(
self.name.UTF8String,
3347 GetDefaultTaskRunner(),
3348 GetDefaultTaskRunner(),
3349 GetDefaultTaskRunner(),
3350 GetDefaultTaskRunner());
3351 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3352 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3353 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3355 mock_delegate.settings_.enable_impeller
3358 flutterPlatformViewsController,
3361 std::make_shared<fml::SyncSwitch>());
3363 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3364 flutterPlatformViewsController->SetFlutterView(flutterView);
3368 flutterPlatformViewsController->RegisterViewFactory(
3369 factory,
@"MockFlutterPlatformView",
3373 flutterPlatformViewsController->OnMethodCall(
3375 methodCallWithMethodName:
@"create"
3376 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
3381 flutterPlatformViewsController->OnMethodCall(
3383 methodCallWithMethodName:
@"create"
3384 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3388 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3389 flutter::MutatorsStack stack;
3390 SkMatrix finalMatrix;
3391 auto embeddedViewParams1 =
3392 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3393 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3395 auto embeddedViewParams2 =
3396 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
3397 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
3400 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3401 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3402 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3403 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3404 std::move(mock_sk_surface), framebuffer_info,
3405 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3406 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3407 SkISize::Make(800, 600));
3410 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3413 UIView* clippingView1 = view1.superview.superview;
3414 UIView* clippingView2 = view2.superview.superview;
3415 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
3416 [flutterView.subviews indexOfObject:clippingView2],
3417 @"The first clipping view should be added before the second clipping view.");
3420 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3422 embeddedViewParams2 =
3423 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
3424 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
3426 embeddedViewParams1 =
3427 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3428 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3430 mock_sk_surface = SkSurfaces::Raster(image_info);
3431 mock_surface = std::make_unique<flutter::SurfaceFrame>(
3432 std::move(mock_sk_surface), framebuffer_info,
3433 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3434 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3435 SkISize::Make(800, 600));
3437 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3439 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] >
3440 [flutterView.subviews indexOfObject:clippingView2],
3441 @"The first clipping view should be added after the second clipping view.");
3445 testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy {
3446 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3448 flutter::TaskRunners runners(
self.name.UTF8String,
3449 GetDefaultTaskRunner(),
3450 GetDefaultTaskRunner(),
3451 GetDefaultTaskRunner(),
3452 GetDefaultTaskRunner());
3453 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3454 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3455 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3457 mock_delegate.settings_.enable_impeller
3460 flutterPlatformViewsController,
3463 std::make_shared<fml::SyncSwitch>());
3465 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3466 flutterPlatformViewsController->SetFlutterView(flutterView);
3470 flutterPlatformViewsController->RegisterViewFactory(
3471 factory,
@"MockFlutterPlatformView",
3475 flutterPlatformViewsController->OnMethodCall(
3477 methodCallWithMethodName:
@"create"
3478 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
3483 flutterPlatformViewsController->OnMethodCall(
3485 methodCallWithMethodName:
@"create"
3486 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3490 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3491 flutter::MutatorsStack stack;
3492 SkMatrix finalMatrix;
3493 auto embeddedViewParams1 =
3494 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3495 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3497 auto embeddedViewParams2 =
3498 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
3499 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
3502 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3503 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3504 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3505 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3506 std::move(mock_sk_surface), framebuffer_info,
3507 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3508 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3509 SkISize::Make(800, 600));
3512 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3515 UIView* clippingView1 = view1.superview.superview;
3516 UIView* clippingView2 = view2.superview.superview;
3517 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
3518 [flutterView.subviews indexOfObject:clippingView2],
3519 @"The first clipping view should be added before the second clipping view.");
3522 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3524 embeddedViewParams1 =
3525 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3526 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3528 embeddedViewParams2 =
3529 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
3530 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
3532 mock_sk_surface = SkSurfaces::Raster(image_info);
3533 mock_surface = std::make_unique<flutter::SurfaceFrame>(
3534 std::move(mock_sk_surface), framebuffer_info,
3535 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3536 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3537 SkISize::Make(800, 600));
3539 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3541 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
3542 [flutterView.subviews indexOfObject:clippingView2],
3543 @"The first clipping view should be added before the second clipping view.");
3546 - (int)alphaOfPoint:(CGPoint)point onView:(UIView*)view {
3547 unsigned char pixel[4] = {0};
3549 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
3552 CGContextRef context = CGBitmapContextCreate(
3553 pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast);
3554 CGContextTranslateCTM(context, -point.x, -point.y);
3555 [view.layer renderInContext:context];
3557 CGContextRelease(context);
3558 CGColorSpaceRelease(colorSpace);
3563 - (void)testHasFirstResponderInViewHierarchySubtree_viewItselfBecomesFirstResponder {
3565 UIWindow* window = [[UIWindow alloc] init];
3566 UITextField* textField = [[UITextField alloc] init];
3567 [window addSubview:textField];
3569 [textField becomeFirstResponder];
3570 XCTAssertTrue(textField.isFirstResponder);
3571 XCTAssertTrue(textField.flt_hasFirstResponderInViewHierarchySubtree);
3572 [textField resignFirstResponder];
3573 XCTAssertFalse(textField.isFirstResponder);
3574 XCTAssertFalse(textField.flt_hasFirstResponderInViewHierarchySubtree);
3577 - (void)testHasFirstResponderInViewHierarchySubtree_descendantViewBecomesFirstResponder {
3579 UIWindow* window = [[UIWindow alloc] init];
3580 UIView* view = [[UIView alloc] init];
3581 UIView* childView = [[UIView alloc] init];
3582 UITextField* textField = [[UITextField alloc] init];
3583 [window addSubview:view];
3584 [view addSubview:childView];
3585 [childView addSubview:textField];
3587 [textField becomeFirstResponder];
3588 XCTAssertTrue(textField.isFirstResponder);
3589 XCTAssertTrue(view.flt_hasFirstResponderInViewHierarchySubtree);
3590 [textField resignFirstResponder];
3591 XCTAssertFalse(textField.isFirstResponder);
3592 XCTAssertFalse(view.flt_hasFirstResponderInViewHierarchySubtree);
3595 - (void)testFlutterClippingMaskViewPoolReuseViewsAfterRecycle {
3601 CGRect newRect = CGRectMake(0, 0, 10, 10);
3605 NSSet* set1 = [NSSet setWithObjects:view1, view2, nil];
3606 NSSet* set2 = [NSSet setWithObjects:view3, view4, nil];
3607 XCTAssertEqualObjects(set1, set2);
3608 XCTAssertTrue(CGRectEqualToRect(view3.frame, newRect));
3609 XCTAssertTrue(CGRectEqualToRect(view4.frame, newRect));
3612 - (void)testFlutterClippingMaskViewPoolAllocsNewMaskViewsAfterReachingCapacity {
3617 XCTAssertNotEqual(view1, view3);
3618 XCTAssertNotEqual(view2, view3);
3621 - (void)testMaskViewsReleasedWhenPoolIsReleased {
3622 __weak UIView* weakView;
3627 XCTAssertNotNil(weakView);
3629 XCTAssertNil(weakView);
3632 - (void)testClipMaskViewIsReused {
3633 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3635 flutter::TaskRunners runners(
self.name.UTF8String,
3636 GetDefaultTaskRunner(),
3637 GetDefaultTaskRunner(),
3638 GetDefaultTaskRunner(),
3639 GetDefaultTaskRunner());
3640 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3641 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3642 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3644 mock_delegate.settings_.enable_impeller
3647 flutterPlatformViewsController,
3650 std::make_shared<fml::SyncSwitch>());
3654 flutterPlatformViewsController->RegisterViewFactory(
3655 factory,
@"MockFlutterPlatformView",
3659 flutterPlatformViewsController->OnMethodCall(
3661 methodCallWithMethodName:
@"create"
3662 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3666 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
3667 flutterPlatformViewsController->SetFlutterView(flutterView);
3669 flutter::MutatorsStack stack1;
3671 SkMatrix screenScaleMatrix =
3672 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3673 stack1.PushTransform(screenScaleMatrix);
3675 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
3676 stack1.PushClipRect(rect);
3678 auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
3679 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3681 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3682 flutterPlatformViewsController->CompositeWithParams(
3683 1, flutterPlatformViewsController->GetCompositionParams(1));
3686 UIView* maskView1 = childClippingView1.maskView;
3687 XCTAssertNotNil(maskView1);
3690 flutterPlatformViewsController->BeginFrame(SkISize::Make(100, 100));
3691 flutter::MutatorsStack stack2;
3692 auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
3693 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3694 auto embeddedViewParams3 = std::make_unique<flutter::EmbeddedViewParams>(
3695 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3696 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams3));
3697 flutterPlatformViewsController->CompositeWithParams(
3698 1, flutterPlatformViewsController->GetCompositionParams(1));
3703 flutterPlatformViewsController->OnMethodCall(
3705 methodCallWithMethodName:
@"create"
3706 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3709 auto embeddedViewParams4 = std::make_unique<flutter::EmbeddedViewParams>(
3710 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3711 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams4));
3712 flutterPlatformViewsController->CompositeWithParams(
3713 2, flutterPlatformViewsController->GetCompositionParams(2));
3717 UIView* maskView2 = childClippingView2.maskView;
3718 XCTAssertEqual(maskView1, maskView2);
3719 XCTAssertNotNil(childClippingView2.maskView);
3720 XCTAssertNil(childClippingView1.maskView);
3723 - (void)testDifferentClipMaskViewIsUsedForEachView {
3724 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3726 flutter::TaskRunners runners(
self.name.UTF8String,
3727 GetDefaultTaskRunner(),
3728 GetDefaultTaskRunner(),
3729 GetDefaultTaskRunner(),
3730 GetDefaultTaskRunner());
3731 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3732 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3733 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3735 mock_delegate.settings_.enable_impeller
3738 flutterPlatformViewsController,
3741 std::make_shared<fml::SyncSwitch>());
3745 flutterPlatformViewsController->RegisterViewFactory(
3746 factory,
@"MockFlutterPlatformView",
3751 flutterPlatformViewsController->OnMethodCall(
3753 methodCallWithMethodName:
@"create"
3754 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3759 flutterPlatformViewsController->OnMethodCall(
3761 methodCallWithMethodName:
@"create"
3762 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3767 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
3768 flutterPlatformViewsController->SetFlutterView(flutterView);
3770 flutter::MutatorsStack stack1;
3772 SkMatrix screenScaleMatrix =
3773 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3774 stack1.PushTransform(screenScaleMatrix);
3776 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
3777 stack1.PushClipRect(rect);
3779 auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
3780 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3782 flutter::MutatorsStack stack2;
3783 stack2.PushClipRect(rect);
3784 auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
3785 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3787 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3788 flutterPlatformViewsController->CompositeWithParams(
3789 1, flutterPlatformViewsController->GetCompositionParams(1));
3791 UIView* childClippingView1 = view1.superview.superview;
3793 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2));
3794 flutterPlatformViewsController->CompositeWithParams(
3795 2, flutterPlatformViewsController->GetCompositionParams(2));
3797 UIView* childClippingView2 = view2.superview.superview;
3798 UIView* maskView1 = childClippingView1.maskView;
3799 UIView* maskView2 = childClippingView2.maskView;
3800 XCTAssertNotEqual(maskView1, maskView2);
3803 - (void)testMaskViewUsesCAShapeLayerAsTheBackingLayer {
3804 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3806 flutter::TaskRunners runners(
self.name.UTF8String,
3807 GetDefaultTaskRunner(),
3808 GetDefaultTaskRunner(),
3809 GetDefaultTaskRunner(),
3810 GetDefaultTaskRunner());
3811 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3812 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3813 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3815 mock_delegate.settings_.enable_impeller
3818 flutterPlatformViewsController,
3821 std::make_shared<fml::SyncSwitch>());
3825 flutterPlatformViewsController->RegisterViewFactory(
3826 factory,
@"MockFlutterPlatformView",
3831 flutterPlatformViewsController->OnMethodCall(
3833 methodCallWithMethodName:
@"create"
3834 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3838 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
3839 flutterPlatformViewsController->SetFlutterView(flutterView);
3841 flutter::MutatorsStack stack1;
3843 SkMatrix screenScaleMatrix =
3844 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3845 stack1.PushTransform(screenScaleMatrix);
3847 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
3848 stack1.PushClipRect(rect);
3850 auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
3851 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3853 flutter::MutatorsStack stack2;
3854 stack2.PushClipRect(rect);
3855 auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
3856 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3858 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3859 flutterPlatformViewsController->CompositeWithParams(
3860 1, flutterPlatformViewsController->GetCompositionParams(1));
3864 UIView* maskView = childClippingView.maskView;
3865 XCTAssert([maskView.layer isKindOfClass:[CAShapeLayer
class]],
3866 @"Mask view must use CAShapeLayer as its backing layer.");
3874 - (BOOL)validateOneVisualEffectView:(UIView*)visualEffectView
3875 expectedFrame:(CGRect)frame
3876 inputRadius:(CGFloat)inputRadius {
3877 XCTAssertTrue(CGRectEqualToRect(visualEffectView.frame, frame));
3878 for (UIView* view in visualEffectView.subviews) {
3879 if (![NSStringFromClass([view
class]) hasSuffix:
@"BackdropView"]) {
3882 XCTAssertEqual(view.layer.filters.count, 1u);
3883 NSObject* filter = view.layer.filters.firstObject;
3885 XCTAssertEqualObjects([filter valueForKey:
@"name"],
@"gaussianBlur");
3887 NSObject* inputRadiusInFilter = [filter valueForKey:@"inputRadius"];
3888 XCTAssertTrue([inputRadiusInFilter isKindOfClass:[NSNumber
class]] &&
3889 flutter::BlurRadiusEqualToBlurRadius(((NSNumber*)inputRadiusInFilter).floatValue,
3896 - (void)testDisposingViewInCompositionOrderDoNotCrash {
3897 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3899 flutter::TaskRunners runners(
self.name.UTF8String,
3900 GetDefaultTaskRunner(),
3901 GetDefaultTaskRunner(),
3902 GetDefaultTaskRunner(),
3903 GetDefaultTaskRunner());
3904 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3905 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3906 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3908 mock_delegate.settings_.enable_impeller
3911 flutterPlatformViewsController,
3914 std::make_shared<fml::SyncSwitch>());
3916 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3917 flutterPlatformViewsController->SetFlutterView(flutterView);
3921 flutterPlatformViewsController->RegisterViewFactory(
3922 factory,
@"MockFlutterPlatformView",
3927 flutterPlatformViewsController->OnMethodCall(
3929 methodCallWithMethodName:
@"create"
3930 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
3932 flutterPlatformViewsController->OnMethodCall(
3934 methodCallWithMethodName:
@"create"
3935 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3941 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3942 flutter::MutatorsStack stack;
3943 SkMatrix finalMatrix;
3944 auto embeddedViewParams0 =
3945 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3946 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams0));
3948 auto embeddedViewParams1 =
3949 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3950 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3952 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL);
3954 XCTestExpectation* expectation = [
self expectationWithDescription:@"dispose call ended."];
3956 [expectation fulfill];
3959 flutterPlatformViewsController->OnMethodCall(
3960 [
FlutterMethodCall methodCallWithMethodName:
@"dispose" arguments:@0], disposeResult);
3961 [
self waitForExpectationsWithTimeout:30 handler:nil];
3963 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3964 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3965 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3966 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3967 std::move(mock_sk_surface), framebuffer_info,
3968 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3969 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3970 SkISize::Make(800, 600));
3972 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3975 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL);
3976 XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(0));
3977 XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1));
3983 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3984 flutter::MutatorsStack stack;
3985 SkMatrix finalMatrix;
3986 auto embeddedViewParams1 =
3987 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3988 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3990 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3991 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3992 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3993 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3994 std::move(mock_sk_surface), framebuffer_info,
3995 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3996 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3997 SkISize::Make(800, 600));
3999 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
4002 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL);
4003 XCTAssertNil(flutterPlatformViewsController->GetPlatformViewByID(0));
4004 XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1));
4007 - (void)testOnlyPlatformViewsAreRemovedWhenReset {
4008 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
4010 flutter::TaskRunners runners(
self.name.UTF8String,
4011 GetDefaultTaskRunner(),
4012 GetDefaultTaskRunner(),
4013 GetDefaultTaskRunner(),
4014 GetDefaultTaskRunner());
4015 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
4016 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
4017 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
4019 mock_delegate.settings_.enable_impeller
4022 flutterPlatformViewsController,
4025 std::make_shared<fml::SyncSwitch>());
4029 flutterPlatformViewsController->RegisterViewFactory(
4030 factory,
@"MockFlutterPlatformView",
4034 flutterPlatformViewsController->OnMethodCall(
4036 methodCallWithMethodName:
@"create"
4037 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
4039 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
4040 flutterPlatformViewsController->SetFlutterView(flutterView);
4042 flutter::MutatorsStack stack;
4044 SkMatrix screenScaleMatrix =
4045 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
4046 stack.PushTransform(screenScaleMatrix);
4048 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
4049 stack.PushTransform(translateMatrix);
4050 SkMatrix finalMatrix;
4051 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
4053 auto embeddedViewParams =
4054 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
4056 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
4059 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
4060 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
4061 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
4062 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
4063 std::move(mock_sk_surface), framebuffer_info,
4064 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
4065 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
4066 SkISize::Make(800, 600));
4068 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface));
4070 UIView* someView = [[UIView alloc] init];
4071 [flutterView addSubview:someView];
4073 flutterPlatformViewsController->Reset();
4074 XCTAssertEqual(flutterView.subviews.count, 1u);
4075 XCTAssertEqual(flutterView.subviews.firstObject, someView);
4078 - (void)testNilPlatformViewDoesntCrash {
4079 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
4081 flutter::TaskRunners runners(
self.name.UTF8String,
4082 GetDefaultTaskRunner(),
4083 GetDefaultTaskRunner(),
4084 GetDefaultTaskRunner(),
4085 GetDefaultTaskRunner());
4086 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
4087 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
4088 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
4090 mock_delegate.settings_.enable_impeller
4093 flutterPlatformViewsController,
4096 std::make_shared<fml::SyncSwitch>());
4100 flutterPlatformViewsController->RegisterViewFactory(
4101 factory,
@"MockFlutterPlatformView",
4105 flutterPlatformViewsController->OnMethodCall(
4107 methodCallWithMethodName:
@"create"
4108 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
4110 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
4111 flutterPlatformViewsController->SetFlutterView(flutterView);
4114 flutter::MutatorsStack stack;
4116 SkMatrix screenScaleMatrix =
4117 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
4118 stack.PushTransform(screenScaleMatrix);
4120 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
4121 stack.PushTransform(translateMatrix);
4122 SkMatrix finalMatrix;
4123 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
4125 auto embeddedViewParams =
4126 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
4128 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
4131 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
4132 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
4133 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
4134 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
4135 std::move(mock_sk_surface), framebuffer_info,
4136 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
4137 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
4138 SkISize::Make(800, 600));
4140 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface));
4142 XCTAssertEqual(flutterView.subviews.count, 1u);
4145 - (void)testFlutterTouchInterceptingViewLinksToAccessibilityContainer {
4147 NSObject* container = [[NSObject alloc] init];
4148 [touchInteceptorView setFlutterAccessibilityContainer:container];
4149 XCTAssertEqualObjects([touchInteceptorView accessibilityContainer], container);
4152 - (void)testLayerPool {
4156 XCTAssertTrue([
engine iosPlatformView] !=
nullptr);
4157 auto ios_context = [engine iosPlatformView]->GetIosContext();
4158 auto gr_context = ios_context->GetMainContext();
4163 pool.
CreateLayer(gr_context.get(), ios_context, MTLPixelFormatBGRA8Unorm);
4164 XCTAssertEqual(pool.size(), 1u);
4165 pool.CreateLayer(gr_context.get(), ios_context, MTLPixelFormatBGRA8Unorm);
4166 XCTAssertEqual(pool.size(), 2u);
4169 pool.RecycleLayers();
4170 XCTAssertEqual(pool.size(), 2u);
4173 auto unused_layers = pool.RemoveUnusedLayers();
4174 XCTAssertEqual(unused_layers.size(), 2u);
4175 XCTAssertEqual(pool.size(), 1u);
4178 - (void)testFlutterPlatformViewControllerSubmitFramePreservingFrameDamage {
4179 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
4181 flutter::TaskRunners runners(
self.name.UTF8String,
4182 GetDefaultTaskRunner(),
4183 GetDefaultTaskRunner(),
4184 GetDefaultTaskRunner(),
4185 GetDefaultTaskRunner());
4186 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
4187 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
4188 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
4190 mock_delegate.settings_.enable_impeller
4193 flutterPlatformViewsController,
4196 std::make_shared<fml::SyncSwitch>());
4198 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
4199 flutterPlatformViewsController->SetFlutterView(flutterView);
4203 flutterPlatformViewsController->RegisterViewFactory(
4204 factory,
@"MockFlutterPlatformView",
4208 flutterPlatformViewsController->OnMethodCall(
4210 methodCallWithMethodName:
@"create"
4211 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
4215 flutterPlatformViewsController->OnMethodCall(
4217 methodCallWithMethodName:
@"create"
4218 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
4221 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
4222 flutter::MutatorsStack stack;
4223 SkMatrix finalMatrix;
4224 auto embeddedViewParams1 =
4225 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
4226 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
4228 auto embeddedViewParams2 =
4229 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
4230 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
4233 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
4234 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
4235 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
4236 std::optional<flutter::SurfaceFrame::SubmitInfo> submit_info;
4237 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
4238 std::move(mock_sk_surface), framebuffer_info,
4239 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
4240 [&](
const flutter::SurfaceFrame& surface_frame) {
4241 submit_info = surface_frame.submit_info();
4244 SkISize::Make(800, 600));
4245 mock_surface->set_submit_info({
4246 .frame_damage = SkIRect::MakeWH(800, 600),
4247 .buffer_damage = SkIRect::MakeWH(400, 600),
4251 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
4253 XCTAssertTrue(submit_info.has_value());
4254 XCTAssertEqual(*submit_info->frame_damage, SkIRect::MakeWH(800, 600));
4255 XCTAssertEqual(*submit_info->buffer_damage, SkIRect::MakeWH(400, 600));