6 #include "gtest/gtest.h"
8 #include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
12 #include "flutter/shell/platform/linux/testing/fl_test.h"
13 #include "flutter/shell/platform/linux/testing/mock_signal_handler.h"
19 g_autoptr(GBytes) bytes = g_bytes_new(data, data_length);
27 TEST(FlAccessibleTextFieldTest, SetValue) {
33 flutter::testing::MockSignalHandler2<int, int> text_inserted(node,
35 flutter::testing::MockSignalHandler text_removed(node,
"text-remove");
37 EXPECT_SIGNAL2(text_inserted, ::testing::Eq(0), ::testing::Eq(7));
38 EXPECT_SIGNAL(text_removed).Times(0);
45 flutter::testing::MockSignalHandler text_inserted(node,
"text-insert");
46 flutter::testing::MockSignalHandler text_removed(node,
"text-remove");
48 EXPECT_SIGNAL(text_inserted).Times(0);
49 EXPECT_SIGNAL(text_removed).Times(0);
56 flutter::testing::MockSignalHandler2<int, int> text_inserted(node,
58 flutter::testing::MockSignalHandler2<int, int> text_removed(node,
61 EXPECT_SIGNAL2(text_inserted, ::testing::Eq(0), ::testing::Eq(6));
62 EXPECT_SIGNAL2(text_removed, ::testing::Eq(0), ::testing::Eq(7));
69 flutter::testing::MockSignalHandler text_inserted(node,
"text-insert");
70 flutter::testing::MockSignalHandler2<int, int> text_removed(node,
73 EXPECT_SIGNAL(text_inserted).Times(0);
74 EXPECT_SIGNAL2(text_removed, ::testing::Eq(0), ::testing::Eq(6));
83 TEST(FlAccessibleTextFieldTest, SetTextSelection) {
89 flutter::testing::MockSignalHandler text_selection_changed(
90 node,
"text-selection-changed");
91 flutter::testing::MockSignalHandler1<int> text_caret_moved(
92 node,
"text-caret-moved");
94 EXPECT_SIGNAL(text_selection_changed);
95 EXPECT_SIGNAL1(text_caret_moved, ::testing::Eq(3));
102 flutter::testing::MockSignalHandler text_selection_changed(
103 node,
"text-selection-changed");
104 flutter::testing::MockSignalHandler text_caret_moved(node,
107 EXPECT_SIGNAL(text_selection_changed);
108 EXPECT_SIGNAL(text_caret_moved).Times(0);
115 flutter::testing::MockSignalHandler text_selection_changed(
116 node,
"text-selection-changed");
117 flutter::testing::MockSignalHandler text_caret_moved(node,
120 EXPECT_SIGNAL(text_selection_changed).Times(0);
121 EXPECT_SIGNAL(text_caret_moved).Times(0);
128 flutter::testing::MockSignalHandler text_selection_changed(
129 node,
"text-selection-changed");
130 flutter::testing::MockSignalHandler1<int> text_caret_moved(
131 node,
"text-caret-moved");
133 EXPECT_SIGNAL(text_selection_changed).Times(0);
134 EXPECT_SIGNAL1(text_caret_moved, ::testing::Eq(4));
142 TEST(FlAccessibleTextFieldTest, PerformAction) {
143 g_autoptr(GPtrArray) action_datas = g_ptr_array_new_with_free_func(
149 DispatchSemanticsAction,
150 ([&action_datas](
auto engine, uint64_t
id,
151 FlutterSemanticsAction action,
const uint8_t* data,
152 size_t data_length) {
153 g_ptr_array_add(action_datas,
160 node,
static_cast<FlutterSemanticsAction
>(
161 kFlutterSemanticsActionMoveCursorForwardByCharacter |
162 kFlutterSemanticsActionMoveCursorBackwardByCharacter |
163 kFlutterSemanticsActionMoveCursorForwardByWord |
164 kFlutterSemanticsActionMoveCursorBackwardByWord));
168 for (
int i = 0;
i < 4; ++
i) {
169 atk_action_do_action(ATK_ACTION(node),
i);
171 FlValue* data =
static_cast<FlValue*
>(g_ptr_array_index(action_datas,
i));
172 EXPECT_NE(data,
nullptr);
178 TEST(FlAccessibleTextFieldTest, GetCharacterCount) {
182 EXPECT_EQ(atk_text_get_character_count(ATK_TEXT(node)), 0);
186 EXPECT_EQ(atk_text_get_character_count(ATK_TEXT(node)), 8);
190 TEST(FlAccessibleTextFieldTest, GetText) {
194 g_autofree gchar* empty = atk_text_get_text(ATK_TEXT(node), 0, -1);
195 EXPECT_STREQ(empty,
"");
197 flutter::testing::MockSignalHandler text_inserted(node,
"text-insert");
198 EXPECT_SIGNAL(text_inserted).Times(1);
202 g_autofree gchar*
flutter = atk_text_get_text(ATK_TEXT(node), 0, -1);
203 EXPECT_STREQ(
flutter,
"Flutter!");
205 g_autofree gchar* tt = atk_text_get_text(ATK_TEXT(node), 3, 5);
206 EXPECT_STREQ(tt,
"tt");
210 TEST(FlAccessibleTextFieldTest, GetCaretOffset) {
214 EXPECT_EQ(atk_text_get_caret_offset(ATK_TEXT(node)), -1);
218 EXPECT_EQ(atk_text_get_caret_offset(ATK_TEXT(node)), 2);
222 TEST(FlAccessibleTextFieldTest, SetCaretOffset) {
229 DispatchSemanticsAction,
230 ([&base, &extent](
auto engine, uint64_t
id,
231 FlutterSemanticsAction action,
const uint8_t* data,
232 size_t data_length) {
233 EXPECT_EQ(action, kFlutterSemanticsActionSetSelection);
243 EXPECT_TRUE(atk_text_set_caret_offset(ATK_TEXT(node), 3));
245 EXPECT_EQ(extent, 3);
249 TEST(FlAccessibleTextFieldTest, GetNSelections) {
253 EXPECT_EQ(atk_text_get_n_selections(ATK_TEXT(node)), 0);
257 EXPECT_EQ(atk_text_get_n_selections(ATK_TEXT(node)), 1);
261 TEST(FlAccessibleTextFieldTest, GetSelection) {
265 EXPECT_EQ(atk_text_get_selection(ATK_TEXT(node), 0,
nullptr,
nullptr),
272 g_autofree gchar* selection =
273 atk_text_get_selection(ATK_TEXT(node), 0, &
start, &
end);
274 EXPECT_STREQ(selection,
"utt");
280 g_autofree gchar* reverse =
281 atk_text_get_selection(ATK_TEXT(node), 0, &
start, &
end);
282 EXPECT_STREQ(reverse,
"utt");
288 EXPECT_EQ(atk_text_get_selection(ATK_TEXT(node), 0, &
start, &
end),
nullptr);
291 EXPECT_EQ(atk_text_get_selection(ATK_TEXT(node), 1, &
start, &
end),
nullptr);
295 TEST(FlAccessibleTextFieldTest, AddSelection) {
302 DispatchSemanticsAction,
303 ([&base, &extent](
auto engine, uint64_t
id,
304 FlutterSemanticsAction action,
const uint8_t* data,
305 size_t data_length) {
306 EXPECT_EQ(action, kFlutterSemanticsActionSetSelection);
316 EXPECT_TRUE(atk_text_add_selection(ATK_TEXT(node), 2, 4));
318 EXPECT_EQ(extent, 4);
323 EXPECT_FALSE(atk_text_add_selection(ATK_TEXT(node), 6, 7));
325 EXPECT_EQ(extent, 4);
329 TEST(FlAccessibleTextFieldTest, RemoveSelection) {
336 DispatchSemanticsAction,
337 ([&base, &extent](
auto engine, uint64_t
id,
338 FlutterSemanticsAction action,
const uint8_t* data,
339 size_t data_length) {
340 EXPECT_EQ(action, kFlutterSemanticsActionSetSelection);
351 EXPECT_FALSE(atk_text_remove_selection(ATK_TEXT(node), 0));
353 EXPECT_EQ(extent, -1);
358 EXPECT_FALSE(atk_text_remove_selection(ATK_TEXT(node), 1));
360 EXPECT_EQ(extent, -1);
363 EXPECT_TRUE(atk_text_remove_selection(ATK_TEXT(node), 0));
365 EXPECT_EQ(extent, 4);
369 TEST(FlAccessibleTextFieldTest, SetSelection) {
376 DispatchSemanticsAction,
377 ([&base, &extent](
auto engine, uint64_t
id,
378 FlutterSemanticsAction action,
const uint8_t* data,
379 size_t data_length) {
380 EXPECT_EQ(action, kFlutterSemanticsActionSetSelection);
391 EXPECT_FALSE(atk_text_set_selection(ATK_TEXT(node), 1, 2, 4));
393 EXPECT_EQ(extent, -1);
395 EXPECT_TRUE(atk_text_set_selection(ATK_TEXT(node), 0, 2, 4));
397 EXPECT_EQ(extent, 4);
399 EXPECT_TRUE(atk_text_set_selection(ATK_TEXT(node), 0, 5, 1));
401 EXPECT_EQ(extent, 1);
405 TEST(FlAccessibleTextFieldTest, SetTextContents) {
406 g_autofree gchar* text =
nullptr;
411 DispatchSemanticsAction,
412 ([&text](
auto engine, uint64_t
id, FlutterSemanticsAction action,
413 const uint8_t* data,
size_t data_length) {
414 EXPECT_EQ(action, kFlutterSemanticsActionSetText);
423 atk_editable_text_set_text_contents(ATK_EDITABLE_TEXT(node),
"Flutter");
424 EXPECT_STREQ(text,
"Flutter");
428 TEST(FlAccessibleTextFieldTest, InsertDeleteText) {
429 g_autofree gchar* text =
nullptr;
436 DispatchSemanticsAction,
437 ([&text, &base, &extent](
auto engine, uint64_t
id,
438 FlutterSemanticsAction action,
439 const uint8_t* data,
size_t data_length) {
441 ::testing::AnyOf(kFlutterSemanticsActionSetText,
442 kFlutterSemanticsActionSetSelection));
443 if (action == kFlutterSemanticsActionSetText) {
464 atk_editable_text_insert_text(ATK_EDITABLE_TEXT(node),
"utt", 3, &pos);
466 EXPECT_STREQ(text,
"Flutter");
467 EXPECT_EQ(base, pos);
468 EXPECT_EQ(extent, pos);
470 atk_editable_text_delete_text(ATK_EDITABLE_TEXT(node), 2, 5);
471 EXPECT_STREQ(text,
"Fler");
473 EXPECT_EQ(extent, 2);
477 TEST(FlAccessibleTextFieldTest, CopyCutPasteText) {
480 FlutterSemanticsAction act = kFlutterSemanticsActionCustomAction;
485 DispatchSemanticsAction,
486 ([&act, &base, &extent](
auto engine, uint64_t
id,
487 FlutterSemanticsAction action,
488 const uint8_t* data,
size_t data_length) {
490 ::testing::AnyOf(kFlutterSemanticsActionCut,
491 kFlutterSemanticsActionCopy,
492 kFlutterSemanticsActionPaste,
493 kFlutterSemanticsActionSetSelection));
495 if (action == kFlutterSemanticsActionSetSelection) {
508 atk_editable_text_copy_text(ATK_EDITABLE_TEXT(node), 2, 5);
510 EXPECT_EQ(extent, 5);
511 EXPECT_EQ(act, kFlutterSemanticsActionCopy);
513 atk_editable_text_cut_text(ATK_EDITABLE_TEXT(node), 1, 4);
515 EXPECT_EQ(extent, 4);
516 EXPECT_EQ(act, kFlutterSemanticsActionCut);
518 atk_editable_text_paste_text(ATK_EDITABLE_TEXT(node), 3);
520 EXPECT_EQ(extent, 3);
521 EXPECT_EQ(act, kFlutterSemanticsActionPaste);
524 TEST(FlAccessibleTextFieldTest, TextBoundary) {
529 "Lorem ipsum.\nDolor sit amet. Praesent commodo?"
530 "\n\nPraesent et felis dui.");
533 gint start_offset = -1, end_offset = -1;
534 g_autofree gchar* lorem_char = atk_text_get_string_at_offset(
535 ATK_TEXT(node), 0, ATK_TEXT_GRANULARITY_CHAR, &start_offset, &end_offset);
536 EXPECT_STREQ(lorem_char,
"L");
537 EXPECT_EQ(start_offset, 0);
538 EXPECT_EQ(end_offset, 1);
540 g_autofree gchar* lorem_word = atk_text_get_string_at_offset(
541 ATK_TEXT(node), 0, ATK_TEXT_GRANULARITY_WORD, &start_offset, &end_offset);
542 EXPECT_STREQ(lorem_word,
"Lorem");
543 EXPECT_EQ(start_offset, 0);
544 EXPECT_EQ(end_offset, 5);
546 g_autofree gchar* lorem_sentence = atk_text_get_string_at_offset(
547 ATK_TEXT(node), 0, ATK_TEXT_GRANULARITY_SENTENCE, &start_offset,
549 EXPECT_STREQ(lorem_sentence,
"Lorem ipsum.");
550 EXPECT_EQ(start_offset, 0);
551 EXPECT_EQ(end_offset, 12);
553 g_autofree gchar* lorem_line = atk_text_get_string_at_offset(
554 ATK_TEXT(node), 0, ATK_TEXT_GRANULARITY_LINE, &start_offset, &end_offset);
555 EXPECT_STREQ(lorem_line,
"Lorem ipsum.");
556 EXPECT_EQ(start_offset, 0);
557 EXPECT_EQ(end_offset, 12);
559 g_autofree gchar* lorem_paragraph = atk_text_get_string_at_offset(
560 ATK_TEXT(node), 0, ATK_TEXT_GRANULARITY_PARAGRAPH, &start_offset,
562 EXPECT_STREQ(lorem_paragraph,
563 "Lorem ipsum.\nDolor sit amet. Praesent commodo?");
564 EXPECT_EQ(start_offset, 0);
565 EXPECT_EQ(end_offset, 46);
568 g_autofree gchar* praesent_char = atk_text_get_string_at_offset(
569 ATK_TEXT(node), 32, ATK_TEXT_GRANULARITY_CHAR, &start_offset,
571 EXPECT_STREQ(praesent_char,
"e");
572 EXPECT_EQ(start_offset, 32);
573 EXPECT_EQ(end_offset, 33);
575 g_autofree gchar* praesent_word = atk_text_get_string_at_offset(
576 ATK_TEXT(node), 32, ATK_TEXT_GRANULARITY_WORD, &start_offset,
578 EXPECT_STREQ(praesent_word,
"Praesent");
579 EXPECT_EQ(start_offset, 29);
580 EXPECT_EQ(end_offset, 37);
582 g_autofree gchar* praesent_sentence = atk_text_get_string_at_offset(
583 ATK_TEXT(node), 32, ATK_TEXT_GRANULARITY_SENTENCE, &start_offset,
585 EXPECT_STREQ(praesent_sentence,
"Praesent commodo?");
586 EXPECT_EQ(start_offset, 29);
587 EXPECT_EQ(end_offset, 46);
589 g_autofree gchar* praesent_line = atk_text_get_string_at_offset(
590 ATK_TEXT(node), 32, ATK_TEXT_GRANULARITY_LINE, &start_offset,
592 EXPECT_STREQ(praesent_line,
"Dolor sit amet. Praesent commodo?");
593 EXPECT_EQ(start_offset, 13);
594 EXPECT_EQ(end_offset, 46);
596 g_autofree gchar* praesent_paragraph = atk_text_get_string_at_offset(
597 ATK_TEXT(node), 32, ATK_TEXT_GRANULARITY_PARAGRAPH, &start_offset,
599 EXPECT_STREQ(praesent_paragraph,
600 "Lorem ipsum.\nDolor sit amet. Praesent commodo?");
601 EXPECT_EQ(start_offset, 0);
602 EXPECT_EQ(end_offset, 46);
605 g_autofree gchar* felis_char = atk_text_get_string_at_offset(
606 ATK_TEXT(node), 64, ATK_TEXT_GRANULARITY_CHAR, &start_offset,
608 EXPECT_STREQ(felis_char,
"s");
609 EXPECT_EQ(start_offset, 64);
610 EXPECT_EQ(end_offset, 65);
612 g_autofree gchar* felis_word = atk_text_get_string_at_offset(
613 ATK_TEXT(node), 64, ATK_TEXT_GRANULARITY_WORD, &start_offset,
615 EXPECT_STREQ(felis_word,
"felis");
616 EXPECT_EQ(start_offset, 60);
617 EXPECT_EQ(end_offset, 65);
619 g_autofree gchar* felis_sentence = atk_text_get_string_at_offset(
620 ATK_TEXT(node), 64, ATK_TEXT_GRANULARITY_SENTENCE, &start_offset,
622 EXPECT_STREQ(felis_sentence,
"Praesent et felis dui.");
623 EXPECT_EQ(start_offset, 48);
624 EXPECT_EQ(end_offset, 70);
626 g_autofree gchar* felis_line = atk_text_get_string_at_offset(
627 ATK_TEXT(node), 64, ATK_TEXT_GRANULARITY_LINE, &start_offset,
629 EXPECT_STREQ(felis_line,
"Praesent et felis dui.");
630 EXPECT_EQ(start_offset, 48);
631 EXPECT_EQ(end_offset, 70);
633 g_autofree gchar* felis_paragraph = atk_text_get_string_at_offset(
634 ATK_TEXT(node), 64, ATK_TEXT_GRANULARITY_PARAGRAPH, &start_offset,
636 EXPECT_STREQ(felis_paragraph,
"\nPraesent et felis dui.");
637 EXPECT_EQ(start_offset, 47);
638 EXPECT_EQ(end_offset, 70);