Flutter Engine
The Flutter Engine
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 "flutter/testing/testing.h"
13
14namespace flutter::testing {
15
16namespace {
17// Returns an engine configured for the text fixture resource configuration.
18FlutterEngine* CreateTestEngine() {
19 NSString* fixtures = @(testing::GetFixturesPath());
20 FlutterDartProject* project = [[FlutterDartProject alloc]
21 initWithAssetsPath:fixtures
22 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
23 return [[FlutterEngine alloc] initWithName:@"test" project:project allowHeadlessExecution:true];
24}
25} // namespace
26
27TEST(FlutterTextInputSemanticsObjectTest, DoesInitialize) {
28 FlutterEngine* engine = CreateTestEngine();
29 {
31 nibName:nil
32 bundle:nil];
33 [viewController loadView];
34 // Create a NSWindow so that the native text field can become first responder.
35 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
36 styleMask:NSBorderlessWindowMask
37 backing:NSBackingStoreBuffered
38 defer:NO];
39 window.contentView = viewController.view;
40
42
43 auto bridge = viewController.accessibilityBridge.lock();
45 ui::AXTree tree;
46 ui::AXNode ax_node(&tree, nullptr, 0, 0);
47 ui::AXNodeData node_data;
48 node_data.SetValue("initial text");
49 ax_node.SetData(node_data);
50 delegate.Init(viewController.accessibilityBridge, &ax_node);
51 // Verify that a FlutterTextField is attached to the view.
52 FlutterTextPlatformNode text_platform_node(&delegate, viewController);
53 id native_accessibility = text_platform_node.GetNativeViewAccessible();
54 EXPECT_TRUE([native_accessibility isKindOfClass:[FlutterTextField class]]);
55 auto subviews = [viewController.view subviews];
56 EXPECT_EQ([subviews count], 2u);
57 EXPECT_TRUE([subviews[0] isKindOfClass:[FlutterTextField class]]);
58 FlutterTextField* nativeTextField = subviews[0];
59 EXPECT_EQ(text_platform_node.GetNativeViewAccessible(), nativeTextField);
60 }
61
62 [engine shutDownEngine];
63 engine = nil;
64 // Pump the event loop to make sure no stray nodes cause crashes after the
65 // engine has been destroyed.
66 // From issue: https://github.com/flutter/flutter/issues/115599
67 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
68}
69
70} // namespace flutter::testing
int count
Definition: FontMgrTest.cpp:50
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 ...
The ax platform node for a text field.
gfx::NativeViewAccessible GetNativeViewAccessible() override
void SetData(const AXNodeData &src)
Definition: ax_node.cc:373
GLFWwindow * window
Definition: main.cc:45
FlutterEngine engine
Definition: main.cc:68
std::weak_ptr< flutter::AccessibilityBridgeMac > accessibilityBridge()
FlutterViewController * viewController
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
TEST(DisplayListComplexity, EmptyDisplayList)
void SetValue(const std::string &value)
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678