Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 80db950

Browse files
committed
Add test
1 parent 3ca3a12 commit 80db950

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,61 @@
55
#import <XCTest/XCTest.h>
66

77
#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"
810
#import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h"
911
#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
1012
#import "third_party/ocmock/Source/OCMock/OCMock.h"
1113

1214
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
1363

1464
namespace flutter {
1565
namespace {
@@ -131,4 +181,55 @@ - (void)testUpdateSemanticsOneNode {
131181
OCMVerifyAll(mockFlutterView);
132182
}
133183

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+
134235
@end

0 commit comments

Comments
 (0)