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;
75 : NSObject <FlutterPlatformViewFactory>
80 viewIdentifier:(int64_t)viewId
81 arguments:(
id _Nullable)args {
88 @property(nonatomic, strong) UIView* view;
89 @property(nonatomic, assign) BOOL viewCreated;
93 - (instancetype)init {
94 if (
self = [super init]) {
95 _view = [[WKWebView alloc] init];
103 [
self checkViewCreatedOnce];
107 - (void)checkViewCreatedOnce {
111 self.viewCreated = YES;
119 - (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
120 viewIdentifier:(int64_t)viewId
121 arguments:(
id _Nullable)args {
130 - (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
131 viewIdentifier:(int64_t)viewId
132 arguments:(
id _Nullable)args {
140 class FlutterPlatformViewsTestMockPlatformViewDelegate :
public PlatformView::Delegate {
142 void OnPlatformViewCreated(std::unique_ptr<Surface> surface)
override {}
143 void OnPlatformViewDestroyed()
override {}
144 void OnPlatformViewScheduleFrame()
override {}
145 void OnPlatformViewAddView(int64_t view_id,
146 const ViewportMetrics& viewport_metrics,
147 AddViewCallback callback)
override {}
148 void OnPlatformViewRemoveView(int64_t view_id, RemoveViewCallback callback)
override {}
149 void OnPlatformViewSetNextFrameCallback(
const fml::closure& closure)
override {}
150 void OnPlatformViewSetViewportMetrics(int64_t view_id,
const ViewportMetrics& metrics)
override {}
151 const flutter::Settings& OnPlatformViewGetSettings()
const override {
return settings_; }
152 void OnPlatformViewDispatchPlatformMessage(std::unique_ptr<PlatformMessage> message)
override {}
153 void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet)
override {
155 void OnPlatformViewDispatchSemanticsAction(int32_t
id,
156 SemanticsAction action,
157 fml::MallocMapping args)
override {}
158 void OnPlatformViewSetSemanticsEnabled(
bool enabled)
override {}
159 void OnPlatformViewSetAccessibilityFeatures(int32_t flags)
override {}
160 void OnPlatformViewRegisterTexture(std::shared_ptr<Texture> texture)
override {}
161 void OnPlatformViewUnregisterTexture(int64_t
texture_id)
override {}
162 void OnPlatformViewMarkTextureFrameAvailable(int64_t
texture_id)
override {}
164 void LoadDartDeferredLibrary(intptr_t loading_unit_id,
165 std::unique_ptr<const fml::Mapping> snapshot_data,
166 std::unique_ptr<const fml::Mapping> snapshot_instructions)
override {
168 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
169 const std::string error_message,
170 bool transient)
override {}
171 void UpdateAssetResolverByType(std::unique_ptr<flutter::AssetResolver> updated_asset_resolver,
172 flutter::AssetResolver::AssetResolverType type)
override {}
177 BOOL BlurRadiusEqualToBlurRadius(CGFloat radius1, CGFloat radius2) {
178 const CGFloat epsilon = 0.01;
179 return std::abs(radius1 - radius2) < epsilon;
191 fml::RefPtr<fml::TaskRunner> GetDefaultTaskRunner() {
192 fml::MessageLoop::EnsureInitializedForCurrentThread();
193 return fml::MessageLoop::GetCurrent().GetTaskRunner();
197 - (void)testFlutterViewOnlyCreateOnceInOneFrame {
198 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
200 flutter::TaskRunners runners(
self.name.UTF8String,
201 GetDefaultTaskRunner(),
202 GetDefaultTaskRunner(),
203 GetDefaultTaskRunner(),
204 GetDefaultTaskRunner());
205 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
206 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
207 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
209 mock_delegate.settings_.enable_impeller
212 flutterPlatformViewsController,
215 std::make_shared<fml::SyncSwitch>());
219 flutterPlatformViewsController->RegisterViewFactory(
220 factory,
@"MockFlutterPlatformView",
224 flutterPlatformViewsController->OnMethodCall(
226 methodCallWithMethodName:
@"create"
227 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
229 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
230 flutterPlatformViewsController->SetFlutterView(flutterView);
232 flutter::MutatorsStack stack;
234 SkMatrix screenScaleMatrix =
235 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
236 stack.PushTransform(screenScaleMatrix);
238 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
239 stack.PushTransform(translateMatrix);
240 SkMatrix finalMatrix;
241 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
243 auto embeddedViewParams =
244 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
246 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
250 flutterPlatformViewsController->Reset();
253 - (void)testCanCreatePlatformViewWithoutFlutterView {
254 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
256 flutter::TaskRunners runners(
self.name.UTF8String,
257 GetDefaultTaskRunner(),
258 GetDefaultTaskRunner(),
259 GetDefaultTaskRunner(),
260 GetDefaultTaskRunner());
261 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
262 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
263 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
265 mock_delegate.settings_.enable_impeller
268 flutterPlatformViewsController,
271 std::make_shared<fml::SyncSwitch>());
275 flutterPlatformViewsController->RegisterViewFactory(
276 factory,
@"MockFlutterPlatformView",
280 flutterPlatformViewsController->OnMethodCall(
282 methodCallWithMethodName:
@"create"
283 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
289 - (void)testChildClippingViewHitTests {
292 UIView* childView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
293 [childClippingView addSubview:childView];
295 XCTAssertFalse([childClippingView pointInside:CGPointMake(50, 50) withEvent:nil]);
296 XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 100) withEvent:nil]);
297 XCTAssertFalse([childClippingView pointInside:CGPointMake(100, 99) withEvent:nil]);
298 XCTAssertFalse([childClippingView pointInside:CGPointMake(201, 200) withEvent:nil]);
299 XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 201) withEvent:nil]);
300 XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 200) withEvent:nil]);
301 XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 299) withEvent:nil]);
303 XCTAssertTrue([childClippingView pointInside:CGPointMake(150, 150) withEvent:nil]);
304 XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 100) withEvent:nil]);
305 XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 100) withEvent:nil]);
306 XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 199) withEvent:nil]);
307 XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 199) withEvent:nil]);
310 - (void)testReleasesBackdropFilterSubviewsOnChildClippingViewDealloc {
311 __weak NSMutableArray<UIVisualEffectView*>* weakBackdropFilterSubviews = nil;
312 __weak UIVisualEffectView* weakVisualEffectView1 = nil;
313 __weak UIVisualEffectView* weakVisualEffectView2 = nil;
317 UIVisualEffectView* visualEffectView1 = [[UIVisualEffectView alloc]
318 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
319 weakVisualEffectView1 = visualEffectView1;
323 visualEffectView:visualEffectView1];
328 UIVisualEffectView* visualEffectView2 = [[UIVisualEffectView alloc]
329 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
330 weakVisualEffectView2 = visualEffectView2;
334 visualEffectView:visualEffectView2];
338 XCTAssertNotNil(weakBackdropFilterSubviews);
341 XCTAssertNil(weakBackdropFilterSubviews);
342 XCTAssertNil(weakVisualEffectView1);
343 XCTAssertNil(weakVisualEffectView2);
346 - (void)testApplyBackdropFilter {
347 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
349 flutter::TaskRunners runners(
self.name.UTF8String,
350 GetDefaultTaskRunner(),
351 GetDefaultTaskRunner(),
352 GetDefaultTaskRunner(),
353 GetDefaultTaskRunner());
354 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
355 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
356 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
358 mock_delegate.settings_.enable_impeller
361 flutterPlatformViewsController,
364 std::make_shared<fml::SyncSwitch>());
368 flutterPlatformViewsController->RegisterViewFactory(
369 factory,
@"MockFlutterPlatformView",
373 flutterPlatformViewsController->OnMethodCall(
375 methodCallWithMethodName:
@"create"
376 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
381 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
382 flutterPlatformViewsController->SetFlutterView(flutterView);
384 flutter::MutatorsStack stack;
386 CGFloat screenScale = [UIScreen mainScreen].scale;
387 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
388 stack.PushTransform(screenScaleMatrix);
390 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
391 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
393 auto embeddedViewParams =
394 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
396 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
397 flutterPlatformViewsController->CompositeWithParams(
398 2, flutterPlatformViewsController->GetCompositionParams(2));
402 [flutterView addSubview:childClippingView];
404 [flutterView setNeedsLayout];
405 [flutterView layoutIfNeeded];
408 NSUInteger numberOfExpectedVisualEffectView = 0;
409 for (UIView* subview in childClippingView.subviews) {
410 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
413 XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u);
414 if ([
self validateOneVisualEffectView:subview
415 expectedFrame:CGRectMake(0, 0, 10, 10)
417 numberOfExpectedVisualEffectView++;
420 XCTAssertEqual(numberOfExpectedVisualEffectView, 1u);
423 - (void)testApplyBackdropFilterWithCorrectFrame {
424 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
426 flutter::TaskRunners runners(
self.name.UTF8String,
427 GetDefaultTaskRunner(),
428 GetDefaultTaskRunner(),
429 GetDefaultTaskRunner(),
430 GetDefaultTaskRunner());
431 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
432 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
433 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
435 mock_delegate.settings_.enable_impeller
438 flutterPlatformViewsController,
441 std::make_shared<fml::SyncSwitch>());
445 flutterPlatformViewsController->RegisterViewFactory(
446 factory,
@"MockFlutterPlatformView",
450 flutterPlatformViewsController->OnMethodCall(
452 methodCallWithMethodName:
@"create"
453 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
458 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
459 flutterPlatformViewsController->SetFlutterView(flutterView);
461 flutter::MutatorsStack stack;
463 CGFloat screenScale = [UIScreen mainScreen].scale;
464 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
465 stack.PushTransform(screenScaleMatrix);
467 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
468 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 8, screenScale * 8));
470 auto embeddedViewParams =
471 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(5, 10), stack);
473 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
474 flutterPlatformViewsController->CompositeWithParams(
475 2, flutterPlatformViewsController->GetCompositionParams(2));
479 [flutterView addSubview:childClippingView];
481 [flutterView setNeedsLayout];
482 [flutterView layoutIfNeeded];
485 NSUInteger numberOfExpectedVisualEffectView = 0;
486 for (UIView* subview in childClippingView.subviews) {
487 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
490 XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u);
491 if ([
self validateOneVisualEffectView:subview
492 expectedFrame:CGRectMake(0, 0, 5, 8)
494 numberOfExpectedVisualEffectView++;
497 XCTAssertEqual(numberOfExpectedVisualEffectView, 1u);
500 - (void)testApplyMultipleBackdropFilters {
501 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
503 flutter::TaskRunners runners(
self.name.UTF8String,
504 GetDefaultTaskRunner(),
505 GetDefaultTaskRunner(),
506 GetDefaultTaskRunner(),
507 GetDefaultTaskRunner());
508 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
509 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
510 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
512 mock_delegate.settings_.enable_impeller
515 flutterPlatformViewsController,
518 std::make_shared<fml::SyncSwitch>());
522 flutterPlatformViewsController->RegisterViewFactory(
523 factory,
@"MockFlutterPlatformView",
527 flutterPlatformViewsController->OnMethodCall(
529 methodCallWithMethodName:
@"create"
530 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
535 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
536 flutterPlatformViewsController->SetFlutterView(flutterView);
538 flutter::MutatorsStack stack;
540 CGFloat screenScale = [UIScreen mainScreen].scale;
541 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
542 stack.PushTransform(screenScaleMatrix);
544 for (
int i = 0; i < 50; i++) {
545 auto filter = std::make_shared<flutter::DlBlurImageFilter>(i, 2, flutter::DlTileMode::kClamp);
546 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
549 auto embeddedViewParams =
550 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(20, 20), stack);
552 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
553 flutterPlatformViewsController->CompositeWithParams(
554 2, flutterPlatformViewsController->GetCompositionParams(2));
558 [flutterView addSubview:childClippingView];
560 [flutterView setNeedsLayout];
561 [flutterView layoutIfNeeded];
563 NSUInteger numberOfExpectedVisualEffectView = 0;
564 for (UIView* subview in childClippingView.subviews) {
565 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
568 XCTAssertLessThan(numberOfExpectedVisualEffectView, 50u);
569 if ([
self validateOneVisualEffectView:subview
570 expectedFrame:CGRectMake(0, 0, 10, 10)
571 inputRadius:(CGFloat)numberOfExpectedVisualEffectView]) {
572 numberOfExpectedVisualEffectView++;
575 XCTAssertEqual(numberOfExpectedVisualEffectView, (NSUInteger)numberOfExpectedVisualEffectView);
578 - (void)testAddBackdropFilters {
579 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
581 flutter::TaskRunners runners(
self.name.UTF8String,
582 GetDefaultTaskRunner(),
583 GetDefaultTaskRunner(),
584 GetDefaultTaskRunner(),
585 GetDefaultTaskRunner());
586 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
587 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
588 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
590 mock_delegate.settings_.enable_impeller
593 flutterPlatformViewsController,
596 std::make_shared<fml::SyncSwitch>());
600 flutterPlatformViewsController->RegisterViewFactory(
601 factory,
@"MockFlutterPlatformView",
605 flutterPlatformViewsController->OnMethodCall(
607 methodCallWithMethodName:
@"create"
608 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
613 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
614 flutterPlatformViewsController->SetFlutterView(flutterView);
616 flutter::MutatorsStack stack;
618 CGFloat screenScale = [UIScreen mainScreen].scale;
619 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
620 stack.PushTransform(screenScaleMatrix);
622 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
623 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
625 auto embeddedViewParams =
626 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
628 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
629 flutterPlatformViewsController->CompositeWithParams(
630 2, flutterPlatformViewsController->GetCompositionParams(2));
634 [flutterView addSubview:childClippingView];
636 [flutterView setNeedsLayout];
637 [flutterView layoutIfNeeded];
639 NSMutableArray* originalVisualEffectViews = [[NSMutableArray alloc] init];
640 for (UIView* subview in childClippingView.subviews) {
641 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
644 XCTAssertLessThan(originalVisualEffectViews.count, 1u);
645 if ([
self validateOneVisualEffectView:subview
646 expectedFrame:CGRectMake(0, 0, 10, 10)
647 inputRadius:(CGFloat)5]) {
648 [originalVisualEffectViews addObject:subview];
651 XCTAssertEqual(originalVisualEffectViews.count, 1u);
656 flutter::MutatorsStack stack2;
658 stack2.PushTransform(screenScaleMatrix);
660 for (
int i = 0; i < 2; i++) {
661 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
664 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
665 SkSize::Make(10, 10), stack2);
667 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
668 flutterPlatformViewsController->CompositeWithParams(
669 2, flutterPlatformViewsController->GetCompositionParams(2));
671 [flutterView setNeedsLayout];
672 [flutterView layoutIfNeeded];
674 NSMutableArray* newVisualEffectViews = [[NSMutableArray alloc] init];
675 for (UIView* subview in childClippingView.subviews) {
676 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
679 XCTAssertLessThan(newVisualEffectViews.count, 2u);
681 if ([
self validateOneVisualEffectView:subview
682 expectedFrame:CGRectMake(0, 0, 10, 10)
683 inputRadius:(CGFloat)5]) {
684 [newVisualEffectViews addObject:subview];
687 XCTAssertEqual(newVisualEffectViews.count, 2u);
688 for (NSUInteger i = 0; i < originalVisualEffectViews.count; i++) {
689 UIView* originalView = originalVisualEffectViews[i];
690 UIView* newView = newVisualEffectViews[i];
692 XCTAssertEqual(originalView, newView);
693 id mockOrignalView = OCMPartialMock(originalView);
694 OCMReject([mockOrignalView removeFromSuperview]);
695 [mockOrignalView stopMocking];
699 - (void)testRemoveBackdropFilters {
700 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
702 flutter::TaskRunners runners(
self.name.UTF8String,
703 GetDefaultTaskRunner(),
704 GetDefaultTaskRunner(),
705 GetDefaultTaskRunner(),
706 GetDefaultTaskRunner());
707 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
708 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
709 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
711 mock_delegate.settings_.enable_impeller
714 flutterPlatformViewsController,
717 std::make_shared<fml::SyncSwitch>());
721 flutterPlatformViewsController->RegisterViewFactory(
722 factory,
@"MockFlutterPlatformView",
726 flutterPlatformViewsController->OnMethodCall(
728 methodCallWithMethodName:
@"create"
729 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
734 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
735 flutterPlatformViewsController->SetFlutterView(flutterView);
737 flutter::MutatorsStack stack;
739 CGFloat screenScale = [UIScreen mainScreen].scale;
740 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
741 stack.PushTransform(screenScaleMatrix);
743 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
744 for (
int i = 0; i < 5; i++) {
745 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
748 auto embeddedViewParams =
749 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
751 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
752 flutterPlatformViewsController->CompositeWithParams(
753 2, flutterPlatformViewsController->GetCompositionParams(2));
757 [flutterView addSubview:childClippingView];
759 [flutterView setNeedsLayout];
760 [flutterView layoutIfNeeded];
762 NSMutableArray* originalVisualEffectViews = [[NSMutableArray alloc] init];
763 for (UIView* subview in childClippingView.subviews) {
764 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
767 XCTAssertLessThan(originalVisualEffectViews.count, 5u);
768 if ([
self validateOneVisualEffectView:subview
769 expectedFrame:CGRectMake(0, 0, 10, 10)
770 inputRadius:(CGFloat)5]) {
771 [originalVisualEffectViews addObject:subview];
777 flutter::MutatorsStack stack2;
779 stack2.PushTransform(screenScaleMatrix);
781 for (
int i = 0; i < 4; i++) {
782 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
785 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
786 SkSize::Make(10, 10), stack2);
788 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
789 flutterPlatformViewsController->CompositeWithParams(
790 2, flutterPlatformViewsController->GetCompositionParams(2));
792 [flutterView setNeedsLayout];
793 [flutterView layoutIfNeeded];
795 NSMutableArray* newVisualEffectViews = [[NSMutableArray alloc] init];
796 for (UIView* subview in childClippingView.subviews) {
797 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
800 XCTAssertLessThan(newVisualEffectViews.count, 4u);
801 if ([
self validateOneVisualEffectView:subview
802 expectedFrame:CGRectMake(0, 0, 10, 10)
803 inputRadius:(CGFloat)5]) {
804 [newVisualEffectViews addObject:subview];
807 XCTAssertEqual(newVisualEffectViews.count, 4u);
809 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
810 UIView* newView = newVisualEffectViews[i];
811 id mockNewView = OCMPartialMock(newView);
812 UIView* originalView = originalVisualEffectViews[i];
814 XCTAssertEqual(originalView, newView);
815 OCMReject([mockNewView removeFromSuperview]);
816 [mockNewView stopMocking];
821 for (
int i = 0; i < 5; i++) {
826 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
827 SkSize::Make(10, 10), stack2);
829 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
830 flutterPlatformViewsController->CompositeWithParams(
831 2, flutterPlatformViewsController->GetCompositionParams(2));
833 [flutterView setNeedsLayout];
834 [flutterView layoutIfNeeded];
836 NSUInteger numberOfExpectedVisualEffectView = 0u;
837 for (UIView* subview in childClippingView.subviews) {
838 if ([subview isKindOfClass:[UIVisualEffectView
class]]) {
839 numberOfExpectedVisualEffectView++;
842 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
845 - (void)testEditBackdropFilters {
846 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
848 flutter::TaskRunners runners(
self.name.UTF8String,
849 GetDefaultTaskRunner(),
850 GetDefaultTaskRunner(),
851 GetDefaultTaskRunner(),
852 GetDefaultTaskRunner());
853 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
854 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
855 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
857 mock_delegate.settings_.enable_impeller
860 flutterPlatformViewsController,
863 std::make_shared<fml::SyncSwitch>());
867 flutterPlatformViewsController->RegisterViewFactory(
868 factory,
@"MockFlutterPlatformView",
872 flutterPlatformViewsController->OnMethodCall(
874 methodCallWithMethodName:
@"create"
875 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
880 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
881 flutterPlatformViewsController->SetFlutterView(flutterView);
883 flutter::MutatorsStack stack;
885 CGFloat screenScale = [UIScreen mainScreen].scale;
886 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
887 stack.PushTransform(screenScaleMatrix);
889 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
890 for (
int i = 0; i < 5; i++) {
891 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
894 auto embeddedViewParams =
895 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
897 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
898 flutterPlatformViewsController->CompositeWithParams(
899 2, flutterPlatformViewsController->GetCompositionParams(2));
903 [flutterView addSubview:childClippingView];
905 [flutterView setNeedsLayout];
906 [flutterView layoutIfNeeded];
908 NSMutableArray* originalVisualEffectViews = [[NSMutableArray alloc] init];
909 for (UIView* subview in childClippingView.subviews) {
910 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
913 XCTAssertLessThan(originalVisualEffectViews.count, 5u);
914 if ([
self validateOneVisualEffectView:subview
915 expectedFrame:CGRectMake(0, 0, 10, 10)
916 inputRadius:(CGFloat)5]) {
917 [originalVisualEffectViews addObject:subview];
923 flutter::MutatorsStack stack2;
925 stack2.PushTransform(screenScaleMatrix);
927 for (
int i = 0; i < 5; i++) {
930 std::make_shared<flutter::DlBlurImageFilter>(2, 5, flutter::DlTileMode::kClamp);
932 stack2.PushBackdropFilter(filter2,
933 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
937 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
940 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
941 SkSize::Make(10, 10), stack2);
943 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
944 flutterPlatformViewsController->CompositeWithParams(
945 2, flutterPlatformViewsController->GetCompositionParams(2));
947 [flutterView setNeedsLayout];
948 [flutterView layoutIfNeeded];
950 NSMutableArray* newVisualEffectViews = [[NSMutableArray alloc] init];
951 for (UIView* subview in childClippingView.subviews) {
952 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
955 XCTAssertLessThan(newVisualEffectViews.count, 5u);
956 CGFloat expectInputRadius = 5;
957 if (newVisualEffectViews.count == 3) {
958 expectInputRadius = 2;
960 if ([
self validateOneVisualEffectView:subview
961 expectedFrame:CGRectMake(0, 0, 10, 10)
962 inputRadius:(CGFloat)expectInputRadius]) {
963 [newVisualEffectViews addObject:subview];
966 XCTAssertEqual(newVisualEffectViews.count, 5u);
967 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
968 UIView* newView = newVisualEffectViews[i];
969 id mockNewView = OCMPartialMock(newView);
970 UIView* originalView = originalVisualEffectViews[i];
972 XCTAssertEqual(originalView, newView);
973 OCMReject([mockNewView removeFromSuperview]);
974 [mockNewView stopMocking];
976 [newVisualEffectViews removeAllObjects];
980 for (
int i = 0; i < 5; i++) {
984 for (
int i = 0; i < 5; i++) {
987 std::make_shared<flutter::DlBlurImageFilter>(2, 5, flutter::DlTileMode::kClamp);
988 stack2.PushBackdropFilter(filter2,
989 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
993 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
996 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
997 SkSize::Make(10, 10), stack2);
999 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1000 flutterPlatformViewsController->CompositeWithParams(
1001 2, flutterPlatformViewsController->GetCompositionParams(2));
1003 [flutterView setNeedsLayout];
1004 [flutterView layoutIfNeeded];
1006 for (UIView* subview in childClippingView.subviews) {
1007 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1010 XCTAssertLessThan(newVisualEffectViews.count, 5u);
1011 CGFloat expectInputRadius = 5;
1012 if (newVisualEffectViews.count == 0) {
1013 expectInputRadius = 2;
1015 if ([
self validateOneVisualEffectView:subview
1016 expectedFrame:CGRectMake(0, 0, 10, 10)
1017 inputRadius:(CGFloat)expectInputRadius]) {
1018 [newVisualEffectViews addObject:subview];
1021 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
1022 UIView* newView = newVisualEffectViews[i];
1023 id mockNewView = OCMPartialMock(newView);
1024 UIView* originalView = originalVisualEffectViews[i];
1026 XCTAssertEqual(originalView, newView);
1027 OCMReject([mockNewView removeFromSuperview]);
1028 [mockNewView stopMocking];
1030 [newVisualEffectViews removeAllObjects];
1034 for (
int i = 0; i < 5; i++) {
1038 for (
int i = 0; i < 5; i++) {
1041 std::make_shared<flutter::DlBlurImageFilter>(2, 5, flutter::DlTileMode::kClamp);
1042 stack2.PushBackdropFilter(filter2,
1043 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1047 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1050 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1051 SkSize::Make(10, 10), stack2);
1053 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1054 flutterPlatformViewsController->CompositeWithParams(
1055 2, flutterPlatformViewsController->GetCompositionParams(2));
1057 [flutterView setNeedsLayout];
1058 [flutterView layoutIfNeeded];
1060 for (UIView* subview in childClippingView.subviews) {
1061 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1064 XCTAssertLessThan(newVisualEffectViews.count, 5u);
1065 CGFloat expectInputRadius = 5;
1066 if (newVisualEffectViews.count == 4) {
1067 expectInputRadius = 2;
1069 if ([
self validateOneVisualEffectView:subview
1070 expectedFrame:CGRectMake(0, 0, 10, 10)
1071 inputRadius:(CGFloat)expectInputRadius]) {
1072 [newVisualEffectViews addObject:subview];
1075 XCTAssertEqual(newVisualEffectViews.count, 5u);
1077 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
1078 UIView* newView = newVisualEffectViews[i];
1079 id mockNewView = OCMPartialMock(newView);
1080 UIView* originalView = originalVisualEffectViews[i];
1082 XCTAssertEqual(originalView, newView);
1083 OCMReject([mockNewView removeFromSuperview]);
1084 [mockNewView stopMocking];
1086 [newVisualEffectViews removeAllObjects];
1090 for (
int i = 0; i < 5; i++) {
1094 for (
int i = 0; i < 5; i++) {
1095 auto filter2 = std::make_shared<flutter::DlBlurImageFilter>(i, 2, flutter::DlTileMode::kClamp);
1097 stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1100 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1101 SkSize::Make(10, 10), stack2);
1103 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1104 flutterPlatformViewsController->CompositeWithParams(
1105 2, flutterPlatformViewsController->GetCompositionParams(2));
1107 [flutterView setNeedsLayout];
1108 [flutterView layoutIfNeeded];
1110 for (UIView* subview in childClippingView.subviews) {
1111 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1114 XCTAssertLessThan(newVisualEffectViews.count, 5u);
1115 if ([
self validateOneVisualEffectView:subview
1116 expectedFrame:CGRectMake(0, 0, 10, 10)
1117 inputRadius:(CGFloat)newVisualEffectViews.count]) {
1118 [newVisualEffectViews addObject:subview];
1121 XCTAssertEqual(newVisualEffectViews.count, 5u);
1123 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
1124 UIView* newView = newVisualEffectViews[i];
1125 id mockNewView = OCMPartialMock(newView);
1126 UIView* originalView = originalVisualEffectViews[i];
1128 XCTAssertEqual(originalView, newView);
1129 OCMReject([mockNewView removeFromSuperview]);
1130 [mockNewView stopMocking];
1132 [newVisualEffectViews removeAllObjects];
1135 - (void)testApplyBackdropFilterNotDlBlurImageFilter {
1136 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1138 flutter::TaskRunners runners(
self.name.UTF8String,
1139 GetDefaultTaskRunner(),
1140 GetDefaultTaskRunner(),
1141 GetDefaultTaskRunner(),
1142 GetDefaultTaskRunner());
1143 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1144 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1145 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1147 mock_delegate.settings_.enable_impeller
1150 flutterPlatformViewsController,
1153 std::make_shared<fml::SyncSwitch>());
1157 flutterPlatformViewsController->RegisterViewFactory(
1158 factory,
@"MockFlutterPlatformView",
1162 flutterPlatformViewsController->OnMethodCall(
1164 methodCallWithMethodName:
@"create"
1165 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1170 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1171 flutterPlatformViewsController->SetFlutterView(flutterView);
1173 flutter::MutatorsStack stack;
1175 CGFloat screenScale = [UIScreen mainScreen].scale;
1176 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
1177 stack.PushTransform(screenScaleMatrix);
1179 auto dilateFilter = std::make_shared<flutter::DlDilateImageFilter>(5, 2);
1180 stack.PushBackdropFilter(dilateFilter, SkRect::MakeEmpty());
1182 auto embeddedViewParams =
1183 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1185 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1186 flutterPlatformViewsController->CompositeWithParams(
1187 2, flutterPlatformViewsController->GetCompositionParams(2));
1192 [flutterView addSubview:childClippingView];
1194 [flutterView setNeedsLayout];
1195 [flutterView layoutIfNeeded];
1197 NSUInteger numberOfExpectedVisualEffectView = 0;
1198 for (UIView* subview in childClippingView.subviews) {
1199 if ([subview isKindOfClass:[UIVisualEffectView
class]]) {
1200 numberOfExpectedVisualEffectView++;
1203 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
1207 flutter::MutatorsStack stack2;
1209 stack2.PushTransform(screenScaleMatrix);
1211 auto blurFilter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
1213 for (
int i = 0; i < 5; i++) {
1215 stack2.PushBackdropFilter(dilateFilter,
1216 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1220 stack2.PushBackdropFilter(blurFilter,
1221 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1224 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1225 SkSize::Make(10, 10), stack2);
1227 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1228 flutterPlatformViewsController->CompositeWithParams(
1229 2, flutterPlatformViewsController->GetCompositionParams(2));
1231 [flutterView setNeedsLayout];
1232 [flutterView layoutIfNeeded];
1234 numberOfExpectedVisualEffectView = 0;
1235 for (UIView* subview in childClippingView.subviews) {
1236 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1239 XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u);
1240 if ([
self validateOneVisualEffectView:subview
1241 expectedFrame:CGRectMake(0, 0, 10, 10)
1242 inputRadius:(CGFloat)5]) {
1243 numberOfExpectedVisualEffectView++;
1246 XCTAssertEqual(numberOfExpectedVisualEffectView, 4u);
1250 for (
int i = 0; i < 5; i++) {
1254 for (
int i = 0; i < 5; i++) {
1256 stack2.PushBackdropFilter(dilateFilter,
1257 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1261 stack2.PushBackdropFilter(blurFilter,
1262 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1265 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1266 SkSize::Make(10, 10), stack2);
1268 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1269 flutterPlatformViewsController->CompositeWithParams(
1270 2, flutterPlatformViewsController->GetCompositionParams(2));
1272 [flutterView setNeedsLayout];
1273 [flutterView layoutIfNeeded];
1275 numberOfExpectedVisualEffectView = 0;
1276 for (UIView* subview in childClippingView.subviews) {
1277 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1280 XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u);
1281 if ([
self validateOneVisualEffectView:subview
1282 expectedFrame:CGRectMake(0, 0, 10, 10)
1283 inputRadius:(CGFloat)5]) {
1284 numberOfExpectedVisualEffectView++;
1287 XCTAssertEqual(numberOfExpectedVisualEffectView, 4u);
1291 for (
int i = 0; i < 5; i++) {
1295 for (
int i = 0; i < 5; i++) {
1297 stack2.PushBackdropFilter(dilateFilter,
1298 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1302 stack2.PushBackdropFilter(blurFilter,
1303 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1306 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1307 SkSize::Make(10, 10), stack2);
1309 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1310 flutterPlatformViewsController->CompositeWithParams(
1311 2, flutterPlatformViewsController->GetCompositionParams(2));
1313 [flutterView setNeedsLayout];
1314 [flutterView layoutIfNeeded];
1316 numberOfExpectedVisualEffectView = 0;
1317 for (UIView* subview in childClippingView.subviews) {
1318 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1321 XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u);
1322 if ([
self validateOneVisualEffectView:subview
1323 expectedFrame:CGRectMake(0, 0, 10, 10)
1324 inputRadius:(CGFloat)5]) {
1325 numberOfExpectedVisualEffectView++;
1328 XCTAssertEqual(numberOfExpectedVisualEffectView, 4u);
1332 for (
int i = 0; i < 5; i++) {
1336 for (
int i = 0; i < 5; i++) {
1337 stack2.PushBackdropFilter(dilateFilter,
1338 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1341 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1342 SkSize::Make(10, 10), stack2);
1344 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1345 flutterPlatformViewsController->CompositeWithParams(
1346 2, flutterPlatformViewsController->GetCompositionParams(2));
1348 [flutterView setNeedsLayout];
1349 [flutterView layoutIfNeeded];
1351 numberOfExpectedVisualEffectView = 0;
1352 for (UIView* subview in childClippingView.subviews) {
1353 if ([subview isKindOfClass:[UIVisualEffectView
class]]) {
1354 numberOfExpectedVisualEffectView++;
1357 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
1360 - (void)testApplyBackdropFilterCorrectAPI {
1365 UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc]
1366 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1370 visualEffectView:visualEffectView];
1371 XCTAssertNotNil(platformViewFilter);
1374 - (void)testApplyBackdropFilterAPIChangedInvalidUIVisualEffectView {
1376 UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] init];
1380 visualEffectView:visualEffectView];
1381 XCTAssertNil(platformViewFilter);
1384 - (void)testApplyBackdropFilterAPIChangedNoGaussianBlurFilter {
1386 UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc]
1387 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1388 NSArray* subviews = editedUIVisualEffectView.subviews;
1389 for (UIView* view in subviews) {
1390 if ([NSStringFromClass([view
class]) hasSuffix:
@"BackdropView"]) {
1391 for (CIFilter* filter in view.layer.filters) {
1392 if ([[filter valueForKey:
@"name"] isEqual:
@"gaussianBlur"]) {
1393 [filter setValue:@"notGaussianBlur" forKey:@"name"];
1403 visualEffectView:editedUIVisualEffectView];
1404 XCTAssertNil(platformViewFilter);
1407 - (void)testApplyBackdropFilterAPIChangedInvalidInputRadius {
1409 UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc]
1410 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1411 NSArray* subviews = editedUIVisualEffectView.subviews;
1412 for (UIView* view in subviews) {
1413 if ([NSStringFromClass([view
class]) hasSuffix:
@"BackdropView"]) {
1414 for (CIFilter* filter in view.layer.filters) {
1415 if ([[filter valueForKey:
@"name"] isEqual:
@"gaussianBlur"]) {
1416 [filter setValue:@"invalidInputRadius" forKey:@"inputRadius"];
1427 visualEffectView:editedUIVisualEffectView];
1428 XCTAssertNil(platformViewFilter);
1431 - (void)testBackdropFilterVisualEffectSubviewBackgroundColor {
1432 __weak UIVisualEffectView* weakVisualEffectView;
1435 UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc]
1436 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1437 weakVisualEffectView = visualEffectView;
1441 visualEffectView:visualEffectView];
1442 CGColorRef visualEffectSubviewBackgroundColor = nil;
1443 for (UIView* view in [platformViewFilter backdropFilterView].subviews) {
1444 if ([NSStringFromClass([view
class]) hasSuffix:
@"VisualEffectSubview"]) {
1445 visualEffectSubviewBackgroundColor = view.layer.backgroundColor;
1449 CGColorEqualToColor(visualEffectSubviewBackgroundColor, UIColor.clearColor.CGColor));
1451 XCTAssertNil(weakVisualEffectView);
1454 - (void)testCompositePlatformView {
1455 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1457 flutter::TaskRunners runners(
self.name.UTF8String,
1458 GetDefaultTaskRunner(),
1459 GetDefaultTaskRunner(),
1460 GetDefaultTaskRunner(),
1461 GetDefaultTaskRunner());
1462 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1463 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1464 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1466 mock_delegate.settings_.enable_impeller
1469 flutterPlatformViewsController,
1472 std::make_shared<fml::SyncSwitch>());
1476 flutterPlatformViewsController->RegisterViewFactory(
1477 factory,
@"MockFlutterPlatformView",
1481 flutterPlatformViewsController->OnMethodCall(
1483 methodCallWithMethodName:
@"create"
1484 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1489 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
1490 flutterPlatformViewsController->SetFlutterView(flutterView);
1492 flutter::MutatorsStack stack;
1494 SkMatrix screenScaleMatrix =
1495 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1496 stack.PushTransform(screenScaleMatrix);
1498 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
1499 stack.PushTransform(translateMatrix);
1500 SkMatrix finalMatrix;
1501 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
1503 auto embeddedViewParams =
1504 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
1506 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1507 flutterPlatformViewsController->CompositeWithParams(
1508 2, flutterPlatformViewsController->GetCompositionParams(2));
1510 CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds
1511 toView:flutterView];
1512 XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, 300)));
1515 - (void)testBackdropFilterCorrectlyPushedAndReset {
1516 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1518 flutter::TaskRunners runners(
self.name.UTF8String,
1519 GetDefaultTaskRunner(),
1520 GetDefaultTaskRunner(),
1521 GetDefaultTaskRunner(),
1522 GetDefaultTaskRunner());
1523 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1524 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1525 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1527 mock_delegate.settings_.enable_impeller
1530 flutterPlatformViewsController,
1533 std::make_shared<fml::SyncSwitch>());
1537 flutterPlatformViewsController->RegisterViewFactory(
1538 factory,
@"MockFlutterPlatformView",
1542 flutterPlatformViewsController->OnMethodCall(
1544 methodCallWithMethodName:
@"create"
1545 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1550 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1551 flutterPlatformViewsController->SetFlutterView(flutterView);
1553 flutter::MutatorsStack stack;
1555 CGFloat screenScale = [UIScreen mainScreen].scale;
1556 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
1557 stack.PushTransform(screenScaleMatrix);
1559 auto embeddedViewParams =
1560 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1562 flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0));
1563 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1564 flutterPlatformViewsController->PushVisitedPlatformView(2);
1565 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
1566 flutterPlatformViewsController->PushFilterToVisitedPlatformViews(
1567 filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1568 flutterPlatformViewsController->CompositeWithParams(
1569 2, flutterPlatformViewsController->GetCompositionParams(2));
1573 [flutterView addSubview:childClippingView];
1575 [flutterView setNeedsLayout];
1576 [flutterView layoutIfNeeded];
1579 NSUInteger numberOfExpectedVisualEffectView = 0;
1580 for (UIView* subview in childClippingView.subviews) {
1581 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1584 XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u);
1585 if ([
self validateOneVisualEffectView:subview
1586 expectedFrame:CGRectMake(0, 0, 10, 10)
1588 numberOfExpectedVisualEffectView++;
1591 XCTAssertEqual(numberOfExpectedVisualEffectView, 1u);
1594 auto embeddedViewParams2 =
1595 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1596 flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0));
1597 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2));
1598 flutterPlatformViewsController->CompositeWithParams(
1599 2, flutterPlatformViewsController->GetCompositionParams(2));
1603 [flutterView setNeedsLayout];
1604 [flutterView layoutIfNeeded];
1606 numberOfExpectedVisualEffectView = 0;
1607 for (UIView* subview in childClippingView.subviews) {
1608 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1611 numberOfExpectedVisualEffectView++;
1613 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
1616 - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView {
1617 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1619 flutter::TaskRunners runners(
self.name.UTF8String,
1620 GetDefaultTaskRunner(),
1621 GetDefaultTaskRunner(),
1622 GetDefaultTaskRunner(),
1623 GetDefaultTaskRunner());
1624 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1625 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1626 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1628 mock_delegate.settings_.enable_impeller
1631 flutterPlatformViewsController,
1634 std::make_shared<fml::SyncSwitch>());
1638 flutterPlatformViewsController->RegisterViewFactory(
1639 factory,
@"MockFlutterPlatformView",
1643 flutterPlatformViewsController->OnMethodCall(
1645 methodCallWithMethodName:
@"create"
1646 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1651 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
1652 flutterPlatformViewsController->SetFlutterView(flutterView);
1654 flutter::MutatorsStack stack;
1656 SkMatrix screenScaleMatrix =
1657 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1658 stack.PushTransform(screenScaleMatrix);
1660 SkMatrix rotateMatrix;
1661 rotateMatrix.setRotate(10);
1662 stack.PushTransform(rotateMatrix);
1663 SkMatrix finalMatrix;
1664 finalMatrix.setConcat(screenScaleMatrix, rotateMatrix);
1666 auto embeddedViewParams =
1667 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
1669 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1670 flutterPlatformViewsController->CompositeWithParams(
1671 2, flutterPlatformViewsController->GetCompositionParams(2));
1673 CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds
1674 toView:flutterView];
1680 XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - childClippingView.frame.origin.x),
1682 XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - childClippingView.frame.origin.y),
1685 fabs(platformViewRectInFlutterView.size.width - childClippingView.frame.size.width),
1688 fabs(platformViewRectInFlutterView.size.height - childClippingView.frame.size.height),
1692 - (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView {
1693 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1695 flutter::TaskRunners runners(
self.name.UTF8String,
1696 GetDefaultTaskRunner(),
1697 GetDefaultTaskRunner(),
1698 GetDefaultTaskRunner(),
1699 GetDefaultTaskRunner());
1700 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1701 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1702 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1704 mock_delegate.settings_.enable_impeller
1707 flutterPlatformViewsController,
1710 std::make_shared<fml::SyncSwitch>());
1714 flutterPlatformViewsController->RegisterViewFactory(
1715 factory,
@"MockFlutterPlatformView",
1719 flutterPlatformViewsController->OnMethodCall(
1721 methodCallWithMethodName:
@"create"
1722 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1727 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
1728 flutterPlatformViewsController->SetFlutterView(flutterView);
1730 flutter::MutatorsStack stack;
1732 SkMatrix screenScaleMatrix =
1733 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1734 stack.PushTransform(screenScaleMatrix);
1735 SkMatrix translateMatrix = SkMatrix::Translate(5, 5);
1737 stack.PushTransform(translateMatrix);
1739 SkRect rect = SkRect::MakeXYWH(0, 0, 25, 25);
1740 stack.PushClipRect(rect);
1743 SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25);
1744 SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1);
1745 stack.PushClipRRect(rrect);
1747 auto embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(
1748 SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack);
1750 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1751 flutterPlatformViewsController->CompositeWithParams(
1752 2, flutterPlatformViewsController->GetCompositionParams(2));
1757 [flutterView addSubview:childClippingView];
1759 [flutterView setNeedsLayout];
1760 [flutterView layoutIfNeeded];
1761 XCTAssertNil(childClippingView.maskView);
1764 - (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView {
1765 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1767 flutter::TaskRunners runners(
self.name.UTF8String,
1768 GetDefaultTaskRunner(),
1769 GetDefaultTaskRunner(),
1770 GetDefaultTaskRunner(),
1771 GetDefaultTaskRunner());
1772 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1773 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1774 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1776 mock_delegate.settings_.enable_impeller
1779 flutterPlatformViewsController,
1782 std::make_shared<fml::SyncSwitch>());
1786 flutterPlatformViewsController->RegisterViewFactory(
1787 factory,
@"MockFlutterPlatformView",
1791 flutterPlatformViewsController->OnMethodCall(
1793 methodCallWithMethodName:
@"create"
1794 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1799 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
1800 flutterPlatformViewsController->SetFlutterView(flutterView);
1802 flutter::MutatorsStack stack;
1804 SkMatrix screenScaleMatrix =
1805 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1806 stack.PushTransform(screenScaleMatrix);
1807 SkMatrix translateMatrix = SkMatrix::Translate(5, 5);
1809 stack.PushTransform(translateMatrix);
1813 SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10);
1814 SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1);
1815 stack.PushClipRRect(rrect);
1817 auto embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(
1818 SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack);
1820 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1821 flutterPlatformViewsController->CompositeWithParams(
1822 2, flutterPlatformViewsController->GetCompositionParams(2));
1827 [flutterView addSubview:childClippingView];
1829 [flutterView setNeedsLayout];
1830 [flutterView layoutIfNeeded];
1832 XCTAssertNotNil(childClippingView.maskView);
1835 - (void)testClipRect {
1836 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1838 flutter::TaskRunners runners(
self.name.UTF8String,
1839 GetDefaultTaskRunner(),
1840 GetDefaultTaskRunner(),
1841 GetDefaultTaskRunner(),
1842 GetDefaultTaskRunner());
1843 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1844 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1845 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1847 mock_delegate.settings_.enable_impeller
1850 flutterPlatformViewsController,
1853 std::make_shared<fml::SyncSwitch>());
1857 flutterPlatformViewsController->RegisterViewFactory(
1858 factory,
@"MockFlutterPlatformView",
1862 flutterPlatformViewsController->OnMethodCall(
1864 methodCallWithMethodName:
@"create"
1865 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1870 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1871 flutterPlatformViewsController->SetFlutterView(flutterView);
1873 flutter::MutatorsStack stack;
1875 SkMatrix screenScaleMatrix =
1876 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1877 stack.PushTransform(screenScaleMatrix);
1879 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
1880 stack.PushClipRect(rect);
1882 auto embeddedViewParams =
1883 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1885 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1886 flutterPlatformViewsController->CompositeWithParams(
1887 2, flutterPlatformViewsController->GetCompositionParams(2));
1892 [flutterView addSubview:childClippingView];
1894 [flutterView setNeedsLayout];
1895 [flutterView layoutIfNeeded];
1897 CGRect insideClipping = CGRectMake(2, 2, 3, 3);
1898 for (
int i = 0; i < 10; i++) {
1899 for (
int j = 0; j < 10; j++) {
1900 CGPoint point = CGPointMake(i, j);
1901 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
1902 if (CGRectContainsPoint(insideClipping, point)) {
1903 XCTAssertEqual(alpha, 255);
1905 XCTAssertEqual(alpha, 0);
1911 - (void)testClipRect_multipleClips {
1912 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1914 flutter::TaskRunners runners(
self.name.UTF8String,
1915 GetDefaultTaskRunner(),
1916 GetDefaultTaskRunner(),
1917 GetDefaultTaskRunner(),
1918 GetDefaultTaskRunner());
1919 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
1920 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
1921 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1923 mock_delegate.settings_.enable_impeller
1926 flutterPlatformViewsController,
1929 std::make_shared<fml::SyncSwitch>());
1933 flutterPlatformViewsController->RegisterViewFactory(
1934 factory,
@"MockFlutterPlatformView",
1938 flutterPlatformViewsController->OnMethodCall(
1940 methodCallWithMethodName:
@"create"
1941 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1946 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1947 flutterPlatformViewsController->SetFlutterView(flutterView);
1949 flutter::MutatorsStack stack;
1951 SkMatrix screenScaleMatrix =
1952 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1953 stack.PushTransform(screenScaleMatrix);
1955 SkRect rect1 = SkRect::MakeXYWH(2, 2, 3, 3);
1956 stack.PushClipRect(rect1);
1958 SkRect rect2 = SkRect::MakeXYWH(3, 3, 3, 3);
1959 stack.PushClipRect(rect2);
1961 auto embeddedViewParams =
1962 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1964 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1965 flutterPlatformViewsController->CompositeWithParams(
1966 2, flutterPlatformViewsController->GetCompositionParams(2));
1971 [flutterView addSubview:childClippingView];
1973 [flutterView setNeedsLayout];
1974 [flutterView layoutIfNeeded];
1993 CGRect insideClipping = CGRectMake(3, 3, 2, 2);
1994 for (
int i = 0; i < 10; i++) {
1995 for (
int j = 0; j < 10; j++) {
1996 CGPoint point = CGPointMake(i, j);
1997 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
1998 if (CGRectContainsPoint(insideClipping, point)) {
1999 XCTAssertEqual(alpha, 255);
2001 XCTAssertEqual(alpha, 0);
2007 - (void)testClipRRect {
2008 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2010 flutter::TaskRunners runners(
self.name.UTF8String,
2011 GetDefaultTaskRunner(),
2012 GetDefaultTaskRunner(),
2013 GetDefaultTaskRunner(),
2014 GetDefaultTaskRunner());
2015 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2016 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2017 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2019 mock_delegate.settings_.enable_impeller
2022 flutterPlatformViewsController,
2025 std::make_shared<fml::SyncSwitch>());
2029 flutterPlatformViewsController->RegisterViewFactory(
2030 factory,
@"MockFlutterPlatformView",
2034 flutterPlatformViewsController->OnMethodCall(
2036 methodCallWithMethodName:
@"create"
2037 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2042 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2043 flutterPlatformViewsController->SetFlutterView(flutterView);
2045 flutter::MutatorsStack stack;
2047 SkMatrix screenScaleMatrix =
2048 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2049 stack.PushTransform(screenScaleMatrix);
2051 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2052 stack.PushClipRRect(rrect);
2054 auto embeddedViewParams =
2055 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2057 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2058 flutterPlatformViewsController->CompositeWithParams(
2059 2, flutterPlatformViewsController->GetCompositionParams(2));
2064 [flutterView addSubview:childClippingView];
2066 [flutterView setNeedsLayout];
2067 [flutterView layoutIfNeeded];
2088 CGRect innerClipping1 = CGRectMake(3, 2, 4, 6);
2089 CGRect innerClipping2 = CGRectMake(2, 3, 6, 4);
2090 CGRect outterClipping = CGRectMake(2, 2, 6, 6);
2091 for (
int i = 0; i < 10; i++) {
2092 for (
int j = 0; j < 10; j++) {
2093 CGPoint point = CGPointMake(i, j);
2094 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2095 if (CGRectContainsPoint(innerClipping1, point) ||
2096 CGRectContainsPoint(innerClipping2, point)) {
2098 XCTAssertEqual(alpha, 255);
2099 }
else if (CGRectContainsPoint(outterClipping, point)) {
2101 XCTAssert(0 < alpha && alpha < 255);
2104 XCTAssertEqual(alpha, 0);
2110 - (void)testClipRRect_multipleClips {
2111 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2113 flutter::TaskRunners runners(
self.name.UTF8String,
2114 GetDefaultTaskRunner(),
2115 GetDefaultTaskRunner(),
2116 GetDefaultTaskRunner(),
2117 GetDefaultTaskRunner());
2118 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2119 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2120 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2122 mock_delegate.settings_.enable_impeller
2125 flutterPlatformViewsController,
2128 std::make_shared<fml::SyncSwitch>());
2132 flutterPlatformViewsController->RegisterViewFactory(
2133 factory,
@"MockFlutterPlatformView",
2137 flutterPlatformViewsController->OnMethodCall(
2139 methodCallWithMethodName:
@"create"
2140 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2145 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2146 flutterPlatformViewsController->SetFlutterView(flutterView);
2148 flutter::MutatorsStack stack;
2150 SkMatrix screenScaleMatrix =
2151 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2152 stack.PushTransform(screenScaleMatrix);
2154 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2155 stack.PushClipRRect(rrect);
2157 SkRect rect = SkRect::MakeXYWH(4, 2, 6, 6);
2158 stack.PushClipRect(rect);
2160 auto embeddedViewParams =
2161 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2163 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2164 flutterPlatformViewsController->CompositeWithParams(
2165 2, flutterPlatformViewsController->GetCompositionParams(2));
2170 [flutterView addSubview:childClippingView];
2172 [flutterView setNeedsLayout];
2173 [flutterView layoutIfNeeded];
2194 CGRect clipping = CGRectMake(4, 2, 4, 6);
2195 for (
int i = 0; i < 10; i++) {
2196 for (
int j = 0; j < 10; j++) {
2197 CGPoint point = CGPointMake(i, j);
2198 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2199 if (i == 7 && (j == 2 || j == 7)) {
2201 XCTAssert(0 < alpha && alpha < 255);
2204 (i == 4 && j >= 2 && j <= 7) ||
2206 (i == 7 && j >= 2 && j <= 7) ||
2208 (j == 2 && i >= 4 && i <= 7) ||
2210 (j == 7 && i >= 4 && i <= 7)) {
2213 XCTAssert(alpha > 127);
2214 }
else if ((i == 3 && j >= 1 && j <= 8) || (i == 8 && j >= 1 && j <= 8) ||
2215 (j == 1 && i >= 3 && i <= 8) || (j == 8 && i >= 3 && i <= 8)) {
2218 XCTAssert(alpha < 127);
2219 }
else if (CGRectContainsPoint(clipping, point)) {
2221 XCTAssertEqual(alpha, 255);
2224 XCTAssertEqual(alpha, 0);
2230 - (void)testClipPath {
2231 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2233 flutter::TaskRunners runners(
self.name.UTF8String,
2234 GetDefaultTaskRunner(),
2235 GetDefaultTaskRunner(),
2236 GetDefaultTaskRunner(),
2237 GetDefaultTaskRunner());
2238 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2239 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2240 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2242 mock_delegate.settings_.enable_impeller
2245 flutterPlatformViewsController,
2248 std::make_shared<fml::SyncSwitch>());
2252 flutterPlatformViewsController->RegisterViewFactory(
2253 factory,
@"MockFlutterPlatformView",
2257 flutterPlatformViewsController->OnMethodCall(
2259 methodCallWithMethodName:
@"create"
2260 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2265 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2266 flutterPlatformViewsController->SetFlutterView(flutterView);
2268 flutter::MutatorsStack stack;
2270 SkMatrix screenScaleMatrix =
2271 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2272 stack.PushTransform(screenScaleMatrix);
2275 path.addRoundRect(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2276 stack.PushClipPath(path);
2278 auto embeddedViewParams =
2279 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2281 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2282 flutterPlatformViewsController->CompositeWithParams(
2283 2, flutterPlatformViewsController->GetCompositionParams(2));
2288 [flutterView addSubview:childClippingView];
2290 [flutterView setNeedsLayout];
2291 [flutterView layoutIfNeeded];
2312 CGRect innerClipping1 = CGRectMake(3, 2, 4, 6);
2313 CGRect innerClipping2 = CGRectMake(2, 3, 6, 4);
2314 CGRect outterClipping = CGRectMake(2, 2, 6, 6);
2315 for (
int i = 0; i < 10; i++) {
2316 for (
int j = 0; j < 10; j++) {
2317 CGPoint point = CGPointMake(i, j);
2318 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2319 if (CGRectContainsPoint(innerClipping1, point) ||
2320 CGRectContainsPoint(innerClipping2, point)) {
2322 XCTAssertEqual(alpha, 255);
2323 }
else if (CGRectContainsPoint(outterClipping, point)) {
2325 XCTAssert(0 < alpha && alpha < 255);
2328 XCTAssertEqual(alpha, 0);
2334 - (void)testClipPath_multipleClips {
2335 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2337 flutter::TaskRunners runners(
self.name.UTF8String,
2338 GetDefaultTaskRunner(),
2339 GetDefaultTaskRunner(),
2340 GetDefaultTaskRunner(),
2341 GetDefaultTaskRunner());
2342 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2343 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2344 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2346 mock_delegate.settings_.enable_impeller
2349 flutterPlatformViewsController,
2352 std::make_shared<fml::SyncSwitch>());
2356 flutterPlatformViewsController->RegisterViewFactory(
2357 factory,
@"MockFlutterPlatformView",
2361 flutterPlatformViewsController->OnMethodCall(
2363 methodCallWithMethodName:
@"create"
2364 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2369 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2370 flutterPlatformViewsController->SetFlutterView(flutterView);
2372 flutter::MutatorsStack stack;
2374 SkMatrix screenScaleMatrix =
2375 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2376 stack.PushTransform(screenScaleMatrix);
2379 path.addRoundRect(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2380 stack.PushClipPath(path);
2382 SkRect rect = SkRect::MakeXYWH(4, 2, 6, 6);
2383 stack.PushClipRect(rect);
2385 auto embeddedViewParams =
2386 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2388 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2389 flutterPlatformViewsController->CompositeWithParams(
2390 2, flutterPlatformViewsController->GetCompositionParams(2));
2395 [flutterView addSubview:childClippingView];
2397 [flutterView setNeedsLayout];
2398 [flutterView layoutIfNeeded];
2419 CGRect clipping = CGRectMake(4, 2, 4, 6);
2420 for (
int i = 0; i < 10; i++) {
2421 for (
int j = 0; j < 10; j++) {
2422 CGPoint point = CGPointMake(i, j);
2423 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2424 if (i == 7 && (j == 2 || j == 7)) {
2426 XCTAssert(0 < alpha && alpha < 255);
2429 (i == 4 && j >= 2 && j <= 7) ||
2431 (i == 7 && j >= 2 && j <= 7) ||
2433 (j == 2 && i >= 4 && i <= 7) ||
2435 (j == 7 && i >= 4 && i <= 7)) {
2438 XCTAssert(alpha > 127);
2439 }
else if ((i == 3 && j >= 1 && j <= 8) || (i == 8 && j >= 1 && j <= 8) ||
2440 (j == 1 && i >= 3 && i <= 8) || (j == 8 && i >= 3 && i <= 8)) {
2443 XCTAssert(alpha < 127);
2444 }
else if (CGRectContainsPoint(clipping, point)) {
2446 XCTAssertEqual(alpha, 255);
2449 XCTAssertEqual(alpha, 0);
2455 - (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents {
2456 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2458 flutter::TaskRunners runners(
self.name.UTF8String,
2459 GetDefaultTaskRunner(),
2460 GetDefaultTaskRunner(),
2461 GetDefaultTaskRunner(),
2462 GetDefaultTaskRunner());
2463 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2464 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2465 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2467 mock_delegate.settings_.enable_impeller
2470 flutterPlatformViewsController,
2473 std::make_shared<fml::SyncSwitch>());
2477 flutterPlatformViewsController->RegisterViewFactory(
2478 factory,
@"MockFlutterPlatformView",
2482 flutterPlatformViewsController->OnMethodCall(
2484 methodCallWithMethodName:
@"create"
2485 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2492 while (touchInteceptorView != nil &&
2494 touchInteceptorView = touchInteceptorView.superview;
2496 XCTAssertNotNil(touchInteceptorView);
2499 UIGestureRecognizer* forwardGectureRecognizer = nil;
2500 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2501 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2502 forwardGectureRecognizer = gestureRecognizer;
2508 NSSet* touches1 = [[NSSet alloc] init];
2509 id event1 = OCMClassMock([UIEvent
class]);
2511 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2512 OCMReject([flutterViewContoller touchesBegan:touches1 withEvent:event1]);
2515 NSSet* touches2 = [[NSSet alloc] init];
2516 id event2 = OCMClassMock([UIEvent
class]);
2517 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller);
2518 [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2];
2519 OCMVerify([flutterViewContoller touchesBegan:touches2 withEvent:event2]);
2522 - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGesturesToBeHandled {
2523 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2525 flutter::TaskRunners runners(
self.name.UTF8String,
2526 GetDefaultTaskRunner(),
2527 GetDefaultTaskRunner(),
2528 GetDefaultTaskRunner(),
2529 GetDefaultTaskRunner());
2530 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2531 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2532 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2534 mock_delegate.settings_.enable_impeller
2537 flutterPlatformViewsController,
2540 std::make_shared<fml::SyncSwitch>());
2544 flutterPlatformViewsController->RegisterViewFactory(
2545 factory,
@"MockFlutterPlatformView",
2549 flutterPlatformViewsController->OnMethodCall(
2551 methodCallWithMethodName:
@"create"
2552 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2559 while (touchInteceptorView != nil &&
2561 touchInteceptorView = touchInteceptorView.superview;
2563 XCTAssertNotNil(touchInteceptorView);
2566 UIGestureRecognizer* forwardGectureRecognizer = nil;
2567 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2568 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2569 forwardGectureRecognizer = gestureRecognizer;
2576 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller);
2578 NSSet* touches1 = [[NSSet alloc] init];
2579 id event1 = OCMClassMock([UIEvent
class]);
2580 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2581 OCMVerify([flutterViewContoller touchesBegan:touches1 withEvent:event1]);
2583 flutterPlatformViewsController->SetFlutterViewController(nil);
2586 NSSet* touches2 = [[NSSet alloc] init];
2587 id event2 = OCMClassMock([UIEvent
class]);
2588 [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2];
2589 OCMVerify([flutterViewContoller touchesMoved:touches2 withEvent:event2]);
2591 NSSet* touches3 = [[NSSet alloc] init];
2592 id event3 = OCMClassMock([UIEvent
class]);
2593 [forwardGectureRecognizer touchesEnded:touches3 withEvent:event3];
2594 OCMVerify([flutterViewContoller touchesEnded:touches3 withEvent:event3]);
2597 NSSet* touches4 = [[NSSet alloc] init];
2598 id event4 = OCMClassMock([UIEvent
class]);
2599 [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4];
2600 OCMReject([flutterViewContoller touchesBegan:touches4 withEvent:event4]);
2602 NSSet* touches5 = [[NSSet alloc] init];
2603 id event5 = OCMClassMock([UIEvent
class]);
2604 [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5];
2605 OCMReject([flutterViewContoller touchesEnded:touches5 withEvent:event5]);
2610 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller);
2612 NSSet* touches1 = [[NSSet alloc] init];
2613 id event1 = OCMClassMock([UIEvent
class]);
2614 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2615 OCMVerify([flutterViewContoller touchesBegan:touches1 withEvent:event1]);
2617 flutterPlatformViewsController->SetFlutterViewController(nil);
2620 NSSet* touches2 = [[NSSet alloc] init];
2621 id event2 = OCMClassMock([UIEvent
class]);
2622 [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2];
2623 OCMVerify([flutterViewContoller touchesMoved:touches2 withEvent:event2]);
2625 NSSet* touches3 = [[NSSet alloc] init];
2626 id event3 = OCMClassMock([UIEvent
class]);
2627 [forwardGectureRecognizer touchesCancelled:touches3 withEvent:event3];
2628 OCMVerify([flutterViewContoller forceTouchesCancelled:touches3]);
2631 NSSet* touches4 = [[NSSet alloc] init];
2632 id event4 = OCMClassMock([UIEvent
class]);
2633 [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4];
2634 OCMReject([flutterViewContoller touchesBegan:touches4 withEvent:event4]);
2636 NSSet* touches5 = [[NSSet alloc] init];
2637 id event5 = OCMClassMock([UIEvent
class]);
2638 [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5];
2639 OCMReject([flutterViewContoller touchesEnded:touches5 withEvent:event5]);
2642 flutterPlatformViewsController->Reset();
2646 testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence {
2647 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2649 flutter::TaskRunners runners(
self.name.UTF8String,
2650 GetDefaultTaskRunner(),
2651 GetDefaultTaskRunner(),
2652 GetDefaultTaskRunner(),
2653 GetDefaultTaskRunner());
2654 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2655 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2656 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2658 mock_delegate.settings_.enable_impeller
2661 flutterPlatformViewsController,
2664 std::make_shared<fml::SyncSwitch>());
2668 flutterPlatformViewsController->RegisterViewFactory(
2669 factory,
@"MockFlutterPlatformView",
2673 flutterPlatformViewsController->OnMethodCall(
2675 methodCallWithMethodName:
@"create"
2676 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2683 while (touchInteceptorView != nil &&
2685 touchInteceptorView = touchInteceptorView.superview;
2687 XCTAssertNotNil(touchInteceptorView);
2690 UIGestureRecognizer* forwardGectureRecognizer = nil;
2691 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2692 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2693 forwardGectureRecognizer = gestureRecognizer;
2699 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller);
2702 NSSet* touches1 = [NSSet setWithObject:@1];
2703 id event1 = OCMClassMock([UIEvent
class]);
2704 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2705 OCMVerify([flutterViewContoller touchesBegan:touches1 withEvent:event1]);
2708 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller2);
2712 NSSet* touches2 = [NSSet setWithObject:@1];
2713 id event2 = OCMClassMock([UIEvent
class]);
2714 [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2];
2715 OCMVerify([flutterViewContoller touchesBegan:touches2 withEvent:event2]);
2716 OCMReject([flutterViewContoller2 touchesBegan:touches2 withEvent:event2]);
2718 NSSet* touches3 = [NSSet setWithObject:@1];
2719 id event3 = OCMClassMock([UIEvent
class]);
2720 [forwardGectureRecognizer touchesMoved:touches3 withEvent:event3];
2721 OCMVerify([flutterViewContoller touchesMoved:touches3 withEvent:event3]);
2722 OCMReject([flutterViewContoller2 touchesMoved:touches3 withEvent:event3]);
2724 NSSet* touches4 = [NSSet setWithObject:@1];
2725 id event4 = OCMClassMock([UIEvent
class]);
2726 [forwardGectureRecognizer touchesEnded:touches4 withEvent:event4];
2727 OCMVerify([flutterViewContoller touchesEnded:touches4 withEvent:event4]);
2728 OCMReject([flutterViewContoller2 touchesEnded:touches4 withEvent:event4]);
2730 NSSet* touches5 = [NSSet setWithObject:@1];
2731 id event5 = OCMClassMock([UIEvent
class]);
2732 [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5];
2733 OCMVerify([flutterViewContoller touchesEnded:touches5 withEvent:event5]);
2734 OCMReject([flutterViewContoller2 touchesEnded:touches5 withEvent:event5]);
2738 NSSet* touches6 = [NSSet setWithObject:@1];
2739 id event6 = OCMClassMock([UIEvent
class]);
2740 [forwardGectureRecognizer touchesBegan:touches6 withEvent:event6];
2741 OCMVerify([flutterViewContoller2 touchesBegan:touches6 withEvent:event6]);
2742 OCMReject([flutterViewContoller touchesBegan:touches6 withEvent:event6]);
2745 NSSet* touches7 = [NSSet setWithObject:@1];
2746 id event7 = OCMClassMock([UIEvent
class]);
2747 [forwardGectureRecognizer touchesMoved:touches7 withEvent:event7];
2748 OCMVerify([flutterViewContoller2 touchesMoved:touches7 withEvent:event7]);
2749 OCMReject([flutterViewContoller touchesMoved:touches7 withEvent:event7]);
2751 NSSet* touches8 = [NSSet setWithObject:@1];
2752 id event8 = OCMClassMock([UIEvent
class]);
2753 [forwardGectureRecognizer touchesEnded:touches8 withEvent:event8];
2754 OCMVerify([flutterViewContoller2 touchesEnded:touches8 withEvent:event8]);
2755 OCMReject([flutterViewContoller touchesEnded:touches8 withEvent:event8]);
2757 flutterPlatformViewsController->Reset();
2760 - (void)testFlutterPlatformViewTouchesCancelledEventAreForcedToBeCancelled {
2761 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2763 flutter::TaskRunners runners(
self.name.UTF8String,
2764 GetDefaultTaskRunner(),
2765 GetDefaultTaskRunner(),
2766 GetDefaultTaskRunner(),
2767 GetDefaultTaskRunner());
2768 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2769 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2770 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2772 mock_delegate.settings_.enable_impeller
2775 flutterPlatformViewsController,
2778 std::make_shared<fml::SyncSwitch>());
2782 flutterPlatformViewsController->RegisterViewFactory(
2783 factory,
@"MockFlutterPlatformView",
2787 flutterPlatformViewsController->OnMethodCall(
2789 methodCallWithMethodName:
@"create"
2790 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2797 while (touchInteceptorView != nil &&
2799 touchInteceptorView = touchInteceptorView.superview;
2801 XCTAssertNotNil(touchInteceptorView);
2804 UIGestureRecognizer* forwardGectureRecognizer = nil;
2805 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2806 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2807 forwardGectureRecognizer = gestureRecognizer;
2813 flutterPlatformViewsController->SetFlutterViewController(flutterViewContoller);
2815 NSSet* touches1 = [NSSet setWithObject:@1];
2816 id event1 = OCMClassMock([UIEvent
class]);
2817 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2819 [forwardGectureRecognizer touchesCancelled:touches1 withEvent:event1];
2820 OCMVerify([flutterViewContoller forceTouchesCancelled:touches1]);
2822 flutterPlatformViewsController->Reset();
2826 testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldRemoveAndAddBackDelayingRecognizerForWebView {
2827 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2829 flutter::TaskRunners runners(
self.name.UTF8String,
2830 GetDefaultTaskRunner(),
2831 GetDefaultTaskRunner(),
2832 GetDefaultTaskRunner(),
2833 GetDefaultTaskRunner());
2834 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2835 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2836 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2838 mock_delegate.settings_.enable_impeller
2841 flutterPlatformViewsController,
2844 std::make_shared<fml::SyncSwitch>());
2848 flutterPlatformViewsController->RegisterViewFactory(
2852 flutterPlatformViewsController->OnMethodCall(
2854 arguments:@{
@"id" : @2,
@"viewType" :
@"MockWebView"}],
2861 while (touchInteceptorView != nil &&
2863 touchInteceptorView = touchInteceptorView.superview;
2865 XCTAssertNotNil(touchInteceptorView);
2867 XCTAssert(touchInteceptorView.gestureRecognizers.count == 2);
2868 UIGestureRecognizer* delayingRecognizer = touchInteceptorView.gestureRecognizers[0];
2869 UIGestureRecognizer* forwardingRecognizer = touchInteceptorView.gestureRecognizers[1];
2876 if (@available(iOS 18.2, *)) {
2878 XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], forwardingRecognizer);
2879 XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], delayingRecognizer);
2881 XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], delayingRecognizer);
2882 XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], forwardingRecognizer);
2887 testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldNotRemoveAndAddBackDelayingRecognizerForNonWebView {
2888 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2890 flutter::TaskRunners runners(
self.name.UTF8String,
2891 GetDefaultTaskRunner(),
2892 GetDefaultTaskRunner(),
2893 GetDefaultTaskRunner(),
2894 GetDefaultTaskRunner());
2895 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2896 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2897 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2899 mock_delegate.settings_.enable_impeller
2902 flutterPlatformViewsController,
2905 std::make_shared<fml::SyncSwitch>());
2909 flutterPlatformViewsController->RegisterViewFactory(
2910 factory,
@"MockFlutterPlatformView",
2914 flutterPlatformViewsController->OnMethodCall(
2916 methodCallWithMethodName:
@"create"
2917 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2924 while (touchInteceptorView != nil &&
2926 touchInteceptorView = touchInteceptorView.superview;
2928 XCTAssertNotNil(touchInteceptorView);
2930 XCTAssert(touchInteceptorView.gestureRecognizers.count == 2);
2931 UIGestureRecognizer* delayingRecognizer = touchInteceptorView.gestureRecognizers[0];
2932 UIGestureRecognizer* forwardingRecognizer = touchInteceptorView.gestureRecognizers[1];
2939 XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], delayingRecognizer);
2940 XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], forwardingRecognizer);
2943 - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashing {
2944 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2946 flutter::TaskRunners runners(
self.name.UTF8String,
2947 GetDefaultTaskRunner(),
2948 GetDefaultTaskRunner(),
2949 GetDefaultTaskRunner(),
2950 GetDefaultTaskRunner());
2951 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
2952 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
2953 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2955 mock_delegate.settings_.enable_impeller
2958 flutterPlatformViewsController,
2961 std::make_shared<fml::SyncSwitch>());
2965 flutterPlatformViewsController->RegisterViewFactory(
2966 factory,
@"MockFlutterPlatformView",
2970 flutterPlatformViewsController->OnMethodCall(
2972 methodCallWithMethodName:
@"create"
2973 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2979 flutter::MutatorsStack stack;
2980 SkMatrix finalMatrix;
2982 auto embeddedViewParams_1 =
2983 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
2985 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_1));
2986 flutterPlatformViewsController->CompositeWithParams(
2987 2, flutterPlatformViewsController->GetCompositionParams(2));
2989 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
2990 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
2991 nullptr, framebuffer_info,
2992 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return false; },
2993 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
2994 SkISize::Make(800, 600));
2996 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
2998 auto embeddedViewParams_2 =
2999 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3000 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_2));
3001 flutterPlatformViewsController->CompositeWithParams(
3002 2, flutterPlatformViewsController->GetCompositionParams(2));
3004 auto mock_surface_submit_true = std::make_unique<flutter::SurfaceFrame>(
3005 nullptr, framebuffer_info,
3006 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3007 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3008 SkISize::Make(800, 600));
3009 XCTAssertTrue(flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr,
3010 std::move(mock_surface_submit_true)));
3014 testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView {
3015 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3017 flutter::TaskRunners runners(
self.name.UTF8String,
3018 GetDefaultTaskRunner(),
3019 GetDefaultTaskRunner(),
3020 GetDefaultTaskRunner(),
3021 GetDefaultTaskRunner());
3022 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3023 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3024 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3026 mock_delegate.settings_.enable_impeller
3029 flutterPlatformViewsController,
3032 std::make_shared<fml::SyncSwitch>());
3034 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3035 flutterPlatformViewsController->SetFlutterView(flutterView);
3039 flutterPlatformViewsController->RegisterViewFactory(
3040 factory,
@"MockFlutterPlatformView",
3046 flutterPlatformViewsController->OnMethodCall(
3048 methodCallWithMethodName:
@"create"
3049 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3052 flutter::MutatorsStack stack;
3053 SkMatrix finalMatrix;
3054 auto embeddedViewParams =
3055 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3056 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
3062 flutterPlatformViewsController->Reset();
3067 - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
3068 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3070 flutter::TaskRunners runners(
self.name.UTF8String,
3071 GetDefaultTaskRunner(),
3072 GetDefaultTaskRunner(),
3073 GetDefaultTaskRunner(),
3074 GetDefaultTaskRunner());
3075 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3076 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3077 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3079 mock_delegate.settings_.enable_impeller
3082 flutterPlatformViewsController,
3085 std::make_shared<fml::SyncSwitch>());
3087 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3088 flutterPlatformViewsController->SetFlutterView(flutterView);
3092 flutterPlatformViewsController->RegisterViewFactory(
3093 factory,
@"MockFlutterPlatformView",
3098 flutterPlatformViewsController->OnMethodCall(
3100 methodCallWithMethodName:
@"create"
3101 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
3105 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3106 flutter::MutatorsStack stack;
3107 SkMatrix finalMatrix;
3108 auto embeddedViewParams1 =
3109 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3110 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3111 flutterPlatformViewsController->CompositeWithParams(
3112 0, flutterPlatformViewsController->GetCompositionParams(0));
3114 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL);
3117 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3118 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 0UL);
3120 auto embeddedViewParams2 =
3121 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3122 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams2));
3123 flutterPlatformViewsController->CompositeWithParams(
3124 0, flutterPlatformViewsController->GetCompositionParams(0));
3126 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL);
3130 testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy {
3131 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3133 flutter::TaskRunners runners(
self.name.UTF8String,
3134 GetDefaultTaskRunner(),
3135 GetDefaultTaskRunner(),
3136 GetDefaultTaskRunner(),
3137 GetDefaultTaskRunner());
3138 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3139 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3140 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3142 mock_delegate.settings_.enable_impeller
3145 flutterPlatformViewsController,
3148 std::make_shared<fml::SyncSwitch>());
3150 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3151 flutterPlatformViewsController->SetFlutterView(flutterView);
3155 flutterPlatformViewsController->RegisterViewFactory(
3156 factory,
@"MockFlutterPlatformView",
3160 flutterPlatformViewsController->OnMethodCall(
3162 methodCallWithMethodName:
@"create"
3163 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
3168 flutterPlatformViewsController->OnMethodCall(
3170 methodCallWithMethodName:
@"create"
3171 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3175 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3176 flutter::MutatorsStack stack;
3177 SkMatrix finalMatrix;
3178 auto embeddedViewParams1 =
3179 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3180 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3182 auto embeddedViewParams2 =
3183 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
3184 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
3187 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3188 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3189 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3190 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3191 std::move(mock_sk_surface), framebuffer_info,
3192 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3193 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3194 SkISize::Make(800, 600));
3197 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3200 UIView* clippingView1 = view1.superview.superview;
3201 UIView* clippingView2 = view2.superview.superview;
3202 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
3203 [flutterView.subviews indexOfObject:clippingView2],
3204 @"The first clipping view should be added before the second clipping view.");
3207 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3209 embeddedViewParams2 =
3210 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
3211 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
3213 embeddedViewParams1 =
3214 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3215 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3217 mock_sk_surface = SkSurfaces::Raster(image_info);
3218 mock_surface = std::make_unique<flutter::SurfaceFrame>(
3219 std::move(mock_sk_surface), framebuffer_info,
3220 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3221 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3222 SkISize::Make(800, 600));
3224 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3226 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] >
3227 [flutterView.subviews indexOfObject:clippingView2],
3228 @"The first clipping view should be added after the second clipping view.");
3232 testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy {
3233 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3235 flutter::TaskRunners runners(
self.name.UTF8String,
3236 GetDefaultTaskRunner(),
3237 GetDefaultTaskRunner(),
3238 GetDefaultTaskRunner(),
3239 GetDefaultTaskRunner());
3240 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3241 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3242 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3244 mock_delegate.settings_.enable_impeller
3247 flutterPlatformViewsController,
3250 std::make_shared<fml::SyncSwitch>());
3252 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3253 flutterPlatformViewsController->SetFlutterView(flutterView);
3257 flutterPlatformViewsController->RegisterViewFactory(
3258 factory,
@"MockFlutterPlatformView",
3262 flutterPlatformViewsController->OnMethodCall(
3264 methodCallWithMethodName:
@"create"
3265 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
3270 flutterPlatformViewsController->OnMethodCall(
3272 methodCallWithMethodName:
@"create"
3273 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3277 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3278 flutter::MutatorsStack stack;
3279 SkMatrix finalMatrix;
3280 auto embeddedViewParams1 =
3281 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3282 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3284 auto embeddedViewParams2 =
3285 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
3286 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
3289 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3290 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3291 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3292 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3293 std::move(mock_sk_surface), framebuffer_info,
3294 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3295 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3296 SkISize::Make(800, 600));
3299 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3302 UIView* clippingView1 = view1.superview.superview;
3303 UIView* clippingView2 = view2.superview.superview;
3304 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
3305 [flutterView.subviews indexOfObject:clippingView2],
3306 @"The first clipping view should be added before the second clipping view.");
3309 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3311 embeddedViewParams1 =
3312 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3313 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3315 embeddedViewParams2 =
3316 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
3317 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
3319 mock_sk_surface = SkSurfaces::Raster(image_info);
3320 mock_surface = std::make_unique<flutter::SurfaceFrame>(
3321 std::move(mock_sk_surface), framebuffer_info,
3322 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3323 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3324 SkISize::Make(800, 600));
3326 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3328 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
3329 [flutterView.subviews indexOfObject:clippingView2],
3330 @"The first clipping view should be added before the second clipping view.");
3333 - (int)alphaOfPoint:(CGPoint)point onView:(UIView*)view {
3334 unsigned char pixel[4] = {0};
3336 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
3339 CGContextRef context = CGBitmapContextCreate(
3340 pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast);
3341 CGContextTranslateCTM(context, -point.x, -point.y);
3342 [view.layer renderInContext:context];
3344 CGContextRelease(context);
3345 CGColorSpaceRelease(colorSpace);
3350 - (void)testHasFirstResponderInViewHierarchySubtree_viewItselfBecomesFirstResponder {
3352 UIWindow* window = [[UIWindow alloc] init];
3353 UITextField* textField = [[UITextField alloc] init];
3354 [window addSubview:textField];
3356 [textField becomeFirstResponder];
3357 XCTAssertTrue(textField.isFirstResponder);
3358 XCTAssertTrue(textField.flt_hasFirstResponderInViewHierarchySubtree);
3359 [textField resignFirstResponder];
3360 XCTAssertFalse(textField.isFirstResponder);
3361 XCTAssertFalse(textField.flt_hasFirstResponderInViewHierarchySubtree);
3364 - (void)testHasFirstResponderInViewHierarchySubtree_descendantViewBecomesFirstResponder {
3366 UIWindow* window = [[UIWindow alloc] init];
3367 UIView* view = [[UIView alloc] init];
3368 UIView* childView = [[UIView alloc] init];
3369 UITextField* textField = [[UITextField alloc] init];
3370 [window addSubview:view];
3371 [view addSubview:childView];
3372 [childView addSubview:textField];
3374 [textField becomeFirstResponder];
3375 XCTAssertTrue(textField.isFirstResponder);
3376 XCTAssertTrue(view.flt_hasFirstResponderInViewHierarchySubtree);
3377 [textField resignFirstResponder];
3378 XCTAssertFalse(textField.isFirstResponder);
3379 XCTAssertFalse(view.flt_hasFirstResponderInViewHierarchySubtree);
3382 - (void)testFlutterClippingMaskViewPoolReuseViewsAfterRecycle {
3388 CGRect newRect = CGRectMake(0, 0, 10, 10);
3392 NSSet* set1 = [NSSet setWithObjects:view1, view2, nil];
3393 NSSet* set2 = [NSSet setWithObjects:view3, view4, nil];
3394 XCTAssertEqualObjects(set1, set2);
3395 XCTAssertTrue(CGRectEqualToRect(view3.frame, newRect));
3396 XCTAssertTrue(CGRectEqualToRect(view4.frame, newRect));
3399 - (void)testFlutterClippingMaskViewPoolAllocsNewMaskViewsAfterReachingCapacity {
3404 XCTAssertNotEqual(view1, view3);
3405 XCTAssertNotEqual(view2, view3);
3408 - (void)testMaskViewsReleasedWhenPoolIsReleased {
3409 __weak UIView* weakView;
3414 XCTAssertNotNil(weakView);
3416 XCTAssertNil(weakView);
3419 - (void)testClipMaskViewIsReused {
3420 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3422 flutter::TaskRunners runners(
self.name.UTF8String,
3423 GetDefaultTaskRunner(),
3424 GetDefaultTaskRunner(),
3425 GetDefaultTaskRunner(),
3426 GetDefaultTaskRunner());
3427 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3428 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3429 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3431 mock_delegate.settings_.enable_impeller
3434 flutterPlatformViewsController,
3437 std::make_shared<fml::SyncSwitch>());
3441 flutterPlatformViewsController->RegisterViewFactory(
3442 factory,
@"MockFlutterPlatformView",
3446 flutterPlatformViewsController->OnMethodCall(
3448 methodCallWithMethodName:
@"create"
3449 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3453 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
3454 flutterPlatformViewsController->SetFlutterView(flutterView);
3456 flutter::MutatorsStack stack1;
3458 SkMatrix screenScaleMatrix =
3459 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3460 stack1.PushTransform(screenScaleMatrix);
3462 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
3463 stack1.PushClipRect(rect);
3465 auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
3466 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3468 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3469 flutterPlatformViewsController->CompositeWithParams(
3470 1, flutterPlatformViewsController->GetCompositionParams(1));
3473 UIView* maskView1 = childClippingView1.maskView;
3474 XCTAssertNotNil(maskView1);
3477 flutterPlatformViewsController->BeginFrame(SkISize::Make(100, 100));
3478 flutter::MutatorsStack stack2;
3479 auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
3480 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3481 auto embeddedViewParams3 = std::make_unique<flutter::EmbeddedViewParams>(
3482 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3483 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams3));
3484 flutterPlatformViewsController->CompositeWithParams(
3485 1, flutterPlatformViewsController->GetCompositionParams(1));
3490 flutterPlatformViewsController->OnMethodCall(
3492 methodCallWithMethodName:
@"create"
3493 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3496 auto embeddedViewParams4 = std::make_unique<flutter::EmbeddedViewParams>(
3497 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3498 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams4));
3499 flutterPlatformViewsController->CompositeWithParams(
3500 2, flutterPlatformViewsController->GetCompositionParams(2));
3504 UIView* maskView2 = childClippingView2.maskView;
3505 XCTAssertEqual(maskView1, maskView2);
3506 XCTAssertNotNil(childClippingView2.maskView);
3507 XCTAssertNil(childClippingView1.maskView);
3510 - (void)testDifferentClipMaskViewIsUsedForEachView {
3511 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3513 flutter::TaskRunners runners(
self.name.UTF8String,
3514 GetDefaultTaskRunner(),
3515 GetDefaultTaskRunner(),
3516 GetDefaultTaskRunner(),
3517 GetDefaultTaskRunner());
3518 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3519 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3520 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3522 mock_delegate.settings_.enable_impeller
3525 flutterPlatformViewsController,
3528 std::make_shared<fml::SyncSwitch>());
3532 flutterPlatformViewsController->RegisterViewFactory(
3533 factory,
@"MockFlutterPlatformView",
3538 flutterPlatformViewsController->OnMethodCall(
3540 methodCallWithMethodName:
@"create"
3541 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3546 flutterPlatformViewsController->OnMethodCall(
3548 methodCallWithMethodName:
@"create"
3549 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3554 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
3555 flutterPlatformViewsController->SetFlutterView(flutterView);
3557 flutter::MutatorsStack stack1;
3559 SkMatrix screenScaleMatrix =
3560 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3561 stack1.PushTransform(screenScaleMatrix);
3563 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
3564 stack1.PushClipRect(rect);
3566 auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
3567 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3569 flutter::MutatorsStack stack2;
3570 stack2.PushClipRect(rect);
3571 auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
3572 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3574 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3575 flutterPlatformViewsController->CompositeWithParams(
3576 1, flutterPlatformViewsController->GetCompositionParams(1));
3578 UIView* childClippingView1 = view1.superview.superview;
3580 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2));
3581 flutterPlatformViewsController->CompositeWithParams(
3582 2, flutterPlatformViewsController->GetCompositionParams(2));
3584 UIView* childClippingView2 = view2.superview.superview;
3585 UIView* maskView1 = childClippingView1.maskView;
3586 UIView* maskView2 = childClippingView2.maskView;
3587 XCTAssertNotEqual(maskView1, maskView2);
3590 - (void)testMaskViewUsesCAShapeLayerAsTheBackingLayer {
3591 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3593 flutter::TaskRunners runners(
self.name.UTF8String,
3594 GetDefaultTaskRunner(),
3595 GetDefaultTaskRunner(),
3596 GetDefaultTaskRunner(),
3597 GetDefaultTaskRunner());
3598 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3599 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3600 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3602 mock_delegate.settings_.enable_impeller
3605 flutterPlatformViewsController,
3608 std::make_shared<fml::SyncSwitch>());
3612 flutterPlatformViewsController->RegisterViewFactory(
3613 factory,
@"MockFlutterPlatformView",
3618 flutterPlatformViewsController->OnMethodCall(
3620 methodCallWithMethodName:
@"create"
3621 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3625 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
3626 flutterPlatformViewsController->SetFlutterView(flutterView);
3628 flutter::MutatorsStack stack1;
3630 SkMatrix screenScaleMatrix =
3631 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3632 stack1.PushTransform(screenScaleMatrix);
3634 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
3635 stack1.PushClipRect(rect);
3637 auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
3638 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3640 flutter::MutatorsStack stack2;
3641 stack2.PushClipRect(rect);
3642 auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
3643 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3645 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3646 flutterPlatformViewsController->CompositeWithParams(
3647 1, flutterPlatformViewsController->GetCompositionParams(1));
3651 UIView* maskView = childClippingView.maskView;
3652 XCTAssert([maskView.layer isKindOfClass:[CAShapeLayer
class]],
3653 @"Mask view must use CAShapeLayer as its backing layer.");
3661 - (BOOL)validateOneVisualEffectView:(UIView*)visualEffectView
3662 expectedFrame:(CGRect)frame
3663 inputRadius:(CGFloat)inputRadius {
3664 XCTAssertTrue(CGRectEqualToRect(visualEffectView.frame, frame));
3665 for (UIView* view in visualEffectView.subviews) {
3666 if (![NSStringFromClass([view
class]) hasSuffix:
@"BackdropView"]) {
3669 XCTAssertEqual(view.layer.filters.count, 1u);
3670 NSObject* filter = view.layer.filters.firstObject;
3672 XCTAssertEqualObjects([filter valueForKey:
@"name"],
@"gaussianBlur");
3674 NSObject* inputRadiusInFilter = [filter valueForKey:@"inputRadius"];
3675 XCTAssertTrue([inputRadiusInFilter isKindOfClass:[NSNumber
class]] &&
3676 flutter::BlurRadiusEqualToBlurRadius(((NSNumber*)inputRadiusInFilter).floatValue,
3683 - (void)testDisposingViewInCompositionOrderDoNotCrash {
3684 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3686 flutter::TaskRunners runners(
self.name.UTF8String,
3687 GetDefaultTaskRunner(),
3688 GetDefaultTaskRunner(),
3689 GetDefaultTaskRunner(),
3690 GetDefaultTaskRunner());
3691 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3692 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3693 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3695 mock_delegate.settings_.enable_impeller
3698 flutterPlatformViewsController,
3701 std::make_shared<fml::SyncSwitch>());
3703 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3704 flutterPlatformViewsController->SetFlutterView(flutterView);
3708 flutterPlatformViewsController->RegisterViewFactory(
3709 factory,
@"MockFlutterPlatformView",
3714 flutterPlatformViewsController->OnMethodCall(
3716 methodCallWithMethodName:
@"create"
3717 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
3719 flutterPlatformViewsController->OnMethodCall(
3721 methodCallWithMethodName:
@"create"
3722 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3728 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3729 flutter::MutatorsStack stack;
3730 SkMatrix finalMatrix;
3731 auto embeddedViewParams0 =
3732 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3733 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams0));
3735 auto embeddedViewParams1 =
3736 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3737 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3739 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL);
3741 XCTestExpectation* expectation = [
self expectationWithDescription:@"dispose call ended."];
3743 [expectation fulfill];
3746 flutterPlatformViewsController->OnMethodCall(
3747 [
FlutterMethodCall methodCallWithMethodName:
@"dispose" arguments:@0], disposeResult);
3748 [
self waitForExpectationsWithTimeout:30 handler:nil];
3750 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3751 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3752 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3753 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3754 std::move(mock_sk_surface), framebuffer_info,
3755 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3756 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3757 SkISize::Make(800, 600));
3759 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3762 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL);
3763 XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(0));
3764 XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1));
3770 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3771 flutter::MutatorsStack stack;
3772 SkMatrix finalMatrix;
3773 auto embeddedViewParams1 =
3774 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3775 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3777 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3778 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3779 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3780 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3781 std::move(mock_sk_surface), framebuffer_info,
3782 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3783 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3784 SkISize::Make(800, 600));
3786 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3789 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL);
3790 XCTAssertNil(flutterPlatformViewsController->GetPlatformViewByID(0));
3791 XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1));
3794 - (void)testOnlyPlatformViewsAreRemovedWhenReset {
3795 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3797 flutter::TaskRunners runners(
self.name.UTF8String,
3798 GetDefaultTaskRunner(),
3799 GetDefaultTaskRunner(),
3800 GetDefaultTaskRunner(),
3801 GetDefaultTaskRunner());
3802 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3803 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3804 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3806 mock_delegate.settings_.enable_impeller
3809 flutterPlatformViewsController,
3812 std::make_shared<fml::SyncSwitch>());
3816 flutterPlatformViewsController->RegisterViewFactory(
3817 factory,
@"MockFlutterPlatformView",
3821 flutterPlatformViewsController->OnMethodCall(
3823 methodCallWithMethodName:
@"create"
3824 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3826 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3827 flutterPlatformViewsController->SetFlutterView(flutterView);
3829 flutter::MutatorsStack stack;
3831 SkMatrix screenScaleMatrix =
3832 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3833 stack.PushTransform(screenScaleMatrix);
3835 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
3836 stack.PushTransform(translateMatrix);
3837 SkMatrix finalMatrix;
3838 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
3840 auto embeddedViewParams =
3841 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3843 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
3846 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3847 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3848 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3849 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3850 std::move(mock_sk_surface), framebuffer_info,
3851 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3852 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3853 SkISize::Make(800, 600));
3855 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface));
3857 UIView* someView = [[UIView alloc] init];
3858 [flutterView addSubview:someView];
3860 flutterPlatformViewsController->Reset();
3861 XCTAssertEqual(flutterView.subviews.count, 1u);
3862 XCTAssertEqual(flutterView.subviews.firstObject, someView);
3865 - (void)testNilPlatformViewDoesntCrash {
3866 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3868 flutter::TaskRunners runners(
self.name.UTF8String,
3869 GetDefaultTaskRunner(),
3870 GetDefaultTaskRunner(),
3871 GetDefaultTaskRunner(),
3872 GetDefaultTaskRunner());
3873 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3874 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3875 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3877 mock_delegate.settings_.enable_impeller
3880 flutterPlatformViewsController,
3883 std::make_shared<fml::SyncSwitch>());
3887 flutterPlatformViewsController->RegisterViewFactory(
3888 factory,
@"MockFlutterPlatformView",
3892 flutterPlatformViewsController->OnMethodCall(
3894 methodCallWithMethodName:
@"create"
3895 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3897 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3898 flutterPlatformViewsController->SetFlutterView(flutterView);
3901 flutter::MutatorsStack stack;
3903 SkMatrix screenScaleMatrix =
3904 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3905 stack.PushTransform(screenScaleMatrix);
3907 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
3908 stack.PushTransform(translateMatrix);
3909 SkMatrix finalMatrix;
3910 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
3912 auto embeddedViewParams =
3913 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3915 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
3918 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3919 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3920 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3921 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3922 std::move(mock_sk_surface), framebuffer_info,
3923 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3924 [](
const flutter::SurfaceFrame& surface_frame) {
return true; },
3925 SkISize::Make(800, 600));
3927 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface));
3929 XCTAssertEqual(flutterView.subviews.count, 1u);
3932 - (void)testFlutterTouchInterceptingViewLinksToAccessibilityContainer {
3934 NSObject* container = [[NSObject alloc] init];
3935 [touchInteceptorView setFlutterAccessibilityContainer:container];
3936 XCTAssertEqualObjects([touchInteceptorView accessibilityContainer], container);
3939 - (void)testLayerPool {
3943 XCTAssertTrue([
engine iosPlatformView] !=
nullptr);
3944 auto ios_context = [engine iosPlatformView]->GetIosContext();
3945 auto gr_context = ios_context->GetMainContext();
3950 pool.
CreateLayer(gr_context.get(), ios_context, MTLPixelFormatBGRA8Unorm);
3951 XCTAssertEqual(pool.size(), 1u);
3952 pool.CreateLayer(gr_context.get(), ios_context, MTLPixelFormatBGRA8Unorm);
3953 XCTAssertEqual(pool.size(), 2u);
3956 pool.RecycleLayers();
3957 XCTAssertEqual(pool.size(), 2u);
3960 auto unused_layers = pool.RemoveUnusedLayers();
3961 XCTAssertEqual(unused_layers.size(), 2u);
3962 XCTAssertEqual(pool.size(), 1u);
3965 - (void)testFlutterPlatformViewControllerSubmitFramePreservingFrameDamage {
3966 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3968 flutter::TaskRunners runners(
self.name.UTF8String,
3969 GetDefaultTaskRunner(),
3970 GetDefaultTaskRunner(),
3971 GetDefaultTaskRunner(),
3972 GetDefaultTaskRunner());
3973 auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3974 flutterPlatformViewsController->SetTaskRunner(GetDefaultTaskRunner());
3975 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3977 mock_delegate.settings_.enable_impeller
3980 flutterPlatformViewsController,
3983 std::make_shared<fml::SyncSwitch>());
3985 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3986 flutterPlatformViewsController->SetFlutterView(flutterView);
3990 flutterPlatformViewsController->RegisterViewFactory(
3991 factory,
@"MockFlutterPlatformView",
3995 flutterPlatformViewsController->OnMethodCall(
3997 methodCallWithMethodName:
@"create"
3998 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
4002 flutterPlatformViewsController->OnMethodCall(
4004 methodCallWithMethodName:
@"create"
4005 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
4008 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
4009 flutter::MutatorsStack stack;
4010 SkMatrix finalMatrix;
4011 auto embeddedViewParams1 =
4012 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
4013 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
4015 auto embeddedViewParams2 =
4016 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
4017 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
4020 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
4021 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
4022 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
4023 std::optional<flutter::SurfaceFrame::SubmitInfo> submit_info;
4024 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
4025 std::move(mock_sk_surface), framebuffer_info,
4026 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
4027 [&](
const flutter::SurfaceFrame& surface_frame) {
4028 submit_info = surface_frame.submit_info();
4031 SkISize::Make(800, 600));
4032 mock_surface->set_submit_info({
4033 .frame_damage = SkIRect::MakeWH(800, 600),
4034 .buffer_damage = SkIRect::MakeWH(400, 600),
4038 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
4040 XCTAssertTrue(submit_info.has_value());
4041 XCTAssertEqual(*submit_info->frame_damage, SkIRect::MakeWH(800, 600));
4042 XCTAssertEqual(*submit_info->buffer_damage, SkIRect::MakeWH(400, 600));