|
27 | 27 |
|
28 | 28 | TEST(FlutterTextInputSemanticsObjectTest, DoesInitialize) { |
29 | 29 | FlutterEngine* engine = CreateTestEngine(); |
30 | | - NSString* fixtures = @(testing::GetFixturesPath()); |
31 | | - FlutterDartProject* project = [[FlutterDartProject alloc] |
32 | | - initWithAssetsPath:fixtures |
33 | | - ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]]; |
34 | | - FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project]; |
35 | | - [viewController loadView]; |
36 | | - [engine setViewController:viewController]; |
37 | | - // Create a NSWindow so that the native text field can become first responder. |
38 | | - NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600) |
39 | | - styleMask:NSBorderlessWindowMask |
40 | | - backing:NSBackingStoreBuffered |
41 | | - defer:NO]; |
42 | | - window.contentView = viewController.view; |
| 30 | + { |
| 31 | + NSString* fixtures = @(testing::GetFixturesPath()); |
| 32 | + FlutterDartProject* project = [[FlutterDartProject alloc] |
| 33 | + initWithAssetsPath:fixtures |
| 34 | + ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]]; |
| 35 | + FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project]; |
| 36 | + [viewController loadView]; |
| 37 | + [engine setViewController:viewController]; |
| 38 | + // Create a NSWindow so that the native text field can become first responder. |
| 39 | + NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600) |
| 40 | + styleMask:NSBorderlessWindowMask |
| 41 | + backing:NSBackingStoreBuffered |
| 42 | + defer:NO]; |
| 43 | + window.contentView = viewController.view; |
| 44 | + |
| 45 | + engine.semanticsEnabled = YES; |
43 | 46 |
|
44 | | - engine.semanticsEnabled = YES; |
| 47 | + auto bridge = engine.accessibilityBridge.lock(); |
| 48 | + FlutterPlatformNodeDelegateMac delegate(bridge, viewController); |
| 49 | + ui::AXTree tree; |
| 50 | + ui::AXNode ax_node(&tree, nullptr, 0, 0); |
| 51 | + ui::AXNodeData node_data; |
| 52 | + node_data.SetValue("initial text"); |
| 53 | + ax_node.SetData(node_data); |
| 54 | + delegate.Init(engine.accessibilityBridge, &ax_node); |
| 55 | + // Verify that a FlutterTextField is attached to the view. |
| 56 | + FlutterTextPlatformNode text_platform_node(&delegate, viewController); |
| 57 | + id native_accessibility = text_platform_node.GetNativeViewAccessible(); |
| 58 | + EXPECT_TRUE([native_accessibility isKindOfClass:[FlutterTextField class]]); |
| 59 | + auto subviews = [viewController.view subviews]; |
| 60 | + EXPECT_EQ([subviews count], 2u); |
| 61 | + EXPECT_TRUE([subviews[0] isKindOfClass:[FlutterTextField class]]); |
| 62 | + FlutterTextField* nativeTextField = subviews[0]; |
| 63 | + EXPECT_EQ(text_platform_node.GetNativeViewAccessible(), nativeTextField); |
| 64 | + } |
45 | 65 |
|
46 | | - auto bridge = engine.accessibilityBridge.lock(); |
47 | | - FlutterPlatformNodeDelegateMac delegate(bridge, viewController); |
48 | | - ui::AXTree tree; |
49 | | - ui::AXNode ax_node(&tree, nullptr, 0, 0); |
50 | | - ui::AXNodeData node_data; |
51 | | - node_data.SetValue("initial text"); |
52 | | - ax_node.SetData(node_data); |
53 | | - delegate.Init(engine.accessibilityBridge, &ax_node); |
54 | | - // Verify that a FlutterTextField is attached to the view. |
55 | | - FlutterTextPlatformNode text_platform_node(&delegate, viewController); |
56 | | - id native_accessibility = text_platform_node.GetNativeViewAccessible(); |
57 | | - EXPECT_TRUE([native_accessibility isKindOfClass:[FlutterTextField class]]); |
58 | | - auto subviews = [viewController.view subviews]; |
59 | | - EXPECT_EQ([subviews count], 2u); |
60 | | - EXPECT_TRUE([subviews[0] isKindOfClass:[FlutterTextField class]]); |
61 | | - FlutterTextField* nativeTextField = subviews[0]; |
62 | | - EXPECT_EQ(text_platform_node.GetNativeViewAccessible(), nativeTextField); |
| 66 | + [engine shutDownEngine]; |
| 67 | + engine = nil; |
| 68 | + // Pump the event loop to make sure no stray nodes cause crashes after the |
| 69 | + // engine has been destroyed. |
| 70 | + // From issue: https://github.com/flutter/flutter/issues/115599 |
| 71 | + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; |
63 | 72 | } |
64 | 73 |
|
65 | 74 | } // namespace flutter::testing |
0 commit comments