From 8eab0d9b79c5170546d27e93ef06e1ffc0cef616 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 3 Mar 2023 10:54:01 -0800 Subject: [PATCH 01/27] Upload xcresults to LUCI cloud storage test fail add logs add try catch format format add scenario app test failure log zip and upload fix raise exception update if else add curly braces --- .../Source/FlutterPlatformViewsTest.mm | 2 +- testing/run_tests.py | 29 ++++++++++- .../scenario_app/lib/src/platform_view.dart | 2 +- testing/scenario_app/run_ios_tests.sh | 49 ++++++++++++++----- 4 files changed, 65 insertions(+), 17 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 97285cfcc78be..7155bd59b2c8d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -219,7 +219,7 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], result); - XCTAssertNotNil(gMockPlatformView); + XCTAssertNil(gMockPlatformView); } - (void)testChildClippingViewHitTests { diff --git a/testing/run_tests.py b/testing/run_tests.py index f800a474544a6..d5c16f0209dbd 100755 --- a/testing/run_tests.py +++ b/testing/run_tests.py @@ -17,6 +17,7 @@ import multiprocessing import os import re +import shutil import subprocess import sys import tempfile @@ -752,6 +753,12 @@ def run_objc_tests(ios_variant='ios_debug_sim_unopt', test_filter=None): ios_unit_test_dir = os.path.join( BUILDROOT_DIR, 'flutter', 'testing', 'ios', 'IosUnitTests' ) + + result_bundle_temp = tempfile.TemporaryDirectory( + suffix='ios_embedding_xcresult' + ).name + result_bundle_path = os.path.join(result_bundle_temp, 'ios_embedding') + # Avoid using xcpretty unless the following can be addressed: # - Make sure all relevant failure output is printed on a failure. # - Make sure that a failing exit code is set for CI. @@ -760,13 +767,31 @@ def run_objc_tests(ios_variant='ios_debug_sim_unopt', test_filter=None): 'xcodebuild ' '-sdk iphonesimulator ' '-scheme IosUnitTests ' - "-destination name='" + new_simulator_name + "' " + '-resultBundlePath ' + result_bundle_path + " -destination name='" + + new_simulator_name + "' " 'test ' 'FLUTTER_ENGINE=' + ios_variant ] if test_filter is not None: test_command[0] = test_command[0] + ' -only-testing:%s' % test_filter - run_cmd(test_command, cwd=ios_unit_test_dir, shell=True) + try: + run_cmd(test_command, cwd=ios_unit_test_dir, shell=True) + except: + # The LUCI environment may provide a variable containing a directory path + # for additional output files that will be uploaded to cloud storage. + # Upload the xcresult when the tests fail. + luci_test_outputs_path = os.environ.get('FLUTTER_TEST_OUTPUTS_DIR') + xcresult_bundle = os.path.join( + result_bundle_temp, 'ios_embedding.xcresult' + ) + if luci_test_outputs_path and os.path.exists(xcresult_bundle): + dump_path = os.path.join( + luci_test_outputs_path, 'ios_embedding.xcresult' + ) + # xcresults contain many little files. Archive the bundle before upload. + shutil.make_archive(dump_path, 'zip', root_dir=xcresult_bundle) + raise + finally: delete_simulator(new_simulator_name) diff --git a/testing/scenario_app/lib/src/platform_view.dart b/testing/scenario_app/lib/src/platform_view.dart index 75ccd395206be..d3349dadfdb1a 100644 --- a/testing/scenario_app/lib/src/platform_view.dart +++ b/testing/scenario_app/lib/src/platform_view.dart @@ -539,7 +539,7 @@ class PlatformViewClipRectScenario extends Scenario with _BasePlatformViewScenar @override void onBeginFrame(Duration duration) { final SceneBuilder builder = SceneBuilder() - ..pushClipRect(const Rect.fromLTRB(100, 100, 400, 400)); + ..pushClipRect(const Rect.fromLTRB(90, 100, 400, 400)); addPlatformView( id, diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index fd84de214150f..da93c5788284d 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -41,25 +41,48 @@ fi # Can also be set via Simulator app Device > Rotate Device Automatically defaults write com.apple.iphonesimulator RotateWindowWhenSignaledByGuest -int 1 -cd $SRC_DIR/out/$FLUTTER_ENGINE/scenario_app/Scenarios +SCENARIO_PATH=$SRC_DIR/out/$FLUTTER_ENGINE/scenario_app/Scenarios +cd $SCENARIO_PATH echo "Running simulator tests with Skia" echo "" -set -o pipefail && xcodebuild -sdk iphonesimulator \ - -scheme Scenarios \ - -destination 'platform=iOS Simulator,OS=16.2,name=iPhone SE (3rd generation)' \ - clean test \ - FLUTTER_ENGINE="$FLUTTER_ENGINE" +RESULT_BUNDLE_FOLDER="ios_scenario_xcresult" +RESULT_BUNDLE_PATH="${SCENARIO_PATH}/${RESULT_BUNDLE_FOLDER}" -echo "Running simulator tests with Impeller" -echo "" +mktemp -d $RESULT_BUNDLE_PATH +trap 'rm -rf $RESULT_BUNDLE_PATH' EXIT -# Skip testFontRenderingWhenSuppliedWithBogusFont: https://github.com/flutter/flutter/issues/113250 -set -o pipefail && xcodebuild -sdk iphonesimulator \ +if set -o pipefail && xcodebuild -sdk iphonesimulator \ -scheme Scenarios \ + -resultBundlePath "$RESULT_BUNDLE_PATH/ios_scenario.xcresult" \ -destination 'platform=iOS Simulator,OS=16.2,name=iPhone SE (3rd generation)' \ clean test \ - FLUTTER_ENGINE="$FLUTTER_ENGINE" \ - -skip-testing "ScenariosUITests/BogusFontTextTest/testFontRenderingWhenSuppliedWithBogusFont" \ - INFOPLIST_FILE="Scenarios/Info_Impeller.plist" # Plist with FLTEnableImpeller=YES + FLUTTER_ENGINE="$FLUTTER_ENGINE"; then + echo "success" +else + echo "cyanglaz scenario test failed" + + LUCI_TEST_OUTPUTS_PATH="${FLUTTER_TEST_OUTPUTS_DIR:-NULL}" + echo "LUCI_TEST_OUTPUTS_PATH ${LUCI_TEST_OUTPUTS_PATH}" + DUMP_PATH=$LUCI_TEST_OUTPUTS_PATH/ios_scenario_xcresult + echo "Zip" + # Using RESULT_BUNDLE_PATH causes the zip containing all the sub directories. + # So use relative directory instead. + zip -q ios_scenario_xcresult.zip "./$RESULT_BUNDLE_FOLDER" + mv ios_scenario_xcresult.zip $LUCI_TEST_OUTPUTS_PATH +fi + +# echo "Running simulator tests with Impeller" +# echo "" + +# # Skip testFontRenderingWhenSuppliedWithBogusFont: https://github.com/flutter/flutter/issues/113250 +# if set -o pipefail && xcodebuild -sdk iphonesimulator \ +# -scheme Scenarios \ +# -destination 'platform=iOS Simulator,OS=16.2,name=iPhone SE (3rd generation)' \ +# clean test \ +# FLUTTER_ENGINE="$FLUTTER_ENGINE" \ +# -skip-testing "ScenariosUITests/BogusFontTextTest/testFontRenderingWhenSuppliedWithBogusFont" \ +# INFOPLIST_FILE="Scenarios/Info_Impeller.plist"; then # Plist with FLTEnableImpeller=YES +# echo "cyanglaz scenario test failed" +# fi From 8722a94f235bd6b0c9c7e0fb6cf47de9c7da4a69 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 9 May 2023 10:17:32 -0700 Subject: [PATCH 02/27] make unittest success --- .../darwin/ios/framework/Source/FlutterPlatformViewsTest.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 7155bd59b2c8d..718533fcf0e82 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -219,7 +219,7 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], result); - XCTAssertNil(gMockPlatformView); + XCTAsserNottNil(gMockPlatformView); } - (void)testChildClippingViewHitTests { From c75159204b42c50fe6e0a4078e9d3d046b7d0af8 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 9 May 2023 11:23:13 -0700 Subject: [PATCH 03/27] fix --- .../darwin/ios/framework/Source/FlutterPlatformViewsTest.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 718533fcf0e82..02deb0c76e21f 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -219,7 +219,7 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], result); - XCTAsserNottNil(gMockPlatformView); + XCTAsserNotNil(gMockPlatformView); } - (void)testChildClippingViewHitTests { From ca62d55a2f5e28229d3d386f3833fa90b7ff3be7 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 9 May 2023 14:15:00 -0700 Subject: [PATCH 04/27] fix --- .../darwin/ios/framework/Source/FlutterPlatformViewsTest.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 02deb0c76e21f..97285cfcc78be 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -219,7 +219,7 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], result); - XCTAsserNotNil(gMockPlatformView); + XCTAssertNotNil(gMockPlatformView); } - (void)testChildClippingViewHitTests { From 7d90efb36f0fe6cacabbb59913235d59ae1fab56 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 9 May 2023 18:02:46 -0700 Subject: [PATCH 05/27] fix and temp disable tests --- .../Source/FlutterPlatformViewsTest.mm | 5352 ++++++++--------- .../ScenariosUITests/PlatformViewUITests.m | 526 +- .../UnobstructedPlatformViewTests.m | 592 +- testing/scenario_app/run_ios_tests.sh | 4 +- 4 files changed, 3237 insertions(+), 3237 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 97285cfcc78be..2fc4d1466b10d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -222,2679 +222,2679 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { XCTAssertNotNil(gMockPlatformView); } -- (void)testChildClippingViewHitTests { - ChildClippingView* childClippingView = - [[[ChildClippingView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; - UIView* childView = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] autorelease]; - [childClippingView addSubview:childView]; - - XCTAssertFalse([childClippingView pointInside:CGPointMake(50, 50) withEvent:nil]); - XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 100) withEvent:nil]); - XCTAssertFalse([childClippingView pointInside:CGPointMake(100, 99) withEvent:nil]); - XCTAssertFalse([childClippingView pointInside:CGPointMake(201, 200) withEvent:nil]); - XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 201) withEvent:nil]); - XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 200) withEvent:nil]); - XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 299) withEvent:nil]); - - XCTAssertTrue([childClippingView pointInside:CGPointMake(150, 150) withEvent:nil]); - XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 100) withEvent:nil]); - XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 100) withEvent:nil]); - XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 199) withEvent:nil]); - XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 199) withEvent:nil]); -} - -- (void)testApplyBackdropFilter { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - CGFloat screenScale = [UIScreen mainScreen].scale; - SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); - stack.PushTransform(screenScaleMatrix); - // Push a backdrop filter - auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); - stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - // childClippingView has visual effect view with the correct configurations. - NSUInteger numberOfExpectedVisualEffectView = 0; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:5]) { - numberOfExpectedVisualEffectView++; - } - } - XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); -} - -- (void)testApplyBackdropFilterWithCorrectFrame { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - CGFloat screenScale = [UIScreen mainScreen].scale; - SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); - stack.PushTransform(screenScaleMatrix); - // Push a backdrop filter - auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); - stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 8, screenScale * 8)); - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(5, 10), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - // childClippingView has visual effect view with the correct configurations. - NSUInteger numberOfExpectedVisualEffectView = 0; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 5, 8) - inputRadius:5]) { - numberOfExpectedVisualEffectView++; - } - } - XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); -} - -- (void)testApplyMultipleBackdropFilters { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - CGFloat screenScale = [UIScreen mainScreen].scale; - SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); - stack.PushTransform(screenScaleMatrix); - // Push backdrop filters - for (int i = 0; i < 50; i++) { - auto filter = std::make_shared(i, 2, flutter::DlTileMode::kClamp); - stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(20, 20), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - NSUInteger numberOfExpectedVisualEffectView = 0; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(numberOfExpectedVisualEffectView, 50u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)numberOfExpectedVisualEffectView]) { - numberOfExpectedVisualEffectView++; - } - } - XCTAssertEqual(numberOfExpectedVisualEffectView, (NSUInteger)numberOfExpectedVisualEffectView); -} - -- (void)testAddBackdropFilters { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - CGFloat screenScale = [UIScreen mainScreen].scale; - SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); - stack.PushTransform(screenScaleMatrix); - // Push a backdrop filter - auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); - stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(originalVisualEffectViews.count, 1u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)5]) { - [originalVisualEffectViews addObject:subview]; - } - } - XCTAssertEqual(originalVisualEffectViews.count, 1u); - - // - // Simulate adding 1 backdrop filter (create a new mutators stack) - // Create embedded view params - flutter::MutatorsStack stack2; - // Layer tree always pushes a screen scale factor to the stack - stack2.PushTransform(screenScaleMatrix); - // Push backdrop filters - for (int i = 0; i < 2; i++) { - stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(newVisualEffectViews.count, 2u); - - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)5]) { - [newVisualEffectViews addObject:subview]; - } - } - XCTAssertEqual(newVisualEffectViews.count, 2u); - for (NSUInteger i = 0; i < originalVisualEffectViews.count; i++) { - UIView* originalView = originalVisualEffectViews[i]; - UIView* newView = newVisualEffectViews[i]; - // Compare reference. - XCTAssertEqual(originalView, newView); - id mockOrignalView = OCMPartialMock(originalView); - OCMReject([mockOrignalView removeFromSuperview]); - } -} - -- (void)testRemoveBackdropFilters { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - CGFloat screenScale = [UIScreen mainScreen].scale; - SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); - stack.PushTransform(screenScaleMatrix); - // Push backdrop filters - auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); - for (int i = 0; i < 5; i++) { - stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(originalVisualEffectViews.count, 5u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)5]) { - [originalVisualEffectViews addObject:subview]; - } - } - - // Simulate removing 1 backdrop filter (create a new mutators stack) - // Create embedded view params - flutter::MutatorsStack stack2; - // Layer tree always pushes a screen scale factor to the stack - stack2.PushTransform(screenScaleMatrix); - // Push backdrop filters - for (int i = 0; i < 4; i++) { - stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(newVisualEffectViews.count, 4u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)5]) { - [newVisualEffectViews addObject:subview]; - } - } - XCTAssertEqual(newVisualEffectViews.count, 4u); - - for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { - UIView* newView = newVisualEffectViews[i]; - id mockNewView = OCMPartialMock(newView); - UIView* originalView = originalVisualEffectViews[i]; - // Compare reference. - XCTAssertEqual(originalView, newView); - OCMReject([mockNewView removeFromSuperview]); - [mockNewView stopMocking]; - } - - // Simulate removing all backdrop filters (replace the mutators stack) - // Update embedded view params, delete except screenScaleMatrix - for (int i = 0; i < 5; i++) { - stack2.Pop(); - } - // No backdrop filters in the stack, so no nothing to push - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - NSUInteger numberOfExpectedVisualEffectView = 0u; - for (UIView* subview in childClippingView.subviews) { - if ([subview isKindOfClass:[UIVisualEffectView class]]) { - numberOfExpectedVisualEffectView++; - } - } - XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); -} - -- (void)testEditBackdropFilters { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - CGFloat screenScale = [UIScreen mainScreen].scale; - SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); - stack.PushTransform(screenScaleMatrix); - // Push backdrop filters - auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); - for (int i = 0; i < 5; i++) { - stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(originalVisualEffectViews.count, 5u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)5]) { - [originalVisualEffectViews addObject:subview]; - } - } - - // Simulate editing 1 backdrop filter in the middle of the stack (create a new mutators stack) - // Create embedded view params - flutter::MutatorsStack stack2; - // Layer tree always pushes a screen scale factor to the stack - stack2.PushTransform(screenScaleMatrix); - // Push backdrop filters - for (int i = 0; i < 5; i++) { - if (i == 3) { - auto filter2 = - std::make_shared(2, 5, flutter::DlTileMode::kClamp); - - stack2.PushBackdropFilter(filter2, - SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - continue; - } - - stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(newVisualEffectViews.count, 5u); - CGFloat expectInputRadius = 5; - if (newVisualEffectViews.count == 3) { - expectInputRadius = 2; - } - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)expectInputRadius]) { - [newVisualEffectViews addObject:subview]; - } - } - XCTAssertEqual(newVisualEffectViews.count, 5u); - for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { - UIView* newView = newVisualEffectViews[i]; - id mockNewView = OCMPartialMock(newView); - UIView* originalView = originalVisualEffectViews[i]; - // Compare reference. - XCTAssertEqual(originalView, newView); - OCMReject([mockNewView removeFromSuperview]); - [mockNewView stopMocking]; - } - [newVisualEffectViews removeAllObjects]; - - // Simulate editing 1 backdrop filter in the beginning of the stack (replace the mutators stack) - // Update embedded view params, delete except screenScaleMatrix - for (int i = 0; i < 5; i++) { - stack2.Pop(); - } - // Push backdrop filters - for (int i = 0; i < 5; i++) { - if (i == 0) { - auto filter2 = - std::make_shared(2, 5, flutter::DlTileMode::kClamp); - stack2.PushBackdropFilter(filter2, - SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - continue; - } - - stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(newVisualEffectViews.count, 5u); - CGFloat expectInputRadius = 5; - if (newVisualEffectViews.count == 0) { - expectInputRadius = 2; - } - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)expectInputRadius]) { - [newVisualEffectViews addObject:subview]; - } - } - for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { - UIView* newView = newVisualEffectViews[i]; - id mockNewView = OCMPartialMock(newView); - UIView* originalView = originalVisualEffectViews[i]; - // Compare reference. - XCTAssertEqual(originalView, newView); - OCMReject([mockNewView removeFromSuperview]); - [mockNewView stopMocking]; - } - [newVisualEffectViews removeAllObjects]; - - // Simulate editing 1 backdrop filter in the end of the stack (replace the mutators stack) - // Update embedded view params, delete except screenScaleMatrix - for (int i = 0; i < 5; i++) { - stack2.Pop(); - } - // Push backdrop filters - for (int i = 0; i < 5; i++) { - if (i == 4) { - auto filter2 = - std::make_shared(2, 5, flutter::DlTileMode::kClamp); - stack2.PushBackdropFilter(filter2, - SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - continue; - } - - stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(newVisualEffectViews.count, 5u); - CGFloat expectInputRadius = 5; - if (newVisualEffectViews.count == 4) { - expectInputRadius = 2; - } - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)expectInputRadius]) { - [newVisualEffectViews addObject:subview]; - } - } - XCTAssertEqual(newVisualEffectViews.count, 5u); - - for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { - UIView* newView = newVisualEffectViews[i]; - id mockNewView = OCMPartialMock(newView); - UIView* originalView = originalVisualEffectViews[i]; - // Compare reference. - XCTAssertEqual(originalView, newView); - OCMReject([mockNewView removeFromSuperview]); - [mockNewView stopMocking]; - } - [newVisualEffectViews removeAllObjects]; - - // Simulate editing all backdrop filters in the stack (replace the mutators stack) - // Update embedded view params, delete except screenScaleMatrix - for (int i = 0; i < 5; i++) { - stack2.Pop(); - } - // Push backdrop filters - for (int i = 0; i < 5; i++) { - auto filter2 = std::make_shared(i, 2, flutter::DlTileMode::kClamp); - - stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(newVisualEffectViews.count, 5u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)newVisualEffectViews.count]) { - [newVisualEffectViews addObject:subview]; - } - } - XCTAssertEqual(newVisualEffectViews.count, 5u); - - for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { - UIView* newView = newVisualEffectViews[i]; - id mockNewView = OCMPartialMock(newView); - UIView* originalView = originalVisualEffectViews[i]; - // Compare reference. - XCTAssertEqual(originalView, newView); - OCMReject([mockNewView removeFromSuperview]); - [mockNewView stopMocking]; - } - [newVisualEffectViews removeAllObjects]; -} - -- (void)testApplyBackdropFilterNotDlBlurImageFilter { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - CGFloat screenScale = [UIScreen mainScreen].scale; - SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); - stack.PushTransform(screenScaleMatrix); - // Push a dilate backdrop filter - auto dilateFilter = std::make_shared(5, 2); - stack.PushBackdropFilter(dilateFilter, SkRect::MakeEmpty()); - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - NSUInteger numberOfExpectedVisualEffectView = 0; - for (UIView* subview in childClippingView.subviews) { - if ([subview isKindOfClass:[UIVisualEffectView class]]) { - numberOfExpectedVisualEffectView++; - } - } - XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); - - // Simulate adding a non-DlBlurImageFilter in the middle of the stack (create a new mutators - // stack) Create embedded view params - flutter::MutatorsStack stack2; - // Layer tree always pushes a screen scale factor to the stack - stack2.PushTransform(screenScaleMatrix); - // Push backdrop filters and dilate filter - auto blurFilter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); - - for (int i = 0; i < 5; i++) { - if (i == 2) { - stack2.PushBackdropFilter(dilateFilter, - SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - continue; - } - - stack2.PushBackdropFilter(blurFilter, - SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - numberOfExpectedVisualEffectView = 0; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)5]) { - numberOfExpectedVisualEffectView++; - } - } - XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); - - // Simulate adding a non-DlBlurImageFilter to the beginning of the stack (replace the mutators - // stack) Update embedded view params, delete except screenScaleMatrix - for (int i = 0; i < 5; i++) { - stack2.Pop(); - } - // Push backdrop filters and dilate filter - for (int i = 0; i < 5; i++) { - if (i == 0) { - stack2.PushBackdropFilter(dilateFilter, - SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - continue; - } - - stack2.PushBackdropFilter(blurFilter, - SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - numberOfExpectedVisualEffectView = 0; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)5]) { - numberOfExpectedVisualEffectView++; - } - } - XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); - - // Simulate adding a non-DlBlurImageFilter to the end of the stack (replace the mutators stack) - // Update embedded view params, delete except screenScaleMatrix - for (int i = 0; i < 5; i++) { - stack2.Pop(); - } - // Push backdrop filters and dilate filter - for (int i = 0; i < 5; i++) { - if (i == 4) { - stack2.PushBackdropFilter(dilateFilter, - SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - continue; - } - - stack2.PushBackdropFilter(blurFilter, - SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - numberOfExpectedVisualEffectView = 0; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:(CGFloat)5]) { - numberOfExpectedVisualEffectView++; - } - } - XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); - - // Simulate adding only non-DlBlurImageFilter to the stack (replace the mutators stack) - // Update embedded view params, delete except screenScaleMatrix - for (int i = 0; i < 5; i++) { - stack2.Pop(); - } - // Push dilate filters - for (int i = 0; i < 5; i++) { - stack2.PushBackdropFilter(dilateFilter, - SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - } - - embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - numberOfExpectedVisualEffectView = 0; - for (UIView* subview in childClippingView.subviews) { - if ([subview isKindOfClass:[UIVisualEffectView class]]) { - numberOfExpectedVisualEffectView++; - } - } - XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); -} - -- (void)testApplyBackdropFilterCorrectAPI { - [PlatformViewFilter resetPreparation]; - // The gaussianBlur filter is extracted from UIVisualEffectView. - // Each test requires a new PlatformViewFilter - // Valid UIVisualEffectView API - UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] - initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; - PlatformViewFilter* platformViewFilter = - [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) - blurRadius:5 - visualEffectView:visualEffectView]; - XCTAssertNotNil(platformViewFilter); -} - -- (void)testApplyBackdropFilterAPIChangedInvalidUIVisualEffectView { - [PlatformViewFilter resetPreparation]; - UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] init]; - PlatformViewFilter* platformViewFilter = - [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) - blurRadius:5 - visualEffectView:visualEffectView]; - XCTAssertNil(platformViewFilter); -} - -- (void)testApplyBackdropFilterAPIChangedNoGaussianBlurFilter { - [PlatformViewFilter resetPreparation]; - UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc] - initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; - NSArray* subviews = editedUIVisualEffectView.subviews; - for (UIView* view in subviews) { - if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { - for (CIFilter* filter in view.layer.filters) { - if ([[filter valueForKey:@"name"] isEqual:@"gaussianBlur"]) { - [filter setValue:@"notGaussianBlur" forKey:@"name"]; - break; - } - } - break; - } - } - PlatformViewFilter* platformViewFilter = - [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) - blurRadius:5 - visualEffectView:editedUIVisualEffectView]; - XCTAssertNil(platformViewFilter); -} - -- (void)testApplyBackdropFilterAPIChangedInvalidInputRadius { - [PlatformViewFilter resetPreparation]; - UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc] - initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; - NSArray* subviews = editedUIVisualEffectView.subviews; - for (UIView* view in subviews) { - if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { - for (CIFilter* filter in view.layer.filters) { - if ([[filter valueForKey:@"name"] isEqual:@"gaussianBlur"]) { - [filter setValue:@"invalidInputRadius" forKey:@"inputRadius"]; - break; - } - } - break; - } - } - - PlatformViewFilter* platformViewFilter = - [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) - blurRadius:5 - visualEffectView:editedUIVisualEffectView]; - XCTAssertNil(platformViewFilter); -} - -- (void)testBackdropFilterVisualEffectSubviewBackgroundColor { - UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] - initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; - PlatformViewFilter* platformViewFilter = - [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) - blurRadius:5 - visualEffectView:visualEffectView]; - CGColorRef visualEffectSubviewBackgroundColor; - for (UIView* view in [platformViewFilter backdropFilterView].subviews) { - if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectSubview")]) { - visualEffectSubviewBackgroundColor = view.layer.backgroundColor; - } - } - XCTAssertTrue( - CGColorEqualToColor(visualEffectSubviewBackgroundColor, UIColor.clearColor.CGColor)); -} - -- (void)testCompositePlatformView { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - SkMatrix screenScaleMatrix = - SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); - stack.PushTransform(screenScaleMatrix); - // Push a translate matrix - SkMatrix translateMatrix = SkMatrix::Translate(100, 100); - stack.PushTransform(translateMatrix); - SkMatrix finalMatrix; - finalMatrix.setConcat(screenScaleMatrix, translateMatrix); - - auto embeddedViewParams = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds - toView:mockFlutterView]; - XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, 300))); -} - -- (void)testBackdropFilterCorrectlyPushedAndReset { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - CGFloat screenScale = [UIScreen mainScreen].scale; - SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); - stack.PushTransform(screenScaleMatrix); - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); - - flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->PushVisitedPlatformView(2); - auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); - flutterPlatformViewsController->PushFilterToVisitedPlatformViews( - filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - // childClippingView has visual effect view with the correct configurations. - NSUInteger numberOfExpectedVisualEffectView = 0; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); - if ([self validateOneVisualEffectView:subview - expectedFrame:CGRectMake(0, 0, 10, 10) - inputRadius:5]) { - numberOfExpectedVisualEffectView++; - } - } - XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); - - // New frame, with no filter pushed. - auto embeddedViewParams2 = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); - flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - numberOfExpectedVisualEffectView = 0; - for (UIView* subview in childClippingView.subviews) { - if (![subview isKindOfClass:[UIVisualEffectView class]]) { - continue; - } - numberOfExpectedVisualEffectView++; - } - XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); -} - -- (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - SkMatrix screenScaleMatrix = - SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); - stack.PushTransform(screenScaleMatrix); - // Push a rotate matrix - SkMatrix rotateMatrix; - rotateMatrix.setRotate(10); - stack.PushTransform(rotateMatrix); - SkMatrix finalMatrix; - finalMatrix.setConcat(screenScaleMatrix, rotateMatrix); - - auto embeddedViewParams = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds - toView:mockFlutterView]; - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - // The childclippingview's frame is set based on flow, but the platform view's frame is set based - // on quartz. Although they should be the same, but we should tolerate small floating point - // errors. - XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - childClippingView.frame.origin.x), - kFloatCompareEpsilon); - XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - childClippingView.frame.origin.y), - kFloatCompareEpsilon); - XCTAssertLessThan( - fabs(platformViewRectInFlutterView.size.width - childClippingView.frame.size.width), - kFloatCompareEpsilon); - XCTAssertLessThan( - fabs(platformViewRectInFlutterView.size.height - childClippingView.frame.size.height), - kFloatCompareEpsilon); -} - -- (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params. - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack. - SkMatrix screenScaleMatrix = - SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); - stack.PushTransform(screenScaleMatrix); - SkMatrix translateMatrix = SkMatrix::Translate(5, 5); - // The platform view's rect for this test will be (5, 5, 10, 10). - stack.PushTransform(translateMatrix); - // Push a clip rect, big enough to contain the entire platform view bound. - SkRect rect = SkRect::MakeXYWH(0, 0, 25, 25); - stack.PushClipRect(rect); - // Push a clip rrect, big enough to contain the entire platform view bound without clipping it. - // Make the origin (-1, -1) so that the top left rounded corner isn't clipping the PlatformView. - SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25); - SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); - stack.PushClipRRect(rrect); - - auto embeddedViewParams = std::make_unique( - SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - gMockPlatformView.backgroundColor = UIColor.redColor; - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - XCTAssertNil(childClippingView.maskView); -} - -- (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack. - SkMatrix screenScaleMatrix = - SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); - stack.PushTransform(screenScaleMatrix); - SkMatrix translateMatrix = SkMatrix::Translate(5, 5); - // The platform view's rect for this test will be (5, 5, 10, 10). - stack.PushTransform(translateMatrix); - - // Push a clip rrect, the rect of the rrect is the same as the PlatformView of the corner should. - // clip the PlatformView. - SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10); - SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); - stack.PushClipRRect(rrect); - - auto embeddedViewParams = std::make_unique( - SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - gMockPlatformView.backgroundColor = UIColor.redColor; - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - XCTAssertNotNil(childClippingView.maskView); -} - -- (void)testClipRect { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - SkMatrix screenScaleMatrix = - SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); - stack.PushTransform(screenScaleMatrix); - // Push a clip rect - SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3); - stack.PushClipRect(rect); - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - gMockPlatformView.backgroundColor = UIColor.redColor; - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10; j++) { - CGPoint point = CGPointMake(i, j); - int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; - // Edges of the clipping might have a semi transparent pixel, we only check the pixels that - // are fully inside the clipped area. - CGRect insideClipping = CGRectMake(3, 3, 1, 1); - if (CGRectContainsPoint(insideClipping, point)) { - XCTAssertEqual(alpha, 255); - } else { - XCTAssertLessThan(alpha, 255); - } - } - } -} - -- (void)testClipRRect { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - SkMatrix screenScaleMatrix = - SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); - stack.PushTransform(screenScaleMatrix); - // Push a clip rrect - SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1); - stack.PushClipRRect(rrect); - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - gMockPlatformView.backgroundColor = UIColor.redColor; - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10; j++) { - CGPoint point = CGPointMake(i, j); - int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; - // Edges of the clipping might have a semi transparent pixel, we only check the pixels that - // are fully inside the clipped area. - CGRect insideClipping = CGRectMake(3, 3, 4, 4); - if (CGRectContainsPoint(insideClipping, point)) { - XCTAssertEqual(alpha, 255); - } else { - XCTAssertLessThan(alpha, 255); - } - } - } -} - -- (void)testClipPath { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack; - // Layer tree always pushes a screen scale factor to the stack - SkMatrix screenScaleMatrix = - SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); - stack.PushTransform(screenScaleMatrix); - // Push a clip path - SkPath path; - path.addRoundRect(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1); - stack.PushClipPath(path); - - auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - gMockPlatformView.backgroundColor = UIColor.redColor; - XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - [mockFlutterView addSubview:childClippingView]; - - [mockFlutterView setNeedsLayout]; - [mockFlutterView layoutIfNeeded]; - - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10; j++) { - CGPoint point = CGPointMake(i, j); - int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; - // Edges of the clipping might have a semi transparent pixel, we only check the pixels that - // are fully inside the clipped area. - CGRect insideClipping = CGRectMake(3, 3, 4, 4); - if (CGRectContainsPoint(insideClipping, point)) { - XCTAssertEqual(alpha, 255); - } else { - XCTAssertLessThan(alpha, 255); - } - } - } -} - -- (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - // Find touch inteceptor view - UIView* touchInteceptorView = gMockPlatformView; - while (touchInteceptorView != nil && - ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { - touchInteceptorView = touchInteceptorView.superview; - } - XCTAssertNotNil(touchInteceptorView); - - // Find ForwardGestureRecognizer - UIGestureRecognizer* forwardGectureRecognizer = nil; - for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { - forwardGectureRecognizer = gestureRecognizer; - break; - } - } - - // Before setting flutter view controller, events are not dispatched. - NSSet* touches1 = [[[NSSet alloc] init] autorelease]; - id event1 = OCMClassMock([UIEvent class]); - id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); - [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; - OCMReject([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); - - // Set flutter view controller allows events to be dispatched. - NSSet* touches2 = [[[NSSet alloc] init] autorelease]; - id event2 = OCMClassMock([UIEvent class]); - flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); - [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2]; - OCMVerify([mockFlutterViewContoller touchesBegan:touches2 withEvent:event2]); -} - -- (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGesturesToBeHandled { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - // Find touch inteceptor view - UIView* touchInteceptorView = gMockPlatformView; - while (touchInteceptorView != nil && - ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { - touchInteceptorView = touchInteceptorView.superview; - } - XCTAssertNotNil(touchInteceptorView); - - // Find ForwardGestureRecognizer - UIGestureRecognizer* forwardGectureRecognizer = nil; - for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { - forwardGectureRecognizer = gestureRecognizer; - break; - } - } - id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); - { - // ***** Sequence 1, finishing touch event with touchEnded ***** // - flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); - - NSSet* touches1 = [[[NSSet alloc] init] autorelease]; - id event1 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; - OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); - - flutterPlatformViewsController->SetFlutterViewController(nil); - - // Allow the touch events to finish - NSSet* touches2 = [[[NSSet alloc] init] autorelease]; - id event2 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2]; - OCMVerify([mockFlutterViewContoller touchesMoved:touches2 withEvent:event2]); - - NSSet* touches3 = [[[NSSet alloc] init] autorelease]; - id event3 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesEnded:touches3 withEvent:event3]; - OCMVerify([mockFlutterViewContoller touchesEnded:touches3 withEvent:event3]); - - // Now the 2nd touch sequence should not be allowed. - NSSet* touches4 = [[[NSSet alloc] init] autorelease]; - id event4 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4]; - OCMReject([mockFlutterViewContoller touchesBegan:touches4 withEvent:event4]); - - NSSet* touches5 = [[[NSSet alloc] init] autorelease]; - id event5 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; - OCMReject([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); - } - - { - // ***** Sequence 2, finishing touch event with touchCancelled ***** // - flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); - - NSSet* touches1 = [[[NSSet alloc] init] autorelease]; - id event1 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; - OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); - - flutterPlatformViewsController->SetFlutterViewController(nil); - - // Allow the touch events to finish - NSSet* touches2 = [[[NSSet alloc] init] autorelease]; - id event2 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2]; - OCMVerify([mockFlutterViewContoller touchesMoved:touches2 withEvent:event2]); - - NSSet* touches3 = [[[NSSet alloc] init] autorelease]; - id event3 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesCancelled:touches3 withEvent:event3]; - OCMVerify([mockFlutterViewContoller forceTouchesCancelled:touches3]); - - // Now the 2nd touch sequence should not be allowed. - NSSet* touches4 = [[[NSSet alloc] init] autorelease]; - id event4 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4]; - OCMReject([mockFlutterViewContoller touchesBegan:touches4 withEvent:event4]); - - NSSet* touches5 = [[[NSSet alloc] init] autorelease]; - id event5 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; - OCMReject([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); - } - - flutterPlatformViewsController->Reset(); -} - -- (void) - testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - // Find touch inteceptor view - UIView* touchInteceptorView = gMockPlatformView; - while (touchInteceptorView != nil && - ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { - touchInteceptorView = touchInteceptorView.superview; - } - XCTAssertNotNil(touchInteceptorView); - - // Find ForwardGestureRecognizer - UIGestureRecognizer* forwardGectureRecognizer = nil; - for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { - forwardGectureRecognizer = gestureRecognizer; - break; - } - } - id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); - - flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); - - // The touches in this sequence requires 1 touch object, we always create the NSSet with one item. - NSSet* touches1 = [NSSet setWithObject:@1]; - id event1 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; - OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); - - UIViewController* mockFlutterViewContoller2 = OCMClassMock([UIViewController class]); - flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller2); - - // Touch events should still send to the old FlutterViewController if FlutterViewController - // is updated in between. - NSSet* touches2 = [NSSet setWithObject:@1]; - id event2 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2]; - OCMVerify([mockFlutterViewContoller touchesBegan:touches2 withEvent:event2]); - OCMReject([mockFlutterViewContoller2 touchesBegan:touches2 withEvent:event2]); - - NSSet* touches3 = [NSSet setWithObject:@1]; - id event3 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesMoved:touches3 withEvent:event3]; - OCMVerify([mockFlutterViewContoller touchesMoved:touches3 withEvent:event3]); - OCMReject([mockFlutterViewContoller2 touchesMoved:touches3 withEvent:event3]); - - NSSet* touches4 = [NSSet setWithObject:@1]; - id event4 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesEnded:touches4 withEvent:event4]; - OCMVerify([mockFlutterViewContoller touchesEnded:touches4 withEvent:event4]); - OCMReject([mockFlutterViewContoller2 touchesEnded:touches4 withEvent:event4]); - - NSSet* touches5 = [NSSet setWithObject:@1]; - id event5 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; - OCMVerify([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); - OCMReject([mockFlutterViewContoller2 touchesEnded:touches5 withEvent:event5]); - - // Now the 2nd touch sequence should go to the new FlutterViewController - - NSSet* touches6 = [NSSet setWithObject:@1]; - id event6 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesBegan:touches6 withEvent:event6]; - OCMVerify([mockFlutterViewContoller2 touchesBegan:touches6 withEvent:event6]); - OCMReject([mockFlutterViewContoller touchesBegan:touches6 withEvent:event6]); - - // Allow the touch events to finish - NSSet* touches7 = [NSSet setWithObject:@1]; - id event7 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesMoved:touches7 withEvent:event7]; - OCMVerify([mockFlutterViewContoller2 touchesMoved:touches7 withEvent:event7]); - OCMReject([mockFlutterViewContoller touchesMoved:touches7 withEvent:event7]); - - NSSet* touches8 = [NSSet setWithObject:@1]; - id event8 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesEnded:touches8 withEvent:event8]; - OCMVerify([mockFlutterViewContoller2 touchesEnded:touches8 withEvent:event8]); - OCMReject([mockFlutterViewContoller touchesEnded:touches8 withEvent:event8]); - - flutterPlatformViewsController->Reset(); -} - -- (void)testFlutterPlatformViewTouchesCancelledEventAreForcedToBeCancelled { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - // Find touch inteceptor view - UIView* touchInteceptorView = gMockPlatformView; - while (touchInteceptorView != nil && - ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { - touchInteceptorView = touchInteceptorView.superview; - } - XCTAssertNotNil(touchInteceptorView); - - // Find ForwardGestureRecognizer - UIGestureRecognizer* forwardGectureRecognizer = nil; - for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { - forwardGectureRecognizer = gestureRecognizer; - break; - } - } - id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); - - flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); - - NSSet* touches1 = [NSSet setWithObject:@1]; - id event1 = OCMClassMock([UIEvent class]); - [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; - - [forwardGectureRecognizer touchesCancelled:touches1 withEvent:event1]; - OCMVerify([mockFlutterViewContoller forceTouchesCancelled:touches1]); - - flutterPlatformViewsController->Reset(); -} - -- (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashing { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - - // Create embedded view params - flutter::MutatorsStack stack; - SkMatrix finalMatrix; - - auto embeddedViewParams_1 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_1)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - flutter::SurfaceFrame::FramebufferInfo framebuffer_info; - auto mock_surface = std::make_unique( - nullptr, framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return false; }, - /*frame_size=*/SkISize::Make(800, 600)); - XCTAssertFalse( - flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - - auto embeddedViewParams_2 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_2)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - auto mock_surface_submit_true = std::make_unique( - nullptr, framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, - /*frame_size=*/SkISize::Make(800, 600)); - XCTAssertTrue(flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, - std::move(mock_surface_submit_true))); -} - -- (void) - testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - // autorelease pool to trigger an autorelease for all the root_views_ and touch_interceptors_. - @autoreleasepool { - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - flutter::MutatorsStack stack; - SkMatrix finalMatrix; - auto embeddedViewParams = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - // Not calling |flutterPlatformViewsController::SubmitFrame| so that the platform views are not - // added to flutter_view_. - - XCTAssertNotNil(gMockPlatformView); - flutterPlatformViewsController->Reset(); - } - XCTAssertNil(gMockPlatformView); -} - -- (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], - result); - - // First frame, |EmbeddedViewCount| is not empty after composite. - flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); - flutter::MutatorsStack stack; - SkMatrix finalMatrix; - auto embeddedViewParams1 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); - flutterPlatformViewsController->CompositeEmbeddedView(0); - XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); - - // Second frame, |EmbeddedViewCount| should be empty at the start - flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); - XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 0UL); - - auto embeddedViewParams2 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams2)); - flutterPlatformViewsController->CompositeEmbeddedView(0); - XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); -} - -- (void) - testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], - result); - UIView* view1 = gMockPlatformView; - - // This overwrites `gMockPlatformView` to another view. - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], - result); - UIView* view2 = gMockPlatformView; - - flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); - flutter::MutatorsStack stack; - SkMatrix finalMatrix; - auto embeddedViewParams1 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); - flutterPlatformViewsController->CompositeEmbeddedView(0); - auto embeddedViewParams2 = - std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); - flutterPlatformViewsController->CompositeEmbeddedView(1); - - // SKSurface is required if the root FlutterView is present. - const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); - sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); - flutter::SurfaceFrame::FramebufferInfo framebuffer_info; - auto mock_surface = std::make_unique( - std::move(mock_sk_surface), framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, - /*frame_size=*/SkISize::Make(800, 600)); - - XCTAssertTrue( - flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - // platform view is wrapped by touch interceptor, which itself is wrapped by clipping view. - UIView* clippingView1 = view1.superview.superview; - UIView* clippingView2 = view2.superview.superview; - UIView* flutterView = clippingView1.superview; - XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < - [flutterView.subviews indexOfObject:clippingView2], - @"The first clipping view should be added before the second clipping view."); - - // Need to recreate these params since they are `std::move`ed. - flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); - // Process the second frame in the opposite order. - embeddedViewParams2 = - std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); - flutterPlatformViewsController->CompositeEmbeddedView(1); - embeddedViewParams1 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); - flutterPlatformViewsController->CompositeEmbeddedView(0); - - mock_sk_surface = SkSurface::MakeRaster(image_info); - mock_surface = std::make_unique( - std::move(mock_sk_surface), framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, - /*frame_size=*/SkISize::Make(800, 600)); - XCTAssertTrue( - flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] > - [flutterView.subviews indexOfObject:clippingView2], - @"The first clipping view should be added after the second clipping view."); -} - -- (void) - testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], - result); - UIView* view1 = gMockPlatformView; - - // This overwrites `gMockPlatformView` to another view. - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], - result); - UIView* view2 = gMockPlatformView; - - flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); - flutter::MutatorsStack stack; - SkMatrix finalMatrix; - auto embeddedViewParams1 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); - flutterPlatformViewsController->CompositeEmbeddedView(0); - auto embeddedViewParams2 = - std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); - flutterPlatformViewsController->CompositeEmbeddedView(1); - - // SKSurface is required if the root FlutterView is present. - const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); - sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); - flutter::SurfaceFrame::FramebufferInfo framebuffer_info; - auto mock_surface = std::make_unique( - std::move(mock_sk_surface), framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, - /*frame_size=*/SkISize::Make(800, 600)); - - XCTAssertTrue( - flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - // platform view is wrapped by touch interceptor, which itself is wrapped by clipping view. - UIView* clippingView1 = view1.superview.superview; - UIView* clippingView2 = view2.superview.superview; - UIView* flutterView = clippingView1.superview; - XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < - [flutterView.subviews indexOfObject:clippingView2], - @"The first clipping view should be added before the second clipping view."); - - // Need to recreate these params since they are `std::move`ed. - flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); - // Process the second frame in the same order. - embeddedViewParams1 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); - flutterPlatformViewsController->CompositeEmbeddedView(0); - embeddedViewParams2 = - std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); - flutterPlatformViewsController->CompositeEmbeddedView(1); - - mock_sk_surface = SkSurface::MakeRaster(image_info); - mock_surface = std::make_unique( - std::move(mock_sk_surface), framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, - /*frame_size=*/SkISize::Make(800, 600)); - XCTAssertTrue( - flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < - [flutterView.subviews indexOfObject:clippingView2], - @"The first clipping view should be added before the second clipping view."); -} - -- (void)testThreadMergeAtEndFrame { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner_platform = CreateNewThread("FlutterPlatformViewsTest1"); - auto thread_task_runner_other = CreateNewThread("FlutterPlatformViewsTest2"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner_platform, - /*raster=*/thread_task_runner_other, - /*ui=*/thread_task_runner_other, - /*io=*/thread_task_runner_other); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - XCTestExpectation* waitForPlatformView = - [self expectationWithDescription:@"wait for platform view to be created"]; - FlutterResult result = ^(id result) { - [waitForPlatformView fulfill]; - }; - - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - [self waitForExpectations:@[ waitForPlatformView ] timeout:30]; - XCTAssertNotNil(gMockPlatformView); - - flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); - SkMatrix finalMatrix; - flutter::MutatorsStack stack; - auto embeddedViewParams = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - - fml::RefPtr raster_thread_merger = - fml::MakeRefCounted(thread_task_runner_platform->GetTaskQueueId(), - thread_task_runner_other->GetTaskQueueId()); - XCTAssertEqual(flutterPlatformViewsController->PostPrerollAction(raster_thread_merger), - flutter::PostPrerollResult::kSkipAndRetryFrame); - XCTAssertFalse(raster_thread_merger->IsMerged()); - - flutterPlatformViewsController->EndFrame(true, raster_thread_merger); - XCTAssertTrue(raster_thread_merger->IsMerged()); - - // Unmerge threads before the end of the test - // TaskRunners are required to be unmerged before destruction. - while (raster_thread_merger->DecrementLease() != fml::RasterThreadStatus::kUnmergedNow) - ; -} - -- (int)alphaOfPoint:(CGPoint)point onView:(UIView*)view { - unsigned char pixel[4] = {0}; - - CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - - // Draw the pixel on `point` in the context. - CGContextRef context = CGBitmapContextCreate( - pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast); - CGContextTranslateCTM(context, -point.x, -point.y); - [view.layer renderInContext:context]; - - CGContextRelease(context); - CGColorSpaceRelease(colorSpace); - // Get the alpha from the pixel that we just rendered. - return pixel[3]; -} - -- (void)testHasFirstResponderInViewHierarchySubtree_viewItselfBecomesFirstResponder { - // For view to become the first responder, it must be a descendant of a UIWindow - UIWindow* window = [[UIWindow alloc] init]; - UITextField* textField = [[UITextField alloc] init]; - [window addSubview:textField]; - - [textField becomeFirstResponder]; - XCTAssertTrue(textField.isFirstResponder); - XCTAssertTrue(textField.flt_hasFirstResponderInViewHierarchySubtree); - [textField resignFirstResponder]; - XCTAssertFalse(textField.isFirstResponder); - XCTAssertFalse(textField.flt_hasFirstResponderInViewHierarchySubtree); -} - -- (void)testHasFirstResponderInViewHierarchySubtree_descendantViewBecomesFirstResponder { - // For view to become the first responder, it must be a descendant of a UIWindow - UIWindow* window = [[UIWindow alloc] init]; - UIView* view = [[UIView alloc] init]; - UIView* childView = [[UIView alloc] init]; - UITextField* textField = [[UITextField alloc] init]; - [window addSubview:view]; - [view addSubview:childView]; - [childView addSubview:textField]; - - [textField becomeFirstResponder]; - XCTAssertTrue(textField.isFirstResponder); - XCTAssertTrue(view.flt_hasFirstResponderInViewHierarchySubtree); - [textField resignFirstResponder]; - XCTAssertFalse(textField.isFirstResponder); - XCTAssertFalse(view.flt_hasFirstResponderInViewHierarchySubtree); -} - -- (void)testFlutterClippingMaskViewPoolReuseViewsAfterRecycle { - FlutterClippingMaskViewPool* pool = - [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; - FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero]; - FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero]; - [pool recycleMaskViews]; - CGRect newRect = CGRectMake(0, 0, 10, 10); - FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:newRect]; - FlutterClippingMaskView* view4 = [pool getMaskViewWithFrame:newRect]; - XCTAssertEqual(view1, view3); - XCTAssertEqual(view2, view4); - XCTAssertTrue(CGRectEqualToRect(view3.frame, newRect)); - XCTAssertTrue(CGRectEqualToRect(view4.frame, newRect)); -} - -- (void)testFlutterClippingMaskViewPoolAllocsNewMaskViewsAfterReachingCapacity { - FlutterClippingMaskViewPool* pool = - [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; - FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero]; - FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero]; - FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:CGRectZero]; - XCTAssertNotEqual(view1, view3); - XCTAssertNotEqual(view2, view3); -} - -- (void)testMaskViewsReleasedWhenPoolIsReleased { - UIView* retainedView; - @autoreleasepool { - FlutterClippingMaskViewPool* pool = - [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; - FlutterClippingMaskView* view = [pool getMaskViewWithFrame:CGRectZero]; - retainedView = [view retain]; - XCTAssertGreaterThan(retainedView.retainCount, 1u); - } - // The only retain left is our manual retain called inside the autorelease pool, meaning the - // maskViews are dealloc'd. - XCTAssertEqual(retainedView.retainCount, 1u); -} - -- (void)testClipMaskViewIsReused { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], - result); - - XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - // Create embedded view params - flutter::MutatorsStack stack1; - // Layer tree always pushes a screen scale factor to the stack - SkMatrix screenScaleMatrix = - SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); - stack1.PushTransform(screenScaleMatrix); - // Push a clip rect - SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3); - stack1.PushClipRect(rect); - - auto embeddedViewParams1 = std::make_unique( - screenScaleMatrix, SkSize::Make(10, 10), stack1); - - flutter::MutatorsStack stack2; - auto embeddedViewParams2 = std::make_unique( - screenScaleMatrix, SkSize::Make(10, 10), stack2); - - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); - flutterPlatformViewsController->CompositeEmbeddedView(1); - UIView* childClippingView1 = gMockPlatformView.superview.superview; - UIView* maskView1 = childClippingView1.maskView; - XCTAssertNotNil(maskView1); - - // Composite a new frame. - auto embeddedViewParams3 = std::make_unique( - screenScaleMatrix, SkSize::Make(10, 10), stack2); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams3)); - flutterPlatformViewsController->CompositeEmbeddedView(1); - childClippingView1 = gMockPlatformView.superview.superview; - - // This overrides gMockPlatformView to point to the newly created platform view. - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); - - auto embeddedViewParams4 = std::make_unique( - screenScaleMatrix, SkSize::Make(10, 10), stack1); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams4)); - flutterPlatformViewsController->CompositeEmbeddedView(2); - UIView* childClippingView2 = gMockPlatformView.superview.superview; - - UIView* maskView2 = childClippingView2.maskView; - XCTAssertEqual(maskView1, maskView2); - XCTAssertNotNil(childClippingView2.maskView); - XCTAssertNil(childClippingView1.maskView); -} - -// Return true if a correct visual effect view is found. It also implies all the validation in this -// method passes. -// -// There are two fail states for this method. 1. One of the XCTAssert method failed; or 2. No -// correct visual effect view found. -- (BOOL)validateOneVisualEffectView:(UIView*)visualEffectView - expectedFrame:(CGRect)frame - inputRadius:(CGFloat)inputRadius { - XCTAssertTrue(CGRectEqualToRect(visualEffectView.frame, frame)); - for (UIView* view in visualEffectView.subviews) { - if (![view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { - continue; - } - XCTAssertEqual(view.layer.filters.count, 1u); - NSObject* filter = view.layer.filters.firstObject; - - XCTAssertEqualObjects([filter valueForKey:@"name"], @"gaussianBlur"); - - NSObject* inputRadiusInFilter = [filter valueForKey:@"inputRadius"]; - XCTAssertTrue([inputRadiusInFilter isKindOfClass:[NSNumber class]] && - flutter::BlurRadiusEqualToBlurRadius(((NSNumber*)inputRadiusInFilter).floatValue, - inputRadius)); - return YES; - } - return NO; -} - -- (void)testDisposingViewInCompositionOrderDoNotCrash { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); - - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; - flutterPlatformViewsController->SetFlutterView(mockFlutterView); - - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], - result); - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], - result); - - { - // **** First frame, view id 0, 1 in the composition_order_, disposing view 0 is called. **** // - // No view should be disposed, or removed from the composition order. - flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); - flutter::MutatorsStack stack; - SkMatrix finalMatrix; - auto embeddedViewParams0 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams0)); - flutterPlatformViewsController->CompositeEmbeddedView(0); - - auto embeddedViewParams1 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); - flutterPlatformViewsController->CompositeEmbeddedView(1); - XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); - - XCTestExpectation* expectation = [self expectationWithDescription:@"dispose call ended."]; - FlutterResult disposeResult = ^(id result) { - [expectation fulfill]; - }; - - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall methodCallWithMethodName:@"dispose" arguments:@0], disposeResult); - [self waitForExpectationsWithTimeout:30 handler:nil]; - - const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); - sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); - flutter::SurfaceFrame::FramebufferInfo framebuffer_info; - auto mock_surface = std::make_unique( - std::move(mock_sk_surface), framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, - /*frame_size=*/SkISize::Make(800, 600)); - XCTAssertTrue( - flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - - // Disposing won't remove embedded views until the view is removed from the composition_order_ - XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); - XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(0)); - XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); - } - - { - // **** Second frame, view id 1 in the composition_order_, no disposing view is called, **** // - // View 0 is removed from the composition order in this frame, hence also disposed. - flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); - flutter::MutatorsStack stack; - SkMatrix finalMatrix; - auto embeddedViewParams1 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); - flutterPlatformViewsController->CompositeEmbeddedView(1); - - const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); - sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); - flutter::SurfaceFrame::FramebufferInfo framebuffer_info; - auto mock_surface = std::make_unique( - std::move(mock_sk_surface), framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, - /*frame_size=*/SkISize::Make(800, 600)); - XCTAssertTrue( - flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - - // Disposing won't remove embedded views until the view is removed from the composition_order_ - XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); - XCTAssertNil(flutterPlatformViewsController->GetPlatformViewByID(0)); - XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); - } -} - -@end +// - (void)testChildClippingViewHitTests { +// ChildClippingView* childClippingView = +// [[[ChildClippingView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; +// UIView* childView = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] autorelease]; +// [childClippingView addSubview:childView]; + +// XCTAssertFalse([childClippingView pointInside:CGPointMake(50, 50) withEvent:nil]); +// XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 100) withEvent:nil]); +// XCTAssertFalse([childClippingView pointInside:CGPointMake(100, 99) withEvent:nil]); +// XCTAssertFalse([childClippingView pointInside:CGPointMake(201, 200) withEvent:nil]); +// XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 201) withEvent:nil]); +// XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 200) withEvent:nil]); +// XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 299) withEvent:nil]); + +// XCTAssertTrue([childClippingView pointInside:CGPointMake(150, 150) withEvent:nil]); +// XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 100) withEvent:nil]); +// XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 100) withEvent:nil]); +// XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 199) withEvent:nil]); +// XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 199) withEvent:nil]); +// } + +// - (void)testApplyBackdropFilter { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// CGFloat screenScale = [UIScreen mainScreen].scale; +// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); +// stack.PushTransform(screenScaleMatrix); +// // Push a backdrop filter +// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); +// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// // childClippingView has visual effect view with the correct configurations. +// NSUInteger numberOfExpectedVisualEffectView = 0; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:5]) { +// numberOfExpectedVisualEffectView++; +// } +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); +// } + +// - (void)testApplyBackdropFilterWithCorrectFrame { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// CGFloat screenScale = [UIScreen mainScreen].scale; +// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); +// stack.PushTransform(screenScaleMatrix); +// // Push a backdrop filter +// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); +// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 8, screenScale * 8)); + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(5, 10), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// // childClippingView has visual effect view with the correct configurations. +// NSUInteger numberOfExpectedVisualEffectView = 0; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 5, 8) +// inputRadius:5]) { +// numberOfExpectedVisualEffectView++; +// } +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); +// } + +// - (void)testApplyMultipleBackdropFilters { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// CGFloat screenScale = [UIScreen mainScreen].scale; +// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); +// stack.PushTransform(screenScaleMatrix); +// // Push backdrop filters +// for (int i = 0; i < 50; i++) { +// auto filter = std::make_shared(i, 2, flutter::DlTileMode::kClamp); +// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(20, 20), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// NSUInteger numberOfExpectedVisualEffectView = 0; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(numberOfExpectedVisualEffectView, 50u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)numberOfExpectedVisualEffectView]) { +// numberOfExpectedVisualEffectView++; +// } +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, (NSUInteger)numberOfExpectedVisualEffectView); +// } + +// - (void)testAddBackdropFilters { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// CGFloat screenScale = [UIScreen mainScreen].scale; +// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); +// stack.PushTransform(screenScaleMatrix); +// // Push a backdrop filter +// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); +// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(originalVisualEffectViews.count, 1u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)5]) { +// [originalVisualEffectViews addObject:subview]; +// } +// } +// XCTAssertEqual(originalVisualEffectViews.count, 1u); + +// // +// // Simulate adding 1 backdrop filter (create a new mutators stack) +// // Create embedded view params +// flutter::MutatorsStack stack2; +// // Layer tree always pushes a screen scale factor to the stack +// stack2.PushTransform(screenScaleMatrix); +// // Push backdrop filters +// for (int i = 0; i < 2; i++) { +// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(newVisualEffectViews.count, 2u); + +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)5]) { +// [newVisualEffectViews addObject:subview]; +// } +// } +// XCTAssertEqual(newVisualEffectViews.count, 2u); +// for (NSUInteger i = 0; i < originalVisualEffectViews.count; i++) { +// UIView* originalView = originalVisualEffectViews[i]; +// UIView* newView = newVisualEffectViews[i]; +// // Compare reference. +// XCTAssertEqual(originalView, newView); +// id mockOrignalView = OCMPartialMock(originalView); +// OCMReject([mockOrignalView removeFromSuperview]); +// } +// } + +// - (void)testRemoveBackdropFilters { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// CGFloat screenScale = [UIScreen mainScreen].scale; +// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); +// stack.PushTransform(screenScaleMatrix); +// // Push backdrop filters +// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); +// for (int i = 0; i < 5; i++) { +// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(originalVisualEffectViews.count, 5u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)5]) { +// [originalVisualEffectViews addObject:subview]; +// } +// } + +// // Simulate removing 1 backdrop filter (create a new mutators stack) +// // Create embedded view params +// flutter::MutatorsStack stack2; +// // Layer tree always pushes a screen scale factor to the stack +// stack2.PushTransform(screenScaleMatrix); +// // Push backdrop filters +// for (int i = 0; i < 4; i++) { +// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(newVisualEffectViews.count, 4u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)5]) { +// [newVisualEffectViews addObject:subview]; +// } +// } +// XCTAssertEqual(newVisualEffectViews.count, 4u); + +// for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { +// UIView* newView = newVisualEffectViews[i]; +// id mockNewView = OCMPartialMock(newView); +// UIView* originalView = originalVisualEffectViews[i]; +// // Compare reference. +// XCTAssertEqual(originalView, newView); +// OCMReject([mockNewView removeFromSuperview]); +// [mockNewView stopMocking]; +// } + +// // Simulate removing all backdrop filters (replace the mutators stack) +// // Update embedded view params, delete except screenScaleMatrix +// for (int i = 0; i < 5; i++) { +// stack2.Pop(); +// } +// // No backdrop filters in the stack, so no nothing to push + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// NSUInteger numberOfExpectedVisualEffectView = 0u; +// for (UIView* subview in childClippingView.subviews) { +// if ([subview isKindOfClass:[UIVisualEffectView class]]) { +// numberOfExpectedVisualEffectView++; +// } +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); +// } + +// - (void)testEditBackdropFilters { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// CGFloat screenScale = [UIScreen mainScreen].scale; +// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); +// stack.PushTransform(screenScaleMatrix); +// // Push backdrop filters +// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); +// for (int i = 0; i < 5; i++) { +// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(originalVisualEffectViews.count, 5u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)5]) { +// [originalVisualEffectViews addObject:subview]; +// } +// } + +// // Simulate editing 1 backdrop filter in the middle of the stack (create a new mutators stack) +// // Create embedded view params +// flutter::MutatorsStack stack2; +// // Layer tree always pushes a screen scale factor to the stack +// stack2.PushTransform(screenScaleMatrix); +// // Push backdrop filters +// for (int i = 0; i < 5; i++) { +// if (i == 3) { +// auto filter2 = +// std::make_shared(2, 5, flutter::DlTileMode::kClamp); + +// stack2.PushBackdropFilter(filter2, +// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// continue; +// } + +// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(newVisualEffectViews.count, 5u); +// CGFloat expectInputRadius = 5; +// if (newVisualEffectViews.count == 3) { +// expectInputRadius = 2; +// } +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)expectInputRadius]) { +// [newVisualEffectViews addObject:subview]; +// } +// } +// XCTAssertEqual(newVisualEffectViews.count, 5u); +// for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { +// UIView* newView = newVisualEffectViews[i]; +// id mockNewView = OCMPartialMock(newView); +// UIView* originalView = originalVisualEffectViews[i]; +// // Compare reference. +// XCTAssertEqual(originalView, newView); +// OCMReject([mockNewView removeFromSuperview]); +// [mockNewView stopMocking]; +// } +// [newVisualEffectViews removeAllObjects]; + +// // Simulate editing 1 backdrop filter in the beginning of the stack (replace the mutators stack) +// // Update embedded view params, delete except screenScaleMatrix +// for (int i = 0; i < 5; i++) { +// stack2.Pop(); +// } +// // Push backdrop filters +// for (int i = 0; i < 5; i++) { +// if (i == 0) { +// auto filter2 = +// std::make_shared(2, 5, flutter::DlTileMode::kClamp); +// stack2.PushBackdropFilter(filter2, +// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// continue; +// } + +// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(newVisualEffectViews.count, 5u); +// CGFloat expectInputRadius = 5; +// if (newVisualEffectViews.count == 0) { +// expectInputRadius = 2; +// } +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)expectInputRadius]) { +// [newVisualEffectViews addObject:subview]; +// } +// } +// for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { +// UIView* newView = newVisualEffectViews[i]; +// id mockNewView = OCMPartialMock(newView); +// UIView* originalView = originalVisualEffectViews[i]; +// // Compare reference. +// XCTAssertEqual(originalView, newView); +// OCMReject([mockNewView removeFromSuperview]); +// [mockNewView stopMocking]; +// } +// [newVisualEffectViews removeAllObjects]; + +// // Simulate editing 1 backdrop filter in the end of the stack (replace the mutators stack) +// // Update embedded view params, delete except screenScaleMatrix +// for (int i = 0; i < 5; i++) { +// stack2.Pop(); +// } +// // Push backdrop filters +// for (int i = 0; i < 5; i++) { +// if (i == 4) { +// auto filter2 = +// std::make_shared(2, 5, flutter::DlTileMode::kClamp); +// stack2.PushBackdropFilter(filter2, +// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// continue; +// } + +// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(newVisualEffectViews.count, 5u); +// CGFloat expectInputRadius = 5; +// if (newVisualEffectViews.count == 4) { +// expectInputRadius = 2; +// } +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)expectInputRadius]) { +// [newVisualEffectViews addObject:subview]; +// } +// } +// XCTAssertEqual(newVisualEffectViews.count, 5u); + +// for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { +// UIView* newView = newVisualEffectViews[i]; +// id mockNewView = OCMPartialMock(newView); +// UIView* originalView = originalVisualEffectViews[i]; +// // Compare reference. +// XCTAssertEqual(originalView, newView); +// OCMReject([mockNewView removeFromSuperview]); +// [mockNewView stopMocking]; +// } +// [newVisualEffectViews removeAllObjects]; + +// // Simulate editing all backdrop filters in the stack (replace the mutators stack) +// // Update embedded view params, delete except screenScaleMatrix +// for (int i = 0; i < 5; i++) { +// stack2.Pop(); +// } +// // Push backdrop filters +// for (int i = 0; i < 5; i++) { +// auto filter2 = std::make_shared(i, 2, flutter::DlTileMode::kClamp); + +// stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(newVisualEffectViews.count, 5u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)newVisualEffectViews.count]) { +// [newVisualEffectViews addObject:subview]; +// } +// } +// XCTAssertEqual(newVisualEffectViews.count, 5u); + +// for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { +// UIView* newView = newVisualEffectViews[i]; +// id mockNewView = OCMPartialMock(newView); +// UIView* originalView = originalVisualEffectViews[i]; +// // Compare reference. +// XCTAssertEqual(originalView, newView); +// OCMReject([mockNewView removeFromSuperview]); +// [mockNewView stopMocking]; +// } +// [newVisualEffectViews removeAllObjects]; +// } + +// - (void)testApplyBackdropFilterNotDlBlurImageFilter { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// CGFloat screenScale = [UIScreen mainScreen].scale; +// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); +// stack.PushTransform(screenScaleMatrix); +// // Push a dilate backdrop filter +// auto dilateFilter = std::make_shared(5, 2); +// stack.PushBackdropFilter(dilateFilter, SkRect::MakeEmpty()); + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// NSUInteger numberOfExpectedVisualEffectView = 0; +// for (UIView* subview in childClippingView.subviews) { +// if ([subview isKindOfClass:[UIVisualEffectView class]]) { +// numberOfExpectedVisualEffectView++; +// } +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); + +// // Simulate adding a non-DlBlurImageFilter in the middle of the stack (create a new mutators +// // stack) Create embedded view params +// flutter::MutatorsStack stack2; +// // Layer tree always pushes a screen scale factor to the stack +// stack2.PushTransform(screenScaleMatrix); +// // Push backdrop filters and dilate filter +// auto blurFilter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); + +// for (int i = 0; i < 5; i++) { +// if (i == 2) { +// stack2.PushBackdropFilter(dilateFilter, +// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// continue; +// } + +// stack2.PushBackdropFilter(blurFilter, +// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// numberOfExpectedVisualEffectView = 0; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)5]) { +// numberOfExpectedVisualEffectView++; +// } +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); + +// // Simulate adding a non-DlBlurImageFilter to the beginning of the stack (replace the mutators +// // stack) Update embedded view params, delete except screenScaleMatrix +// for (int i = 0; i < 5; i++) { +// stack2.Pop(); +// } +// // Push backdrop filters and dilate filter +// for (int i = 0; i < 5; i++) { +// if (i == 0) { +// stack2.PushBackdropFilter(dilateFilter, +// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// continue; +// } + +// stack2.PushBackdropFilter(blurFilter, +// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// numberOfExpectedVisualEffectView = 0; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)5]) { +// numberOfExpectedVisualEffectView++; +// } +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); + +// // Simulate adding a non-DlBlurImageFilter to the end of the stack (replace the mutators stack) +// // Update embedded view params, delete except screenScaleMatrix +// for (int i = 0; i < 5; i++) { +// stack2.Pop(); +// } +// // Push backdrop filters and dilate filter +// for (int i = 0; i < 5; i++) { +// if (i == 4) { +// stack2.PushBackdropFilter(dilateFilter, +// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// continue; +// } + +// stack2.PushBackdropFilter(blurFilter, +// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// numberOfExpectedVisualEffectView = 0; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:(CGFloat)5]) { +// numberOfExpectedVisualEffectView++; +// } +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); + +// // Simulate adding only non-DlBlurImageFilter to the stack (replace the mutators stack) +// // Update embedded view params, delete except screenScaleMatrix +// for (int i = 0; i < 5; i++) { +// stack2.Pop(); +// } +// // Push dilate filters +// for (int i = 0; i < 5; i++) { +// stack2.PushBackdropFilter(dilateFilter, +// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// } + +// embeddedViewParams = std::make_unique(screenScaleMatrix, +// SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// numberOfExpectedVisualEffectView = 0; +// for (UIView* subview in childClippingView.subviews) { +// if ([subview isKindOfClass:[UIVisualEffectView class]]) { +// numberOfExpectedVisualEffectView++; +// } +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); +// } + +// - (void)testApplyBackdropFilterCorrectAPI { +// [PlatformViewFilter resetPreparation]; +// // The gaussianBlur filter is extracted from UIVisualEffectView. +// // Each test requires a new PlatformViewFilter +// // Valid UIVisualEffectView API +// UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] +// initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; +// PlatformViewFilter* platformViewFilter = +// [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) +// blurRadius:5 +// visualEffectView:visualEffectView]; +// XCTAssertNotNil(platformViewFilter); +// } + +// - (void)testApplyBackdropFilterAPIChangedInvalidUIVisualEffectView { +// [PlatformViewFilter resetPreparation]; +// UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] init]; +// PlatformViewFilter* platformViewFilter = +// [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) +// blurRadius:5 +// visualEffectView:visualEffectView]; +// XCTAssertNil(platformViewFilter); +// } + +// - (void)testApplyBackdropFilterAPIChangedNoGaussianBlurFilter { +// [PlatformViewFilter resetPreparation]; +// UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc] +// initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; +// NSArray* subviews = editedUIVisualEffectView.subviews; +// for (UIView* view in subviews) { +// if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { +// for (CIFilter* filter in view.layer.filters) { +// if ([[filter valueForKey:@"name"] isEqual:@"gaussianBlur"]) { +// [filter setValue:@"notGaussianBlur" forKey:@"name"]; +// break; +// } +// } +// break; +// } +// } +// PlatformViewFilter* platformViewFilter = +// [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) +// blurRadius:5 +// visualEffectView:editedUIVisualEffectView]; +// XCTAssertNil(platformViewFilter); +// } + +// - (void)testApplyBackdropFilterAPIChangedInvalidInputRadius { +// [PlatformViewFilter resetPreparation]; +// UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc] +// initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; +// NSArray* subviews = editedUIVisualEffectView.subviews; +// for (UIView* view in subviews) { +// if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { +// for (CIFilter* filter in view.layer.filters) { +// if ([[filter valueForKey:@"name"] isEqual:@"gaussianBlur"]) { +// [filter setValue:@"invalidInputRadius" forKey:@"inputRadius"]; +// break; +// } +// } +// break; +// } +// } + +// PlatformViewFilter* platformViewFilter = +// [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) +// blurRadius:5 +// visualEffectView:editedUIVisualEffectView]; +// XCTAssertNil(platformViewFilter); +// } + +// - (void)testBackdropFilterVisualEffectSubviewBackgroundColor { +// UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] +// initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; +// PlatformViewFilter* platformViewFilter = +// [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) +// blurRadius:5 +// visualEffectView:visualEffectView]; +// CGColorRef visualEffectSubviewBackgroundColor; +// for (UIView* view in [platformViewFilter backdropFilterView].subviews) { +// if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectSubview")]) { +// visualEffectSubviewBackgroundColor = view.layer.backgroundColor; +// } +// } +// XCTAssertTrue( +// CGColorEqualToColor(visualEffectSubviewBackgroundColor, UIColor.clearColor.CGColor)); +// } + +// - (void)testCompositePlatformView { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// SkMatrix screenScaleMatrix = +// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); +// stack.PushTransform(screenScaleMatrix); +// // Push a translate matrix +// SkMatrix translateMatrix = SkMatrix::Translate(100, 100); +// stack.PushTransform(translateMatrix); +// SkMatrix finalMatrix; +// finalMatrix.setConcat(screenScaleMatrix, translateMatrix); + +// auto embeddedViewParams = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds +// toView:mockFlutterView]; +// XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, 300))); +// } + +// - (void)testBackdropFilterCorrectlyPushedAndReset { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// CGFloat screenScale = [UIScreen mainScreen].scale; +// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); +// stack.PushTransform(screenScaleMatrix); + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); + +// flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->PushVisitedPlatformView(2); +// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); +// flutterPlatformViewsController->PushFilterToVisitedPlatformViews( +// filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// // childClippingView has visual effect view with the correct configurations. +// NSUInteger numberOfExpectedVisualEffectView = 0; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); +// if ([self validateOneVisualEffectView:subview +// expectedFrame:CGRectMake(0, 0, 10, 10) +// inputRadius:5]) { +// numberOfExpectedVisualEffectView++; +// } +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); + +// // New frame, with no filter pushed. +// auto embeddedViewParams2 = +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// numberOfExpectedVisualEffectView = 0; +// for (UIView* subview in childClippingView.subviews) { +// if (![subview isKindOfClass:[UIVisualEffectView class]]) { +// continue; +// } +// numberOfExpectedVisualEffectView++; +// } +// XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); +// } + +// - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// SkMatrix screenScaleMatrix = +// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); +// stack.PushTransform(screenScaleMatrix); +// // Push a rotate matrix +// SkMatrix rotateMatrix; +// rotateMatrix.setRotate(10); +// stack.PushTransform(rotateMatrix); +// SkMatrix finalMatrix; +// finalMatrix.setConcat(screenScaleMatrix, rotateMatrix); + +// auto embeddedViewParams = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds +// toView:mockFlutterView]; +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// // The childclippingview's frame is set based on flow, but the platform view's frame is set based +// // on quartz. Although they should be the same, but we should tolerate small floating point +// // errors. +// XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - childClippingView.frame.origin.x), +// kFloatCompareEpsilon); +// XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - childClippingView.frame.origin.y), +// kFloatCompareEpsilon); +// XCTAssertLessThan( +// fabs(platformViewRectInFlutterView.size.width - childClippingView.frame.size.width), +// kFloatCompareEpsilon); +// XCTAssertLessThan( +// fabs(platformViewRectInFlutterView.size.height - childClippingView.frame.size.height), +// kFloatCompareEpsilon); +// } + +// - (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params. +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack. +// SkMatrix screenScaleMatrix = +// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); +// stack.PushTransform(screenScaleMatrix); +// SkMatrix translateMatrix = SkMatrix::Translate(5, 5); +// // The platform view's rect for this test will be (5, 5, 10, 10). +// stack.PushTransform(translateMatrix); +// // Push a clip rect, big enough to contain the entire platform view bound. +// SkRect rect = SkRect::MakeXYWH(0, 0, 25, 25); +// stack.PushClipRect(rect); +// // Push a clip rrect, big enough to contain the entire platform view bound without clipping it. +// // Make the origin (-1, -1) so that the top left rounded corner isn't clipping the PlatformView. +// SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25); +// SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); +// stack.PushClipRRect(rrect); + +// auto embeddedViewParams = std::make_unique( +// SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// gMockPlatformView.backgroundColor = UIColor.redColor; +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; +// XCTAssertNil(childClippingView.maskView); +// } + +// - (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack. +// SkMatrix screenScaleMatrix = +// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); +// stack.PushTransform(screenScaleMatrix); +// SkMatrix translateMatrix = SkMatrix::Translate(5, 5); +// // The platform view's rect for this test will be (5, 5, 10, 10). +// stack.PushTransform(translateMatrix); + +// // Push a clip rrect, the rect of the rrect is the same as the PlatformView of the corner should. +// // clip the PlatformView. +// SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10); +// SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); +// stack.PushClipRRect(rrect); + +// auto embeddedViewParams = std::make_unique( +// SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// gMockPlatformView.backgroundColor = UIColor.redColor; +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// XCTAssertNotNil(childClippingView.maskView); +// } + +// - (void)testClipRect { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// SkMatrix screenScaleMatrix = +// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); +// stack.PushTransform(screenScaleMatrix); +// // Push a clip rect +// SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3); +// stack.PushClipRect(rect); + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// gMockPlatformView.backgroundColor = UIColor.redColor; +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// for (int i = 0; i < 10; i++) { +// for (int j = 0; j < 10; j++) { +// CGPoint point = CGPointMake(i, j); +// int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; +// // Edges of the clipping might have a semi transparent pixel, we only check the pixels that +// // are fully inside the clipped area. +// CGRect insideClipping = CGRectMake(3, 3, 1, 1); +// if (CGRectContainsPoint(insideClipping, point)) { +// XCTAssertEqual(alpha, 255); +// } else { +// XCTAssertLessThan(alpha, 255); +// } +// } +// } +// } + +// - (void)testClipRRect { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// SkMatrix screenScaleMatrix = +// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); +// stack.PushTransform(screenScaleMatrix); +// // Push a clip rrect +// SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1); +// stack.PushClipRRect(rrect); + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// gMockPlatformView.backgroundColor = UIColor.redColor; +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// for (int i = 0; i < 10; i++) { +// for (int j = 0; j < 10; j++) { +// CGPoint point = CGPointMake(i, j); +// int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; +// // Edges of the clipping might have a semi transparent pixel, we only check the pixels that +// // are fully inside the clipped area. +// CGRect insideClipping = CGRectMake(3, 3, 4, 4); +// if (CGRectContainsPoint(insideClipping, point)) { +// XCTAssertEqual(alpha, 255); +// } else { +// XCTAssertLessThan(alpha, 255); +// } +// } +// } +// } + +// - (void)testClipPath { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack; +// // Layer tree always pushes a screen scale factor to the stack +// SkMatrix screenScaleMatrix = +// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); +// stack.PushTransform(screenScaleMatrix); +// // Push a clip path +// SkPath path; +// path.addRoundRect(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1); +// stack.PushClipPath(path); + +// auto embeddedViewParams = +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// gMockPlatformView.backgroundColor = UIColor.redColor; +// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); +// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// [mockFlutterView addSubview:childClippingView]; + +// [mockFlutterView setNeedsLayout]; +// [mockFlutterView layoutIfNeeded]; + +// for (int i = 0; i < 10; i++) { +// for (int j = 0; j < 10; j++) { +// CGPoint point = CGPointMake(i, j); +// int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; +// // Edges of the clipping might have a semi transparent pixel, we only check the pixels that +// // are fully inside the clipped area. +// CGRect insideClipping = CGRectMake(3, 3, 4, 4); +// if (CGRectContainsPoint(insideClipping, point)) { +// XCTAssertEqual(alpha, 255); +// } else { +// XCTAssertLessThan(alpha, 255); +// } +// } +// } +// } + +// - (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// // Find touch inteceptor view +// UIView* touchInteceptorView = gMockPlatformView; +// while (touchInteceptorView != nil && +// ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { +// touchInteceptorView = touchInteceptorView.superview; +// } +// XCTAssertNotNil(touchInteceptorView); + +// // Find ForwardGestureRecognizer +// UIGestureRecognizer* forwardGectureRecognizer = nil; +// for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { +// if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { +// forwardGectureRecognizer = gestureRecognizer; +// break; +// } +// } + +// // Before setting flutter view controller, events are not dispatched. +// NSSet* touches1 = [[[NSSet alloc] init] autorelease]; +// id event1 = OCMClassMock([UIEvent class]); +// id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); +// [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; +// OCMReject([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); + +// // Set flutter view controller allows events to be dispatched. +// NSSet* touches2 = [[[NSSet alloc] init] autorelease]; +// id event2 = OCMClassMock([UIEvent class]); +// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); +// [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2]; +// OCMVerify([mockFlutterViewContoller touchesBegan:touches2 withEvent:event2]); +// } + +// - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGesturesToBeHandled { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// // Find touch inteceptor view +// UIView* touchInteceptorView = gMockPlatformView; +// while (touchInteceptorView != nil && +// ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { +// touchInteceptorView = touchInteceptorView.superview; +// } +// XCTAssertNotNil(touchInteceptorView); + +// // Find ForwardGestureRecognizer +// UIGestureRecognizer* forwardGectureRecognizer = nil; +// for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { +// if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { +// forwardGectureRecognizer = gestureRecognizer; +// break; +// } +// } +// id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); +// { +// // ***** Sequence 1, finishing touch event with touchEnded ***** // +// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); + +// NSSet* touches1 = [[[NSSet alloc] init] autorelease]; +// id event1 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; +// OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); + +// flutterPlatformViewsController->SetFlutterViewController(nil); + +// // Allow the touch events to finish +// NSSet* touches2 = [[[NSSet alloc] init] autorelease]; +// id event2 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2]; +// OCMVerify([mockFlutterViewContoller touchesMoved:touches2 withEvent:event2]); + +// NSSet* touches3 = [[[NSSet alloc] init] autorelease]; +// id event3 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesEnded:touches3 withEvent:event3]; +// OCMVerify([mockFlutterViewContoller touchesEnded:touches3 withEvent:event3]); + +// // Now the 2nd touch sequence should not be allowed. +// NSSet* touches4 = [[[NSSet alloc] init] autorelease]; +// id event4 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4]; +// OCMReject([mockFlutterViewContoller touchesBegan:touches4 withEvent:event4]); + +// NSSet* touches5 = [[[NSSet alloc] init] autorelease]; +// id event5 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; +// OCMReject([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); +// } + +// { +// // ***** Sequence 2, finishing touch event with touchCancelled ***** // +// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); + +// NSSet* touches1 = [[[NSSet alloc] init] autorelease]; +// id event1 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; +// OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); + +// flutterPlatformViewsController->SetFlutterViewController(nil); + +// // Allow the touch events to finish +// NSSet* touches2 = [[[NSSet alloc] init] autorelease]; +// id event2 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2]; +// OCMVerify([mockFlutterViewContoller touchesMoved:touches2 withEvent:event2]); + +// NSSet* touches3 = [[[NSSet alloc] init] autorelease]; +// id event3 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesCancelled:touches3 withEvent:event3]; +// OCMVerify([mockFlutterViewContoller forceTouchesCancelled:touches3]); + +// // Now the 2nd touch sequence should not be allowed. +// NSSet* touches4 = [[[NSSet alloc] init] autorelease]; +// id event4 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4]; +// OCMReject([mockFlutterViewContoller touchesBegan:touches4 withEvent:event4]); + +// NSSet* touches5 = [[[NSSet alloc] init] autorelease]; +// id event5 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; +// OCMReject([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); +// } + +// flutterPlatformViewsController->Reset(); +// } + +// - (void) +// testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// // Find touch inteceptor view +// UIView* touchInteceptorView = gMockPlatformView; +// while (touchInteceptorView != nil && +// ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { +// touchInteceptorView = touchInteceptorView.superview; +// } +// XCTAssertNotNil(touchInteceptorView); + +// // Find ForwardGestureRecognizer +// UIGestureRecognizer* forwardGectureRecognizer = nil; +// for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { +// if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { +// forwardGectureRecognizer = gestureRecognizer; +// break; +// } +// } +// id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); + +// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); + +// // The touches in this sequence requires 1 touch object, we always create the NSSet with one item. +// NSSet* touches1 = [NSSet setWithObject:@1]; +// id event1 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; +// OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); + +// UIViewController* mockFlutterViewContoller2 = OCMClassMock([UIViewController class]); +// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller2); + +// // Touch events should still send to the old FlutterViewController if FlutterViewController +// // is updated in between. +// NSSet* touches2 = [NSSet setWithObject:@1]; +// id event2 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2]; +// OCMVerify([mockFlutterViewContoller touchesBegan:touches2 withEvent:event2]); +// OCMReject([mockFlutterViewContoller2 touchesBegan:touches2 withEvent:event2]); + +// NSSet* touches3 = [NSSet setWithObject:@1]; +// id event3 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesMoved:touches3 withEvent:event3]; +// OCMVerify([mockFlutterViewContoller touchesMoved:touches3 withEvent:event3]); +// OCMReject([mockFlutterViewContoller2 touchesMoved:touches3 withEvent:event3]); + +// NSSet* touches4 = [NSSet setWithObject:@1]; +// id event4 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesEnded:touches4 withEvent:event4]; +// OCMVerify([mockFlutterViewContoller touchesEnded:touches4 withEvent:event4]); +// OCMReject([mockFlutterViewContoller2 touchesEnded:touches4 withEvent:event4]); + +// NSSet* touches5 = [NSSet setWithObject:@1]; +// id event5 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; +// OCMVerify([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); +// OCMReject([mockFlutterViewContoller2 touchesEnded:touches5 withEvent:event5]); + +// // Now the 2nd touch sequence should go to the new FlutterViewController + +// NSSet* touches6 = [NSSet setWithObject:@1]; +// id event6 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesBegan:touches6 withEvent:event6]; +// OCMVerify([mockFlutterViewContoller2 touchesBegan:touches6 withEvent:event6]); +// OCMReject([mockFlutterViewContoller touchesBegan:touches6 withEvent:event6]); + +// // Allow the touch events to finish +// NSSet* touches7 = [NSSet setWithObject:@1]; +// id event7 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesMoved:touches7 withEvent:event7]; +// OCMVerify([mockFlutterViewContoller2 touchesMoved:touches7 withEvent:event7]); +// OCMReject([mockFlutterViewContoller touchesMoved:touches7 withEvent:event7]); + +// NSSet* touches8 = [NSSet setWithObject:@1]; +// id event8 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesEnded:touches8 withEvent:event8]; +// OCMVerify([mockFlutterViewContoller2 touchesEnded:touches8 withEvent:event8]); +// OCMReject([mockFlutterViewContoller touchesEnded:touches8 withEvent:event8]); + +// flutterPlatformViewsController->Reset(); +// } + +// - (void)testFlutterPlatformViewTouchesCancelledEventAreForcedToBeCancelled { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// // Find touch inteceptor view +// UIView* touchInteceptorView = gMockPlatformView; +// while (touchInteceptorView != nil && +// ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { +// touchInteceptorView = touchInteceptorView.superview; +// } +// XCTAssertNotNil(touchInteceptorView); + +// // Find ForwardGestureRecognizer +// UIGestureRecognizer* forwardGectureRecognizer = nil; +// for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { +// if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { +// forwardGectureRecognizer = gestureRecognizer; +// break; +// } +// } +// id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); + +// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); + +// NSSet* touches1 = [NSSet setWithObject:@1]; +// id event1 = OCMClassMock([UIEvent class]); +// [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; + +// [forwardGectureRecognizer touchesCancelled:touches1 withEvent:event1]; +// OCMVerify([mockFlutterViewContoller forceTouchesCancelled:touches1]); + +// flutterPlatformViewsController->Reset(); +// } + +// - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashing { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); + +// // Create embedded view params +// flutter::MutatorsStack stack; +// SkMatrix finalMatrix; + +// auto embeddedViewParams_1 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_1)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// flutter::SurfaceFrame::FramebufferInfo framebuffer_info; +// auto mock_surface = std::make_unique( +// nullptr, framebuffer_info, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return false; }, +// /*frame_size=*/SkISize::Make(800, 600)); +// XCTAssertFalse( +// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); + +// auto embeddedViewParams_2 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_2)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// auto mock_surface_submit_true = std::make_unique( +// nullptr, framebuffer_info, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, +// /*frame_size=*/SkISize::Make(800, 600)); +// XCTAssertTrue(flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, +// std::move(mock_surface_submit_true))); +// } + +// - (void) +// testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// // autorelease pool to trigger an autorelease for all the root_views_ and touch_interceptors_. +// @autoreleasepool { +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// flutter::MutatorsStack stack; +// SkMatrix finalMatrix; +// auto embeddedViewParams = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// // Not calling |flutterPlatformViewsController::SubmitFrame| so that the platform views are not +// // added to flutter_view_. + +// XCTAssertNotNil(gMockPlatformView); +// flutterPlatformViewsController->Reset(); +// } +// XCTAssertNil(gMockPlatformView); +// } + +// - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; + +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// // First frame, |EmbeddedViewCount| is not empty after composite. +// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); +// flutter::MutatorsStack stack; +// SkMatrix finalMatrix; +// auto embeddedViewParams1 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); +// flutterPlatformViewsController->CompositeEmbeddedView(0); +// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); + +// // Second frame, |EmbeddedViewCount| should be empty at the start +// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); +// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 0UL); + +// auto embeddedViewParams2 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams2)); +// flutterPlatformViewsController->CompositeEmbeddedView(0); +// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); +// } + +// - (void) +// testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], +// result); +// UIView* view1 = gMockPlatformView; + +// // This overwrites `gMockPlatformView` to another view. +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], +// result); +// UIView* view2 = gMockPlatformView; + +// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); +// flutter::MutatorsStack stack; +// SkMatrix finalMatrix; +// auto embeddedViewParams1 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); +// flutterPlatformViewsController->CompositeEmbeddedView(0); +// auto embeddedViewParams2 = +// std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); +// flutterPlatformViewsController->CompositeEmbeddedView(1); + +// // SKSurface is required if the root FlutterView is present. +// const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); +// sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); +// flutter::SurfaceFrame::FramebufferInfo framebuffer_info; +// auto mock_surface = std::make_unique( +// std::move(mock_sk_surface), framebuffer_info, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, +// /*frame_size=*/SkISize::Make(800, 600)); + +// XCTAssertTrue( +// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); +// // platform view is wrapped by touch interceptor, which itself is wrapped by clipping view. +// UIView* clippingView1 = view1.superview.superview; +// UIView* clippingView2 = view2.superview.superview; +// UIView* flutterView = clippingView1.superview; +// XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < +// [flutterView.subviews indexOfObject:clippingView2], +// @"The first clipping view should be added before the second clipping view."); + +// // Need to recreate these params since they are `std::move`ed. +// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); +// // Process the second frame in the opposite order. +// embeddedViewParams2 = +// std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); +// flutterPlatformViewsController->CompositeEmbeddedView(1); +// embeddedViewParams1 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); +// flutterPlatformViewsController->CompositeEmbeddedView(0); + +// mock_sk_surface = SkSurface::MakeRaster(image_info); +// mock_surface = std::make_unique( +// std::move(mock_sk_surface), framebuffer_info, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, +// /*frame_size=*/SkISize::Make(800, 600)); +// XCTAssertTrue( +// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); +// XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] > +// [flutterView.subviews indexOfObject:clippingView2], +// @"The first clipping view should be added after the second clipping view."); +// } + +// - (void) +// testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], +// result); +// UIView* view1 = gMockPlatformView; + +// // This overwrites `gMockPlatformView` to another view. +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], +// result); +// UIView* view2 = gMockPlatformView; + +// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); +// flutter::MutatorsStack stack; +// SkMatrix finalMatrix; +// auto embeddedViewParams1 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); +// flutterPlatformViewsController->CompositeEmbeddedView(0); +// auto embeddedViewParams2 = +// std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); +// flutterPlatformViewsController->CompositeEmbeddedView(1); + +// // SKSurface is required if the root FlutterView is present. +// const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); +// sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); +// flutter::SurfaceFrame::FramebufferInfo framebuffer_info; +// auto mock_surface = std::make_unique( +// std::move(mock_sk_surface), framebuffer_info, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, +// /*frame_size=*/SkISize::Make(800, 600)); + +// XCTAssertTrue( +// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); +// // platform view is wrapped by touch interceptor, which itself is wrapped by clipping view. +// UIView* clippingView1 = view1.superview.superview; +// UIView* clippingView2 = view2.superview.superview; +// UIView* flutterView = clippingView1.superview; +// XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < +// [flutterView.subviews indexOfObject:clippingView2], +// @"The first clipping view should be added before the second clipping view."); + +// // Need to recreate these params since they are `std::move`ed. +// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); +// // Process the second frame in the same order. +// embeddedViewParams1 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); +// flutterPlatformViewsController->CompositeEmbeddedView(0); +// embeddedViewParams2 = +// std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); +// flutterPlatformViewsController->CompositeEmbeddedView(1); + +// mock_sk_surface = SkSurface::MakeRaster(image_info); +// mock_surface = std::make_unique( +// std::move(mock_sk_surface), framebuffer_info, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, +// /*frame_size=*/SkISize::Make(800, 600)); +// XCTAssertTrue( +// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); +// XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < +// [flutterView.subviews indexOfObject:clippingView2], +// @"The first clipping view should be added before the second clipping view."); +// } + +// - (void)testThreadMergeAtEndFrame { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner_platform = CreateNewThread("FlutterPlatformViewsTest1"); +// auto thread_task_runner_other = CreateNewThread("FlutterPlatformViewsTest2"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner_platform, +// /*raster=*/thread_task_runner_other, +// /*ui=*/thread_task_runner_other, +// /*io=*/thread_task_runner_other); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// XCTestExpectation* waitForPlatformView = +// [self expectationWithDescription:@"wait for platform view to be created"]; +// FlutterResult result = ^(id result) { +// [waitForPlatformView fulfill]; +// }; + +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); +// [self waitForExpectations:@[ waitForPlatformView ] timeout:30]; +// XCTAssertNotNil(gMockPlatformView); + +// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); +// SkMatrix finalMatrix; +// flutter::MutatorsStack stack; +// auto embeddedViewParams = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + +// fml::RefPtr raster_thread_merger = +// fml::MakeRefCounted(thread_task_runner_platform->GetTaskQueueId(), +// thread_task_runner_other->GetTaskQueueId()); +// XCTAssertEqual(flutterPlatformViewsController->PostPrerollAction(raster_thread_merger), +// flutter::PostPrerollResult::kSkipAndRetryFrame); +// XCTAssertFalse(raster_thread_merger->IsMerged()); + +// flutterPlatformViewsController->EndFrame(true, raster_thread_merger); +// XCTAssertTrue(raster_thread_merger->IsMerged()); + +// // Unmerge threads before the end of the test +// // TaskRunners are required to be unmerged before destruction. +// while (raster_thread_merger->DecrementLease() != fml::RasterThreadStatus::kUnmergedNow) +// ; +// } + +// - (int)alphaOfPoint:(CGPoint)point onView:(UIView*)view { +// unsigned char pixel[4] = {0}; + +// CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + +// // Draw the pixel on `point` in the context. +// CGContextRef context = CGBitmapContextCreate( +// pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast); +// CGContextTranslateCTM(context, -point.x, -point.y); +// [view.layer renderInContext:context]; + +// CGContextRelease(context); +// CGColorSpaceRelease(colorSpace); +// // Get the alpha from the pixel that we just rendered. +// return pixel[3]; +// } + +// - (void)testHasFirstResponderInViewHierarchySubtree_viewItselfBecomesFirstResponder { +// // For view to become the first responder, it must be a descendant of a UIWindow +// UIWindow* window = [[UIWindow alloc] init]; +// UITextField* textField = [[UITextField alloc] init]; +// [window addSubview:textField]; + +// [textField becomeFirstResponder]; +// XCTAssertTrue(textField.isFirstResponder); +// XCTAssertTrue(textField.flt_hasFirstResponderInViewHierarchySubtree); +// [textField resignFirstResponder]; +// XCTAssertFalse(textField.isFirstResponder); +// XCTAssertFalse(textField.flt_hasFirstResponderInViewHierarchySubtree); +// } + +// - (void)testHasFirstResponderInViewHierarchySubtree_descendantViewBecomesFirstResponder { +// // For view to become the first responder, it must be a descendant of a UIWindow +// UIWindow* window = [[UIWindow alloc] init]; +// UIView* view = [[UIView alloc] init]; +// UIView* childView = [[UIView alloc] init]; +// UITextField* textField = [[UITextField alloc] init]; +// [window addSubview:view]; +// [view addSubview:childView]; +// [childView addSubview:textField]; + +// [textField becomeFirstResponder]; +// XCTAssertTrue(textField.isFirstResponder); +// XCTAssertTrue(view.flt_hasFirstResponderInViewHierarchySubtree); +// [textField resignFirstResponder]; +// XCTAssertFalse(textField.isFirstResponder); +// XCTAssertFalse(view.flt_hasFirstResponderInViewHierarchySubtree); +// } + +// - (void)testFlutterClippingMaskViewPoolReuseViewsAfterRecycle { +// FlutterClippingMaskViewPool* pool = +// [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; +// FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero]; +// FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero]; +// [pool recycleMaskViews]; +// CGRect newRect = CGRectMake(0, 0, 10, 10); +// FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:newRect]; +// FlutterClippingMaskView* view4 = [pool getMaskViewWithFrame:newRect]; +// XCTAssertEqual(view1, view3); +// XCTAssertEqual(view2, view4); +// XCTAssertTrue(CGRectEqualToRect(view3.frame, newRect)); +// XCTAssertTrue(CGRectEqualToRect(view4.frame, newRect)); +// } + +// - (void)testFlutterClippingMaskViewPoolAllocsNewMaskViewsAfterReachingCapacity { +// FlutterClippingMaskViewPool* pool = +// [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; +// FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero]; +// FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero]; +// FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:CGRectZero]; +// XCTAssertNotEqual(view1, view3); +// XCTAssertNotEqual(view2, view3); +// } + +// - (void)testMaskViewsReleasedWhenPoolIsReleased { +// UIView* retainedView; +// @autoreleasepool { +// FlutterClippingMaskViewPool* pool = +// [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; +// FlutterClippingMaskView* view = [pool getMaskViewWithFrame:CGRectZero]; +// retainedView = [view retain]; +// XCTAssertGreaterThan(retainedView.retainCount, 1u); +// } +// // The only retain left is our manual retain called inside the autorelease pool, meaning the +// // maskViews are dealloc'd. +// XCTAssertEqual(retainedView.retainCount, 1u); +// } + +// - (void)testClipMaskViewIsReused { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// XCTAssertNotNil(gMockPlatformView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// // Create embedded view params +// flutter::MutatorsStack stack1; +// // Layer tree always pushes a screen scale factor to the stack +// SkMatrix screenScaleMatrix = +// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); +// stack1.PushTransform(screenScaleMatrix); +// // Push a clip rect +// SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3); +// stack1.PushClipRect(rect); + +// auto embeddedViewParams1 = std::make_unique( +// screenScaleMatrix, SkSize::Make(10, 10), stack1); + +// flutter::MutatorsStack stack2; +// auto embeddedViewParams2 = std::make_unique( +// screenScaleMatrix, SkSize::Make(10, 10), stack2); + +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); +// flutterPlatformViewsController->CompositeEmbeddedView(1); +// UIView* childClippingView1 = gMockPlatformView.superview.superview; +// UIView* maskView1 = childClippingView1.maskView; +// XCTAssertNotNil(maskView1); + +// // Composite a new frame. +// auto embeddedViewParams3 = std::make_unique( +// screenScaleMatrix, SkSize::Make(10, 10), stack2); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams3)); +// flutterPlatformViewsController->CompositeEmbeddedView(1); +// childClippingView1 = gMockPlatformView.superview.superview; + +// // This overrides gMockPlatformView to point to the newly created platform view. +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// auto embeddedViewParams4 = std::make_unique( +// screenScaleMatrix, SkSize::Make(10, 10), stack1); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams4)); +// flutterPlatformViewsController->CompositeEmbeddedView(2); +// UIView* childClippingView2 = gMockPlatformView.superview.superview; + +// UIView* maskView2 = childClippingView2.maskView; +// XCTAssertEqual(maskView1, maskView2); +// XCTAssertNotNil(childClippingView2.maskView); +// XCTAssertNil(childClippingView1.maskView); +// } + +// // Return true if a correct visual effect view is found. It also implies all the validation in this +// // method passes. +// // +// // There are two fail states for this method. 1. One of the XCTAssert method failed; or 2. No +// // correct visual effect view found. +// - (BOOL)validateOneVisualEffectView:(UIView*)visualEffectView +// expectedFrame:(CGRect)frame +// inputRadius:(CGFloat)inputRadius { +// XCTAssertTrue(CGRectEqualToRect(visualEffectView.frame, frame)); +// for (UIView* view in visualEffectView.subviews) { +// if (![view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { +// continue; +// } +// XCTAssertEqual(view.layer.filters.count, 1u); +// NSObject* filter = view.layer.filters.firstObject; + +// XCTAssertEqualObjects([filter valueForKey:@"name"], @"gaussianBlur"); + +// NSObject* inputRadiusInFilter = [filter valueForKey:@"inputRadius"]; +// XCTAssertTrue([inputRadiusInFilter isKindOfClass:[NSNumber class]] && +// flutter::BlurRadiusEqualToBlurRadius(((NSNumber*)inputRadiusInFilter).floatValue, +// inputRadius)); +// return YES; +// } +// return NO; +// } + +// - (void)testDisposingViewInCompositionOrderDoNotCrash { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); + +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; +// flutterPlatformViewsController->SetFlutterView(mockFlutterView); + +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; + +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], +// result); +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], +// result); + +// { +// // **** First frame, view id 0, 1 in the composition_order_, disposing view 0 is called. **** // +// // No view should be disposed, or removed from the composition order. +// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); +// flutter::MutatorsStack stack; +// SkMatrix finalMatrix; +// auto embeddedViewParams0 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams0)); +// flutterPlatformViewsController->CompositeEmbeddedView(0); + +// auto embeddedViewParams1 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); +// flutterPlatformViewsController->CompositeEmbeddedView(1); +// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); + +// XCTestExpectation* expectation = [self expectationWithDescription:@"dispose call ended."]; +// FlutterResult disposeResult = ^(id result) { +// [expectation fulfill]; +// }; + +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall methodCallWithMethodName:@"dispose" arguments:@0], disposeResult); +// [self waitForExpectationsWithTimeout:30 handler:nil]; + +// const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); +// sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); +// flutter::SurfaceFrame::FramebufferInfo framebuffer_info; +// auto mock_surface = std::make_unique( +// std::move(mock_sk_surface), framebuffer_info, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, +// /*frame_size=*/SkISize::Make(800, 600)); +// XCTAssertTrue( +// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); + +// // Disposing won't remove embedded views until the view is removed from the composition_order_ +// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); +// XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(0)); +// XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); +// } + +// { +// // **** Second frame, view id 1 in the composition_order_, no disposing view is called, **** // +// // View 0 is removed from the composition order in this frame, hence also disposed. +// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); +// flutter::MutatorsStack stack; +// SkMatrix finalMatrix; +// auto embeddedViewParams1 = +// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); +// flutterPlatformViewsController->CompositeEmbeddedView(1); + +// const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); +// sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); +// flutter::SurfaceFrame::FramebufferInfo framebuffer_info; +// auto mock_surface = std::make_unique( +// std::move(mock_sk_surface), framebuffer_info, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, +// /*frame_size=*/SkISize::Make(800, 600)); +// XCTAssertTrue( +// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); + +// // Disposing won't remove embedded views until the view is removed from the composition_order_ +// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); +// XCTAssertNil(flutterPlatformViewsController->GetPlatformViewByID(0)); +// XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); +// } +// } + +// @end diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m index 47d49f3c7779c..481c249395b21 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m @@ -6,97 +6,97 @@ static const NSInteger kSecondsToWaitForPlatformView = 30; -@interface PlatformViewUITests : GoldenPlatformViewTests +// @interface PlatformViewUITests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewUITests +// @implementation PlatformViewUITests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface NonFullScreenFlutterViewPlatformViewUITests : GoldenPlatformViewTests +// @interface NonFullScreenFlutterViewPlatformViewUITests : GoldenPlatformViewTests -@end +// @end -@implementation NonFullScreenFlutterViewPlatformViewUITests +// @implementation NonFullScreenFlutterViewPlatformViewUITests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--non-full-screen-flutter-view-platform-view"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--non-full-screen-flutter-view-platform-view"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface MultiplePlatformViewsTest : GoldenPlatformViewTests +// @interface MultiplePlatformViewsTest : GoldenPlatformViewTests -@end +// @end -@implementation MultiplePlatformViewsTest +// @implementation MultiplePlatformViewsTest -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-multiple"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-multiple"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface MultiplePlatformViewsBackgroundForegroundTest : GoldenPlatformViewTests +// @interface MultiplePlatformViewsBackgroundForegroundTest : GoldenPlatformViewTests -@end +// @end -@implementation MultiplePlatformViewsBackgroundForegroundTest +// @implementation MultiplePlatformViewsBackgroundForegroundTest -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = [[GoldenTestManager alloc] - initWithLaunchArg:@"--platform-view-multiple-background-foreground"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = [[GoldenTestManager alloc] +// initWithLaunchArg:@"--platform-view-multiple-background-foreground"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonHome]; - [self.application activate]; - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonHome]; +// [self.application activate]; +// [self checkPlatformViewGolden]; +// } -@end +// @end -// Clip Rect Tests -@interface PlatformViewMutationClipRectTests : GoldenPlatformViewTests +// // Clip Rect Tests +// @interface PlatformViewMutationClipRectTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewMutationClipRectTests +// @implementation PlatformViewMutationClipRectTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprect"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprect"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end @interface PlatformViewMutationClipRectAfterMovedTests : GoldenPlatformViewTests @@ -128,289 +128,289 @@ - (void)testPlatformView { @end -@interface PlatformViewMutationClipRRectTests : GoldenPlatformViewTests +// @interface PlatformViewMutationClipRRectTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewMutationClipRRectTests +// @implementation PlatformViewMutationClipRRectTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprrect"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprrect"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface PlatformViewMutationLargeClipRRectTests : GoldenPlatformViewTests +// @interface PlatformViewMutationLargeClipRRectTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewMutationLargeClipRRectTests +// @implementation PlatformViewMutationLargeClipRRectTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-large-cliprrect"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-large-cliprrect"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface PlatformViewMutationClipPathTests : GoldenPlatformViewTests +// @interface PlatformViewMutationClipPathTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewMutationClipPathTests +// @implementation PlatformViewMutationClipPathTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-clippath"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-clippath"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface PlatformViewMutationClipRectWithTransformTests : GoldenPlatformViewTests +// @interface PlatformViewMutationClipRectWithTransformTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewMutationClipRectWithTransformTests +// @implementation PlatformViewMutationClipRectWithTransformTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprect-with-transform"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprect-with-transform"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface PlatformViewMutationClipRRectWithTransformTests : GoldenPlatformViewTests +// @interface PlatformViewMutationClipRRectWithTransformTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewMutationClipRRectWithTransformTests +// @implementation PlatformViewMutationClipRRectWithTransformTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprrect-with-transform"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprrect-with-transform"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface PlatformViewMutationLargeClipRRectWithTransformTests : GoldenPlatformViewTests +// @interface PlatformViewMutationLargeClipRRectWithTransformTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewMutationLargeClipRRectWithTransformTests +// @implementation PlatformViewMutationLargeClipRRectWithTransformTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = [[GoldenTestManager alloc] - initWithLaunchArg:@"--platform-view-large-cliprrect-with-transform"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = [[GoldenTestManager alloc] +// initWithLaunchArg:@"--platform-view-large-cliprrect-with-transform"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface PlatformViewMutationClipPathWithTransformTests : GoldenPlatformViewTests +// @interface PlatformViewMutationClipPathWithTransformTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewMutationClipPathWithTransformTests +// @implementation PlatformViewMutationClipPathWithTransformTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-clippath-with-transform"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-clippath-with-transform"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface PlatformViewMutationTransformTests : GoldenPlatformViewTests +// @interface PlatformViewMutationTransformTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewMutationTransformTests +// @implementation PlatformViewMutationTransformTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-transform"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-transform"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface PlatformViewMutationOpacityTests : GoldenPlatformViewTests +// @interface PlatformViewMutationOpacityTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewMutationOpacityTests +// @implementation PlatformViewMutationOpacityTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-opacity"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-opacity"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface PlatformViewWithOtherBackdropFilterTests : GoldenPlatformViewTests +// @interface PlatformViewWithOtherBackdropFilterTests : GoldenPlatformViewTests -@end +// @end -@implementation PlatformViewWithOtherBackdropFilterTests +// @implementation PlatformViewWithOtherBackdropFilterTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-with-other-backdrop-filter"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-with-other-backdrop-filter"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface TwoPlatformViewsWithOtherBackDropFilterTests : GoldenPlatformViewTests +// @interface TwoPlatformViewsWithOtherBackDropFilterTests : GoldenPlatformViewTests -@end +// @end -@implementation TwoPlatformViewsWithOtherBackDropFilterTests +// @implementation TwoPlatformViewsWithOtherBackDropFilterTests -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = [[GoldenTestManager alloc] - initWithLaunchArg:@"--two-platform-views-with-other-backdrop-filter"]; - return [super initWithManager:manager invocation:invocation]; -} +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = [[GoldenTestManager alloc] +// initWithLaunchArg:@"--two-platform-views-with-other-backdrop-filter"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - [self checkPlatformViewGolden]; -} +// - (void)testPlatformView { +// [self checkPlatformViewGolden]; +// } -@end +// @end -@interface PlatformViewRotation : GoldenPlatformViewTests -@end - -@implementation PlatformViewRotation -- (instancetype)initWithInvocation:(NSInvocation*)invocation { - GoldenTestManager* manager = - [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-rotate"]; - return [super initWithManager:manager invocation:invocation]; -} +// @interface PlatformViewRotation : GoldenPlatformViewTests +// @end -- (void)tearDown { - XCUIDevice.sharedDevice.orientation = UIDeviceOrientationPortrait; - [super tearDown]; -} +// @implementation PlatformViewRotation +// - (instancetype)initWithInvocation:(NSInvocation*)invocation { +// GoldenTestManager* manager = +// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-rotate"]; +// return [super initWithManager:manager invocation:invocation]; +// } -- (void)testPlatformView { - XCUIDevice.sharedDevice.orientation = UIDeviceOrientationLandscapeLeft; - [self checkPlatformViewGolden]; -} +// - (void)tearDown { +// XCUIDevice.sharedDevice.orientation = UIDeviceOrientationPortrait; +// [super tearDown]; +// } -@end +// - (void)testPlatformView { +// XCUIDevice.sharedDevice.orientation = UIDeviceOrientationLandscapeLeft; +// [self checkPlatformViewGolden]; +// } -@interface PlatformViewWithContinuousTexture : XCTestCase +// @end -@end +// @interface PlatformViewWithContinuousTexture : XCTestCase -@implementation PlatformViewWithContinuousTexture +// @end -- (void)setUp { - self.continueAfterFailure = NO; -} +// @implementation PlatformViewWithContinuousTexture -- (void)testPlatformViewWithContinuousTexture { - XCUIApplication* app = [[XCUIApplication alloc] init]; - app.launchArguments = - @[ @"--platform-view-with-continuous-texture", @"--with-continuous-texture" ]; - [app launch]; +// - (void)setUp { +// self.continueAfterFailure = NO; +// } - XCUIElement* platformView = app.textViews.firstMatch; - BOOL exists = [platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]; - if (!exists) { - XCTFail(@"It took longer than %@ second to find the platform view." - @"There might be issues with the platform view's construction," - @"or with how the scenario is built.", - @(kSecondsToWaitForPlatformView)); - } +// - (void)testPlatformViewWithContinuousTexture { +// XCUIApplication* app = [[XCUIApplication alloc] init]; +// app.launchArguments = +// @[ @"--platform-view-with-continuous-texture", @"--with-continuous-texture" ]; +// [app launch]; - XCTAssertNotNil(platformView); -} +// XCUIElement* platformView = app.textViews.firstMatch; +// BOOL exists = [platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]; +// if (!exists) { +// XCTFail(@"It took longer than %@ second to find the platform view." +// @"There might be issues with the platform view's construction," +// @"or with how the scenario is built.", +// @(kSecondsToWaitForPlatformView)); +// } -@end +// XCTAssertNotNil(platformView); +// } -@interface PlatformViewScrollingUnderWidget : XCTestCase +// @end -@end +// @interface PlatformViewScrollingUnderWidget : XCTestCase -@implementation PlatformViewScrollingUnderWidget +// @end -- (void)setUp { - [super setUp]; - self.continueAfterFailure = NO; -} +// @implementation PlatformViewScrollingUnderWidget -- (void)testPlatformViewScrollingUnderWidget { - XCUIApplication* app = [[XCUIApplication alloc] init]; - app.launchArguments = - @[ @"--platform-view-scrolling-under-widget", @"--with-continuous-texture" ]; - [app launch]; +// - (void)setUp { +// [super setUp]; +// self.continueAfterFailure = NO; +// } - XCUIElement* platformView = app.textViews.firstMatch; - BOOL exists = [platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]; - if (!exists) { - XCTFail(@"It took longer than %@ second to find the platform view." - @"There might be issues with the platform view's construction," - @"or with how the scenario is built.", - @(kSecondsToWaitForPlatformView)); - } +// - (void)testPlatformViewScrollingUnderWidget { +// XCUIApplication* app = [[XCUIApplication alloc] init]; +// app.launchArguments = +// @[ @"--platform-view-scrolling-under-widget", @"--with-continuous-texture" ]; +// [app launch]; - // Wait and let the scenario app scroll a bit. - XCTWaiterResult waitResult = [XCTWaiter - waitForExpectations:@[ [[XCTestExpectation alloc] initWithDescription:@"Wait for 5 seconds"] ] - timeout:5]; - // If the waiter is not interrupted, we know the app is in a valid state after timeout, thus the - // test passes. - XCTAssert(waitResult != XCTWaiterResultInterrupted); -} +// XCUIElement* platformView = app.textViews.firstMatch; +// BOOL exists = [platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]; +// if (!exists) { +// XCTFail(@"It took longer than %@ second to find the platform view." +// @"There might be issues with the platform view's construction," +// @"or with how the scenario is built.", +// @(kSecondsToWaitForPlatformView)); +// } -@end +// // Wait and let the scenario app scroll a bit. +// XCTWaiterResult waitResult = [XCTWaiter +// waitForExpectations:@[ [[XCTestExpectation alloc] initWithDescription:@"Wait for 5 seconds"] ] +// timeout:5]; +// // If the waiter is not interrupted, we know the app is in a valid state after timeout, thus the +// // test passes. +// XCTAssert(waitResult != XCTWaiterResultInterrupted); +// } + +// @end diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m index 57d627e2b2145..679c07e5b4f21 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m @@ -21,301 +21,301 @@ - (void)setUp { // | PV | +---+ // +--------+ | A | // +---+ -- (void)testNoOverlay { - XCUIApplication* app = [[XCUIApplication alloc] init]; - app.launchArguments = - @[ @"--platform-view-no-overlay-intersection", @"--enable-software-rendering" ]; - [app launch]; - - XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; - XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); - XCTAssertEqual(platform_view.frame.origin.x, 0); - XCTAssertEqual(platform_view.frame.origin.y, 0); - XCTAssertEqual(platform_view.frame.size.width, 250); - XCTAssertEqual(platform_view.frame.size.height, 250); - - XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; - XCTAssertFalse(overlay.exists); -} - -// A is the layer above the platform view. -// +-----------------+ -// | PV +---+ | -// | | A | | -// | +---+ | -// +-----------------+ -- (void)testOneOverlay { - XCUIApplication* app = [[XCUIApplication alloc] init]; - app.launchArguments = @[ @"--platform-view" ]; - [app launch]; - - XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; - XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); - XCTAssertEqual(platform_view.frame.origin.x, 0); - XCTAssertEqual(platform_view.frame.origin.y, 0); - XCTAssertEqual(platform_view.frame.size.width, 250); - XCTAssertEqual(platform_view.frame.size.height, 250); - - XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; - XCTAssertTrue(overlay.exists); - XCTAssertEqual(overlay.frame.origin.x, 150); - XCTAssertEqual(overlay.frame.origin.y, 150); - XCTAssertEqual(overlay.frame.size.width, 50); - XCTAssertEqual(overlay.frame.size.height, 50); - - XCUIElement* overlayView = app.otherElements[@"platform_view[0].overlay_view[0]"]; - XCTAssertTrue(overlayView.exists); - // Overlay should always be the same frame as the app. - XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView.frame.size.height, app.frame.size.height, - kCompareAccuracy); -} - -// A is the layer above the platform view. -// +-----------------+ -// | PV +---+ | -// +-----------| A |-+ -// +---+ -- (void)testOneOverlayPartialIntersection { - XCUIApplication* app = [[XCUIApplication alloc] init]; - app.launchArguments = @[ @"--platform-view-partial-intersection" ]; - [app launch]; - - XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; - XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); - XCTAssertEqual(platform_view.frame.origin.x, 0); - XCTAssertEqual(platform_view.frame.origin.y, 0); - XCTAssertEqual(platform_view.frame.size.width, 250); - XCTAssertEqual(platform_view.frame.size.height, 250); - - XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; - XCTAssertTrue(overlay.exists); - XCTAssertEqual(overlay.frame.origin.x, 200); - XCTAssertEqual(overlay.frame.origin.y, 245); - XCTAssertEqual(overlay.frame.size.width, 50); - // Half the height of the overlay. - XCTAssertEqual(overlay.frame.size.height, 5); - - XCUIElement* overlayView = app.otherElements[@"platform_view[0].overlay_view[0]"]; - XCTAssertTrue(overlayView.exists); - // Overlay should always be the same frame as the app. - XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView.frame.size.height, app.frame.size.height, - kCompareAccuracy); -} - -// A and B are the layers above the platform view. -// +--------------------+ -// | PV +------------+ | -// | | B +-----+ | | -// | +---| A |-+ | -// +----------| |---+ -// +-----+ -- (void)testTwoIntersectingOverlays { - XCUIApplication* app = [[XCUIApplication alloc] init]; - app.launchArguments = @[ @"--platform-view-two-intersecting-overlays" ]; - [app launch]; - - XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; - XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); - XCTAssertEqual(platform_view.frame.origin.x, 0); - XCTAssertEqual(platform_view.frame.origin.y, 0); - XCTAssertEqual(platform_view.frame.size.width, 250); - XCTAssertEqual(platform_view.frame.size.height, 250); - - XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; - XCTAssertTrue(overlay.exists); - XCTAssertEqual(overlay.frame.origin.x, 150); - XCTAssertEqual(overlay.frame.origin.y, 150); - XCTAssertEqual(overlay.frame.size.width, 75); - XCTAssertEqual(overlay.frame.size.height, 75); - - XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists); -} - -// A, B, and C are the layers above the platform view. -// +-------------------------+ -// | PV +-----------+ | -// | +---+ | B +-----+ | | -// | | C | +---| A |-+ | -// | +---+ +-----+ | -// +-------------------------+ -- (void)testOneOverlayAndTwoIntersectingOverlays { - XCUIApplication* app = [[XCUIApplication alloc] init]; - app.launchArguments = @[ @"--platform-view-one-overlay-two-intersecting-overlays" ]; - [app launch]; - - XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; - XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); - XCTAssertEqual(platform_view.frame.origin.x, 0); - XCTAssertEqual(platform_view.frame.origin.y, 0); - XCTAssertEqual(platform_view.frame.size.width, 250); - XCTAssertEqual(platform_view.frame.size.height, 250); - - XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"]; - XCTAssertTrue(overlay1.exists); - XCTAssertEqual(overlay1.frame.origin.x, 150); - XCTAssertEqual(overlay1.frame.origin.y, 150); - XCTAssertEqual(overlay1.frame.size.width, 75); - XCTAssertEqual(overlay1.frame.size.height, 75); - - XCUIElement* overlay2 = app.otherElements[@"platform_view[0].overlay[1]"]; - XCTAssertTrue(overlay2.exists); - XCTAssertEqual(overlay2.frame.origin.x, 75); - XCTAssertEqual(overlay2.frame.origin.y, 225); - XCTAssertEqual(overlay2.frame.size.width, 50); - XCTAssertEqual(overlay2.frame.size.height, 25); - - XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; - XCTAssertTrue(overlayView0.exists); - // Overlay should always be the same frame as the app. - XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, - kCompareAccuracy); - - XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; - XCTAssertTrue(overlayView1.exists); - // Overlay should always be the same frame as the app. - XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, app.frame.size.height, - kCompareAccuracy); -} - -// A is the layer, which z index is higher than the platform view. -// +--------+ -// | PV | +---+ -// +--------+ | A | -// +--------+ +---+ -// | PV | -// +--------+ -- (void)testMultiplePlatformViewsWithoutOverlays { - XCUIApplication* app = [[XCUIApplication alloc] init]; - app.launchArguments = @[ @"--platform-view-multiple-without-overlays" ]; - [app launch]; - - XCUIElement* platform_view1 = app.otherElements[@"platform_view[0]"]; - XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]); - XCTAssertEqual(platform_view1.frame.origin.x, 0); - XCTAssertEqual(platform_view1.frame.origin.y, 300); - XCTAssertEqual(platform_view1.frame.size.width, 250); - XCTAssertEqual(platform_view1.frame.size.height, 250); - - XCUIElement* platform_view2 = app.otherElements[@"platform_view[1]"]; - XCTAssertTrue(platform_view2.exists); - XCTAssertEqual(platform_view2.frame.origin.x, 0); - XCTAssertEqual(platform_view2.frame.origin.y, 0); - XCTAssertEqual(platform_view2.frame.size.width, 250); - XCTAssertEqual(platform_view2.frame.size.height, 250); - - XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[0]"].exists); - XCTAssertFalse(app.otherElements[@"platform_view[1].overlay[0]"].exists); - XCTAssertFalse(app.otherElements[@"platform_view[0].overlay_view[0]"].exists); - XCTAssertFalse(app.otherElements[@"platform_view[1].overlay_view[0]"].exists); -} - -// A is the layer above both platform view. -// +------------+ -// | PV +----+ | -// +-----| A |-+ -// +-----| |-+ -// | PV +----+ | -// +------------+ -- (void)testMultiplePlatformViewsWithOverlays { - XCUIApplication* app = [[XCUIApplication alloc] init]; - app.launchArguments = @[ @"--platform-view-multiple-background-foreground" ]; - [app launch]; - - XCUIElement* platform_view1 = app.otherElements[@"platform_view[0]"]; - XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]); - XCTAssertEqual(platform_view1.frame.origin.x, 25); - XCTAssertEqual(platform_view1.frame.origin.y, 300); - XCTAssertEqual(platform_view1.frame.size.width, 250); - XCTAssertEqual(platform_view1.frame.size.height, 250); - - XCUIElement* platform_view2 = app.otherElements[@"platform_view[1]"]; - XCTAssertTrue(platform_view2.exists); - XCTAssertEqual(platform_view2.frame.origin.x, 25); - XCTAssertEqual(platform_view2.frame.origin.y, 0); - XCTAssertEqual(platform_view2.frame.size.width, 250); - XCTAssertEqual(platform_view2.frame.size.height, 250); - - XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"]; - XCTAssertTrue(overlay1.exists); - XCTAssertEqual(overlay1.frame.origin.x, 25); - XCTAssertEqual(overlay1.frame.origin.y, 300); - XCTAssertEqual(overlay1.frame.size.width, 225); - XCTAssertEqual(overlay1.frame.size.height, 200); - - XCUIElement* overlay2 = app.otherElements[@"platform_view[1].overlay[0]"]; - XCTAssertTrue(overlay2.exists); - XCTAssertEqual(overlay2.frame.origin.x, 25); - XCTAssertEqual(overlay2.frame.origin.y, 0); - XCTAssertEqual(overlay2.frame.size.width, 225); - XCTAssertEqual(overlay2.frame.size.height, 250); - - XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; - XCTAssertTrue(overlayView0.exists); - // Overlay should always be the same frame as the app. - XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, - kCompareAccuracy); - - XCUIElement* overlayView1 = app.otherElements[@"platform_view[1].overlay_view[0]"]; - XCTAssertTrue(overlayView1.exists); - // Overlay should always be the same frame as the app. - XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, app.frame.size.height, - kCompareAccuracy); -} - -// More then two overlays are merged into a single layer. -// +---------------------+ -// | +---+ +---+ +---+ | -// | | A | | B | | C | | -// | +---+ +---+ +---+ | -// | +-------+ | -// +-| D |-----------+ -// +-------+ -- (void)testPlatformViewsMaxOverlays { - XCUIApplication* app = [[XCUIApplication alloc] init]; - app.launchArguments = @[ @"--platform-view-max-overlays" ]; - [app launch]; - - XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; - XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); - XCTAssertEqual(platform_view.frame.origin.x, 0); - XCTAssertEqual(platform_view.frame.origin.y, 0); - XCTAssertEqual(platform_view.frame.size.width, 250); - XCTAssertEqual(platform_view.frame.size.height, 250); - - XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; - XCTAssertTrue(overlay.exists); - XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists); - XCTAssertTrue(CGRectContainsRect(platform_view.frame, overlay.frame)); - - XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; - XCTAssertTrue(overlayView0.exists); - // Overlay should always be the same frame as the app. - XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, - kCompareAccuracy); - - XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; - XCTAssertFalse(overlayView1.exists); -} +// - (void)testNoOverlay { +// XCUIApplication* app = [[XCUIApplication alloc] init]; +// app.launchArguments = +// @[ @"--platform-view-no-overlay-intersection", @"--enable-software-rendering" ]; +// [app launch]; + +// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; +// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); +// XCTAssertEqual(platform_view.frame.origin.x, 0); +// XCTAssertEqual(platform_view.frame.origin.y, 0); +// XCTAssertEqual(platform_view.frame.size.width, 250); +// XCTAssertEqual(platform_view.frame.size.height, 250); + +// XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; +// XCTAssertFalse(overlay.exists); +// } + +// // A is the layer above the platform view. +// // +-----------------+ +// // | PV +---+ | +// // | | A | | +// // | +---+ | +// // +-----------------+ +// - (void)testOneOverlay { +// XCUIApplication* app = [[XCUIApplication alloc] init]; +// app.launchArguments = @[ @"--platform-view" ]; +// [app launch]; + +// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; +// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); +// XCTAssertEqual(platform_view.frame.origin.x, 0); +// XCTAssertEqual(platform_view.frame.origin.y, 0); +// XCTAssertEqual(platform_view.frame.size.width, 250); +// XCTAssertEqual(platform_view.frame.size.height, 250); + +// XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; +// XCTAssertTrue(overlay.exists); +// XCTAssertEqual(overlay.frame.origin.x, 150); +// XCTAssertEqual(overlay.frame.origin.y, 150); +// XCTAssertEqual(overlay.frame.size.width, 50); +// XCTAssertEqual(overlay.frame.size.height, 50); + +// XCUIElement* overlayView = app.otherElements[@"platform_view[0].overlay_view[0]"]; +// XCTAssertTrue(overlayView.exists); +// // Overlay should always be the same frame as the app. +// XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView.frame.size.height, app.frame.size.height, +// kCompareAccuracy); +// } + +// // A is the layer above the platform view. +// // +-----------------+ +// // | PV +---+ | +// // +-----------| A |-+ +// // +---+ +// - (void)testOneOverlayPartialIntersection { +// XCUIApplication* app = [[XCUIApplication alloc] init]; +// app.launchArguments = @[ @"--platform-view-partial-intersection" ]; +// [app launch]; + +// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; +// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); +// XCTAssertEqual(platform_view.frame.origin.x, 0); +// XCTAssertEqual(platform_view.frame.origin.y, 0); +// XCTAssertEqual(platform_view.frame.size.width, 250); +// XCTAssertEqual(platform_view.frame.size.height, 250); + +// XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; +// XCTAssertTrue(overlay.exists); +// XCTAssertEqual(overlay.frame.origin.x, 200); +// XCTAssertEqual(overlay.frame.origin.y, 245); +// XCTAssertEqual(overlay.frame.size.width, 50); +// // Half the height of the overlay. +// XCTAssertEqual(overlay.frame.size.height, 5); + +// XCUIElement* overlayView = app.otherElements[@"platform_view[0].overlay_view[0]"]; +// XCTAssertTrue(overlayView.exists); +// // Overlay should always be the same frame as the app. +// XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView.frame.size.height, app.frame.size.height, +// kCompareAccuracy); +// } + +// // A and B are the layers above the platform view. +// // +--------------------+ +// // | PV +------------+ | +// // | | B +-----+ | | +// // | +---| A |-+ | +// // +----------| |---+ +// // +-----+ +// - (void)testTwoIntersectingOverlays { +// XCUIApplication* app = [[XCUIApplication alloc] init]; +// app.launchArguments = @[ @"--platform-view-two-intersecting-overlays" ]; +// [app launch]; + +// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; +// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); +// XCTAssertEqual(platform_view.frame.origin.x, 0); +// XCTAssertEqual(platform_view.frame.origin.y, 0); +// XCTAssertEqual(platform_view.frame.size.width, 250); +// XCTAssertEqual(platform_view.frame.size.height, 250); + +// XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; +// XCTAssertTrue(overlay.exists); +// XCTAssertEqual(overlay.frame.origin.x, 150); +// XCTAssertEqual(overlay.frame.origin.y, 150); +// XCTAssertEqual(overlay.frame.size.width, 75); +// XCTAssertEqual(overlay.frame.size.height, 75); + +// XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists); +// } + +// // A, B, and C are the layers above the platform view. +// // +-------------------------+ +// // | PV +-----------+ | +// // | +---+ | B +-----+ | | +// // | | C | +---| A |-+ | +// // | +---+ +-----+ | +// // +-------------------------+ +// - (void)testOneOverlayAndTwoIntersectingOverlays { +// XCUIApplication* app = [[XCUIApplication alloc] init]; +// app.launchArguments = @[ @"--platform-view-one-overlay-two-intersecting-overlays" ]; +// [app launch]; + +// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; +// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); +// XCTAssertEqual(platform_view.frame.origin.x, 0); +// XCTAssertEqual(platform_view.frame.origin.y, 0); +// XCTAssertEqual(platform_view.frame.size.width, 250); +// XCTAssertEqual(platform_view.frame.size.height, 250); + +// XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"]; +// XCTAssertTrue(overlay1.exists); +// XCTAssertEqual(overlay1.frame.origin.x, 150); +// XCTAssertEqual(overlay1.frame.origin.y, 150); +// XCTAssertEqual(overlay1.frame.size.width, 75); +// XCTAssertEqual(overlay1.frame.size.height, 75); + +// XCUIElement* overlay2 = app.otherElements[@"platform_view[0].overlay[1]"]; +// XCTAssertTrue(overlay2.exists); +// XCTAssertEqual(overlay2.frame.origin.x, 75); +// XCTAssertEqual(overlay2.frame.origin.y, 225); +// XCTAssertEqual(overlay2.frame.size.width, 50); +// XCTAssertEqual(overlay2.frame.size.height, 25); + +// XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; +// XCTAssertTrue(overlayView0.exists); +// // Overlay should always be the same frame as the app. +// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, +// kCompareAccuracy); + +// XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; +// XCTAssertTrue(overlayView1.exists); +// // Overlay should always be the same frame as the app. +// XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, app.frame.size.height, +// kCompareAccuracy); +// } + +// // A is the layer, which z index is higher than the platform view. +// // +--------+ +// // | PV | +---+ +// // +--------+ | A | +// // +--------+ +---+ +// // | PV | +// // +--------+ +// - (void)testMultiplePlatformViewsWithoutOverlays { +// XCUIApplication* app = [[XCUIApplication alloc] init]; +// app.launchArguments = @[ @"--platform-view-multiple-without-overlays" ]; +// [app launch]; + +// XCUIElement* platform_view1 = app.otherElements[@"platform_view[0]"]; +// XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]); +// XCTAssertEqual(platform_view1.frame.origin.x, 0); +// XCTAssertEqual(platform_view1.frame.origin.y, 300); +// XCTAssertEqual(platform_view1.frame.size.width, 250); +// XCTAssertEqual(platform_view1.frame.size.height, 250); + +// XCUIElement* platform_view2 = app.otherElements[@"platform_view[1]"]; +// XCTAssertTrue(platform_view2.exists); +// XCTAssertEqual(platform_view2.frame.origin.x, 0); +// XCTAssertEqual(platform_view2.frame.origin.y, 0); +// XCTAssertEqual(platform_view2.frame.size.width, 250); +// XCTAssertEqual(platform_view2.frame.size.height, 250); + +// XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[0]"].exists); +// XCTAssertFalse(app.otherElements[@"platform_view[1].overlay[0]"].exists); +// XCTAssertFalse(app.otherElements[@"platform_view[0].overlay_view[0]"].exists); +// XCTAssertFalse(app.otherElements[@"platform_view[1].overlay_view[0]"].exists); +// } + +// // A is the layer above both platform view. +// // +------------+ +// // | PV +----+ | +// // +-----| A |-+ +// // +-----| |-+ +// // | PV +----+ | +// // +------------+ +// - (void)testMultiplePlatformViewsWithOverlays { +// XCUIApplication* app = [[XCUIApplication alloc] init]; +// app.launchArguments = @[ @"--platform-view-multiple-background-foreground" ]; +// [app launch]; + +// XCUIElement* platform_view1 = app.otherElements[@"platform_view[0]"]; +// XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]); +// XCTAssertEqual(platform_view1.frame.origin.x, 25); +// XCTAssertEqual(platform_view1.frame.origin.y, 300); +// XCTAssertEqual(platform_view1.frame.size.width, 250); +// XCTAssertEqual(platform_view1.frame.size.height, 250); + +// XCUIElement* platform_view2 = app.otherElements[@"platform_view[1]"]; +// XCTAssertTrue(platform_view2.exists); +// XCTAssertEqual(platform_view2.frame.origin.x, 25); +// XCTAssertEqual(platform_view2.frame.origin.y, 0); +// XCTAssertEqual(platform_view2.frame.size.width, 250); +// XCTAssertEqual(platform_view2.frame.size.height, 250); + +// XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"]; +// XCTAssertTrue(overlay1.exists); +// XCTAssertEqual(overlay1.frame.origin.x, 25); +// XCTAssertEqual(overlay1.frame.origin.y, 300); +// XCTAssertEqual(overlay1.frame.size.width, 225); +// XCTAssertEqual(overlay1.frame.size.height, 200); + +// XCUIElement* overlay2 = app.otherElements[@"platform_view[1].overlay[0]"]; +// XCTAssertTrue(overlay2.exists); +// XCTAssertEqual(overlay2.frame.origin.x, 25); +// XCTAssertEqual(overlay2.frame.origin.y, 0); +// XCTAssertEqual(overlay2.frame.size.width, 225); +// XCTAssertEqual(overlay2.frame.size.height, 250); + +// XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; +// XCTAssertTrue(overlayView0.exists); +// // Overlay should always be the same frame as the app. +// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, +// kCompareAccuracy); + +// XCUIElement* overlayView1 = app.otherElements[@"platform_view[1].overlay_view[0]"]; +// XCTAssertTrue(overlayView1.exists); +// // Overlay should always be the same frame as the app. +// XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, app.frame.size.height, +// kCompareAccuracy); +// } + +// // More then two overlays are merged into a single layer. +// // +---------------------+ +// // | +---+ +---+ +---+ | +// // | | A | | B | | C | | +// // | +---+ +---+ +---+ | +// // | +-------+ | +// // +-| D |-----------+ +// // +-------+ +// - (void)testPlatformViewsMaxOverlays { +// XCUIApplication* app = [[XCUIApplication alloc] init]; +// app.launchArguments = @[ @"--platform-view-max-overlays" ]; +// [app launch]; + +// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; +// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); +// XCTAssertEqual(platform_view.frame.origin.x, 0); +// XCTAssertEqual(platform_view.frame.origin.y, 0); +// XCTAssertEqual(platform_view.frame.size.width, 250); +// XCTAssertEqual(platform_view.frame.size.height, 250); + +// XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; +// XCTAssertTrue(overlay.exists); +// XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists); +// XCTAssertTrue(CGRectContainsRect(platform_view.frame, overlay.frame)); + +// XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; +// XCTAssertTrue(overlayView0.exists); +// // Overlay should always be the same frame as the app. +// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); +// XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, +// kCompareAccuracy); + +// XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; +// XCTAssertFalse(overlayView1.exists); +// } @end diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index da93c5788284d..a1b60bd24767d 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -69,8 +69,8 @@ else echo "Zip" # Using RESULT_BUNDLE_PATH causes the zip containing all the sub directories. # So use relative directory instead. - zip -q ios_scenario_xcresult.zip "./$RESULT_BUNDLE_FOLDER" - mv ios_scenario_xcresult.zip $LUCI_TEST_OUTPUTS_PATH + zip -q -r ios_scenario_xcresult.zip "./$RESULT_BUNDLE_FOLDER" + mv ios_scenario_xcresult.zip $DUMP_PATH fi # echo "Running simulator tests with Impeller" From 401b96b26c92d8ea1e0d45acf51a9e716042daec Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 9 May 2023 18:04:29 -0700 Subject: [PATCH 06/27] format --- .../Source/FlutterPlatformViewsTest.mm | 558 ++++++++++-------- .../ScenariosUITests/PlatformViewUITests.m | 12 +- .../UnobstructedPlatformViewTests.m | 35 +- 3 files changed, 354 insertions(+), 251 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 2fc4d1466b10d..56f229e56335d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -225,8 +225,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // - (void)testChildClippingViewHitTests { // ChildClippingView* childClippingView = // [[[ChildClippingView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; -// UIView* childView = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] autorelease]; -// [childClippingView addSubview:childView]; +// UIView* childView = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] +// autorelease]; [childClippingView addSubview:childView]; // XCTAssertFalse([childClippingView pointInside:CGPointMake(50, 50) withEvent:nil]); // XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 100) withEvent:nil]); @@ -251,8 +251,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -273,8 +274,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -286,13 +287,15 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), +// stack); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -321,8 +324,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -343,8 +347,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -356,13 +360,15 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 8, screenScale * 8)); // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(5, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(5, 10), +// stack); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -391,8 +397,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -413,8 +420,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -423,18 +430,21 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack.PushTransform(screenScaleMatrix); // // Push backdrop filters // for (int i = 0; i < 50; i++) { -// auto filter = std::make_shared(i, 2, flutter::DlTileMode::kClamp); -// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// auto filter = std::make_shared(i, 2, +// flutter::DlTileMode::kClamp); stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, +// screenScale * 10, screenScale * 10)); // } // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(20, 20), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(20, 20), +// stack); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -462,8 +472,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -484,8 +495,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -497,13 +508,15 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), +// stack); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -530,11 +543,13 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack2.PushTransform(screenScaleMatrix); // // Push backdrop filters // for (int i = 0; i < 2; i++) { -// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * +// 10)); // } // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -573,8 +588,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -595,8 +611,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -610,13 +626,15 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), +// stack); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -641,11 +659,13 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack2.PushTransform(screenScaleMatrix); // // Push backdrop filters // for (int i = 0; i < 4; i++) { -// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * +// 10)); // } // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -684,7 +704,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // // No backdrop filters in the stack, so no nothing to push // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -708,8 +729,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -730,8 +752,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -745,13 +767,15 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), +// stack); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -785,11 +809,13 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // continue; // } -// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * +// 10)); // } // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -824,7 +850,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // [newVisualEffectViews removeAllObjects]; -// // Simulate editing 1 backdrop filter in the beginning of the stack (replace the mutators stack) +// // Simulate editing 1 backdrop filter in the beginning of the stack (replace the mutators +// stack) // // Update embedded view params, delete except screenScaleMatrix // for (int i = 0; i < 5; i++) { // stack2.Pop(); @@ -839,11 +866,13 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // continue; // } -// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * +// 10)); // } // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -891,11 +920,13 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // continue; // } -// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * +// 10)); // } // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -937,13 +968,16 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // // Push backdrop filters // for (int i = 0; i < 5; i++) { -// auto filter2 = std::make_shared(i, 2, flutter::DlTileMode::kClamp); +// auto filter2 = std::make_shared(i, 2, +// flutter::DlTileMode::kClamp); -// stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); +// stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * +// 10)); // } // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -983,8 +1017,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -1005,8 +1040,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -1018,12 +1053,14 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack.PushBackdropFilter(dilateFilter, SkRect::MakeEmpty()); // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), +// stack); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; // [mockFlutterView addSubview:childClippingView]; @@ -1044,7 +1081,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // // Layer tree always pushes a screen scale factor to the stack // stack2.PushTransform(screenScaleMatrix); // // Push backdrop filters and dilate filter -// auto blurFilter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); +// auto blurFilter = std::make_shared(5, 2, +// flutter::DlTileMode::kClamp); // for (int i = 0; i < 5; i++) { // if (i == 2) { @@ -1058,7 +1096,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -1097,7 +1136,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -1136,7 +1176,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -1169,7 +1210,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), stack2); +// SkSize::Make(10, 10), +// stack2); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -1281,8 +1323,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -1303,8 +1346,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -1324,7 +1367,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // flutterPlatformViewsController->CompositeEmbeddedView(2); // CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds // toView:mockFlutterView]; -// XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, 300))); +// XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, +// 300))); // } // - (void)testBackdropFilterCorrectlyPushedAndReset { @@ -1335,8 +1379,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -1357,8 +1402,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -1367,7 +1412,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack.PushTransform(screenScaleMatrix); // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), +// stack); // flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); @@ -1377,8 +1423,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -1400,10 +1447,11 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // // New frame, with no filter pushed. // auto embeddedViewParams2 = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), +// stack); // flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, +// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(2); // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); // [mockFlutterView setNeedsLayout]; @@ -1427,8 +1475,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -1449,8 +1498,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -1472,13 +1521,17 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds // toView:mockFlutterView]; // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// // The childclippingview's frame is set based on flow, but the platform view's frame is set based +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; +// // The childclippingview's frame is set based on flow, but the platform view's frame is set +// based // // on quartz. Although they should be the same, but we should tolerate small floating point // // errors. -// XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - childClippingView.frame.origin.x), +// XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - +// childClippingView.frame.origin.x), // kFloatCompareEpsilon); -// XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - childClippingView.frame.origin.y), +// XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - +// childClippingView.frame.origin.y), // kFloatCompareEpsilon); // XCTAssertLessThan( // fabs(platformViewRectInFlutterView.size.width - childClippingView.frame.size.width), @@ -1496,8 +1549,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -1518,8 +1572,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params. // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack. @@ -1533,10 +1587,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // SkRect rect = SkRect::MakeXYWH(0, 0, 25, 25); // stack.PushClipRect(rect); // // Push a clip rrect, big enough to contain the entire platform view bound without clipping it. -// // Make the origin (-1, -1) so that the top left rounded corner isn't clipping the PlatformView. -// SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25); -// SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); -// stack.PushClipRRect(rrect); +// // Make the origin (-1, -1) so that the top left rounded corner isn't clipping the +// PlatformView. SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25); SkRRect rrect = +// SkRRect::MakeRectXY(rect_for_rrect, 1, 1); stack.PushClipRRect(rrect); // auto embeddedViewParams = std::make_unique( // SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack); @@ -1545,8 +1598,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // flutterPlatformViewsController->CompositeEmbeddedView(2); // gMockPlatformView.backgroundColor = UIColor.redColor; // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -1561,8 +1615,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -1583,8 +1638,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack. @@ -1595,7 +1650,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // // The platform view's rect for this test will be (5, 5, 10, 10). // stack.PushTransform(translateMatrix); -// // Push a clip rrect, the rect of the rrect is the same as the PlatformView of the corner should. +// // Push a clip rrect, the rect of the rrect is the same as the PlatformView of the corner +// should. // // clip the PlatformView. // SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10); // SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); @@ -1608,8 +1664,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // flutterPlatformViewsController->CompositeEmbeddedView(2); // gMockPlatformView.backgroundColor = UIColor.redColor; // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -1625,8 +1682,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -1647,8 +1705,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -1660,14 +1718,16 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack.PushClipRect(rect); // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), +// stack); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // gMockPlatformView.backgroundColor = UIColor.redColor; // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -1696,8 +1756,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -1718,8 +1779,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -1731,14 +1792,16 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack.PushClipRRect(rrect); // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), +// stack); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // gMockPlatformView.backgroundColor = UIColor.redColor; // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -1767,8 +1830,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -1789,8 +1853,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack; // // Layer tree always pushes a screen scale factor to the stack @@ -1803,14 +1867,16 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // stack.PushClipPath(path); // auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); +// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), +// stack); // flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); // flutterPlatformViewsController->CompositeEmbeddedView(2); // gMockPlatformView.backgroundColor = UIColor.redColor; // XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; -// [mockFlutterView addSubview:childClippingView]; +// ChildClippingView* childClippingView = +// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView +// addSubview:childClippingView]; // [mockFlutterView setNeedsLayout]; // [mockFlutterView layoutIfNeeded]; @@ -1839,8 +1905,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -1901,8 +1968,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -2012,7 +2080,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // - (void) -// testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence { +// testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence +// { // flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; // auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); // flutter::TaskRunners runners(/*label=*/self.name.UTF8String, @@ -2020,8 +2089,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -2062,9 +2132,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); -// // The touches in this sequence requires 1 touch object, we always create the NSSet with one item. -// NSSet* touches1 = [NSSet setWithObject:@1]; -// id event1 = OCMClassMock([UIEvent class]); +// // The touches in this sequence requires 1 touch object, we always create the NSSet with one +// item. NSSet* touches1 = [NSSet setWithObject:@1]; id event1 = OCMClassMock([UIEvent class]); // [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; // OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); @@ -2129,8 +2198,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -2189,8 +2259,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -2218,20 +2289,21 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // auto embeddedViewParams_1 = // std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_1)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, +// std::move(embeddedViewParams_1)); flutterPlatformViewsController->CompositeEmbeddedView(2); // flutter::SurfaceFrame::FramebufferInfo framebuffer_info; // auto mock_surface = std::make_unique( // nullptr, framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return false; }, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return false; +// }, // /*frame_size=*/SkISize::Make(800, 600)); // XCTAssertFalse( // flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); // auto embeddedViewParams_2 = // std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_2)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, +// std::move(embeddedViewParams_2)); flutterPlatformViewsController->CompositeEmbeddedView(2); // auto mock_surface_submit_true = std::make_unique( // nullptr, framebuffer_info, // [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, @@ -2241,7 +2313,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // - (void) -// testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView { +// testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView +// { // flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; // auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); // flutter::TaskRunners runners(/*label=*/self.name.UTF8String, @@ -2249,15 +2322,16 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, // /*task_runners=*/runners); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = // [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2277,10 +2351,12 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // flutter::MutatorsStack stack; // SkMatrix finalMatrix; // auto embeddedViewParams = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// // Not calling |flutterPlatformViewsController::SubmitFrame| so that the platform views are not +// std::make_unique(finalMatrix, SkSize::Make(300, 300), +// stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, +// std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); +// // Not calling |flutterPlatformViewsController::SubmitFrame| so that the platform views are +// not // // added to flutter_view_. // XCTAssertNotNil(gMockPlatformView); @@ -2297,15 +2373,16 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, // /*task_runners=*/runners); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = // [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2327,8 +2404,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // SkMatrix finalMatrix; // auto embeddedViewParams1 = // std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); -// flutterPlatformViewsController->CompositeEmbeddedView(0); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, +// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); // XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); // // Second frame, |EmbeddedViewCount| should be empty at the start @@ -2337,13 +2414,14 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // auto embeddedViewParams2 = // std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams2)); -// flutterPlatformViewsController->CompositeEmbeddedView(0); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, +// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(0); // XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); // } // - (void) -// testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy { +// testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy +// { // flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; // auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); // flutter::TaskRunners runners(/*label=*/self.name.UTF8String, @@ -2351,15 +2429,16 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, // /*task_runners=*/runners); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = // [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2388,12 +2467,12 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // SkMatrix finalMatrix; // auto embeddedViewParams1 = // std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); -// flutterPlatformViewsController->CompositeEmbeddedView(0); -// auto embeddedViewParams2 = +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, +// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); auto +// embeddedViewParams2 = // std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); -// flutterPlatformViewsController->CompositeEmbeddedView(1); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, +// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); // // SKSurface is required if the root FlutterView is present. // const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); @@ -2419,12 +2498,12 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // // Process the second frame in the opposite order. // embeddedViewParams2 = // std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); -// flutterPlatformViewsController->CompositeEmbeddedView(1); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, +// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); // embeddedViewParams1 = // std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); -// flutterPlatformViewsController->CompositeEmbeddedView(0); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, +// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); // mock_sk_surface = SkSurface::MakeRaster(image_info); // mock_surface = std::make_unique( @@ -2439,7 +2518,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // - (void) -// testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy { +// testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy +// { // flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; // auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); // flutter::TaskRunners runners(/*label=*/self.name.UTF8String, @@ -2447,15 +2527,16 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, // /*task_runners=*/runners); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = // [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2484,12 +2565,12 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // SkMatrix finalMatrix; // auto embeddedViewParams1 = // std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); -// flutterPlatformViewsController->CompositeEmbeddedView(0); -// auto embeddedViewParams2 = +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, +// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); auto +// embeddedViewParams2 = // std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); -// flutterPlatformViewsController->CompositeEmbeddedView(1); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, +// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); // // SKSurface is required if the root FlutterView is present. // const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); @@ -2515,12 +2596,12 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // // Process the second frame in the same order. // embeddedViewParams1 = // std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); -// flutterPlatformViewsController->CompositeEmbeddedView(0); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, +// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); // embeddedViewParams2 = // std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); -// flutterPlatformViewsController->CompositeEmbeddedView(1); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, +// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); // mock_sk_surface = SkSurface::MakeRaster(image_info); // mock_surface = std::make_unique( @@ -2543,15 +2624,16 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner_other, // /*ui=*/thread_task_runner_other, // /*io=*/thread_task_runner_other); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, // /*task_runners=*/runners); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = // [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2691,8 +2773,9 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, @@ -2712,8 +2795,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // result); // XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // // Create embedded view params // flutter::MutatorsStack stack1; // // Layer tree always pushes a screen scale factor to the stack @@ -2731,8 +2814,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // auto embeddedViewParams2 = std::make_unique( // screenScaleMatrix, SkSize::Make(10, 10), stack2); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); -// flutterPlatformViewsController->CompositeEmbeddedView(1); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, +// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); // UIView* childClippingView1 = gMockPlatformView.superview.superview; // UIView* maskView1 = childClippingView1.maskView; // XCTAssertNotNil(maskView1); @@ -2740,8 +2823,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // // Composite a new frame. // auto embeddedViewParams3 = std::make_unique( // screenScaleMatrix, SkSize::Make(10, 10), stack2); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams3)); -// flutterPlatformViewsController->CompositeEmbeddedView(1); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, +// std::move(embeddedViewParams3)); flutterPlatformViewsController->CompositeEmbeddedView(1); // childClippingView1 = gMockPlatformView.superview.superview; // // This overrides gMockPlatformView to point to the newly created platform view. @@ -2753,8 +2836,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // auto embeddedViewParams4 = std::make_unique( // screenScaleMatrix, SkSize::Make(10, 10), stack1); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams4)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, +// std::move(embeddedViewParams4)); flutterPlatformViewsController->CompositeEmbeddedView(2); // UIView* childClippingView2 = gMockPlatformView.superview.superview; // UIView* maskView2 = childClippingView2.maskView; @@ -2763,7 +2846,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // XCTAssertNil(childClippingView1.maskView); // } -// // Return true if a correct visual effect view is found. It also implies all the validation in this +// // Return true if a correct visual effect view is found. It also implies all the validation in +// this // // method passes. // // // // There are two fail states for this method. 1. One of the XCTAssert method failed; or 2. No @@ -2798,15 +2882,16 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, // /*task_runners=*/runners); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; -// flutterPlatformViewsController->SetFlutterView(mockFlutterView); +// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] +// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); // FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = // [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2828,20 +2913,23 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // result); // { -// // **** First frame, view id 0, 1 in the composition_order_, disposing view 0 is called. **** // +// // **** First frame, view id 0, 1 in the composition_order_, disposing view 0 is called. **** +// // // // No view should be disposed, or removed from the composition order. // flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); // flutter::MutatorsStack stack; // SkMatrix finalMatrix; // auto embeddedViewParams0 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams0)); -// flutterPlatformViewsController->CompositeEmbeddedView(0); +// std::make_unique(finalMatrix, SkSize::Make(300, 300), +// stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, +// std::move(embeddedViewParams0)); flutterPlatformViewsController->CompositeEmbeddedView(0); // auto embeddedViewParams1 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); -// flutterPlatformViewsController->CompositeEmbeddedView(1); +// std::make_unique(finalMatrix, SkSize::Make(300, 300), +// stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, +// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); // XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); // XCTestExpectation* expectation = [self expectationWithDescription:@"dispose call ended."]; @@ -2858,40 +2946,44 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // flutter::SurfaceFrame::FramebufferInfo framebuffer_info; // auto mock_surface = std::make_unique( // std::move(mock_sk_surface), framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; +// }, // /*frame_size=*/SkISize::Make(800, 600)); // XCTAssertTrue( // flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); -// // Disposing won't remove embedded views until the view is removed from the composition_order_ -// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); +// // Disposing won't remove embedded views until the view is removed from the +// composition_order_ XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); // XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(0)); // XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); // } // { -// // **** Second frame, view id 1 in the composition_order_, no disposing view is called, **** // +// // **** Second frame, view id 1 in the composition_order_, no disposing view is called, **** +// // // // View 0 is removed from the composition order in this frame, hence also disposed. // flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); // flutter::MutatorsStack stack; // SkMatrix finalMatrix; // auto embeddedViewParams1 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); -// flutterPlatformViewsController->CompositeEmbeddedView(1); +// std::make_unique(finalMatrix, SkSize::Make(300, 300), +// stack); +// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, +// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); // const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); // sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); // flutter::SurfaceFrame::FramebufferInfo framebuffer_info; // auto mock_surface = std::make_unique( // std::move(mock_sk_surface), framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, +// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; +// }, // /*frame_size=*/SkISize::Make(800, 600)); // XCTAssertTrue( // flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); -// // Disposing won't remove embedded views until the view is removed from the composition_order_ -// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); +// // Disposing won't remove embedded views until the view is removed from the +// composition_order_ XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); // XCTAssertNil(flutterPlatformViewsController->GetPlatformViewByID(0)); // XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); // } diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m index 481c249395b21..6dc61139f42d7 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m @@ -31,7 +31,8 @@ // - (instancetype)initWithInvocation:(NSInvocation*)invocation { // GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--non-full-screen-flutter-view-platform-view"]; +// [[GoldenTestManager alloc] +// initWithLaunchArg:@"--non-full-screen-flutter-view-platform-view"]; // return [super initWithManager:manager invocation:invocation]; // } @@ -298,7 +299,8 @@ - (void)testPlatformView { // - (instancetype)initWithInvocation:(NSInvocation*)invocation { // GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-with-other-backdrop-filter"]; +// [[GoldenTestManager alloc] +// initWithLaunchArg:@"--platform-view-with-other-backdrop-filter"]; // return [super initWithManager:manager invocation:invocation]; // } @@ -406,9 +408,11 @@ - (void)testPlatformView { // // Wait and let the scenario app scroll a bit. // XCTWaiterResult waitResult = [XCTWaiter -// waitForExpectations:@[ [[XCTestExpectation alloc] initWithDescription:@"Wait for 5 seconds"] ] +// waitForExpectations:@[ [[XCTestExpectation alloc] initWithDescription:@"Wait for 5 +// seconds"] ] // timeout:5]; -// // If the waiter is not interrupted, we know the app is in a valid state after timeout, thus the +// // If the waiter is not interrupted, we know the app is in a valid state after timeout, thus +// the // // test passes. // XCTAssert(waitResult != XCTWaiterResultInterrupted); // } diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m index 679c07e5b4f21..7e640da1ef778 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m @@ -68,8 +68,9 @@ - (void)setUp { // // Overlay should always be the same frame as the app. // XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); // XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView.frame.size.height, app.frame.size.height, +// XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, +// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView.frame.size.height, +// app.frame.size.height, // kCompareAccuracy); // } @@ -103,8 +104,9 @@ - (void)setUp { // // Overlay should always be the same frame as the app. // XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); // XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView.frame.size.height, app.frame.size.height, +// XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, +// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView.frame.size.height, +// app.frame.size.height, // kCompareAccuracy); // } @@ -175,8 +177,9 @@ - (void)setUp { // // Overlay should always be the same frame as the app. // XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); // XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, +// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, +// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, +// app.frame.size.height, // kCompareAccuracy); // XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; @@ -184,8 +187,9 @@ - (void)setUp { // // Overlay should always be the same frame as the app. // XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); // XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, app.frame.size.height, +// XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, +// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, +// app.frame.size.height, // kCompareAccuracy); // } @@ -266,8 +270,9 @@ - (void)setUp { // // Overlay should always be the same frame as the app. // XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); // XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, +// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, +// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, +// app.frame.size.height, // kCompareAccuracy); // XCUIElement* overlayView1 = app.otherElements[@"platform_view[1].overlay_view[0]"]; @@ -275,8 +280,9 @@ - (void)setUp { // // Overlay should always be the same frame as the app. // XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); // XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, app.frame.size.height, +// XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, +// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, +// app.frame.size.height, // kCompareAccuracy); // } @@ -310,8 +316,9 @@ - (void)setUp { // // Overlay should always be the same frame as the app. // XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); // XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, +// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, +// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, +// app.frame.size.height, // kCompareAccuracy); // XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; From 1785df06999929f138f1aee0399c61aec1754fbd Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 9 May 2023 19:08:38 -0700 Subject: [PATCH 07/27] fix build error --- .../Source/FlutterPlatformViewsTest.mm | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 56f229e56335d..15fe0a2049fa4 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -191,36 +191,36 @@ - (void)testFlutterViewOnlyCreateOnceInOneFrame { flutterPlatformViewsController->Reset(); } -- (void)testCanCreatePlatformViewWithoutFlutterView { - flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; - auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto flutterPlatformViewsController = std::make_shared(); - auto platform_view = std::make_unique( - /*delegate=*/mock_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*platform_views_controller=*/flutterPlatformViewsController, - /*task_runners=*/runners); +// - (void)testCanCreatePlatformViewWithoutFlutterView { +// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; +// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); +// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, +// /*platform=*/thread_task_runner, +// /*raster=*/thread_task_runner, +// /*ui=*/thread_task_runner, +// /*io=*/thread_task_runner); +// auto flutterPlatformViewsController = std::make_shared(); +// auto platform_view = std::make_unique( +// /*delegate=*/mock_delegate, +// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, +// /*platform_views_controller=*/flutterPlatformViewsController, +// /*task_runners=*/runners); - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; - flutterPlatformViewsController->RegisterViewFactory( - factory, @"MockFlutterPlatformView", - FlutterPlatformViewGestureRecognizersBlockingPolicyEager); - FlutterResult result = ^(id result) { - }; - flutterPlatformViewsController->OnMethodCall( - [FlutterMethodCall - methodCallWithMethodName:@"create" - arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], - result); +// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = +// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; +// flutterPlatformViewsController->RegisterViewFactory( +// factory, @"MockFlutterPlatformView", +// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); +// FlutterResult result = ^(id result) { +// }; +// flutterPlatformViewsController->OnMethodCall( +// [FlutterMethodCall +// methodCallWithMethodName:@"create" +// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], +// result); - XCTAssertNotNil(gMockPlatformView); -} +// XCTAssertNotNil(gMockPlatformView); +// } // - (void)testChildClippingViewHitTests { // ChildClippingView* childClippingView = @@ -2989,4 +2989,4 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { // } // } -// @end +@end From 8738aaf5afc0f186312c866bfce3a727da1a1c2a Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 9 May 2023 19:36:07 -0700 Subject: [PATCH 08/27] format --- .../darwin/ios/framework/Source/FlutterPlatformViewsTest.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 15fe0a2049fa4..6a1142928c180 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -199,8 +199,9 @@ - (void)testFlutterViewOnlyCreateOnceInOneFrame { // /*raster=*/thread_task_runner, // /*ui=*/thread_task_runner, // /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = std::make_shared(); -// auto platform_view = std::make_unique( +// auto flutterPlatformViewsController = +// std::make_shared(); auto platform_view = +// std::make_unique( // /*delegate=*/mock_delegate, // /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, // /*platform_views_controller=*/flutterPlatformViewsController, From 03afc3a596e7752aa9320b4bc3b800b67d007cb3 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 9 May 2023 20:26:41 -0700 Subject: [PATCH 09/27] fix build error --- .../darwin/ios/framework/Source/FlutterPlatformViewsTest.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 6a1142928c180..cf16c72b8a388 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -17,7 +17,7 @@ FLUTTER_ASSERT_NOT_ARC @class FlutterPlatformViewsTestMockPlatformView; static FlutterPlatformViewsTestMockPlatformView* gMockPlatformView = nil; -const float kFloatCompareEpsilon = 0.001; +// const float kFloatCompareEpsilon = 0.001; @interface FlutterPlatformViewsTestMockPlatformView : UIView @end From 1d9ca4738e7dade8f9636e3984be272cd09235db Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 9 May 2023 21:29:58 -0700 Subject: [PATCH 10/27] enable scenario tests --- .../ScenariosUITests/PlatformViewUITests.m | 534 +++++++++--------- 1 file changed, 267 insertions(+), 267 deletions(-) diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m index 6dc61139f42d7..0dd2f7b707623 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m @@ -6,98 +6,98 @@ static const NSInteger kSecondsToWaitForPlatformView = 30; -// @interface PlatformViewUITests : GoldenPlatformViewTests +@interface PlatformViewUITests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewUITests +@implementation PlatformViewUITests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface NonFullScreenFlutterViewPlatformViewUITests : GoldenPlatformViewTests +@interface NonFullScreenFlutterViewPlatformViewUITests : GoldenPlatformViewTests -// @end +@end -// @implementation NonFullScreenFlutterViewPlatformViewUITests +@implementation NonFullScreenFlutterViewPlatformViewUITests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] -// initWithLaunchArg:@"--non-full-screen-flutter-view-platform-view"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] + initWithLaunchArg:@"--non-full-screen-flutter-view-platform-view"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface MultiplePlatformViewsTest : GoldenPlatformViewTests +@interface MultiplePlatformViewsTest : GoldenPlatformViewTests -// @end +@end -// @implementation MultiplePlatformViewsTest +@implementation MultiplePlatformViewsTest -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-multiple"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-multiple"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface MultiplePlatformViewsBackgroundForegroundTest : GoldenPlatformViewTests +@interface MultiplePlatformViewsBackgroundForegroundTest : GoldenPlatformViewTests -// @end +@end -// @implementation MultiplePlatformViewsBackgroundForegroundTest +@implementation MultiplePlatformViewsBackgroundForegroundTest -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = [[GoldenTestManager alloc] -// initWithLaunchArg:@"--platform-view-multiple-background-foreground"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = [[GoldenTestManager alloc] + initWithLaunchArg:@"--platform-view-multiple-background-foreground"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonHome]; -// [self.application activate]; -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonHome]; + [self.application activate]; + [self checkPlatformViewGolden]; +} -// @end +@end -// // Clip Rect Tests -// @interface PlatformViewMutationClipRectTests : GoldenPlatformViewTests +// Clip Rect Tests +@interface PlatformViewMutationClipRectTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewMutationClipRectTests +@implementation PlatformViewMutationClipRectTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprect"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprect"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end @interface PlatformViewMutationClipRectAfterMovedTests : GoldenPlatformViewTests @@ -129,292 +129,292 @@ - (void)testPlatformView { @end -// @interface PlatformViewMutationClipRRectTests : GoldenPlatformViewTests +@interface PlatformViewMutationClipRRectTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewMutationClipRRectTests +@implementation PlatformViewMutationClipRRectTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprrect"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprrect"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface PlatformViewMutationLargeClipRRectTests : GoldenPlatformViewTests +@interface PlatformViewMutationLargeClipRRectTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewMutationLargeClipRRectTests +@implementation PlatformViewMutationLargeClipRRectTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-large-cliprrect"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-large-cliprrect"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface PlatformViewMutationClipPathTests : GoldenPlatformViewTests +@interface PlatformViewMutationClipPathTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewMutationClipPathTests +@implementation PlatformViewMutationClipPathTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-clippath"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-clippath"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface PlatformViewMutationClipRectWithTransformTests : GoldenPlatformViewTests +@interface PlatformViewMutationClipRectWithTransformTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewMutationClipRectWithTransformTests +@implementation PlatformViewMutationClipRectWithTransformTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprect-with-transform"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprect-with-transform"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface PlatformViewMutationClipRRectWithTransformTests : GoldenPlatformViewTests +@interface PlatformViewMutationClipRRectWithTransformTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewMutationClipRRectWithTransformTests +@implementation PlatformViewMutationClipRRectWithTransformTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprrect-with-transform"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-cliprrect-with-transform"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface PlatformViewMutationLargeClipRRectWithTransformTests : GoldenPlatformViewTests +@interface PlatformViewMutationLargeClipRRectWithTransformTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewMutationLargeClipRRectWithTransformTests +@implementation PlatformViewMutationLargeClipRRectWithTransformTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = [[GoldenTestManager alloc] -// initWithLaunchArg:@"--platform-view-large-cliprrect-with-transform"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = [[GoldenTestManager alloc] + initWithLaunchArg:@"--platform-view-large-cliprrect-with-transform"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface PlatformViewMutationClipPathWithTransformTests : GoldenPlatformViewTests +@interface PlatformViewMutationClipPathWithTransformTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewMutationClipPathWithTransformTests +@implementation PlatformViewMutationClipPathWithTransformTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-clippath-with-transform"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-clippath-with-transform"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface PlatformViewMutationTransformTests : GoldenPlatformViewTests +@interface PlatformViewMutationTransformTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewMutationTransformTests +@implementation PlatformViewMutationTransformTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-transform"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-transform"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface PlatformViewMutationOpacityTests : GoldenPlatformViewTests +@interface PlatformViewMutationOpacityTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewMutationOpacityTests +@implementation PlatformViewMutationOpacityTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-opacity"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-opacity"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface PlatformViewWithOtherBackdropFilterTests : GoldenPlatformViewTests +@interface PlatformViewWithOtherBackdropFilterTests : GoldenPlatformViewTests -// @end +@end -// @implementation PlatformViewWithOtherBackdropFilterTests +@implementation PlatformViewWithOtherBackdropFilterTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] -// initWithLaunchArg:@"--platform-view-with-other-backdrop-filter"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] + initWithLaunchArg:@"--platform-view-with-other-backdrop-filter"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface TwoPlatformViewsWithOtherBackDropFilterTests : GoldenPlatformViewTests +@interface TwoPlatformViewsWithOtherBackDropFilterTests : GoldenPlatformViewTests -// @end +@end -// @implementation TwoPlatformViewsWithOtherBackDropFilterTests +@implementation TwoPlatformViewsWithOtherBackDropFilterTests -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = [[GoldenTestManager alloc] -// initWithLaunchArg:@"--two-platform-views-with-other-backdrop-filter"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = [[GoldenTestManager alloc] + initWithLaunchArg:@"--two-platform-views-with-other-backdrop-filter"]; + return [super initWithManager:manager invocation:invocation]; +} -// - (void)testPlatformView { -// [self checkPlatformViewGolden]; -// } +- (void)testPlatformView { + [self checkPlatformViewGolden]; +} -// @end +@end -// @interface PlatformViewRotation : GoldenPlatformViewTests -// @end +@interface PlatformViewRotation : GoldenPlatformViewTests +@end + +@implementation PlatformViewRotation +- (instancetype)initWithInvocation:(NSInvocation*)invocation { + GoldenTestManager* manager = + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-rotate"]; + return [super initWithManager:manager invocation:invocation]; +} -// @implementation PlatformViewRotation -// - (instancetype)initWithInvocation:(NSInvocation*)invocation { -// GoldenTestManager* manager = -// [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-rotate"]; -// return [super initWithManager:manager invocation:invocation]; -// } +- (void)tearDown { + XCUIDevice.sharedDevice.orientation = UIDeviceOrientationPortrait; + [super tearDown]; +} -// - (void)tearDown { -// XCUIDevice.sharedDevice.orientation = UIDeviceOrientationPortrait; -// [super tearDown]; -// } +- (void)testPlatformView { + XCUIDevice.sharedDevice.orientation = UIDeviceOrientationLandscapeLeft; + [self checkPlatformViewGolden]; +} -// - (void)testPlatformView { -// XCUIDevice.sharedDevice.orientation = UIDeviceOrientationLandscapeLeft; -// [self checkPlatformViewGolden]; -// } +@end -// @end +@interface PlatformViewWithContinuousTexture : XCTestCase -// @interface PlatformViewWithContinuousTexture : XCTestCase +@end -// @end +@implementation PlatformViewWithContinuousTexture -// @implementation PlatformViewWithContinuousTexture +- (void)setUp { + self.continueAfterFailure = NO; +} -// - (void)setUp { -// self.continueAfterFailure = NO; -// } +- (void)testPlatformViewWithContinuousTexture { + XCUIApplication* app = [[XCUIApplication alloc] init]; + app.launchArguments = + @[ @"--platform-view-with-continuous-texture", @"--with-continuous-texture" ]; + [app launch]; -// - (void)testPlatformViewWithContinuousTexture { -// XCUIApplication* app = [[XCUIApplication alloc] init]; -// app.launchArguments = -// @[ @"--platform-view-with-continuous-texture", @"--with-continuous-texture" ]; -// [app launch]; + XCUIElement* platformView = app.textViews.firstMatch; + BOOL exists = [platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]; + if (!exists) { + XCTFail(@"It took longer than %@ second to find the platform view." + @"There might be issues with the platform view's construction," + @"or with how the scenario is built.", + @(kSecondsToWaitForPlatformView)); + } -// XCUIElement* platformView = app.textViews.firstMatch; -// BOOL exists = [platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]; -// if (!exists) { -// XCTFail(@"It took longer than %@ second to find the platform view." -// @"There might be issues with the platform view's construction," -// @"or with how the scenario is built.", -// @(kSecondsToWaitForPlatformView)); -// } + XCTAssertNotNil(platformView); +} -// XCTAssertNotNil(platformView); -// } +@end -// @end +@interface PlatformViewScrollingUnderWidget : XCTestCase -// @interface PlatformViewScrollingUnderWidget : XCTestCase +@end -// @end +@implementation PlatformViewScrollingUnderWidget -// @implementation PlatformViewScrollingUnderWidget +- (void)setUp { + [super setUp]; + self.continueAfterFailure = NO; +} -// - (void)setUp { -// [super setUp]; -// self.continueAfterFailure = NO; -// } +- (void)testPlatformViewScrollingUnderWidget { + XCUIApplication* app = [[XCUIApplication alloc] init]; + app.launchArguments = + @[ @"--platform-view-scrolling-under-widget", @"--with-continuous-texture" ]; + [app launch]; -// - (void)testPlatformViewScrollingUnderWidget { -// XCUIApplication* app = [[XCUIApplication alloc] init]; -// app.launchArguments = -// @[ @"--platform-view-scrolling-under-widget", @"--with-continuous-texture" ]; -// [app launch]; + XCUIElement* platformView = app.textViews.firstMatch; + BOOL exists = [platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]; + if (!exists) { + XCTFail(@"It took longer than %@ second to find the platform view." + @"There might be issues with the platform view's construction," + @"or with how the scenario is built.", + @(kSecondsToWaitForPlatformView)); + } -// XCUIElement* platformView = app.textViews.firstMatch; -// BOOL exists = [platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]; -// if (!exists) { -// XCTFail(@"It took longer than %@ second to find the platform view." -// @"There might be issues with the platform view's construction," -// @"or with how the scenario is built.", -// @(kSecondsToWaitForPlatformView)); -// } + // Wait and let the scenario app scroll a bit. + XCTWaiterResult waitResult = [XCTWaiter + waitForExpectations:@[ [[XCTestExpectation alloc] initWithDescription:@"Wait for 5 + seconds"] ] + timeout:5]; + // If the waiter is not interrupted, we know the app is in a valid state after timeout, thus + the + // test passes. + XCTAssert(waitResult != XCTWaiterResultInterrupted); +} -// // Wait and let the scenario app scroll a bit. -// XCTWaiterResult waitResult = [XCTWaiter -// waitForExpectations:@[ [[XCTestExpectation alloc] initWithDescription:@"Wait for 5 -// seconds"] ] -// timeout:5]; -// // If the waiter is not interrupted, we know the app is in a valid state after timeout, thus -// the -// // test passes. -// XCTAssert(waitResult != XCTWaiterResultInterrupted); -// } - -// @end +@end From 804b728ea962aa1525d8f9236d066cb186f4d6c5 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 9 May 2023 21:30:28 -0700 Subject: [PATCH 11/27] format --- .../ios/Scenarios/ScenariosUITests/PlatformViewUITests.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m index 0dd2f7b707623..040dd675dc387 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m @@ -31,8 +31,7 @@ @implementation NonFullScreenFlutterViewPlatformViewUITests - (instancetype)initWithInvocation:(NSInvocation*)invocation { GoldenTestManager* manager = - [[GoldenTestManager alloc] - initWithLaunchArg:@"--non-full-screen-flutter-view-platform-view"]; + [[GoldenTestManager alloc] initWithLaunchArg:@"--non-full-screen-flutter-view-platform-view"]; return [super initWithManager:manager invocation:invocation]; } @@ -299,8 +298,7 @@ @implementation PlatformViewWithOtherBackdropFilterTests - (instancetype)initWithInvocation:(NSInvocation*)invocation { GoldenTestManager* manager = - [[GoldenTestManager alloc] - initWithLaunchArg:@"--platform-view-with-other-backdrop-filter"]; + [[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-with-other-backdrop-filter"]; return [super initWithManager:manager invocation:invocation]; } From 805419593de232aff9cf14e136ab7e4648580fd0 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 10:45:39 -0700 Subject: [PATCH 12/27] bring back tests --- .../Source/FlutterPlatformViewsTest.mm | 5598 ++++++++--------- .../UnobstructedPlatformViewTests.m | 606 +- 2 files changed, 3102 insertions(+), 3102 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index cf16c72b8a388..63d42b82daa04 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -17,7 +17,7 @@ FLUTTER_ASSERT_NOT_ARC @class FlutterPlatformViewsTestMockPlatformView; static FlutterPlatformViewsTestMockPlatformView* gMockPlatformView = nil; -// const float kFloatCompareEpsilon = 0.001; +const float kFloatCompareEpsilon = 0.001; @interface FlutterPlatformViewsTestMockPlatformView : UIView @end @@ -191,2803 +191,2803 @@ - (void)testFlutterViewOnlyCreateOnceInOneFrame { flutterPlatformViewsController->Reset(); } -// - (void)testCanCreatePlatformViewWithoutFlutterView { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); -// } - -// - (void)testChildClippingViewHitTests { -// ChildClippingView* childClippingView = -// [[[ChildClippingView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; -// UIView* childView = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] -// autorelease]; [childClippingView addSubview:childView]; - -// XCTAssertFalse([childClippingView pointInside:CGPointMake(50, 50) withEvent:nil]); -// XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 100) withEvent:nil]); -// XCTAssertFalse([childClippingView pointInside:CGPointMake(100, 99) withEvent:nil]); -// XCTAssertFalse([childClippingView pointInside:CGPointMake(201, 200) withEvent:nil]); -// XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 201) withEvent:nil]); -// XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 200) withEvent:nil]); -// XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 299) withEvent:nil]); - -// XCTAssertTrue([childClippingView pointInside:CGPointMake(150, 150) withEvent:nil]); -// XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 100) withEvent:nil]); -// XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 100) withEvent:nil]); -// XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 199) withEvent:nil]); -// XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 199) withEvent:nil]); -// } - -// - (void)testApplyBackdropFilter { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// CGFloat screenScale = [UIScreen mainScreen].scale; -// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); -// stack.PushTransform(screenScaleMatrix); -// // Push a backdrop filter -// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); -// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), -// stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// // childClippingView has visual effect view with the correct configurations. -// NSUInteger numberOfExpectedVisualEffectView = 0; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:5]) { -// numberOfExpectedVisualEffectView++; -// } -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); -// } - -// - (void)testApplyBackdropFilterWithCorrectFrame { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// CGFloat screenScale = [UIScreen mainScreen].scale; -// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); -// stack.PushTransform(screenScaleMatrix); -// // Push a backdrop filter -// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); -// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 8, screenScale * 8)); - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(5, 10), -// stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// // childClippingView has visual effect view with the correct configurations. -// NSUInteger numberOfExpectedVisualEffectView = 0; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 5, 8) -// inputRadius:5]) { -// numberOfExpectedVisualEffectView++; -// } -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); -// } - -// - (void)testApplyMultipleBackdropFilters { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// CGFloat screenScale = [UIScreen mainScreen].scale; -// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); -// stack.PushTransform(screenScaleMatrix); -// // Push backdrop filters -// for (int i = 0; i < 50; i++) { -// auto filter = std::make_shared(i, 2, -// flutter::DlTileMode::kClamp); stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, -// screenScale * 10, screenScale * 10)); -// } - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(20, 20), -// stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// NSUInteger numberOfExpectedVisualEffectView = 0; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(numberOfExpectedVisualEffectView, 50u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)numberOfExpectedVisualEffectView]) { -// numberOfExpectedVisualEffectView++; -// } -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, (NSUInteger)numberOfExpectedVisualEffectView); -// } - -// - (void)testAddBackdropFilters { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// CGFloat screenScale = [UIScreen mainScreen].scale; -// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); -// stack.PushTransform(screenScaleMatrix); -// // Push a backdrop filter -// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); -// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), -// stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(originalVisualEffectViews.count, 1u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)5]) { -// [originalVisualEffectViews addObject:subview]; -// } -// } -// XCTAssertEqual(originalVisualEffectViews.count, 1u); - -// // -// // Simulate adding 1 backdrop filter (create a new mutators stack) -// // Create embedded view params -// flutter::MutatorsStack stack2; -// // Layer tree always pushes a screen scale factor to the stack -// stack2.PushTransform(screenScaleMatrix); -// // Push backdrop filters -// for (int i = 0; i < 2; i++) { -// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * -// 10)); -// } - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(newVisualEffectViews.count, 2u); - -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)5]) { -// [newVisualEffectViews addObject:subview]; -// } -// } -// XCTAssertEqual(newVisualEffectViews.count, 2u); -// for (NSUInteger i = 0; i < originalVisualEffectViews.count; i++) { -// UIView* originalView = originalVisualEffectViews[i]; -// UIView* newView = newVisualEffectViews[i]; -// // Compare reference. -// XCTAssertEqual(originalView, newView); -// id mockOrignalView = OCMPartialMock(originalView); -// OCMReject([mockOrignalView removeFromSuperview]); -// } -// } - -// - (void)testRemoveBackdropFilters { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// CGFloat screenScale = [UIScreen mainScreen].scale; -// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); -// stack.PushTransform(screenScaleMatrix); -// // Push backdrop filters -// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); -// for (int i = 0; i < 5; i++) { -// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// } - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), -// stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(originalVisualEffectViews.count, 5u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)5]) { -// [originalVisualEffectViews addObject:subview]; -// } -// } - -// // Simulate removing 1 backdrop filter (create a new mutators stack) -// // Create embedded view params -// flutter::MutatorsStack stack2; -// // Layer tree always pushes a screen scale factor to the stack -// stack2.PushTransform(screenScaleMatrix); -// // Push backdrop filters -// for (int i = 0; i < 4; i++) { -// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * -// 10)); -// } - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(newVisualEffectViews.count, 4u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)5]) { -// [newVisualEffectViews addObject:subview]; -// } -// } -// XCTAssertEqual(newVisualEffectViews.count, 4u); - -// for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { -// UIView* newView = newVisualEffectViews[i]; -// id mockNewView = OCMPartialMock(newView); -// UIView* originalView = originalVisualEffectViews[i]; -// // Compare reference. -// XCTAssertEqual(originalView, newView); -// OCMReject([mockNewView removeFromSuperview]); -// [mockNewView stopMocking]; -// } - -// // Simulate removing all backdrop filters (replace the mutators stack) -// // Update embedded view params, delete except screenScaleMatrix -// for (int i = 0; i < 5; i++) { -// stack2.Pop(); -// } -// // No backdrop filters in the stack, so no nothing to push - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// NSUInteger numberOfExpectedVisualEffectView = 0u; -// for (UIView* subview in childClippingView.subviews) { -// if ([subview isKindOfClass:[UIVisualEffectView class]]) { -// numberOfExpectedVisualEffectView++; -// } -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); -// } - -// - (void)testEditBackdropFilters { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// CGFloat screenScale = [UIScreen mainScreen].scale; -// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); -// stack.PushTransform(screenScaleMatrix); -// // Push backdrop filters -// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); -// for (int i = 0; i < 5; i++) { -// stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// } - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), -// stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(originalVisualEffectViews.count, 5u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)5]) { -// [originalVisualEffectViews addObject:subview]; -// } -// } - -// // Simulate editing 1 backdrop filter in the middle of the stack (create a new mutators stack) -// // Create embedded view params -// flutter::MutatorsStack stack2; -// // Layer tree always pushes a screen scale factor to the stack -// stack2.PushTransform(screenScaleMatrix); -// // Push backdrop filters -// for (int i = 0; i < 5; i++) { -// if (i == 3) { -// auto filter2 = -// std::make_shared(2, 5, flutter::DlTileMode::kClamp); - -// stack2.PushBackdropFilter(filter2, -// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// continue; -// } - -// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * -// 10)); -// } - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(newVisualEffectViews.count, 5u); -// CGFloat expectInputRadius = 5; -// if (newVisualEffectViews.count == 3) { -// expectInputRadius = 2; -// } -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)expectInputRadius]) { -// [newVisualEffectViews addObject:subview]; -// } -// } -// XCTAssertEqual(newVisualEffectViews.count, 5u); -// for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { -// UIView* newView = newVisualEffectViews[i]; -// id mockNewView = OCMPartialMock(newView); -// UIView* originalView = originalVisualEffectViews[i]; -// // Compare reference. -// XCTAssertEqual(originalView, newView); -// OCMReject([mockNewView removeFromSuperview]); -// [mockNewView stopMocking]; -// } -// [newVisualEffectViews removeAllObjects]; - -// // Simulate editing 1 backdrop filter in the beginning of the stack (replace the mutators -// stack) -// // Update embedded view params, delete except screenScaleMatrix -// for (int i = 0; i < 5; i++) { -// stack2.Pop(); -// } -// // Push backdrop filters -// for (int i = 0; i < 5; i++) { -// if (i == 0) { -// auto filter2 = -// std::make_shared(2, 5, flutter::DlTileMode::kClamp); -// stack2.PushBackdropFilter(filter2, -// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// continue; -// } - -// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * -// 10)); -// } - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(newVisualEffectViews.count, 5u); -// CGFloat expectInputRadius = 5; -// if (newVisualEffectViews.count == 0) { -// expectInputRadius = 2; -// } -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)expectInputRadius]) { -// [newVisualEffectViews addObject:subview]; -// } -// } -// for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { -// UIView* newView = newVisualEffectViews[i]; -// id mockNewView = OCMPartialMock(newView); -// UIView* originalView = originalVisualEffectViews[i]; -// // Compare reference. -// XCTAssertEqual(originalView, newView); -// OCMReject([mockNewView removeFromSuperview]); -// [mockNewView stopMocking]; -// } -// [newVisualEffectViews removeAllObjects]; - -// // Simulate editing 1 backdrop filter in the end of the stack (replace the mutators stack) -// // Update embedded view params, delete except screenScaleMatrix -// for (int i = 0; i < 5; i++) { -// stack2.Pop(); -// } -// // Push backdrop filters -// for (int i = 0; i < 5; i++) { -// if (i == 4) { -// auto filter2 = -// std::make_shared(2, 5, flutter::DlTileMode::kClamp); -// stack2.PushBackdropFilter(filter2, -// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// continue; -// } - -// stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * -// 10)); -// } - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(newVisualEffectViews.count, 5u); -// CGFloat expectInputRadius = 5; -// if (newVisualEffectViews.count == 4) { -// expectInputRadius = 2; -// } -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)expectInputRadius]) { -// [newVisualEffectViews addObject:subview]; -// } -// } -// XCTAssertEqual(newVisualEffectViews.count, 5u); - -// for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { -// UIView* newView = newVisualEffectViews[i]; -// id mockNewView = OCMPartialMock(newView); -// UIView* originalView = originalVisualEffectViews[i]; -// // Compare reference. -// XCTAssertEqual(originalView, newView); -// OCMReject([mockNewView removeFromSuperview]); -// [mockNewView stopMocking]; -// } -// [newVisualEffectViews removeAllObjects]; - -// // Simulate editing all backdrop filters in the stack (replace the mutators stack) -// // Update embedded view params, delete except screenScaleMatrix -// for (int i = 0; i < 5; i++) { -// stack2.Pop(); -// } -// // Push backdrop filters -// for (int i = 0; i < 5; i++) { -// auto filter2 = std::make_shared(i, 2, -// flutter::DlTileMode::kClamp); - -// stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * -// 10)); -// } - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(newVisualEffectViews.count, 5u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)newVisualEffectViews.count]) { -// [newVisualEffectViews addObject:subview]; -// } -// } -// XCTAssertEqual(newVisualEffectViews.count, 5u); - -// for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { -// UIView* newView = newVisualEffectViews[i]; -// id mockNewView = OCMPartialMock(newView); -// UIView* originalView = originalVisualEffectViews[i]; -// // Compare reference. -// XCTAssertEqual(originalView, newView); -// OCMReject([mockNewView removeFromSuperview]); -// [mockNewView stopMocking]; -// } -// [newVisualEffectViews removeAllObjects]; -// } - -// - (void)testApplyBackdropFilterNotDlBlurImageFilter { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// CGFloat screenScale = [UIScreen mainScreen].scale; -// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); -// stack.PushTransform(screenScaleMatrix); -// // Push a dilate backdrop filter -// auto dilateFilter = std::make_shared(5, 2); -// stack.PushBackdropFilter(dilateFilter, SkRect::MakeEmpty()); - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), -// stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; - -// [mockFlutterView addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// NSUInteger numberOfExpectedVisualEffectView = 0; -// for (UIView* subview in childClippingView.subviews) { -// if ([subview isKindOfClass:[UIVisualEffectView class]]) { -// numberOfExpectedVisualEffectView++; -// } -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); - -// // Simulate adding a non-DlBlurImageFilter in the middle of the stack (create a new mutators -// // stack) Create embedded view params -// flutter::MutatorsStack stack2; -// // Layer tree always pushes a screen scale factor to the stack -// stack2.PushTransform(screenScaleMatrix); -// // Push backdrop filters and dilate filter -// auto blurFilter = std::make_shared(5, 2, -// flutter::DlTileMode::kClamp); - -// for (int i = 0; i < 5; i++) { -// if (i == 2) { -// stack2.PushBackdropFilter(dilateFilter, -// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// continue; -// } - -// stack2.PushBackdropFilter(blurFilter, -// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// } - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// numberOfExpectedVisualEffectView = 0; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)5]) { -// numberOfExpectedVisualEffectView++; -// } -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); - -// // Simulate adding a non-DlBlurImageFilter to the beginning of the stack (replace the mutators -// // stack) Update embedded view params, delete except screenScaleMatrix -// for (int i = 0; i < 5; i++) { -// stack2.Pop(); -// } -// // Push backdrop filters and dilate filter -// for (int i = 0; i < 5; i++) { -// if (i == 0) { -// stack2.PushBackdropFilter(dilateFilter, -// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// continue; -// } - -// stack2.PushBackdropFilter(blurFilter, -// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// } - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// numberOfExpectedVisualEffectView = 0; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)5]) { -// numberOfExpectedVisualEffectView++; -// } -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); - -// // Simulate adding a non-DlBlurImageFilter to the end of the stack (replace the mutators stack) -// // Update embedded view params, delete except screenScaleMatrix -// for (int i = 0; i < 5; i++) { -// stack2.Pop(); -// } -// // Push backdrop filters and dilate filter -// for (int i = 0; i < 5; i++) { -// if (i == 4) { -// stack2.PushBackdropFilter(dilateFilter, -// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// continue; -// } - -// stack2.PushBackdropFilter(blurFilter, -// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// } - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// numberOfExpectedVisualEffectView = 0; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:(CGFloat)5]) { -// numberOfExpectedVisualEffectView++; -// } -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); - -// // Simulate adding only non-DlBlurImageFilter to the stack (replace the mutators stack) -// // Update embedded view params, delete except screenScaleMatrix -// for (int i = 0; i < 5; i++) { -// stack2.Pop(); -// } -// // Push dilate filters -// for (int i = 0; i < 5; i++) { -// stack2.PushBackdropFilter(dilateFilter, -// SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// } - -// embeddedViewParams = std::make_unique(screenScaleMatrix, -// SkSize::Make(10, 10), -// stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// numberOfExpectedVisualEffectView = 0; -// for (UIView* subview in childClippingView.subviews) { -// if ([subview isKindOfClass:[UIVisualEffectView class]]) { -// numberOfExpectedVisualEffectView++; -// } -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); -// } - -// - (void)testApplyBackdropFilterCorrectAPI { -// [PlatformViewFilter resetPreparation]; -// // The gaussianBlur filter is extracted from UIVisualEffectView. -// // Each test requires a new PlatformViewFilter -// // Valid UIVisualEffectView API -// UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] -// initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; -// PlatformViewFilter* platformViewFilter = -// [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) -// blurRadius:5 -// visualEffectView:visualEffectView]; -// XCTAssertNotNil(platformViewFilter); -// } - -// - (void)testApplyBackdropFilterAPIChangedInvalidUIVisualEffectView { -// [PlatformViewFilter resetPreparation]; -// UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] init]; -// PlatformViewFilter* platformViewFilter = -// [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) -// blurRadius:5 -// visualEffectView:visualEffectView]; -// XCTAssertNil(platformViewFilter); -// } - -// - (void)testApplyBackdropFilterAPIChangedNoGaussianBlurFilter { -// [PlatformViewFilter resetPreparation]; -// UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc] -// initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; -// NSArray* subviews = editedUIVisualEffectView.subviews; -// for (UIView* view in subviews) { -// if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { -// for (CIFilter* filter in view.layer.filters) { -// if ([[filter valueForKey:@"name"] isEqual:@"gaussianBlur"]) { -// [filter setValue:@"notGaussianBlur" forKey:@"name"]; -// break; -// } -// } -// break; -// } -// } -// PlatformViewFilter* platformViewFilter = -// [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) -// blurRadius:5 -// visualEffectView:editedUIVisualEffectView]; -// XCTAssertNil(platformViewFilter); -// } - -// - (void)testApplyBackdropFilterAPIChangedInvalidInputRadius { -// [PlatformViewFilter resetPreparation]; -// UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc] -// initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; -// NSArray* subviews = editedUIVisualEffectView.subviews; -// for (UIView* view in subviews) { -// if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { -// for (CIFilter* filter in view.layer.filters) { -// if ([[filter valueForKey:@"name"] isEqual:@"gaussianBlur"]) { -// [filter setValue:@"invalidInputRadius" forKey:@"inputRadius"]; -// break; -// } -// } -// break; -// } -// } - -// PlatformViewFilter* platformViewFilter = -// [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) -// blurRadius:5 -// visualEffectView:editedUIVisualEffectView]; -// XCTAssertNil(platformViewFilter); -// } - -// - (void)testBackdropFilterVisualEffectSubviewBackgroundColor { -// UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] -// initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; -// PlatformViewFilter* platformViewFilter = -// [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) -// blurRadius:5 -// visualEffectView:visualEffectView]; -// CGColorRef visualEffectSubviewBackgroundColor; -// for (UIView* view in [platformViewFilter backdropFilterView].subviews) { -// if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectSubview")]) { -// visualEffectSubviewBackgroundColor = view.layer.backgroundColor; -// } -// } -// XCTAssertTrue( -// CGColorEqualToColor(visualEffectSubviewBackgroundColor, UIColor.clearColor.CGColor)); -// } - -// - (void)testCompositePlatformView { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// SkMatrix screenScaleMatrix = -// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); -// stack.PushTransform(screenScaleMatrix); -// // Push a translate matrix -// SkMatrix translateMatrix = SkMatrix::Translate(100, 100); -// stack.PushTransform(translateMatrix); -// SkMatrix finalMatrix; -// finalMatrix.setConcat(screenScaleMatrix, translateMatrix); - -// auto embeddedViewParams = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds -// toView:mockFlutterView]; -// XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, -// 300))); -// } - -// - (void)testBackdropFilterCorrectlyPushedAndReset { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// CGFloat screenScale = [UIScreen mainScreen].scale; -// SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); -// stack.PushTransform(screenScaleMatrix); - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), -// stack); - -// flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->PushVisitedPlatformView(2); -// auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); -// flutterPlatformViewsController->PushFilterToVisitedPlatformViews( -// filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// // childClippingView has visual effect view with the correct configurations. -// NSUInteger numberOfExpectedVisualEffectView = 0; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); -// if ([self validateOneVisualEffectView:subview -// expectedFrame:CGRectMake(0, 0, 10, 10) -// inputRadius:5]) { -// numberOfExpectedVisualEffectView++; -// } -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); - -// // New frame, with no filter pushed. -// auto embeddedViewParams2 = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), -// stack); -// flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, -// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(2); -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// numberOfExpectedVisualEffectView = 0; -// for (UIView* subview in childClippingView.subviews) { -// if (![subview isKindOfClass:[UIVisualEffectView class]]) { -// continue; -// } -// numberOfExpectedVisualEffectView++; -// } -// XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); -// } - -// - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// SkMatrix screenScaleMatrix = -// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); -// stack.PushTransform(screenScaleMatrix); -// // Push a rotate matrix -// SkMatrix rotateMatrix; -// rotateMatrix.setRotate(10); -// stack.PushTransform(rotateMatrix); -// SkMatrix finalMatrix; -// finalMatrix.setConcat(screenScaleMatrix, rotateMatrix); - -// auto embeddedViewParams = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds -// toView:mockFlutterView]; -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; -// // The childclippingview's frame is set based on flow, but the platform view's frame is set -// based -// // on quartz. Although they should be the same, but we should tolerate small floating point -// // errors. -// XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - -// childClippingView.frame.origin.x), -// kFloatCompareEpsilon); -// XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - -// childClippingView.frame.origin.y), -// kFloatCompareEpsilon); -// XCTAssertLessThan( -// fabs(platformViewRectInFlutterView.size.width - childClippingView.frame.size.width), -// kFloatCompareEpsilon); -// XCTAssertLessThan( -// fabs(platformViewRectInFlutterView.size.height - childClippingView.frame.size.height), -// kFloatCompareEpsilon); -// } - -// - (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params. -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack. -// SkMatrix screenScaleMatrix = -// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); -// stack.PushTransform(screenScaleMatrix); -// SkMatrix translateMatrix = SkMatrix::Translate(5, 5); -// // The platform view's rect for this test will be (5, 5, 10, 10). -// stack.PushTransform(translateMatrix); -// // Push a clip rect, big enough to contain the entire platform view bound. -// SkRect rect = SkRect::MakeXYWH(0, 0, 25, 25); -// stack.PushClipRect(rect); -// // Push a clip rrect, big enough to contain the entire platform view bound without clipping it. -// // Make the origin (-1, -1) so that the top left rounded corner isn't clipping the -// PlatformView. SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25); SkRRect rrect = -// SkRRect::MakeRectXY(rect_for_rrect, 1, 1); stack.PushClipRRect(rrect); - -// auto embeddedViewParams = std::make_unique( -// SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// gMockPlatformView.backgroundColor = UIColor.redColor; -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; -// XCTAssertNil(childClippingView.maskView); -// } - -// - (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack. -// SkMatrix screenScaleMatrix = -// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); -// stack.PushTransform(screenScaleMatrix); -// SkMatrix translateMatrix = SkMatrix::Translate(5, 5); -// // The platform view's rect for this test will be (5, 5, 10, 10). -// stack.PushTransform(translateMatrix); - -// // Push a clip rrect, the rect of the rrect is the same as the PlatformView of the corner -// should. -// // clip the PlatformView. -// SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10); -// SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); -// stack.PushClipRRect(rrect); - -// auto embeddedViewParams = std::make_unique( -// SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// gMockPlatformView.backgroundColor = UIColor.redColor; -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// XCTAssertNotNil(childClippingView.maskView); -// } - -// - (void)testClipRect { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// SkMatrix screenScaleMatrix = -// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); -// stack.PushTransform(screenScaleMatrix); -// // Push a clip rect -// SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3); -// stack.PushClipRect(rect); - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), -// stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// gMockPlatformView.backgroundColor = UIColor.redColor; -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// for (int i = 0; i < 10; i++) { -// for (int j = 0; j < 10; j++) { -// CGPoint point = CGPointMake(i, j); -// int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; -// // Edges of the clipping might have a semi transparent pixel, we only check the pixels that -// // are fully inside the clipped area. -// CGRect insideClipping = CGRectMake(3, 3, 1, 1); -// if (CGRectContainsPoint(insideClipping, point)) { -// XCTAssertEqual(alpha, 255); -// } else { -// XCTAssertLessThan(alpha, 255); -// } -// } -// } -// } - -// - (void)testClipRRect { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// SkMatrix screenScaleMatrix = -// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); -// stack.PushTransform(screenScaleMatrix); -// // Push a clip rrect -// SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1); -// stack.PushClipRRect(rrect); - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), -// stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// gMockPlatformView.backgroundColor = UIColor.redColor; -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// for (int i = 0; i < 10; i++) { -// for (int j = 0; j < 10; j++) { -// CGPoint point = CGPointMake(i, j); -// int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; -// // Edges of the clipping might have a semi transparent pixel, we only check the pixels that -// // are fully inside the clipped area. -// CGRect insideClipping = CGRectMake(3, 3, 4, 4); -// if (CGRectContainsPoint(insideClipping, point)) { -// XCTAssertEqual(alpha, 255); -// } else { -// XCTAssertLessThan(alpha, 255); -// } -// } -// } -// } - -// - (void)testClipPath { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack; -// // Layer tree always pushes a screen scale factor to the stack -// SkMatrix screenScaleMatrix = -// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); -// stack.PushTransform(screenScaleMatrix); -// // Push a clip path -// SkPath path; -// path.addRoundRect(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1); -// stack.PushClipPath(path); - -// auto embeddedViewParams = -// std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), -// stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); -// flutterPlatformViewsController->CompositeEmbeddedView(2); -// gMockPlatformView.backgroundColor = UIColor.redColor; -// XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); -// ChildClippingView* childClippingView = -// (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView -// addSubview:childClippingView]; - -// [mockFlutterView setNeedsLayout]; -// [mockFlutterView layoutIfNeeded]; - -// for (int i = 0; i < 10; i++) { -// for (int j = 0; j < 10; j++) { -// CGPoint point = CGPointMake(i, j); -// int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; -// // Edges of the clipping might have a semi transparent pixel, we only check the pixels that -// // are fully inside the clipped area. -// CGRect insideClipping = CGRectMake(3, 3, 4, 4); -// if (CGRectContainsPoint(insideClipping, point)) { -// XCTAssertEqual(alpha, 255); -// } else { -// XCTAssertLessThan(alpha, 255); -// } -// } -// } -// } - -// - (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// // Find touch inteceptor view -// UIView* touchInteceptorView = gMockPlatformView; -// while (touchInteceptorView != nil && -// ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { -// touchInteceptorView = touchInteceptorView.superview; -// } -// XCTAssertNotNil(touchInteceptorView); - -// // Find ForwardGestureRecognizer -// UIGestureRecognizer* forwardGectureRecognizer = nil; -// for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { -// if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { -// forwardGectureRecognizer = gestureRecognizer; -// break; -// } -// } - -// // Before setting flutter view controller, events are not dispatched. -// NSSet* touches1 = [[[NSSet alloc] init] autorelease]; -// id event1 = OCMClassMock([UIEvent class]); -// id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); -// [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; -// OCMReject([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); - -// // Set flutter view controller allows events to be dispatched. -// NSSet* touches2 = [[[NSSet alloc] init] autorelease]; -// id event2 = OCMClassMock([UIEvent class]); -// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); -// [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2]; -// OCMVerify([mockFlutterViewContoller touchesBegan:touches2 withEvent:event2]); -// } - -// - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGesturesToBeHandled { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// // Find touch inteceptor view -// UIView* touchInteceptorView = gMockPlatformView; -// while (touchInteceptorView != nil && -// ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { -// touchInteceptorView = touchInteceptorView.superview; -// } -// XCTAssertNotNil(touchInteceptorView); - -// // Find ForwardGestureRecognizer -// UIGestureRecognizer* forwardGectureRecognizer = nil; -// for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { -// if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { -// forwardGectureRecognizer = gestureRecognizer; -// break; -// } -// } -// id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); -// { -// // ***** Sequence 1, finishing touch event with touchEnded ***** // -// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); - -// NSSet* touches1 = [[[NSSet alloc] init] autorelease]; -// id event1 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; -// OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); - -// flutterPlatformViewsController->SetFlutterViewController(nil); - -// // Allow the touch events to finish -// NSSet* touches2 = [[[NSSet alloc] init] autorelease]; -// id event2 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2]; -// OCMVerify([mockFlutterViewContoller touchesMoved:touches2 withEvent:event2]); - -// NSSet* touches3 = [[[NSSet alloc] init] autorelease]; -// id event3 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesEnded:touches3 withEvent:event3]; -// OCMVerify([mockFlutterViewContoller touchesEnded:touches3 withEvent:event3]); - -// // Now the 2nd touch sequence should not be allowed. -// NSSet* touches4 = [[[NSSet alloc] init] autorelease]; -// id event4 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4]; -// OCMReject([mockFlutterViewContoller touchesBegan:touches4 withEvent:event4]); - -// NSSet* touches5 = [[[NSSet alloc] init] autorelease]; -// id event5 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; -// OCMReject([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); -// } - -// { -// // ***** Sequence 2, finishing touch event with touchCancelled ***** // -// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); - -// NSSet* touches1 = [[[NSSet alloc] init] autorelease]; -// id event1 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; -// OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); - -// flutterPlatformViewsController->SetFlutterViewController(nil); - -// // Allow the touch events to finish -// NSSet* touches2 = [[[NSSet alloc] init] autorelease]; -// id event2 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2]; -// OCMVerify([mockFlutterViewContoller touchesMoved:touches2 withEvent:event2]); - -// NSSet* touches3 = [[[NSSet alloc] init] autorelease]; -// id event3 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesCancelled:touches3 withEvent:event3]; -// OCMVerify([mockFlutterViewContoller forceTouchesCancelled:touches3]); - -// // Now the 2nd touch sequence should not be allowed. -// NSSet* touches4 = [[[NSSet alloc] init] autorelease]; -// id event4 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4]; -// OCMReject([mockFlutterViewContoller touchesBegan:touches4 withEvent:event4]); - -// NSSet* touches5 = [[[NSSet alloc] init] autorelease]; -// id event5 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; -// OCMReject([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); -// } - -// flutterPlatformViewsController->Reset(); -// } - -// - (void) -// testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence -// { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// // Find touch inteceptor view -// UIView* touchInteceptorView = gMockPlatformView; -// while (touchInteceptorView != nil && -// ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { -// touchInteceptorView = touchInteceptorView.superview; -// } -// XCTAssertNotNil(touchInteceptorView); - -// // Find ForwardGestureRecognizer -// UIGestureRecognizer* forwardGectureRecognizer = nil; -// for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { -// if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { -// forwardGectureRecognizer = gestureRecognizer; -// break; -// } -// } -// id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); - -// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); - -// // The touches in this sequence requires 1 touch object, we always create the NSSet with one -// item. NSSet* touches1 = [NSSet setWithObject:@1]; id event1 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; -// OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); - -// UIViewController* mockFlutterViewContoller2 = OCMClassMock([UIViewController class]); -// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller2); - -// // Touch events should still send to the old FlutterViewController if FlutterViewController -// // is updated in between. -// NSSet* touches2 = [NSSet setWithObject:@1]; -// id event2 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2]; -// OCMVerify([mockFlutterViewContoller touchesBegan:touches2 withEvent:event2]); -// OCMReject([mockFlutterViewContoller2 touchesBegan:touches2 withEvent:event2]); - -// NSSet* touches3 = [NSSet setWithObject:@1]; -// id event3 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesMoved:touches3 withEvent:event3]; -// OCMVerify([mockFlutterViewContoller touchesMoved:touches3 withEvent:event3]); -// OCMReject([mockFlutterViewContoller2 touchesMoved:touches3 withEvent:event3]); - -// NSSet* touches4 = [NSSet setWithObject:@1]; -// id event4 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesEnded:touches4 withEvent:event4]; -// OCMVerify([mockFlutterViewContoller touchesEnded:touches4 withEvent:event4]); -// OCMReject([mockFlutterViewContoller2 touchesEnded:touches4 withEvent:event4]); - -// NSSet* touches5 = [NSSet setWithObject:@1]; -// id event5 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; -// OCMVerify([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); -// OCMReject([mockFlutterViewContoller2 touchesEnded:touches5 withEvent:event5]); - -// // Now the 2nd touch sequence should go to the new FlutterViewController - -// NSSet* touches6 = [NSSet setWithObject:@1]; -// id event6 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesBegan:touches6 withEvent:event6]; -// OCMVerify([mockFlutterViewContoller2 touchesBegan:touches6 withEvent:event6]); -// OCMReject([mockFlutterViewContoller touchesBegan:touches6 withEvent:event6]); - -// // Allow the touch events to finish -// NSSet* touches7 = [NSSet setWithObject:@1]; -// id event7 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesMoved:touches7 withEvent:event7]; -// OCMVerify([mockFlutterViewContoller2 touchesMoved:touches7 withEvent:event7]); -// OCMReject([mockFlutterViewContoller touchesMoved:touches7 withEvent:event7]); - -// NSSet* touches8 = [NSSet setWithObject:@1]; -// id event8 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesEnded:touches8 withEvent:event8]; -// OCMVerify([mockFlutterViewContoller2 touchesEnded:touches8 withEvent:event8]); -// OCMReject([mockFlutterViewContoller touchesEnded:touches8 withEvent:event8]); - -// flutterPlatformViewsController->Reset(); -// } - -// - (void)testFlutterPlatformViewTouchesCancelledEventAreForcedToBeCancelled { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// // Find touch inteceptor view -// UIView* touchInteceptorView = gMockPlatformView; -// while (touchInteceptorView != nil && -// ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { -// touchInteceptorView = touchInteceptorView.superview; -// } -// XCTAssertNotNil(touchInteceptorView); - -// // Find ForwardGestureRecognizer -// UIGestureRecognizer* forwardGectureRecognizer = nil; -// for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { -// if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { -// forwardGectureRecognizer = gestureRecognizer; -// break; -// } -// } -// id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); - -// flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); - -// NSSet* touches1 = [NSSet setWithObject:@1]; -// id event1 = OCMClassMock([UIEvent class]); -// [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; - -// [forwardGectureRecognizer touchesCancelled:touches1 withEvent:event1]; -// OCMVerify([mockFlutterViewContoller forceTouchesCancelled:touches1]); - -// flutterPlatformViewsController->Reset(); -// } - -// - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashing { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); - -// // Create embedded view params -// flutter::MutatorsStack stack; -// SkMatrix finalMatrix; - -// auto embeddedViewParams_1 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, -// std::move(embeddedViewParams_1)); flutterPlatformViewsController->CompositeEmbeddedView(2); -// flutter::SurfaceFrame::FramebufferInfo framebuffer_info; -// auto mock_surface = std::make_unique( -// nullptr, framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return false; -// }, -// /*frame_size=*/SkISize::Make(800, 600)); -// XCTAssertFalse( -// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - -// auto embeddedViewParams_2 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, -// std::move(embeddedViewParams_2)); flutterPlatformViewsController->CompositeEmbeddedView(2); -// auto mock_surface_submit_true = std::make_unique( -// nullptr, framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, -// /*frame_size=*/SkISize::Make(800, 600)); -// XCTAssertTrue(flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, -// std::move(mock_surface_submit_true))); -// } - -// - (void) -// testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView -// { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// // autorelease pool to trigger an autorelease for all the root_views_ and touch_interceptors_. -// @autoreleasepool { -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// flutter::MutatorsStack stack; -// SkMatrix finalMatrix; -// auto embeddedViewParams = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), -// stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, -// std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); -// // Not calling |flutterPlatformViewsController::SubmitFrame| so that the platform views are -// not -// // added to flutter_view_. - -// XCTAssertNotNil(gMockPlatformView); -// flutterPlatformViewsController->Reset(); -// } -// XCTAssertNil(gMockPlatformView); -// } - -// - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; - -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// // First frame, |EmbeddedViewCount| is not empty after composite. -// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); -// flutter::MutatorsStack stack; -// SkMatrix finalMatrix; -// auto embeddedViewParams1 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, -// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); -// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); - -// // Second frame, |EmbeddedViewCount| should be empty at the start -// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); -// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 0UL); - -// auto embeddedViewParams2 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, -// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(0); -// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); -// } - -// - (void) -// testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy -// { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], -// result); -// UIView* view1 = gMockPlatformView; - -// // This overwrites `gMockPlatformView` to another view. -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], -// result); -// UIView* view2 = gMockPlatformView; - -// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); -// flutter::MutatorsStack stack; -// SkMatrix finalMatrix; -// auto embeddedViewParams1 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, -// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); auto -// embeddedViewParams2 = -// std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, -// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); - -// // SKSurface is required if the root FlutterView is present. -// const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); -// sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); -// flutter::SurfaceFrame::FramebufferInfo framebuffer_info; -// auto mock_surface = std::make_unique( -// std::move(mock_sk_surface), framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, -// /*frame_size=*/SkISize::Make(800, 600)); - -// XCTAssertTrue( -// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); -// // platform view is wrapped by touch interceptor, which itself is wrapped by clipping view. -// UIView* clippingView1 = view1.superview.superview; -// UIView* clippingView2 = view2.superview.superview; -// UIView* flutterView = clippingView1.superview; -// XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < -// [flutterView.subviews indexOfObject:clippingView2], -// @"The first clipping view should be added before the second clipping view."); - -// // Need to recreate these params since they are `std::move`ed. -// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); -// // Process the second frame in the opposite order. -// embeddedViewParams2 = -// std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, -// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); -// embeddedViewParams1 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, -// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); - -// mock_sk_surface = SkSurface::MakeRaster(image_info); -// mock_surface = std::make_unique( -// std::move(mock_sk_surface), framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, -// /*frame_size=*/SkISize::Make(800, 600)); -// XCTAssertTrue( -// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); -// XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] > -// [flutterView.subviews indexOfObject:clippingView2], -// @"The first clipping view should be added after the second clipping view."); -// } - -// - (void) -// testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy -// { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], -// result); -// UIView* view1 = gMockPlatformView; - -// // This overwrites `gMockPlatformView` to another view. -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], -// result); -// UIView* view2 = gMockPlatformView; - -// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); -// flutter::MutatorsStack stack; -// SkMatrix finalMatrix; -// auto embeddedViewParams1 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, -// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); auto -// embeddedViewParams2 = -// std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, -// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); - -// // SKSurface is required if the root FlutterView is present. -// const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); -// sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); -// flutter::SurfaceFrame::FramebufferInfo framebuffer_info; -// auto mock_surface = std::make_unique( -// std::move(mock_sk_surface), framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, -// /*frame_size=*/SkISize::Make(800, 600)); - -// XCTAssertTrue( -// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); -// // platform view is wrapped by touch interceptor, which itself is wrapped by clipping view. -// UIView* clippingView1 = view1.superview.superview; -// UIView* clippingView2 = view2.superview.superview; -// UIView* flutterView = clippingView1.superview; -// XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < -// [flutterView.subviews indexOfObject:clippingView2], -// @"The first clipping view should be added before the second clipping view."); - -// // Need to recreate these params since they are `std::move`ed. -// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); -// // Process the second frame in the same order. -// embeddedViewParams1 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, -// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); -// embeddedViewParams2 = -// std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, -// std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); - -// mock_sk_surface = SkSurface::MakeRaster(image_info); -// mock_surface = std::make_unique( -// std::move(mock_sk_surface), framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, -// /*frame_size=*/SkISize::Make(800, 600)); -// XCTAssertTrue( -// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); -// XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < -// [flutterView.subviews indexOfObject:clippingView2], -// @"The first clipping view should be added before the second clipping view."); -// } - -// - (void)testThreadMergeAtEndFrame { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner_platform = CreateNewThread("FlutterPlatformViewsTest1"); -// auto thread_task_runner_other = CreateNewThread("FlutterPlatformViewsTest2"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner_platform, -// /*raster=*/thread_task_runner_other, -// /*ui=*/thread_task_runner_other, -// /*io=*/thread_task_runner_other); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// XCTestExpectation* waitForPlatformView = -// [self expectationWithDescription:@"wait for platform view to be created"]; -// FlutterResult result = ^(id result) { -// [waitForPlatformView fulfill]; -// }; - -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); -// [self waitForExpectations:@[ waitForPlatformView ] timeout:30]; -// XCTAssertNotNil(gMockPlatformView); - -// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); -// SkMatrix finalMatrix; -// flutter::MutatorsStack stack; -// auto embeddedViewParams = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); - -// fml::RefPtr raster_thread_merger = -// fml::MakeRefCounted(thread_task_runner_platform->GetTaskQueueId(), -// thread_task_runner_other->GetTaskQueueId()); -// XCTAssertEqual(flutterPlatformViewsController->PostPrerollAction(raster_thread_merger), -// flutter::PostPrerollResult::kSkipAndRetryFrame); -// XCTAssertFalse(raster_thread_merger->IsMerged()); - -// flutterPlatformViewsController->EndFrame(true, raster_thread_merger); -// XCTAssertTrue(raster_thread_merger->IsMerged()); - -// // Unmerge threads before the end of the test -// // TaskRunners are required to be unmerged before destruction. -// while (raster_thread_merger->DecrementLease() != fml::RasterThreadStatus::kUnmergedNow) -// ; -// } - -// - (int)alphaOfPoint:(CGPoint)point onView:(UIView*)view { -// unsigned char pixel[4] = {0}; - -// CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - -// // Draw the pixel on `point` in the context. -// CGContextRef context = CGBitmapContextCreate( -// pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast); -// CGContextTranslateCTM(context, -point.x, -point.y); -// [view.layer renderInContext:context]; - -// CGContextRelease(context); -// CGColorSpaceRelease(colorSpace); -// // Get the alpha from the pixel that we just rendered. -// return pixel[3]; -// } - -// - (void)testHasFirstResponderInViewHierarchySubtree_viewItselfBecomesFirstResponder { -// // For view to become the first responder, it must be a descendant of a UIWindow -// UIWindow* window = [[UIWindow alloc] init]; -// UITextField* textField = [[UITextField alloc] init]; -// [window addSubview:textField]; - -// [textField becomeFirstResponder]; -// XCTAssertTrue(textField.isFirstResponder); -// XCTAssertTrue(textField.flt_hasFirstResponderInViewHierarchySubtree); -// [textField resignFirstResponder]; -// XCTAssertFalse(textField.isFirstResponder); -// XCTAssertFalse(textField.flt_hasFirstResponderInViewHierarchySubtree); -// } - -// - (void)testHasFirstResponderInViewHierarchySubtree_descendantViewBecomesFirstResponder { -// // For view to become the first responder, it must be a descendant of a UIWindow -// UIWindow* window = [[UIWindow alloc] init]; -// UIView* view = [[UIView alloc] init]; -// UIView* childView = [[UIView alloc] init]; -// UITextField* textField = [[UITextField alloc] init]; -// [window addSubview:view]; -// [view addSubview:childView]; -// [childView addSubview:textField]; - -// [textField becomeFirstResponder]; -// XCTAssertTrue(textField.isFirstResponder); -// XCTAssertTrue(view.flt_hasFirstResponderInViewHierarchySubtree); -// [textField resignFirstResponder]; -// XCTAssertFalse(textField.isFirstResponder); -// XCTAssertFalse(view.flt_hasFirstResponderInViewHierarchySubtree); -// } - -// - (void)testFlutterClippingMaskViewPoolReuseViewsAfterRecycle { -// FlutterClippingMaskViewPool* pool = -// [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; -// FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero]; -// FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero]; -// [pool recycleMaskViews]; -// CGRect newRect = CGRectMake(0, 0, 10, 10); -// FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:newRect]; -// FlutterClippingMaskView* view4 = [pool getMaskViewWithFrame:newRect]; -// XCTAssertEqual(view1, view3); -// XCTAssertEqual(view2, view4); -// XCTAssertTrue(CGRectEqualToRect(view3.frame, newRect)); -// XCTAssertTrue(CGRectEqualToRect(view4.frame, newRect)); -// } - -// - (void)testFlutterClippingMaskViewPoolAllocsNewMaskViewsAfterReachingCapacity { -// FlutterClippingMaskViewPool* pool = -// [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; -// FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero]; -// FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero]; -// FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:CGRectZero]; -// XCTAssertNotEqual(view1, view3); -// XCTAssertNotEqual(view2, view3); -// } - -// - (void)testMaskViewsReleasedWhenPoolIsReleased { -// UIView* retainedView; -// @autoreleasepool { -// FlutterClippingMaskViewPool* pool = -// [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; -// FlutterClippingMaskView* view = [pool getMaskViewWithFrame:CGRectZero]; -// retainedView = [view retain]; -// XCTAssertGreaterThan(retainedView.retainCount, 1u); -// } -// // The only retain left is our manual retain called inside the autorelease pool, meaning the -// // maskViews are dealloc'd. -// XCTAssertEqual(retainedView.retainCount, 1u); -// } - -// - (void)testClipMaskViewIsReused { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// XCTAssertNotNil(gMockPlatformView); -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); -// // Create embedded view params -// flutter::MutatorsStack stack1; -// // Layer tree always pushes a screen scale factor to the stack -// SkMatrix screenScaleMatrix = -// SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); -// stack1.PushTransform(screenScaleMatrix); -// // Push a clip rect -// SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3); -// stack1.PushClipRect(rect); - -// auto embeddedViewParams1 = std::make_unique( -// screenScaleMatrix, SkSize::Make(10, 10), stack1); - -// flutter::MutatorsStack stack2; -// auto embeddedViewParams2 = std::make_unique( -// screenScaleMatrix, SkSize::Make(10, 10), stack2); - -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, -// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); -// UIView* childClippingView1 = gMockPlatformView.superview.superview; -// UIView* maskView1 = childClippingView1.maskView; -// XCTAssertNotNil(maskView1); - -// // Composite a new frame. -// auto embeddedViewParams3 = std::make_unique( -// screenScaleMatrix, SkSize::Make(10, 10), stack2); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, -// std::move(embeddedViewParams3)); flutterPlatformViewsController->CompositeEmbeddedView(1); -// childClippingView1 = gMockPlatformView.superview.superview; - -// // This overrides gMockPlatformView to point to the newly created platform view. -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// auto embeddedViewParams4 = std::make_unique( -// screenScaleMatrix, SkSize::Make(10, 10), stack1); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, -// std::move(embeddedViewParams4)); flutterPlatformViewsController->CompositeEmbeddedView(2); -// UIView* childClippingView2 = gMockPlatformView.superview.superview; - -// UIView* maskView2 = childClippingView2.maskView; -// XCTAssertEqual(maskView1, maskView2); -// XCTAssertNotNil(childClippingView2.maskView); -// XCTAssertNil(childClippingView1.maskView); -// } - -// // Return true if a correct visual effect view is found. It also implies all the validation in -// this -// // method passes. -// // -// // There are two fail states for this method. 1. One of the XCTAssert method failed; or 2. No -// // correct visual effect view found. -// - (BOOL)validateOneVisualEffectView:(UIView*)visualEffectView -// expectedFrame:(CGRect)frame -// inputRadius:(CGFloat)inputRadius { -// XCTAssertTrue(CGRectEqualToRect(visualEffectView.frame, frame)); -// for (UIView* view in visualEffectView.subviews) { -// if (![view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { -// continue; -// } -// XCTAssertEqual(view.layer.filters.count, 1u); -// NSObject* filter = view.layer.filters.firstObject; - -// XCTAssertEqualObjects([filter valueForKey:@"name"], @"gaussianBlur"); - -// NSObject* inputRadiusInFilter = [filter valueForKey:@"inputRadius"]; -// XCTAssertTrue([inputRadiusInFilter isKindOfClass:[NSNumber class]] && -// flutter::BlurRadiusEqualToBlurRadius(((NSNumber*)inputRadiusInFilter).floatValue, -// inputRadius)); -// return YES; -// } -// return NO; -// } - -// - (void)testDisposingViewInCompositionOrderDoNotCrash { -// flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; -// auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); -// flutter::TaskRunners runners(/*label=*/self.name.UTF8String, -// /*platform=*/thread_task_runner, -// /*raster=*/thread_task_runner, -// /*ui=*/thread_task_runner, -// /*io=*/thread_task_runner); -// auto flutterPlatformViewsController = -// std::make_shared(); auto platform_view = -// std::make_unique( -// /*delegate=*/mock_delegate, -// /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, -// /*platform_views_controller=*/flutterPlatformViewsController, -// /*task_runners=*/runners); - -// UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] -// autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); - -// FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = -// [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; -// flutterPlatformViewsController->RegisterViewFactory( -// factory, @"MockFlutterPlatformView", -// FlutterPlatformViewGestureRecognizersBlockingPolicyEager); -// FlutterResult result = ^(id result) { -// }; - -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], -// result); -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall -// methodCallWithMethodName:@"create" -// arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], -// result); - -// { -// // **** First frame, view id 0, 1 in the composition_order_, disposing view 0 is called. **** -// // -// // No view should be disposed, or removed from the composition order. -// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); -// flutter::MutatorsStack stack; -// SkMatrix finalMatrix; -// auto embeddedViewParams0 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), -// stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, -// std::move(embeddedViewParams0)); flutterPlatformViewsController->CompositeEmbeddedView(0); - -// auto embeddedViewParams1 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), -// stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, -// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); -// XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); - -// XCTestExpectation* expectation = [self expectationWithDescription:@"dispose call ended."]; -// FlutterResult disposeResult = ^(id result) { -// [expectation fulfill]; -// }; - -// flutterPlatformViewsController->OnMethodCall( -// [FlutterMethodCall methodCallWithMethodName:@"dispose" arguments:@0], disposeResult); -// [self waitForExpectationsWithTimeout:30 handler:nil]; - -// const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); -// sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); -// flutter::SurfaceFrame::FramebufferInfo framebuffer_info; -// auto mock_surface = std::make_unique( -// std::move(mock_sk_surface), framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; -// }, -// /*frame_size=*/SkISize::Make(800, 600)); -// XCTAssertTrue( -// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - -// // Disposing won't remove embedded views until the view is removed from the -// composition_order_ XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); -// XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(0)); -// XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); -// } - -// { -// // **** Second frame, view id 1 in the composition_order_, no disposing view is called, **** -// // -// // View 0 is removed from the composition order in this frame, hence also disposed. -// flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); -// flutter::MutatorsStack stack; -// SkMatrix finalMatrix; -// auto embeddedViewParams1 = -// std::make_unique(finalMatrix, SkSize::Make(300, 300), -// stack); -// flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, -// std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); - -// const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); -// sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); -// flutter::SurfaceFrame::FramebufferInfo framebuffer_info; -// auto mock_surface = std::make_unique( -// std::move(mock_sk_surface), framebuffer_info, -// [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; -// }, -// /*frame_size=*/SkISize::Make(800, 600)); -// XCTAssertTrue( -// flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - -// // Disposing won't remove embedded views until the view is removed from the -// composition_order_ XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); -// XCTAssertNil(flutterPlatformViewsController->GetPlatformViewByID(0)); -// XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); -// } -// } +- (void)testCanCreatePlatformViewWithoutFlutterView { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); +} + +- (void)testChildClippingViewHitTests { + ChildClippingView* childClippingView = + [[[ChildClippingView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; + UIView* childView = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] + autorelease]; [childClippingView addSubview:childView]; + + XCTAssertFalse([childClippingView pointInside:CGPointMake(50, 50) withEvent:nil]); + XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 100) withEvent:nil]); + XCTAssertFalse([childClippingView pointInside:CGPointMake(100, 99) withEvent:nil]); + XCTAssertFalse([childClippingView pointInside:CGPointMake(201, 200) withEvent:nil]); + XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 201) withEvent:nil]); + XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 200) withEvent:nil]); + XCTAssertFalse([childClippingView pointInside:CGPointMake(200, 299) withEvent:nil]); + + XCTAssertTrue([childClippingView pointInside:CGPointMake(150, 150) withEvent:nil]); + XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 100) withEvent:nil]); + XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 100) withEvent:nil]); + XCTAssertTrue([childClippingView pointInside:CGPointMake(100, 199) withEvent:nil]); + XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 199) withEvent:nil]); +} + +- (void)testApplyBackdropFilter { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + CGFloat screenScale = [UIScreen mainScreen].scale; + SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); + stack.PushTransform(screenScaleMatrix); + // Push a backdrop filter + auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); + stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), + stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + // childClippingView has visual effect view with the correct configurations. + NSUInteger numberOfExpectedVisualEffectView = 0; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:5]) { + numberOfExpectedVisualEffectView++; + } + } + XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); +} + +- (void)testApplyBackdropFilterWithCorrectFrame { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + CGFloat screenScale = [UIScreen mainScreen].scale; + SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); + stack.PushTransform(screenScaleMatrix); + // Push a backdrop filter + auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); + stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 8, screenScale * 8)); + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(5, 10), + stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + // childClippingView has visual effect view with the correct configurations. + NSUInteger numberOfExpectedVisualEffectView = 0; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 5, 8) + inputRadius:5]) { + numberOfExpectedVisualEffectView++; + } + } + XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); +} + +- (void)testApplyMultipleBackdropFilters { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + CGFloat screenScale = [UIScreen mainScreen].scale; + SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); + stack.PushTransform(screenScaleMatrix); + // Push backdrop filters + for (int i = 0; i < 50; i++) { + auto filter = std::make_shared(i, 2, + flutter::DlTileMode::kClamp); stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, + screenScale * 10, screenScale * 10)); + } + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(20, 20), + stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + NSUInteger numberOfExpectedVisualEffectView = 0; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(numberOfExpectedVisualEffectView, 50u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)numberOfExpectedVisualEffectView]) { + numberOfExpectedVisualEffectView++; + } + } + XCTAssertEqual(numberOfExpectedVisualEffectView, (NSUInteger)numberOfExpectedVisualEffectView); +} + +- (void)testAddBackdropFilters { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + CGFloat screenScale = [UIScreen mainScreen].scale; + SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); + stack.PushTransform(screenScaleMatrix); + // Push a backdrop filter + auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); + stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), + stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(originalVisualEffectViews.count, 1u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)5]) { + [originalVisualEffectViews addObject:subview]; + } + } + XCTAssertEqual(originalVisualEffectViews.count, 1u); + + // + // Simulate adding 1 backdrop filter (create a new mutators stack) + // Create embedded view params + flutter::MutatorsStack stack2; + // Layer tree always pushes a screen scale factor to the stack + stack2.PushTransform(screenScaleMatrix); + // Push backdrop filters + for (int i = 0; i < 2; i++) { + stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * + 10)); + } + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(newVisualEffectViews.count, 2u); + + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)5]) { + [newVisualEffectViews addObject:subview]; + } + } + XCTAssertEqual(newVisualEffectViews.count, 2u); + for (NSUInteger i = 0; i < originalVisualEffectViews.count; i++) { + UIView* originalView = originalVisualEffectViews[i]; + UIView* newView = newVisualEffectViews[i]; + // Compare reference. + XCTAssertEqual(originalView, newView); + id mockOrignalView = OCMPartialMock(originalView); + OCMReject([mockOrignalView removeFromSuperview]); + } +} + +- (void)testRemoveBackdropFilters { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + CGFloat screenScale = [UIScreen mainScreen].scale; + SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); + stack.PushTransform(screenScaleMatrix); + // Push backdrop filters + auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); + for (int i = 0; i < 5; i++) { + stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + } + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), + stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(originalVisualEffectViews.count, 5u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)5]) { + [originalVisualEffectViews addObject:subview]; + } + } + + // Simulate removing 1 backdrop filter (create a new mutators stack) + // Create embedded view params + flutter::MutatorsStack stack2; + // Layer tree always pushes a screen scale factor to the stack + stack2.PushTransform(screenScaleMatrix); + // Push backdrop filters + for (int i = 0; i < 4; i++) { + stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * + 10)); + } + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(newVisualEffectViews.count, 4u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)5]) { + [newVisualEffectViews addObject:subview]; + } + } + XCTAssertEqual(newVisualEffectViews.count, 4u); + + for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { + UIView* newView = newVisualEffectViews[i]; + id mockNewView = OCMPartialMock(newView); + UIView* originalView = originalVisualEffectViews[i]; + // Compare reference. + XCTAssertEqual(originalView, newView); + OCMReject([mockNewView removeFromSuperview]); + [mockNewView stopMocking]; + } + + // Simulate removing all backdrop filters (replace the mutators stack) + // Update embedded view params, delete except screenScaleMatrix + for (int i = 0; i < 5; i++) { + stack2.Pop(); + } + // No backdrop filters in the stack, so no nothing to push + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + NSUInteger numberOfExpectedVisualEffectView = 0u; + for (UIView* subview in childClippingView.subviews) { + if ([subview isKindOfClass:[UIVisualEffectView class]]) { + numberOfExpectedVisualEffectView++; + } + } + XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); +} + +- (void)testEditBackdropFilters { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + CGFloat screenScale = [UIScreen mainScreen].scale; + SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); + stack.PushTransform(screenScaleMatrix); + // Push backdrop filters + auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); + for (int i = 0; i < 5; i++) { + stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + } + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), + stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + NSMutableArray* originalVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(originalVisualEffectViews.count, 5u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)5]) { + [originalVisualEffectViews addObject:subview]; + } + } + + // Simulate editing 1 backdrop filter in the middle of the stack (create a new mutators stack) + // Create embedded view params + flutter::MutatorsStack stack2; + // Layer tree always pushes a screen scale factor to the stack + stack2.PushTransform(screenScaleMatrix); + // Push backdrop filters + for (int i = 0; i < 5; i++) { + if (i == 3) { + auto filter2 = + std::make_shared(2, 5, flutter::DlTileMode::kClamp); + + stack2.PushBackdropFilter(filter2, + SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + continue; + } + + stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * + 10)); + } + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + NSMutableArray* newVisualEffectViews = [[[NSMutableArray alloc] init] autorelease]; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(newVisualEffectViews.count, 5u); + CGFloat expectInputRadius = 5; + if (newVisualEffectViews.count == 3) { + expectInputRadius = 2; + } + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)expectInputRadius]) { + [newVisualEffectViews addObject:subview]; + } + } + XCTAssertEqual(newVisualEffectViews.count, 5u); + for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { + UIView* newView = newVisualEffectViews[i]; + id mockNewView = OCMPartialMock(newView); + UIView* originalView = originalVisualEffectViews[i]; + // Compare reference. + XCTAssertEqual(originalView, newView); + OCMReject([mockNewView removeFromSuperview]); + [mockNewView stopMocking]; + } + [newVisualEffectViews removeAllObjects]; + + // Simulate editing 1 backdrop filter in the beginning of the stack (replace the mutators + stack) + // Update embedded view params, delete except screenScaleMatrix + for (int i = 0; i < 5; i++) { + stack2.Pop(); + } + // Push backdrop filters + for (int i = 0; i < 5; i++) { + if (i == 0) { + auto filter2 = + std::make_shared(2, 5, flutter::DlTileMode::kClamp); + stack2.PushBackdropFilter(filter2, + SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + continue; + } + + stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * + 10)); + } + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(newVisualEffectViews.count, 5u); + CGFloat expectInputRadius = 5; + if (newVisualEffectViews.count == 0) { + expectInputRadius = 2; + } + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)expectInputRadius]) { + [newVisualEffectViews addObject:subview]; + } + } + for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { + UIView* newView = newVisualEffectViews[i]; + id mockNewView = OCMPartialMock(newView); + UIView* originalView = originalVisualEffectViews[i]; + // Compare reference. + XCTAssertEqual(originalView, newView); + OCMReject([mockNewView removeFromSuperview]); + [mockNewView stopMocking]; + } + [newVisualEffectViews removeAllObjects]; + + // Simulate editing 1 backdrop filter in the end of the stack (replace the mutators stack) + // Update embedded view params, delete except screenScaleMatrix + for (int i = 0; i < 5; i++) { + stack2.Pop(); + } + // Push backdrop filters + for (int i = 0; i < 5; i++) { + if (i == 4) { + auto filter2 = + std::make_shared(2, 5, flutter::DlTileMode::kClamp); + stack2.PushBackdropFilter(filter2, + SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + continue; + } + + stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * + 10)); + } + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(newVisualEffectViews.count, 5u); + CGFloat expectInputRadius = 5; + if (newVisualEffectViews.count == 4) { + expectInputRadius = 2; + } + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)expectInputRadius]) { + [newVisualEffectViews addObject:subview]; + } + } + XCTAssertEqual(newVisualEffectViews.count, 5u); + + for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { + UIView* newView = newVisualEffectViews[i]; + id mockNewView = OCMPartialMock(newView); + UIView* originalView = originalVisualEffectViews[i]; + // Compare reference. + XCTAssertEqual(originalView, newView); + OCMReject([mockNewView removeFromSuperview]); + [mockNewView stopMocking]; + } + [newVisualEffectViews removeAllObjects]; + + // Simulate editing all backdrop filters in the stack (replace the mutators stack) + // Update embedded view params, delete except screenScaleMatrix + for (int i = 0; i < 5; i++) { + stack2.Pop(); + } + // Push backdrop filters + for (int i = 0; i < 5; i++) { + auto filter2 = std::make_shared(i, 2, + flutter::DlTileMode::kClamp); + + stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * + 10)); + } + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(newVisualEffectViews.count, 5u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)newVisualEffectViews.count]) { + [newVisualEffectViews addObject:subview]; + } + } + XCTAssertEqual(newVisualEffectViews.count, 5u); + + for (NSUInteger i = 0; i < newVisualEffectViews.count; i++) { + UIView* newView = newVisualEffectViews[i]; + id mockNewView = OCMPartialMock(newView); + UIView* originalView = originalVisualEffectViews[i]; + // Compare reference. + XCTAssertEqual(originalView, newView); + OCMReject([mockNewView removeFromSuperview]); + [mockNewView stopMocking]; + } + [newVisualEffectViews removeAllObjects]; +} + +- (void)testApplyBackdropFilterNotDlBlurImageFilter { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + CGFloat screenScale = [UIScreen mainScreen].scale; + SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); + stack.PushTransform(screenScaleMatrix); + // Push a dilate backdrop filter + auto dilateFilter = std::make_shared(5, 2); + stack.PushBackdropFilter(dilateFilter, SkRect::MakeEmpty()); + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), + stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; + + [mockFlutterView addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + NSUInteger numberOfExpectedVisualEffectView = 0; + for (UIView* subview in childClippingView.subviews) { + if ([subview isKindOfClass:[UIVisualEffectView class]]) { + numberOfExpectedVisualEffectView++; + } + } + XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); + + // Simulate adding a non-DlBlurImageFilter in the middle of the stack (create a new mutators + // stack) Create embedded view params + flutter::MutatorsStack stack2; + // Layer tree always pushes a screen scale factor to the stack + stack2.PushTransform(screenScaleMatrix); + // Push backdrop filters and dilate filter + auto blurFilter = std::make_shared(5, 2, + flutter::DlTileMode::kClamp); + + for (int i = 0; i < 5; i++) { + if (i == 2) { + stack2.PushBackdropFilter(dilateFilter, + SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + continue; + } + + stack2.PushBackdropFilter(blurFilter, + SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + } + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + numberOfExpectedVisualEffectView = 0; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)5]) { + numberOfExpectedVisualEffectView++; + } + } + XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); + + // Simulate adding a non-DlBlurImageFilter to the beginning of the stack (replace the mutators + // stack) Update embedded view params, delete except screenScaleMatrix + for (int i = 0; i < 5; i++) { + stack2.Pop(); + } + // Push backdrop filters and dilate filter + for (int i = 0; i < 5; i++) { + if (i == 0) { + stack2.PushBackdropFilter(dilateFilter, + SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + continue; + } + + stack2.PushBackdropFilter(blurFilter, + SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + } + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + numberOfExpectedVisualEffectView = 0; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)5]) { + numberOfExpectedVisualEffectView++; + } + } + XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); + + // Simulate adding a non-DlBlurImageFilter to the end of the stack (replace the mutators stack) + // Update embedded view params, delete except screenScaleMatrix + for (int i = 0; i < 5; i++) { + stack2.Pop(); + } + // Push backdrop filters and dilate filter + for (int i = 0; i < 5; i++) { + if (i == 4) { + stack2.PushBackdropFilter(dilateFilter, + SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + continue; + } + + stack2.PushBackdropFilter(blurFilter, + SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + } + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + numberOfExpectedVisualEffectView = 0; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(numberOfExpectedVisualEffectView, 4u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:(CGFloat)5]) { + numberOfExpectedVisualEffectView++; + } + } + XCTAssertEqual(numberOfExpectedVisualEffectView, 4u); + + // Simulate adding only non-DlBlurImageFilter to the stack (replace the mutators stack) + // Update embedded view params, delete except screenScaleMatrix + for (int i = 0; i < 5; i++) { + stack2.Pop(); + } + // Push dilate filters + for (int i = 0; i < 5; i++) { + stack2.PushBackdropFilter(dilateFilter, + SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + } + + embeddedViewParams = std::make_unique(screenScaleMatrix, + SkSize::Make(10, 10), + stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + numberOfExpectedVisualEffectView = 0; + for (UIView* subview in childClippingView.subviews) { + if ([subview isKindOfClass:[UIVisualEffectView class]]) { + numberOfExpectedVisualEffectView++; + } + } + XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); +} + +- (void)testApplyBackdropFilterCorrectAPI { + [PlatformViewFilter resetPreparation]; + // The gaussianBlur filter is extracted from UIVisualEffectView. + // Each test requires a new PlatformViewFilter + // Valid UIVisualEffectView API + UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] + initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; + PlatformViewFilter* platformViewFilter = + [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) + blurRadius:5 + visualEffectView:visualEffectView]; + XCTAssertNotNil(platformViewFilter); +} + +- (void)testApplyBackdropFilterAPIChangedInvalidUIVisualEffectView { + [PlatformViewFilter resetPreparation]; + UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] init]; + PlatformViewFilter* platformViewFilter = + [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) + blurRadius:5 + visualEffectView:visualEffectView]; + XCTAssertNil(platformViewFilter); +} + +- (void)testApplyBackdropFilterAPIChangedNoGaussianBlurFilter { + [PlatformViewFilter resetPreparation]; + UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc] + initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; + NSArray* subviews = editedUIVisualEffectView.subviews; + for (UIView* view in subviews) { + if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { + for (CIFilter* filter in view.layer.filters) { + if ([[filter valueForKey:@"name"] isEqual:@"gaussianBlur"]) { + [filter setValue:@"notGaussianBlur" forKey:@"name"]; + break; + } + } + break; + } + } + PlatformViewFilter* platformViewFilter = + [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) + blurRadius:5 + visualEffectView:editedUIVisualEffectView]; + XCTAssertNil(platformViewFilter); +} + +- (void)testApplyBackdropFilterAPIChangedInvalidInputRadius { + [PlatformViewFilter resetPreparation]; + UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc] + initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; + NSArray* subviews = editedUIVisualEffectView.subviews; + for (UIView* view in subviews) { + if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { + for (CIFilter* filter in view.layer.filters) { + if ([[filter valueForKey:@"name"] isEqual:@"gaussianBlur"]) { + [filter setValue:@"invalidInputRadius" forKey:@"inputRadius"]; + break; + } + } + break; + } + } + + PlatformViewFilter* platformViewFilter = + [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) + blurRadius:5 + visualEffectView:editedUIVisualEffectView]; + XCTAssertNil(platformViewFilter); +} + +- (void)testBackdropFilterVisualEffectSubviewBackgroundColor { + UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] + initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; + PlatformViewFilter* platformViewFilter = + [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) + blurRadius:5 + visualEffectView:visualEffectView]; + CGColorRef visualEffectSubviewBackgroundColor; + for (UIView* view in [platformViewFilter backdropFilterView].subviews) { + if ([view isKindOfClass:NSClassFromString(@"_UIVisualEffectSubview")]) { + visualEffectSubviewBackgroundColor = view.layer.backgroundColor; + } + } + XCTAssertTrue( + CGColorEqualToColor(visualEffectSubviewBackgroundColor, UIColor.clearColor.CGColor)); +} + +- (void)testCompositePlatformView { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + SkMatrix screenScaleMatrix = + SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); + stack.PushTransform(screenScaleMatrix); + // Push a translate matrix + SkMatrix translateMatrix = SkMatrix::Translate(100, 100); + stack.PushTransform(translateMatrix); + SkMatrix finalMatrix; + finalMatrix.setConcat(screenScaleMatrix, translateMatrix); + + auto embeddedViewParams = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds + toView:mockFlutterView]; + XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, + 300))); +} + +- (void)testBackdropFilterCorrectlyPushedAndReset { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + CGFloat screenScale = [UIScreen mainScreen].scale; + SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale); + stack.PushTransform(screenScaleMatrix); + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), + stack); + + flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->PushVisitedPlatformView(2); + auto filter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); + flutterPlatformViewsController->PushFilterToVisitedPlatformViews( + filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + // childClippingView has visual effect view with the correct configurations. + NSUInteger numberOfExpectedVisualEffectView = 0; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + XCTAssertLessThan(numberOfExpectedVisualEffectView, 1u); + if ([self validateOneVisualEffectView:subview + expectedFrame:CGRectMake(0, 0, 10, 10) + inputRadius:5]) { + numberOfExpectedVisualEffectView++; + } + } + XCTAssertEqual(numberOfExpectedVisualEffectView, 1u); + + // New frame, with no filter pushed. + auto embeddedViewParams2 = + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), + stack); + flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, + std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(2); + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + numberOfExpectedVisualEffectView = 0; + for (UIView* subview in childClippingView.subviews) { + if (![subview isKindOfClass:[UIVisualEffectView class]]) { + continue; + } + numberOfExpectedVisualEffectView++; + } + XCTAssertEqual(numberOfExpectedVisualEffectView, 0u); +} + +- (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + SkMatrix screenScaleMatrix = + SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); + stack.PushTransform(screenScaleMatrix); + // Push a rotate matrix + SkMatrix rotateMatrix; + rotateMatrix.setRotate(10); + stack.PushTransform(rotateMatrix); + SkMatrix finalMatrix; + finalMatrix.setConcat(screenScaleMatrix, rotateMatrix); + + auto embeddedViewParams = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds + toView:mockFlutterView]; + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; + // The childclippingview's frame is set based on flow, but the platform view's frame is set + based + // on quartz. Although they should be the same, but we should tolerate small floating point + // errors. + XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - + childClippingView.frame.origin.x), + kFloatCompareEpsilon); + XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - + childClippingView.frame.origin.y), + kFloatCompareEpsilon); + XCTAssertLessThan( + fabs(platformViewRectInFlutterView.size.width - childClippingView.frame.size.width), + kFloatCompareEpsilon); + XCTAssertLessThan( + fabs(platformViewRectInFlutterView.size.height - childClippingView.frame.size.height), + kFloatCompareEpsilon); +} + +- (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params. + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack. + SkMatrix screenScaleMatrix = + SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); + stack.PushTransform(screenScaleMatrix); + SkMatrix translateMatrix = SkMatrix::Translate(5, 5); + // The platform view's rect for this test will be (5, 5, 10, 10). + stack.PushTransform(translateMatrix); + // Push a clip rect, big enough to contain the entire platform view bound. + SkRect rect = SkRect::MakeXYWH(0, 0, 25, 25); + stack.PushClipRect(rect); + // Push a clip rrect, big enough to contain the entire platform view bound without clipping it. + // Make the origin (-1, -1) so that the top left rounded corner isn't clipping the + PlatformView. SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25); SkRRect rrect = + SkRRect::MakeRectXY(rect_for_rrect, 1, 1); stack.PushClipRRect(rrect); + + auto embeddedViewParams = std::make_unique( + SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + gMockPlatformView.backgroundColor = UIColor.redColor; + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + XCTAssertNil(childClippingView.maskView); +} + +- (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack. + SkMatrix screenScaleMatrix = + SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); + stack.PushTransform(screenScaleMatrix); + SkMatrix translateMatrix = SkMatrix::Translate(5, 5); + // The platform view's rect for this test will be (5, 5, 10, 10). + stack.PushTransform(translateMatrix); + + // Push a clip rrect, the rect of the rrect is the same as the PlatformView of the corner + should. + // clip the PlatformView. + SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10); + SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); + stack.PushClipRRect(rrect); + + auto embeddedViewParams = std::make_unique( + SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + gMockPlatformView.backgroundColor = UIColor.redColor; + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + XCTAssertNotNil(childClippingView.maskView); +} + +- (void)testClipRect { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + SkMatrix screenScaleMatrix = + SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); + stack.PushTransform(screenScaleMatrix); + // Push a clip rect + SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3); + stack.PushClipRect(rect); + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), + stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + gMockPlatformView.backgroundColor = UIColor.redColor; + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + CGPoint point = CGPointMake(i, j); + int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; + // Edges of the clipping might have a semi transparent pixel, we only check the pixels that + // are fully inside the clipped area. + CGRect insideClipping = CGRectMake(3, 3, 1, 1); + if (CGRectContainsPoint(insideClipping, point)) { + XCTAssertEqual(alpha, 255); + } else { + XCTAssertLessThan(alpha, 255); + } + } + } +} + +- (void)testClipRRect { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + SkMatrix screenScaleMatrix = + SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); + stack.PushTransform(screenScaleMatrix); + // Push a clip rrect + SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1); + stack.PushClipRRect(rrect); + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), + stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + gMockPlatformView.backgroundColor = UIColor.redColor; + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + CGPoint point = CGPointMake(i, j); + int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; + // Edges of the clipping might have a semi transparent pixel, we only check the pixels that + // are fully inside the clipped area. + CGRect insideClipping = CGRectMake(3, 3, 4, 4); + if (CGRectContainsPoint(insideClipping, point)) { + XCTAssertEqual(alpha, 255); + } else { + XCTAssertLessThan(alpha, 255); + } + } + } +} + +- (void)testClipPath { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + SkMatrix screenScaleMatrix = + SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); + stack.PushTransform(screenScaleMatrix); + // Push a clip path + SkPath path; + path.addRoundRect(SkRect::MakeXYWH(2, 2, 6, 6), 1, 1); + stack.PushClipPath(path); + + auto embeddedViewParams = + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), + stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + gMockPlatformView.backgroundColor = UIColor.redColor; + XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); + ChildClippingView* childClippingView = + (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView + addSubview:childClippingView]; + + [mockFlutterView setNeedsLayout]; + [mockFlutterView layoutIfNeeded]; + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + CGPoint point = CGPointMake(i, j); + int alpha = [self alphaOfPoint:CGPointMake(i, j) onView:mockFlutterView]; + // Edges of the clipping might have a semi transparent pixel, we only check the pixels that + // are fully inside the clipped area. + CGRect insideClipping = CGRectMake(3, 3, 4, 4); + if (CGRectContainsPoint(insideClipping, point)) { + XCTAssertEqual(alpha, 255); + } else { + XCTAssertLessThan(alpha, 255); + } + } + } +} + +- (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + // Find touch inteceptor view + UIView* touchInteceptorView = gMockPlatformView; + while (touchInteceptorView != nil && + ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { + touchInteceptorView = touchInteceptorView.superview; + } + XCTAssertNotNil(touchInteceptorView); + + // Find ForwardGestureRecognizer + UIGestureRecognizer* forwardGectureRecognizer = nil; + for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { + if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + forwardGectureRecognizer = gestureRecognizer; + break; + } + } + + // Before setting flutter view controller, events are not dispatched. + NSSet* touches1 = [[[NSSet alloc] init] autorelease]; + id event1 = OCMClassMock([UIEvent class]); + id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); + [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; + OCMReject([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); + + // Set flutter view controller allows events to be dispatched. + NSSet* touches2 = [[[NSSet alloc] init] autorelease]; + id event2 = OCMClassMock([UIEvent class]); + flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); + [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2]; + OCMVerify([mockFlutterViewContoller touchesBegan:touches2 withEvent:event2]); +} + +- (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGesturesToBeHandled { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + // Find touch inteceptor view + UIView* touchInteceptorView = gMockPlatformView; + while (touchInteceptorView != nil && + ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { + touchInteceptorView = touchInteceptorView.superview; + } + XCTAssertNotNil(touchInteceptorView); + + // Find ForwardGestureRecognizer + UIGestureRecognizer* forwardGectureRecognizer = nil; + for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { + if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + forwardGectureRecognizer = gestureRecognizer; + break; + } + } + id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); + { + // ***** Sequence 1, finishing touch event with touchEnded ***** // + flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); + + NSSet* touches1 = [[[NSSet alloc] init] autorelease]; + id event1 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; + OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); + + flutterPlatformViewsController->SetFlutterViewController(nil); + + // Allow the touch events to finish + NSSet* touches2 = [[[NSSet alloc] init] autorelease]; + id event2 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2]; + OCMVerify([mockFlutterViewContoller touchesMoved:touches2 withEvent:event2]); + + NSSet* touches3 = [[[NSSet alloc] init] autorelease]; + id event3 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesEnded:touches3 withEvent:event3]; + OCMVerify([mockFlutterViewContoller touchesEnded:touches3 withEvent:event3]); + + // Now the 2nd touch sequence should not be allowed. + NSSet* touches4 = [[[NSSet alloc] init] autorelease]; + id event4 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4]; + OCMReject([mockFlutterViewContoller touchesBegan:touches4 withEvent:event4]); + + NSSet* touches5 = [[[NSSet alloc] init] autorelease]; + id event5 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; + OCMReject([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); + } + + { + // ***** Sequence 2, finishing touch event with touchCancelled ***** // + flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); + + NSSet* touches1 = [[[NSSet alloc] init] autorelease]; + id event1 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; + OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); + + flutterPlatformViewsController->SetFlutterViewController(nil); + + // Allow the touch events to finish + NSSet* touches2 = [[[NSSet alloc] init] autorelease]; + id event2 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesMoved:touches2 withEvent:event2]; + OCMVerify([mockFlutterViewContoller touchesMoved:touches2 withEvent:event2]); + + NSSet* touches3 = [[[NSSet alloc] init] autorelease]; + id event3 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesCancelled:touches3 withEvent:event3]; + OCMVerify([mockFlutterViewContoller forceTouchesCancelled:touches3]); + + // Now the 2nd touch sequence should not be allowed. + NSSet* touches4 = [[[NSSet alloc] init] autorelease]; + id event4 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesBegan:touches4 withEvent:event4]; + OCMReject([mockFlutterViewContoller touchesBegan:touches4 withEvent:event4]); + + NSSet* touches5 = [[[NSSet alloc] init] autorelease]; + id event5 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; + OCMReject([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); + } + + flutterPlatformViewsController->Reset(); +} + +- (void) + testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence + { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + // Find touch inteceptor view + UIView* touchInteceptorView = gMockPlatformView; + while (touchInteceptorView != nil && + ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { + touchInteceptorView = touchInteceptorView.superview; + } + XCTAssertNotNil(touchInteceptorView); + + // Find ForwardGestureRecognizer + UIGestureRecognizer* forwardGectureRecognizer = nil; + for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { + if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + forwardGectureRecognizer = gestureRecognizer; + break; + } + } + id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); + + flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); + + // The touches in this sequence requires 1 touch object, we always create the NSSet with one + item. NSSet* touches1 = [NSSet setWithObject:@1]; id event1 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; + OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); + + UIViewController* mockFlutterViewContoller2 = OCMClassMock([UIViewController class]); + flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller2); + + // Touch events should still send to the old FlutterViewController if FlutterViewController + // is updated in between. + NSSet* touches2 = [NSSet setWithObject:@1]; + id event2 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesBegan:touches2 withEvent:event2]; + OCMVerify([mockFlutterViewContoller touchesBegan:touches2 withEvent:event2]); + OCMReject([mockFlutterViewContoller2 touchesBegan:touches2 withEvent:event2]); + + NSSet* touches3 = [NSSet setWithObject:@1]; + id event3 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesMoved:touches3 withEvent:event3]; + OCMVerify([mockFlutterViewContoller touchesMoved:touches3 withEvent:event3]); + OCMReject([mockFlutterViewContoller2 touchesMoved:touches3 withEvent:event3]); + + NSSet* touches4 = [NSSet setWithObject:@1]; + id event4 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesEnded:touches4 withEvent:event4]; + OCMVerify([mockFlutterViewContoller touchesEnded:touches4 withEvent:event4]); + OCMReject([mockFlutterViewContoller2 touchesEnded:touches4 withEvent:event4]); + + NSSet* touches5 = [NSSet setWithObject:@1]; + id event5 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesEnded:touches5 withEvent:event5]; + OCMVerify([mockFlutterViewContoller touchesEnded:touches5 withEvent:event5]); + OCMReject([mockFlutterViewContoller2 touchesEnded:touches5 withEvent:event5]); + + // Now the 2nd touch sequence should go to the new FlutterViewController + + NSSet* touches6 = [NSSet setWithObject:@1]; + id event6 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesBegan:touches6 withEvent:event6]; + OCMVerify([mockFlutterViewContoller2 touchesBegan:touches6 withEvent:event6]); + OCMReject([mockFlutterViewContoller touchesBegan:touches6 withEvent:event6]); + + // Allow the touch events to finish + NSSet* touches7 = [NSSet setWithObject:@1]; + id event7 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesMoved:touches7 withEvent:event7]; + OCMVerify([mockFlutterViewContoller2 touchesMoved:touches7 withEvent:event7]); + OCMReject([mockFlutterViewContoller touchesMoved:touches7 withEvent:event7]); + + NSSet* touches8 = [NSSet setWithObject:@1]; + id event8 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesEnded:touches8 withEvent:event8]; + OCMVerify([mockFlutterViewContoller2 touchesEnded:touches8 withEvent:event8]); + OCMReject([mockFlutterViewContoller touchesEnded:touches8 withEvent:event8]); + + flutterPlatformViewsController->Reset(); +} + +- (void)testFlutterPlatformViewTouchesCancelledEventAreForcedToBeCancelled { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + // Find touch inteceptor view + UIView* touchInteceptorView = gMockPlatformView; + while (touchInteceptorView != nil && + ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { + touchInteceptorView = touchInteceptorView.superview; + } + XCTAssertNotNil(touchInteceptorView); + + // Find ForwardGestureRecognizer + UIGestureRecognizer* forwardGectureRecognizer = nil; + for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { + if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + forwardGectureRecognizer = gestureRecognizer; + break; + } + } + id mockFlutterViewContoller = OCMClassMock([FlutterViewController class]); + + flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); + + NSSet* touches1 = [NSSet setWithObject:@1]; + id event1 = OCMClassMock([UIEvent class]); + [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; + + [forwardGectureRecognizer touchesCancelled:touches1 withEvent:event1]; + OCMVerify([mockFlutterViewContoller forceTouchesCancelled:touches1]); + + flutterPlatformViewsController->Reset(); +} + +- (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashing { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + + // Create embedded view params + flutter::MutatorsStack stack; + SkMatrix finalMatrix; + + auto embeddedViewParams_1 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, + std::move(embeddedViewParams_1)); flutterPlatformViewsController->CompositeEmbeddedView(2); + flutter::SurfaceFrame::FramebufferInfo framebuffer_info; + auto mock_surface = std::make_unique( + nullptr, framebuffer_info, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return false; + }, + /*frame_size=*/SkISize::Make(800, 600)); + XCTAssertFalse( + flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); + + auto embeddedViewParams_2 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, + std::move(embeddedViewParams_2)); flutterPlatformViewsController->CompositeEmbeddedView(2); + auto mock_surface_submit_true = std::make_unique( + nullptr, framebuffer_info, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, + /*frame_size=*/SkISize::Make(800, 600)); + XCTAssertTrue(flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, + std::move(mock_surface_submit_true))); +} + +- (void) + testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView + { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + // autorelease pool to trigger an autorelease for all the root_views_ and touch_interceptors_. + @autoreleasepool { + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + flutter::MutatorsStack stack; + SkMatrix finalMatrix; + auto embeddedViewParams = + std::make_unique(finalMatrix, SkSize::Make(300, 300), + stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, + std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); + // Not calling |flutterPlatformViewsController::SubmitFrame| so that the platform views are + not + // added to flutter_view_. + + XCTAssertNotNil(gMockPlatformView); + flutterPlatformViewsController->Reset(); + } + XCTAssertNil(gMockPlatformView); +} + +- (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], + result); + + // First frame, |EmbeddedViewCount| is not empty after composite. + flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); + flutter::MutatorsStack stack; + SkMatrix finalMatrix; + auto embeddedViewParams1 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, + std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); + XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); + + // Second frame, |EmbeddedViewCount| should be empty at the start + flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); + XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 0UL); + + auto embeddedViewParams2 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, + std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(0); + XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); +} + +- (void) + testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy + { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], + result); + UIView* view1 = gMockPlatformView; + + // This overwrites `gMockPlatformView` to another view. + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], + result); + UIView* view2 = gMockPlatformView; + + flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); + flutter::MutatorsStack stack; + SkMatrix finalMatrix; + auto embeddedViewParams1 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, + std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); auto + embeddedViewParams2 = + std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, + std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); + + // SKSurface is required if the root FlutterView is present. + const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); + sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); + flutter::SurfaceFrame::FramebufferInfo framebuffer_info; + auto mock_surface = std::make_unique( + std::move(mock_sk_surface), framebuffer_info, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, + /*frame_size=*/SkISize::Make(800, 600)); + + XCTAssertTrue( + flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); + // platform view is wrapped by touch interceptor, which itself is wrapped by clipping view. + UIView* clippingView1 = view1.superview.superview; + UIView* clippingView2 = view2.superview.superview; + UIView* flutterView = clippingView1.superview; + XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < + [flutterView.subviews indexOfObject:clippingView2], + @"The first clipping view should be added before the second clipping view."); + + // Need to recreate these params since they are `std::move`ed. + flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); + // Process the second frame in the opposite order. + embeddedViewParams2 = + std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, + std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); + embeddedViewParams1 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, + std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); + + mock_sk_surface = SkSurface::MakeRaster(image_info); + mock_surface = std::make_unique( + std::move(mock_sk_surface), framebuffer_info, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, + /*frame_size=*/SkISize::Make(800, 600)); + XCTAssertTrue( + flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); + XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] > + [flutterView.subviews indexOfObject:clippingView2], + @"The first clipping view should be added after the second clipping view."); +} + +- (void) + testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy + { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], + result); + UIView* view1 = gMockPlatformView; + + // This overwrites `gMockPlatformView` to another view. + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], + result); + UIView* view2 = gMockPlatformView; + + flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); + flutter::MutatorsStack stack; + SkMatrix finalMatrix; + auto embeddedViewParams1 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, + std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); auto + embeddedViewParams2 = + std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, + std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); + + // SKSurface is required if the root FlutterView is present. + const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); + sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); + flutter::SurfaceFrame::FramebufferInfo framebuffer_info; + auto mock_surface = std::make_unique( + std::move(mock_sk_surface), framebuffer_info, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, + /*frame_size=*/SkISize::Make(800, 600)); + + XCTAssertTrue( + flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); + // platform view is wrapped by touch interceptor, which itself is wrapped by clipping view. + UIView* clippingView1 = view1.superview.superview; + UIView* clippingView2 = view2.superview.superview; + UIView* flutterView = clippingView1.superview; + XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < + [flutterView.subviews indexOfObject:clippingView2], + @"The first clipping view should be added before the second clipping view."); + + // Need to recreate these params since they are `std::move`ed. + flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); + // Process the second frame in the same order. + embeddedViewParams1 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, + std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); + embeddedViewParams2 = + std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, + std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); + + mock_sk_surface = SkSurface::MakeRaster(image_info); + mock_surface = std::make_unique( + std::move(mock_sk_surface), framebuffer_info, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, + /*frame_size=*/SkISize::Make(800, 600)); + XCTAssertTrue( + flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); + XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] < + [flutterView.subviews indexOfObject:clippingView2], + @"The first clipping view should be added before the second clipping view."); +} + +- (void)testThreadMergeAtEndFrame { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner_platform = CreateNewThread("FlutterPlatformViewsTest1"); + auto thread_task_runner_other = CreateNewThread("FlutterPlatformViewsTest2"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner_platform, + /*raster=*/thread_task_runner_other, + /*ui=*/thread_task_runner_other, + /*io=*/thread_task_runner_other); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + XCTestExpectation* waitForPlatformView = + [self expectationWithDescription:@"wait for platform view to be created"]; + FlutterResult result = ^(id result) { + [waitForPlatformView fulfill]; + }; + + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + [self waitForExpectations:@[ waitForPlatformView ] timeout:30]; + XCTAssertNotNil(gMockPlatformView); + + flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); + SkMatrix finalMatrix; + flutter::MutatorsStack stack; + auto embeddedViewParams = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + + fml::RefPtr raster_thread_merger = + fml::MakeRefCounted(thread_task_runner_platform->GetTaskQueueId(), + thread_task_runner_other->GetTaskQueueId()); + XCTAssertEqual(flutterPlatformViewsController->PostPrerollAction(raster_thread_merger), + flutter::PostPrerollResult::kSkipAndRetryFrame); + XCTAssertFalse(raster_thread_merger->IsMerged()); + + flutterPlatformViewsController->EndFrame(true, raster_thread_merger); + XCTAssertTrue(raster_thread_merger->IsMerged()); + + // Unmerge threads before the end of the test + // TaskRunners are required to be unmerged before destruction. + while (raster_thread_merger->DecrementLease() != fml::RasterThreadStatus::kUnmergedNow) + ; +} + +- (int)alphaOfPoint:(CGPoint)point onView:(UIView*)view { + unsigned char pixel[4] = {0}; + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + // Draw the pixel on `point` in the context. + CGContextRef context = CGBitmapContextCreate( + pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast); + CGContextTranslateCTM(context, -point.x, -point.y); + [view.layer renderInContext:context]; + + CGContextRelease(context); + CGColorSpaceRelease(colorSpace); + // Get the alpha from the pixel that we just rendered. + return pixel[3]; +} + +- (void)testHasFirstResponderInViewHierarchySubtree_viewItselfBecomesFirstResponder { + // For view to become the first responder, it must be a descendant of a UIWindow + UIWindow* window = [[UIWindow alloc] init]; + UITextField* textField = [[UITextField alloc] init]; + [window addSubview:textField]; + + [textField becomeFirstResponder]; + XCTAssertTrue(textField.isFirstResponder); + XCTAssertTrue(textField.flt_hasFirstResponderInViewHierarchySubtree); + [textField resignFirstResponder]; + XCTAssertFalse(textField.isFirstResponder); + XCTAssertFalse(textField.flt_hasFirstResponderInViewHierarchySubtree); +} + +- (void)testHasFirstResponderInViewHierarchySubtree_descendantViewBecomesFirstResponder { + // For view to become the first responder, it must be a descendant of a UIWindow + UIWindow* window = [[UIWindow alloc] init]; + UIView* view = [[UIView alloc] init]; + UIView* childView = [[UIView alloc] init]; + UITextField* textField = [[UITextField alloc] init]; + [window addSubview:view]; + [view addSubview:childView]; + [childView addSubview:textField]; + + [textField becomeFirstResponder]; + XCTAssertTrue(textField.isFirstResponder); + XCTAssertTrue(view.flt_hasFirstResponderInViewHierarchySubtree); + [textField resignFirstResponder]; + XCTAssertFalse(textField.isFirstResponder); + XCTAssertFalse(view.flt_hasFirstResponderInViewHierarchySubtree); +} + +- (void)testFlutterClippingMaskViewPoolReuseViewsAfterRecycle { + FlutterClippingMaskViewPool* pool = + [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; + FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero]; + FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero]; + [pool recycleMaskViews]; + CGRect newRect = CGRectMake(0, 0, 10, 10); + FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:newRect]; + FlutterClippingMaskView* view4 = [pool getMaskViewWithFrame:newRect]; + XCTAssertEqual(view1, view3); + XCTAssertEqual(view2, view4); + XCTAssertTrue(CGRectEqualToRect(view3.frame, newRect)); + XCTAssertTrue(CGRectEqualToRect(view4.frame, newRect)); +} + +- (void)testFlutterClippingMaskViewPoolAllocsNewMaskViewsAfterReachingCapacity { + FlutterClippingMaskViewPool* pool = + [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; + FlutterClippingMaskView* view1 = [pool getMaskViewWithFrame:CGRectZero]; + FlutterClippingMaskView* view2 = [pool getMaskViewWithFrame:CGRectZero]; + FlutterClippingMaskView* view3 = [pool getMaskViewWithFrame:CGRectZero]; + XCTAssertNotEqual(view1, view3); + XCTAssertNotEqual(view2, view3); +} + +- (void)testMaskViewsReleasedWhenPoolIsReleased { + UIView* retainedView; + @autoreleasepool { + FlutterClippingMaskViewPool* pool = + [[[FlutterClippingMaskViewPool alloc] initWithCapacity:2] autorelease]; + FlutterClippingMaskView* view = [pool getMaskViewWithFrame:CGRectZero]; + retainedView = [view retain]; + XCTAssertGreaterThan(retainedView.retainCount, 1u); + } + // The only retain left is our manual retain called inside the autorelease pool, meaning the + // maskViews are dealloc'd. + XCTAssertEqual(retainedView.retainCount, 1u); +} + +- (void)testClipMaskViewIsReused { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], + result); + + XCTAssertNotNil(gMockPlatformView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack1; + // Layer tree always pushes a screen scale factor to the stack + SkMatrix screenScaleMatrix = + SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); + stack1.PushTransform(screenScaleMatrix); + // Push a clip rect + SkRect rect = SkRect::MakeXYWH(2, 2, 3, 3); + stack1.PushClipRect(rect); + + auto embeddedViewParams1 = std::make_unique( + screenScaleMatrix, SkSize::Make(10, 10), stack1); + + flutter::MutatorsStack stack2; + auto embeddedViewParams2 = std::make_unique( + screenScaleMatrix, SkSize::Make(10, 10), stack2); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, + std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); + UIView* childClippingView1 = gMockPlatformView.superview.superview; + UIView* maskView1 = childClippingView1.maskView; + XCTAssertNotNil(maskView1); + + // Composite a new frame. + auto embeddedViewParams3 = std::make_unique( + screenScaleMatrix, SkSize::Make(10, 10), stack2); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, + std::move(embeddedViewParams3)); flutterPlatformViewsController->CompositeEmbeddedView(1); + childClippingView1 = gMockPlatformView.superview.superview; + + // This overrides gMockPlatformView to point to the newly created platform view. + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + + auto embeddedViewParams4 = std::make_unique( + screenScaleMatrix, SkSize::Make(10, 10), stack1); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, + std::move(embeddedViewParams4)); flutterPlatformViewsController->CompositeEmbeddedView(2); + UIView* childClippingView2 = gMockPlatformView.superview.superview; + + UIView* maskView2 = childClippingView2.maskView; + XCTAssertEqual(maskView1, maskView2); + XCTAssertNotNil(childClippingView2.maskView); + XCTAssertNil(childClippingView1.maskView); +} + +// Return true if a correct visual effect view is found. It also implies all the validation in +this +// method passes. +// +// There are two fail states for this method. 1. One of the XCTAssert method failed; or 2. No +// correct visual effect view found. +- (BOOL)validateOneVisualEffectView:(UIView*)visualEffectView + expectedFrame:(CGRect)frame + inputRadius:(CGFloat)inputRadius { + XCTAssertTrue(CGRectEqualToRect(visualEffectView.frame, frame)); + for (UIView* view in visualEffectView.subviews) { + if (![view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { + continue; + } + XCTAssertEqual(view.layer.filters.count, 1u); + NSObject* filter = view.layer.filters.firstObject; + + XCTAssertEqualObjects([filter valueForKey:@"name"], @"gaussianBlur"); + + NSObject* inputRadiusInFilter = [filter valueForKey:@"inputRadius"]; + XCTAssertTrue([inputRadiusInFilter isKindOfClass:[NSNumber class]] && + flutter::BlurRadiusEqualToBlurRadius(((NSNumber*)inputRadiusInFilter).floatValue, + inputRadius)); + return YES; + } + return NO; +} + +- (void)testDisposingViewInCompositionOrderDoNotCrash { + flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = + std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, + /*task_runners=*/runners); + + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] + autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], + result); + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @1, @"viewType" : @"MockFlutterPlatformView"}], + result); + + { + // **** First frame, view id 0, 1 in the composition_order_, disposing view 0 is called. **** + // + // No view should be disposed, or removed from the composition order. + flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); + flutter::MutatorsStack stack; + SkMatrix finalMatrix; + auto embeddedViewParams0 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), + stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, + std::move(embeddedViewParams0)); flutterPlatformViewsController->CompositeEmbeddedView(0); + + auto embeddedViewParams1 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), + stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, + std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); + XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); + + XCTestExpectation* expectation = [self expectationWithDescription:@"dispose call ended."]; + FlutterResult disposeResult = ^(id result) { + [expectation fulfill]; + }; + + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall methodCallWithMethodName:@"dispose" arguments:@0], disposeResult); + [self waitForExpectationsWithTimeout:30 handler:nil]; + + const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); + sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); + flutter::SurfaceFrame::FramebufferInfo framebuffer_info; + auto mock_surface = std::make_unique( + std::move(mock_sk_surface), framebuffer_info, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; + }, + /*frame_size=*/SkISize::Make(800, 600)); + XCTAssertTrue( + flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); + + // Disposing won't remove embedded views until the view is removed from the + composition_order_ XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); + XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(0)); + XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); + } + + { + // **** Second frame, view id 1 in the composition_order_, no disposing view is called, **** + // + // View 0 is removed from the composition order in this frame, hence also disposed. + flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); + flutter::MutatorsStack stack; + SkMatrix finalMatrix; + auto embeddedViewParams1 = + std::make_unique(finalMatrix, SkSize::Make(300, 300), + stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, + std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); + + const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); + sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); + flutter::SurfaceFrame::FramebufferInfo framebuffer_info; + auto mock_surface = std::make_unique( + std::move(mock_sk_surface), framebuffer_info, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; + }, + /*frame_size=*/SkISize::Make(800, 600)); + XCTAssertTrue( + flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); + + // Disposing won't remove embedded views until the view is removed from the + composition_order_ XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); + XCTAssertNil(flutterPlatformViewsController->GetPlatformViewByID(0)); + XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); + } +} @end diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m index 7e640da1ef778..e94a75a875717 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m @@ -21,308 +21,308 @@ - (void)setUp { // | PV | +---+ // +--------+ | A | // +---+ -// - (void)testNoOverlay { -// XCUIApplication* app = [[XCUIApplication alloc] init]; -// app.launchArguments = -// @[ @"--platform-view-no-overlay-intersection", @"--enable-software-rendering" ]; -// [app launch]; - -// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; -// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); -// XCTAssertEqual(platform_view.frame.origin.x, 0); -// XCTAssertEqual(platform_view.frame.origin.y, 0); -// XCTAssertEqual(platform_view.frame.size.width, 250); -// XCTAssertEqual(platform_view.frame.size.height, 250); - -// XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; -// XCTAssertFalse(overlay.exists); -// } - -// // A is the layer above the platform view. -// // +-----------------+ -// // | PV +---+ | -// // | | A | | -// // | +---+ | -// // +-----------------+ -// - (void)testOneOverlay { -// XCUIApplication* app = [[XCUIApplication alloc] init]; -// app.launchArguments = @[ @"--platform-view" ]; -// [app launch]; - -// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; -// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); -// XCTAssertEqual(platform_view.frame.origin.x, 0); -// XCTAssertEqual(platform_view.frame.origin.y, 0); -// XCTAssertEqual(platform_view.frame.size.width, 250); -// XCTAssertEqual(platform_view.frame.size.height, 250); - -// XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; -// XCTAssertTrue(overlay.exists); -// XCTAssertEqual(overlay.frame.origin.x, 150); -// XCTAssertEqual(overlay.frame.origin.y, 150); -// XCTAssertEqual(overlay.frame.size.width, 50); -// XCTAssertEqual(overlay.frame.size.height, 50); - -// XCUIElement* overlayView = app.otherElements[@"platform_view[0].overlay_view[0]"]; -// XCTAssertTrue(overlayView.exists); -// // Overlay should always be the same frame as the app. -// XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, -// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView.frame.size.height, -// app.frame.size.height, -// kCompareAccuracy); -// } - -// // A is the layer above the platform view. -// // +-----------------+ -// // | PV +---+ | -// // +-----------| A |-+ -// // +---+ -// - (void)testOneOverlayPartialIntersection { -// XCUIApplication* app = [[XCUIApplication alloc] init]; -// app.launchArguments = @[ @"--platform-view-partial-intersection" ]; -// [app launch]; - -// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; -// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); -// XCTAssertEqual(platform_view.frame.origin.x, 0); -// XCTAssertEqual(platform_view.frame.origin.y, 0); -// XCTAssertEqual(platform_view.frame.size.width, 250); -// XCTAssertEqual(platform_view.frame.size.height, 250); - -// XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; -// XCTAssertTrue(overlay.exists); -// XCTAssertEqual(overlay.frame.origin.x, 200); -// XCTAssertEqual(overlay.frame.origin.y, 245); -// XCTAssertEqual(overlay.frame.size.width, 50); -// // Half the height of the overlay. -// XCTAssertEqual(overlay.frame.size.height, 5); - -// XCUIElement* overlayView = app.otherElements[@"platform_view[0].overlay_view[0]"]; -// XCTAssertTrue(overlayView.exists); -// // Overlay should always be the same frame as the app. -// XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, -// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView.frame.size.height, -// app.frame.size.height, -// kCompareAccuracy); -// } - -// // A and B are the layers above the platform view. -// // +--------------------+ -// // | PV +------------+ | -// // | | B +-----+ | | -// // | +---| A |-+ | -// // +----------| |---+ -// // +-----+ -// - (void)testTwoIntersectingOverlays { -// XCUIApplication* app = [[XCUIApplication alloc] init]; -// app.launchArguments = @[ @"--platform-view-two-intersecting-overlays" ]; -// [app launch]; - -// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; -// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); -// XCTAssertEqual(platform_view.frame.origin.x, 0); -// XCTAssertEqual(platform_view.frame.origin.y, 0); -// XCTAssertEqual(platform_view.frame.size.width, 250); -// XCTAssertEqual(platform_view.frame.size.height, 250); - -// XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; -// XCTAssertTrue(overlay.exists); -// XCTAssertEqual(overlay.frame.origin.x, 150); -// XCTAssertEqual(overlay.frame.origin.y, 150); -// XCTAssertEqual(overlay.frame.size.width, 75); -// XCTAssertEqual(overlay.frame.size.height, 75); - -// XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists); -// } - -// // A, B, and C are the layers above the platform view. -// // +-------------------------+ -// // | PV +-----------+ | -// // | +---+ | B +-----+ | | -// // | | C | +---| A |-+ | -// // | +---+ +-----+ | -// // +-------------------------+ -// - (void)testOneOverlayAndTwoIntersectingOverlays { -// XCUIApplication* app = [[XCUIApplication alloc] init]; -// app.launchArguments = @[ @"--platform-view-one-overlay-two-intersecting-overlays" ]; -// [app launch]; - -// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; -// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); -// XCTAssertEqual(platform_view.frame.origin.x, 0); -// XCTAssertEqual(platform_view.frame.origin.y, 0); -// XCTAssertEqual(platform_view.frame.size.width, 250); -// XCTAssertEqual(platform_view.frame.size.height, 250); - -// XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"]; -// XCTAssertTrue(overlay1.exists); -// XCTAssertEqual(overlay1.frame.origin.x, 150); -// XCTAssertEqual(overlay1.frame.origin.y, 150); -// XCTAssertEqual(overlay1.frame.size.width, 75); -// XCTAssertEqual(overlay1.frame.size.height, 75); - -// XCUIElement* overlay2 = app.otherElements[@"platform_view[0].overlay[1]"]; -// XCTAssertTrue(overlay2.exists); -// XCTAssertEqual(overlay2.frame.origin.x, 75); -// XCTAssertEqual(overlay2.frame.origin.y, 225); -// XCTAssertEqual(overlay2.frame.size.width, 50); -// XCTAssertEqual(overlay2.frame.size.height, 25); - -// XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; -// XCTAssertTrue(overlayView0.exists); -// // Overlay should always be the same frame as the app. -// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, -// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, -// app.frame.size.height, -// kCompareAccuracy); - -// XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; -// XCTAssertTrue(overlayView1.exists); -// // Overlay should always be the same frame as the app. -// XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, -// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, -// app.frame.size.height, -// kCompareAccuracy); -// } - -// // A is the layer, which z index is higher than the platform view. -// // +--------+ -// // | PV | +---+ -// // +--------+ | A | -// // +--------+ +---+ -// // | PV | -// // +--------+ -// - (void)testMultiplePlatformViewsWithoutOverlays { -// XCUIApplication* app = [[XCUIApplication alloc] init]; -// app.launchArguments = @[ @"--platform-view-multiple-without-overlays" ]; -// [app launch]; - -// XCUIElement* platform_view1 = app.otherElements[@"platform_view[0]"]; -// XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]); -// XCTAssertEqual(platform_view1.frame.origin.x, 0); -// XCTAssertEqual(platform_view1.frame.origin.y, 300); -// XCTAssertEqual(platform_view1.frame.size.width, 250); -// XCTAssertEqual(platform_view1.frame.size.height, 250); - -// XCUIElement* platform_view2 = app.otherElements[@"platform_view[1]"]; -// XCTAssertTrue(platform_view2.exists); -// XCTAssertEqual(platform_view2.frame.origin.x, 0); -// XCTAssertEqual(platform_view2.frame.origin.y, 0); -// XCTAssertEqual(platform_view2.frame.size.width, 250); -// XCTAssertEqual(platform_view2.frame.size.height, 250); - -// XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[0]"].exists); -// XCTAssertFalse(app.otherElements[@"platform_view[1].overlay[0]"].exists); -// XCTAssertFalse(app.otherElements[@"platform_view[0].overlay_view[0]"].exists); -// XCTAssertFalse(app.otherElements[@"platform_view[1].overlay_view[0]"].exists); -// } - -// // A is the layer above both platform view. -// // +------------+ -// // | PV +----+ | -// // +-----| A |-+ -// // +-----| |-+ -// // | PV +----+ | -// // +------------+ -// - (void)testMultiplePlatformViewsWithOverlays { -// XCUIApplication* app = [[XCUIApplication alloc] init]; -// app.launchArguments = @[ @"--platform-view-multiple-background-foreground" ]; -// [app launch]; - -// XCUIElement* platform_view1 = app.otherElements[@"platform_view[0]"]; -// XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]); -// XCTAssertEqual(platform_view1.frame.origin.x, 25); -// XCTAssertEqual(platform_view1.frame.origin.y, 300); -// XCTAssertEqual(platform_view1.frame.size.width, 250); -// XCTAssertEqual(platform_view1.frame.size.height, 250); - -// XCUIElement* platform_view2 = app.otherElements[@"platform_view[1]"]; -// XCTAssertTrue(platform_view2.exists); -// XCTAssertEqual(platform_view2.frame.origin.x, 25); -// XCTAssertEqual(platform_view2.frame.origin.y, 0); -// XCTAssertEqual(platform_view2.frame.size.width, 250); -// XCTAssertEqual(platform_view2.frame.size.height, 250); - -// XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"]; -// XCTAssertTrue(overlay1.exists); -// XCTAssertEqual(overlay1.frame.origin.x, 25); -// XCTAssertEqual(overlay1.frame.origin.y, 300); -// XCTAssertEqual(overlay1.frame.size.width, 225); -// XCTAssertEqual(overlay1.frame.size.height, 200); - -// XCUIElement* overlay2 = app.otherElements[@"platform_view[1].overlay[0]"]; -// XCTAssertTrue(overlay2.exists); -// XCTAssertEqual(overlay2.frame.origin.x, 25); -// XCTAssertEqual(overlay2.frame.origin.y, 0); -// XCTAssertEqual(overlay2.frame.size.width, 225); -// XCTAssertEqual(overlay2.frame.size.height, 250); - -// XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; -// XCTAssertTrue(overlayView0.exists); -// // Overlay should always be the same frame as the app. -// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, -// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, -// app.frame.size.height, -// kCompareAccuracy); - -// XCUIElement* overlayView1 = app.otherElements[@"platform_view[1].overlay_view[0]"]; -// XCTAssertTrue(overlayView1.exists); -// // Overlay should always be the same frame as the app. -// XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, -// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, -// app.frame.size.height, -// kCompareAccuracy); -// } - -// // More then two overlays are merged into a single layer. -// // +---------------------+ -// // | +---+ +---+ +---+ | -// // | | A | | B | | C | | -// // | +---+ +---+ +---+ | -// // | +-------+ | -// // +-| D |-----------+ -// // +-------+ -// - (void)testPlatformViewsMaxOverlays { -// XCUIApplication* app = [[XCUIApplication alloc] init]; -// app.launchArguments = @[ @"--platform-view-max-overlays" ]; -// [app launch]; - -// XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; -// XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); -// XCTAssertEqual(platform_view.frame.origin.x, 0); -// XCTAssertEqual(platform_view.frame.origin.y, 0); -// XCTAssertEqual(platform_view.frame.size.width, 250); -// XCTAssertEqual(platform_view.frame.size.height, 250); - -// XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; -// XCTAssertTrue(overlay.exists); -// XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists); -// XCTAssertTrue(CGRectContainsRect(platform_view.frame, overlay.frame)); - -// XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; -// XCTAssertTrue(overlayView0.exists); -// // Overlay should always be the same frame as the app. -// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); -// XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, -// kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, -// app.frame.size.height, -// kCompareAccuracy); - -// XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; -// XCTAssertFalse(overlayView1.exists); -// } +- (void)testNoOverlay { + XCUIApplication* app = [[XCUIApplication alloc] init]; + app.launchArguments = + @[ @"--platform-view-no-overlay-intersection", @"--enable-software-rendering" ]; + [app launch]; + + XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; + XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); + XCTAssertEqual(platform_view.frame.origin.x, 0); + XCTAssertEqual(platform_view.frame.origin.y, 0); + XCTAssertEqual(platform_view.frame.size.width, 250); + XCTAssertEqual(platform_view.frame.size.height, 250); + + XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; + XCTAssertFalse(overlay.exists); +} + +// A is the layer above the platform view. +// +-----------------+ +// | PV +---+ | +// | | A | | +// | +---+ | +// +-----------------+ +- (void)testOneOverlay { + XCUIApplication* app = [[XCUIApplication alloc] init]; + app.launchArguments = @[ @"--platform-view" ]; + [app launch]; + + XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; + XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); + XCTAssertEqual(platform_view.frame.origin.x, 0); + XCTAssertEqual(platform_view.frame.origin.y, 0); + XCTAssertEqual(platform_view.frame.size.width, 250); + XCTAssertEqual(platform_view.frame.size.height, 250); + + XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; + XCTAssertTrue(overlay.exists); + XCTAssertEqual(overlay.frame.origin.x, 150); + XCTAssertEqual(overlay.frame.origin.y, 150); + XCTAssertEqual(overlay.frame.size.width, 50); + XCTAssertEqual(overlay.frame.size.height, 50); + + XCUIElement* overlayView = app.otherElements[@"platform_view[0].overlay_view[0]"]; + XCTAssertTrue(overlayView.exists); + // Overlay should always be the same frame as the app. + XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, + kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView.frame.size.height, + app.frame.size.height, + kCompareAccuracy); +} + +// A is the layer above the platform view. +// +-----------------+ +// | PV +---+ | +// +-----------| A |-+ +// +---+ +- (void)testOneOverlayPartialIntersection { + XCUIApplication* app = [[XCUIApplication alloc] init]; + app.launchArguments = @[ @"--platform-view-partial-intersection" ]; + [app launch]; + + XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; + XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); + XCTAssertEqual(platform_view.frame.origin.x, 0); + XCTAssertEqual(platform_view.frame.origin.y, 0); + XCTAssertEqual(platform_view.frame.size.width, 250); + XCTAssertEqual(platform_view.frame.size.height, 250); + + XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; + XCTAssertTrue(overlay.exists); + XCTAssertEqual(overlay.frame.origin.x, 200); + XCTAssertEqual(overlay.frame.origin.y, 245); + XCTAssertEqual(overlay.frame.size.width, 50); + // Half the height of the overlay. + XCTAssertEqual(overlay.frame.size.height, 5); + + XCUIElement* overlayView = app.otherElements[@"platform_view[0].overlay_view[0]"]; + XCTAssertTrue(overlayView.exists); + // Overlay should always be the same frame as the app. + XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, + kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView.frame.size.height, + app.frame.size.height, + kCompareAccuracy); +} + +// A and B are the layers above the platform view. +// +--------------------+ +// | PV +------------+ | +// | | B +-----+ | | +// | +---| A |-+ | +// +----------| |---+ +// +-----+ +- (void)testTwoIntersectingOverlays { + XCUIApplication* app = [[XCUIApplication alloc] init]; + app.launchArguments = @[ @"--platform-view-two-intersecting-overlays" ]; + [app launch]; + + XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; + XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); + XCTAssertEqual(platform_view.frame.origin.x, 0); + XCTAssertEqual(platform_view.frame.origin.y, 0); + XCTAssertEqual(platform_view.frame.size.width, 250); + XCTAssertEqual(platform_view.frame.size.height, 250); + + XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; + XCTAssertTrue(overlay.exists); + XCTAssertEqual(overlay.frame.origin.x, 150); + XCTAssertEqual(overlay.frame.origin.y, 150); + XCTAssertEqual(overlay.frame.size.width, 75); + XCTAssertEqual(overlay.frame.size.height, 75); + + XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists); +} + +// A, B, and C are the layers above the platform view. +// +-------------------------+ +// | PV +-----------+ | +// | +---+ | B +-----+ | | +// | | C | +---| A |-+ | +// | +---+ +-----+ | +// +-------------------------+ +- (void)testOneOverlayAndTwoIntersectingOverlays { + XCUIApplication* app = [[XCUIApplication alloc] init]; + app.launchArguments = @[ @"--platform-view-one-overlay-two-intersecting-overlays" ]; + [app launch]; + + XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; + XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); + XCTAssertEqual(platform_view.frame.origin.x, 0); + XCTAssertEqual(platform_view.frame.origin.y, 0); + XCTAssertEqual(platform_view.frame.size.width, 250); + XCTAssertEqual(platform_view.frame.size.height, 250); + + XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"]; + XCTAssertTrue(overlay1.exists); + XCTAssertEqual(overlay1.frame.origin.x, 150); + XCTAssertEqual(overlay1.frame.origin.y, 150); + XCTAssertEqual(overlay1.frame.size.width, 75); + XCTAssertEqual(overlay1.frame.size.height, 75); + + XCUIElement* overlay2 = app.otherElements[@"platform_view[0].overlay[1]"]; + XCTAssertTrue(overlay2.exists); + XCTAssertEqual(overlay2.frame.origin.x, 75); + XCTAssertEqual(overlay2.frame.origin.y, 225); + XCTAssertEqual(overlay2.frame.size.width, 50); + XCTAssertEqual(overlay2.frame.size.height, 25); + + XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; + XCTAssertTrue(overlayView0.exists); + // Overlay should always be the same frame as the app. + XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, + kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, + app.frame.size.height, + kCompareAccuracy); + + XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; + XCTAssertTrue(overlayView1.exists); + // Overlay should always be the same frame as the app. + XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, + kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, + app.frame.size.height, + kCompareAccuracy); +} + +// A is the layer, which z index is higher than the platform view. +// +--------+ +// | PV | +---+ +// +--------+ | A | +// +--------+ +---+ +// | PV | +// +--------+ +- (void)testMultiplePlatformViewsWithoutOverlays { + XCUIApplication* app = [[XCUIApplication alloc] init]; + app.launchArguments = @[ @"--platform-view-multiple-without-overlays" ]; + [app launch]; + + XCUIElement* platform_view1 = app.otherElements[@"platform_view[0]"]; + XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]); + XCTAssertEqual(platform_view1.frame.origin.x, 0); + XCTAssertEqual(platform_view1.frame.origin.y, 300); + XCTAssertEqual(platform_view1.frame.size.width, 250); + XCTAssertEqual(platform_view1.frame.size.height, 250); + + XCUIElement* platform_view2 = app.otherElements[@"platform_view[1]"]; + XCTAssertTrue(platform_view2.exists); + XCTAssertEqual(platform_view2.frame.origin.x, 0); + XCTAssertEqual(platform_view2.frame.origin.y, 0); + XCTAssertEqual(platform_view2.frame.size.width, 250); + XCTAssertEqual(platform_view2.frame.size.height, 250); + + XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[0]"].exists); + XCTAssertFalse(app.otherElements[@"platform_view[1].overlay[0]"].exists); + XCTAssertFalse(app.otherElements[@"platform_view[0].overlay_view[0]"].exists); + XCTAssertFalse(app.otherElements[@"platform_view[1].overlay_view[0]"].exists); +} + +// A is the layer above both platform view. +// +------------+ +// | PV +----+ | +// +-----| A |-+ +// +-----| |-+ +// | PV +----+ | +// +------------+ +- (void)testMultiplePlatformViewsWithOverlays { + XCUIApplication* app = [[XCUIApplication alloc] init]; + app.launchArguments = @[ @"--platform-view-multiple-background-foreground" ]; + [app launch]; + + XCUIElement* platform_view1 = app.otherElements[@"platform_view[0]"]; + XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]); + XCTAssertEqual(platform_view1.frame.origin.x, 25); + XCTAssertEqual(platform_view1.frame.origin.y, 300); + XCTAssertEqual(platform_view1.frame.size.width, 250); + XCTAssertEqual(platform_view1.frame.size.height, 250); + + XCUIElement* platform_view2 = app.otherElements[@"platform_view[1]"]; + XCTAssertTrue(platform_view2.exists); + XCTAssertEqual(platform_view2.frame.origin.x, 25); + XCTAssertEqual(platform_view2.frame.origin.y, 0); + XCTAssertEqual(platform_view2.frame.size.width, 250); + XCTAssertEqual(platform_view2.frame.size.height, 250); + + XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"]; + XCTAssertTrue(overlay1.exists); + XCTAssertEqual(overlay1.frame.origin.x, 25); + XCTAssertEqual(overlay1.frame.origin.y, 300); + XCTAssertEqual(overlay1.frame.size.width, 225); + XCTAssertEqual(overlay1.frame.size.height, 200); + + XCUIElement* overlay2 = app.otherElements[@"platform_view[1].overlay[0]"]; + XCTAssertTrue(overlay2.exists); + XCTAssertEqual(overlay2.frame.origin.x, 25); + XCTAssertEqual(overlay2.frame.origin.y, 0); + XCTAssertEqual(overlay2.frame.size.width, 225); + XCTAssertEqual(overlay2.frame.size.height, 250); + + XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; + XCTAssertTrue(overlayView0.exists); + // Overlay should always be the same frame as the app. + XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, + kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, + app.frame.size.height, + kCompareAccuracy); + + XCUIElement* overlayView1 = app.otherElements[@"platform_view[1].overlay_view[0]"]; + XCTAssertTrue(overlayView1.exists); + // Overlay should always be the same frame as the app. + XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, + kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, + app.frame.size.height, + kCompareAccuracy); +} + +// More then two overlays are merged into a single layer. +// +---------------------+ +// | +---+ +---+ +---+ | +// | | A | | B | | C | | +// | +---+ +---+ +---+ | +// | +-------+ | +// +-| D |-----------+ +// +-------+ +- (void)testPlatformViewsMaxOverlays { + XCUIApplication* app = [[XCUIApplication alloc] init]; + app.launchArguments = @[ @"--platform-view-max-overlays" ]; + [app launch]; + + XCUIElement* platform_view = app.otherElements[@"platform_view[0]"]; + XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]); + XCTAssertEqual(platform_view.frame.origin.x, 0); + XCTAssertEqual(platform_view.frame.origin.y, 0); + XCTAssertEqual(platform_view.frame.size.width, 250); + XCTAssertEqual(platform_view.frame.size.height, 250); + + XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"]; + XCTAssertTrue(overlay.exists); + XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists); + XCTAssertTrue(CGRectContainsRect(platform_view.frame, overlay.frame)); + + XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"]; + XCTAssertTrue(overlayView0.exists); + // Overlay should always be the same frame as the app. + XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, + kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, + app.frame.size.height, + kCompareAccuracy); + + XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; + XCTAssertFalse(overlayView1.exists); +} @end From 37d1611b51d43ca131fecf368029f1855e4a253d Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 10:46:09 -0700 Subject: [PATCH 13/27] bring back tests --- .../Source/FlutterPlatformViewsTest.mm | 558 ++++++++---------- .../UnobstructedPlatformViewTests.m | 35 +- 2 files changed, 250 insertions(+), 343 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 63d42b82daa04..0d74081e559cb 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -199,9 +199,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -226,8 +225,8 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { - (void)testChildClippingViewHitTests { ChildClippingView* childClippingView = [[[ChildClippingView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; - UIView* childView = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] - autorelease]; [childClippingView addSubview:childView]; + UIView* childView = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] autorelease]; + [childClippingView addSubview:childView]; XCTAssertFalse([childClippingView pointInside:CGPointMake(50, 50) withEvent:nil]); XCTAssertFalse([childClippingView pointInside:CGPointMake(99, 100) withEvent:nil]); @@ -252,9 +251,8 @@ - (void)testApplyBackdropFilter { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -275,8 +273,8 @@ - (void)testApplyBackdropFilter { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -288,15 +286,13 @@ - (void)testApplyBackdropFilter { stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -325,9 +321,8 @@ - (void)testApplyBackdropFilterWithCorrectFrame { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -348,8 +343,8 @@ - (void)testApplyBackdropFilterWithCorrectFrame { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -361,15 +356,13 @@ - (void)testApplyBackdropFilterWithCorrectFrame { stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 8, screenScale * 8)); auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(5, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(5, 10), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -398,9 +391,8 @@ - (void)testApplyMultipleBackdropFilters { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -421,8 +413,8 @@ - (void)testApplyMultipleBackdropFilters { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -431,21 +423,18 @@ - (void)testApplyMultipleBackdropFilters { stack.PushTransform(screenScaleMatrix); // Push backdrop filters for (int i = 0; i < 50; i++) { - auto filter = std::make_shared(i, 2, - flutter::DlTileMode::kClamp); stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, - screenScale * 10, screenScale * 10)); + auto filter = std::make_shared(i, 2, flutter::DlTileMode::kClamp); + stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); } auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(20, 20), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(20, 20), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -473,9 +462,8 @@ - (void)testAddBackdropFilters { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -496,8 +484,8 @@ - (void)testAddBackdropFilters { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -509,15 +497,13 @@ - (void)testAddBackdropFilters { stack.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -544,13 +530,11 @@ - (void)testAddBackdropFilters { stack2.PushTransform(screenScaleMatrix); // Push backdrop filters for (int i = 0; i < 2; i++) { - stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * - 10)); + stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); } embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -589,9 +573,8 @@ - (void)testRemoveBackdropFilters { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -612,8 +595,8 @@ - (void)testRemoveBackdropFilters { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -627,15 +610,13 @@ - (void)testRemoveBackdropFilters { } auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -660,13 +641,11 @@ - (void)testRemoveBackdropFilters { stack2.PushTransform(screenScaleMatrix); // Push backdrop filters for (int i = 0; i < 4; i++) { - stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * - 10)); + stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); } embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -705,8 +684,7 @@ - (void)testRemoveBackdropFilters { // No backdrop filters in the stack, so no nothing to push embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -730,9 +708,8 @@ - (void)testEditBackdropFilters { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -753,8 +730,8 @@ - (void)testEditBackdropFilters { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -768,15 +745,13 @@ - (void)testEditBackdropFilters { } auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -810,13 +785,11 @@ - (void)testEditBackdropFilters { continue; } - stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * - 10)); + stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); } embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -867,13 +840,11 @@ - (void)testEditBackdropFilters { continue; } - stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * - 10)); + stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); } embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -921,13 +892,11 @@ - (void)testEditBackdropFilters { continue; } - stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * - 10)); + stack2.PushBackdropFilter(filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); } embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -969,16 +938,13 @@ - (void)testEditBackdropFilters { } // Push backdrop filters for (int i = 0; i < 5; i++) { - auto filter2 = std::make_shared(i, 2, - flutter::DlTileMode::kClamp); + auto filter2 = std::make_shared(i, 2, flutter::DlTileMode::kClamp); - stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * - 10)); + stack2.PushBackdropFilter(filter2, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); } embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -1018,9 +984,8 @@ - (void)testApplyBackdropFilterNotDlBlurImageFilter { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -1041,8 +1006,8 @@ - (void)testApplyBackdropFilterNotDlBlurImageFilter { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -1054,14 +1019,12 @@ - (void)testApplyBackdropFilterNotDlBlurImageFilter { stack.PushBackdropFilter(dilateFilter, SkRect::MakeEmpty()); auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView addSubview:childClippingView]; @@ -1082,8 +1045,7 @@ - (void)testApplyBackdropFilterNotDlBlurImageFilter { // Layer tree always pushes a screen scale factor to the stack stack2.PushTransform(screenScaleMatrix); // Push backdrop filters and dilate filter - auto blurFilter = std::make_shared(5, 2, - flutter::DlTileMode::kClamp); + auto blurFilter = std::make_shared(5, 2, flutter::DlTileMode::kClamp); for (int i = 0; i < 5; i++) { if (i == 2) { @@ -1097,8 +1059,7 @@ - (void)testApplyBackdropFilterNotDlBlurImageFilter { } embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -1137,8 +1098,7 @@ - (void)testApplyBackdropFilterNotDlBlurImageFilter { } embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -1177,8 +1137,7 @@ - (void)testApplyBackdropFilterNotDlBlurImageFilter { } embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -1211,8 +1170,7 @@ - (void)testApplyBackdropFilterNotDlBlurImageFilter { } embeddedViewParams = std::make_unique(screenScaleMatrix, - SkSize::Make(10, 10), - stack2); + SkSize::Make(10, 10), stack2); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); @@ -1324,9 +1282,8 @@ - (void)testCompositePlatformView { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -1347,8 +1304,8 @@ - (void)testCompositePlatformView { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -1368,8 +1325,7 @@ - (void)testCompositePlatformView { flutterPlatformViewsController->CompositeEmbeddedView(2); CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds toView:mockFlutterView]; - XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, - 300))); + XCTAssertTrue(CGRectEqualToRect(platformViewRectInFlutterView, CGRectMake(100, 100, 300, 300))); } - (void)testBackdropFilterCorrectlyPushedAndReset { @@ -1380,9 +1336,8 @@ - (void)testBackdropFilterCorrectlyPushedAndReset { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -1403,8 +1358,8 @@ - (void)testBackdropFilterCorrectlyPushedAndReset { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -1413,8 +1368,7 @@ - (void)testBackdropFilterCorrectlyPushedAndReset { stack.PushTransform(screenScaleMatrix); auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); @@ -1424,9 +1378,8 @@ - (void)testBackdropFilterCorrectlyPushedAndReset { filter, SkRect::MakeXYWH(0, 0, screenScale * 10, screenScale * 10)); flutterPlatformViewsController->CompositeEmbeddedView(2); XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -1448,11 +1401,10 @@ - (void)testBackdropFilterCorrectlyPushedAndReset { // New frame, with no filter pushed. auto embeddedViewParams2 = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); flutterPlatformViewsController->BeginFrame(SkISize::Make(0, 0)); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, - std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(2); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams2)); + flutterPlatformViewsController->CompositeEmbeddedView(2); XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:[ChildClippingView class]]); [mockFlutterView setNeedsLayout]; @@ -1476,9 +1428,8 @@ - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -1499,8 +1450,8 @@ - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -1522,17 +1473,15 @@ - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView { CGRect platformViewRectInFlutterView = [gMockPlatformView convertRect:gMockPlatformView.bounds toView:mockFlutterView]; XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; // The childclippingview's frame is set based on flow, but the platform view's frame is set based - // on quartz. Although they should be the same, but we should tolerate small floating point - // errors. - XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - - childClippingView.frame.origin.x), - kFloatCompareEpsilon); - XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - - childClippingView.frame.origin.y), + // on quartz. Although they should be the same, but we should tolerate small floating point + // errors. + XCTAssertLessThan( + fabs(platformViewRectInFlutterView.origin.x - childClippingView.frame.origin.x), + kFloatCompareEpsilon); + XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - childClippingView.frame.origin.y), kFloatCompareEpsilon); XCTAssertLessThan( fabs(platformViewRectInFlutterView.size.width - childClippingView.frame.size.width), @@ -1550,9 +1499,8 @@ - (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -1573,8 +1521,8 @@ - (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params. flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack. @@ -1589,8 +1537,9 @@ - (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView { stack.PushClipRect(rect); // Push a clip rrect, big enough to contain the entire platform view bound without clipping it. // Make the origin (-1, -1) so that the top left rounded corner isn't clipping the - PlatformView. SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25); SkRRect rrect = - SkRRect::MakeRectXY(rect_for_rrect, 1, 1); stack.PushClipRRect(rrect); + PlatformView.SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25); + SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); + stack.PushClipRRect(rrect); auto embeddedViewParams = std::make_unique( SkMatrix::Concat(screenScaleMatrix, translateMatrix), SkSize::Make(5, 5), stack); @@ -1599,9 +1548,8 @@ - (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView { flutterPlatformViewsController->CompositeEmbeddedView(2); gMockPlatformView.backgroundColor = UIColor.redColor; XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -1616,9 +1564,8 @@ - (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -1639,8 +1586,8 @@ - (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack. @@ -1653,8 +1600,8 @@ - (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView { // Push a clip rrect, the rect of the rrect is the same as the PlatformView of the corner should. - // clip the PlatformView. - SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10); + // clip the PlatformView. + SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10); SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); stack.PushClipRRect(rrect); @@ -1665,9 +1612,8 @@ - (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView { flutterPlatformViewsController->CompositeEmbeddedView(2); gMockPlatformView.backgroundColor = UIColor.redColor; XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -1683,9 +1629,8 @@ - (void)testClipRect { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -1706,8 +1651,8 @@ - (void)testClipRect { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -1719,16 +1664,14 @@ - (void)testClipRect { stack.PushClipRect(rect); auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); gMockPlatformView.backgroundColor = UIColor.redColor; XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -1757,9 +1700,8 @@ - (void)testClipRRect { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -1780,8 +1722,8 @@ - (void)testClipRRect { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -1793,16 +1735,14 @@ - (void)testClipRRect { stack.PushClipRRect(rrect); auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); gMockPlatformView.backgroundColor = UIColor.redColor; XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -1831,9 +1771,8 @@ - (void)testClipPath { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -1854,8 +1793,8 @@ - (void)testClipPath { XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack; // Layer tree always pushes a screen scale factor to the stack @@ -1868,16 +1807,14 @@ - (void)testClipPath { stack.PushClipPath(path); auto embeddedViewParams = - std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), - stack); + std::make_unique(screenScaleMatrix, SkSize::Make(10, 10), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); gMockPlatformView.backgroundColor = UIColor.redColor; XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); - ChildClippingView* childClippingView = - (ChildClippingView*)gMockPlatformView.superview.superview; [mockFlutterView - addSubview:childClippingView]; + ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; + [mockFlutterView addSubview:childClippingView]; [mockFlutterView setNeedsLayout]; [mockFlutterView layoutIfNeeded]; @@ -1906,9 +1843,8 @@ - (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -1969,9 +1905,8 @@ - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGestu /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -2081,8 +2016,7 @@ - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGestu } - (void) - testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence - { + testSetFlutterViewControllerInTheMiddleOfTouchEventAllowsTheNewControllerToHandleSecondTouchSequence { flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); flutter::TaskRunners runners(/*label=*/self.name.UTF8String, @@ -2090,9 +2024,8 @@ - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGestu /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -2134,7 +2067,8 @@ - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGestu flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); // The touches in this sequence requires 1 touch object, we always create the NSSet with one - item. NSSet* touches1 = [NSSet setWithObject:@1]; id event1 = OCMClassMock([UIEvent class]); + item.NSSet* touches1 = [NSSet setWithObject:@1]; + id event1 = OCMClassMock([UIEvent class]); [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); @@ -2199,9 +2133,8 @@ - (void)testFlutterPlatformViewTouchesCancelledEventAreForcedToBeCancelled { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -2260,9 +2193,8 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -2290,21 +2222,20 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin auto embeddedViewParams_1 = std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, - std::move(embeddedViewParams_1)); flutterPlatformViewsController->CompositeEmbeddedView(2); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_1)); + flutterPlatformViewsController->CompositeEmbeddedView(2); flutter::SurfaceFrame::FramebufferInfo framebuffer_info; auto mock_surface = std::make_unique( nullptr, framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return false; - }, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return false; }, /*frame_size=*/SkISize::Make(800, 600)); XCTAssertFalse( flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); auto embeddedViewParams_2 = std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, - std::move(embeddedViewParams_2)); flutterPlatformViewsController->CompositeEmbeddedView(2); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams_2)); + flutterPlatformViewsController->CompositeEmbeddedView(2); auto mock_surface_submit_true = std::make_unique( nullptr, framebuffer_info, [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, @@ -2314,8 +2245,7 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin } - (void) - testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView - { + testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView { flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); flutter::TaskRunners runners(/*label=*/self.name.UTF8String, @@ -2323,16 +2253,15 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2352,15 +2281,14 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin flutter::MutatorsStack stack; SkMatrix finalMatrix; auto embeddedViewParams = - std::make_unique(finalMatrix, SkSize::Make(300, 300), - stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, - std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); // Not calling |flutterPlatformViewsController::SubmitFrame| so that the platform views are not - // added to flutter_view_. + // added to flutter_view_. - XCTAssertNotNil(gMockPlatformView); + XCTAssertNotNil(gMockPlatformView); flutterPlatformViewsController->Reset(); } XCTAssertNil(gMockPlatformView); @@ -2374,16 +2302,15 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2405,8 +2332,8 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { SkMatrix finalMatrix; auto embeddedViewParams1 = std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, - std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); + flutterPlatformViewsController->CompositeEmbeddedView(0); XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); // Second frame, |EmbeddedViewCount| should be empty at the start @@ -2415,14 +2342,13 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { auto embeddedViewParams2 = std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, - std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(0); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams2)); + flutterPlatformViewsController->CompositeEmbeddedView(0); XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); } - (void) - testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy - { + testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithDifferentViewHierarchy { flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); flutter::TaskRunners runners(/*label=*/self.name.UTF8String, @@ -2430,16 +2356,15 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2468,12 +2393,12 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { SkMatrix finalMatrix; auto embeddedViewParams1 = std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, - std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); auto - embeddedViewParams2 = + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); + flutterPlatformViewsController->CompositeEmbeddedView(0); + auto embeddedViewParams2 = std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, - std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); + flutterPlatformViewsController->CompositeEmbeddedView(1); // SKSurface is required if the root FlutterView is present. const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); @@ -2499,12 +2424,12 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { // Process the second frame in the opposite order. embeddedViewParams2 = std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, - std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); + flutterPlatformViewsController->CompositeEmbeddedView(1); embeddedViewParams1 = std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, - std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); + flutterPlatformViewsController->CompositeEmbeddedView(0); mock_sk_surface = SkSurface::MakeRaster(image_info); mock_surface = std::make_unique( @@ -2519,8 +2444,7 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { } - (void) - testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy - { + testFlutterPlatformViewControllerSubmitFrameShouldOrderSubviewsCorrectlyWithSameViewHierarchy { flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); flutter::TaskRunners runners(/*label=*/self.name.UTF8String, @@ -2528,16 +2452,15 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2566,12 +2489,12 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { SkMatrix finalMatrix; auto embeddedViewParams1 = std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, - std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); auto - embeddedViewParams2 = + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); + flutterPlatformViewsController->CompositeEmbeddedView(0); + auto embeddedViewParams2 = std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, - std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); + flutterPlatformViewsController->CompositeEmbeddedView(1); // SKSurface is required if the root FlutterView is present. const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); @@ -2597,12 +2520,12 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { // Process the second frame in the same order. embeddedViewParams1 = std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, - std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(0); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); + flutterPlatformViewsController->CompositeEmbeddedView(0); embeddedViewParams2 = std::make_unique(finalMatrix, SkSize::Make(500, 500), stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, - std::move(embeddedViewParams2)); flutterPlatformViewsController->CompositeEmbeddedView(1); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams2)); + flutterPlatformViewsController->CompositeEmbeddedView(1); mock_sk_surface = SkSurface::MakeRaster(image_info); mock_surface = std::make_unique( @@ -2625,16 +2548,15 @@ - (void)testThreadMergeAtEndFrame { /*raster=*/thread_task_runner_other, /*ui=*/thread_task_runner_other, /*io=*/thread_task_runner_other); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2774,9 +2696,8 @@ - (void)testClipMaskViewIsReused { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, @@ -2796,8 +2717,8 @@ - (void)testClipMaskViewIsReused { result); XCTAssertNotNil(gMockPlatformView); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); // Create embedded view params flutter::MutatorsStack stack1; // Layer tree always pushes a screen scale factor to the stack @@ -2815,8 +2736,8 @@ - (void)testClipMaskViewIsReused { auto embeddedViewParams2 = std::make_unique( screenScaleMatrix, SkSize::Make(10, 10), stack2); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, - std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); + flutterPlatformViewsController->CompositeEmbeddedView(1); UIView* childClippingView1 = gMockPlatformView.superview.superview; UIView* maskView1 = childClippingView1.maskView; XCTAssertNotNil(maskView1); @@ -2824,8 +2745,8 @@ - (void)testClipMaskViewIsReused { // Composite a new frame. auto embeddedViewParams3 = std::make_unique( screenScaleMatrix, SkSize::Make(10, 10), stack2); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, - std::move(embeddedViewParams3)); flutterPlatformViewsController->CompositeEmbeddedView(1); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams3)); + flutterPlatformViewsController->CompositeEmbeddedView(1); childClippingView1 = gMockPlatformView.superview.superview; // This overrides gMockPlatformView to point to the newly created platform view. @@ -2837,8 +2758,8 @@ - (void)testClipMaskViewIsReused { auto embeddedViewParams4 = std::make_unique( screenScaleMatrix, SkSize::Make(10, 10), stack1); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, - std::move(embeddedViewParams4)); flutterPlatformViewsController->CompositeEmbeddedView(2); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams4)); + flutterPlatformViewsController->CompositeEmbeddedView(2); UIView* childClippingView2 = gMockPlatformView.superview.superview; UIView* maskView2 = childClippingView2.maskView; @@ -2849,13 +2770,12 @@ - (void)testClipMaskViewIsReused { // Return true if a correct visual effect view is found. It also implies all the validation in this -// method passes. -// -// There are two fail states for this method. 1. One of the XCTAssert method failed; or 2. No -// correct visual effect view found. -- (BOOL)validateOneVisualEffectView:(UIView*)visualEffectView - expectedFrame:(CGRect)frame - inputRadius:(CGFloat)inputRadius { + // method passes. + // + // There are two fail states for this method. 1. One of the XCTAssert method failed; or 2. No + // correct visual effect view found. + - (BOOL)validateOneVisualEffectView : (UIView*)visualEffectView expectedFrame + : (CGRect)frame inputRadius : (CGFloat)inputRadius { XCTAssertTrue(CGRectEqualToRect(visualEffectView.frame, frame)); for (UIView* view in visualEffectView.subviews) { if (![view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { @@ -2883,16 +2803,15 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto flutterPlatformViewsController = - std::make_shared(); auto platform_view = - std::make_unique( + auto flutterPlatformViewsController = std::make_shared(); + auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] - autorelease]; flutterPlatformViewsController->SetFlutterView(mockFlutterView); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -2921,16 +2840,14 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash { flutter::MutatorsStack stack; SkMatrix finalMatrix; auto embeddedViewParams0 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), - stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, - std::move(embeddedViewParams0)); flutterPlatformViewsController->CompositeEmbeddedView(0); + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams0)); + flutterPlatformViewsController->CompositeEmbeddedView(0); auto embeddedViewParams1 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), - stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, - std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); + flutterPlatformViewsController->CompositeEmbeddedView(1); XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); XCTestExpectation* expectation = [self expectationWithDescription:@"dispose call ended."]; @@ -2947,8 +2864,7 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash { flutter::SurfaceFrame::FramebufferInfo framebuffer_info; auto mock_surface = std::make_unique( std::move(mock_sk_surface), framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; - }, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); XCTAssertTrue( flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); @@ -2967,18 +2883,16 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash { flutter::MutatorsStack stack; SkMatrix finalMatrix; auto embeddedViewParams1 = - std::make_unique(finalMatrix, SkSize::Make(300, 300), - stack); - flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, - std::move(embeddedViewParams1)); flutterPlatformViewsController->CompositeEmbeddedView(1); + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + flutterPlatformViewsController->PrerollCompositeEmbeddedView(1, std::move(embeddedViewParams1)); + flutterPlatformViewsController->CompositeEmbeddedView(1); const SkImageInfo image_info = SkImageInfo::MakeN32Premul(1000, 1000); sk_sp mock_sk_surface = SkSurface::MakeRaster(image_info); flutter::SurfaceFrame::FramebufferInfo framebuffer_info; auto mock_surface = std::make_unique( std::move(mock_sk_surface), framebuffer_info, - [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; - }, + [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); XCTAssertTrue( flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m index e94a75a875717..57d627e2b2145 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m @@ -68,9 +68,8 @@ - (void)testOneOverlay { // Overlay should always be the same frame as the app. XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, - kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView.frame.size.height, - app.frame.size.height, + XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView.frame.size.height, app.frame.size.height, kCompareAccuracy); } @@ -104,9 +103,8 @@ - (void)testOneOverlayPartialIntersection { // Overlay should always be the same frame as the app. XCTAssertEqualWithAccuracy(overlayView.frame.origin.x, app.frame.origin.x, kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, - kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView.frame.size.height, - app.frame.size.height, + XCTAssertEqualWithAccuracy(overlayView.frame.size.width, app.frame.size.width, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView.frame.size.height, app.frame.size.height, kCompareAccuracy); } @@ -177,9 +175,8 @@ - (void)testOneOverlayAndTwoIntersectingOverlays { // Overlay should always be the same frame as the app. XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, - kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, - app.frame.size.height, + XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, kCompareAccuracy); XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; @@ -187,9 +184,8 @@ - (void)testOneOverlayAndTwoIntersectingOverlays { // Overlay should always be the same frame as the app. XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, - kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, - app.frame.size.height, + XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, app.frame.size.height, kCompareAccuracy); } @@ -270,9 +266,8 @@ - (void)testMultiplePlatformViewsWithOverlays { // Overlay should always be the same frame as the app. XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, - kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, - app.frame.size.height, + XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, kCompareAccuracy); XCUIElement* overlayView1 = app.otherElements[@"platform_view[1].overlay_view[0]"]; @@ -280,9 +275,8 @@ - (void)testMultiplePlatformViewsWithOverlays { // Overlay should always be the same frame as the app. XCTAssertEqualWithAccuracy(overlayView1.frame.origin.x, app.frame.origin.x, kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView1.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, - kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, - app.frame.size.height, + XCTAssertEqualWithAccuracy(overlayView1.frame.size.width, app.frame.size.width, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView1.frame.size.height, app.frame.size.height, kCompareAccuracy); } @@ -316,9 +310,8 @@ - (void)testPlatformViewsMaxOverlays { // Overlay should always be the same frame as the app. XCTAssertEqualWithAccuracy(overlayView0.frame.origin.x, app.frame.origin.x, kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.origin.y, app.frame.origin.x, kCompareAccuracy); - XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, - kCompareAccuracy); XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, - app.frame.size.height, + XCTAssertEqualWithAccuracy(overlayView0.frame.size.width, app.frame.size.width, kCompareAccuracy); + XCTAssertEqualWithAccuracy(overlayView0.frame.size.height, app.frame.size.height, kCompareAccuracy); XCUIElement* overlayView1 = app.otherElements[@"platform_view[0].overlay_view[1]"]; From f896d92ff22926f933438aa6cfd24563608c133a Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 10:57:48 -0700 Subject: [PATCH 14/27] fix --- .../ios/Scenarios/ScenariosUITests/PlatformViewUITests.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m index 040dd675dc387..f820d29697cca 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m @@ -409,8 +409,7 @@ - (void)testPlatformViewScrollingUnderWidget { waitForExpectations:@[ [[XCTestExpectation alloc] initWithDescription:@"Wait for 5 seconds"] ] timeout:5]; - // If the waiter is not interrupted, we know the app is in a valid state after timeout, thus - the + // If the waiter is not interrupted, we know the app is in a valid state after timeout, thus the // test passes. XCTAssert(waitResult != XCTWaiterResultInterrupted); } From 7f4609aade633e9752426ceba28f65795cc2139b Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 10:59:13 -0700 Subject: [PATCH 15/27] revert --- .../ios/Scenarios/ScenariosUITests/PlatformViewUITests.m | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m index f820d29697cca..1aa093655b319 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m @@ -406,11 +406,9 @@ - (void)testPlatformViewScrollingUnderWidget { // Wait and let the scenario app scroll a bit. XCTWaiterResult waitResult = [XCTWaiter - waitForExpectations:@[ [[XCTestExpectation alloc] initWithDescription:@"Wait for 5 - seconds"] ] + waitForExpectations:@[ [[XCTestExpectation alloc] initWithDescription:@"Wait for 5 seconds"] ] timeout:5]; // If the waiter is not interrupted, we know the app is in a valid state after timeout, thus the - // test passes. XCTAssert(waitResult != XCTWaiterResultInterrupted); } From 14c30731ba255de727f78753a0489d0f76f0127f Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 11:02:51 -0700 Subject: [PATCH 16/27] revert --- .../Source/FlutterPlatformViewsTest.mm | 67 +++++++++---------- .../ScenariosUITests/PlatformViewUITests.m | 1 + 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 0d74081e559cb..97285cfcc78be 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -824,8 +824,7 @@ - (void)testEditBackdropFilters { } [newVisualEffectViews removeAllObjects]; - // Simulate editing 1 backdrop filter in the beginning of the stack (replace the mutators - stack) + // Simulate editing 1 backdrop filter in the beginning of the stack (replace the mutators stack) // Update embedded view params, delete except screenScaleMatrix for (int i = 0; i < 5; i++) { stack2.Pop(); @@ -1474,13 +1473,11 @@ - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView { toView:mockFlutterView]; XCTAssertTrue([gMockPlatformView.superview.superview isKindOfClass:ChildClippingView.class]); ChildClippingView* childClippingView = (ChildClippingView*)gMockPlatformView.superview.superview; - // The childclippingview's frame is set based on flow, but the platform view's frame is set - based - // on quartz. Although they should be the same, but we should tolerate small floating point - // errors. - XCTAssertLessThan( - fabs(platformViewRectInFlutterView.origin.x - childClippingView.frame.origin.x), - kFloatCompareEpsilon); + // The childclippingview's frame is set based on flow, but the platform view's frame is set based + // on quartz. Although they should be the same, but we should tolerate small floating point + // errors. + XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.x - childClippingView.frame.origin.x), + kFloatCompareEpsilon); XCTAssertLessThan(fabs(platformViewRectInFlutterView.origin.y - childClippingView.frame.origin.y), kFloatCompareEpsilon); XCTAssertLessThan( @@ -1536,8 +1533,8 @@ - (void)testClipsDoNotInterceptWithPlatformViewShouldNotAddMaskView { SkRect rect = SkRect::MakeXYWH(0, 0, 25, 25); stack.PushClipRect(rect); // Push a clip rrect, big enough to contain the entire platform view bound without clipping it. - // Make the origin (-1, -1) so that the top left rounded corner isn't clipping the - PlatformView.SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25); + // Make the origin (-1, -1) so that the top left rounded corner isn't clipping the PlatformView. + SkRect rect_for_rrect = SkRect::MakeXYWH(-1, -1, 25, 25); SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); stack.PushClipRRect(rrect); @@ -1598,10 +1595,9 @@ - (void)testClipRRectOnlyHasCornersInterceptWithPlatformViewShouldAddMaskView { // The platform view's rect for this test will be (5, 5, 10, 10). stack.PushTransform(translateMatrix); - // Push a clip rrect, the rect of the rrect is the same as the PlatformView of the corner - should. - // clip the PlatformView. - SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10); + // Push a clip rrect, the rect of the rrect is the same as the PlatformView of the corner should. + // clip the PlatformView. + SkRect rect_for_rrect = SkRect::MakeXYWH(0, 0, 10, 10); SkRRect rrect = SkRRect::MakeRectXY(rect_for_rrect, 1, 1); stack.PushClipRRect(rrect); @@ -2066,8 +2062,8 @@ - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGestu flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller); - // The touches in this sequence requires 1 touch object, we always create the NSSet with one - item.NSSet* touches1 = [NSSet setWithObject:@1]; + // The touches in this sequence requires 1 touch object, we always create the NSSet with one item. + NSSet* touches1 = [NSSet setWithObject:@1]; id event1 = OCMClassMock([UIEvent class]); [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); @@ -2284,11 +2280,10 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); flutterPlatformViewsController->CompositeEmbeddedView(2); - // Not calling |flutterPlatformViewsController::SubmitFrame| so that the platform views are - not - // added to flutter_view_. + // Not calling |flutterPlatformViewsController::SubmitFrame| so that the platform views are not + // added to flutter_view_. - XCTAssertNotNil(gMockPlatformView); + XCTAssertNotNil(gMockPlatformView); flutterPlatformViewsController->Reset(); } XCTAssertNil(gMockPlatformView); @@ -2768,14 +2763,14 @@ - (void)testClipMaskViewIsReused { XCTAssertNil(childClippingView1.maskView); } -// Return true if a correct visual effect view is found. It also implies all the validation in -this - // method passes. - // - // There are two fail states for this method. 1. One of the XCTAssert method failed; or 2. No - // correct visual effect view found. - - (BOOL)validateOneVisualEffectView : (UIView*)visualEffectView expectedFrame - : (CGRect)frame inputRadius : (CGFloat)inputRadius { +// Return true if a correct visual effect view is found. It also implies all the validation in this +// method passes. +// +// There are two fail states for this method. 1. One of the XCTAssert method failed; or 2. No +// correct visual effect view found. +- (BOOL)validateOneVisualEffectView:(UIView*)visualEffectView + expectedFrame:(CGRect)frame + inputRadius:(CGFloat)inputRadius { XCTAssertTrue(CGRectEqualToRect(visualEffectView.frame, frame)); for (UIView* view in visualEffectView.subviews) { if (![view isKindOfClass:NSClassFromString(@"_UIVisualEffectBackdropView")]) { @@ -2833,8 +2828,7 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash { result); { - // **** First frame, view id 0, 1 in the composition_order_, disposing view 0 is called. **** - // + // **** First frame, view id 0, 1 in the composition_order_, disposing view 0 is called. **** // // No view should be disposed, or removed from the composition order. flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); flutter::MutatorsStack stack; @@ -2869,15 +2863,14 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash { XCTAssertTrue( flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - // Disposing won't remove embedded views until the view is removed from the - composition_order_ XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); + // Disposing won't remove embedded views until the view is removed from the composition_order_ + XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 2UL); XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(0)); XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); } { - // **** Second frame, view id 1 in the composition_order_, no disposing view is called, **** - // + // **** Second frame, view id 1 in the composition_order_, no disposing view is called, **** // // View 0 is removed from the composition order in this frame, hence also disposed. flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); flutter::MutatorsStack stack; @@ -2897,8 +2890,8 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash { XCTAssertTrue( flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface))); - // Disposing won't remove embedded views until the view is removed from the - composition_order_ XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); + // Disposing won't remove embedded views until the view is removed from the composition_order_ + XCTAssertEqual(flutterPlatformViewsController->EmbeddedViewCount(), 1UL); XCTAssertNil(flutterPlatformViewsController->GetPlatformViewByID(0)); XCTAssertNotNil(flutterPlatformViewsController->GetPlatformViewByID(1)); } diff --git a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m index 1aa093655b319..47d49f3c7779c 100644 --- a/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m +++ b/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m @@ -409,6 +409,7 @@ - (void)testPlatformViewScrollingUnderWidget { waitForExpectations:@[ [[XCTestExpectation alloc] initWithDescription:@"Wait for 5 seconds"] ] timeout:5]; // If the waiter is not interrupted, we know the app is in a valid state after timeout, thus the + // test passes. XCTAssert(waitResult != XCTWaiterResultInterrupted); } From f51790718747a8f22462096d99980ae3a09a3d29 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 12:17:45 -0700 Subject: [PATCH 17/27] add exit 1 --- testing/scenario_app/run_ios_tests.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index a1b60bd24767d..b1332f6280e09 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -59,9 +59,9 @@ if set -o pipefail && xcodebuild -sdk iphonesimulator \ -destination 'platform=iOS Simulator,OS=16.2,name=iPhone SE (3rd generation)' \ clean test \ FLUTTER_ENGINE="$FLUTTER_ENGINE"; then - echo "success" + echo "test success." else - echo "cyanglaz scenario test failed" + echo "test failed." LUCI_TEST_OUTPUTS_PATH="${FLUTTER_TEST_OUTPUTS_DIR:-NULL}" echo "LUCI_TEST_OUTPUTS_PATH ${LUCI_TEST_OUTPUTS_PATH}" @@ -71,6 +71,7 @@ else # So use relative directory instead. zip -q -r ios_scenario_xcresult.zip "./$RESULT_BUNDLE_FOLDER" mv ios_scenario_xcresult.zip $DUMP_PATH + exit 1 fi # echo "Running simulator tests with Impeller" From cc7fe8ece84d4785b02ca5bcc56d6fba61a6498b Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 13:17:57 -0700 Subject: [PATCH 18/27] move to test outputs path --- testing/scenario_app/run_ios_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index b1332f6280e09..575fe317013d0 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -65,12 +65,12 @@ else LUCI_TEST_OUTPUTS_PATH="${FLUTTER_TEST_OUTPUTS_DIR:-NULL}" echo "LUCI_TEST_OUTPUTS_PATH ${LUCI_TEST_OUTPUTS_PATH}" - DUMP_PATH=$LUCI_TEST_OUTPUTS_PATH/ios_scenario_xcresult + # DUMP_PATH=$LUCI_TEST_OUTPUTS_PATH echo "Zip" # Using RESULT_BUNDLE_PATH causes the zip containing all the sub directories. # So use relative directory instead. zip -q -r ios_scenario_xcresult.zip "./$RESULT_BUNDLE_FOLDER" - mv ios_scenario_xcresult.zip $DUMP_PATH + mv -f ios_scenario_xcresult.zip $LUCI_TEST_OUTPUTS_PATH exit 1 fi From a527a309c48e241bafbb9f2f716565e789a224cb Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 14:22:11 -0700 Subject: [PATCH 19/27] add impeller --- testing/scenario_app/run_ios_tests.sh | 41 ++++++++++++++++++--------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index 575fe317013d0..9d0fbcb2399f9 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -71,19 +71,32 @@ else # So use relative directory instead. zip -q -r ios_scenario_xcresult.zip "./$RESULT_BUNDLE_FOLDER" mv -f ios_scenario_xcresult.zip $LUCI_TEST_OUTPUTS_PATH - exit 1 + # exit 1 fi -# echo "Running simulator tests with Impeller" -# echo "" - -# # Skip testFontRenderingWhenSuppliedWithBogusFont: https://github.com/flutter/flutter/issues/113250 -# if set -o pipefail && xcodebuild -sdk iphonesimulator \ -# -scheme Scenarios \ -# -destination 'platform=iOS Simulator,OS=16.2,name=iPhone SE (3rd generation)' \ -# clean test \ -# FLUTTER_ENGINE="$FLUTTER_ENGINE" \ -# -skip-testing "ScenariosUITests/BogusFontTextTest/testFontRenderingWhenSuppliedWithBogusFont" \ -# INFOPLIST_FILE="Scenarios/Info_Impeller.plist"; then # Plist with FLTEnableImpeller=YES -# echo "cyanglaz scenario test failed" -# fi +echo "Running simulator tests with Impeller" +echo "" + +# Skip testFontRenderingWhenSuppliedWithBogusFont: https://github.com/flutter/flutter/issues/113250 +if set -o pipefail && xcodebuild -sdk iphonesimulator \ + -scheme Scenarios \ + -resultBundlePath "$RESULT_BUNDLE_PATH/ios_scenario_impeller.xcresult" \ + -destination 'platform=iOS Simulator,OS=16.2,name=iPhone SE (3rd generation)' \ + clean test \ + FLUTTER_ENGINE="$FLUTTER_ENGINE" \ + -skip-testing "ScenariosUITests/BogusFontTextTest/testFontRenderingWhenSuppliedWithBogusFont" \ + INFOPLIST_FILE="Scenarios/Info_Impeller.plist"; then # Plist with FLTEnableImpeller=YES + echo "test success." +else + echo "test failed." + + LUCI_TEST_OUTPUTS_PATH="${FLUTTER_TEST_OUTPUTS_DIR:-NULL}" + echo "LUCI_TEST_OUTPUTS_PATH ${LUCI_TEST_OUTPUTS_PATH}" + # DUMP_PATH=$LUCI_TEST_OUTPUTS_PATH + echo "Zip" + # Using RESULT_BUNDLE_PATH causes the zip containing all the sub directories. + # So use relative directory instead. + zip -q -r ios_scenario_xcresult.zip "./$RESULT_BUNDLE_FOLDER" + mv -f ios_scenario_xcresult.zip $LUCI_TEST_OUTPUTS_PATH + exit 1 +fi From 0059953466878dac663f8111080f7d062fa82eb9 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 14:23:12 -0700 Subject: [PATCH 20/27] add impeller --- testing/scenario_app/run_ios_tests.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index 9d0fbcb2399f9..a005805118106 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -80,7 +80,7 @@ echo "" # Skip testFontRenderingWhenSuppliedWithBogusFont: https://github.com/flutter/flutter/issues/113250 if set -o pipefail && xcodebuild -sdk iphonesimulator \ -scheme Scenarios \ - -resultBundlePath "$RESULT_BUNDLE_PATH/ios_scenario_impeller.xcresult" \ + -resultBundlePath "$RESULT_BUNDLE_PATH/ios_scenario.xcresult" \ -destination 'platform=iOS Simulator,OS=16.2,name=iPhone SE (3rd generation)' \ clean test \ FLUTTER_ENGINE="$FLUTTER_ENGINE" \ @@ -96,7 +96,7 @@ else echo "Zip" # Using RESULT_BUNDLE_PATH causes the zip containing all the sub directories. # So use relative directory instead. - zip -q -r ios_scenario_xcresult.zip "./$RESULT_BUNDLE_FOLDER" - mv -f ios_scenario_xcresult.zip $LUCI_TEST_OUTPUTS_PATH + zip -q -r ios_scenario_impeller_xcresult.zip "./$RESULT_BUNDLE_FOLDER" + mv -f ios_scenario_impeller_xcresult.zip $LUCI_TEST_OUTPUTS_PATH exit 1 fi From aa826341ce7a0ad6eb46edcae0f27aa96456324d Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 15:13:38 -0700 Subject: [PATCH 21/27] fix --- testing/scenario_app/run_ios_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index a005805118106..edf55b9d4c33f 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -71,7 +71,7 @@ else # So use relative directory instead. zip -q -r ios_scenario_xcresult.zip "./$RESULT_BUNDLE_FOLDER" mv -f ios_scenario_xcresult.zip $LUCI_TEST_OUTPUTS_PATH - # exit 1 + exit 1 fi echo "Running simulator tests with Impeller" From 40773237ecad9b97ddb50a870fa514ae24f9889c Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 20:52:23 -0700 Subject: [PATCH 22/27] refactor script --- testing/scenario_app/run_ios_tests.sh | 39 +++++++++++---------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index edf55b9d4c33f..204861ac0e2b3 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -44,12 +44,23 @@ defaults write com.apple.iphonesimulator RotateWindowWhenSignaledByGuest -int 1 SCENARIO_PATH=$SRC_DIR/out/$FLUTTER_ENGINE/scenario_app/Scenarios cd $SCENARIO_PATH -echo "Running simulator tests with Skia" -echo "" - RESULT_BUNDLE_FOLDER="ios_scenario_xcresult" RESULT_BUNDLE_PATH="${SCENARIO_PATH}/${RESULT_BUNDLE_FOLDER}" +# Zip and upload xcresult to luci. +# First parameter ($1) is the zip output name. +ZIP_AND_UPLOAD_XCRESULT_TO_LUCI () { + LUCI_TEST_OUTPUTS_PATH="${FLUTTER_TEST_OUTPUTS_DIR:-NULL}" + # Using RESULT_BUNDLE_PATH causes the zip containing all the sub directories. + # So use relative directory instead. + zip -q -r $1 "./$RESULT_BUNDLE_FOLDER" + mv -f $1 $LUCI_TEST_OUTPUTS_PATH + exit 1 +} + +echo "Running simulator tests with Skia" +echo "" + mktemp -d $RESULT_BUNDLE_PATH trap 'rm -rf $RESULT_BUNDLE_PATH' EXIT @@ -62,16 +73,7 @@ if set -o pipefail && xcodebuild -sdk iphonesimulator \ echo "test success." else echo "test failed." - - LUCI_TEST_OUTPUTS_PATH="${FLUTTER_TEST_OUTPUTS_DIR:-NULL}" - echo "LUCI_TEST_OUTPUTS_PATH ${LUCI_TEST_OUTPUTS_PATH}" - # DUMP_PATH=$LUCI_TEST_OUTPUTS_PATH - echo "Zip" - # Using RESULT_BUNDLE_PATH causes the zip containing all the sub directories. - # So use relative directory instead. - zip -q -r ios_scenario_xcresult.zip "./$RESULT_BUNDLE_FOLDER" - mv -f ios_scenario_xcresult.zip $LUCI_TEST_OUTPUTS_PATH - exit 1 + ZIP_AND_UPLOAD_XCRESULT_TO_LUCI ios_scenario_xcresult.zip fi echo "Running simulator tests with Impeller" @@ -89,14 +91,5 @@ if set -o pipefail && xcodebuild -sdk iphonesimulator \ echo "test success." else echo "test failed." - - LUCI_TEST_OUTPUTS_PATH="${FLUTTER_TEST_OUTPUTS_DIR:-NULL}" - echo "LUCI_TEST_OUTPUTS_PATH ${LUCI_TEST_OUTPUTS_PATH}" - # DUMP_PATH=$LUCI_TEST_OUTPUTS_PATH - echo "Zip" - # Using RESULT_BUNDLE_PATH causes the zip containing all the sub directories. - # So use relative directory instead. - zip -q -r ios_scenario_impeller_xcresult.zip "./$RESULT_BUNDLE_FOLDER" - mv -f ios_scenario_impeller_xcresult.zip $LUCI_TEST_OUTPUTS_PATH - exit 1 + ZIP_AND_UPLOAD_XCRESULT_TO_LUCI ios_scenario_impeller_xcresult.zip fi From 2537268a08ca997c608232fbacd116b83a735f16 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 10 May 2023 21:15:59 -0700 Subject: [PATCH 23/27] refactor script --- testing/scenario_app/run_ios_tests.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index 204861ac0e2b3..d8a54146d6f16 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -50,11 +50,13 @@ RESULT_BUNDLE_PATH="${SCENARIO_PATH}/${RESULT_BUNDLE_FOLDER}" # Zip and upload xcresult to luci. # First parameter ($1) is the zip output name. ZIP_AND_UPLOAD_XCRESULT_TO_LUCI () { - LUCI_TEST_OUTPUTS_PATH="${FLUTTER_TEST_OUTPUTS_DIR:-NULL}" # Using RESULT_BUNDLE_PATH causes the zip containing all the sub directories. # So use relative directory instead. + echo $1 zip -q -r $1 "./$RESULT_BUNDLE_FOLDER" - mv -f $1 $LUCI_TEST_OUTPUTS_PATH + if ( -z "$FLUTTER_TEST_OUTPUTS_DIR") then + mv -f $1 $FLUTTER_TEST_OUTPUTS_DIR + fi exit 1 } @@ -73,7 +75,7 @@ if set -o pipefail && xcodebuild -sdk iphonesimulator \ echo "test success." else echo "test failed." - ZIP_AND_UPLOAD_XCRESULT_TO_LUCI ios_scenario_xcresult.zip + ZIP_AND_UPLOAD_XCRESULT_TO_LUCI "ios_scenario_xcresult.zip" fi echo "Running simulator tests with Impeller" @@ -91,5 +93,5 @@ if set -o pipefail && xcodebuild -sdk iphonesimulator \ echo "test success." else echo "test failed." - ZIP_AND_UPLOAD_XCRESULT_TO_LUCI ios_scenario_impeller_xcresult.zip + ZIP_AND_UPLOAD_XCRESULT_TO_LUCI "ios_scenario_impeller_xcresult.zip" fi From 55fad6b0f204d00e876ac21e30f7f605cfe89539 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Thu, 11 May 2023 09:44:42 -0700 Subject: [PATCH 24/27] fix --- testing/scenario_app/run_ios_tests.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index d8a54146d6f16..ac71ba4b139c8 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -50,13 +50,11 @@ RESULT_BUNDLE_PATH="${SCENARIO_PATH}/${RESULT_BUNDLE_FOLDER}" # Zip and upload xcresult to luci. # First parameter ($1) is the zip output name. ZIP_AND_UPLOAD_XCRESULT_TO_LUCI () { - # Using RESULT_BUNDLE_PATH causes the zip containing all the sub directories. - # So use relative directory instead. + # Using absolute directory causes the zip containing all the sub directories. + # So use relative directory (./$RESULT_BUNDLE_FOLDER) instead. echo $1 zip -q -r $1 "./$RESULT_BUNDLE_FOLDER" - if ( -z "$FLUTTER_TEST_OUTPUTS_DIR") then - mv -f $1 $FLUTTER_TEST_OUTPUTS_DIR - fi + mv -f $1 $FLUTTER_TEST_OUTPUTS_DIR exit 1 } From ce5eee4e57ffa6231d5e6ed90c04bd436812cfd8 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Thu, 11 May 2023 20:38:16 -0700 Subject: [PATCH 25/27] update script --- testing/scenario_app/run_ios_tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index ac71ba4b139c8..3f14e5e8d622c 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -62,7 +62,6 @@ echo "Running simulator tests with Skia" echo "" mktemp -d $RESULT_BUNDLE_PATH -trap 'rm -rf $RESULT_BUNDLE_PATH' EXIT if set -o pipefail && xcodebuild -sdk iphonesimulator \ -scheme Scenarios \ @@ -75,6 +74,7 @@ else echo "test failed." ZIP_AND_UPLOAD_XCRESULT_TO_LUCI "ios_scenario_xcresult.zip" fi +rm -rf $RESULT_BUNDLE_PATH echo "Running simulator tests with Impeller" echo "" @@ -93,3 +93,4 @@ else echo "test failed." ZIP_AND_UPLOAD_XCRESULT_TO_LUCI "ios_scenario_impeller_xcresult.zip" fi +rm -rf $RESULT_BUNDLE_PATH From d39b6b1c2fcb6ab654dee273c5cdae5439ada8cf Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Fri, 12 May 2023 10:13:52 -0700 Subject: [PATCH 26/27] update script --- testing/run_tests.py | 44 +++++++++++++-------------- testing/scenario_app/run_ios_tests.sh | 11 +++---- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/testing/run_tests.py b/testing/run_tests.py index d5c16f0209dbd..0d7962f9dc98a 100755 --- a/testing/run_tests.py +++ b/testing/run_tests.py @@ -754,29 +754,28 @@ def run_objc_tests(ios_variant='ios_debug_sim_unopt', test_filter=None): BUILDROOT_DIR, 'flutter', 'testing', 'ios', 'IosUnitTests' ) - result_bundle_temp = tempfile.TemporaryDirectory( - suffix='ios_embedding_xcresult' - ).name - result_bundle_path = os.path.join(result_bundle_temp, 'ios_embedding') - - # Avoid using xcpretty unless the following can be addressed: - # - Make sure all relevant failure output is printed on a failure. - # - Make sure that a failing exit code is set for CI. - # See https://github.com/flutter/flutter/issues/63742 - test_command = [ - 'xcodebuild ' - '-sdk iphonesimulator ' - '-scheme IosUnitTests ' - '-resultBundlePath ' + result_bundle_path + " -destination name='" + - new_simulator_name + "' " - 'test ' - 'FLUTTER_ENGINE=' + ios_variant - ] - if test_filter is not None: - test_command[0] = test_command[0] + ' -only-testing:%s' % test_filter - try: + with tempfile.TemporaryDirectory(suffix='ios_embedding_xcresult' + ) as result_bundle_temp: + result_bundle_path = os.path.join(result_bundle_temp, 'ios_embedding') + + # Avoid using xcpretty unless the following can be addressed: + # - Make sure all relevant failure output is printed on a failure. + # - Make sure that a failing exit code is set for CI. + # See https://github.com/flutter/flutter/issues/63742 + test_command = [ + 'xcodebuild ' + '-sdk iphonesimulator ' + '-scheme IosUnitTests ' + '-resultBundlePath ' + result_bundle_path + ' ' + '-destination name=' + new_simulator_name + ' ' + 'test ' + 'FLUTTER_ENGINE=' + ios_variant + ] + if test_filter is not None: + test_command[0] = test_command[0] + ' -only-testing:%s' % test_filter run_cmd(test_command, cwd=ios_unit_test_dir, shell=True) - except: + + # except: # The LUCI environment may provide a variable containing a directory path # for additional output files that will be uploaded to cloud storage. # Upload the xcresult when the tests fail. @@ -790,7 +789,6 @@ def run_objc_tests(ios_variant='ios_debug_sim_unopt', test_filter=None): ) # xcresults contain many little files. Archive the bundle before upload. shutil.make_archive(dump_path, 'zip', root_dir=xcresult_bundle) - raise finally: delete_simulator(new_simulator_name) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index 3f14e5e8d622c..f0518a776ac62 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -49,10 +49,9 @@ RESULT_BUNDLE_PATH="${SCENARIO_PATH}/${RESULT_BUNDLE_FOLDER}" # Zip and upload xcresult to luci. # First parameter ($1) is the zip output name. -ZIP_AND_UPLOAD_XCRESULT_TO_LUCI () { - # Using absolute directory causes the zip containing all the sub directories. - # So use relative directory (./$RESULT_BUNDLE_FOLDER) instead. - echo $1 +zip_and_upload_xcresult_to_luci () { + # We don't want the zip to contain the abusolute path, + # so use relative path (./$RESULT_BUNDLE_FOLDER) instead. zip -q -r $1 "./$RESULT_BUNDLE_FOLDER" mv -f $1 $FLUTTER_TEST_OUTPUTS_DIR exit 1 @@ -72,7 +71,7 @@ if set -o pipefail && xcodebuild -sdk iphonesimulator \ echo "test success." else echo "test failed." - ZIP_AND_UPLOAD_XCRESULT_TO_LUCI "ios_scenario_xcresult.zip" + zip_and_upload_xcresult_to_luci "ios_scenario_xcresult.zip" fi rm -rf $RESULT_BUNDLE_PATH @@ -91,6 +90,6 @@ if set -o pipefail && xcodebuild -sdk iphonesimulator \ echo "test success." else echo "test failed." - ZIP_AND_UPLOAD_XCRESULT_TO_LUCI "ios_scenario_impeller_xcresult.zip" + zip_and_upload_xcresult_to_luci "ios_scenario_impeller_xcresult.zip" fi rm -rf $RESULT_BUNDLE_PATH From 4e1dffb723a3f543fa8b8a6779f456de41b2f22d Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Fri, 12 May 2023 12:52:03 -0700 Subject: [PATCH 27/27] fix sript --- testing/scenario_app/run_ios_tests.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/scenario_app/run_ios_tests.sh b/testing/scenario_app/run_ios_tests.sh index f0518a776ac62..0034a42e4899a 100755 --- a/testing/scenario_app/run_ios_tests.sh +++ b/testing/scenario_app/run_ios_tests.sh @@ -42,6 +42,7 @@ fi defaults write com.apple.iphonesimulator RotateWindowWhenSignaledByGuest -int 1 SCENARIO_PATH=$SRC_DIR/out/$FLUTTER_ENGINE/scenario_app/Scenarios +pushd . cd $SCENARIO_PATH RESULT_BUNDLE_FOLDER="ios_scenario_xcresult" @@ -93,3 +94,5 @@ else zip_and_upload_xcresult_to_luci "ios_scenario_impeller_xcresult.zip" fi rm -rf $RESULT_BUNDLE_PATH + +popd