4#include "flutter/testing/testing.h"
6#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h"
7#import "flutter/shell/platform/darwin/macos/framework/Source/AccessibilityBridgeMac.h"
8#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
9#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
10#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMac.h"
11#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputSemanticsObject.h"
12#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTestUtils.h"
13#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
15#include "flutter/shell/platform/common/accessibility_bridge.h"
16#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
17#include "flutter/third_party/accessibility/ax/ax_action_data.h"
26 initWithAssetsPath:fixtures
27 ICUDataPath:[fixtures stringByAppendingString:
@"/icudtl.dat"]];
43 root.text_selection_base = -1;
44 root.text_selection_extent = -1;
45 root.label =
"accessibility";
48 root.increased_value =
"";
49 root.decreased_value =
"";
52 root.custom_accessibility_actions_count = 0;
53 bridge->AddFlutterSemanticsNodeUpdate(
root);
55 bridge->CommitUpdates();
57 auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
59 NSAccessibilityElement* native_accessibility =
60 root_platform_node_delegate->GetNativeViewAccessible();
61 std::string
value = [native_accessibility.accessibilityValue UTF8String];
63 EXPECT_EQ(native_accessibility.accessibilityRole, NSAccessibilityStaticTextRole);
64 EXPECT_EQ([native_accessibility.accessibilityChildren
count], 0u);
80 root.text_selection_base = 1;
81 root.text_selection_extent = 3;
85 root.value =
"selectable text";
86 root.increased_value =
"";
87 root.decreased_value =
"";
90 root.custom_accessibility_actions_count = 0;
91 bridge->AddFlutterSemanticsNodeUpdate(
root);
93 bridge->CommitUpdates();
95 auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
97 NSAccessibilityElement* native_accessibility =
98 root_platform_node_delegate->GetNativeViewAccessible();
99 std::string
value = [native_accessibility.accessibilityValue UTF8String];
100 EXPECT_EQ(
value,
"selectable text");
101 EXPECT_EQ(native_accessibility.accessibilityRole, NSAccessibilityStaticTextRole);
102 EXPECT_EQ([native_accessibility.accessibilityChildren
count], 0u);
103 NSRange selection = native_accessibility.accessibilitySelectedTextRange;
104 EXPECT_EQ(selection.location, 1u);
105 EXPECT_EQ(selection.length, 2u);
106 std::string selected_text = [native_accessibility.accessibilitySelectedText UTF8String];
107 EXPECT_EQ(selected_text,
"el");
122 root.text_selection_base = -1;
123 root.text_selection_extent = -1;
127 root.value =
"selectable text";
128 root.increased_value =
"";
129 root.decreased_value =
"";
131 root.child_count = 0;
132 root.custom_accessibility_actions_count = 0;
133 bridge->AddFlutterSemanticsNodeUpdate(
root);
135 bridge->CommitUpdates();
137 auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
139 NSAccessibilityElement* native_accessibility =
140 root_platform_node_delegate->GetNativeViewAccessible();
141 NSRange selection = native_accessibility.accessibilitySelectedTextRange;
143 EXPECT_EQ(selection.length, 0u);
154 NSWindow*
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
155 styleMask:NSBorderlessWindowMask
156 backing:NSBackingStoreBuffered
168 root.increased_value =
"";
169 root.decreased_value =
"";
171 root.child_count = 1;
172 int32_t children[] = {1};
173 root.children_in_traversal_order = children;
174 root.custom_accessibility_actions_count = 0;
175 bridge->AddFlutterSemanticsNodeUpdate(
root);
179 child1.
label =
"child 1";
187 bridge->AddFlutterSemanticsNodeUpdate(child1);
189 bridge->CommitUpdates();
191 auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
200 const uint8_t*
data,
size_t data_length) {
209 root_platform_node_delegate->AccessibilityPerformAction(action_data);
212 EXPECT_EQ(called_id, 1u);
214 [
engine setViewController:nil];
229 NSWindow*
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
230 styleMask:NSBorderlessWindowMask
231 backing:NSBackingStoreBuffered
245 root.increased_value =
"";
246 root.decreased_value =
"";
248 root.child_count = 1;
249 int32_t children[] = {1};
250 root.children_in_traversal_order = children;
251 root.custom_accessibility_actions_count = 0;
252 root.rect = {0, 0, 100, 100};
253 root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
254 bridge->AddFlutterSemanticsNodeUpdate(
root);
256 double rectSize = 50;
257 double transformFactor = 0.5;
265 child1.
value =
"textfield";
273 child1.
rect = {0, 0, rectSize, rectSize};
274 child1.
transform = {transformFactor, 0, 0, 0, transformFactor, 0, 0, 0, 1};
275 bridge->AddFlutterSemanticsNodeUpdate(child1);
277 bridge->CommitUpdates();
279 auto child_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
281 id native_accessibility = child_platform_node_delegate->GetNativeViewAccessible();
282 EXPECT_EQ([native_accessibility isKindOfClass:[
FlutterTextField class]], YES);
286 CGRect scaledBounds = [view convertRectToBacking:view.bounds];
287 CGSize scaledSize = scaledBounds.size;
288 double pixelRatio = view.bounds.size.width == 0 ? 1 : scaledSize.width / view.bounds.size.width;
290 double expectedFrameSize = rectSize * transformFactor / pixelRatio;
291 EXPECT_EQ(NSEqualRects(native_text_field.
frame, NSMakeRect(0, 600 - expectedFrameSize,
292 expectedFrameSize, expectedFrameSize)),
295 [native_text_field startEditing];
296 EXPECT_EQ([native_text_field.stringValue isEqualToString:
@"textfield"], YES);
@ kFlutterSemanticsActionTap
@ kFlutterSemanticsFlagIsReadOnly
@ kFlutterSemanticsFlagIsTextField
Whether the semantic node represents a text field.
FlutterEngineProcTable & embedderAPI()
std::weak_ptr< flutter::AccessibilityBridgeMac > accessibilityBridge()
FlutterTextInputPlugin * textInputPlugin
FlutterView * flutterView
FlutterViewController * viewController
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
TEST(DisplayListComplexity, EmptyDisplayList)
static void DispatchSemanticsAction(JNIEnv *env, jobject jcaller, jlong shell_holder, jint id, jint action, jobject args, jint args_position)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
#define MOCK_ENGINE_PROC(proc, mock_impl)
FlutterEngineDispatchSemanticsActionFnPtr DispatchSemanticsAction
const char * increased_value
const char * tooltip
A textual tooltip attached to the node.
size_t custom_accessibility_actions_count
The number of custom accessibility action associated with this node.
int32_t text_selection_extent
The position at which the text selection terminates.
FlutterSemanticsAction actions
The set of semantics actions applicable to this node.
int32_t id
The unique identifier for this node.
FlutterRect rect
The bounding box for this node in its coordinate system.
FlutterTransformation transform
size_t child_count
The number of children this node has.
const char * decreased_value
const char * label
A textual description of the node.
int32_t text_selection_base
The position at which the text selection originates.
const char * hint
A brief description of the result of performing an action on the node.
const char * value
A textual description of the current value of the node.
FlutterSemanticsFlag flags
The set of semantics flags associated with this node.
#define EXPECT_TRUE(handle)