15
15
#include " flutter/shell/platform/embedder/embedder.h"
16
16
#include " flutter/shell/platform/embedder/tests/embedder_config_builder.h"
17
17
#include " flutter/testing/testing.h"
18
+ #include " third_party/tonic/converter/dart_converter.h"
19
+
20
+ #include " gmock/gmock.h" // For EXPECT_THAT and matchers
21
+ #include " gtest/gtest.h"
18
22
19
23
// CREATE_NATIVE_ENTRY is leaky by design
20
24
// NOLINTBEGIN(clang-analyzer-core.StackAddressEscape)
@@ -23,6 +27,7 @@ namespace flutter {
23
27
namespace testing {
24
28
25
29
using EmbedderA11yTest = testing::EmbedderTest;
30
+ using ::testing::ElementsAre;
26
31
27
32
constexpr static char kTooltip [] = " tooltip" ;
28
33
@@ -175,9 +180,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
175
180
// Wait for initial NotifySemanticsEnabled(false).
176
181
fml::AutoResetWaitableEvent notify_semantics_enabled_latch;
177
182
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
178
- bool enabled = true ;
179
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
180
- ASSERT_FALSE ( Dart_IsError (handle) );
183
+ Dart_Handle exception = nullptr ;
184
+ bool enabled =
185
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
181
186
ASSERT_FALSE (enabled);
182
187
notify_semantics_enabled_latch.Signal ();
183
188
};
@@ -186,19 +191,19 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
186
191
// Prepare to NotifyAccessibilityFeatures call
187
192
fml::AutoResetWaitableEvent notify_features_latch;
188
193
notify_accessibility_features_callback = [&](Dart_NativeArguments args) {
189
- bool enabled = true ;
190
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
191
- ASSERT_FALSE ( Dart_IsError (handle) );
194
+ Dart_Handle exception = nullptr ;
195
+ bool enabled =
196
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
192
197
ASSERT_FALSE (enabled);
193
198
notify_features_latch.Signal ();
194
199
};
195
200
196
201
// Enable semantics. Wait for NotifySemanticsEnabled(true).
197
202
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_2;
198
203
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
199
- bool enabled = false ;
200
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
201
- ASSERT_FALSE ( Dart_IsError (handle) );
204
+ Dart_Handle exception = nullptr ;
205
+ bool enabled =
206
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
202
207
ASSERT_TRUE (enabled);
203
208
notify_semantics_enabled_latch_2.Signal ();
204
209
};
@@ -212,9 +217,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
212
217
// Set accessibility features: (reduce_motion == true)
213
218
fml::AutoResetWaitableEvent notify_features_latch_2;
214
219
notify_accessibility_features_callback = [&](Dart_NativeArguments args) {
215
- bool enabled = false ;
216
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
217
- ASSERT_FALSE ( Dart_IsError (handle) );
220
+ Dart_Handle exception = nullptr ;
221
+ bool enabled =
222
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
218
223
ASSERT_TRUE (enabled);
219
224
notify_features_latch_2.Signal ();
220
225
};
@@ -231,24 +236,19 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
231
236
// Dispatch a tap to semantics node 42. Wait for NotifySemanticsAction.
232
237
fml::AutoResetWaitableEvent notify_semantics_action_latch;
233
238
notify_semantics_action_callback = [&](Dart_NativeArguments args) {
234
- int64_t node_id = 0 ;
235
- Dart_GetNativeIntegerArgument (args, 0 , &node_id);
239
+ Dart_Handle exception = nullptr ;
240
+ int64_t node_id =
241
+ ::tonic::DartConverter<int64_t >::FromArguments (args, 0 , exception);
236
242
ASSERT_EQ (42 , node_id);
237
243
238
- int64_t action_id;
239
- auto handle = Dart_GetNativeIntegerArgument (args, 1 , &action_id);
240
- ASSERT_FALSE (Dart_IsError (handle));
244
+ int64_t action_id =
245
+ ::tonic::DartConverter<int64_t >::FromArguments (args, 1 , exception);
241
246
ASSERT_EQ (static_cast <int32_t >(flutter::SemanticsAction::kTap ), action_id);
242
247
243
- Dart_Handle semantic_args = Dart_GetNativeArgument (args, 2 );
244
- int64_t data;
245
- Dart_Handle dart_int = Dart_ListGetAt (semantic_args, 0 );
246
- Dart_IntegerToInt64 (dart_int, &data);
247
- ASSERT_EQ (2 , data);
248
-
249
- dart_int = Dart_ListGetAt (semantic_args, 1 );
250
- Dart_IntegerToInt64 (dart_int, &data);
251
- ASSERT_EQ (1 , data);
248
+ std::vector<int64_t > semantic_args =
249
+ ::tonic::DartConverter<std::vector<int64_t >>::FromArguments (args, 2 ,
250
+ exception);
251
+ ASSERT_THAT (semantic_args, ElementsAre (2 , 1 ));
252
252
notify_semantics_action_latch.Signal ();
253
253
};
254
254
std::vector<uint8_t > bytes ({2 , 1 });
@@ -260,8 +260,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
260
260
// Disable semantics. Wait for NotifySemanticsEnabled(false).
261
261
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_3;
262
262
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
263
- bool enabled = true ;
264
- Dart_GetNativeBooleanArgument (args, 0 , &enabled);
263
+ Dart_Handle exception = nullptr ;
264
+ bool enabled =
265
+ ::tonic::DartConverter<bool >::FromArguments (args, 0 , exception);
265
266
ASSERT_FALSE (enabled);
266
267
notify_semantics_enabled_latch_3.Signal ();
267
268
};
@@ -355,9 +356,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingUnstableCallbacks) {
355
356
// Wait for initial NotifySemanticsEnabled(false).
356
357
fml::AutoResetWaitableEvent notify_semantics_enabled_latch;
357
358
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
358
- bool enabled = true ;
359
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
360
- ASSERT_FALSE ( Dart_IsError (handle) );
359
+ Dart_Handle exception = nullptr ;
360
+ bool enabled =
361
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
361
362
ASSERT_FALSE (enabled);
362
363
notify_semantics_enabled_latch.Signal ();
363
364
};
@@ -366,19 +367,19 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingUnstableCallbacks) {
366
367
// Prepare to NotifyAccessibilityFeatures call
367
368
fml::AutoResetWaitableEvent notify_features_latch;
368
369
notify_accessibility_features_callback = [&](Dart_NativeArguments args) {
369
- bool enabled = true ;
370
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
371
- ASSERT_FALSE ( Dart_IsError (handle) );
370
+ Dart_Handle exception = nullptr ;
371
+ bool enabled =
372
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
372
373
ASSERT_FALSE (enabled);
373
374
notify_features_latch.Signal ();
374
375
};
375
376
376
377
// Enable semantics. Wait for NotifySemanticsEnabled(true).
377
378
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_2;
378
379
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
379
- bool enabled = false ;
380
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
381
- ASSERT_FALSE ( Dart_IsError (handle) );
380
+ Dart_Handle exception = nullptr ;
381
+ bool enabled =
382
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
382
383
ASSERT_TRUE (enabled);
383
384
notify_semantics_enabled_latch_2.Signal ();
384
385
};
@@ -392,9 +393,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingUnstableCallbacks) {
392
393
// Set accessibility features: (reduce_motion == true)
393
394
fml::AutoResetWaitableEvent notify_features_latch_2;
394
395
notify_accessibility_features_callback = [&](Dart_NativeArguments args) {
395
- bool enabled = false ;
396
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
397
- ASSERT_FALSE ( Dart_IsError (handle) );
396
+ Dart_Handle exception = nullptr ;
397
+ bool enabled =
398
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
398
399
ASSERT_TRUE (enabled);
399
400
notify_features_latch_2.Signal ();
400
401
};
@@ -411,24 +412,19 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingUnstableCallbacks) {
411
412
// Dispatch a tap to semantics node 42. Wait for NotifySemanticsAction.
412
413
fml::AutoResetWaitableEvent notify_semantics_action_latch;
413
414
notify_semantics_action_callback = [&](Dart_NativeArguments args) {
414
- int64_t node_id = 0 ;
415
- Dart_GetNativeIntegerArgument (args, 0 , &node_id);
415
+ Dart_Handle exception = nullptr ;
416
+ int64_t node_id =
417
+ ::tonic::DartConverter<int64_t >::FromArguments (args, 0 , exception);
416
418
ASSERT_EQ (42 , node_id);
417
419
418
- int64_t action_id;
419
- auto handle = Dart_GetNativeIntegerArgument (args, 1 , &action_id);
420
- ASSERT_FALSE (Dart_IsError (handle));
420
+ int64_t action_id =
421
+ ::tonic::DartConverter<int64_t >::FromArguments (args, 1 , exception);
421
422
ASSERT_EQ (static_cast <int32_t >(flutter::SemanticsAction::kTap ), action_id);
422
423
423
- Dart_Handle semantic_args = Dart_GetNativeArgument (args, 2 );
424
- int64_t data;
425
- Dart_Handle dart_int = Dart_ListGetAt (semantic_args, 0 );
426
- Dart_IntegerToInt64 (dart_int, &data);
427
- ASSERT_EQ (2 , data);
428
-
429
- dart_int = Dart_ListGetAt (semantic_args, 1 );
430
- Dart_IntegerToInt64 (dart_int, &data);
431
- ASSERT_EQ (1 , data);
424
+ std::vector<int64_t > semantic_args =
425
+ ::tonic::DartConverter<std::vector<int64_t >>::FromArguments (args, 2 ,
426
+ exception);
427
+ ASSERT_THAT (semantic_args, ElementsAre (2 , 1 ));
432
428
notify_semantics_action_latch.Signal ();
433
429
};
434
430
std::vector<uint8_t > bytes ({2 , 1 });
@@ -440,8 +436,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingUnstableCallbacks) {
440
436
// Disable semantics. Wait for NotifySemanticsEnabled(false).
441
437
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_3;
442
438
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
443
- bool enabled = true ;
444
- Dart_GetNativeBooleanArgument (args, 0 , &enabled);
439
+ Dart_Handle exception = nullptr ;
440
+ bool enabled =
441
+ ::tonic::DartConverter<bool >::FromArguments (args, 0 , exception);
445
442
ASSERT_FALSE (enabled);
446
443
notify_semantics_enabled_latch_3.Signal ();
447
444
};
@@ -552,9 +549,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingLegacyCallbacks) {
552
549
// Wait for initial NotifySemanticsEnabled(false).
553
550
fml::AutoResetWaitableEvent notify_semantics_enabled_latch;
554
551
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
555
- bool enabled = true ;
556
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
557
- ASSERT_FALSE ( Dart_IsError (handle) );
552
+ Dart_Handle exception = nullptr ;
553
+ bool enabled =
554
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
558
555
ASSERT_FALSE (enabled);
559
556
notify_semantics_enabled_latch.Signal ();
560
557
};
@@ -563,19 +560,19 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingLegacyCallbacks) {
563
560
// Prepare to NotifyAccessibilityFeatures call
564
561
fml::AutoResetWaitableEvent notify_features_latch;
565
562
notify_accessibility_features_callback = [&](Dart_NativeArguments args) {
566
- bool enabled = true ;
567
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
568
- ASSERT_FALSE ( Dart_IsError (handle) );
563
+ Dart_Handle exception = nullptr ;
564
+ bool enabled =
565
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
569
566
ASSERT_FALSE (enabled);
570
567
notify_features_latch.Signal ();
571
568
};
572
569
573
570
// Enable semantics. Wait for NotifySemanticsEnabled(true).
574
571
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_2;
575
572
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
576
- bool enabled = false ;
577
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
578
- ASSERT_FALSE ( Dart_IsError (handle) );
573
+ Dart_Handle exception = nullptr ;
574
+ bool enabled =
575
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
579
576
ASSERT_TRUE (enabled);
580
577
notify_semantics_enabled_latch_2.Signal ();
581
578
};
@@ -589,9 +586,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingLegacyCallbacks) {
589
586
// Set accessibility features: (reduce_motion == true)
590
587
fml::AutoResetWaitableEvent notify_features_latch_2;
591
588
notify_accessibility_features_callback = [&](Dart_NativeArguments args) {
592
- bool enabled = false ;
593
- auto handle = Dart_GetNativeBooleanArgument (args, 0 , &enabled);
594
- ASSERT_FALSE ( Dart_IsError (handle) );
589
+ Dart_Handle exception = nullptr ;
590
+ bool enabled =
591
+ ::tonic::DartConverter< bool >:: FromArguments (args, 0 , exception );
595
592
ASSERT_TRUE (enabled);
596
593
notify_features_latch_2.Signal ();
597
594
};
@@ -613,24 +610,19 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingLegacyCallbacks) {
613
610
// Dispatch a tap to semantics node 42. Wait for NotifySemanticsAction.
614
611
fml::AutoResetWaitableEvent notify_semantics_action_latch;
615
612
notify_semantics_action_callback = [&](Dart_NativeArguments args) {
616
- int64_t node_id = 0 ;
617
- Dart_GetNativeIntegerArgument (args, 0 , &node_id);
613
+ Dart_Handle exception = nullptr ;
614
+ int64_t node_id =
615
+ ::tonic::DartConverter<int64_t >::FromArguments (args, 0 , exception);
618
616
ASSERT_EQ (42 , node_id);
619
617
620
- int64_t action_id;
621
- auto handle = Dart_GetNativeIntegerArgument (args, 1 , &action_id);
622
- ASSERT_FALSE (Dart_IsError (handle));
618
+ int64_t action_id =
619
+ ::tonic::DartConverter<int64_t >::FromArguments (args, 1 , exception);
623
620
ASSERT_EQ (static_cast <int32_t >(flutter::SemanticsAction::kTap ), action_id);
624
621
625
- Dart_Handle semantic_args = Dart_GetNativeArgument (args, 2 );
626
- int64_t data;
627
- Dart_Handle dart_int = Dart_ListGetAt (semantic_args, 0 );
628
- Dart_IntegerToInt64 (dart_int, &data);
629
- ASSERT_EQ (2 , data);
630
-
631
- dart_int = Dart_ListGetAt (semantic_args, 1 );
632
- Dart_IntegerToInt64 (dart_int, &data);
633
- ASSERT_EQ (1 , data);
622
+ std::vector<int64_t > semantic_args =
623
+ ::tonic::DartConverter<std::vector<int64_t >>::FromArguments (args, 2 ,
624
+ exception);
625
+ ASSERT_THAT (semantic_args, ElementsAre (2 , 1 ));
634
626
notify_semantics_action_latch.Signal ();
635
627
};
636
628
std::vector<uint8_t > bytes ({2 , 1 });
@@ -642,8 +634,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingLegacyCallbacks) {
642
634
// Disable semantics. Wait for NotifySemanticsEnabled(false).
643
635
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_3;
644
636
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
645
- bool enabled = true ;
646
- Dart_GetNativeBooleanArgument (args, 0 , &enabled);
637
+ Dart_Handle exception = nullptr ;
638
+ bool enabled =
639
+ ::tonic::DartConverter<bool >::FromArguments (args, 0 , exception);
647
640
ASSERT_FALSE (enabled);
648
641
notify_semantics_enabled_latch_3.Signal ();
649
642
};
0 commit comments