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

Commit 9487a06

Browse files
committed
Add unsupported event test
1 parent 3942683 commit 9487a06

2 files changed

Lines changed: 82 additions & 28 deletions

File tree

shell/platform/windows/fixtures/main.dart

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,36 +59,65 @@ void sendAccessibilityAnnouncement() async {
5959
await semanticsChanged;
6060
}
6161

62-
// Serializers for data types are in the framework, so this will be hardcoded.
62+
// Standard message codec magic number identifiers.
63+
// See: https://github.com/flutter/flutter/blob/ee94fe262b63b0761e8e1f889ae52322fef068d2/packages/flutter/lib/src/services/message_codecs.dart#L262
6364
const int valueMap = 13, valueString = 7;
64-
// Corresponds to:
65-
// Map<String, Object> data =
66-
// {"type": "announce", "data": {"message": ""}};
65+
66+
// Corresponds to: {"type": "announcement", "data": {"message": "hello"}}
67+
// See: https://github.com/flutter/flutter/blob/b781da9b5822de1461a769c3b245075359f5464d/packages/flutter/lib/src/semantics/semantics_event.dart#L86
68+
final Uint8List data = Uint8List.fromList([
69+
// Map with 2 entries
70+
valueMap, 2,
71+
// Map key: "type"
72+
valueString, 'type'.length, ...'type'.codeUnits,
73+
// Map value: "announcement"
74+
valueString, 'announcement'.length, ...'announcement'.codeUnits,
75+
// Map key: "data"
76+
valueString, 'data'.length, ...'data'.codeUnits,
77+
// Map value: map with 1 entry
78+
valueMap, 1,
79+
// Map key: "message"
80+
valueString, 'message'.length, ...'message'.codeUnits,
81+
// Map value: "hello"
82+
valueString, 'hello'.length, ...'hello'.codeUnits,
83+
]);
84+
final ByteData byteData = data.buffer.asByteData();
85+
86+
ui.PlatformDispatcher.instance.sendPlatformMessage(
87+
'flutter/accessibility',
88+
byteData,
89+
(ByteData? _) => signal(),
90+
);
91+
}
92+
93+
@pragma('vm:entry-point')
94+
void sendAccessibilityTooltipEvent() async {
95+
// Wait until semantics are enabled.
96+
if (!ui.PlatformDispatcher.instance.semanticsEnabled) {
97+
await semanticsChanged;
98+
}
99+
100+
// Standard message codec magic number identifiers.
101+
// See: https://github.com/flutter/flutter/blob/ee94fe262b63b0761e8e1f889ae52322fef068d2/packages/flutter/lib/src/services/message_codecs.dart#L262
102+
const int valueMap = 13, valueString = 7;
103+
104+
// Corresponds to: {"type": "tooltip", "data": {"message": "hello"}}
105+
// See: https://github.com/flutter/flutter/blob/b781da9b5822de1461a769c3b245075359f5464d/packages/flutter/lib/src/semantics/semantics_event.dart#L120
67106
final Uint8List data = Uint8List.fromList([
68-
valueMap, // _valueMap
69-
2, // Size
70-
// key: "type"
71-
valueString,
72-
'type'.length,
73-
...'type'.codeUnits,
74-
// value: "announce"
75-
valueString,
76-
'announce'.length,
77-
...'announce'.codeUnits,
78-
// key: "data"
79-
valueString,
80-
'data'.length,
81-
...'data'.codeUnits,
82-
// value: map
83-
valueMap, // _valueMap
84-
1, // Size
85-
// key: "message"
86-
valueString,
87-
'message'.length,
88-
...'message'.codeUnits,
89-
// value: ""
90-
valueString,
91-
0, // Length of empty string == 0.
107+
// Map with 2 entries
108+
valueMap, 2,
109+
// Map key: "type"
110+
valueString, 'type'.length, ...'type'.codeUnits,
111+
// Map value: "tooltip"
112+
valueString, 'tooltip'.length, ...'tooltip'.codeUnits,
113+
// Map key: "data"
114+
valueString, 'data'.length, ...'data'.codeUnits,
115+
// Map value: map with 1 entry
116+
valueMap, 1,
117+
// Map key: "message"
118+
valueString, 'message'.length, ...'message'.codeUnits,
119+
// Map value: "hello"
120+
valueString, 'hello'.length, ...'hello'.codeUnits,
92121
]);
93122
final ByteData byteData = data.buffer.asByteData();
94123

shell/platform/windows/flutter_windows_engine_unittests.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,31 @@ TEST_F(FlutterWindowsEngineTest, AccessibilityAnnouncement) {
676676
}
677677
}
678678

679+
// Verify the engine does not crash if it receives an accessibility event
680+
// it does not support yet.
681+
TEST_F(FlutterWindowsEngineTest, AccessibilityTooltip) {
682+
auto& context = GetContext();
683+
WindowsConfigBuilder builder{context};
684+
builder.SetDartEntrypoint("sendAccessibilityTooltipEvent");
685+
686+
bool done = false;
687+
auto native_entry =
688+
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
689+
context.AddNativeFunction("Signal", native_entry);
690+
691+
ViewControllerPtr controller{builder.Run()};
692+
ASSERT_NE(controller, nullptr);
693+
694+
auto engine = FlutterDesktopViewControllerGetEngine(controller.get());
695+
auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine);
696+
windows_engine->UpdateSemanticsEnabled(true);
697+
698+
// Rely on timeout mechanism in CI.
699+
while (!done) {
700+
windows_engine->task_runner()->ProcessTasks();
701+
}
702+
}
703+
679704
class MockWindowsLifecycleManager : public WindowsLifecycleManager {
680705
public:
681706
MockWindowsLifecycleManager(FlutterWindowsEngine* engine)

0 commit comments

Comments
 (0)