|
5 | 5 | #import <XCTest/XCTest.h> |
6 | 6 |
|
7 | 7 | #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" |
| 8 | +#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h" |
| 9 | +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" |
8 | 10 | #import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h" |
9 | 11 | #import "flutter/shell/platform/darwin/ios/platform_view_ios.h" |
10 | 12 | #import "third_party/ocmock/Source/OCMock/OCMock.h" |
11 | 13 |
|
12 | 14 | FLUTTER_ASSERT_NOT_ARC |
| 15 | +@class MockPlatformView; |
| 16 | +MockPlatformView* mockPlatformView = nil; |
| 17 | + |
| 18 | +@interface MockPlatformView : UIView |
| 19 | +@end |
| 20 | +@implementation MockPlatformView |
| 21 | + |
| 22 | +- (void)dealloc { |
| 23 | + mockPlatformView = nil; |
| 24 | + [super dealloc]; |
| 25 | +} |
| 26 | + |
| 27 | +@end |
| 28 | + |
| 29 | +@interface MockFlutterPlatformView : NSObject <FlutterPlatformView> |
| 30 | +@property(nonatomic, strong) UIView* view; |
| 31 | +@end |
| 32 | + |
| 33 | +@implementation MockFlutterPlatformView |
| 34 | + |
| 35 | +- (instancetype)init { |
| 36 | + if (self = [super init]) { |
| 37 | + MockPlatformView* view = [[MockPlatformView new] autorelease]; |
| 38 | + mockPlatformView = view; |
| 39 | + self.view = view; |
| 40 | + } |
| 41 | + return self; |
| 42 | +} |
| 43 | + |
| 44 | +- (void)dealloc { |
| 45 | + self.view = nil; |
| 46 | + [super dealloc]; |
| 47 | +} |
| 48 | + |
| 49 | +@end |
| 50 | + |
| 51 | +@interface MockFlutterPlatformFactory : NSObject <FlutterPlatformViewFactory> |
| 52 | +@end |
| 53 | + |
| 54 | +@implementation MockFlutterPlatformFactory |
| 55 | +- (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame |
| 56 | + viewIdentifier:(int64_t)viewId |
| 57 | + arguments:(id _Nullable)args { |
| 58 | + MockFlutterPlatformView* platformView = [[MockFlutterPlatformView new] autorelease]; |
| 59 | + return platformView; |
| 60 | +} |
| 61 | + |
| 62 | +@end |
13 | 63 |
|
14 | 64 | namespace flutter { |
15 | 65 | namespace { |
@@ -131,4 +181,55 @@ - (void)testUpdateSemanticsOneNode { |
131 | 181 | OCMVerifyAll(mockFlutterView); |
132 | 182 | } |
133 | 183 |
|
| 184 | +- (void)testSemanticsDeallocated { |
| 185 | + @autoreleasepool { |
| 186 | + flutter::MockDelegate mock_delegate; |
| 187 | + auto thread_task_runner = CreateNewThread("AccessibilityBridgeTest"); |
| 188 | + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, |
| 189 | + /*platform=*/thread_task_runner, |
| 190 | + /*raster=*/thread_task_runner, |
| 191 | + /*ui=*/thread_task_runner, |
| 192 | + /*io=*/thread_task_runner); |
| 193 | + auto platform_view = std::make_unique<flutter::PlatformViewIOS>( |
| 194 | + /*delegate=*/mock_delegate, |
| 195 | + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, |
| 196 | + /*task_runners=*/runners); |
| 197 | + id mockFlutterView = OCMClassMock([FlutterView class]); |
| 198 | + std::string label = "some label"; |
| 199 | + |
| 200 | + flutter::FlutterPlatformViewsController* flutterPlatformViewsController = |
| 201 | + (flutter::FlutterPlatformViewsController*)(new flutter::FlutterPlatformViewsController()); |
| 202 | + flutterPlatformViewsController->SetFlutterView(mockFlutterView); |
| 203 | + |
| 204 | + MockFlutterPlatformFactory* factory = [[MockFlutterPlatformFactory new] autorelease]; |
| 205 | + flutterPlatformViewsController->RegisterViewFactory( |
| 206 | + factory, @"MockFlutterPlatformView", |
| 207 | + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); |
| 208 | + FlutterResult result = ^(id result) { |
| 209 | + }; |
| 210 | + flutterPlatformViewsController->OnMethodCall( |
| 211 | + [FlutterMethodCall |
| 212 | + methodCallWithMethodName:@"create" |
| 213 | + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], |
| 214 | + result); |
| 215 | + |
| 216 | + __block auto bridge = std::make_unique<flutter::AccessibilityBridge>( |
| 217 | + /*view=*/mockFlutterView, |
| 218 | + /*platform_view=*/platform_view.get(), |
| 219 | + /*platform_views_controller=*/flutterPlatformViewsController); |
| 220 | + |
| 221 | + flutter::SemanticsNodeUpdates nodes; |
| 222 | + flutter::SemanticsNode semantics_node; |
| 223 | + semantics_node.id = 2; |
| 224 | + semantics_node.platformViewId = 2; |
| 225 | + semantics_node.label = label; |
| 226 | + nodes[kRootNodeId] = semantics_node; |
| 227 | + flutter::CustomAccessibilityActionUpdates actions; |
| 228 | + bridge->UpdateSemantics(/*nodes=*/nodes, /*actions=*/actions); |
| 229 | + flutterPlatformViewsController->Reset(); |
| 230 | + delete flutterPlatformViewsController; |
| 231 | + } |
| 232 | + XCTAssertNil(mockPlatformView); |
| 233 | +} |
| 234 | + |
134 | 235 | @end |
0 commit comments