@@ -63,6 +63,95 @@ TEST_F_UI(TextTest, AutoFontSizeStepGranularity) {
6363 EXPECT_NE (text_shadow_node_->text_style_ ->font_size , font_size);
6464}
6565
66+ TEST_F_UI (TextTest, AutoFontSizeIgnoresInvalidStepGranularity) {
67+ MeasureConstraint constraint{4000 , MeasureMode::kDefinite , 1000 ,
68+ MeasureMode::kDefinite };
69+ text_shadow_node_->enable_auto_font_size_ = true ;
70+ text_shadow_node_->auto_font_size_max_size_ = 50 ;
71+ text_shadow_node_->auto_font_size_min_size_ = 30 ;
72+ text_shadow_node_->auto_font_size_step_granularity_ = 0 ;
73+ raw_text_shadow_node_->SetText (" Hello" );
74+
75+ text_shadow_node_->Measure (constraint);
76+
77+ EXPECT_EQ (text_shadow_node_->text_style_ ->font_size , 42 );
78+ }
79+
80+ TEST_F_UI (TextTest, AutoFontSizeAllowsUnsetMaxSize) {
81+ MeasureConstraint constraint{1000 , MeasureMode::kDefinite , 100 ,
82+ MeasureMode::kDefinite };
83+ text_shadow_node_->enable_auto_font_size_ = true ;
84+ text_shadow_node_->auto_font_size_min_size_ = 10 ;
85+ text_shadow_node_->auto_font_size_max_size_ = 0 ;
86+ text_shadow_node_->auto_font_size_step_granularity_ = 1 ;
87+ raw_text_shadow_node_->SetText (
88+ " Hello, Compiler NG Hello, Compiler NG Hello, Compiler NG Hello, "
89+ " Compiler NG Hello, Compiler NG Hello, Compiler NG " );
90+
91+ text_shadow_node_->Measure (constraint);
92+
93+ EXPECT_LT (text_shadow_node_->text_style_ ->font_size , 42 );
94+ }
95+
96+ TEST_F_UI (TextTest, AutoFontSizeIgnoresUnsetMinSize) {
97+ MeasureConstraint constraint{100 , MeasureMode::kDefinite , 1 ,
98+ MeasureMode::kDefinite };
99+ text_shadow_node_->enable_auto_font_size_ = true ;
100+ text_shadow_node_->auto_font_size_min_size_ = 0 ;
101+ text_shadow_node_->auto_font_size_max_size_ = 0 ;
102+ text_shadow_node_->auto_font_size_step_granularity_ = 1 ;
103+ raw_text_shadow_node_->SetText (
104+ " Hello, Compiler NG Hello, Compiler NG Hello, Compiler NG Hello, "
105+ " Compiler NG Hello, Compiler NG Hello, Compiler NG " );
106+
107+ text_shadow_node_->Measure (constraint);
108+
109+ EXPECT_EQ (text_shadow_node_->text_style_ ->font_size , 42 );
110+ }
111+
112+ TEST_F_UI (TextTest, AutoFontSizeDoesNotShrinkBelowMinSize) {
113+ MeasureConstraint constraint{100 , MeasureMode::kDefinite , 1 ,
114+ MeasureMode::kDefinite };
115+ text_shadow_node_->enable_auto_font_size_ = true ;
116+ text_shadow_node_->auto_font_size_min_size_ = 10 ;
117+ text_shadow_node_->auto_font_size_max_size_ = 0 ;
118+ text_shadow_node_->auto_font_size_step_granularity_ = 3 ;
119+ raw_text_shadow_node_->SetText (
120+ " Hello, Compiler NG Hello, Compiler NG Hello, Compiler NG Hello, "
121+ " Compiler NG Hello, Compiler NG Hello, Compiler NG " );
122+
123+ text_shadow_node_->Measure (constraint);
124+
125+ EXPECT_GE (text_shadow_node_->text_style_ ->font_size , 10 );
126+ }
127+
128+ TEST_F_UI (TextTest, AutoFontSizeIgnoresInlineTruncation) {
129+ MeasureConstraint constraint{1000 , MeasureMode::kDefinite , 100 ,
130+ MeasureMode::kDefinite };
131+ text_shadow_node_->enable_auto_font_size_ = true ;
132+ text_shadow_node_->auto_font_size_min_size_ = 10 ;
133+ text_shadow_node_->auto_font_size_max_size_ = 0 ;
134+ text_shadow_node_->auto_font_size_step_granularity_ = 1 ;
135+ text_shadow_node_->SetTextMaxLine (1 );
136+ raw_text_shadow_node_->SetText (
137+ " Hello, Compiler NG Hello, Compiler NG Hello, Compiler NG Hello, "
138+ " Compiler NG Hello, Compiler NG Hello, Compiler NG " );
139+ auto inline_truncation_node = std::make_unique<InlineTruncationShadowNode>(
140+ owner_, std::string (" inline-truncation" ), -1 );
141+ auto inline_text_node = std::make_unique<InlineTextShadowNode>(
142+ owner_, std::string (" inline-text" ), -1 );
143+ auto inline_raw_text_node =
144+ std::make_unique<RawTextShadowNode>(owner_, std::string (" raw-text" ), -1 );
145+ inline_raw_text_node->SetText (" ..." );
146+ inline_text_node->AddChild (inline_raw_text_node.get ());
147+ inline_truncation_node->AddChild (inline_text_node.get ());
148+ text_shadow_node_->AddChild (inline_truncation_node.get ());
149+
150+ text_shadow_node_->Measure (constraint);
151+
152+ EXPECT_EQ (text_shadow_node_->text_style_ ->font_size , 42 );
153+ }
154+
66155TEST_F_UI (TextTest, DISABLED_AutoFontSizePreset) {
67156 MeasureConstraint constraint{1000 , MeasureMode::kDefinite , 100 ,
68157 MeasureMode::kDefinite };
0 commit comments