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

Commit c47ba05

Browse files
committed
[a11y] Use DartConverter for embedder a11y tests
No semantic change. This just simplifies converting Dart arguments to C++ types, making it more consistent with the rest of the codebase.
1 parent fd79552 commit c47ba05

File tree

1 file changed

+73
-82
lines changed

1 file changed

+73
-82
lines changed

shell/platform/embedder/tests/embedder_a11y_unittests.cc

Lines changed: 73 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "flutter/shell/platform/embedder/embedder.h"
1616
#include "flutter/shell/platform/embedder/tests/embedder_config_builder.h"
1717
#include "flutter/testing/testing.h"
18+
#include "third_party/tonic/converter/dart_converter.h"
1819

1920
// CREATE_NATIVE_ENTRY is leaky by design
2021
// NOLINTBEGIN(clang-analyzer-core.StackAddressEscape)
@@ -175,9 +176,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
175176
// Wait for initial NotifySemanticsEnabled(false).
176177
fml::AutoResetWaitableEvent notify_semantics_enabled_latch;
177178
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));
179+
Dart_Handle exception = nullptr;
180+
bool enabled =
181+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
181182
ASSERT_FALSE(enabled);
182183
notify_semantics_enabled_latch.Signal();
183184
};
@@ -186,19 +187,19 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
186187
// Prepare to NotifyAccessibilityFeatures call
187188
fml::AutoResetWaitableEvent notify_features_latch;
188189
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));
190+
Dart_Handle exception = nullptr;
191+
bool enabled =
192+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
192193
ASSERT_FALSE(enabled);
193194
notify_features_latch.Signal();
194195
};
195196

196197
// Enable semantics. Wait for NotifySemanticsEnabled(true).
197198
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_2;
198199
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));
200+
Dart_Handle exception = nullptr;
201+
bool enabled =
202+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
202203
ASSERT_TRUE(enabled);
203204
notify_semantics_enabled_latch_2.Signal();
204205
};
@@ -212,9 +213,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
212213
// Set accessibility features: (reduce_motion == true)
213214
fml::AutoResetWaitableEvent notify_features_latch_2;
214215
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));
216+
Dart_Handle exception = nullptr;
217+
bool enabled =
218+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
218219
ASSERT_TRUE(enabled);
219220
notify_features_latch_2.Signal();
220221
};
@@ -231,24 +232,20 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
231232
// Dispatch a tap to semantics node 42. Wait for NotifySemanticsAction.
232233
fml::AutoResetWaitableEvent notify_semantics_action_latch;
233234
notify_semantics_action_callback = [&](Dart_NativeArguments args) {
234-
int64_t node_id = 0;
235-
Dart_GetNativeIntegerArgument(args, 0, &node_id);
235+
Dart_Handle exception = nullptr;
236+
int64_t node_id =
237+
::tonic::DartConverter<int64_t>::FromArguments(args, 0, exception);
236238
ASSERT_EQ(42, node_id);
237239

238-
int64_t action_id;
239-
auto handle = Dart_GetNativeIntegerArgument(args, 1, &action_id);
240-
ASSERT_FALSE(Dart_IsError(handle));
240+
int64_t action_id =
241+
::tonic::DartConverter<int64_t>::FromArguments(args, 1, exception);
241242
ASSERT_EQ(static_cast<int32_t>(flutter::SemanticsAction::kTap), action_id);
242243

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);
244+
std::vector<int64_t> semantic_args =
245+
::tonic::DartConverter<std::vector<int64_t>>::FromArguments(args, 2,
246+
exception);
247+
ASSERT_EQ(2, semantic_args[0]);
248+
ASSERT_EQ(1, semantic_args[1]);
252249
notify_semantics_action_latch.Signal();
253250
};
254251
std::vector<uint8_t> bytes({2, 1});
@@ -260,8 +257,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
260257
// Disable semantics. Wait for NotifySemanticsEnabled(false).
261258
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_3;
262259
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
263-
bool enabled = true;
264-
Dart_GetNativeBooleanArgument(args, 0, &enabled);
260+
Dart_Handle exception = nullptr;
261+
bool enabled =
262+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
265263
ASSERT_FALSE(enabled);
266264
notify_semantics_enabled_latch_3.Signal();
267265
};
@@ -355,9 +353,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingUnstableCallbacks) {
355353
// Wait for initial NotifySemanticsEnabled(false).
356354
fml::AutoResetWaitableEvent notify_semantics_enabled_latch;
357355
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));
356+
Dart_Handle exception = nullptr;
357+
bool enabled =
358+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
361359
ASSERT_FALSE(enabled);
362360
notify_semantics_enabled_latch.Signal();
363361
};
@@ -366,19 +364,19 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingUnstableCallbacks) {
366364
// Prepare to NotifyAccessibilityFeatures call
367365
fml::AutoResetWaitableEvent notify_features_latch;
368366
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));
367+
Dart_Handle exception = nullptr;
368+
bool enabled =
369+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
372370
ASSERT_FALSE(enabled);
373371
notify_features_latch.Signal();
374372
};
375373

376374
// Enable semantics. Wait for NotifySemanticsEnabled(true).
377375
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_2;
378376
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));
377+
Dart_Handle exception = nullptr;
378+
bool enabled =
379+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
382380
ASSERT_TRUE(enabled);
383381
notify_semantics_enabled_latch_2.Signal();
384382
};
@@ -392,9 +390,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingUnstableCallbacks) {
392390
// Set accessibility features: (reduce_motion == true)
393391
fml::AutoResetWaitableEvent notify_features_latch_2;
394392
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));
393+
Dart_Handle exception = nullptr;
394+
bool enabled =
395+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
398396
ASSERT_TRUE(enabled);
399397
notify_features_latch_2.Signal();
400398
};
@@ -411,24 +409,20 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingUnstableCallbacks) {
411409
// Dispatch a tap to semantics node 42. Wait for NotifySemanticsAction.
412410
fml::AutoResetWaitableEvent notify_semantics_action_latch;
413411
notify_semantics_action_callback = [&](Dart_NativeArguments args) {
414-
int64_t node_id = 0;
415-
Dart_GetNativeIntegerArgument(args, 0, &node_id);
412+
Dart_Handle exception = nullptr;
413+
int64_t node_id =
414+
::tonic::DartConverter<int64_t>::FromArguments(args, 0, exception);
416415
ASSERT_EQ(42, node_id);
417416

418-
int64_t action_id;
419-
auto handle = Dart_GetNativeIntegerArgument(args, 1, &action_id);
420-
ASSERT_FALSE(Dart_IsError(handle));
417+
int64_t action_id =
418+
::tonic::DartConverter<int64_t>::FromArguments(args, 1, exception);
421419
ASSERT_EQ(static_cast<int32_t>(flutter::SemanticsAction::kTap), action_id);
422420

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);
421+
std::vector<int64_t> semantic_args =
422+
::tonic::DartConverter<std::vector<int64_t>>::FromArguments(args, 2,
423+
exception);
424+
ASSERT_EQ(2, semantic_args[0]);
425+
ASSERT_EQ(1, semantic_args[1]);
432426
notify_semantics_action_latch.Signal();
433427
};
434428
std::vector<uint8_t> bytes({2, 1});
@@ -440,8 +434,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingUnstableCallbacks) {
440434
// Disable semantics. Wait for NotifySemanticsEnabled(false).
441435
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_3;
442436
notify_semantics_enabled_callback = [&](Dart_NativeArguments args) {
443-
bool enabled = true;
444-
Dart_GetNativeBooleanArgument(args, 0, &enabled);
437+
Dart_Handle exception = nullptr;
438+
bool enabled =
439+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
445440
ASSERT_FALSE(enabled);
446441
notify_semantics_enabled_latch_3.Signal();
447442
};
@@ -552,9 +547,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingLegacyCallbacks) {
552547
// Wait for initial NotifySemanticsEnabled(false).
553548
fml::AutoResetWaitableEvent notify_semantics_enabled_latch;
554549
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));
550+
Dart_Handle exception = nullptr;
551+
bool enabled =
552+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
558553
ASSERT_FALSE(enabled);
559554
notify_semantics_enabled_latch.Signal();
560555
};
@@ -563,19 +558,19 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingLegacyCallbacks) {
563558
// Prepare to NotifyAccessibilityFeatures call
564559
fml::AutoResetWaitableEvent notify_features_latch;
565560
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));
561+
Dart_Handle exception = nullptr;
562+
bool enabled =
563+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
569564
ASSERT_FALSE(enabled);
570565
notify_features_latch.Signal();
571566
};
572567

573568
// Enable semantics. Wait for NotifySemanticsEnabled(true).
574569
fml::AutoResetWaitableEvent notify_semantics_enabled_latch_2;
575570
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));
571+
Dart_Handle exception = nullptr;
572+
bool enabled =
573+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
579574
ASSERT_TRUE(enabled);
580575
notify_semantics_enabled_latch_2.Signal();
581576
};
@@ -589,9 +584,9 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingLegacyCallbacks) {
589584
// Set accessibility features: (reduce_motion == true)
590585
fml::AutoResetWaitableEvent notify_features_latch_2;
591586
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));
587+
Dart_Handle exception = nullptr;
588+
bool enabled =
589+
::tonic::DartConverter<bool>::FromArguments(args, 0, exception);
595590
ASSERT_TRUE(enabled);
596591
notify_features_latch_2.Signal();
597592
};
@@ -613,24 +608,20 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingLegacyCallbacks) {
613608
// Dispatch a tap to semantics node 42. Wait for NotifySemanticsAction.
614609
fml::AutoResetWaitableEvent notify_semantics_action_latch;
615610
notify_semantics_action_callback = [&](Dart_NativeArguments args) {
616-
int64_t node_id = 0;
617-
Dart_GetNativeIntegerArgument(args, 0, &node_id);
611+
Dart_Handle exception = nullptr;
612+
int64_t node_id =
613+
::tonic::DartConverter<int64_t>::FromArguments(args, 0, exception);
618614
ASSERT_EQ(42, node_id);
619615

620-
int64_t action_id;
621-
auto handle = Dart_GetNativeIntegerArgument(args, 1, &action_id);
622-
ASSERT_FALSE(Dart_IsError(handle));
616+
int64_t action_id =
617+
::tonic::DartConverter<int64_t>::FromArguments(args, 1, exception);
623618
ASSERT_EQ(static_cast<int32_t>(flutter::SemanticsAction::kTap), action_id);
624619

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);
620+
std::vector<int64_t> semantic_args =
621+
::tonic::DartConverter<std::vector<int64_t>>::FromArguments(args, 2,
622+
exception);
623+
ASSERT_EQ(2, semantic_args[0]);
624+
ASSERT_EQ(1, semantic_args[1]);
634625
notify_semantics_action_latch.Signal();
635626
};
636627
std::vector<uint8_t> bytes({2, 1});

0 commit comments

Comments
 (0)