6#include "gtest/gtest.h"
8#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
9#include "flutter/shell/platform/linux/fl_accessible_text_field.h"
10#include "flutter/shell/platform/linux/fl_engine_private.h"
11#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.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);
27TEST(FlAccessibleTextFieldTest, SetValue) {
83TEST(FlAccessibleTextFieldTest, SetTextSelection) {
90 node,
"text-selection-changed");
92 node,
"text-caret-moved");
103 node,
"text-selection-changed");
116 node,
"text-selection-changed");
129 node,
"text-selection-changed");
131 node,
"text-caret-moved");
142TEST(FlAccessibleTextFieldTest, PerformAction) {
143 g_autoptr(GPtrArray) action_datas = g_ptr_array_new_with_free_func(
150 ([&action_datas](
auto engine, uint64_t
id,
152 size_t data_length) {
153 g_ptr_array_add(action_datas,
168 for (
int i = 0;
i < 4; ++
i) {
169 atk_action_do_action(ATK_ACTION(node),
i);
172 EXPECT_NE(
data,
nullptr);
178TEST(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);
190TEST(FlAccessibleTextFieldTest, GetText) {
194 g_autofree gchar*
empty = atk_text_get_text(ATK_TEXT(node), 0, -1);
195 EXPECT_STREQ(
empty,
"");
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");
210TEST(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);
222TEST(FlAccessibleTextFieldTest, SetCaretOffset) {
232 size_t data_length) {
243 EXPECT_TRUE(atk_text_set_caret_offset(ATK_TEXT(node), 3));
245 EXPECT_EQ(extent, 3);
249TEST(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);
261TEST(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");
281 atk_text_get_selection(ATK_TEXT(node), 0, &
start, &
end);
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);
295TEST(FlAccessibleTextFieldTest, AddSelection) {
305 size_t data_length) {
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);
329TEST(FlAccessibleTextFieldTest, RemoveSelection) {
339 size_t data_length) {
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);
369TEST(FlAccessibleTextFieldTest, SetSelection) {
379 size_t data_length) {
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);
405TEST(FlAccessibleTextFieldTest, SetTextContents) {
406 g_autofree gchar*
text =
nullptr;
413 const uint8_t*
data,
size_t data_length) {
423 atk_editable_text_set_text_contents(ATK_EDITABLE_TEXT(node),
"Flutter");
424 EXPECT_STREQ(
text,
"Flutter");
428TEST(FlAccessibleTextFieldTest, InsertDeleteText) {
429 g_autofree gchar*
text =
nullptr;
439 const uint8_t*
data,
size_t data_length) {
464 atk_editable_text_insert_text(ATK_EDITABLE_TEXT(node),
"utt", 3, &
pos);
466 EXPECT_STREQ(
text,
"Flutter");
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);
477TEST(FlAccessibleTextFieldTest, CopyCutPasteText) {
486 ([&act, &
base, &extent](
auto engine, uint64_t
id,
488 const uint8_t*
data,
size_t data_length) {
508 atk_editable_text_copy_text(ATK_EDITABLE_TEXT(node), 2, 5);
510 EXPECT_EQ(extent, 5);
513 atk_editable_text_cut_text(ATK_EDITABLE_TEXT(node), 1, 4);
515 EXPECT_EQ(extent, 4);
518 atk_editable_text_paste_text(ATK_EDITABLE_TEXT(node), 3);
520 EXPECT_EQ(extent, 3);
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);
@ kFlutterSemanticsActionMoveCursorForwardByCharacter
Move the cursor forward by one character.
@ kFlutterSemanticsActionMoveCursorBackwardByCharacter
Move the cursor backward by one character.
@ kFlutterSemanticsActionMoveCursorForwardByWord
Move the cursor forward by one word.
@ kFlutterSemanticsActionSetSelection
Set the text selection to the given range.
@ kFlutterSemanticsActionPaste
Paste the current content of the clipboard.
@ kFlutterSemanticsActionCut
Cut the current selection and place it in the clipboard.
@ kFlutterSemanticsActionCustomAction
Indicate that the user has invoked a custom accessibility action.
@ kFlutterSemanticsActionCopy
Copy the current selection to the clipboard.
@ kFlutterSemanticsActionMoveCursorBackwardByWord
Move the cursor backward by one word.
@ kFlutterSemanticsActionSetText
Replace the current text in the text field.
EMSCRIPTEN_KEEPALIVE void empty()
void fl_accessible_node_set_text_selection(FlAccessibleNode *self, gint base, gint extent)
void fl_accessible_node_set_actions(FlAccessibleNode *self, FlutterSemanticsAction actions)
void fl_accessible_node_set_value(FlAccessibleNode *self, const gchar *value)
FlAccessibleNode * fl_accessible_text_field_new(FlEngine *engine, int32_t id)
static FlValue * decode_semantic_data(const uint8_t *data, size_t data_length)
TEST(FlAccessibleTextFieldTest, SetValue)
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
G_MODULE_EXPORT FlStandardMessageCodec * fl_standard_message_codec_new()
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
G_MODULE_EXPORT void fl_value_unref(FlValue *self)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
typedefG_BEGIN_DECLS struct _FlValue FlValue
#define EXPECT_SIGNAL(mock)
#define EXPECT_SIGNAL2(mock, a1, a2)
#define EXPECT_SIGNAL1(mock, a1)
static void DispatchSemanticsAction(JNIEnv *env, jobject jcaller, jlong shell_holder, jint id, jint action, jobject args, jint args_position)
#define MOCK_ENGINE_PROC(proc, mock_impl)
FlutterEngineDispatchSemanticsActionFnPtr DispatchSemanticsAction
std::shared_ptr< const fml::Mapping > data
#define EXPECT_TRUE(handle)