| Flutter macOS Embedder |

FlutterTextInputSemanticsObjectTest.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterViewController.h"
6 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
7 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
8 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h"
9 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputSemanticsObject.h"
10 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
11
12 #import <OCMock/OCMock.h>
13 #import "flutter/testing/testing.h"
14
15 namespace flutter::testing {
16
17 namespace {
18 // Returns an engine configured for the text fixture resource configuration.
19 FlutterEngine* CreateTestEngine() {
20 NSString* fixtures = @(testing::GetFixturesPath());
21 FlutterDartProject* project = [[FlutterDartProject alloc]
22 initWithAssetsPath:fixtures
23 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
24 return [[FlutterEngine alloc] initWithName:@"test" project:project allowHeadlessExecution:true];
25 }
26 } // namespace
27
28 TEST(FlutterTextInputSemanticsObjectTest, DoesInitialize) {
29 FlutterEngine* engine = CreateTestEngine();
30 {
31 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
32 nibName:nil
33 bundle:nil];
34 [viewController loadView];
35 // Create a NSWindow so that the native text field can become first responder.
36 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
37 styleMask:NSBorderlessWindowMask
38 backing:NSBackingStoreBuffered
39 defer:NO];
40 window.contentView = viewController.view;
41
42 engine.semanticsEnabled = YES;
43
44 auto bridge = viewController.accessibilityBridge.lock();
45 FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
46 ui::AXTree tree;
47 ui::AXNode ax_node(&tree, nullptr, 0, 0);
48 ui::AXNodeData node_data;
49 node_data.SetValue("initial text");
50 ax_node.SetData(node_data);
51 delegate.Init(viewController.accessibilityBridge, &ax_node);
52 // Verify that a FlutterTextField is attached to the view.
53 FlutterTextPlatformNode text_platform_node(&delegate, viewController);
54 id native_accessibility = text_platform_node.GetNativeViewAccessible();
55 EXPECT_TRUE([native_accessibility isKindOfClass:[FlutterTextField class]]);
56 auto subviews = [viewController.view subviews];
57 EXPECT_EQ([subviews count], 2u);
58 EXPECT_TRUE([subviews[0] isKindOfClass:[FlutterTextField class]]);
59 FlutterTextField* nativeTextField = subviews[0];
60 EXPECT_EQ(text_platform_node.GetNativeViewAccessible(), nativeTextField);
61 }
62
63 [engine shutDownEngine];
64 engine = nil;
65 // Pump the event loop to make sure no stray nodes cause crashes after the
66 // engine has been destroyed.
67 // From issue: https://github.com/flutter/flutter/issues/115599
68 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
69 }
70
71 } // namespace flutter::testing
flutter::FlutterPlatformNodeDelegateMac::Init
void Init(std::weak_ptr< OwnerBridge > bridge, ui::AXNode *node) override
Called only once, immediately after construction. The constructor doesn't take any arguments because ...
Definition: FlutterPlatformNodeDelegateMac.mm:28
FlutterEngine
Definition: FlutterEngine.h:30
FlutterViewController
Definition: FlutterViewController.h:62
flutter::FlutterTextPlatformNode
The ax platform node for a text field.
Definition: FlutterTextInputSemanticsObject.h:19
FlutterTextInputPlugin.h
FlutterEngine_Internal.h
flutter::FlutterTextPlatformNode::GetNativeViewAccessible
gfx::NativeViewAccessible GetNativeViewAccessible() override
Definition: FlutterTextInputSemanticsObject.mm:179
flutter::testing
Definition: AccessibilityBridgeMacTest.mm:11
flutter::testing::TEST
TEST(AccessibilityBridgeMacTest, SendsAccessibilityCreateNotificationToWindowOfFlutterView)
Definition: AccessibilityBridgeMacTest.mm:61
FlutterDartProject_Internal.h
FlutterViewController_Internal.h
FlutterTextInputSemanticsObject.h
FlutterDartProject
Definition: FlutterDartProject.mm:24
FlutterTextField
Definition: FlutterTextInputSemanticsObject.h:78
flutter::FlutterPlatformNodeDelegateMac
Definition: FlutterPlatformNodeDelegateMac.h:22
FlutterViewController.h