5 #import <OCMock/OCMock.h>
6 #import <UIKit/UIKit.h>
7 #import <XCTest/XCTest.h>
9 #import "flutter/fml/thread.h"
27 - (instancetype)init {
42 @property(nonatomic, strong) UIView* view;
43 @property(nonatomic, assign) BOOL viewCreated;
48 - (instancetype)init {
49 if (
self = [super init]) {
57 [
self checkViewCreatedOnce];
61 - (void)checkViewCreatedOnce {
65 self.viewCreated = YES;
71 : NSObject <FlutterPlatformViewFactory>
76 viewIdentifier:(int64_t)viewId
77 arguments:(
id _Nullable)args {
85 class FlutterPlatformViewsTestMockPlatformViewDelegate :
public PlatformView::Delegate {
87 void OnPlatformViewCreated(std::unique_ptr<Surface> surface)
override {}
88 void OnPlatformViewDestroyed()
override {}
89 void OnPlatformViewScheduleFrame()
override {}
90 void OnPlatformViewAddView(int64_t view_id,
91 const ViewportMetrics& viewport_metrics,
92 AddViewCallback callback)
override {}
93 void OnPlatformViewRemoveView(int64_t view_id, RemoveViewCallback callback)
override {}
94 void OnPlatformViewSetNextFrameCallback(
const fml::closure& closure)
override {}
95 void OnPlatformViewSetViewportMetrics(int64_t view_id,
const ViewportMetrics& metrics)
override {}
96 const flutter::Settings& OnPlatformViewGetSettings()
const override {
return settings_; }
97 void OnPlatformViewDispatchPlatformMessage(std::unique_ptr<PlatformMessage> message)
override {}
98 void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet)
override {
100 void OnPlatformViewDispatchSemanticsAction(int32_t
id,
101 SemanticsAction action,
102 fml::MallocMapping args)
override {}
103 void OnPlatformViewSetSemanticsEnabled(
bool enabled)
override {}
104 void OnPlatformViewSetAccessibilityFeatures(int32_t flags)
override {}
105 void OnPlatformViewRegisterTexture(std::shared_ptr<Texture> texture)
override {}
106 void OnPlatformViewUnregisterTexture(int64_t
texture_id)
override {}
107 void OnPlatformViewMarkTextureFrameAvailable(int64_t
texture_id)
override {}
109 void LoadDartDeferredLibrary(intptr_t loading_unit_id,
110 std::unique_ptr<const fml::Mapping> snapshot_data,
111 std::unique_ptr<const fml::Mapping> snapshot_instructions)
override {
113 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
114 const std::string error_message,
115 bool transient)
override {}
116 void UpdateAssetResolverByType(std::unique_ptr<flutter::AssetResolver> updated_asset_resolver,
117 flutter::AssetResolver::AssetResolverType type)
override {}
126 fml::RefPtr<fml::TaskRunner>
CreateNewThread(
const std::string& name) {
127 auto thread = std::make_unique<fml::Thread>(name);
128 auto runner = thread->GetTaskRunner();
138 - (void)testFlutterViewOnlyCreateOnceInOneFrame {
139 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
141 flutter::TaskRunners runners(
self.name.UTF8String,
146 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
147 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
149 mock_delegate.settings_.enable_impeller
152 flutterPlatformViewsController,
155 std::make_shared<fml::SyncSwitch>());
159 flutterPlatformViewsController->RegisterViewFactory(
160 factory,
@"MockFlutterPlatformView",
164 flutterPlatformViewsController->OnMethodCall(
166 methodCallWithMethodName:
@"create"
167 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
169 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
170 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
172 flutter::MutatorsStack stack;
174 SkMatrix screenScaleMatrix =
175 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
176 stack.PushTransform(screenScaleMatrix);
178 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
179 stack.PushTransform(translateMatrix);
180 SkMatrix finalMatrix;
181 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
183 auto embeddedViewParams =
184 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
186 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
187 flutterPlatformViewsController->CompositeEmbeddedView(2);
189 flutterPlatformViewsController->GetPlatformViewRect(2);
193 flutterPlatformViewsController->Reset();
196 - (void)testCanCreatePlatformViewWithoutFlutterView {
197 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
199 flutter::TaskRunners runners(
self.name.UTF8String,
204 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
205 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
207 mock_delegate.settings_.enable_impeller
210 flutterPlatformViewsController,
213 std::make_shared<fml::SyncSwitch>());
217 flutterPlatformViewsController->RegisterViewFactory(
218 factory,
@"MockFlutterPlatformView",
222 flutterPlatformViewsController->OnMethodCall(
224 methodCallWithMethodName:
@"create"
225 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
231 - (void)testChildClippingViewHitTests {
234 UIView* childView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
235 [childClippingView addSubview:childView];
237 XCTAssertFalse([childClippingView pointInside:CGPointMake(50, 50) withEvent:nil]);
238 XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 100) withEvent:nil]);
239 XCTAssertFalse([childClippingView pointInside:CGPointMake(100, 99) withEvent:nil]);
240 XCTAssertFalse([childClippingView pointInside:CGPointMake(201, 200) withEvent:nil]);
241 XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 201) withEvent:nil]);
242 XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 200) withEvent:nil]);
243 XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 299) withEvent:nil]);
245 XCTAssertTrue([childClippingView pointInside:CGPointMake(150, 150) withEvent:nil]);
246 XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 100) withEvent:nil]);
247 XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 100) withEvent:nil]);
248 XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 199) withEvent:nil]);
249 XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 199) withEvent:nil]);
252 - (void)testReleasesBackdropFilterSubviewsOnChildClippingViewDealloc {
253 __weak NSMutableArray<UIVisualEffectView*>* weakBackdropFilterSubviews = nil;
254 __weak UIVisualEffectView* weakVisualEffectView1 = nil;
255 __weak UIVisualEffectView* weakVisualEffectView2 = nil;
259 UIVisualEffectView* visualEffectView1 = [[UIVisualEffectView alloc]
260 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
261 weakVisualEffectView1 = visualEffectView1;
265 visualEffectView:visualEffectView1];
270 UIVisualEffectView* visualEffectView2 = [[UIVisualEffectView alloc]
271 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
272 weakVisualEffectView2 = visualEffectView2;
276 visualEffectView:visualEffectView2];
280 XCTAssertNotNil(weakBackdropFilterSubviews);
283 XCTAssertNil(weakBackdropFilterSubviews);
284 XCTAssertNil(weakVisualEffectView1);
285 XCTAssertNil(weakVisualEffectView2);
288 - (void)testApplyBackdropFilter {
289 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
291 flutter::TaskRunners runners(
self.name.UTF8String,
296 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
297 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
299 mock_delegate.settings_.enable_impeller
302 flutterPlatformViewsController,
305 std::make_shared<fml::SyncSwitch>());
309 flutterPlatformViewsController->RegisterViewFactory(
310 factory,
@"MockFlutterPlatformView",
314 flutterPlatformViewsController->OnMethodCall(
316 methodCallWithMethodName:
@"create"
317 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
322 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
323 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
325 flutter::MutatorsStack stack;
327 CGFloat screenScale = [UIScreen mainScreen].scale;
328 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
329 stack.PushTransform(screenScaleMatrix);
331 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
332 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
334 auto embeddedViewParams =
335 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
337 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
338 flutterPlatformViewsController->CompositeEmbeddedView(2);
341 [mockFlutterView addSubview:childClippingView];
343 [mockFlutterView setNeedsLayout];
344 [mockFlutterView layoutIfNeeded];
347 NSUInteger numberOfExpectedVisualEffectView = 0;
348 for (UIView* subview in childClippingView.subviews) {
349 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
352 XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u);
353 if ([
self validateOneVisualEffectView:subview
354 expectedFrame:CGRectMake(0, 0, 10, 10)
356 numberOfExpectedVisualEffectView++;
359 XCTAssertEqual(numberOfExpectedVisualEffectView, 1u);
362 - (void)testApplyBackdropFilterWithCorrectFrame {
363 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
365 flutter::TaskRunners runners(
self.name.UTF8String,
370 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
371 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
373 mock_delegate.settings_.enable_impeller
376 flutterPlatformViewsController,
379 std::make_shared<fml::SyncSwitch>());
383 flutterPlatformViewsController->RegisterViewFactory(
384 factory,
@"MockFlutterPlatformView",
388 flutterPlatformViewsController->OnMethodCall(
390 methodCallWithMethodName:
@"create"
391 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
396 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
397 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
399 flutter::MutatorsStack stack;
401 CGFloat screenScale = [UIScreen mainScreen].scale;
402 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
403 stack.PushTransform(screenScaleMatrix);
405 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
406 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 8, screenScale * 8));
408 auto embeddedViewParams =
409 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(5, 10), stack);
411 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
412 flutterPlatformViewsController->CompositeEmbeddedView(2);
415 [mockFlutterView addSubview:childClippingView];
417 [mockFlutterView setNeedsLayout];
418 [mockFlutterView layoutIfNeeded];
421 NSUInteger numberOfExpectedVisualEffectView = 0;
422 for (UIView* subview in childClippingView.subviews) {
423 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
426 XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u);
427 if ([
self validateOneVisualEffectView:subview
428 expectedFrame:CGRectMake(0, 0, 5, 8)
430 numberOfExpectedVisualEffectView++;
433 XCTAssertEqual(numberOfExpectedVisualEffectView, 1u);
436 - (void)testApplyMultipleBackdropFilters {
437 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
439 flutter::TaskRunners runners(
self.name.UTF8String,
444 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
445 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
447 mock_delegate.settings_.enable_impeller
450 flutterPlatformViewsController,
453 std::make_shared<fml::SyncSwitch>());
457 flutterPlatformViewsController->RegisterViewFactory(
458 factory,
@"MockFlutterPlatformView",
462 flutterPlatformViewsController->OnMethodCall(
464 methodCallWithMethodName:
@"create"
465 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
470 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
471 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
473 flutter::MutatorsStack stack;
475 CGFloat screenScale = [UIScreen mainScreen].scale;
476 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
477 stack.PushTransform(screenScaleMatrix);
479 for (
int i = 0; i < 50; i++) {
480 auto filter = std::make_shared<flutter::DlBlurImageFilter>(i, 2, flutter::DlTileMode::kClamp);
481 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
484 auto embeddedViewParams =
485 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(20, 20), stack);
487 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
488 flutterPlatformViewsController->CompositeEmbeddedView(2);
491 [mockFlutterView addSubview:childClippingView];
493 [mockFlutterView setNeedsLayout];
494 [mockFlutterView layoutIfNeeded];
496 NSUInteger numberOfExpectedVisualEffectView = 0;
497 for (UIView* subview in childClippingView.subviews) {
498 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
501 XCTAssertLessThan(numberOfExpectedVisualEffectView, 50u);
502 if ([
self validateOneVisualEffectView:subview
503 expectedFrame:CGRectMake(0, 0, 10, 10)
504 inputRadius:(CGFloat)numberOfExpectedVisualEffectView]) {
505 numberOfExpectedVisualEffectView++;
508 XCTAssertEqual(numberOfExpectedVisualEffectView, (NSUInteger)numberOfExpectedVisualEffectView);
511 - (void)testAddBackdropFilters {
512 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
514 flutter::TaskRunners runners(
self.name.UTF8String,
519 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
520 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
522 mock_delegate.settings_.enable_impeller
525 flutterPlatformViewsController,
528 std::make_shared<fml::SyncSwitch>());
532 flutterPlatformViewsController->RegisterViewFactory(
533 factory,
@"MockFlutterPlatformView",
537 flutterPlatformViewsController->OnMethodCall(
539 methodCallWithMethodName:
@"create"
540 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
545 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
546 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
548 flutter::MutatorsStack stack;
550 CGFloat screenScale = [UIScreen mainScreen].scale;
551 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
552 stack.PushTransform(screenScaleMatrix);
554 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
555 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
557 auto embeddedViewParams =
558 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
560 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
561 flutterPlatformViewsController->CompositeEmbeddedView(2);
564 [mockFlutterView addSubview:childClippingView];
566 [mockFlutterView setNeedsLayout];
567 [mockFlutterView layoutIfNeeded];
569 NSMutableArray* originalVisualEffectViews = [[NSMutableArray alloc] init];
570 for (UIView* subview in childClippingView.subviews) {
571 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
574 XCTAssertLessThan(originalVisualEffectViews.count, 1u);
575 if ([
self validateOneVisualEffectView:subview
576 expectedFrame:CGRectMake(0, 0, 10, 10)
577 inputRadius:(CGFloat)5]) {
578 [originalVisualEffectViews addObject:subview];
581 XCTAssertEqual(originalVisualEffectViews.count, 1u);
586 flutter::MutatorsStack stack2;
588 stack2.PushTransform(screenScaleMatrix);
590 for (
int i = 0; i < 2; i++) {
591 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
594 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
595 SkSize::Make(10, 10), stack2);
597 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
598 flutterPlatformViewsController->CompositeEmbeddedView(2);
599 [mockFlutterView setNeedsLayout];
600 [mockFlutterView layoutIfNeeded];
602 NSMutableArray* newVisualEffectViews = [[NSMutableArray alloc] init];
603 for (UIView* subview in childClippingView.subviews) {
604 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
607 XCTAssertLessThan(newVisualEffectViews.count, 2u);
609 if ([
self validateOneVisualEffectView:subview
610 expectedFrame:CGRectMake(0, 0, 10, 10)
611 inputRadius:(CGFloat)5]) {
612 [newVisualEffectViews addObject:subview];
615 XCTAssertEqual(newVisualEffectViews.count, 2u);
616 for (NSUInteger i = 0; i < originalVisualEffectViews.count; i++) {
617 UIView* originalView = originalVisualEffectViews[i];
618 UIView* newView = newVisualEffectViews[i];
620 XCTAssertEqual(originalView, newView);
621 id mockOrignalView = OCMPartialMock(originalView);
622 OCMReject([mockOrignalView removeFromSuperview]);
623 [mockOrignalView stopMocking];
627 - (void)testRemoveBackdropFilters {
628 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
630 flutter::TaskRunners runners(
self.name.UTF8String,
635 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
636 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
638 mock_delegate.settings_.enable_impeller
641 flutterPlatformViewsController,
644 std::make_shared<fml::SyncSwitch>());
648 flutterPlatformViewsController->RegisterViewFactory(
649 factory,
@"MockFlutterPlatformView",
653 flutterPlatformViewsController->OnMethodCall(
655 methodCallWithMethodName:
@"create"
656 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
661 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
662 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
664 flutter::MutatorsStack stack;
666 CGFloat screenScale = [UIScreen mainScreen].scale;
667 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
668 stack.PushTransform(screenScaleMatrix);
670 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
671 for (
int i = 0; i < 5; i++) {
672 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
675 auto embeddedViewParams =
676 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
678 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
679 flutterPlatformViewsController->CompositeEmbeddedView(2);
682 [mockFlutterView addSubview:childClippingView];
684 [mockFlutterView setNeedsLayout];
685 [mockFlutterView layoutIfNeeded];
687 NSMutableArray* originalVisualEffectViews = [[NSMutableArray alloc] init];
688 for (UIView* subview in childClippingView.subviews) {
689 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
692 XCTAssertLessThan(originalVisualEffectViews.count, 5u);
693 if ([
self validateOneVisualEffectView:subview
694 expectedFrame:CGRectMake(0, 0, 10, 10)
695 inputRadius:(CGFloat)5]) {
696 [originalVisualEffectViews addObject:subview];
702 flutter::MutatorsStack stack2;
704 stack2.PushTransform(screenScaleMatrix);
706 for (
int i = 0; i < 4; i++) {
707 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
710 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
711 SkSize::Make(10, 10), stack2);
713 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
714 flutterPlatformViewsController->CompositeEmbeddedView(2);
715 [mockFlutterView setNeedsLayout];
716 [mockFlutterView layoutIfNeeded];
718 NSMutableArray* newVisualEffectViews = [[NSMutableArray alloc] init];
719 for (UIView* subview in childClippingView.subviews) {
720 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
723 XCTAssertLessThan(newVisualEffectViews.count, 4u);
724 if ([
self validateOneVisualEffectView:subview
725 expectedFrame:CGRectMake(0, 0, 10, 10)
726 inputRadius:(CGFloat)5]) {
727 [newVisualEffectViews addObject:subview];
730 XCTAssertEqual(newVisualEffectViews.count, 4u);
732 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
733 UIView* newView = newVisualEffectViews[i];
734 id mockNewView = OCMPartialMock(newView);
735 UIView* originalView = originalVisualEffectViews[i];
737 XCTAssertEqual(originalView, newView);
738 OCMReject([mockNewView removeFromSuperview]);
739 [mockNewView stopMocking];
744 for (
int i = 0; i < 5; i++) {
749 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
750 SkSize::Make(10, 10), stack2);
752 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
753 flutterPlatformViewsController->CompositeEmbeddedView(2);
754 [mockFlutterView setNeedsLayout];
755 [mockFlutterView layoutIfNeeded];
757 NSUInteger numberOfExpectedVisualEffectView = 0u;
758 for (UIView* subview in childClippingView.subviews) {
759 if ([subview isKindOfClass:[UIVisualEffectView
class]]) {
760 numberOfExpectedVisualEffectView++;
763 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
766 - (void)testEditBackdropFilters {
767 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
769 flutter::TaskRunners runners(
self.name.UTF8String,
774 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
775 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
777 mock_delegate.settings_.enable_impeller
780 flutterPlatformViewsController,
783 std::make_shared<fml::SyncSwitch>());
787 flutterPlatformViewsController->RegisterViewFactory(
788 factory,
@"MockFlutterPlatformView",
792 flutterPlatformViewsController->OnMethodCall(
794 methodCallWithMethodName:
@"create"
795 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
800 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
801 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
803 flutter::MutatorsStack stack;
805 CGFloat screenScale = [UIScreen mainScreen].scale;
806 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
807 stack.PushTransform(screenScaleMatrix);
809 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
810 for (
int i = 0; i < 5; i++) {
811 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
814 auto embeddedViewParams =
815 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
817 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
818 flutterPlatformViewsController->CompositeEmbeddedView(2);
821 [mockFlutterView addSubview:childClippingView];
823 [mockFlutterView setNeedsLayout];
824 [mockFlutterView layoutIfNeeded];
826 NSMutableArray* originalVisualEffectViews = [[NSMutableArray alloc] init];
827 for (UIView* subview in childClippingView.subviews) {
828 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
831 XCTAssertLessThan(originalVisualEffectViews.count, 5u);
832 if ([
self validateOneVisualEffectView:subview
833 expectedFrame:CGRectMake(0, 0, 10, 10)
834 inputRadius:(CGFloat)5]) {
835 [originalVisualEffectViews addObject:subview];
841 flutter::MutatorsStack stack2;
843 stack2.PushTransform(screenScaleMatrix);
845 for (
int i = 0; i < 5; i++) {
848 std::make_shared<flutter::DlBlurImageFilter>(2, 5, flutter::DlTileMode::kClamp);
850 stack2.PushBackdropFilter(filter2,
851 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
855 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
858 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
859 SkSize::Make(10, 10), stack2);
861 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
862 flutterPlatformViewsController->CompositeEmbeddedView(2);
863 [mockFlutterView setNeedsLayout];
864 [mockFlutterView layoutIfNeeded];
866 NSMutableArray* newVisualEffectViews = [[NSMutableArray alloc] init];
867 for (UIView* subview in childClippingView.subviews) {
868 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
871 XCTAssertLessThan(newVisualEffectViews.count, 5u);
872 CGFloat expectInputRadius = 5;
873 if (newVisualEffectViews.count == 3) {
874 expectInputRadius = 2;
876 if ([
self validateOneVisualEffectView:subview
877 expectedFrame:CGRectMake(0, 0, 10, 10)
878 inputRadius:(CGFloat)expectInputRadius]) {
879 [newVisualEffectViews addObject:subview];
882 XCTAssertEqual(newVisualEffectViews.count, 5u);
883 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
884 UIView* newView = newVisualEffectViews[i];
885 id mockNewView = OCMPartialMock(newView);
886 UIView* originalView = originalVisualEffectViews[i];
888 XCTAssertEqual(originalView, newView);
889 OCMReject([mockNewView removeFromSuperview]);
890 [mockNewView stopMocking];
892 [newVisualEffectViews removeAllObjects];
896 for (
int i = 0; i < 5; i++) {
900 for (
int i = 0; i < 5; i++) {
903 std::make_shared<flutter::DlBlurImageFilter>(2, 5, flutter::DlTileMode::kClamp);
904 stack2.PushBackdropFilter(filter2,
905 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
909 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
912 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
913 SkSize::Make(10, 10), stack2);
915 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
916 flutterPlatformViewsController->CompositeEmbeddedView(2);
917 [mockFlutterView setNeedsLayout];
918 [mockFlutterView layoutIfNeeded];
920 for (UIView* subview in childClippingView.subviews) {
921 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
924 XCTAssertLessThan(newVisualEffectViews.count, 5u);
925 CGFloat expectInputRadius = 5;
926 if (newVisualEffectViews.count == 0) {
927 expectInputRadius = 2;
929 if ([
self validateOneVisualEffectView:subview
930 expectedFrame:CGRectMake(0, 0, 10, 10)
931 inputRadius:(CGFloat)expectInputRadius]) {
932 [newVisualEffectViews addObject:subview];
935 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
936 UIView* newView = newVisualEffectViews[i];
937 id mockNewView = OCMPartialMock(newView);
938 UIView* originalView = originalVisualEffectViews[i];
940 XCTAssertEqual(originalView, newView);
941 OCMReject([mockNewView removeFromSuperview]);
942 [mockNewView stopMocking];
944 [newVisualEffectViews removeAllObjects];
948 for (
int i = 0; i < 5; i++) {
952 for (
int i = 0; i < 5; i++) {
955 std::make_shared<flutter::DlBlurImageFilter>(2, 5, flutter::DlTileMode::kClamp);
956 stack2.PushBackdropFilter(filter2,
957 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
961 stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
964 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
965 SkSize::Make(10, 10), stack2);
967 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
968 flutterPlatformViewsController->CompositeEmbeddedView(2);
969 [mockFlutterView setNeedsLayout];
970 [mockFlutterView layoutIfNeeded];
972 for (UIView* subview in childClippingView.subviews) {
973 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
976 XCTAssertLessThan(newVisualEffectViews.count, 5u);
977 CGFloat expectInputRadius = 5;
978 if (newVisualEffectViews.count == 4) {
979 expectInputRadius = 2;
981 if ([
self validateOneVisualEffectView:subview
982 expectedFrame:CGRectMake(0, 0, 10, 10)
983 inputRadius:(CGFloat)expectInputRadius]) {
984 [newVisualEffectViews addObject:subview];
987 XCTAssertEqual(newVisualEffectViews.count, 5u);
989 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
990 UIView* newView = newVisualEffectViews[i];
991 id mockNewView = OCMPartialMock(newView);
992 UIView* originalView = originalVisualEffectViews[i];
994 XCTAssertEqual(originalView, newView);
995 OCMReject([mockNewView removeFromSuperview]);
996 [mockNewView stopMocking];
998 [newVisualEffectViews removeAllObjects];
1002 for (
int i = 0; i < 5; i++) {
1006 for (
int i = 0; i < 5; i++) {
1007 auto filter2 = std::make_shared<flutter::DlBlurImageFilter>(i, 2, flutter::DlTileMode::kClamp);
1009 stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1012 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1013 SkSize::Make(10, 10), stack2);
1015 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1016 flutterPlatformViewsController->CompositeEmbeddedView(2);
1017 [mockFlutterView setNeedsLayout];
1018 [mockFlutterView layoutIfNeeded];
1020 for (UIView* subview in childClippingView.subviews) {
1021 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1024 XCTAssertLessThan(newVisualEffectViews.count, 5u);
1025 if ([
self validateOneVisualEffectView:subview
1026 expectedFrame:CGRectMake(0, 0, 10, 10)
1027 inputRadius:(CGFloat)newVisualEffectViews.count]) {
1028 [newVisualEffectViews addObject:subview];
1031 XCTAssertEqual(newVisualEffectViews.count, 5u);
1033 for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) {
1034 UIView* newView = newVisualEffectViews[i];
1035 id mockNewView = OCMPartialMock(newView);
1036 UIView* originalView = originalVisualEffectViews[i];
1038 XCTAssertEqual(originalView, newView);
1039 OCMReject([mockNewView removeFromSuperview]);
1040 [mockNewView stopMocking];
1042 [newVisualEffectViews removeAllObjects];
1045 - (void)testApplyBackdropFilterNotDlBlurImageFilter {
1046 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1047 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
1048 flutter::TaskRunners runners(
self.name.UTF8String,
1052 thread_task_runner);
1053 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
1054 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1056 mock_delegate.settings_.enable_impeller
1059 flutterPlatformViewsController,
1062 std::make_shared<fml::SyncSwitch>());
1066 flutterPlatformViewsController->RegisterViewFactory(
1067 factory,
@"MockFlutterPlatformView",
1071 flutterPlatformViewsController->OnMethodCall(
1073 methodCallWithMethodName:
@"create"
1074 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1079 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1080 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
1082 flutter::MutatorsStack stack;
1084 CGFloat screenScale = [UIScreen mainScreen].scale;
1085 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
1086 stack.PushTransform(screenScaleMatrix);
1088 auto dilateFilter = std::make_shared<flutter::DlDilateImageFilter>(5, 2);
1089 stack.PushBackdropFilter(dilateFilter, SkRect::MakeEmpty());
1091 auto embeddedViewParams =
1092 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1094 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1095 flutterPlatformViewsController->CompositeEmbeddedView(2);
1099 [mockFlutterView addSubview:childClippingView];
1101 [mockFlutterView setNeedsLayout];
1102 [mockFlutterView layoutIfNeeded];
1104 NSUInteger numberOfExpectedVisualEffectView = 0;
1105 for (UIView* subview in childClippingView.subviews) {
1106 if ([subview isKindOfClass:[UIVisualEffectView
class]]) {
1107 numberOfExpectedVisualEffectView++;
1110 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
1114 flutter::MutatorsStack stack2;
1116 stack2.PushTransform(screenScaleMatrix);
1118 auto blurFilter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
1120 for (
int i = 0; i < 5; i++) {
1122 stack2.PushBackdropFilter(dilateFilter,
1123 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1127 stack2.PushBackdropFilter(blurFilter,
1128 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1131 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1132 SkSize::Make(10, 10), stack2);
1134 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1135 flutterPlatformViewsController->CompositeEmbeddedView(2);
1136 [mockFlutterView setNeedsLayout];
1137 [mockFlutterView layoutIfNeeded];
1139 numberOfExpectedVisualEffectView = 0;
1140 for (UIView* subview in childClippingView.subviews) {
1141 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1144 XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u);
1145 if ([
self validateOneVisualEffectView:subview
1146 expectedFrame:CGRectMake(0, 0, 10, 10)
1147 inputRadius:(CGFloat)5]) {
1148 numberOfExpectedVisualEffectView++;
1151 XCTAssertEqual(numberOfExpectedVisualEffectView, 4u);
1155 for (
int i = 0; i < 5; i++) {
1159 for (
int i = 0; i < 5; i++) {
1161 stack2.PushBackdropFilter(dilateFilter,
1162 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1166 stack2.PushBackdropFilter(blurFilter,
1167 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1170 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1171 SkSize::Make(10, 10), stack2);
1173 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1174 flutterPlatformViewsController->CompositeEmbeddedView(2);
1175 [mockFlutterView setNeedsLayout];
1176 [mockFlutterView layoutIfNeeded];
1178 numberOfExpectedVisualEffectView = 0;
1179 for (UIView* subview in childClippingView.subviews) {
1180 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1183 XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u);
1184 if ([
self validateOneVisualEffectView:subview
1185 expectedFrame:CGRectMake(0, 0, 10, 10)
1186 inputRadius:(CGFloat)5]) {
1187 numberOfExpectedVisualEffectView++;
1190 XCTAssertEqual(numberOfExpectedVisualEffectView, 4u);
1194 for (
int i = 0; i < 5; i++) {
1198 for (
int i = 0; i < 5; i++) {
1200 stack2.PushBackdropFilter(dilateFilter,
1201 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1205 stack2.PushBackdropFilter(blurFilter,
1206 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1209 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1210 SkSize::Make(10, 10), stack2);
1212 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1213 flutterPlatformViewsController->CompositeEmbeddedView(2);
1214 [mockFlutterView setNeedsLayout];
1215 [mockFlutterView layoutIfNeeded];
1217 numberOfExpectedVisualEffectView = 0;
1218 for (UIView* subview in childClippingView.subviews) {
1219 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1222 XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u);
1223 if ([
self validateOneVisualEffectView:subview
1224 expectedFrame:CGRectMake(0, 0, 10, 10)
1225 inputRadius:(CGFloat)5]) {
1226 numberOfExpectedVisualEffectView++;
1229 XCTAssertEqual(numberOfExpectedVisualEffectView, 4u);
1233 for (
int i = 0; i < 5; i++) {
1237 for (
int i = 0; i < 5; i++) {
1238 stack2.PushBackdropFilter(dilateFilter,
1239 SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1242 embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix,
1243 SkSize::Make(10, 10), stack2);
1245 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1246 flutterPlatformViewsController->CompositeEmbeddedView(2);
1247 [mockFlutterView setNeedsLayout];
1248 [mockFlutterView layoutIfNeeded];
1250 numberOfExpectedVisualEffectView = 0;
1251 for (UIView* subview in childClippingView.subviews) {
1252 if ([subview isKindOfClass:[UIVisualEffectView
class]]) {
1253 numberOfExpectedVisualEffectView++;
1256 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
1259 - (void)testApplyBackdropFilterCorrectAPI {
1264 UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc]
1265 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1269 visualEffectView:visualEffectView];
1270 XCTAssertNotNil(platformViewFilter);
1273 - (void)testApplyBackdropFilterAPIChangedInvalidUIVisualEffectView {
1275 UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] init];
1279 visualEffectView:visualEffectView];
1280 XCTAssertNil(platformViewFilter);
1283 - (void)testApplyBackdropFilterAPIChangedNoGaussianBlurFilter {
1285 UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc]
1286 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1287 NSArray* subviews = editedUIVisualEffectView.subviews;
1288 for (UIView* view in subviews) {
1289 if ([NSStringFromClass([view
class]) hasSuffix:
@"BackdropView"]) {
1290 for (CIFilter* filter in view.layer.filters) {
1291 if ([[filter valueForKey:
@"name"] isEqual:
@"gaussianBlur"]) {
1292 [filter setValue:@"notGaussianBlur" forKey:@"name"];
1302 visualEffectView:editedUIVisualEffectView];
1303 XCTAssertNil(platformViewFilter);
1306 - (void)testApplyBackdropFilterAPIChangedInvalidInputRadius {
1308 UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc]
1309 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1310 NSArray* subviews = editedUIVisualEffectView.subviews;
1311 for (UIView* view in subviews) {
1312 if ([NSStringFromClass([view
class]) hasSuffix:
@"BackdropView"]) {
1313 for (CIFilter* filter in view.layer.filters) {
1314 if ([[filter valueForKey:
@"name"] isEqual:
@"gaussianBlur"]) {
1315 [filter setValue:@"invalidInputRadius" forKey:@"inputRadius"];
1326 visualEffectView:editedUIVisualEffectView];
1327 XCTAssertNil(platformViewFilter);
1330 - (void)testBackdropFilterVisualEffectSubviewBackgroundColor {
1331 __weak UIVisualEffectView* weakVisualEffectView;
1334 UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc]
1335 initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
1336 weakVisualEffectView = visualEffectView;
1340 visualEffectView:visualEffectView];
1341 CGColorRef visualEffectSubviewBackgroundColor = nil;
1342 for (UIView* view in [platformViewFilter backdropFilterView].subviews) {
1343 if ([NSStringFromClass([view
class]) hasSuffix:
@"VisualEffectSubview"]) {
1344 visualEffectSubviewBackgroundColor = view.layer.backgroundColor;
1348 CGColorEqualToColor(visualEffectSubviewBackgroundColor, UIColor.clearColor.CGColor));
1350 XCTAssertNil(weakVisualEffectView);
1353 - (void)testCompositePlatformView {
1354 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1355 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
1356 flutter::TaskRunners runners(
self.name.UTF8String,
1360 thread_task_runner);
1361 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
1362 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1364 mock_delegate.settings_.enable_impeller
1367 flutterPlatformViewsController,
1370 std::make_shared<fml::SyncSwitch>());
1374 flutterPlatformViewsController->RegisterViewFactory(
1375 factory,
@"MockFlutterPlatformView",
1379 flutterPlatformViewsController->OnMethodCall(
1381 methodCallWithMethodName:
@"create"
1382 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1387 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
1388 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
1390 flutter::MutatorsStack stack;
1392 SkMatrix screenScaleMatrix =
1393 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1394 stack.PushTransform(screenScaleMatrix);
1396 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
1397 stack.PushTransform(translateMatrix);
1398 SkMatrix finalMatrix;
1399 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
1401 auto embeddedViewParams =
1402 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
1404 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1405 flutterPlatformViewsController->CompositeEmbeddedView(2);
1406 CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds
1407 toView:mockFlutterView];
1408 XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, 300)));
1411 - (void)testBackdropFilterCorrectlyPushedAndReset {
1412 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1413 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
1414 flutter::TaskRunners runners(
self.name.UTF8String,
1418 thread_task_runner);
1419 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
1420 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1422 mock_delegate.settings_.enable_impeller
1425 flutterPlatformViewsController,
1428 std::make_shared<fml::SyncSwitch>());
1432 flutterPlatformViewsController->RegisterViewFactory(
1433 factory,
@"MockFlutterPlatformView",
1437 flutterPlatformViewsController->OnMethodCall(
1439 methodCallWithMethodName:
@"create"
1440 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1445 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1446 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
1448 flutter::MutatorsStack stack;
1450 CGFloat screenScale = [UIScreen mainScreen].scale;
1451 SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
1452 stack.PushTransform(screenScaleMatrix);
1454 auto embeddedViewParams =
1455 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1457 flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0));
1458 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1459 flutterPlatformViewsController->PushVisitedPlatformView(2);
1460 auto filter = std::make_shared<flutter::DlBlurImageFilter>(5, 2, flutter::DlTileMode::kClamp);
1461 flutterPlatformViewsController->PushFilterToVisitedPlatformViews(
1462 filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10));
1463 flutterPlatformViewsController->CompositeEmbeddedView(2);
1466 [mockFlutterView addSubview:childClippingView];
1468 [mockFlutterView setNeedsLayout];
1469 [mockFlutterView layoutIfNeeded];
1472 NSUInteger numberOfExpectedVisualEffectView = 0;
1473 for (UIView* subview in childClippingView.subviews) {
1474 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1477 XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u);
1478 if ([
self validateOneVisualEffectView:subview
1479 expectedFrame:CGRectMake(0, 0, 10, 10)
1481 numberOfExpectedVisualEffectView++;
1484 XCTAssertEqual(numberOfExpectedVisualEffectView, 1u);
1487 auto embeddedViewParams2 =
1488 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1489 flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0));
1490 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2));
1491 flutterPlatformViewsController->CompositeEmbeddedView(2);
1494 [mockFlutterView setNeedsLayout];
1495 [mockFlutterView layoutIfNeeded];
1497 numberOfExpectedVisualEffectView = 0;
1498 for (UIView* subview in childClippingView.subviews) {
1499 if (![subview isKindOfClass:[UIVisualEffectView
class]]) {
1502 numberOfExpectedVisualEffectView++;
1504 XCTAssertEqual(numberOfExpectedVisualEffectView, 0u);
1507 - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView {
1508 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1509 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
1510 flutter::TaskRunners runners(
self.name.UTF8String,
1514 thread_task_runner);
1515 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
1516 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1518 mock_delegate.settings_.enable_impeller
1521 flutterPlatformViewsController,
1524 std::make_shared<fml::SyncSwitch>());
1528 flutterPlatformViewsController->RegisterViewFactory(
1529 factory,
@"MockFlutterPlatformView",
1533 flutterPlatformViewsController->OnMethodCall(
1535 methodCallWithMethodName:
@"create"
1536 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1541 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
1542 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
1544 flutter::MutatorsStack stack;
1546 SkMatrix screenScaleMatrix =
1547 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1548 stack.PushTransform(screenScaleMatrix);
1550 SkMatrix rotateMatrix;
1551 rotateMatrix.setRotate(10);
1552 stack.PushTransform(rotateMatrix);
1553 SkMatrix finalMatrix;
1554 finalMatrix.setConcat(screenScaleMatrix, rotateMatrix);
1556 auto embeddedViewParams =
1557 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
1559 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1560 flutterPlatformViewsController->CompositeEmbeddedView(2);
1561 CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds
1562 toView:mockFlutterView];
1568 XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - childClippingView.frame.origin.x),
1570 XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - childClippingView.frame.origin.y),
1573 fabs(platformViewRectInFlutterView.size.width - childClippingView.frame.size.width),
1576 fabs(platformViewRectInFlutterView.size.height - childClippingView.frame.size.height),
1580 - (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView {
1581 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1582 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
1583 flutter::TaskRunners runners(
self.name.UTF8String,
1587 thread_task_runner);
1588 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
1589 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1591 mock_delegate.settings_.enable_impeller
1594 flutterPlatformViewsController,
1597 std::make_shared<fml::SyncSwitch>());
1601 flutterPlatformViewsController->RegisterViewFactory(
1602 factory,
@"MockFlutterPlatformView",
1606 flutterPlatformViewsController->OnMethodCall(
1608 methodCallWithMethodName:
@"create"
1609 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1614 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
1615 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
1617 flutter::MutatorsStack stack;
1619 SkMatrix screenScaleMatrix =
1620 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1621 stack.PushTransform(screenScaleMatrix);
1622 SkMatrix translateMatrix = SkMatrix::Translate(5, 5);
1624 stack.PushTransform(translateMatrix);
1626 SkRect rect = SkRect::MakeXYWH(0, 0, 25, 25);
1627 stack.PushClipRect(rect);
1630 SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25);
1631 SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1);
1632 stack.PushClipRRect(rrect);
1634 auto embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(
1635 SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack);
1637 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1638 flutterPlatformViewsController->CompositeEmbeddedView(2);
1642 [mockFlutterView addSubview:childClippingView];
1644 [mockFlutterView setNeedsLayout];
1645 [mockFlutterView layoutIfNeeded];
1646 XCTAssertNil(childClippingView.maskView);
1649 - (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView {
1650 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1651 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
1652 flutter::TaskRunners runners(
self.name.UTF8String,
1656 thread_task_runner);
1657 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
1658 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1660 mock_delegate.settings_.enable_impeller
1663 flutterPlatformViewsController,
1666 std::make_shared<fml::SyncSwitch>());
1670 flutterPlatformViewsController->RegisterViewFactory(
1671 factory,
@"MockFlutterPlatformView",
1675 flutterPlatformViewsController->OnMethodCall(
1677 methodCallWithMethodName:
@"create"
1678 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1683 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
1684 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
1686 flutter::MutatorsStack stack;
1688 SkMatrix screenScaleMatrix =
1689 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1690 stack.PushTransform(screenScaleMatrix);
1691 SkMatrix translateMatrix = SkMatrix::Translate(5, 5);
1693 stack.PushTransform(translateMatrix);
1697 SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10);
1698 SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1);
1699 stack.PushClipRRect(rrect);
1701 auto embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(
1702 SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack);
1704 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1705 flutterPlatformViewsController->CompositeEmbeddedView(2);
1709 [mockFlutterView addSubview:childClippingView];
1711 [mockFlutterView setNeedsLayout];
1712 [mockFlutterView layoutIfNeeded];
1714 XCTAssertNotNil(childClippingView.maskView);
1717 - (void)testClipRect {
1718 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1719 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
1720 flutter::TaskRunners runners(
self.name.UTF8String,
1724 thread_task_runner);
1725 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
1726 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1728 mock_delegate.settings_.enable_impeller
1731 flutterPlatformViewsController,
1734 std::make_shared<fml::SyncSwitch>());
1738 flutterPlatformViewsController->RegisterViewFactory(
1739 factory,
@"MockFlutterPlatformView",
1743 flutterPlatformViewsController->OnMethodCall(
1745 methodCallWithMethodName:
@"create"
1746 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1751 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1752 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
1754 flutter::MutatorsStack stack;
1756 SkMatrix screenScaleMatrix =
1757 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1758 stack.PushTransform(screenScaleMatrix);
1760 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
1761 stack.PushClipRect(rect);
1763 auto embeddedViewParams =
1764 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1766 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1767 flutterPlatformViewsController->CompositeEmbeddedView(2);
1771 [mockFlutterView addSubview:childClippingView];
1773 [mockFlutterView setNeedsLayout];
1774 [mockFlutterView layoutIfNeeded];
1776 CGRect insideClipping = CGRectMake(2, 2, 3, 3);
1777 for (
int i = 0; i < 10; i++) {
1778 for (
int j = 0; j < 10; j++) {
1779 CGPoint point = CGPointMake(i, j);
1780 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView];
1781 if (CGRectContainsPoint(insideClipping, point)) {
1782 XCTAssertEqual(alpha, 255);
1784 XCTAssertEqual(alpha, 0);
1790 - (void)testClipRect_multipleClips {
1791 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1792 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
1793 flutter::TaskRunners runners(
self.name.UTF8String,
1797 thread_task_runner);
1798 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
1799 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1801 mock_delegate.settings_.enable_impeller
1804 flutterPlatformViewsController,
1807 std::make_shared<fml::SyncSwitch>());
1811 flutterPlatformViewsController->RegisterViewFactory(
1812 factory,
@"MockFlutterPlatformView",
1816 flutterPlatformViewsController->OnMethodCall(
1818 methodCallWithMethodName:
@"create"
1819 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1824 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1825 flutterPlatformViewsController->SetFlutterView(flutterView);
1827 flutter::MutatorsStack stack;
1829 SkMatrix screenScaleMatrix =
1830 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1831 stack.PushTransform(screenScaleMatrix);
1833 SkRect rect1 = SkRect::MakeXYWH(2, 2, 3, 3);
1834 stack.PushClipRect(rect1);
1836 SkRect rect2 = SkRect::MakeXYWH(3, 3, 3, 3);
1837 stack.PushClipRect(rect2);
1839 auto embeddedViewParams =
1840 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1842 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1843 flutterPlatformViewsController->CompositeEmbeddedView(2);
1848 [flutterView addSubview:childClippingView];
1850 [flutterView setNeedsLayout];
1851 [flutterView layoutIfNeeded];
1870 CGRect insideClipping = CGRectMake(3, 3, 2, 2);
1871 for (
int i = 0; i < 10; i++) {
1872 for (
int j = 0; j < 10; j++) {
1873 CGPoint point = CGPointMake(i, j);
1874 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
1875 if (CGRectContainsPoint(insideClipping, point)) {
1876 XCTAssertEqual(alpha, 255);
1878 XCTAssertEqual(alpha, 0);
1884 - (void)testClipRRect {
1885 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1886 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
1887 flutter::TaskRunners runners(
self.name.UTF8String,
1891 thread_task_runner);
1892 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
1893 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1895 mock_delegate.settings_.enable_impeller
1898 flutterPlatformViewsController,
1901 std::make_shared<fml::SyncSwitch>());
1905 flutterPlatformViewsController->RegisterViewFactory(
1906 factory,
@"MockFlutterPlatformView",
1910 flutterPlatformViewsController->OnMethodCall(
1912 methodCallWithMethodName:
@"create"
1913 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
1918 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
1919 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
1921 flutter::MutatorsStack stack;
1923 SkMatrix screenScaleMatrix =
1924 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1925 stack.PushTransform(screenScaleMatrix);
1927 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
1928 stack.PushClipRRect(rrect);
1930 auto embeddedViewParams =
1931 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
1933 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
1934 flutterPlatformViewsController->CompositeEmbeddedView(2);
1938 [mockFlutterView addSubview:childClippingView];
1940 [mockFlutterView setNeedsLayout];
1941 [mockFlutterView layoutIfNeeded];
1962 CGRect innerClipping1 = CGRectMake(3, 2, 4, 6);
1963 CGRect innerClipping2 = CGRectMake(2, 3, 6, 4);
1964 CGRect outterClipping = CGRectMake(2, 2, 6, 6);
1965 for (
int i = 0; i < 10; i++) {
1966 for (
int j = 0; j < 10; j++) {
1967 CGPoint point = CGPointMake(i, j);
1968 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView];
1969 if (CGRectContainsPoint(innerClipping1, point) ||
1970 CGRectContainsPoint(innerClipping2, point)) {
1972 XCTAssertEqual(alpha, 255);
1973 }
else if (CGRectContainsPoint(outterClipping, point)) {
1975 XCTAssert(0 < alpha && alpha < 255);
1978 XCTAssertEqual(alpha, 0);
1984 - (void)testClipRRect_multipleClips {
1985 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
1986 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
1987 flutter::TaskRunners runners(
self.name.UTF8String,
1991 thread_task_runner);
1992 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
1993 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1995 mock_delegate.settings_.enable_impeller
1998 flutterPlatformViewsController,
2001 std::make_shared<fml::SyncSwitch>());
2005 flutterPlatformViewsController->RegisterViewFactory(
2006 factory,
@"MockFlutterPlatformView",
2010 flutterPlatformViewsController->OnMethodCall(
2012 methodCallWithMethodName:
@"create"
2013 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2018 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2019 flutterPlatformViewsController->SetFlutterView(flutterView);
2021 flutter::MutatorsStack stack;
2023 SkMatrix screenScaleMatrix =
2024 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2025 stack.PushTransform(screenScaleMatrix);
2027 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2028 stack.PushClipRRect(rrect);
2030 SkRect rect = SkRect::MakeXYWH(4, 2, 6, 6);
2031 stack.PushClipRect(rect);
2033 auto embeddedViewParams =
2034 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2036 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2037 flutterPlatformViewsController->CompositeEmbeddedView(2);
2042 [flutterView addSubview:childClippingView];
2044 [flutterView setNeedsLayout];
2045 [flutterView layoutIfNeeded];
2066 CGRect clipping = CGRectMake(4, 2, 4, 6);
2067 for (
int i = 0; i < 10; i++) {
2068 for (
int j = 0; j < 10; j++) {
2069 CGPoint point = CGPointMake(i, j);
2070 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2071 if (i == 7 && (j == 2 || j == 7)) {
2073 XCTAssert(0 < alpha && alpha < 255);
2076 (i == 4 && j >= 2 && j <= 7) ||
2078 (i == 7 && j >= 2 && j <= 7) ||
2080 (j == 2 && i >= 4 && i <= 7) ||
2082 (j == 7 && i >= 4 && i <= 7)) {
2085 XCTAssert(alpha > 127);
2086 }
else if ((i == 3 && j >= 1 && j <= 8) || (i == 8 && j >= 1 && j <= 8) ||
2087 (j == 1 && i >= 3 && i <= 8) || (j == 8 && i >= 3 && i <= 8)) {
2090 XCTAssert(alpha < 127);
2091 }
else if (CGRectContainsPoint(clipping, point)) {
2093 XCTAssertEqual(alpha, 255);
2096 XCTAssertEqual(alpha, 0);
2102 - (void)testClipPath {
2103 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2104 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2105 flutter::TaskRunners runners(
self.name.UTF8String,
2109 thread_task_runner);
2110 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2111 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2113 mock_delegate.settings_.enable_impeller
2116 flutterPlatformViewsController,
2119 std::make_shared<fml::SyncSwitch>());
2123 flutterPlatformViewsController->RegisterViewFactory(
2124 factory,
@"MockFlutterPlatformView",
2128 flutterPlatformViewsController->OnMethodCall(
2130 methodCallWithMethodName:
@"create"
2131 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2136 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2137 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
2139 flutter::MutatorsStack stack;
2141 SkMatrix screenScaleMatrix =
2142 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2143 stack.PushTransform(screenScaleMatrix);
2146 path.addRoundRect(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2147 stack.PushClipPath(path);
2149 auto embeddedViewParams =
2150 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2152 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2153 flutterPlatformViewsController->CompositeEmbeddedView(2);
2157 [mockFlutterView addSubview:childClippingView];
2159 [mockFlutterView setNeedsLayout];
2160 [mockFlutterView layoutIfNeeded];
2181 CGRect innerClipping1 = CGRectMake(3, 2, 4, 6);
2182 CGRect innerClipping2 = CGRectMake(2, 3, 6, 4);
2183 CGRect outterClipping = CGRectMake(2, 2, 6, 6);
2184 for (
int i = 0; i < 10; i++) {
2185 for (
int j = 0; j < 10; j++) {
2186 CGPoint point = CGPointMake(i, j);
2187 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView];
2188 if (CGRectContainsPoint(innerClipping1, point) ||
2189 CGRectContainsPoint(innerClipping2, point)) {
2191 XCTAssertEqual(alpha, 255);
2192 }
else if (CGRectContainsPoint(outterClipping, point)) {
2194 XCTAssert(0 < alpha && alpha < 255);
2197 XCTAssertEqual(alpha, 0);
2203 - (void)testClipPath_multipleClips {
2204 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2205 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2206 flutter::TaskRunners runners(
self.name.UTF8String,
2210 thread_task_runner);
2211 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2212 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2214 mock_delegate.settings_.enable_impeller
2217 flutterPlatformViewsController,
2220 std::make_shared<fml::SyncSwitch>());
2224 flutterPlatformViewsController->RegisterViewFactory(
2225 factory,
@"MockFlutterPlatformView",
2229 flutterPlatformViewsController->OnMethodCall(
2231 methodCallWithMethodName:
@"create"
2232 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2237 UIView* flutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
2238 flutterPlatformViewsController->SetFlutterView(flutterView);
2240 flutter::MutatorsStack stack;
2242 SkMatrix screenScaleMatrix =
2243 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2244 stack.PushTransform(screenScaleMatrix);
2247 path.addRoundRect(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1);
2248 stack.PushClipPath(path);
2250 SkRect rect = SkRect::MakeXYWH(4, 2, 6, 6);
2251 stack.PushClipRect(rect);
2253 auto embeddedViewParams =
2254 std::make_unique<flutter::EmbeddedViewParams>(screenScaleMatrix, SkSize::Make(10, 10), stack);
2256 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2257 flutterPlatformViewsController->CompositeEmbeddedView(2);
2262 [flutterView addSubview:childClippingView];
2264 [flutterView setNeedsLayout];
2265 [flutterView layoutIfNeeded];
2286 CGRect clipping = CGRectMake(4, 2, 4, 6);
2287 for (
int i = 0; i < 10; i++) {
2288 for (
int j = 0; j < 10; j++) {
2289 CGPoint point = CGPointMake(i, j);
2290 int alpha = [
self alphaOfPoint:CGPointMake(i, j) onView:flutterView];
2291 if (i == 7 && (j == 2 || j == 7)) {
2293 XCTAssert(0 < alpha && alpha < 255);
2296 (i == 4 && j >= 2 && j <= 7) ||
2298 (i == 7 && j >= 2 && j <= 7) ||
2300 (j == 2 && i >= 4 && i <= 7) ||
2302 (j == 7 && i >= 4 && i <= 7)) {
2305 XCTAssert(alpha > 127);
2306 }
else if ((i == 3 && j >= 1 && j <= 8) || (i == 8 && j >= 1 && j <= 8) ||
2307 (j == 1 && i >= 3 && i <= 8) || (j == 8 && i >= 3 && i <= 8)) {
2310 XCTAssert(alpha < 127);
2311 }
else if (CGRectContainsPoint(clipping, point)) {
2313 XCTAssertEqual(alpha, 255);
2316 XCTAssertEqual(alpha, 0);
2322 - (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents {
2323 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2324 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2325 flutter::TaskRunners runners(
self.name.UTF8String,
2329 thread_task_runner);
2330 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2331 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2333 mock_delegate.settings_.enable_impeller
2336 flutterPlatformViewsController,
2339 std::make_shared<fml::SyncSwitch>());
2343 flutterPlatformViewsController->RegisterViewFactory(
2344 factory,
@"MockFlutterPlatformView",
2348 flutterPlatformViewsController->OnMethodCall(
2350 methodCallWithMethodName:
@"create"
2351 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2358 while (touchInteceptorView != nil &&
2360 touchInteceptorView = touchInteceptorView.superview;
2362 XCTAssertNotNil(touchInteceptorView);
2365 UIGestureRecognizer* forwardGectureRecognizer = nil;
2366 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2367 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2368 forwardGectureRecognizer = gestureRecognizer;
2374 NSSet* touches1 = [[NSSet alloc] init];
2375 id event1 = OCMClassMock([UIEvent
class]);
2377 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2378 OCMReject([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]);
2381 NSSet* touches2 = [[NSSet alloc] init];
2382 id event2 = OCMClassMock([UIEvent
class]);
2383 flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller);
2384 [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2];
2385 OCMVerify([mockFlutterViewContoller touchesBegan:touches2 withEvent:event2]);
2388 - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGesturesToBeHandled {
2389 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2390 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2391 flutter::TaskRunners runners(
self.name.UTF8String,
2395 thread_task_runner);
2396 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2397 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2399 mock_delegate.settings_.enable_impeller
2402 flutterPlatformViewsController,
2405 std::make_shared<fml::SyncSwitch>());
2409 flutterPlatformViewsController->RegisterViewFactory(
2410 factory,
@"MockFlutterPlatformView",
2414 flutterPlatformViewsController->OnMethodCall(
2416 methodCallWithMethodName:
@"create"
2417 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2424 while (touchInteceptorView != nil &&
2426 touchInteceptorView = touchInteceptorView.superview;
2428 XCTAssertNotNil(touchInteceptorView);
2431 UIGestureRecognizer* forwardGectureRecognizer = nil;
2432 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2433 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2434 forwardGectureRecognizer = gestureRecognizer;
2441 flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller);
2443 NSSet* touches1 = [[NSSet alloc] init];
2444 id event1 = OCMClassMock([UIEvent
class]);
2445 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2446 OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]);
2448 flutterPlatformViewsController->SetFlutterViewController(nil);
2451 NSSet* touches2 = [[NSSet alloc] init];
2452 id event2 = OCMClassMock([UIEvent
class]);
2453 [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2];
2454 OCMVerify([mockFlutterViewContoller touchesMoved:touches2 withEvent:event2]);
2456 NSSet* touches3 = [[NSSet alloc] init];
2457 id event3 = OCMClassMock([UIEvent
class]);
2458 [forwardGectureRecognizer touchesEnded:touches3 withEvent:event3];
2459 OCMVerify([mockFlutterViewContoller touchesEnded:touches3 withEvent:event3]);
2462 NSSet* touches4 = [[NSSet alloc] init];
2463 id event4 = OCMClassMock([UIEvent
class]);
2464 [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4];
2465 OCMReject([mockFlutterViewContoller touchesBegan:touches4 withEvent:event4]);
2467 NSSet* touches5 = [[NSSet alloc] init];
2468 id event5 = OCMClassMock([UIEvent
class]);
2469 [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5];
2470 OCMReject([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]);
2475 flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller);
2477 NSSet* touches1 = [[NSSet alloc] init];
2478 id event1 = OCMClassMock([UIEvent
class]);
2479 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2480 OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]);
2482 flutterPlatformViewsController->SetFlutterViewController(nil);
2485 NSSet* touches2 = [[NSSet alloc] init];
2486 id event2 = OCMClassMock([UIEvent
class]);
2487 [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2];
2488 OCMVerify([mockFlutterViewContoller touchesMoved:touches2 withEvent:event2]);
2490 NSSet* touches3 = [[NSSet alloc] init];
2491 id event3 = OCMClassMock([UIEvent
class]);
2492 [forwardGectureRecognizer touchesCancelled:touches3 withEvent:event3];
2493 OCMVerify([mockFlutterViewContoller forceTouchesCancelled:touches3]);
2496 NSSet* touches4 = [[NSSet alloc] init];
2497 id event4 = OCMClassMock([UIEvent
class]);
2498 [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4];
2499 OCMReject([mockFlutterViewContoller touchesBegan:touches4 withEvent:event4]);
2501 NSSet* touches5 = [[NSSet alloc] init];
2502 id event5 = OCMClassMock([UIEvent
class]);
2503 [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5];
2504 OCMReject([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]);
2507 flutterPlatformViewsController->Reset();
2511 testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence {
2512 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2513 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2514 flutter::TaskRunners runners(
self.name.UTF8String,
2518 thread_task_runner);
2519 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2520 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2522 mock_delegate.settings_.enable_impeller
2525 flutterPlatformViewsController,
2528 std::make_shared<fml::SyncSwitch>());
2532 flutterPlatformViewsController->RegisterViewFactory(
2533 factory,
@"MockFlutterPlatformView",
2537 flutterPlatformViewsController->OnMethodCall(
2539 methodCallWithMethodName:
@"create"
2540 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2547 while (touchInteceptorView != nil &&
2549 touchInteceptorView = touchInteceptorView.superview;
2551 XCTAssertNotNil(touchInteceptorView);
2554 UIGestureRecognizer* forwardGectureRecognizer = nil;
2555 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2556 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2557 forwardGectureRecognizer = gestureRecognizer;
2563 flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller);
2566 NSSet* touches1 = [NSSet setWithObject:@1];
2567 id event1 = OCMClassMock([UIEvent
class]);
2568 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2569 OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]);
2572 flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller2);
2576 NSSet* touches2 = [NSSet setWithObject:@1];
2577 id event2 = OCMClassMock([UIEvent
class]);
2578 [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2];
2579 OCMVerify([mockFlutterViewContoller touchesBegan:touches2 withEvent:event2]);
2580 OCMReject([mockFlutterViewContoller2 touchesBegan:touches2 withEvent:event2]);
2582 NSSet* touches3 = [NSSet setWithObject:@1];
2583 id event3 = OCMClassMock([UIEvent
class]);
2584 [forwardGectureRecognizer touchesMoved:touches3 withEvent:event3];
2585 OCMVerify([mockFlutterViewContoller touchesMoved:touches3 withEvent:event3]);
2586 OCMReject([mockFlutterViewContoller2 touchesMoved:touches3 withEvent:event3]);
2588 NSSet* touches4 = [NSSet setWithObject:@1];
2589 id event4 = OCMClassMock([UIEvent
class]);
2590 [forwardGectureRecognizer touchesEnded:touches4 withEvent:event4];
2591 OCMVerify([mockFlutterViewContoller touchesEnded:touches4 withEvent:event4]);
2592 OCMReject([mockFlutterViewContoller2 touchesEnded:touches4 withEvent:event4]);
2594 NSSet* touches5 = [NSSet setWithObject:@1];
2595 id event5 = OCMClassMock([UIEvent
class]);
2596 [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5];
2597 OCMVerify([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]);
2598 OCMReject([mockFlutterViewContoller2 touchesEnded:touches5 withEvent:event5]);
2602 NSSet* touches6 = [NSSet setWithObject:@1];
2603 id event6 = OCMClassMock([UIEvent
class]);
2604 [forwardGectureRecognizer touchesBegan:touches6 withEvent:event6];
2605 OCMVerify([mockFlutterViewContoller2 touchesBegan:touches6 withEvent:event6]);
2606 OCMReject([mockFlutterViewContoller touchesBegan:touches6 withEvent:event6]);
2609 NSSet* touches7 = [NSSet setWithObject:@1];
2610 id event7 = OCMClassMock([UIEvent
class]);
2611 [forwardGectureRecognizer touchesMoved:touches7 withEvent:event7];
2612 OCMVerify([mockFlutterViewContoller2 touchesMoved:touches7 withEvent:event7]);
2613 OCMReject([mockFlutterViewContoller touchesMoved:touches7 withEvent:event7]);
2615 NSSet* touches8 = [NSSet setWithObject:@1];
2616 id event8 = OCMClassMock([UIEvent
class]);
2617 [forwardGectureRecognizer touchesEnded:touches8 withEvent:event8];
2618 OCMVerify([mockFlutterViewContoller2 touchesEnded:touches8 withEvent:event8]);
2619 OCMReject([mockFlutterViewContoller touchesEnded:touches8 withEvent:event8]);
2621 flutterPlatformViewsController->Reset();
2624 - (void)testFlutterPlatformViewTouchesCancelledEventAreForcedToBeCancelled {
2625 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2626 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2627 flutter::TaskRunners runners(
self.name.UTF8String,
2631 thread_task_runner);
2632 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2633 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2635 mock_delegate.settings_.enable_impeller
2638 flutterPlatformViewsController,
2641 std::make_shared<fml::SyncSwitch>());
2645 flutterPlatformViewsController->RegisterViewFactory(
2646 factory,
@"MockFlutterPlatformView",
2650 flutterPlatformViewsController->OnMethodCall(
2652 methodCallWithMethodName:
@"create"
2653 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2660 while (touchInteceptorView != nil &&
2662 touchInteceptorView = touchInteceptorView.superview;
2664 XCTAssertNotNil(touchInteceptorView);
2667 UIGestureRecognizer* forwardGectureRecognizer = nil;
2668 for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) {
2669 if ([gestureRecognizer isKindOfClass:NSClassFromString(
@"ForwardingGestureRecognizer")]) {
2670 forwardGectureRecognizer = gestureRecognizer;
2676 flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller);
2678 NSSet* touches1 = [NSSet setWithObject:@1];
2679 id event1 = OCMClassMock([UIEvent
class]);
2680 [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
2682 [forwardGectureRecognizer touchesCancelled:touches1 withEvent:event1];
2683 OCMVerify([mockFlutterViewContoller forceTouchesCancelled:touches1]);
2685 flutterPlatformViewsController->Reset();
2688 - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashing {
2689 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2690 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2691 flutter::TaskRunners runners(
self.name.UTF8String,
2695 thread_task_runner);
2696 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2697 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2699 mock_delegate.settings_.enable_impeller
2702 flutterPlatformViewsController,
2705 std::make_shared<fml::SyncSwitch>());
2709 flutterPlatformViewsController->RegisterViewFactory(
2710 factory,
@"MockFlutterPlatformView",
2714 flutterPlatformViewsController->OnMethodCall(
2716 methodCallWithMethodName:
@"create"
2717 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2723 flutter::MutatorsStack stack;
2724 SkMatrix finalMatrix;
2726 auto embeddedViewParams_1 =
2727 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
2729 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_1));
2730 flutterPlatformViewsController->CompositeEmbeddedView(2);
2731 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
2732 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
2733 nullptr, framebuffer_info,
2734 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return false; },
2735 SkISize::Make(800, 600));
2737 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
2739 auto embeddedViewParams_2 =
2740 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
2741 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_2));
2742 flutterPlatformViewsController->CompositeEmbeddedView(2);
2743 auto mock_surface_submit_true = std::make_unique<flutter::SurfaceFrame>(
2744 nullptr, framebuffer_info,
2745 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
2746 SkISize::Make(800, 600));
2747 XCTAssertTrue(flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr,
2748 std::move(mock_surface_submit_true)));
2752 testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView {
2753 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2754 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2755 flutter::TaskRunners runners(
self.name.UTF8String,
2759 thread_task_runner);
2760 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2761 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2763 mock_delegate.settings_.enable_impeller
2766 flutterPlatformViewsController,
2769 std::make_shared<fml::SyncSwitch>());
2771 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
2772 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
2776 flutterPlatformViewsController->RegisterViewFactory(
2777 factory,
@"MockFlutterPlatformView",
2783 flutterPlatformViewsController->OnMethodCall(
2785 methodCallWithMethodName:
@"create"
2786 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
2789 flutter::MutatorsStack stack;
2790 SkMatrix finalMatrix;
2791 auto embeddedViewParams =
2792 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
2793 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
2794 flutterPlatformViewsController->CompositeEmbeddedView(2);
2799 flutterPlatformViewsController->Reset();
2804 - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
2805 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2806 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2807 flutter::TaskRunners runners(
self.name.UTF8String,
2811 thread_task_runner);
2812 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2813 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2815 mock_delegate.settings_.enable_impeller
2818 flutterPlatformViewsController,
2821 std::make_shared<fml::SyncSwitch>());
2823 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
2824 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
2828 flutterPlatformViewsController->RegisterViewFactory(
2829 factory,
@"MockFlutterPlatformView",
2834 flutterPlatformViewsController->OnMethodCall(
2836 methodCallWithMethodName:
@"create"
2837 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
2841 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
2842 flutter::MutatorsStack stack;
2843 SkMatrix finalMatrix;
2844 auto embeddedViewParams1 =
2845 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
2846 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
2847 flutterPlatformViewsController->CompositeEmbeddedView(0);
2848 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL);
2851 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
2852 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 0UL);
2854 auto embeddedViewParams2 =
2855 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
2856 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams2));
2857 flutterPlatformViewsController->CompositeEmbeddedView(0);
2858 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL);
2862 testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy {
2863 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2864 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2865 flutter::TaskRunners runners(
self.name.UTF8String,
2869 thread_task_runner);
2870 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2871 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2873 mock_delegate.settings_.enable_impeller
2876 flutterPlatformViewsController,
2879 std::make_shared<fml::SyncSwitch>());
2881 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
2882 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
2886 flutterPlatformViewsController->RegisterViewFactory(
2887 factory,
@"MockFlutterPlatformView",
2891 flutterPlatformViewsController->OnMethodCall(
2893 methodCallWithMethodName:
@"create"
2894 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
2899 flutterPlatformViewsController->OnMethodCall(
2901 methodCallWithMethodName:
@"create"
2902 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
2906 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
2907 flutter::MutatorsStack stack;
2908 SkMatrix finalMatrix;
2909 auto embeddedViewParams1 =
2910 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
2911 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
2912 flutterPlatformViewsController->CompositeEmbeddedView(0);
2913 auto embeddedViewParams2 =
2914 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
2915 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
2916 flutterPlatformViewsController->CompositeEmbeddedView(1);
2919 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
2920 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
2921 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
2922 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
2923 std::move(mock_sk_surface), framebuffer_info,
2924 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
2925 SkISize::Make(800, 600));
2928 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
2930 UIView* clippingView1 = view1.superview.superview;
2931 UIView* clippingView2 = view2.superview.superview;
2932 UIView* flutterView = clippingView1.superview;
2933 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
2934 [flutterView.subviews indexOfObject:clippingView2],
2935 @"The first clipping view should be added before the second clipping view.");
2938 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
2940 embeddedViewParams2 =
2941 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
2942 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
2943 flutterPlatformViewsController->CompositeEmbeddedView(1);
2944 embeddedViewParams1 =
2945 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
2946 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
2947 flutterPlatformViewsController->CompositeEmbeddedView(0);
2949 mock_sk_surface = SkSurfaces::Raster(image_info);
2950 mock_surface = std::make_unique<flutter::SurfaceFrame>(
2951 std::move(mock_sk_surface), framebuffer_info,
2952 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
2953 SkISize::Make(800, 600));
2955 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
2956 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] >
2957 [flutterView.subviews indexOfObject:clippingView2],
2958 @"The first clipping view should be added after the second clipping view.");
2962 testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy {
2963 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
2964 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
2965 flutter::TaskRunners runners(
self.name.UTF8String,
2969 thread_task_runner);
2970 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
2971 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
2973 mock_delegate.settings_.enable_impeller
2976 flutterPlatformViewsController,
2979 std::make_shared<fml::SyncSwitch>());
2981 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
2982 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
2986 flutterPlatformViewsController->RegisterViewFactory(
2987 factory,
@"MockFlutterPlatformView",
2991 flutterPlatformViewsController->OnMethodCall(
2993 methodCallWithMethodName:
@"create"
2994 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
2999 flutterPlatformViewsController->OnMethodCall(
3001 methodCallWithMethodName:
@"create"
3002 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3006 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3007 flutter::MutatorsStack stack;
3008 SkMatrix finalMatrix;
3009 auto embeddedViewParams1 =
3010 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3011 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3012 flutterPlatformViewsController->CompositeEmbeddedView(0);
3013 auto embeddedViewParams2 =
3014 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
3015 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
3016 flutterPlatformViewsController->CompositeEmbeddedView(1);
3019 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3020 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3021 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3022 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3023 std::move(mock_sk_surface), framebuffer_info,
3024 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3025 SkISize::Make(800, 600));
3028 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3030 UIView* clippingView1 = view1.superview.superview;
3031 UIView* clippingView2 = view2.superview.superview;
3032 UIView* flutterView = clippingView1.superview;
3033 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
3034 [flutterView.subviews indexOfObject:clippingView2],
3035 @"The first clipping view should be added before the second clipping view.");
3038 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3040 embeddedViewParams1 =
3041 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3042 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1));
3043 flutterPlatformViewsController->CompositeEmbeddedView(0);
3044 embeddedViewParams2 =
3045 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(500, 500), stack);
3046 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2));
3047 flutterPlatformViewsController->CompositeEmbeddedView(1);
3049 mock_sk_surface = SkSurfaces::Raster(image_info);
3050 mock_surface = std::make_unique<flutter::SurfaceFrame>(
3051 std::move(mock_sk_surface), framebuffer_info,
3052 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3053 SkISize::Make(800, 600));
3055 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3056 XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
3057 [flutterView.subviews indexOfObject:clippingView2],
3058 @"The first clipping view should be added before the second clipping view.");
3061 - (void)testThreadMergeAtEndFrame {
3062 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3063 auto thread_task_runner_platform =
CreateNewThread(
"FlutterPlatformViewsTest1");
3064 auto thread_task_runner_other =
CreateNewThread(
"FlutterPlatformViewsTest2");
3065 flutter::TaskRunners runners(
self.name.UTF8String,
3066 thread_task_runner_platform,
3067 thread_task_runner_other,
3068 thread_task_runner_other,
3069 thread_task_runner_other);
3070 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
3071 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3073 mock_delegate.settings_.enable_impeller
3076 flutterPlatformViewsController,
3079 std::make_shared<fml::SyncSwitch>());
3081 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3082 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
3086 flutterPlatformViewsController->RegisterViewFactory(
3087 factory,
@"MockFlutterPlatformView",
3089 XCTestExpectation* waitForPlatformView =
3090 [
self expectationWithDescription:@"wait for platform view to be created"];
3092 [waitForPlatformView fulfill];
3095 flutterPlatformViewsController->OnMethodCall(
3097 methodCallWithMethodName:
@"create"
3098 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3100 [
self waitForExpectations:@[ waitForPlatformView ] timeout:30];
3103 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3104 SkMatrix finalMatrix;
3105 flutter::MutatorsStack stack;
3106 auto embeddedViewParams =
3107 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3108 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
3110 fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger =
3111 fml::MakeRefCounted<fml::RasterThreadMerger>(thread_task_runner_platform->GetTaskQueueId(),
3112 thread_task_runner_other->GetTaskQueueId());
3113 XCTAssertEqual(flutterPlatformViewsController->PostPrerollAction(raster_thread_merger),
3114 flutter::PostPrerollResult::kSkipAndRetryFrame);
3115 XCTAssertFalse(raster_thread_merger->IsMerged());
3117 flutterPlatformViewsController->EndFrame(
true, raster_thread_merger);
3118 XCTAssertTrue(raster_thread_merger->IsMerged());
3122 while (raster_thread_merger->DecrementLease() != fml::RasterThreadStatus::kUnmergedNow) {
3126 - (int)alphaOfPoint:(CGPoint)point onView:(UIView*)view {
3127 unsigned char pixel[4] = {0};
3129 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
3132 CGContextRef context = CGBitmapContextCreate(
3133 pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast);
3134 CGContextTranslateCTM(context, -point.x, -point.y);
3135 [view.layer renderInContext:context];
3137 CGContextRelease(context);
3138 CGColorSpaceRelease(colorSpace);
3143 - (void)testHasFirstResponderInViewHierarchySubtree_viewItselfBecomesFirstResponder {
3145 UIWindow* window = [[UIWindow alloc] init];
3146 UITextField* textField = [[UITextField alloc] init];
3147 [window addSubview:textField];
3149 [textField becomeFirstResponder];
3150 XCTAssertTrue(textField.isFirstResponder);
3151 XCTAssertTrue(textField.flt_hasFirstResponderInViewHierarchySubtree);
3152 [textField resignFirstResponder];
3153 XCTAssertFalse(textField.isFirstResponder);
3154 XCTAssertFalse(textField.flt_hasFirstResponderInViewHierarchySubtree);
3157 - (void)testHasFirstResponderInViewHierarchySubtree_descendantViewBecomesFirstResponder {
3159 UIWindow* window = [[UIWindow alloc] init];
3160 UIView* view = [[UIView alloc] init];
3161 UIView* childView = [[UIView alloc] init];
3162 UITextField* textField = [[UITextField alloc] init];
3163 [window addSubview:view];
3164 [view addSubview:childView];
3165 [childView addSubview:textField];
3167 [textField becomeFirstResponder];
3168 XCTAssertTrue(textField.isFirstResponder);
3169 XCTAssertTrue(view.flt_hasFirstResponderInViewHierarchySubtree);
3170 [textField resignFirstResponder];
3171 XCTAssertFalse(textField.isFirstResponder);
3172 XCTAssertFalse(view.flt_hasFirstResponderInViewHierarchySubtree);
3175 - (void)testFlutterClippingMaskViewPoolReuseViewsAfterRecycle {
3181 CGRect newRect = CGRectMake(0, 0, 10, 10);
3185 NSSet* set1 = [NSSet setWithObjects:view1, view2, nil];
3186 NSSet* set2 = [NSSet setWithObjects:view3, view4, nil];
3187 XCTAssertEqualObjects(set1, set2);
3188 XCTAssertTrue(CGRectEqualToRect(view3.frame, newRect));
3189 XCTAssertTrue(CGRectEqualToRect(view4.frame, newRect));
3192 - (void)testFlutterClippingMaskViewPoolAllocsNewMaskViewsAfterReachingCapacity {
3197 XCTAssertNotEqual(view1, view3);
3198 XCTAssertNotEqual(view2, view3);
3201 - (void)testMaskViewsReleasedWhenPoolIsReleased {
3202 __weak UIView* weakView;
3207 XCTAssertNotNil(weakView);
3209 XCTAssertNil(weakView);
3212 - (void)testClipMaskViewIsReused {
3213 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3214 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
3215 flutter::TaskRunners runners(
self.name.UTF8String,
3219 thread_task_runner);
3220 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
3221 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3223 mock_delegate.settings_.enable_impeller
3226 flutterPlatformViewsController,
3229 std::make_shared<fml::SyncSwitch>());
3233 flutterPlatformViewsController->RegisterViewFactory(
3234 factory,
@"MockFlutterPlatformView",
3238 flutterPlatformViewsController->OnMethodCall(
3240 methodCallWithMethodName:
@"create"
3241 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3245 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
3246 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
3248 flutter::MutatorsStack stack1;
3250 SkMatrix screenScaleMatrix =
3251 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3252 stack1.PushTransform(screenScaleMatrix);
3254 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
3255 stack1.PushClipRect(rect);
3257 auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
3258 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3260 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3261 flutterPlatformViewsController->CompositeEmbeddedView(1);
3263 UIView* maskView1 = childClippingView1.maskView;
3264 XCTAssertNotNil(maskView1);
3267 flutterPlatformViewsController->BeginFrame(SkISize::Make(100, 100));
3268 flutter::MutatorsStack stack2;
3269 auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
3270 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3271 auto embeddedViewParams3 = std::make_unique<flutter::EmbeddedViewParams>(
3272 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3273 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams3));
3274 flutterPlatformViewsController->CompositeEmbeddedView(1);
3278 flutterPlatformViewsController->OnMethodCall(
3280 methodCallWithMethodName:
@"create"
3281 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3284 auto embeddedViewParams4 = std::make_unique<flutter::EmbeddedViewParams>(
3285 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3286 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams4));
3287 flutterPlatformViewsController->CompositeEmbeddedView(2);
3290 UIView* maskView2 = childClippingView2.maskView;
3291 XCTAssertEqual(maskView1, maskView2);
3292 XCTAssertNotNil(childClippingView2.maskView);
3293 XCTAssertNil(childClippingView1.maskView);
3296 - (void)testDifferentClipMaskViewIsUsedForEachView {
3297 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3298 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
3299 flutter::TaskRunners runners(
self.name.UTF8String,
3303 thread_task_runner);
3304 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
3305 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3307 mock_delegate.settings_.enable_impeller
3310 flutterPlatformViewsController,
3313 std::make_shared<fml::SyncSwitch>());
3317 flutterPlatformViewsController->RegisterViewFactory(
3318 factory,
@"MockFlutterPlatformView",
3323 flutterPlatformViewsController->OnMethodCall(
3325 methodCallWithMethodName:
@"create"
3326 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3331 flutterPlatformViewsController->OnMethodCall(
3333 methodCallWithMethodName:
@"create"
3334 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3339 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
3340 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
3342 flutter::MutatorsStack stack1;
3344 SkMatrix screenScaleMatrix =
3345 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3346 stack1.PushTransform(screenScaleMatrix);
3348 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
3349 stack1.PushClipRect(rect);
3351 auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
3352 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3354 flutter::MutatorsStack stack2;
3355 stack2.PushClipRect(rect);
3356 auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
3357 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3359 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3360 flutterPlatformViewsController->CompositeEmbeddedView(1);
3361 UIView* childClippingView1 = view1.superview.superview;
3363 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2));
3364 flutterPlatformViewsController->CompositeEmbeddedView(2);
3365 UIView* childClippingView2 = view2.superview.superview;
3366 UIView* maskView1 = childClippingView1.maskView;
3367 UIView* maskView2 = childClippingView2.maskView;
3368 XCTAssertNotEqual(maskView1, maskView2);
3371 - (void)testMaskViewUsesCAShapeLayerAsTheBackingLayer {
3372 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3373 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
3374 flutter::TaskRunners runners(
self.name.UTF8String,
3378 thread_task_runner);
3379 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
3380 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3382 mock_delegate.settings_.enable_impeller
3385 flutterPlatformViewsController,
3388 std::make_shared<fml::SyncSwitch>());
3392 flutterPlatformViewsController->RegisterViewFactory(
3393 factory,
@"MockFlutterPlatformView",
3398 flutterPlatformViewsController->OnMethodCall(
3400 methodCallWithMethodName:
@"create"
3401 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3405 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
3406 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
3408 flutter::MutatorsStack stack1;
3410 SkMatrix screenScaleMatrix =
3411 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3412 stack1.PushTransform(screenScaleMatrix);
3414 SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3);
3415 stack1.PushClipRect(rect);
3417 auto embeddedViewParams1 = std::make_unique<flutter::EmbeddedViewParams>(
3418 screenScaleMatrix, SkSize::Make(10, 10), stack1);
3420 flutter::MutatorsStack stack2;
3421 stack2.PushClipRect(rect);
3422 auto embeddedViewParams2 = std::make_unique<flutter::EmbeddedViewParams>(
3423 screenScaleMatrix, SkSize::Make(10, 10), stack2);
3425 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3426 flutterPlatformViewsController->CompositeEmbeddedView(1);
3429 UIView* maskView = childClippingView.maskView;
3430 XCTAssert([maskView.layer isKindOfClass:[CAShapeLayer
class]],
3431 @"Mask view must use CAShapeLayer as its backing layer.");
3439 - (BOOL)validateOneVisualEffectView:(UIView*)visualEffectView
3440 expectedFrame:(CGRect)frame
3441 inputRadius:(CGFloat)inputRadius {
3442 XCTAssertTrue(CGRectEqualToRect(visualEffectView.frame, frame));
3443 for (UIView* view in visualEffectView.subviews) {
3444 if (![NSStringFromClass([view
class]) hasSuffix:
@"BackdropView"]) {
3447 XCTAssertEqual(view.layer.filters.count, 1u);
3448 NSObject* filter = view.layer.filters.firstObject;
3450 XCTAssertEqualObjects([filter valueForKey:
@"name"],
@"gaussianBlur");
3452 NSObject* inputRadiusInFilter = [filter valueForKey:@"inputRadius"];
3453 XCTAssertTrue([inputRadiusInFilter isKindOfClass:[NSNumber
class]] &&
3461 - (void)testDisposingViewInCompositionOrderDoNotCrash {
3462 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3463 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
3464 flutter::TaskRunners runners(
self.name.UTF8String,
3468 thread_task_runner);
3469 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
3470 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3472 mock_delegate.settings_.enable_impeller
3475 flutterPlatformViewsController,
3478 std::make_shared<fml::SyncSwitch>());
3480 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3481 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
3485 flutterPlatformViewsController->RegisterViewFactory(
3486 factory,
@"MockFlutterPlatformView",
3491 flutterPlatformViewsController->OnMethodCall(
3493 methodCallWithMethodName:
@"create"
3494 arguments:@{
@"id" : @0,
@"viewType" :
@"MockFlutterPlatformView"}],
3496 flutterPlatformViewsController->OnMethodCall(
3498 methodCallWithMethodName:
@"create"
3499 arguments:@{
@"id" : @1,
@"viewType" :
@"MockFlutterPlatformView"}],
3505 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3506 flutter::MutatorsStack stack;
3507 SkMatrix finalMatrix;
3508 auto embeddedViewParams0 =
3509 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3510 flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams0));
3511 flutterPlatformViewsController->CompositeEmbeddedView(0);
3513 auto embeddedViewParams1 =
3514 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3515 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3516 flutterPlatformViewsController->CompositeEmbeddedView(1);
3517 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL);
3519 XCTestExpectation* expectation = [
self expectationWithDescription:@"dispose call ended."];
3521 [expectation fulfill];
3524 flutterPlatformViewsController->OnMethodCall(
3525 [
FlutterMethodCall methodCallWithMethodName:
@"dispose" arguments:@0], disposeResult);
3526 [
self waitForExpectationsWithTimeout:30 handler:nil];
3528 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3529 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3530 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3531 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3532 std::move(mock_sk_surface), framebuffer_info,
3533 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3534 SkISize::Make(800, 600));
3536 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3539 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL);
3540 XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(0));
3541 XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1));
3547 flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300));
3548 flutter::MutatorsStack stack;
3549 SkMatrix finalMatrix;
3550 auto embeddedViewParams1 =
3551 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3552 flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1));
3553 flutterPlatformViewsController->CompositeEmbeddedView(1);
3555 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3556 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3557 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3558 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3559 std::move(mock_sk_surface), framebuffer_info,
3560 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3561 SkISize::Make(800, 600));
3563 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface)));
3566 XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL);
3567 XCTAssertNil(flutterPlatformViewsController->GetPlatformViewByID(0));
3568 XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1));
3571 - (void)testOnlyPlatformViewsAreRemovedWhenReset {
3572 flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3573 auto thread_task_runner =
CreateNewThread(
"FlutterPlatformViewsTest");
3574 flutter::TaskRunners runners(
self.name.UTF8String,
3578 thread_task_runner);
3579 auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
3580 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3582 mock_delegate.settings_.enable_impeller
3585 flutterPlatformViewsController,
3588 std::make_shared<fml::SyncSwitch>());
3592 flutterPlatformViewsController->RegisterViewFactory(
3593 factory,
@"MockFlutterPlatformView",
3597 flutterPlatformViewsController->OnMethodCall(
3599 methodCallWithMethodName:
@"create"
3600 arguments:@{
@"id" : @2,
@"viewType" :
@"MockFlutterPlatformView"}],
3602 UIView* mockFlutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
3603 flutterPlatformViewsController->SetFlutterView(mockFlutterView);
3605 flutter::MutatorsStack stack;
3607 SkMatrix screenScaleMatrix =
3608 SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
3609 stack.PushTransform(screenScaleMatrix);
3611 SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
3612 stack.PushTransform(translateMatrix);
3613 SkMatrix finalMatrix;
3614 finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
3616 auto embeddedViewParams =
3617 std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
3619 flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
3620 flutterPlatformViewsController->CompositeEmbeddedView(2);
3623 const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000);
3624 sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster(image_info);
3625 flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3626 auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3627 std::move(mock_sk_surface), framebuffer_info,
3628 [](
const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) {
return true; },
3629 SkISize::Make(800, 600));
3631 flutterPlatformViewsController->SubmitFrame(
nullptr,
nullptr, std::move(mock_surface));
3633 UIView* someView = [[UIView alloc] init];
3634 [mockFlutterView addSubview:someView];
3636 flutterPlatformViewsController->Reset();
3637 XCTAssertEqual(mockFlutterView.subviews.count, 1u);
3638 XCTAssertEqual(mockFlutterView.subviews.firstObject, someView);
3641 - (void)testFlutterTouchInterceptingViewLinksToAccessibilityContainer {
3643 NSObject* container = [[NSObject alloc] init];
3644 [touchInteceptorView setFlutterAccessibilityContainer:container];
3645 XCTAssertEqualObjects([touchInteceptorView accessibilityContainer], container);