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