1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "text_base.h"
17 
18 namespace OHOS::Ace::NG {
19 
20 namespace {} // namespace
21 
22 class TextTestTwoNg : public TextBases {
23 public:
24 };
25 
26 /**
27  * @tc.name: TextOverlayModifierTest001
28  * @tc.desc: test text_overlay_modifier.cpp.
29  * @tc.type: FUNC
30  */
31 HWTEST_F(TextTestTwoNg, TextOverlayModifierTest001, TestSize.Level1)
32 {
33     /**
34      * @tc.steps: step1. create textOverlayModifier and call text_overlay_modifier.cpp function.
35      * @tc.expected: The member variable value of textOverlayModifier is the value set above
36      */
37     TextOverlayModifier textOverlayModifier;
38     OffsetF paintOffset;
39     textOverlayModifier.SetPrintOffset(paintOffset);
40     textOverlayModifier.SetCursorColor(CURSOR_COLOR);
41     textOverlayModifier.SetSelectedColor(SELECTED_COLOR);
42     std::vector<RectF> rectList;
43     rectList.push_back(RectF(RECT_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE));
44     textOverlayModifier.SetSelectedRects(rectList);
45     // change selectedRects_ and call IsSelectedRectsChanged function
46     RectF secondRect(RECT_SECOND_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE);
47     textOverlayModifier.selectedRects_[0] = secondRect;
48     Testing::MockCanvas canvas;
49     EXPECT_CALL(canvas, Save()).WillRepeatedly(Return());
50     EXPECT_CALL(canvas, AttachBrush(_)).WillRepeatedly(ReturnRef(canvas));
51     EXPECT_CALL(canvas, DrawRect(_)).WillRepeatedly(Return());
52     EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
53     EXPECT_CALL(canvas, Restore()).WillRepeatedly(Return());
54     DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE };
55     RectF contentRect;
56     textOverlayModifier.SetContentRect(contentRect);
57     textOverlayModifier.onDraw(context);
58     EXPECT_EQ(textOverlayModifier.paintOffset_->Get(), paintOffset);
59     EXPECT_EQ(textOverlayModifier.cursorColor_->Get(), CURSOR_COLOR);
60     EXPECT_EQ(textOverlayModifier.selectedColor_->Get(), SELECTED_COLOR);
61     EXPECT_EQ(textOverlayModifier.IsSelectedRectsChanged(rectList), true);
62     EXPECT_EQ(textOverlayModifier.contentRect_, contentRect);
63 }
64 
65 /**
66  * @tc.name: TextPaintMethodTest002
67  * @tc.desc: test text_paint_method.cpp without setting textOverflow
68  * @tc.type: FUNC
69  */
70 HWTEST_F(TextTestTwoNg, TextPaintMethodTest002, TestSize.Level1)
71 {
72     /**
73      * @tc.steps: step1. create textFrameNode and textLayoutProperty.
74      */
75     auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
76     ASSERT_NE(textFrameNode, nullptr);
77     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
78     ASSERT_NE(geometryNode, nullptr);
79     RefPtr<LayoutWrapperNode> layoutWrapper =
80         AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
81     auto textPattern = textFrameNode->GetPattern<TextPattern>();
82     ASSERT_NE(textPattern, nullptr);
83     auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
84     ASSERT_NE(textLayoutProperty, nullptr);
85 
86     /**
87      * @tc.steps: step2. create textPaintMethod and update textLayoutProperty.
88      */
89     auto pattern = textFrameNode->GetPattern<Pattern>();
90     ParagraphStyle paragraphStyle;
91     RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
92     RefPtr<TextContentModifier> textContentModifier =
93         AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
94     RefPtr<TextOverlayModifier> textOverlayModifier = AceType::MakeRefPtr<TextOverlayModifier>();
95     TextPaintMethod textPaintMethod(pattern, BASE_LINE_OFFSET_VALUE, textContentModifier, textOverlayModifier);
96     textLayoutProperty->UpdateFontSize(ADAPT_FONT_SIZE_VALUE);
97     textLayoutProperty->UpdateFontWeight(Ace::FontWeight::W200);
98     textLayoutProperty->UpdateTextColor(TEXT_COLOR_VALUE);
99     Shadow textShadow;
100     textShadow.SetBlurRadius(BLURRADIUS_VALUE);
101     textShadow.SetColor(TEXT_COLOR_VALUE);
102     textShadow.SetSpreadRadius(SPREADRADIUS_VALUE);
103     textShadow.SetOffsetX(ADAPT_OFFSETX_VALUE);
104     textShadow.SetOffsetY(ADAPT_OFFSETY_VALUE);
105     textLayoutProperty->UpdateTextShadow({ textShadow });
106     textLayoutProperty->UpdateTextDecorationColor(TEXT_COLOR_VALUE);
107     textLayoutProperty->UpdateTextDecoration(TextDecoration::OVERLINE);
108     textLayoutProperty->UpdateBaselineOffset(ADAPT_BASE_LINE_OFFSET_VALUE);
109 
110     /**
111      * @tc.steps: step3. call UpdateContentModifier,UpdateOverlayModifier and GetOverlayModifier.
112      * @tc.expected: The return value of GetOverlayModifier is not empty
113      */
114     RefPtr<RenderContext> renderContext = RenderContext::Create();
115     auto paintProperty = textPattern->CreatePaintProperty();
116     auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty);
117     textPaintMethod.UpdateContentModifier(AceType::RawPtr(paintWrapper));
118     textPaintMethod.UpdateOverlayModifier(AceType::RawPtr(paintWrapper));
119     auto OverlayModifier = textPaintMethod.GetOverlayModifier(AceType::RawPtr(paintWrapper));
120     ASSERT_NE(OverlayModifier, nullptr);
121 }
122 
123 /**
124  * @tc.name: TextAccessibilityPropertyGetText001
125  * @tc.desc: Test GetText of text.
126  * @tc.type: FUNC
127  */
128 HWTEST_F(TextTestTwoNg, TextAccessibilityPropertyGetText001, TestSize.Level1)
129 {
130     TextModelNG textModel;
131     textModel.Create(CREATE_VALUE);
132     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
133     ASSERT_NE(frameNode, nullptr);
134     auto textPattern = frameNode->GetPattern<TextPattern>();
135     ASSERT_NE(textPattern, nullptr);
136     auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
137     ASSERT_NE(textAccessibilityProperty, nullptr);
138 
139     auto textLayoutProperty = frameNode->GetLayoutProperty<TextLayoutProperty>();
140     ASSERT_NE(textLayoutProperty, nullptr);
141     textLayoutProperty->UpdateContent(CREATE_VALUE);
142     EXPECT_EQ(textAccessibilityProperty->GetText(), CREATE_VALUE);
143 
144     auto spanNode = SpanNode::GetOrCreateSpanNode(ElementRegister::GetInstance()->MakeUniqueId());
145     frameNode->AddChild(spanNode);
146     textPattern->textForDisplay_ = TEXT_CONTENT;
147     EXPECT_EQ(textAccessibilityProperty->GetText(), TEXT_CONTENT);
148 }
149 
150 /**
151  * @tc.name: TextAccessibilityPropertyIsSelected001
152  * @tc.desc: Test IsSelected of text.
153  * @tc.type: FUNC
154  */
155 HWTEST_F(TextTestTwoNg, TextAccessibilityPropertyIsSelected001, TestSize.Level1)
156 {
157     TextModelNG textModel;
158     textModel.Create(CREATE_VALUE);
159     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
160     ASSERT_NE(frameNode, nullptr);
161     auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
162     ASSERT_NE(textAccessibilityProperty, nullptr);
163     EXPECT_FALSE(textAccessibilityProperty->IsSelected());
164     textAccessibilityProperty->SetSelected(true);
165     EXPECT_TRUE(textAccessibilityProperty->IsSelected());
166 }
167 
168 /**
169  * @tc.name: TextAccessibilityPropertyGetTextSelectionStart001
170  * @tc.desc: Test GetTextSelectionStart of text.
171  * @tc.type: FUNC
172  */
173 HWTEST_F(TextTestTwoNg, TextAccessibilityPropertyGetTextSelectionStart001, TestSize.Level1)
174 {
175     TextModelNG textModel;
176     textModel.Create(CREATE_VALUE);
177     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
178     ASSERT_NE(frameNode, nullptr);
179     auto textPattern = frameNode->GetPattern<TextPattern>();
180     ASSERT_NE(textPattern, nullptr);
181     auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
182     ASSERT_NE(textAccessibilityProperty, nullptr);
183     EXPECT_EQ(textAccessibilityProperty->GetTextSelectionStart(), TEXT_ERROR);
184     textPattern->textSelector_.Update(0, TEXT_SIZE_INT);
185     EXPECT_EQ(textAccessibilityProperty->GetTextSelectionStart(), 0);
186 }
187 
188 /**
189  * @tc.name: TextAccessibilityPropertyGetTextSelectionEnd001
190  * @tc.desc: Test GetTextSelectionEnd of text.
191  * @tc.type: FUNC
192  */
193 HWTEST_F(TextTestTwoNg, TextAccessibilityPropertyGetTextSelectionEnd001, TestSize.Level1)
194 {
195     TextModelNG textModel;
196     textModel.Create(CREATE_VALUE);
197     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
198     ASSERT_NE(frameNode, nullptr);
199     auto textPattern = frameNode->GetPattern<TextPattern>();
200     ASSERT_NE(textPattern, nullptr);
201     auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
202     ASSERT_NE(textAccessibilityProperty, nullptr);
203     EXPECT_EQ(textAccessibilityProperty->GetTextSelectionEnd(), TEXT_ERROR);
204     textPattern->textSelector_.Update(0, TEXT_SIZE_INT);
205     EXPECT_EQ(textAccessibilityProperty->GetTextSelectionEnd(), TEXT_SIZE_INT);
206 }
207 
208 /**
209  * @tc.name: TextAccessibilityPropertyGetSupportAction001
210  * @tc.desc: Test GetSupportAction of text.
211  * @tc.type: FUNC
212  */
213 HWTEST_F(TextTestTwoNg, TextAccessibilityPropertyGetSupportAction001, TestSize.Level1)
214 {
215     TextModelNG textModel;
216     textModel.Create(CREATE_VALUE);
217     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
218     ASSERT_NE(frameNode, nullptr);
219     auto textPattern = frameNode->GetPattern<TextPattern>();
220     ASSERT_NE(textPattern, nullptr);
221     auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
222     ASSERT_NE(textAccessibilityProperty, nullptr);
223     auto textLayoutProperty = frameNode->GetLayoutProperty<TextLayoutProperty>();
224     ASSERT_NE(textLayoutProperty, nullptr);
225     textLayoutProperty->UpdateCopyOption(CopyOptions::InApp);
226     textAccessibilityProperty->ResetSupportAction();
227     std::unordered_set<AceAction> supportAceActions = textAccessibilityProperty->GetSupportAction();
228     uint64_t actions = 0, expectActions = 0;
229     expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_COPY);
230     expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_SET_SELECTION);
231     expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_CLEAR_SELECTION);
232     for (auto action : supportAceActions) {
233         actions |= 1UL << static_cast<uint32_t>(action);
234     }
235     EXPECT_EQ(actions, expectActions);
236 }
237 
238 /**
239  * @tc.name: TextModelNgTest001
240  * @tc.desc: test text_model_ng.cpp SetHeightAdaptivePolicy and SetTextShadow
241  * @tc.type: FUNC
242  */
243 HWTEST_F(TextTestTwoNg, TextModelNgTest001, TestSize.Level1)
244 {
245     /**
246      * @tc.steps: step1. create textFrameNode.
247      */
248     auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
249     ASSERT_NE(textFrameNode, nullptr);
250     auto textPattern = textFrameNode->GetPattern<TextPattern>();
251     ASSERT_NE(textPattern, nullptr);
252     auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
253     ASSERT_NE(textLayoutProperty, nullptr);
254 
255     /**
256      * @tc.steps: step2. call SetHeightAdaptivePolicy and SetTextShadow.
257      * @tc.expected: The HeightAdaptivePolicyValue of textLayoutProperty is MAX_LINES_FIRST.
258      *               The TextShadowValue of textLayoutProperty is textShadow.
259      */
260     TextModelNG text;
261     text.Create("text");
262     text.SetHeightAdaptivePolicy(TextHeightAdaptivePolicy::MAX_LINES_FIRST);
263     Shadow textShadow;
264     text.SetTextShadow({ textShadow });
265     EXPECT_EQ(textLayoutProperty->GetHeightAdaptivePolicyValue(TextHeightAdaptivePolicy::MAX_LINES_FIRST),
266         TextHeightAdaptivePolicy::MAX_LINES_FIRST);
267     EXPECT_EQ(*textLayoutProperty->GetTextShadowValue({ textShadow }).begin(), textShadow);
268 }
269 
270 /**
271  * @tc.name: TextPatternTest001
272  * @tc.desc: test text_pattern.h CreateNodePaintMethod function
273  * @tc.type: FUNC
274  */
275 HWTEST_F(TextTestTwoNg, TextPatternTest001, TestSize.Level1)
276 {
277     /**
278      * @tc.steps: step1. create textFrameNode and textPattern.
279      */
280     auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
281     ASSERT_NE(textFrameNode, nullptr);
282     auto textPattern = textFrameNode->GetPattern<TextPattern>();
283     ASSERT_NE(textPattern, nullptr);
284 
285     /**
286      * @tc.steps: step2. call CreateNodePaintMethod function.
287      * @tc.expected: The return value of CreateNodePaintMethod is not empty.
288      *               textPattern's textContentModifier_ is not empty.
289      *               textPattern's textOverlayModifier_ is not empty.
290      */
291     auto nodePaintMethod = textPattern->CreateNodePaintMethod();
292     ASSERT_NE(nodePaintMethod, nullptr);
293     ASSERT_NE(textPattern->contentMod_, nullptr);
294     ASSERT_NE(textPattern->overlayMod_, nullptr);
295 }
296 
297 /**
298  * @tc.name: TextPatternTest002
299  * @tc.desc: test text_pattern.h CreateNodePaintMethod function
300  * @tc.type: FUNC
301  */
302 HWTEST_F(TextTestTwoNg, TextPatternTest002, TestSize.Level1)
303 {
304     /**
305      * @tc.steps: step1. create textFrameNode and textPattern.
306      */
307     auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
308     ASSERT_NE(textFrameNode, nullptr);
309     auto textPattern = textFrameNode->GetPattern<TextPattern>();
310     ASSERT_NE(textPattern, nullptr);
311 
312     /**
313      * @tc.steps: step2. call CreateLayoutProperty function.
314      * @tc.expected: The return value of CreateLayoutProperty is not empty.
315      */
316     RefPtr<LayoutProperty> textLayoutProperty = textPattern->CreateLayoutProperty();
317     ASSERT_NE(textLayoutProperty, nullptr);
318 }
319 
320 /**
321  * @tc.name: TextPatternTest003
322  * @tc.desc: test text_pattern.h CreateNodePaintMethod function
323  * @tc.type: FUNC
324  */
325 HWTEST_F(TextTestTwoNg, TextPatternTest003, TestSize.Level1)
326 {
327     /**
328      * @tc.steps: step1. create textFrameNode and textPattern.
329      */
330     auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
331     ASSERT_NE(textFrameNode, nullptr);
332     auto textPattern = textFrameNode->GetPattern<TextPattern>();
333     ASSERT_NE(textPattern, nullptr);
334 
335     /**
336      * @tc.steps: step2. call CreateLayoutAlgorithm function.
337      * @tc.expected: The return value of CreateLayoutAlgorithm is not empty.
338      */
339     RefPtr<LayoutAlgorithm> textLayoutAlgorithm = textPattern->CreateLayoutAlgorithm();
340     ASSERT_NE(textLayoutAlgorithm, nullptr);
341 }
342 
343 /**
344  * @tc.name: TextPatternTest004
345  * @tc.desc: Test the CopyOption value while in Marquee state.
346  * @tc.type: FUNC
347  */
348 HWTEST_F(TextTestTwoNg, TextPatternTest004, TestSize.Level1)
349 {
350     /**
351      * @tc.steps: step1. create textFrameNode and textPattern.
352      */
353     auto textFrameNode = FrameNode::CreateFrameNode("", 0, AceType::MakeRefPtr<TextPattern>());
354     ASSERT_NE(textFrameNode, nullptr);
355     auto textPattern = textFrameNode->GetPattern<TextPattern>();
356     ASSERT_NE(textPattern, nullptr);
357 
358     /**
359      * @tc.steps: step2. set the TextOverflow value to Marquee.
360      */
361     auto textLayoutProperty = textFrameNode->GetLayoutProperty<TextLayoutProperty>();
362     ASSERT_NE(textLayoutProperty, nullptr);
363     textLayoutProperty->UpdateCopyOption(CopyOptions::InApp);
364     textLayoutProperty->UpdateTextOverflow(TextOverflow::MARQUEE);
365 
366     /**
367      * @tc.steps: step3. call OnModifyDone function.
368      * @tc.expected: The copyOption_ value is equal to CopyOptions::InApp.
369      */
370     textPattern->OnModifyDone();
371 }
372 
373 /**
374  * @tc.name: TextPatternTest005
375  * @tc.desc: Test the SetImageSpanNodeList func of TextPattern.
376  * @tc.type: FUNC
377  */
378 HWTEST_F(TextTestTwoNg, TextPatternTest005, TestSize.Level1)
379 {
380     /**
381      * @tc.steps: step1. create textFrameNode and textPattern.
382      */
383     auto textFrameNode = FrameNode::CreateFrameNode("", 0, AceType::MakeRefPtr<TextPattern>());
384     ASSERT_NE(textFrameNode, nullptr);
385     auto textPattern = textFrameNode->GetPattern<TextPattern>();
386     ASSERT_NE(textPattern, nullptr);
387 
388     /**
389      * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList.
390      */
391     std::vector<WeakPtr<FrameNode>> imageNodeList;
392     auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG,
393 		ElementRegister::GetInstance()->MakeUniqueId(),
__anonfc8d98b90202() 394         []() { return AceType::MakeRefPtr<ImagePattern>(); });
395     imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode)));
396 
397     /**
398      * @tc.steps: step3. call SetImageSpanNodeList.
399      * @tc.expected: The imageNodeList_ size is equal to 1.
400      */
401     textPattern->SetImageSpanNodeList(imageNodeList);
402     EXPECT_EQ(textPattern->imageNodeList_.size(), 1);
403 }
404 
405 /**
406  * @tc.name: TextPatternTest006
407  * @tc.desc: Test the SetImageSpanNodeList func of TextPattern.
408  * @tc.type: FUNC
409  */
410 HWTEST_F(TextTestTwoNg, TextPatternTest006, TestSize.Level1)
411 {
412     /**
413      * @tc.steps: step1. create textFrameNode and textPattern.
414      */
415     auto textFrameNode = FrameNode::CreateFrameNode("", 0, AceType::MakeRefPtr<TextPattern>());
416     ASSERT_NE(textFrameNode, nullptr);
417     auto textPattern = textFrameNode->GetPattern<TextPattern>();
418     ASSERT_NE(textPattern, nullptr);
419 
420     /**
421      * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList.
422      */
423     std::vector<WeakPtr<FrameNode>> imageNodeLocalList;
424     std::vector<WeakPtr<FrameNode>> imageNodeList;
425     for (int i = 0; i < 10; i++) {
426         auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG,
427 			ElementRegister::GetInstance()->MakeUniqueId(),
__anonfc8d98b90302() 428             []() { return AceType::MakeRefPtr<ImagePattern>(); });
429         imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode)));
430         imageNodeLocalList.emplace_back(imageNode);
431     }
432 
433     /**
434      * @tc.steps: step3. call SetImageSpanNodeList.
435      * @tc.expected: The imageNodeList_ size is equal to 10.
436      */
437     textPattern->SetImageSpanNodeList(imageNodeList);
438     EXPECT_EQ(textPattern->imageNodeList_.size(), 10);
439 }
440 
441 /**
442  * @tc.name: TextPatternTest007
443  * @tc.desc: Test the SetImageSpanNodeList func of TextPattern.
444  * @tc.type: FUNC
445  */
446 HWTEST_F(TextTestTwoNg, TextPatternTest007, TestSize.Level1)
447 {
448     /**
449      * @tc.steps: step1. create textFrameNode and textPattern.
450      */
451     auto textFrameNode = FrameNode::CreateFrameNode("", 0, AceType::MakeRefPtr<TextPattern>());
452     ASSERT_NE(textFrameNode, nullptr);
453     auto textPattern = textFrameNode->GetPattern<TextPattern>();
454     ASSERT_NE(textPattern, nullptr);
455 
456     /**
457      * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList.
458      */
459     std::vector<WeakPtr<FrameNode>> imageNodeLocalList;
460     std::vector<WeakPtr<FrameNode>> imageNodeList;
461     for (int i = 0; i < 100; i++) {
462         auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG,
463             ElementRegister::GetInstance()->MakeUniqueId(),
__anonfc8d98b90402() 464 			[]() { return AceType::MakeRefPtr<ImagePattern>(); });
465         imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode)));
466         imageNodeLocalList.emplace_back(imageNode);
467     }
468 
469     /**
470      * @tc.steps: step3. call SetImageSpanNodeList.
471      * @tc.expected: The imageNodeList_ size is equal to 100.
472      */
473     textPattern->SetImageSpanNodeList(imageNodeList);
474     EXPECT_EQ(textPattern->imageNodeList_.size(), 100);
475 }
476 
477 /**
478  * @tc.name: TextPatternTest008
479  * @tc.desc: Test the SetImageSpanNodeList func of TextPattern.
480  * @tc.type: FUNC
481  */
482 HWTEST_F(TextTestTwoNg, TextPatternTest008, TestSize.Level1)
483 {
484     /**
485      * @tc.steps: step1. create textFrameNode and textPattern.
486      */
487     auto textFrameNode = FrameNode::CreateFrameNode("", 0, AceType::MakeRefPtr<TextPattern>());
488     ASSERT_NE(textFrameNode, nullptr);
489     auto textPattern = textFrameNode->GetPattern<TextPattern>();
490     ASSERT_NE(textPattern, nullptr);
491 
492     /**
493      * @tc.steps: step2. call SetImageSpanNodeList.
494      * @tc.expected: The imageNodeList_ size is equal to 0.
495      */
496     EXPECT_EQ(textPattern->imageNodeList_.size(), 0);
497 }
498 
499 /**
500  * @tc.name: TextPatternTest009
501  * @tc.desc: Test the SetImageSpanNodeList func of TextPattern.
502  * @tc.type: FUNC
503  */
504 HWTEST_F(TextTestTwoNg, TextPatternTest009, TestSize.Level1)
505 {
506     /**
507      * @tc.steps: step1. create textFrameNode and textPattern.
508      */
509     auto textFrameNode = FrameNode::CreateFrameNode("", 0, AceType::MakeRefPtr<TextPattern>());
510     ASSERT_NE(textFrameNode, nullptr);
511     auto textPattern = textFrameNode->GetPattern<TextPattern>();
512     ASSERT_NE(textPattern, nullptr);
513 
514     /**
515      * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList.
516      */
517     std::vector<WeakPtr<FrameNode>> imageNodeList;
518     imageNodeList.emplace_back(nullptr);
519 
520     /**
521      * @tc.steps: step3. call SetImageSpanNodeList.
522      * @tc.expected: The imageNodeList_ size is equal to 1.
523      */
524     textPattern->SetImageSpanNodeList(imageNodeList);
525     EXPECT_EQ(textPattern->imageNodeList_.size(), 1);
526 }
527 
528 /**
529  * @tc.name: TextPatternTest010
530  * @tc.desc: Test the SetImageSpanNodeList func of TextPattern.
531  * @tc.type: FUNC
532  */
533 HWTEST_F(TextTestTwoNg, TextPatternTest010, TestSize.Level1)
534 {
535     /**
536      * @tc.steps: step1. create textFrameNode and textPattern.
537      */
538     auto textFrameNode = FrameNode::CreateFrameNode("", 0, AceType::MakeRefPtr<TextPattern>());
539     ASSERT_NE(textFrameNode, nullptr);
540     auto textPattern = textFrameNode->GetPattern<TextPattern>();
541     ASSERT_NE(textPattern, nullptr);
542 
543     /**
544      * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList.
545      */
546     std::vector<WeakPtr<FrameNode>> imageNodeList;
547     for (int i = 0; i < 10; i++) {
548         imageNodeList.emplace_back(nullptr);
549     }
550 
551     /**
552      * @tc.steps: step3. call SetImageSpanNodeList.
553      * @tc.expected: The imageNodeList_ size is equal to 10.
554      */
555     textPattern->SetImageSpanNodeList(imageNodeList);
556     EXPECT_EQ(textPattern->imageNodeList_.size(), 10);
557 }
558 
559 /**
560  * @tc.name: TextPatternTest011
561  * @tc.desc: Test the SetImageSpanNodeList func of TextPattern.
562  * @tc.type: FUNC
563  */
564 HWTEST_F(TextTestTwoNg, TextPatternTest011, TestSize.Level1)
565 {
566     /**
567      * @tc.steps: step1. create textFrameNode and textPattern.
568      */
569     auto textFrameNode = FrameNode::CreateFrameNode("", 0, AceType::MakeRefPtr<TextPattern>());
570     ASSERT_NE(textFrameNode, nullptr);
571     auto textPattern = textFrameNode->GetPattern<TextPattern>();
572     ASSERT_NE(textPattern, nullptr);
573 
574     /**
575      * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList.
576      */
577     std::vector<WeakPtr<FrameNode>> imageNodeLocalList;
578     std::vector<WeakPtr<FrameNode>> imageNodeList;
579     for (int i = 0; i < 100; i++) {
580         imageNodeList.emplace_back(nullptr);
581     }
582 
583     /**
584      * @tc.steps: step3. call SetImageSpanNodeList.
585      * @tc.expected: The imageNodeList_ size is equal to 100.
586      */
587     textPattern->SetImageSpanNodeList(imageNodeList);
588     EXPECT_EQ(textPattern->imageNodeList_.size(), 100);
589 }
590 
591 /**
592  * @tc.name: CreateParagraph001
593  * @tc.desc: test text_pattern.h CreateNodePaintMethod function
594  * @tc.type: FUNC
595  */
596 HWTEST_F(TextTestTwoNg, CreateParagraph001, TestSize.Level1)
597 {
598     auto paragraph = MockParagraph::GetOrCreateMockParagraph();
599     EXPECT_CALL(*paragraph, PushStyle);
600     EXPECT_CALL(*paragraph, AddText);
601     EXPECT_CALL(*paragraph, Build);
602 
603     auto pattern = AceType::MakeRefPtr<TextPattern>();
604     ASSERT_NE(pattern, nullptr);
605     auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
606     ASSERT_NE(frameNode, nullptr);
607     pattern->AttachToFrameNode(frameNode);
608 
609     DirtySwapConfig config;
610     config.skipMeasure = false;
611     auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
612         frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
613     ASSERT_NE(layoutWrapper, nullptr);
614     auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
615     TextStyle textStyle;
616     LayoutConstraintF contentConstraint;
617     auto ret = rowLayoutAlgorithm->CreateParagraph(textStyle, "", AceType::RawPtr(frameNode));
618     EXPECT_TRUE(ret);
619 }
620 
621 /**
622  * @tc.name: Layout001
623  * @tc.desc: test text_pattern.h CreateNodePaintMethod function
624  * @tc.type: FUNC
625  */
626 HWTEST_F(TextTestTwoNg, Layout001, TestSize.Level1)
627 {
628     auto* stack = ViewStackProcessor::GetInstance();
629     auto nodeId = stack->ClaimNodeId();
630     auto pattern = AceType::MakeRefPtr<TextPattern>();
631     ASSERT_NE(pattern, nullptr);
632     auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
633     ASSERT_NE(frameNode, nullptr);
634     pattern->AttachToFrameNode(frameNode);
635 
636     DirtySwapConfig config;
637     config.skipMeasure = false;
638     auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
639         frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
640     ASSERT_NE(layoutWrapper, nullptr);
641 
642     layoutWrapper->children_.push_back(layoutWrapper);
643     auto imageSpanNode = FrameNode::GetOrCreateFrameNode(
__anonfc8d98b90502() 644         V2::IMAGE_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ImagePattern>(); });
645     ASSERT_NE(imageSpanNode, nullptr);
646 }
647 
648 /**
649  * @tc.name: ApplyIndents001
650  * @tc.desc: test text_pattern.h CreateNodePaintMethod function
651  * @tc.type: FUNC
652  */
653 HWTEST_F(TextTestTwoNg, ApplyIndents001, TestSize.Level1)
654 {
655     auto pattern = AceType::MakeRefPtr<TextPattern>();
656     ASSERT_NE(pattern, nullptr);
657     auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
658     ASSERT_NE(frameNode, nullptr);
659     pattern->AttachToFrameNode(frameNode);
660 
661     DirtySwapConfig config;
662     config.skipMeasure = false;
663     auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
664         frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
665     ASSERT_NE(layoutWrapper, nullptr);
666     auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
667     TextStyle textStyle;
668     LayoutConstraintF contentConstraint;
669     auto ret = rowLayoutAlgorithm->CreateParagraph(textStyle, "", AceType::RawPtr(frameNode));
670     EXPECT_TRUE(ret);
671 }
672 
673 /**
674  * @tc.name: AddChildSpanItem001
675  * @tc.desc: test text_pattern.h CreateNodePaintMethod function
676  * @tc.type: FUNC
677  */
678 HWTEST_F(TextTestTwoNg, AddChildSpanItem001, TestSize.Level1)
679 {
680     auto pattern = AceType::MakeRefPtr<TextPattern>();
681     ASSERT_NE(pattern, nullptr);
682     auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
683     ASSERT_NE(frameNode, nullptr);
684     pattern->AttachToFrameNode(frameNode);
685 
686     DirtySwapConfig config;
687     config.skipMeasure = false;
688     auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
689         frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
690     ASSERT_NE(layoutWrapper, nullptr);
691     auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
692     SpanModelNG spanModelNG;
693     spanModelNG.Create(CREATE_VALUE);
694     TextStyle textStyle;
695     RefPtr<UINode> element = ViewStackProcessor::GetInstance()->Finish();
696     pattern->AddChildSpanItem(element);
697     auto ret = rowLayoutAlgorithm->CreateParagraph(textStyle, "", AceType::RawPtr(frameNode));
698     EXPECT_TRUE(ret);
699 }
700 
701 /**
702  * @tc.name: ShowSelectOverlay003
703  * @tc.desc: test text_pattern.h ShowSelectOverlay function
704  * @tc.type: FUNC
705  */
706 HWTEST_F(TextTestTwoNg, ShowSelectOverlay003, TestSize.Level1)
707 {
708     auto [frameNode, pattern] = Init();
709     GestureEvent info;
710     info.localLocation_ = Offset(1, 1);
711     // copyOption = None
712     pattern->HandleLongPress(info);
713     EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
714 
715     pattern->copyOption_ = CopyOptions::Distributed;
716     pattern->textForDisplay_ = "test";
717     pattern->textSelector_.Update(0, 20);
718 
719     pattern->ShowSelectOverlay();
720     EXPECT_NE(pattern->textSelector_.GetTextStart(), -1);
721     EXPECT_NE(pattern->textSelector_.GetTextEnd(), -1);
722 }
723 
724 /**
725  * @tc.name: ShowSelectOverlay004
726  * @tc.desc: test text_pattern.h ShowSelectOverlay function when menuOptionItems_ is not nullptr
727  * @tc.type: FUNC
728  */
729 HWTEST_F(TextTestTwoNg, ShowSelectOverlay004, TestSize.Level1)
730 {
731     /**
732      * @tc.steps: step1. create frameNode and pattern
733      */
734     auto [frameNode, pattern] = Init();
735     GestureEvent info;
736     info.localLocation_ = Offset(1, 1);
737     pattern->HandleLongPress(info);
738     EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
739     /**
740      * @tc.steps: step2. construct menuOptionItems
741      */
742     pattern->copyOption_ = CopyOptions::InApp;
743     pattern->textForDisplay_ = "test";
744     pattern->textSelector_.Update(0, 20);
745     OnCreateMenuCallback onCreateMenuCallback;
746     OnMenuItemClickCallback onMenuItemClick;
747     pattern->selectOverlay_->OnSelectionMenuOptionsUpdate(std::move(onCreateMenuCallback), std::move(onMenuItemClick));
748 
749     /**
750      * @tc.steps: step2. call ShowSelectOverlay function
751      * @tc.expected: the property of selectInfo is assigned.
752      */
753     pattern->ShowSelectOverlay();
754     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
755     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 20);
756 }
757 
758 /**
759  * @tc.name: IsDraggable001
760  * @tc.desc: test text_pattern.h Draggable function
761  * @tc.type: FUNC
762  */
763 HWTEST_F(TextTestTwoNg, IsDraggable001, TestSize.Level1)
764 {
765     auto paragraph = MockParagraph::GetOrCreateMockParagraph();
766     std::vector<RectF> rects { RectF(0, 0, 20, 20) };
767     EXPECT_CALL(*paragraph, GetRectsForRange(_, _, _)).WillRepeatedly(SetArgReferee<2>(rects));
768 
769     auto [host, pattern] = Init();
770     pattern->copyOption_ = CopyOptions::Distributed;
771     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 });
772     host->draggable_ = true;
773     host->eventHub_->SetOnDragStart(
__anonfc8d98b90602(const RefPtr<Ace::DragEvent>&, const std::string&) 774         [](const RefPtr<Ace::DragEvent>&, const std::string&) -> DragDropInfo { return {}; });
775 
776     /**
777      * @tc.steps: step1. set selected rect to [0, 0] - [20, 20]
778      * @tc.expected: return true if the location is in region
779      */
780     pattern->textSelector_.Update(0, 20);
781     EXPECT_TRUE(pattern->IsDraggable(Offset(1, 1)));
782 
783     /**
784      * @tc.expected: return false if the location is not in region
785      */
786     EXPECT_FALSE(pattern->IsDraggable(Offset(21, 21)));
787 
788     /**
789      * @tc.steps: step2. text not selected
790      * @tc.expected: return false
791      */
792     pattern->textSelector_.Update(-1);
793     EXPECT_FALSE(pattern->IsDraggable(Offset(1, 1)));
794     pattern->pManager_->Reset();
795 }
796 
797 /**
798  * @tc.name: DragBase001
799  * @tc.desc: test text_pattern.h DragBase function
800  * @tc.type: FUNC
801  */
802 HWTEST_F(TextTestTwoNg, DragBase001, TestSize.Level1)
803 {
804     auto [frameNode, pattern] = Init();
805 
806     // test ResetSelection should reset textSelector
807     pattern->CreateHandles();
808     pattern->textSelector_.Update(0, 20);
809     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
810     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 20);
811     pattern->CloseSelectOverlay();
812     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
813     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 20);
814     pattern->ResetSelection();
815     EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
816     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
817 
818     // test GetTextBoxes and GetLineHeight
819     auto paragraph = MockParagraph::GetOrCreateMockParagraph();
820     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 });
821     std::vector<RectF> rects { RectF(0, 0, 20, 20) };
822     EXPECT_CALL(*paragraph, GetRectsForRange(_, _, _)).WillRepeatedly(SetArgReferee<2>(rects));
823 
824     pattern->textSelector_.Update(0, 20);
825     auto boxes = pattern->GetTextBoxes();
826     EXPECT_EQ(boxes.size(), 1);
827     EXPECT_EQ(boxes[0].Left(), 0);
828     EXPECT_EQ(boxes[0].Right(), 20);
829 
830     auto height = pattern->GetLineHeight();
831     EXPECT_EQ(height, 20);
832     pattern->pManager_->Reset();
833 }
834 
835 /**
836  * @tc.name: TextDecorationStyleTest001
837  * @tc.desc: test text_model_ng.cpp SetTextDecorationStyle
838  * @tc.type: FUNC
839  */
840 HWTEST_F(TextTestTwoNg, TextDecorationStyleTest001, TestSize.Level1)
841 {
842     TextModelNG text;
843     text.Create(CREATE_VALUE);
844     text.SetTextDecorationStyle(TextDecorationStyle::DOUBLE);
845     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
846     ASSERT_NE(frameNode, nullptr);
847     RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
848     ASSERT_NE(layoutProperty, nullptr);
849     RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
850     ASSERT_NE(textLayoutProperty, nullptr);
851     EXPECT_EQ(textLayoutProperty->GetTextDecorationStyle(), TextDecorationStyle::DOUBLE);
852 }
853 
854 /**
855  * @tc.name: TextDecorationStyleTest002
856  * @tc.desc: Test TextDecorationStyle of Text will be inheritted by Span
857  * @tc.type: FUNC
858  */
859 HWTEST_F(TextTestTwoNg, TextDecorationStyleTest002, TestSize.Level1)
860 {
861     /**
862      * @tc.steps: step1. create text FrameNode and set TextDecoration values
863      * @tc.expected: Successfully created parent Node
864      */
865     TextModelNG textModelNG;
866     textModelNG.Create(CREATE_VALUE);
867     textModelNG.SetTextDecoration(TextDecoration::LINE_THROUGH);
868     textModelNG.SetTextDecorationStyle(TextDecorationStyle::DOUBLE);
869     auto textFrameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
870 
871     /**
872      * @tc.steps: step2. create spanNode without setting TextDecoration values
873      * @tc.expected: Successfully created spanNode
874      */
875     SpanModelNG spanModelNG;
876     spanModelNG.Create(CREATE_VALUE);
877     auto spanNode = AceType::DynamicCast<SpanNode>(ViewStackProcessor::GetInstance()->Finish());
878 
879     /**
880      * @tc.steps: step3. SpanNode mount to parent
881      */
882     textFrameNode->AddChild(spanNode);
883 
884     /**
885      * @tc.steps: step4. called BeforeCreateLayoutWrapper function to UpdateChildProperty
886      * @tc.expected: spanNode inherits parent property
887      */
888     auto textPattern = textFrameNode->GetPattern<TextPattern>();
889     ASSERT_NE(textPattern, nullptr);
890     textPattern->BeforeCreateLayoutWrapper();
891     EXPECT_EQ(spanNode->GetTextDecoration(), TextDecoration::LINE_THROUGH);
892     EXPECT_EQ(spanNode->GetTextDecorationStyle(), TextDecorationStyle::DOUBLE);
893 }
894 
895 /**
896  * @tc.name: TextDecorationStyleTest003
897  * @tc.desc: Test TextDecorationStyle of Text won't override that of Span
898  * @tc.type: FUNC
899  */
900 HWTEST_F(TextTestTwoNg, TextDecorationStyleTest003, TestSize.Level1)
901 {
902     /**
903      * @tc.steps: step1. create text FrameNode and set TextDecoration values
904      * @tc.expected: Successfully created parent Node
905      */
906     TextModelNG textModelNG;
907     textModelNG.Create(CREATE_VALUE);
908     textModelNG.SetTextDecoration(TextDecoration::LINE_THROUGH);
909     textModelNG.SetTextDecorationStyle(TextDecorationStyle::DOUBLE);
910     auto textFrameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
911 
912     /**
913      * @tc.steps: step2. create spanNode1 and set TextDecoration values
914      * @tc.expected: Successfully created spanNode1
915      */
916     SpanModelNG spanModelNG1;
917     spanModelNG1.Create(CREATE_VALUE);
918     spanModelNG1.SetTextDecoration(TextDecoration::OVERLINE);
919     spanModelNG1.SetTextDecorationStyle(TextDecorationStyle::WAVY);
920     auto spanNode1 = AceType::DynamicCast<SpanNode>(ViewStackProcessor::GetInstance()->Finish());
921 
922     /**
923      * @tc.steps: step3. create spanNode2 without setting TextDecoration values
924      * @tc.expected: Successfully created spanNode2
925      */
926     SpanModelNG spanModelNG2;
927     spanModelNG2.Create(TEXT_CONTENT);
928     auto spanNode2 = AceType::DynamicCast<SpanNode>(ViewStackProcessor::GetInstance()->Finish());
929 
930     /**
931      * @tc.steps: step4. SpanNode mount to parent
932      */
933     textFrameNode->AddChild(spanNode1);
934     textFrameNode->AddChild(spanNode2);
935 
936     /**
937      * @tc.steps: step5. called BeforeCreateLayoutWrapper function to UpdateChildProperty
938      * @tc.expected: spanNode1 uses own property and spanNode2 inherits parent property
939      */
940     auto textPattern = textFrameNode->GetPattern<TextPattern>();
941     ASSERT_NE(textPattern, nullptr);
942     textPattern->BeforeCreateLayoutWrapper();
943     EXPECT_EQ(spanNode1->GetTextDecoration(), TextDecoration::OVERLINE);
944     EXPECT_EQ(spanNode1->GetTextDecorationStyle(), TextDecorationStyle::WAVY);
945     EXPECT_EQ(spanNode2->GetTextDecoration(), TextDecoration::LINE_THROUGH);
946     EXPECT_EQ(spanNode2->GetTextDecorationStyle(), TextDecorationStyle::DOUBLE);
947 }
948 
949 /**
950  * @tc.name: TextDecorationToJsonValue001
951  * @tc.desc: Test Text Decoration ToJsonValue when values set.
952  * @tc.type: FUNC
953  */
954 HWTEST_F(TextTestTwoNg, TextDecorationToJsonValue001, TestSize.Level1)
955 {
956     TextModelNG text;
957     text.Create(CREATE_VALUE);
958     text.SetTextDecoration(TextDecoration::LINE_THROUGH);
959     text.SetTextDecorationColor(TEXT_DECORATION_COLOR_VALUE);
960     text.SetTextDecorationStyle(TextDecorationStyle::DOUBLE);
961     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
962     ASSERT_NE(frameNode, nullptr);
963     RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
964     ASSERT_NE(layoutProperty, nullptr);
965     RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
966     ASSERT_NE(textLayoutProperty, nullptr);
967     auto json = JsonUtil::Create(true);
968     textLayoutProperty->ToJsonValue(json, filter);
969     EXPECT_TRUE(json->Contains("content"));
970     EXPECT_TRUE(json->GetValue("content")->GetString() == CREATE_VALUE);
971     EXPECT_TRUE(json->Contains("decoration"));
972     std::string decorationStr = json->GetValue("decoration")->GetString();
973     auto decorationJson = JsonUtil::ParseJsonString(decorationStr);
974     ASSERT_NE(decorationJson, nullptr);
975     EXPECT_TRUE(decorationJson->Contains("type"));
976     EXPECT_TRUE(decorationJson->GetValue("type")->GetString() ==
977                 V2::ConvertWrapTextDecorationToStirng(TextDecoration::LINE_THROUGH));
978     EXPECT_TRUE(decorationJson->Contains("color"));
979     EXPECT_TRUE(decorationJson->GetValue("color")->GetString() == TEXT_COLOR_VALUE.ColorToString());
980     EXPECT_TRUE(decorationJson->Contains("style"));
981     EXPECT_TRUE(decorationJson->GetValue("style")->GetString() ==
982                 V2::ConvertWrapTextDecorationStyleToString(TextDecorationStyle::DOUBLE));
983 }
984 
985 /**
986  * @tc.name: TextDecorationToJsonValue002
987  * @tc.desc: Test Text Decoration ToJsonValue when default values.
988  * @tc.type: FUNC
989  */
990 HWTEST_F(TextTestTwoNg, TextDecorationToJsonValue002, TestSize.Level1)
991 {
992     TextModelNG text;
993     text.Create(CREATE_VALUE);
994     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
995     ASSERT_NE(frameNode, nullptr);
996     RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
997     ASSERT_NE(layoutProperty, nullptr);
998     RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
999     ASSERT_NE(textLayoutProperty, nullptr);
1000     auto json = JsonUtil::Create(true);
1001     textLayoutProperty->ToJsonValue(json, filter);
1002     EXPECT_TRUE(json->Contains("content"));
1003     EXPECT_TRUE(json->GetValue("content")->GetString() == CREATE_VALUE);
1004     EXPECT_TRUE(json->Contains("decoration"));
1005     std::string decorationStr = json->GetValue("decoration")->GetString();
1006     auto decorationJson = JsonUtil::ParseJsonString(decorationStr);
1007     ASSERT_NE(decorationJson, nullptr);
1008     EXPECT_TRUE(decorationJson->Contains("type"));
1009     EXPECT_TRUE(
1010         decorationJson->GetValue("type")->GetString() == V2::ConvertWrapTextDecorationToStirng(TextDecoration::NONE));
1011     EXPECT_TRUE(decorationJson->Contains("color"));
1012     EXPECT_TRUE(decorationJson->GetValue("color")->GetString() == Color::BLACK.ColorToString());
1013     EXPECT_TRUE(decorationJson->Contains("style"));
1014     EXPECT_TRUE(decorationJson->GetValue("style")->GetString() ==
1015                 V2::ConvertWrapTextDecorationStyleToString(TextDecorationStyle::SOLID));
1016 }
1017 
1018 /**
1019  * @tc.name: TextDecorationToJsonValue003
1020  * @tc.desc: Test Text Decoration ToJsonValue when set multiple textShadows.
1021  * @tc.type: FUNC
1022  */
1023 HWTEST_F(TextTestTwoNg, TextDecorationToJsonValue003, TestSize.Level1)
1024 {
1025     TextModelNG text;
1026     text.Create(CREATE_VALUE);
1027     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1028     ASSERT_NE(frameNode, nullptr);
1029     RefPtr<LayoutProperty> layoutProperty = frameNode->GetLayoutProperty();
1030     ASSERT_NE(layoutProperty, nullptr);
1031     RefPtr<TextLayoutProperty> textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(layoutProperty);
1032     ASSERT_NE(textLayoutProperty, nullptr);
1033     Shadow textShadow1 = Shadow();
1034     Shadow textShadow2 = Shadow();
1035     textShadow1.SetColor(Color::RED);
1036     textShadow2.SetColor(Color::WHITE);
1037     std::vector<Shadow> shadows { textShadow1, textShadow2 };
1038     textLayoutProperty->UpdateTextShadow(shadows);
1039     auto json = JsonUtil::Create(true);
1040     textLayoutProperty->ToJsonValue(json, filter);
1041     EXPECT_TRUE(json->Contains("textShadow"));
1042     auto textShadowJson = json->GetValue("textShadow");
1043     EXPECT_TRUE(textShadowJson->IsArray());
1044 }
1045 
1046 /**
1047  * @tc.name: UpdateChildProperty001
1048  * @tc.desc: test UpdateChildProperty function
1049  * @tc.type: FUNC
1050  */
1051 HWTEST_F(TextTestTwoNg, UpdateChildProperty001, TestSize.Level1)
1052 {
1053     TestProperty testProperty;
1054     testProperty.fontSizeValue = std::make_optional(FONT_SIZE_VALUE);
1055     testProperty.textColorValue = std::make_optional(TEXT_COLOR_VALUE);
1056     testProperty.italicFontStyleValue = std::make_optional(ITALIC_FONT_STYLE_VALUE);
1057     testProperty.fontWeightValue = std::make_optional(FONT_WEIGHT_VALUE);
1058     testProperty.textDecorationValue = std::make_optional(TEXT_DECORATION_VALUE);
1059     testProperty.textDecorationColorValue = std::make_optional(TEXT_DECORATION_COLOR_VALUE);
1060     testProperty.textCaseValue = std::make_optional(TEXT_CASE_VALUE);
1061     testProperty.letterSpacing = std::make_optional(LETTER_SPACING);
1062     testProperty.lineHeightValue = std::make_optional(LINE_HEIGHT_VALUE);
1063     testProperty.fontFamilyValue = std::make_optional(FONT_FAMILY_VALUE);
1064     testProperty.lineSpacingValue = std::make_optional(LINE_SPACING_VALUE);
1065     /**
1066      * @tc.steps: step1. create text FrameNode and SpanNode, Update parent FrameNode properties
1067      * @tc.expected: Successfully created parent Node and child Node
1068      */
1069     auto host = CreateTextParagraph(CREATE_VALUE, testProperty);
1070     ASSERT_NE(host, nullptr);
1071     SpanModelNG spanModelNG;
1072     spanModelNG.Create("span1");
1073     auto firstChild = ViewStackProcessor::GetInstance()->Finish();
1074     spanModelNG.Create("span2");
1075     auto secondChild = ViewStackProcessor::GetInstance()->Finish();
1076 
1077     /**
1078      * @tc.steps: step2. SpanNode mount to parent
1079      */
1080     host->AddChild(firstChild);
1081     host->AddChild(secondChild);
1082 
1083     /**
1084      * @tc.steps: step3. called BeforeCreateLayoutWrapper function to UpdateChildProperty
1085      * @tc.expected: child count is not empty, Child inherits parent property
1086      */
1087     auto pattern = host->GetPattern<TextPattern>();
1088     ASSERT_NE(pattern, nullptr);
1089     pattern->BeforeCreateLayoutWrapper();
1090     EXPECT_EQ(host->GetChildren().size(), 2);
1091     for (const auto& child : host->GetChildren()) {
1092         auto spanNode = AceType::DynamicCast<SpanNode>(child);
1093         ASSERT_NE(spanNode, nullptr);
1094         EXPECT_EQ(spanNode->GetFontSize().value(), FONT_SIZE_VALUE);
1095         EXPECT_EQ(spanNode->GetTextColor().value(), TEXT_COLOR_VALUE);
1096         EXPECT_EQ(spanNode->GetItalicFontStyle().value(), ITALIC_FONT_STYLE_VALUE);
1097         EXPECT_EQ(spanNode->GetFontWeight().value(), FONT_WEIGHT_VALUE);
1098         EXPECT_EQ(spanNode->GetTextDecoration().value(), TEXT_DECORATION_VALUE);
1099         EXPECT_EQ(spanNode->GetTextDecorationColor().value(), TEXT_DECORATION_COLOR_VALUE);
1100         EXPECT_EQ(spanNode->GetTextCase().value(), TEXT_CASE_VALUE);
1101         EXPECT_EQ(spanNode->GetLetterSpacing().value(), LETTER_SPACING);
1102         EXPECT_EQ(spanNode->GetLineHeight().value(), LINE_HEIGHT_VALUE);
1103         EXPECT_EQ(spanNode->GetFontFamily().value(), FONT_FAMILY_VALUE);
1104         EXPECT_EQ(spanNode->GetLineSpacing().value(), LINE_SPACING_VALUE);
1105     }
1106 
1107     /**
1108      * @tc.steps: step4. Update parent fontsize property, called BeforeCreateLayoutWrapper again
1109      * @tc.expected: Child update fontsize property
1110      */
1111     TestUpdateScenario(pattern);
1112 }
1113 
1114 /**
1115  * @tc.name: UpdateChildProperty002
1116  * @tc.desc: test UpdateChildProperty function
1117  * @tc.type: FUNC
1118  */
1119 HWTEST_F(TextTestTwoNg, UpdateChildProperty002, TestSize.Level1)
1120 {
1121     TestProperty testProperty;
1122     /**
1123      * @tc.steps: step1. create text FrameNode and SpanNode, Update child FrameNode properties
1124      * @tc.expected: Successfully created parent Node and child Node
1125      */
1126     auto host = CreateTextParagraph(CREATE_VALUE, testProperty);
1127     ASSERT_NE(host, nullptr);
1128     auto firstChild = CreateSpanNodeWithSetDefaultProperty("SPANNODE");
1129     auto secondChild = CreateSpanNodeWithSetDefaultProperty("spanNode");
1130 
1131     /**
1132      * @tc.steps: step2. SpanNode mount to parent
1133      */
1134     host->AddChild(firstChild);
1135     host->AddChild(secondChild);
1136 
1137     /**
1138      * @tc.steps: step3. called BeforeCreateLayoutWrapper function to UpdateChildProperty
1139      * @tc.expected: child count is not empty, Child use owner property
1140      */
1141     auto pattern = host->GetPattern<TextPattern>();
1142     ASSERT_NE(pattern, nullptr);
1143     pattern->BeforeCreateLayoutWrapper();
1144     EXPECT_EQ(host->GetChildren().size(), 2);
1145     for (const auto& child : host->GetChildren()) {
1146         auto spanNode = AceType::DynamicCast<SpanNode>(child);
1147         ASSERT_NE(spanNode, nullptr);
1148         EXPECT_EQ(spanNode->GetFontSize().value(), FONT_SIZE_VALUE);
1149         EXPECT_EQ(spanNode->GetTextColor().value(), TEXT_COLOR_VALUE);
1150         EXPECT_EQ(spanNode->GetItalicFontStyle().value(), ITALIC_FONT_STYLE_VALUE);
1151         EXPECT_EQ(spanNode->GetFontWeight().value(), FONT_WEIGHT_VALUE);
1152         EXPECT_EQ(spanNode->GetTextDecoration().value(), TEXT_DECORATION_VALUE);
1153         EXPECT_EQ(spanNode->GetTextDecorationColor().value(), TEXT_DECORATION_COLOR_VALUE);
1154         EXPECT_EQ(spanNode->GetTextCase().value(), TEXT_CASE_VALUE);
1155         EXPECT_EQ(spanNode->GetLetterSpacing().value(), LETTER_SPACING);
1156         EXPECT_EQ(spanNode->GetLineHeight().value(), LINE_HEIGHT_VALUE);
1157         EXPECT_EQ(spanNode->GetFontFamily().value(), FONT_FAMILY_VALUE);
1158     }
1159 
1160     /**
1161      * @tc.steps: step4. Update parent fontsize property, called BeforeCreateLayoutWrapper again
1162      * @tc.expected: Child use owner property
1163      */
1164     TestUpdateScenario(pattern);
1165 }
1166 
1167 /**
1168  * @tc.name: InitSurfaceChangedTest001
1169  * @tc.desc: test InitSurfaceChangedCallback function
1170  * @tc.type: FUNC
1171  */
1172 HWTEST_F(TextTestTwoNg, InitSurfaceChangedTest001, TestSize.Level1)
1173 {
1174     TestProperty testProperty;
1175     /**
1176      * @tc.steps: step1. create text FrameNode and SpanNode, Update child FrameNode properties
1177      * @tc.expected: Successfully created parent Node and child Node
1178      */
1179     auto host = CreateTextParagraph(CREATE_VALUE, testProperty);
1180     ASSERT_NE(host, nullptr);
1181     /**
1182      * @tc.steps: step2. get text pattern called InitSurfaceChangedCallback function.
1183      * @tc.expected: HasSurfaceChangedCallback return true.
1184      */
1185     auto pattern = host->GetPattern<TextPattern>();
1186     pattern->InitSurfaceChangedCallback();
1187     EXPECT_TRUE(pattern->HasSurfaceChangedCallback());
1188 }
1189 
1190 /**
1191  * @tc.name: HandleClickEvent001
1192  * @tc.desc: test test_pattern.h HandleClickEvent function with valid textSelector
1193  * @tc.type: FUNC
1194  */
1195 HWTEST_F(TextTestTwoNg, HandleClickEvent001, TestSize.Level1)
1196 {
1197     /**
1198      * @tc.steps: step1. create frameNode and pattern
1199      */
1200     auto [frameNode, pattern] = Init();
1201     pattern->textSelector_.Update(0, 20);
1202 
1203     /**
1204      * @tc.steps: step2. create GestureEvent and call HandleClickEvent function
1205      * @tc.expected: selectOverlay is closed
1206      */
1207     GestureEvent info;
1208     info.localLocation_ = Offset(0, 0);
1209     pattern->HandleClickEvent(info);
1210     EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
1211     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
1212 }
1213 
1214 /**
1215  * @tc.name: HandleClickEvent002
1216  * @tc.desc: test test_pattern.h HandleClickEvent function when spanItemChildren is not nullptr.
1217  * @tc.type: FUNC
1218  */
1219 HWTEST_F(TextTestTwoNg, HandleClickEvent002, TestSize.Level1)
1220 {
1221     /**
1222      * @tc.steps: step1. create frameNode and pattern
1223      */
1224     auto [frameNode, pattern] = Init();
1225 
1226     /**
1227      * @tc.steps: step2. construct spanItemChildren
1228      */
1229     std::list<RefPtr<SpanItem>> spanItemChildren;
1230     auto spanItemChild1 = AceType::MakeRefPtr<SpanItem>();
1231     spanItemChildren.emplace_back(spanItemChild1);
1232     pattern->spans_ = spanItemChildren;
1233 
1234     /**
1235      * @tc.steps: step3. create paragraph
1236      */
1237     ParagraphStyle paragraphStyle;
1238     RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
1239     ASSERT_NE(paragraph, nullptr);
1240     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 });
1241 
1242     /**
1243      * @tc.steps: step4. create GestureEvent and call HandleClickEvent function with invalid textSelector
1244      * @tc.expected: function run rightly
1245      */
1246     pattern->textSelector_.Update(-2, -2);
1247     GestureEvent info;
1248     info.localLocation_ = Offset(0, 0);
1249     pattern->HandleClickEvent(info);
1250     EXPECT_EQ(pattern->textSelector_.GetTextStart(), -2);
1251     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -2);
1252     pattern->pManager_->Reset();
1253 }
1254 
1255 /**
1256  * @tc.name: HandleMouseEvent001
1257  * @tc.desc: test test_pattern.h HandleMouseEvent function when copyOption is none
1258  * @tc.type: FUNC
1259  */
1260 HWTEST_F(TextTestTwoNg, HandleMouseEvent001, TestSize.Level1)
1261 {
1262     /**
1263      * @tc.steps: step1. create frameNode and pattern
1264      */
1265     auto [frameNode, pattern] = Init();
1266 
1267     /**
1268      * @tc.steps: step2.call OnVisibleChange function
1269      * @tc.expected: selectOverlay is closed
1270      */
1271     pattern->CreateHandles();
1272     pattern->textSelector_.Update(0, 20);
1273     pattern->OnVisibleChange(false);
1274     EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
1275     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
1276 
1277     /**
1278      * @tc.steps: step3. create MouseEvent and call HandleMouseEvent function when copyOption is none
1279      * @tc.expected: selectOverlay is closed
1280      */
1281     MouseInfo info;
1282     info.localLocation_ = Offset(1, 1);
1283     pattern->copyOption_ = copyOption;
1284     pattern->HandleMouseEvent(info);
1285     EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
1286     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
1287 }
1288 
1289 /**
1290  * @tc.name: HandleMouseEvent002
1291  * @tc.desc: test test_pattern.h HandleMouseEvent function when copyOption is not none
1292  * @tc.type: FUNC
1293  */
1294 HWTEST_F(TextTestTwoNg, HandleMouseEvent002, TestSize.Level1)
1295 {
1296     /**
1297      * @tc.steps: step1. create frameNode and pattern
1298      */
1299     auto [frameNode, pattern] = Init();
1300     pattern->textForDisplay_ = "test";
1301     pattern->textSelector_.Update(0, 3);
1302     pattern->copyOption_ = CopyOptions::InApp;
1303 
1304     /**
1305      * @tc.steps: step2. create paragraph
1306      */
1307     ParagraphStyle paragraphStyle;
1308     RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
1309     ASSERT_NE(paragraph, nullptr);
1310     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 });
1311 
1312     /**
1313      * @tc.steps: step3. create MouseInfo and call HandleMouseEvent function
1314      * @tc.expected: selectOverlay is not closed
1315      */
1316     MouseInfo info;
1317     info.localLocation_ = Offset(2, 2);
1318     info.button_ = MouseButton::RIGHT_BUTTON;
1319     info.action_ = MouseAction::PRESS;
1320     pattern->HandleMouseEvent(info);
1321     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1322     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 3);
1323     pattern->pManager_->Reset();
1324 }
1325 
1326 /**
1327  * @tc.name: HandleMouseEvent003
1328  * @tc.desc: test test_pattern.h HandleMouseEvent function when copyOption is not none
1329  * @tc.type: FUNC
1330  */
1331 HWTEST_F(TextTestTwoNg, HandleMouseEvent003, TestSize.Level1)
1332 {
1333     /**
1334      * @tc.steps: step1. create frameNode and pattern
1335      */
1336     auto [frameNode, pattern] = Init();
1337     pattern->textForDisplay_ = "test";
1338     pattern->textSelector_.Update(0, 3);
1339     pattern->copyOption_ = CopyOptions::InApp;
1340 
1341     /**
1342      * @tc.steps: step2. create paragraph
1343      */
1344     ParagraphStyle paragraphStyle;
1345     RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
1346     ASSERT_NE(paragraph, nullptr);
1347     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 0 });
1348 
1349     /**
1350      * @tc.steps: step3. create MouseInfo and call HandleMouseEvent function
1351      * @tc.expected: selectOverlay is not closed
1352      */
1353     MouseInfo info;
1354     // none none
1355     pattern->textSelector_.Update(0, 3);
1356     info.button_ = MouseButton::NONE_BUTTON;
1357     info.action_ = MouseAction::NONE;
1358     pattern->HandleMouseEvent(info);
1359     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1360     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 3);
1361 
1362     // left none
1363     pattern->textSelector_.Update(0, 3);
1364     info.localLocation_ = Offset(2, 2);
1365     info.button_ = MouseButton::LEFT_BUTTON;
1366     info.action_ = MouseAction::NONE;
1367     pattern->HandleMouseEvent(info);
1368     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1369     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 3);
1370 
1371     // right none
1372     pattern->textSelector_.Update(0, 3);
1373     info.button_ = MouseButton::RIGHT_BUTTON;
1374     info.action_ = MouseAction::NONE;
1375     pattern->HandleMouseEvent(info);
1376     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1377     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 3);
1378 
1379     // left press
1380     pattern->textSelector_.Update(0, 3);
1381     info.button_ = MouseButton::LEFT_BUTTON;
1382     info.action_ = MouseAction::PRESS;
1383     pattern->HandleMouseEvent(info);
1384     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1385     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 0);
1386 
1387     // left move
1388     pattern->textSelector_.Update(0, 3);
1389     info.button_ = MouseButton::LEFT_BUTTON;
1390     info.action_ = MouseAction::MOVE;
1391     pattern->blockPress_ = true;
1392     pattern->HandleMouseEvent(info);
1393     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1394     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 3);
1395 
1396     pattern->textSelector_.Update(0, 3);
1397     pattern->blockPress_ = false;
1398     pattern->HandleMouseEvent(info);
1399     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1400     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 0);
1401 
1402     // left RELEASE
1403     pattern->textSelector_.Update(0, 3);
1404     info.button_ = MouseButton::LEFT_BUTTON;
1405     info.action_ = MouseAction::RELEASE;
1406     pattern->blockPress_ = true;
1407     pattern->HandleMouseEvent(info);
1408     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1409     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 3);
1410 
1411     pattern->textSelector_.Update(0, 3);
1412     pattern->blockPress_ = false;
1413     pattern->HandleMouseEvent(info);
1414     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1415     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 3);
1416     pattern->pManager_->Reset();
1417 }
1418 
1419 /**
1420  * @tc.name: HandleMouseEvent004
1421  * @tc.desc: test test_pattern.h HandleMouseEvent function when isDoubleClick_ is true
1422  * @tc.type: FUNC
1423  */
1424 HWTEST_F(TextTestTwoNg, HandleMouseEvent004, TestSize.Level1)
1425 {
1426     /**
1427      * @tc.steps: step1. create frameNode and pattern
1428      */
1429     auto [frameNode, pattern] = Init();
1430     pattern->textForDisplay_ = "test";
1431     pattern->textSelector_.Update(0, 3);
1432     pattern->copyOption_ = CopyOptions::InApp;
1433 
1434     /**
1435      * @tc.steps: step2. create paragraph
1436      */
1437     ParagraphStyle paragraphStyle;
1438     RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
1439     ASSERT_NE(paragraph, nullptr);
1440     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 });
1441 
1442     /**
1443      * @tc.steps: step3. create MouseInfo and call HandleMouseEvent function
1444      * @tc.expected: isDoubleClick_ is false
1445      */
1446     MouseInfo info;
1447     // left RELEASE
1448     info.button_ = MouseButton::LEFT_BUTTON;
1449     info.action_ = MouseAction::RELEASE;
1450     pattern->blockPress_ = true;
1451     pattern->isDoubleClick_ = true;
1452     pattern->HandleMouseEvent(info);
1453     EXPECT_FALSE(pattern->isDoubleClick_);
1454     pattern->pManager_->Reset();
1455 }
1456 
1457 /**
1458  * @tc.name: HandleMouseEvent005
1459  * @tc.desc: test test_pattern.h HandleMouseEvent
1460  * @tc.type: FUNC
1461  */
1462 HWTEST_F(TextTestTwoNg, HandleMouseEvent005, TestSize.Level1)
1463 {
1464     /**
1465      * @tc.steps: step1. create frameNode and pattern, InitMouseEvent.
1466      */
1467     TextModelNG textModelNG;
1468     textModelNG.Create("1234567890");
1469     textModelNG.SetCopyOption(CopyOptions::InApp);
1470     textModelNG.SetTextDetectEnable(true);
1471     auto host = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1472     auto pattern = host->GetPattern<TextPattern>();
1473     auto inputHub = host->GetEventHub<EventHub>()->GetOrCreateInputEventHub();
1474     auto mouseEvent = inputHub->mouseEventActuator_->inputEvents_.back();
1475 
1476     AISpan aiSpan1;
1477     aiSpan1.start = AI_SPAN_START;
1478     aiSpan1.end = AI_SPAN_END;
1479     aiSpan1.content = SPAN_PHONE;
1480     aiSpan1.type = TextDataDetectType::PHONE_NUMBER;
1481     AISpan aiSpan2;
1482     aiSpan2.start = AI_SPAN_START_II;
1483     aiSpan2.end = AI_SPAN_END_II;
1484     aiSpan2.content = SPAN_URL;
1485     aiSpan2.type = TextDataDetectType::URL;
1486     std::map<int32_t, AISpan> aiSpanMap;
1487     aiSpanMap[AI_SPAN_START] = aiSpan1;
1488     aiSpanMap[AI_SPAN_START_II] = aiSpan2;
1489     pattern->dataDetectorAdapter_->aiSpanMap_ = aiSpanMap;
1490     auto paragraph = MockParagraph::GetOrCreateMockParagraph();
1491     std::vector<RectF> rects { RectF(0, 0, 40, 40) };
1492     EXPECT_CALL(*paragraph, GetRectsForRange(_, _, _)).WillRepeatedly(SetArgReferee<2>(rects));
1493     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 });
1494     pattern->CreateHandles();
1495     pattern->textSelector_.Update(0, 20);
1496 
1497     /**
1498      * @tc.steps: step2. test text_pattern.h HandleMouseRightButton function.
1499      * @tc.expect: MouseInfo localLocation is in GetRectsForRange region, expect MouseRightButton release event
1500      *     captured by AISpan.
1501      */
1502     MouseInfo info;
1503     info.button_ = MouseButton::LEFT_BUTTON;
1504     info.action_ = MouseAction::PRESS;
1505     (*mouseEvent)(info);
1506     info.SetLocalLocation(Offset(5.f, 5.f));
1507     info.button_ = MouseButton::RIGHT_BUTTON;
1508     info.action_ = MouseAction::RELEASE;
1509     (*mouseEvent)(info);
1510     EXPECT_TRUE(pattern->dataDetectorAdapter_->hasClickedAISpan_);
1511 
1512     /**
1513      * @tc.steps: step3. test text_pattern.h HandleMouseRightButton function.
1514      * @tc.expect: MouseInfo localLocation is not in GetRectsForRange region.
1515      */
1516     pattern->dataDetectorAdapter_->hasClickedAISpan_ = false;
1517     info.SetLocalLocation(Offset(60.f, 60.f));
1518     info.button_ = MouseButton::RIGHT_BUTTON;
1519     info.action_ = MouseAction::RELEASE;
1520     (*mouseEvent)(info);
1521     EXPECT_TRUE(!pattern->dataDetectorAdapter_->hasClickedAISpan_);
1522     EXPECT_EQ(pattern->textResponseType_, TextResponseType::RIGHT_CLICK);
1523     EXPECT_EQ(pattern->selectedType_, TextSpanType::TEXT);
1524     pattern->pManager_->Reset();
1525 }
1526 
1527 /**
1528  * @tc.name: HandleMouseEvent006
1529  * @tc.desc: test test_pattern.h HandleMouseEvent
1530  * @tc.type: FUNC
1531  */
1532 HWTEST_F(TextTestTwoNg, HandleMouseEvent006, TestSize.Level1)
1533 {
1534     /**
1535      * @tc.steps: step1. create frameNode and pattern, add child imageSpanNode.
1536      */
1537     SuppressMockParagraph();
1538     TextModelNG textModelNG;
1539     textModelNG.Create("1234567890");
1540     textModelNG.SetCopyOption(CopyOptions::InApp);
1541     textModelNG.SetTextDetectEnable(true);
1542     auto host = AceType::Claim(ViewStackProcessor::GetInstance()->GetMainFrameNode());
1543     auto pattern = host->GetPattern<TextPattern>();
1544     auto paragraph = MockParagraph::GetOrCreateMockParagraph();
1545     std::vector<RectF> rects { RectF(0, 0, 40, 40) };
1546     EXPECT_CALL(*paragraph, GetRectsForRange(_, _, _)).WillRepeatedly(SetArgReferee<2>(rects));
1547     ImageSpanNodeProperty firstProperty { .imageSrc = std::make_optional("image") };
1548     auto imageSpanNode = CreateImageSpanNode(firstProperty);
1549     host->AddChild(imageSpanNode);
1550     imageSpanNode->SetParent(host);
1551     ImageSpanNodeProperty secondProperty { .pixelMap = std::make_optional(PixelMap::CreatePixelMap(nullptr)),
1552         .imageFit = std::make_optional(ImageFit::FILL) };
1553     imageSpanNode = CreateImageSpanNode(secondProperty);
1554     host->AddChild(imageSpanNode);
1555     imageSpanNode->SetParent(host);
1556     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1557     LayoutConstraintF layoutConstraintF;
1558     frameNode->Measure(layoutConstraintF);
1559     pattern->CreateHandles();
1560 
1561     /**
1562      * @tc.steps: step2. test text_pattern.h HandleMouseRightButton function.
1563      * @tc.expect: expect selectedType_ IMAGE when mouse release offset not in textContentRect region.
1564      */
1565     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 30 });
1566     auto inputHub = host->GetEventHub<EventHub>()->GetOrCreateInputEventHub();
1567     auto mouseEvent = inputHub->mouseEventActuator_->inputEvents_.back();
1568     MouseInfo info;
1569     info.button_ = MouseButton::LEFT_BUTTON;
1570     info.action_ = MouseAction::PRESS;
1571     (*mouseEvent)(info);
1572     info.SetLocalLocation(Offset(40.f, 40.f));
1573     info.button_ = MouseButton::RIGHT_BUTTON;
1574     info.action_ = MouseAction::RELEASE;
1575     pattern->contentRect_ = { 30, 30, 20, 20 };
1576     (*mouseEvent)(info);
1577     EXPECT_EQ(pattern->textResponseType_, TextResponseType::RIGHT_CLICK);
1578     EXPECT_EQ(pattern->selectedType_, TextSpanType::IMAGE);
1579     pattern->pManager_->Reset();
1580 }
1581 
1582 /**
1583  * @tc.name: HandleOnCopy001
1584  * @tc.desc: test test_pattern.h HandleOnCopy function
1585  * @tc.type: FUNC
1586  */
1587 HWTEST_F(TextTestTwoNg, HandleOnCopy001, TestSize.Level1)
1588 {
1589     /**
1590      * @tc.steps: step1. create frameNode and pattern
1591      */
1592     auto [frameNode, pattern] = Init();
1593 
1594     /**
1595      * @tc.steps: step2. call HandleOnCopy function when textSelector is valid and textStart is equal to textEnd
1596      * @tc.steps: step3. call HandleOnCopy function when textSelector is not valid and textStart < 0
1597      * @tc.expected: selectOverlay is closed
1598      */
1599     std::vector<std::vector<int32_t>> params = { { 2, 2 }, { 1, 20 } };
1600     for (int turn = 0; turn < params.size(); turn++) {
1601         pattern->textSelector_.Update(params[turn][0], params[turn][1]);
1602         pattern->HandleOnCopy();
1603         if (turn == 0) {
1604             EXPECT_EQ(pattern->textSelector_.GetTextStart(), -1);
1605             EXPECT_EQ(pattern->textSelector_.GetTextEnd(), -1);
1606         } else {
1607             EXPECT_EQ(pattern->textSelector_.GetTextStart(), 1);
1608             EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 20);
1609         }
1610     }
1611 }
1612 
1613 /**
1614  * @tc.name: HandleOnCopy002
1615  * @tc.desc: test test_pattern.h HandleOnCopy function
1616  * @tc.type: FUNC
1617  */
1618 HWTEST_F(TextTestTwoNg, HandleOnCopy002, TestSize.Level1)
1619 {
1620     /**
1621      * @tc.steps: step1. create frameNode and pattern
1622      */
1623     auto [frameNode, pattern] = Init();
1624 
1625     /**
1626      * @tc.steps: step2. call HandleOnCopy function with valid textSelector and copyOption
1627      * @tc.expected: selectOverlay is closed
1628      */
1629     pattern->textSelector_.Update(0, 6);
1630     pattern->textForDisplay_ = "TestHandleOnCopy";
1631     pattern->copyOption_ = CopyOptions::InApp;
1632     pattern->HandleOnCopy();
1633     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1634     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 6);
1635 }
1636 
1637 /**
1638  * @tc.name: HandleLongPress001
1639  * @tc.desc: test text_pattern.h HandleLongPress function when IsDraggable is false
1640  * @tc.type: FUNC
1641  */
1642 HWTEST_F(TextTestTwoNg, HandleLongPress001, TestSize.Level1)
1643 {
1644     /**
1645      * @tc.steps: step1. create frameNode and pattern
1646      */
1647     auto [frameNode, pattern] = Init();
1648     frameNode->draggable_ = false;
1649     pattern->copyOption_ = CopyOptions::InApp;
1650     pattern->textSelector_.Update(0, 3);
1651     pattern->textForDisplay_ = TEXT_CONTENT;
1652     GestureEvent info;
1653     info.localLocation_ = Offset(1, 1);
1654     EXPECT_FALSE(pattern->IsDraggable(info.GetLocalLocation()));
1655 
1656     /**
1657      * @tc.steps: step2. call HandleLongPress function
1658      * @tc.expected: The function exits normally
1659      */
1660     pattern->HandleLongPress(info);
1661     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1662     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 1);
1663 }
1664 
1665 /**
1666  * @tc.name: HandleLongPress002
1667  * @tc.desc: test text_pattern.h HandleLongPress function when IsDraggable is true
1668  * @tc.type: FUNC
1669  */
1670 HWTEST_F(TextTestTwoNg, HandleLongPress002, TestSize.Level1)
1671 {
1672     auto paragraph = MockParagraph::GetOrCreateMockParagraph();
1673     EXPECT_CALL(*paragraph, ComputeOffsetForCaretDownstream).WillRepeatedly(Return(true));
1674     EXPECT_CALL(*paragraph, ComputeOffsetForCaretUpstream).WillRepeatedly(Return(true));
1675     EXPECT_CALL(*paragraph, GetWordBoundary).WillRepeatedly(Return(false));
1676     std::vector<RectF> rects { RectF(0, 0, 20, 20) };
1677     EXPECT_CALL(*paragraph, GetRectsForRange(_, _, _)).Times(2).WillRepeatedly(SetArgReferee<2>(rects));
1678     /**
1679      * @tc.steps: step1. create frameNode and pattern
1680      */
1681     auto [frameNode, pattern] = Init();
1682 
1683     frameNode->draggable_ = true;
1684     frameNode->eventHub_->SetOnDragStart(
__anonfc8d98b90702(const RefPtr<Ace::DragEvent>&, const std::string&) 1685         [](const RefPtr<Ace::DragEvent>&, const std::string&) -> DragDropInfo { return {}; });
1686     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 });
1687     pattern->copyOption_ = CopyOptions::InApp;
1688     pattern->textSelector_.Update(0, 3);
1689     pattern->textForDisplay_ = TEXT_CONTENT;
1690     GestureEvent info;
1691     info.localLocation_ = Offset(1, 1);
1692     /**
1693      * @tc.steps: step2. call HandleLongPress function
1694      * @tc.expected: The function exits normally
1695      */
1696     pattern->HandleLongPress(info);
1697     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1698     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 3);
1699     pattern->pManager_->Reset();
1700 }
1701 
1702 /**
1703  * @tc.name: HandleOnSelectAll001
1704  * @tc.desc: Test TextPattern HandleOnSelectAll when selectOverlayProxy is nullptr.
1705  * @tc.type: FUNC
1706  */
1707 HWTEST_F(TextTestTwoNg, HandleOnSelectAll001, TestSize.Level1)
1708 {
1709     /**
1710      * @tc.steps: step1. create frameNode and pattern
1711      */
1712     auto [frameNode, pattern] = Init();
1713     pattern->textForDisplay_ = "TestHandleOnSelectAll";
1714     pattern->selectOverlayProxy_ = nullptr;
1715 
1716     /**
1717      * @tc.steps: step2. create paragraph
1718      */
1719     ParagraphStyle paragraphStyle;
1720     RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
1721     ASSERT_NE(paragraph, nullptr);
1722     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 });
1723 
1724     /**
1725      * @tc.steps: step3. call HandleOnSelectAll
1726      * @tc.expected:The function exits normally
1727      */
1728     pattern->HandleOnSelectAll();
1729     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1730     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), pattern->textForDisplay_.length());
1731     pattern->pManager_->Reset();
1732 }
1733 
1734 /**
1735  * @tc.name: HandleOnSelectAll002
1736  * @tc.desc: Test TextPattern HandleOnSelectAll when selectOverlayProxy is not nullptr.
1737  * @tc.type: FUNC
1738  */
1739 HWTEST_F(TextTestTwoNg, HandleOnSelectAll002, TestSize.Level1)
1740 {
1741     /**
1742      * @tc.steps: step1. create frameNode and pattern
1743      */
1744     auto [frameNode, pattern] = Init();
1745     /**
1746      * @tc.steps: step2. construct a SelectOverlayManager and rootNode
1747      */
1748     SelectOverlayInfo selectOverlayInfo;
1749     selectOverlayInfo.singleLineHeight = NODE_ID;
1750     auto root = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
1751     auto selectOverlayManager = AceType::MakeRefPtr<SelectOverlayManager>(root);
1752 
1753     /**
1754      * @tc.steps: step3. call CreateAndShowSelectOverlay
1755      * @tc.expected: return the proxy which has the right SelectOverlayId
1756      */
1757     auto proxy = selectOverlayManager->CreateAndShowSelectOverlay(selectOverlayInfo, nullptr, false);
1758     pattern->selectOverlayProxy_ = proxy;
1759     pattern->textForDisplay_ = "TestHandleOnSelectAll";
1760 
1761     /**
1762      * @tc.steps: step4. call HandleOnSelectAll
1763      * @tc.expected:textSelector updates successfully
1764      */
1765     pattern->HandleOnSelectAll();
1766     EXPECT_EQ(pattern->textSelector_.GetTextStart(), 0);
1767     EXPECT_EQ(pattern->textSelector_.GetTextEnd(), 21);
1768 
1769     /**
1770      * @tc.steps: step5. call CloseSelectOverlay
1771      * @tc.expected: Related function is called
1772      */
1773     pattern->CloseSelectOverlay();
1774     EXPECT_TRUE(pattern->selectOverlayProxy_->IsClosed());
1775 }
1776 
1777 /**
1778  * @tc.name: PerformActionTest001
1779  * @tc.desc: Text Accessibility PerformAction test Select ClearSelection and Copy.
1780  * @tc.type: FUNC
1781  */
1782 HWTEST_F(TextTestTwoNg, PerformActionTest001, TestSize.Level1)
1783 {
1784     /**
1785      * @tc.steps: step1. Create text, get text frameNode and pattern, set callback function.
1786      * @tc.expected: FrameNode and pattern is not null, related function is called.
1787      */
1788     MockPipelineContext::GetCurrent()->rootNode_ =
1789         FrameNode::CreateFrameNodeWithTree(V2::ROOT_ETS_TAG, 0, AceType::MakeRefPtr<RootPattern>());
1790     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1791     ASSERT_NE(frameNode, nullptr);
1792     auto textPattern = frameNode->GetPattern<TextPattern>();
1793     ASSERT_NE(textPattern, nullptr);
1794     auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1795     ASSERT_NE(textLayoutProperty, nullptr);
1796     textLayoutProperty->UpdateCopyOption(CopyOptions::None);
1797     textPattern->SetAccessibilityAction();
1798 
1799     /**
1800      * @tc.steps: step2. Get text accessibilityProperty to call callback function.
1801      * @tc.expected: Related function is called.
1802      */
1803     auto textAccessibilityProperty = frameNode->GetAccessibilityProperty<TextAccessibilityProperty>();
1804     ASSERT_NE(textAccessibilityProperty, nullptr);
1805 
1806     /**
1807      * @tc.steps: step3. When text CopyOptions is None, call the callback function in textAccessibilityProperty.
1808      * @tc.expected: Related function is called.
1809      */
1810     EXPECT_TRUE(textAccessibilityProperty->ActActionSetSelection(1, TEXT_SIZE_INT));
1811     EXPECT_TRUE(textAccessibilityProperty->ActActionClearSelection());
1812     EXPECT_TRUE(textAccessibilityProperty->ActActionCopy());
1813 
1814     /**
1815      * @tc.steps: step4. When text CopyOptions is InApp, call the callback function in textAccessibilityProperty.
1816      * @tc.expected: Related function is called.
1817      */
1818     textLayoutProperty->UpdateCopyOption(CopyOptions::InApp);
1819     EXPECT_TRUE(textAccessibilityProperty->ActActionSetSelection(-1, -1));
1820     EXPECT_TRUE(textAccessibilityProperty->ActActionSetSelection(1, TEXT_SIZE_INT));
1821     EXPECT_TRUE(textAccessibilityProperty->ActActionClearSelection());
1822     EXPECT_TRUE(textAccessibilityProperty->ActActionCopy());
1823 }
1824 
1825 /**
1826  * @tc.name: TextSelectorTest001
1827  * @tc.desc: test Update function in TextSelector
1828  * @tc.type: FUNC
1829  */
1830 HWTEST_F(TextTestTwoNg, TextSelectorTest001, TestSize.Level1)
1831 {
1832     /**
1833      * @tc.steps: step1. Create Text.
1834      */
1835     TextModelNG textModel;
1836     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1837     ASSERT_NE(frameNode, nullptr);
1838     auto textPattern = frameNode->GetPattern<TextPattern>();
1839     ASSERT_NE(textPattern, nullptr);
1840 
1841     /**
1842      * @tc.steps: step2. set callback function.
1843      */
1844     auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
1845     ASSERT_NE(textLayoutProperty, nullptr);
1846     textLayoutProperty->UpdateCopyOption(CopyOptions::InApp);
1847     textPattern->OnModifyDone();
1848 
1849     /**
1850      * @tc.steps: step3. call callback function.
1851      * @tc.expected: textSelector_ update successfully.
1852      */
1853     textPattern->textSelector_.Update(0);
1854     EXPECT_EQ(textPattern->textSelector_.baseOffset, 0);
1855 
1856     textPattern->textSelector_.Update(0, TEXT_SIZE_INT);
1857     EXPECT_EQ(textPattern->textSelector_.baseOffset, 0);
1858     EXPECT_EQ(textPattern->textSelector_.destinationOffset, TEXT_SIZE_INT);
1859 }
1860 
1861 /**
1862  * @tc.name: TextPaintMethodTest003
1863  * @tc.desc: test text_paint_method.cpp UpdateContentModifier function
1864  * @tc.type: FUNC
1865  */
1866 HWTEST_F(TextTestTwoNg, TextPaintMethodTest003, TestSize.Level1)
1867 {
1868     auto paragraph = MockParagraph::GetOrCreateMockParagraph();
1869     std::vector<RectF> rects { RectF(0, 0, 20, 20) };
1870     EXPECT_CALL(*paragraph, GetRectsForRange(_, _, _)).WillRepeatedly(SetArgReferee<2>(rects));
1871     /**
1872      * @tc.steps: step1. create textFrameNode and geometryNode.
1873      */
1874     auto [host, pattern] = Init();
1875     pattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 });
1876     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1877     ASSERT_NE(geometryNode, nullptr);
1878     auto renderContext = host->GetRenderContext();
1879     ASSERT_NE(renderContext, nullptr);
1880     auto paintProperty = pattern->CreatePaintProperty();
1881     ASSERT_NE(paintProperty, nullptr);
1882 
1883     /**
1884      * @tc.steps: step2. set textForDisplay_ to EMPTY_TEXT.
1885      */
1886     pattern->textForDisplay_ = EMPTY_TEXT;
1887 
1888     /**
1889      * @tc.steps: step3. push UNKNOWN_REASON and PLACEHOLDER to reasons.
1890      *                   set obscured of renderContext to reasons.
1891      */
1892     std::vector<ObscuredReasons> reasons;
1893     reasons.push_back((ObscuredReasons)UNKNOWN_REASON);
1894     reasons.push_back(ObscuredReasons::PLACEHOLDER);
1895     renderContext->UpdateObscured(reasons);
1896 
1897     /**
1898      * @tc.steps: step4. create textPaintMethod and call UpdateContentModifier function.
1899      * @tc.expected: The drawObscuredRects_ of textContentModifier is empty.
1900      */
1901     RefPtr<TextContentModifier> textContentModifier =
1902         AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
1903     RefPtr<TextOverlayModifier> textOverlayModifier = AceType::MakeRefPtr<TextOverlayModifier>();
1904     TextPaintMethod textPaintMethod(pattern, BASE_LINE_OFFSET_VALUE, textContentModifier, textOverlayModifier);
1905     auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty);
1906     textPaintMethod.UpdateContentModifier(AceType::RawPtr(paintWrapper));
1907     EXPECT_EQ(textContentModifier->drawObscuredRects_, std::vector<RectF>());
1908 
1909     /**
1910      * @tc.steps: step5. set textForDisplay_ to CREATE_VALUE.
1911      */
1912     pattern->textForDisplay_ = CREATE_VALUE;
1913 
1914     /**
1915      * @tc.steps: step6. call UpdateContentModifier function.
1916      * @tc.expected: The drawObscuredRects_ of textContentModifier is not empty.
1917      */
1918     renderContext = host->GetRenderContext();
1919     paintProperty = pattern->CreatePaintProperty();
1920     paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty);
1921     TextPaintMethod textPaintMethod1(pattern, BASE_LINE_OFFSET_VALUE, textContentModifier, textOverlayModifier);
1922     textPaintMethod1.UpdateContentModifier(AceType::RawPtr(paintWrapper));
1923     EXPECT_NE(textContentModifier->drawObscuredRects_, std::vector<RectF>());
1924 
1925     /**
1926      * @tc.steps: step7. call OnModifyDone function.
1927      * @tc.expected: The obscured of renderContext is reasons.
1928      */
1929     pattern->OnModifyDone();
1930     EXPECT_EQ(renderContext->GetObscured(), reasons);
1931     pattern->pManager_->Reset();
1932 }
1933 
1934 /**
1935  * @tc.name: TextContentModifier004
1936  * @tc.desc: test text_content_modifier.cpp DrawObscuration function
1937  * @tc.type: FUNC
1938  */
1939 HWTEST_F(TextTestTwoNg, TextContentModifier004, TestSize.Level1)
1940 {
1941     /**
1942      * @tc.steps: step1. create textFrameNode.
1943      */
1944     auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
1945     ASSERT_NE(textFrameNode, nullptr);
1946     auto textPattern = textFrameNode->GetPattern<TextPattern>();
1947     ASSERT_NE(textPattern, nullptr);
1948     auto textPaintMethod = textPattern->CreateNodePaintMethod();
1949     ASSERT_NE(textPaintMethod, nullptr);
1950     auto textContentModifier = textPattern->GetContentModifier();
1951     ASSERT_NE(textContentModifier, nullptr);
1952 
1953     /**
1954      * @tc.steps: step2. set context and paragraph.
1955      *                   set defaultFontSize defaultTextColor and contentSize of textContentModifier.
1956      *                   push one rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects.
1957      */
1958     Testing::MockCanvas canvas;
1959     EXPECT_CALL(canvas, ClipRect(_, _, _)).WillRepeatedly(Return());
1960     EXPECT_CALL(canvas, AttachBrush(_)).WillRepeatedly(ReturnRef(canvas));
1961     EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
1962     DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE };
1963     ParagraphStyle paragraphStyle;
1964     RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
1965     textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 100 });
1966     TextStyle textStyle;
1967     textStyle.SetFontSize(ADAPT_FONT_SIZE_VALUE);
1968     textStyle.SetTextColor(TEXT_COLOR_VALUE);
1969     textContentModifier->SetDefaultAnimatablePropertyValue(textStyle);
1970     SizeF contentSize(TEXT_CONTENT_SIZE, TEXT_CONTENT_SIZE);
1971     textContentModifier->SetContentSize(contentSize);
1972     std::vector<RectF> drawObscuredRects;
1973     RectF textRect;
1974     textRect.SetHeight(TEXT_RECT_WIDTH);
1975     textRect.SetWidth(TEXT_RECT_WIDTH);
1976     textRect.SetTop(TEXT_RECT_TOP_ONE);
1977     drawObscuredRects.push_back(textRect);
1978     textContentModifier->SetDrawObscuredRects(drawObscuredRects);
1979 
1980     /**
1981      * @tc.steps: step3. call DrawObscuration function of textContentModifier.
1982      * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects.
1983      */
1984     textContentModifier->DrawObscuration(context);
1985     EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects);
1986 
1987     /**
1988      * @tc.steps: step4. push two rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects.
1989      */
1990     drawObscuredRects.push_back(textRect);
1991     textRect.SetTop(TEXT_RECT_TOP_TWO);
1992     drawObscuredRects.push_back(textRect);
1993     textContentModifier->SetDrawObscuredRects(drawObscuredRects);
1994 
1995     /**
1996      * @tc.steps: step5. call DrawObscuration function of textContentModifier.
1997      * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects.
1998      */
1999     textContentModifier->DrawObscuration(context);
2000     EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects);
2001 
2002     /**
2003      * @tc.steps: step6. push three rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects.
2004      */
2005     textRect.SetHeight(TEXT_RECT_SIZE_ZEOR);
2006     drawObscuredRects.push_back(textRect);
2007     textContentModifier->SetDrawObscuredRects(drawObscuredRects);
2008 
2009     /**
2010      * @tc.steps: step7. call DrawObscuration function of textContentModifier.
2011      * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects.
2012      */
2013     textContentModifier->DrawObscuration(context);
2014     EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects);
2015 
2016     /**
2017      * @tc.steps: step8. push four rect to drawObscuredRects and set drawObscuredRects_ to drawObscuredRects.
2018      */
2019     textRect.SetWidth(TEXT_RECT_SIZE_ZEOR);
2020     drawObscuredRects.push_back(textRect);
2021     textContentModifier->SetDrawObscuredRects(drawObscuredRects);
2022 
2023     /**
2024      * @tc.steps: step9. call DrawObscuration function of textContentModifier.
2025      * @tc.expected: The drawObscuredRects_ of textContentModifier is drawObscuredRects.
2026      */
2027     textContentModifier->DrawObscuration(context);
2028     EXPECT_EQ(textContentModifier->drawObscuredRects_, drawObscuredRects);
2029     textPattern->pManager_->Reset();
2030 }
2031 
2032 /**
2033  * @tc.name: TextContentModifier005
2034  * @tc.desc: test text_content_modifier.cpp SetImageSpanNodeList function
2035  * @tc.type: FUNC
2036  */
2037 HWTEST_F(TextTestTwoNg, TextContentModifier005, TestSize.Level1)
2038 {
2039     /**
2040      * @tc.steps: step1. create textFrameNode and textPattern.
2041      */
2042     auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2043     ASSERT_NE(textFrameNode, nullptr);
2044     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
2045     ASSERT_NE(geometryNode, nullptr);
2046     auto textPattern = textFrameNode->GetPattern<TextPattern>();
2047     ASSERT_NE(textPattern, nullptr);
2048 
2049     /**
2050      * @tc.steps: step2. Create imageNodeList and add imageNode into imageNodeList.
2051      */
2052     ParagraphStyle paragraphStyle;
2053     RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
2054     ASSERT_NE(paragraph, nullptr);
2055     textPattern->pManager_->AddParagraph({ .paragraph = paragraph, .start = 0, .end = 1 });
2056     std::vector<WeakPtr<FrameNode>> imageNodeList;
2057     auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonfc8d98b90802() 2058         []() { return AceType::MakeRefPtr<ImagePattern>(); });
2059     imageNodeList.emplace_back(AceType::WeakClaim(AceType::RawPtr(imageNode)));
2060     textPattern->SetImageSpanNodeList(imageNodeList);
2061     /**
2062      * @tc.steps: step3. call CreateNodePaintMethod func.
2063      * @tc.expected: The imageNodeList_ size is equal to 1.
2064      */
2065     auto textPaintMethod = AceType::DynamicCast<TextPaintMethod>(textPattern->CreateNodePaintMethod());
2066     ASSERT_NE(textPaintMethod, nullptr);
2067     RefPtr<RenderContext> renderContext = textFrameNode->GetRenderContext();
2068     auto paintProperty = textPattern->CreatePaintProperty();
2069     auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty);
2070     textPaintMethod->UpdateContentModifier(AceType::RawPtr(paintWrapper));
2071 
2072     ASSERT_NE(textPaintMethod->textContentModifier_, nullptr);
2073     EXPECT_EQ(textPaintMethod->textContentModifier_->imageNodeList_.size(), 1);
2074     textPattern->pManager_->Reset();
2075 }
2076 
2077 /**
2078  * @tc.name: TextOverlayModifierTest002
2079  * @tc.desc: test IsSelectedRectsChanged function.
2080  * @tc.type: FUNC
2081  */
2082 HWTEST_F(TextTestTwoNg, TextOverlayModifierTest002, TestSize.Level1)
2083 {
2084     /**
2085      * @tc.steps: step1. create textOverlayModifier
2086      */
2087     TextOverlayModifier textOverlayModifier;
2088     std::vector<RectF> rectList;
2089     rectList.push_back(RectF(RECT_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE));
2090     rectList.push_back(RectF(RECT_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE));
2091     textOverlayModifier.SetSelectedRects(rectList);
2092     /**
2093      * @tc.steps: step2. test IsSelectedRectsChanged
2094      */
2095     RectF secondRect(RECT_SECOND_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE);
2096     textOverlayModifier.selectedRects_[0] = secondRect;
2097     bool rectsChanged = textOverlayModifier.IsSelectedRectsChanged(rectList);
2098     EXPECT_EQ(rectsChanged, true);
2099 }
2100 
2101 /**
2102  * @tc.name: TextOverlayModifierTest003
2103  * @tc.desc: test TextOverlayModifier function.
2104  * @tc.type: FUNC
2105  */
2106 HWTEST_F(TextTestTwoNg, TextOverlayModifierTest003, TestSize.Level1)
2107 {
2108     /**
2109      * @tc.steps: step1. create textOverlayModifier
2110      */
2111     TextOverlayModifier textOverlayModifier;
2112     OffsetF paintOffset;
2113     textOverlayModifier.SetPrintOffset(paintOffset);
2114     textOverlayModifier.SetSelectedColor(SELECTED_COLOR);
2115 
2116     /**
2117      * @tc.steps: step2. change version and save initial version
2118      */
2119     int32_t settingHighApiVersion = 12;
2120     int32_t settingLowApiVersion = 10;
2121     int32_t backupApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion();
2122     AceApplicationInfo::GetInstance().SetApiTargetVersion(settingHighApiVersion);
2123 
2124     /**
2125      * @tc.steps: step3. test TextOverlayModifier
2126      */
2127     TextOverlayModifier();
2128     EXPECT_EQ(textOverlayModifier.isClip_->Get(), true);
2129 
2130     /**
2131      * @tc.steps: step4. test TextOverlayModifier again and reuse initial ApiTargetVersion
2132      */
2133     AceApplicationInfo::GetInstance().SetApiTargetVersion(settingLowApiVersion);
2134     TextOverlayModifier();
2135     EXPECT_EQ(textOverlayModifier.isClip_->Get(), true);
2136     AceApplicationInfo::GetInstance().SetApiTargetVersion(backupApiVersion);
2137 }
2138 
2139 /**
2140  * @tc.name: TextOverlayModifierTest004
2141  * @tc.desc: test onDraw function.
2142  * @tc.type: FUNC
2143  */
2144 HWTEST_F(TextTestTwoNg, TextOverlayModifierTest004, TestSize.Level1)
2145 {
2146     /**
2147      * @tc.steps: step1. create textOverlayModifier
2148      */
2149     TextOverlayModifier textOverlayModifier;
2150     OffsetF paintOffset;
2151     textOverlayModifier.SetPrintOffset(paintOffset);
2152     textOverlayModifier.SetSelectedColor(SELECTED_COLOR);
2153 
2154     /**
2155      * @tc.steps: step1. create selectedRects_
2156      */
2157     std::vector<RectF> rectList;
2158     rectList.push_back(RectF(RECT_SECOND_X_VALUE, RECT_Y_VALUE, RECT_WIDTH_VALUE, RECT_HEIGHT_VALUE));
2159     textOverlayModifier.SetSelectedRects(rectList);
2160 
2161     /**
2162      * @tc.steps: step3. create canvas
2163      */
2164 
2165     Testing::MockCanvas canvas;
2166     EXPECT_CALL(canvas, Save()).WillRepeatedly(Return());
2167     EXPECT_CALL(canvas, AttachBrush(_)).WillRepeatedly(ReturnRef(canvas));
2168     EXPECT_CALL(canvas, DrawRect(_)).WillRepeatedly(Return());
2169     EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
2170     EXPECT_CALL(canvas, Restore()).WillRepeatedly(Return());
2171 
2172     /**
2173      * @tc.steps: step4. change ApiVersion and set isClip_ is true
2174      */
2175 
2176     int32_t changeApiVersion = 12;
2177     int32_t backupApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion();
2178     AceApplicationInfo::GetInstance().SetApiTargetVersion(changeApiVersion);
2179     TextOverlayModifier();
2180     EXPECT_EQ(textOverlayModifier.isClip_->Get(), true);
2181 
2182     /**
2183      * @tc.steps: step5. create context and textContentRect
2184      */
2185     DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE };
2186     RectF textContentRect = CONTENT_RECT;
2187     textOverlayModifier.SetContentRect(textContentRect);
2188 
2189     /**
2190      * @tc.steps: step6. test onDraw
2191      */
2192     textOverlayModifier.SetShowSelect(true);
2193     textOverlayModifier.onDraw(context);
2194     RectF finalSelectRect = textOverlayModifier.selectedRects_[0];
2195     EXPECT_EQ(textOverlayModifier.paintOffset_->Get(), paintOffset);
2196     EXPECT_EQ(finalSelectRect.Width(), 5);
2197     EXPECT_EQ(textOverlayModifier.contentRect_, textContentRect);
2198     AceApplicationInfo::GetInstance().SetApiTargetVersion(backupApiVersion);
2199 }
2200 
2201 /**
2202  * @tc.name: TextPaintMethodTest004
2203  * @tc.desc: test text_paint_method.cpp UpdateOverlayModifier
2204  * @tc.type: FUNC
2205  */
2206 HWTEST_F(TextTestTwoNg, TextPaintMethodTest004, TestSize.Level1)
2207 {
2208     /**
2209      * @tc.steps: step1. create textFrameNode and textLayoutProperty.
2210      */
2211     auto textFrameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
2212     ASSERT_NE(textFrameNode, nullptr);
2213     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
2214     ASSERT_NE(geometryNode, nullptr);
2215     RefPtr<LayoutWrapperNode> layoutWrapper =
2216         AceType::MakeRefPtr<LayoutWrapperNode>(textFrameNode, geometryNode, textFrameNode->GetLayoutProperty());
2217     auto textPattern = textFrameNode->GetPattern<TextPattern>();
2218     ASSERT_NE(textPattern, nullptr);
2219     auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
2220     ASSERT_NE(textLayoutProperty, nullptr);
2221 
2222     /**
2223      * @tc.steps: step2. create textPaintMethod and update textLayoutProperty.
2224      */
2225     auto pattern = textFrameNode->GetPattern<Pattern>();
2226     ParagraphStyle paragraphStyle;
2227     RefPtr<Paragraph> paragraph = Paragraph::Create(paragraphStyle, FontCollection::Current());
2228     RefPtr<TextContentModifier> textContentModifier =
2229         AceType::MakeRefPtr<TextContentModifier>(std::optional<TextStyle>(TextStyle()));
2230     RefPtr<TextOverlayModifier> textOverlayModifier = AceType::MakeRefPtr<TextOverlayModifier>();
2231     TextPaintMethod textPaintMethod(pattern, BASE_LINE_OFFSET_VALUE, textContentModifier, textOverlayModifier);
2232     textLayoutProperty->UpdateFontSize(ADAPT_FONT_SIZE_VALUE);
2233     textLayoutProperty->UpdateBaselineOffset(ADAPT_BASE_LINE_OFFSET_VALUE);
2234 
2235     /**
2236      * @tc.steps: step3. update ClipEdge and create textTheme.
2237      */
2238     RefPtr<RenderContext> renderContext = RenderContext::Create();
2239     renderContext->UpdateClipEdge(true);
2240     auto paintProperty = textPattern->CreatePaintProperty();
2241     auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(renderContext, geometryNode, paintProperty);
2242 
2243     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
2244     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
2245     auto textTheme = AceType::MakeRefPtr<TextTheme>();
2246     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(textTheme));
2247     ASSERT_NE(textTheme, nullptr);
2248 
2249     /**
2250      * @tc.steps: step4. call UpdateContentModifier and GetOverlayModifier.
2251      */
2252     textPaintMethod.UpdateOverlayModifier(AceType::RawPtr(paintWrapper));
2253     auto OverlayModifier = textPaintMethod.GetOverlayModifier(AceType::RawPtr(paintWrapper));
2254     ASSERT_NE(OverlayModifier, nullptr);
2255     EXPECT_EQ(textOverlayModifier->isClip_->Get(), true);
2256 }
2257 } // namespace OHOS::Ace::NG
2258