19
19
#include " ax/ax_tree_id.h"
20
20
#include " ax/ax_tree_update.h"
21
21
#include " ax/test_ax_tree_manager.h"
22
+ #include " flutter/fml/platform/win/wstring_conversion.h"
22
23
#include " gtest/gtest.h"
23
24
24
25
namespace ui {
@@ -28,10 +29,6 @@ using TestPositionRange = AXRange<AXPosition<AXNodePosition, AXNode>>;
28
29
29
30
namespace {
30
31
31
- std::u16string WideToUTF16 (const std::wstring wide ) {
32
- return std::u16string (wide .begin (), wide .end ());
33
- }
34
-
35
32
constexpr AXNode::AXID ROOT_ID = 1 ;
36
33
constexpr AXNode::AXID BUTTON_ID = 2 ;
37
34
constexpr AXNode::AXID CHECK_BOX_ID = 3 ;
@@ -43,20 +40,20 @@ constexpr AXNode::AXID STATIC_TEXT2_ID = 8;
43
40
constexpr AXNode::AXID INLINE_BOX2_ID = 9 ;
44
41
45
42
// A group of basic and extended characters.
46
- constexpr const wchar_t * kGraphemeClusters [] = {
43
+ constexpr const char16_t * kGraphemeClusters [] = {
47
44
// The English word "hey" consisting of four ASCII characters.
48
- L " h" ,
49
- L " e" ,
50
- L " y" ,
45
+ u " h" ,
46
+ u " e" ,
47
+ u " y" ,
51
48
// A Hindi word (which means "Hindi") consisting of two Devanagari
52
49
// grapheme clusters.
53
- L "\x0939\x093F " ,
54
- L "\x0928\x094D\x0926\x0940 " ,
50
+ u "\x0939\x093F " ,
51
+ u "\x0928\x094D\x0926\x0940 " ,
55
52
// A Thai word (which means "feel") consisting of three Thai grapheme
56
53
// clusters.
57
- L "\x0E23\x0E39\x0E49 " ,
58
- L "\x0E2A\x0E36 " ,
59
- L "\x0E01 " ,
54
+ u "\x0E23\x0E39\x0E49 " ,
55
+ u "\x0E2A\x0E36 " ,
56
+ u "\x0E01 " ,
60
57
};
61
58
62
59
class AXPositionTest : public testing ::Test, public TestAXTreeManager {
@@ -419,7 +416,7 @@ std::unique_ptr<AXTree> AXPositionTest::CreateMultilingualDocument(
419
416
420
417
std::u16string english_text;
421
418
for (int i = 0 ; i < 3 ; ++i) {
422
- std::u16string grapheme = WideToUTF16 ( kGraphemeClusters [i]) ;
419
+ std::u16string grapheme = kGraphemeClusters [i];
423
420
EXPECT_EQ (1u , grapheme.length ())
424
421
<< " All English characters should be one UTF16 code unit in length." ;
425
422
text_offsets->push_back (text_offsets->back () +
@@ -429,7 +426,7 @@ std::unique_ptr<AXTree> AXPositionTest::CreateMultilingualDocument(
429
426
430
427
std::u16string hindi_text;
431
428
for (int i = 3 ; i < 5 ; ++i) {
432
- std::u16string grapheme = WideToUTF16 ( kGraphemeClusters [i]) ;
429
+ std::u16string grapheme = kGraphemeClusters [i];
433
430
EXPECT_LE (2u , grapheme.length ()) << " All Hindi characters should be two "
434
431
" or more UTF16 code units in length." ;
435
432
text_offsets->push_back (text_offsets->back () +
@@ -439,7 +436,7 @@ std::unique_ptr<AXTree> AXPositionTest::CreateMultilingualDocument(
439
436
440
437
std::u16string thai_text;
441
438
for (int i = 5 ; i < 8 ; ++i) {
442
- std::u16string grapheme = WideToUTF16 ( kGraphemeClusters [i]) ;
439
+ std::u16string grapheme = kGraphemeClusters [i];
443
440
EXPECT_LT (0u , grapheme.length ())
444
441
<< " One of the Thai characters should be one UTF16 code unit, "
445
442
" whilst others should be two or more." ;
@@ -618,7 +615,7 @@ TEST_F(AXPositionTest, ToString) {
618
615
AXNodeData static_text_data_2;
619
616
static_text_data_2.id = 3 ;
620
617
static_text_data_2.role = ax::mojom::Role::kStaticText ;
621
- static_text_data_2.SetName (WideToUTF16 ( L "\xfffc " ) );
618
+ static_text_data_2.SetName (u "\xfffc " );
622
619
623
620
AXNodeData static_text_data_3;
624
621
static_text_data_3.id = 4 ;
@@ -876,7 +873,7 @@ TEST_F(AXPositionTest, GetTextFromNullPosition) {
876
873
TestPositionType text_position = AXNodePosition::CreateNullPosition ();
877
874
ASSERT_NE (nullptr , text_position);
878
875
ASSERT_TRUE (text_position->IsNullPosition ());
879
- ASSERT_EQ (WideToUTF16 ( L" " ) , text_position->GetText ());
876
+ ASSERT_EQ (u" " , text_position->GetText ());
880
877
}
881
878
882
879
TEST_F (AXPositionTest, GetTextFromRoot) {
@@ -885,7 +882,7 @@ TEST_F(AXPositionTest, GetTextFromRoot) {
885
882
ax::mojom::TextAffinity::kUpstream );
886
883
ASSERT_NE (nullptr , text_position);
887
884
ASSERT_TRUE (text_position->IsTextPosition ());
888
- ASSERT_EQ (WideToUTF16 ( L " Line 1\n Line 2" ) , text_position->GetText ());
885
+ ASSERT_EQ (u " Line 1\n Line 2" , text_position->GetText ());
889
886
}
890
887
891
888
TEST_F (AXPositionTest, GetTextFromButton) {
@@ -894,7 +891,7 @@ TEST_F(AXPositionTest, GetTextFromButton) {
894
891
ax::mojom::TextAffinity::kUpstream );
895
892
ASSERT_NE (nullptr , text_position);
896
893
ASSERT_TRUE (text_position->IsTextPosition ());
897
- ASSERT_EQ (WideToUTF16 ( L" " ) , text_position->GetText ());
894
+ ASSERT_EQ (u" " , text_position->GetText ());
898
895
}
899
896
900
897
TEST_F (AXPositionTest, GetTextFromCheckbox) {
@@ -903,7 +900,7 @@ TEST_F(AXPositionTest, GetTextFromCheckbox) {
903
900
ax::mojom::TextAffinity::kUpstream );
904
901
ASSERT_NE (nullptr , text_position);
905
902
ASSERT_TRUE (text_position->IsTextPosition ());
906
- ASSERT_EQ (WideToUTF16 ( L" " ) , text_position->GetText ());
903
+ ASSERT_EQ (u" " , text_position->GetText ());
907
904
}
908
905
909
906
TEST_F (AXPositionTest, GetTextFromTextField) {
@@ -912,7 +909,7 @@ TEST_F(AXPositionTest, GetTextFromTextField) {
912
909
ax::mojom::TextAffinity::kUpstream );
913
910
ASSERT_NE (nullptr , text_position);
914
911
ASSERT_TRUE (text_position->IsTextPosition ());
915
- ASSERT_EQ (WideToUTF16 ( L " Line 1\n Line 2" ) , text_position->GetText ());
912
+ ASSERT_EQ (u " Line 1\n Line 2" , text_position->GetText ());
916
913
}
917
914
918
915
TEST_F (AXPositionTest, GetTextFromStaticText) {
@@ -921,7 +918,7 @@ TEST_F(AXPositionTest, GetTextFromStaticText) {
921
918
ax::mojom::TextAffinity::kUpstream );
922
919
ASSERT_NE (nullptr , text_position);
923
920
ASSERT_TRUE (text_position->IsTextPosition ());
924
- ASSERT_EQ (WideToUTF16 ( L " Line 1" ) , text_position->GetText ());
921
+ ASSERT_EQ (u " Line 1" , text_position->GetText ());
925
922
}
926
923
927
924
TEST_F (AXPositionTest, GetTextFromInlineTextBox) {
@@ -930,7 +927,7 @@ TEST_F(AXPositionTest, GetTextFromInlineTextBox) {
930
927
ax::mojom::TextAffinity::kUpstream );
931
928
ASSERT_NE (nullptr , text_position);
932
929
ASSERT_TRUE (text_position->IsTextPosition ());
933
- ASSERT_EQ (WideToUTF16 ( L " Line 1" ) , text_position->GetText ());
930
+ ASSERT_EQ (u " Line 1" , text_position->GetText ());
934
931
}
935
932
936
933
TEST_F (AXPositionTest, GetTextFromLineBreak) {
@@ -939,7 +936,7 @@ TEST_F(AXPositionTest, GetTextFromLineBreak) {
939
936
ax::mojom::TextAffinity::kUpstream );
940
937
ASSERT_NE (nullptr , text_position);
941
938
ASSERT_TRUE (text_position->IsTextPosition ());
942
- ASSERT_EQ (WideToUTF16 ( L "\n " ) , text_position->GetText ());
939
+ ASSERT_EQ (u "\n " , text_position->GetText ());
943
940
}
944
941
945
942
TEST_F (AXPositionTest, GetMaxTextOffsetFromNullPosition) {
@@ -1106,7 +1103,7 @@ TEST_F(AXPositionTest, GetMaxTextOffsetAndGetTextWithGeneratedContent) {
1106
1103
ASSERT_NE (nullptr , text_position);
1107
1104
EXPECT_TRUE (text_position->IsTextPosition ());
1108
1105
EXPECT_EQ (38 , text_position->MaxTextOffset ());
1109
- EXPECT_EQ (WideToUTF16 ( L " Placeholder from generated content3.14" ) ,
1106
+ EXPECT_EQ (u " Placeholder from generated content3.14" ,
1110
1107
text_position->GetText ());
1111
1108
}
1112
1109
@@ -7712,10 +7709,10 @@ TEST_F(AXPositionTest, EmptyObjectReplacedByCharacterTextNavigation) {
7712
7709
GetTreeID (), root_1.id , 0 /* text_offset */ ,
7713
7710
ax::mojom::TextAffinity::kDownstream );
7714
7711
7715
- expected_text = WideToUTF16 ( L" Hello " ) + AXNodePosition:: kEmbeddedCharacter +
7716
- WideToUTF16 ( L" world3.14 " ) +
7717
- AXNodePosition::kEmbeddedCharacter + WideToUTF16 ( L" hey " ) +
7718
- AXNodePosition::kEmbeddedCharacter ;
7712
+ expected_text =
7713
+ std::u16string ( u" Hello " ) + AXNodePosition:: kEmbeddedCharacter +
7714
+ std::u16string ( u" world3.14 " ) + AXNodePosition::kEmbeddedCharacter +
7715
+ std::u16string ( u" hey " ) + AXNodePosition::kEmbeddedCharacter ;
7719
7716
ASSERT_EQ (expected_text, position->GetText ());
7720
7717
7721
7718
// MaxTextOffset() with an embedded object replacement character.
0 commit comments