Signed-off-by: wangweiyuan <wangweiyuan2@huawei.com>
This commit is contained in:
wangweiyuan 2024-11-21 20:47:03 +08:00
parent d8a5987e9d
commit a63626baea
6 changed files with 1110 additions and 50 deletions

View File

@ -666,15 +666,15 @@ HWTEST_F(RichEditorPatternTestFiveNg, GetSelectSpanSplit002, TestSize.Level1)
auto* stack = ViewStackProcessor::GetInstance();
auto nodeId = stack->ClaimNodeId();
auto spanNode = SpanNode::GetOrCreateSpanNode(V2::RICH_EDITOR_ETS_TAG, nodeId);
auto spanNode_New = SpanNode::GetOrCreateSpanNode(V2::RICH_EDITOR_ETS_TAG, nodeId);
auto spanNodeNew = SpanNode::GetOrCreateSpanNode(V2::RICH_EDITOR_ETS_TAG, nodeId);
richEditorNode_->children_.push_back(spanNode);
richEditorNode_->children_.push_back(spanNode_New);
richEditorNode_->children_.push_back(spanNodeNew);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
SpanPositionInfo startPositionSpanInfo;
SpanPositionInfo endPositionSpanInfo;
richEditorPattern->GetSelectSpanSplit(startPositionSpanInfo, endPositionSpanInfo);
EXPECT_NE(spanNode->tag_, V2::SPAN_ETS_TAG);
auto result = richEditorPattern->GetSelectSpanSplit(startPositionSpanInfo, endPositionSpanInfo);
EXPECT_EQ(result.size(), 0);
}
/**
@ -688,15 +688,15 @@ HWTEST_F(RichEditorPatternTestFiveNg, GetSelectSpanSplit003, TestSize.Level1)
auto* stack = ViewStackProcessor::GetInstance();
auto nodeId = stack->ClaimNodeId();
auto spanNode = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
auto spanNode_New = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
auto spanNodeNew = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
richEditorNode_->children_.push_back(spanNode);
richEditorNode_->children_.push_back(spanNode_New);
richEditorNode_->children_.push_back(spanNodeNew);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
SpanPositionInfo startPositionSpanInfo;
SpanPositionInfo endPositionSpanInfo;
richEditorPattern->GetSelectSpanSplit(startPositionSpanInfo, endPositionSpanInfo);
EXPECT_EQ(spanNode->tag_, V2::SPAN_ETS_TAG);
auto result = richEditorPattern->GetSelectSpanSplit(startPositionSpanInfo, endPositionSpanInfo);
EXPECT_EQ(result.front().spanIndex, 0);
}
/**
@ -756,7 +756,7 @@ HWTEST_F(RichEditorPatternTestFiveNg, HandleOnDragInsertStyledString001, TestSiz
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
RefPtr<SpanString> spanStringRef = AceType::MakeRefPtr<SpanString>("Your text here");
RefPtr<SpanString> spanStringRef = AceType::MakeRefPtr<SpanString>(PREVIEW_TEXT_VALUE2);
richEditorPattern->HandleOnDragInsertStyledString(spanStringRef);
EXPECT_FALSE(richEditorPattern->isDragSponsor_);
}
@ -771,7 +771,7 @@ HWTEST_F(RichEditorPatternTestFiveNg, HandleOnDragInsertStyledString002, TestSiz
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
RefPtr<SpanString> spanStringRef = AceType::MakeRefPtr<SpanString>("Your text here");
RefPtr<SpanString> spanStringRef = AceType::MakeRefPtr<SpanString>(PREVIEW_TEXT_VALUE2);
richEditorPattern->isDragSponsor_ = true;
richEditorPattern->caretPosition_ = 1;
richEditorPattern->HandleOnDragInsertStyledString(spanStringRef);
@ -788,7 +788,7 @@ HWTEST_F(RichEditorPatternTestFiveNg, HandleOnDragInsertStyledString003, TestSiz
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
RefPtr<SpanString> spanStringRef = AceType::MakeRefPtr<SpanString>("Your text here");
RefPtr<SpanString> spanStringRef = AceType::MakeRefPtr<SpanString>(PREVIEW_TEXT_VALUE2);
richEditorPattern->isDragSponsor_ = true;
richEditorPattern->caretPosition_ = 1;
richEditorPattern->dragRange_ = { 2, 8 };
@ -809,10 +809,10 @@ HWTEST_F(RichEditorPatternTestFiveNg, InsertValueToBeforeSpan001, TestSize.Level
auto* stack = ViewStackProcessor::GetInstance();
auto nodeId = stack->ClaimNodeId();
auto spanNodeBefore = SpanNode::GetOrCreateSpanNode(V2::RICH_EDITOR_ETS_TAG, nodeId);
string insertValue = "abc";
spanNodeBefore->GetSpanItem()->content = "Your text here";
string insertValue = PREVIEW_TEXT_VALUE3;
spanNodeBefore->GetSpanItem()->content = PREVIEW_TEXT_VALUE2;
richEditorPattern->InsertValueToBeforeSpan(spanNodeBefore, insertValue);
EXPECT_EQ(spanNodeBefore->GetSpanItem()->position, 2);
EXPECT_EQ(spanNodeBefore->GetSpanItem()->position, 4);
}
/**
@ -828,9 +828,8 @@ HWTEST_F(RichEditorPatternTestFiveNg, InsertValueToBeforeSpan002, TestSize.Level
auto* stack = ViewStackProcessor::GetInstance();
auto nodeId = stack->ClaimNodeId();
auto spanNodeBefore = SpanNode::GetOrCreateSpanNode(V2::RICH_EDITOR_ETS_TAG, nodeId);
string insertValue = "abc\nLL L ";
spanNodeBefore->GetSpanItem()->content = "Your text here\n";
richEditorPattern->InsertValueToBeforeSpan(spanNodeBefore, insertValue);
spanNodeBefore->GetSpanItem()->content = EXCEPT_VALUE;
richEditorPattern->InsertValueToBeforeSpan(spanNodeBefore, EXCEPT_VALUE);
EXPECT_EQ(spanNodeBefore->GetSpanItem()->position, -1);
}
@ -1320,54 +1319,384 @@ HWTEST_F(RichEditorPatternTestFiveNg, HandleOnDragInsertValue001, TestSize.Level
}
/**
* @tc.name: CopySelectionMenuParams001
* @tc.desc: test CopySelectionMenuParams
* @tc.name: HandleOnDragInsertValue002
* @tc.desc: test HandleOnDragInsertValue
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, CopySelectionMenuParams001, TestSize.Level1)
HWTEST_F(RichEditorPatternTestFiveNg, HandleOnDragInsertValue002, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
SelectOverlayInfo selectInfo;
selectInfo.isUsingMouse = true;
richEditorPattern->selectedType_ = TextSpanType::IMAGE;
std::pair<TextSpanType, TextResponseType> key = std::make_pair(TextSpanType::IMAGE, TextResponseType::RIGHT_CLICK);
std::pair<TextSpanType, TextResponseType> key1 = std::make_pair(TextSpanType::IMAGE, TextResponseType::LONG_PRESS);
std::shared_ptr<SelectionMenuParams> selectMenuParams = std::make_shared<SelectionMenuParams>(
TextSpanType::IMAGE, []() {}, [](int32_t x, int32_t y) {}, []() {}, TextResponseType::RIGHT_CLICK);
std::shared_ptr<SelectionMenuParams> selectMenuParams1 = std::make_shared<SelectionMenuParams>(
TextSpanType::IMAGE, []() {}, [](int32_t x, int32_t y) {}, []() {}, TextResponseType::LONG_PRESS);
richEditorPattern->selectionMenuMap_.insert({ key, selectMenuParams });
richEditorPattern->selectionMenuMap_.insert({ key1, selectMenuParams1 });
richEditorPattern->CopySelectionMenuParams(selectInfo, TextResponseType::RIGHT_CLICK);
EXPECT_EQ(selectInfo.menuInfo.menuOffset->GetX(), 0);
EXPECT_EQ(selectInfo.menuInfo.menuOffset->GetY(), 0);
std::string insertValue;
richEditorPattern->textSelector_.baseOffset = 1;
richEditorPattern->textSelector_.destinationOffset = 1;
richEditorPattern->HandleOnDragInsertValue(insertValue);
EXPECT_EQ(richEditorPattern->operationRecords_.size(), 2);
}
/**
* @tc.name: CopySelectionMenuParams002
* @tc.desc: test CopySelectionMenuParams
* @tc.name: UpdateMagnifierStateAfterLayout001
* @tc.desc: test UpdateMagnifierStateAfterLayout
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, CopySelectionMenuParams002, TestSize.Level1)
HWTEST_F(RichEditorPatternTestFiveNg, UpdateMagnifierStateAfterLayout001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
WeakPtr<TextBase> textBase;
richEditorPattern->selectOverlay_ = AceType::MakeRefPtr<RichEditorSelectOverlay>(textBase);
richEditorPattern->magnifierController_.Reset();
richEditorPattern->UpdateMagnifierStateAfterLayout(true);
EXPECT_FALSE(richEditorPattern->caretVisible_);
}
/**
* @tc.name: UpdateMagnifierStateAfterLayout002
* @tc.desc: test UpdateMagnifierStateAfterLayout
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, UpdateMagnifierStateAfterLayout002, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
WeakPtr<TextBase> textBase;
richEditorPattern->selectOverlay_ = AceType::MakeRefPtr<RichEditorSelectOverlay>(textBase);
WeakPtr<Pattern> pattern;
richEditorPattern->magnifierController_ = AceType::MakeRefPtr<MagnifierController>(pattern);
richEditorPattern->magnifierController_->magnifierNodeExist_ = true;
richEditorPattern->UpdateMagnifierStateAfterLayout(true);
EXPECT_FALSE(richEditorPattern->caretVisible_);
}
/**
* @tc.name: SetCaretPosition001
* @tc.desc: test SetCaretPosition
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, SetCaretPosition001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->isSpanStringMode_ = true;
richEditorPattern->styledString_ = AceType::MakeRefPtr<MutableSpanString>("SetCaretPosition");
richEditorPattern->caretChangeListener_ = [](int32_t x) {};
EXPECT_TRUE(richEditorPattern->SetCaretPosition(2, false));
}
/**
* @tc.name: HandleSurfaceChanged001
* @tc.desc: test HandleSurfaceChanged
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, HandleSurfaceChanged001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->magnifierController_.Reset();
richEditorPattern->HandleSurfaceChanged(1, 1, 2, 2);
EXPECT_FALSE(richEditorPattern->originIsMenuShow_);
}
/**
* @tc.name: GetCaretOffsetInfoByPosition001
* @tc.desc: test GetCaretOffsetInfoByPosition
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, GetCaretOffsetInfoByPosition001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
CaretOffsetInfo result = richEditorPattern->GetCaretOffsetInfoByPosition(1);
EXPECT_EQ(result.caretOffsetUp.GetX(), 0);
EXPECT_EQ(result.caretOffsetUp.GetY(), 0);
}
/**
* @tc.name: SetSubSpans001
* @tc.desc: test SetSubSpans
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, SetSubSpans001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
RefPtr<SpanItem> spanItem = AceType::MakeRefPtr<SpanItem>();
RefPtr<SpanItem> spanItem1 = AceType::MakeRefPtr<SpanItem>();
spanItem->spanItemType = SpanItemType::SYMBOL;
spanItem1->spanItemType = SpanItemType::NORMAL;
spanItem1->position = 0;
richEditorPattern->spans_.push_back(spanItem);
richEditorPattern->spans_.push_back(spanItem1);
RefPtr<SpanString> spanString = AceType::MakeRefPtr<SpanString>(INIT_VALUE_1);
richEditorPattern->SetSubSpans(spanString, 1, 1);
EXPECT_EQ(spanString->spans_.size(), 0);
}
/**
* @tc.name: GetSelectSpanSplit004
* @tc.desc: test GetSelectSpanSplit
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, GetSelectSpanSplit004, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto* stack = ViewStackProcessor::GetInstance();
auto nodeId = stack->ClaimNodeId();
auto spanNode = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
auto spanNodeNew = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
richEditorNode_->children_.push_back(spanNode);
richEditorNode_->children_.push_back(spanNodeNew);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
SpanPositionInfo startPositionSpanInfo;
SpanPositionInfo endPositionSpanInfo;
startPositionSpanInfo.spanOffset_ = 1;
auto result = richEditorPattern->GetSelectSpanSplit(startPositionSpanInfo, endPositionSpanInfo);
EXPECT_EQ(result.size(), 1);
}
/**
* @tc.name: GetSelectSpanSplit005
* @tc.desc: test GetSelectSpanSplit
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, GetSelectSpanSplit005, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto* stack = ViewStackProcessor::GetInstance();
auto nodeId = stack->ClaimNodeId();
auto spanNode = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
auto spanNodeNew = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
auto spanNodeAnother = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
richEditorNode_->children_.push_back(spanNode);
richEditorNode_->children_.push_back(spanNodeNew);
richEditorNode_->children_.push_back(spanNodeAnother);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
SpanPositionInfo startPositionSpanInfo;
SpanPositionInfo endPositionSpanInfo;
endPositionSpanInfo.spanIndex_ = 1;
auto result = richEditorPattern->GetSelectSpanSplit(startPositionSpanInfo, endPositionSpanInfo);
EXPECT_EQ(result.size(), 2);
}
/**
* @tc.name: GetSelectSpanSplit006
* @tc.desc: test GetSelectSpanSplit
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, GetSelectSpanSplit006, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto* stack = ViewStackProcessor::GetInstance();
auto nodeId = stack->ClaimNodeId();
auto spanNode = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
auto spanNodeNew = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
auto spanNodeAnother = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
richEditorNode_->children_.push_back(spanNode);
richEditorNode_->children_.push_back(spanNodeNew);
richEditorNode_->children_.push_back(spanNodeAnother);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
SpanPositionInfo startPositionSpanInfo;
SpanPositionInfo endPositionSpanInfo;
endPositionSpanInfo.spanIndex_ = 1;
endPositionSpanInfo.spanOffset_ = 1;
auto result = richEditorPattern->GetSelectSpanSplit(startPositionSpanInfo, endPositionSpanInfo);
EXPECT_EQ(result.size(), 2);
}
/**
* @tc.name: GetSelectSpanSplit007
* @tc.desc: test GetSelectSpanSplit
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, GetSelectSpanSplit007, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto* stack = ViewStackProcessor::GetInstance();
auto nodeId = stack->ClaimNodeId();
auto spanNode = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
auto spanNodeNew = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
auto spanNodeAnother = SpanNode::GetOrCreateSpanNode(V2::SPAN_ETS_TAG, nodeId);
richEditorNode_->children_.push_back(spanNode);
richEditorNode_->children_.push_back(spanNodeNew);
richEditorNode_->children_.push_back(spanNodeAnother);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
SpanPositionInfo startPositionSpanInfo;
SpanPositionInfo endPositionSpanInfo;
endPositionSpanInfo.spanIndex_ = 2;
auto result = richEditorPattern->GetSelectSpanSplit(startPositionSpanInfo, endPositionSpanInfo);
EXPECT_EQ(result.size(), 3);
}
/**
* @tc.name: HandleMouseEvent001
* @tc.desc: test HandleMouseEvent
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, HandleMouseEvent001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
MouseInfo info;
richEditorPattern->textSelector_.baseOffset = 0;
richEditorPattern->textSelector_.destinationOffset = 10;
richEditorPattern->selectOverlay_->ProcessOverlay({ .animation = false });
auto manager = richEditorPattern->selectOverlay_->GetManager<SelectContentOverlayManager>();
ASSERT_NE(manager, nullptr);
SelectOverlayInfo selectInfo;
selectInfo.isUsingMouse = false;
richEditorPattern->selectedType_ = TextSpanType::IMAGE;
std::pair<TextSpanType, TextResponseType> key = std::make_pair(TextSpanType::IMAGE, TextResponseType::RIGHT_CLICK);
std::pair<TextSpanType, TextResponseType> key1 = std::make_pair(TextSpanType::IMAGE, TextResponseType::LONG_PRESS);
std::shared_ptr<SelectionMenuParams> selectMenuParams = std::make_shared<SelectionMenuParams>(
TextSpanType::IMAGE, []() {}, [](int32_t x, int32_t y) {}, []() {}, TextResponseType::RIGHT_CLICK);
std::shared_ptr<SelectionMenuParams> selectMenuParams1 = std::make_shared<SelectionMenuParams>(
TextSpanType::IMAGE, []() {}, [](int32_t x, int32_t y) {}, []() {}, TextResponseType::LONG_PRESS);
richEditorPattern->selectionMenuMap_.insert({ key, selectMenuParams });
richEditorPattern->selectionMenuMap_.insert({ key1, selectMenuParams1 });
richEditorPattern->CopySelectionMenuParams(selectInfo, TextResponseType::RIGHT_CLICK);
EXPECT_EQ(selectInfo.menuInfo.menuOffset->GetX(), 0);
EXPECT_EQ(selectInfo.menuInfo.menuOffset->GetY(), 0);
manager->CreateSelectOverlay(selectInfo);
manager->shareOverlayInfo_ = std::make_shared<SelectOverlayInfo>();
ASSERT_NE(manager->shareOverlayInfo_, nullptr);
richEditorPattern->HandleMouseEvent(info);
EXPECT_EQ(richEditorPattern->caretUpdateType_, CaretUpdateType::NONE);
}
/**
* @tc.name: HandleMouseEvent002
* @tc.desc: test HandleMouseEvent
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, HandleMouseEvent002, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
MouseInfo info;
richEditorPattern->textSelector_.baseOffset = 0;
richEditorPattern->textSelector_.destinationOffset = 10;
richEditorPattern->selectOverlay_->ProcessOverlay({ .animation = false });
auto manager = richEditorPattern->selectOverlay_->GetManager<SelectContentOverlayManager>();
ASSERT_NE(manager, nullptr);
SelectOverlayInfo selectInfo;
manager->CreateSelectOverlay(selectInfo);
manager->shareOverlayInfo_ = std::make_shared<SelectOverlayInfo>();
ASSERT_NE(manager->shareOverlayInfo_, nullptr);
info.SetAction(MouseAction::PRESS);
richEditorPattern->HandleMouseEvent(info);
EXPECT_TRUE(info.GetAction() == MouseAction::PRESS);
}
/**
* @tc.name: HandleMouseEvent003
* @tc.desc: test HandleMouseEvent
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, HandleMouseEvent003, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
MouseInfo info;
richEditorPattern->scrollBar_.Reset();
richEditorPattern->HandleMouseEvent(info);
EXPECT_EQ(richEditorPattern->caretUpdateType_, CaretUpdateType::NONE);
}
/**
* @tc.name: HandleMouseEvent004
* @tc.desc: test HandleMouseEvent
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, HandleMouseEvent004, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
MouseInfo info;
richEditorPattern->scrollBar_->isPressed_ = true;
richEditorPattern->HandleMouseEvent(info);
EXPECT_EQ(richEditorPattern->currentMouseStyle_, MouseFormat::DEFAULT);
}
/**
* @tc.name: HandleMouseEvent005
* @tc.desc: test HandleMouseEvent
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, HandleMouseEvent005, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
MouseInfo info;
richEditorPattern->hasUrlSpan_ = true;
richEditorPattern->HandleMouseEvent(info);
EXPECT_EQ(richEditorPattern->currentMouseStyle_, MouseFormat::TEXT_CURSOR);
}
/**
* @tc.name: HandleMouseEvent006
* @tc.desc: test HandleMouseEvent
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, HandleMouseEvent006, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
MouseInfo info;
RefPtr<SpanItem> spanItem = AceType::MakeRefPtr<SpanItem>();
RefPtr<SpanItem> spanItemAnother = AceType::MakeRefPtr<SpanItem>();
spanItem->position = 2;
spanItemAnother->position = 2;
spanItem->urlOnRelease = []() {};
spanItemAnother->urlOnRelease = []() {};
richEditorPattern->spans_.push_back(spanItem);
richEditorPattern->spans_.push_back(spanItemAnother);
richEditorPattern->hasUrlSpan_ = true;
richEditorPattern->baselineOffset_ = 5;
richEditorPattern->contentRect_ = RectF(10, 20, 100, 200);
ParagraphManager::ParagraphInfo paragraphInfo;
RefPtr<MockParagraph> mockParagraph = AceType::MakeRefPtr<MockParagraph>();
EXPECT_CALL(*mockParagraph, GetRectsForRange(_, _, _))
.WillRepeatedly(Invoke([](int32_t start, int32_t end, std::vector<RectF>& selectedRects) {
selectedRects.emplace_back(RectF(0, 0, 100, 20));
}));
paragraphInfo.paragraph = mockParagraph;
paragraphInfo.start = 0;
paragraphInfo.end = 10;
richEditorPattern->paragraphs_.paragraphs_.emplace_back(paragraphInfo);
richEditorPattern->HandleMouseEvent(info);
EXPECT_EQ(richEditorPattern->currentMouseStyle_, MouseFormat::HAND_POINTING);
}
/**
* @tc.name: GetThumbnailCallback001
* @tc.desc: test GetThumbnailCallback
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFiveNg, GetThumbnailCallback001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->textSelector_.baseOffset = 0;
richEditorPattern->textSelector_.destinationOffset = 10;
richEditorPattern->copyOption_ = CopyOptions::InApp;
ParagraphManager::ParagraphInfo paragraphInfo;
RefPtr<MockParagraph> mockParagraph = AceType::MakeRefPtr<MockParagraph>();
EXPECT_CALL(*mockParagraph, GetRectsForRange(_, _, _))
.WillRepeatedly(Invoke([](int32_t start, int32_t end, std::vector<RectF>& selectedRects) {
selectedRects.emplace_back(RectF(0, 0, 100, 20));
}));
paragraphInfo.paragraph = mockParagraph;
paragraphInfo.start = 0;
paragraphInfo.end = 10;
richEditorPattern->paragraphs_.paragraphs_.emplace_back(paragraphInfo);
auto thumbnailCallback = richEditorPattern->GetThumbnailCallback();
Offset point(10, 10);
thumbnailCallback(point);
EXPECT_TRUE(richEditorPattern->textSelector_.IsValid());
}
} // namespace OHOS::Ace::NG

View File

@ -579,6 +579,216 @@ HWTEST_F(RichEditorPatternTestFourNg, ProcessStyledString001, TestSize.Level1)
ASSERT_EQ(richEditorPattern->spans_.empty(), true);
}
/**
* @tc.name: ProcessStyledString002
* @tc.desc: test ProcessStyledString
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFourNg, ProcessStyledString002, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
AddSpan(INIT_VALUE_1);
richEditorPattern->textDetectEnable_ = true;
bool ret = false;
ret = richEditorPattern->CanStartAITask();
EXPECT_TRUE(ret);
richEditorPattern->textForDisplay_ = INIT_VALUE_1;
richEditorPattern->dataDetectorAdapter_->aiDetectInitialized_ = true;
richEditorPattern->ProcessStyledString();
EXPECT_FALSE(richEditorPattern->spans_.empty());
}
/**
* @tc.name: ProcessStyledString003
* @tc.desc: test ProcessStyledString
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFourNg, ProcessStyledString003, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
AddSpan(INIT_VALUE_1);
richEditorPattern->textDetectEnable_ = true;
bool ret = false;
ret = richEditorPattern->CanStartAITask();
EXPECT_TRUE(ret);
richEditorPattern->dataDetectorAdapter_->aiDetectInitialized_ = false;
richEditorPattern->ProcessStyledString();
EXPECT_FALSE(richEditorPattern->spans_.empty());
}
/**
* @tc.name: SetSelection007
* @tc.desc: test SetSelection
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFourNg, SetSelection007, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->CreateNodePaintMethod();
ASSERT_NE(richEditorPattern->contentMod_, nullptr);
ASSERT_NE(richEditorPattern->overlayMod_, nullptr);
auto focusHub = richEditorPattern->GetFocusHub();
ASSERT_NE(focusHub, nullptr);
focusHub->currentFocus_ = true;
richEditorPattern->previewTextRecord_.previewContent = "test";
richEditorPattern->previewTextRecord_.startOffset = 1;
richEditorPattern->previewTextRecord_.endOffset = 10;
int32_t start = -1;
int32_t end = 1;
SelectionOptions options;
options.menuPolicy = MenuPolicy::DEFAULT;
richEditorPattern->SetSelection(start, end, options, true);
EXPECT_TRUE(richEditorPattern->HasFocus());
richEditorPattern->textSelector_.baseOffset = -1;
richEditorPattern->SetSelection(start, end, options, true);
EXPECT_TRUE(richEditorPattern->HasFocus());
}
/**
* @tc.name: SetSelection008
* @tc.desc: test SetSelection
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFourNg, SetSelection008, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->CreateNodePaintMethod();
ASSERT_NE(richEditorPattern->contentMod_, nullptr);
ASSERT_NE(richEditorPattern->overlayMod_, nullptr);
auto focusHub = richEditorPattern->GetFocusHub();
ASSERT_NE(focusHub, nullptr);
focusHub->currentFocus_ = true;
std::string content = "TEST123";
richEditorPattern->isSpanStringMode_ = true;
richEditorPattern->styledString_ = AceType::MakeRefPtr<MutableSpanString>(content);
richEditorPattern->previewTextRecord_.previewContent = "test";
richEditorPattern->previewTextRecord_.startOffset = -1;
richEditorPattern->previewTextRecord_.endOffset = 10;
int32_t start = -1;
int32_t end = -1;
SelectionOptions options;
options.menuPolicy = MenuPolicy::DEFAULT;
richEditorPattern->textSelector_.baseOffset = -1;
richEditorPattern->textSelector_.destinationOffset = -1;
richEditorPattern->SetSelection(start, end, options, true);
EXPECT_TRUE(richEditorPattern->HasFocus());
richEditorPattern->textSelector_.baseOffset = -1;
richEditorPattern->textSelector_.destinationOffset = -1;
richEditorPattern->SetSelection(start, end, options, true);
EXPECT_TRUE(richEditorPattern->HasFocus());
}
/**
* @tc.name: GetTextBoxes002
* @tc.desc: test GetTextBoxes
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFourNg, GetTextBoxes002, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
richEditorPattern->textForDisplay_ = "testShowHandles";
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->caretPosition_ = 1;
richEditorPattern->textSelector_.baseOffset = 1;
richEditorPattern->textSelector_.destinationOffset = 3;
std::vector<RectF> res;
auto ret = richEditorPattern->GetTextBoxes();
EXPECT_EQ(ret, res);
TextLineMetrics lineMetrics;
richEditorPattern->GetLineCount();
EXPECT_EQ(richEditorPattern->GetLineHeight(), 0.0f);
EXPECT_EQ(richEditorPattern->GetLetterSpacing(), 0.0f);
auto retLineMetrics = richEditorPattern->GetLineMetrics(-1);
EXPECT_EQ(retLineMetrics.x, 0);
auto retLineMetricsS = richEditorPattern->GetLineMetrics(2);
EXPECT_EQ(retLineMetricsS.x, 0);
int32_t scroll_from_update = 1;
richEditorPattern->richTextRect_ = RectF(0, 4, 100, 140);
richEditorPattern->contentRect_ = RectF(0, 1, 100, 160);
richEditorPattern->overlayMod_ = nullptr;
richEditorPattern->UpdateScrollStateAfterLayout(true);
EXPECT_FALSE(richEditorPattern->OnScrollCallback(10, scroll_from_update)) << "Reach Top Boundary";
}
/**
* @tc.name: GetCrossOverHeight004
* @tc.desc: test GetCrossOverHeight
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFourNg, GetCrossOverHeight004, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->status_ = Status::DRAGGING;
richEditorPattern->CreateHandles();
int32_t backupApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion();
AceApplicationInfo::GetInstance().SetApiTargetVersion(static_cast<int32_t>(PlatformVersion::VERSION_TWELVE));
richEditorPattern->contentChange_ = true;
richEditorPattern->keyboardAvoidance_ = true;
EXPECT_EQ(richEditorPattern->GetCrossOverHeight(), 0.0f);
richEditorPattern->contentChange_ = false;
richEditorPattern->keyboardAvoidance_ = true;
EXPECT_EQ(richEditorPattern->GetCrossOverHeight(), 0.0f);
richEditorPattern->contentChange_ = false;
richEditorPattern->keyboardAvoidance_ = false;
EXPECT_EQ(richEditorPattern->GetCrossOverHeight(), 0.0f);
richEditorPattern->contentChange_ = true;
richEditorPattern->keyboardAvoidance_ = false;
EXPECT_EQ(richEditorPattern->GetCrossOverHeight(), 0.0f);
AceApplicationInfo::GetInstance().SetApiTargetVersion(backupApiVersion);
}
/**
* @tc.name: GetCrossOverHeight005
* @tc.desc: test GetCrossOverHeight
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestFourNg, GetCrossOverHeight005, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->status_ = Status::DRAGGING;
richEditorPattern->CreateHandles();
int32_t backupApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion();
AceApplicationInfo::GetInstance().SetApiTargetVersion(static_cast<int32_t>(PlatformVersion::VERSION_FOURTEEN));
richEditorPattern->contentChange_ = true;
richEditorPattern->keyboardAvoidance_ = true;
EXPECT_EQ(richEditorPattern->GetCrossOverHeight(), 0.0f);
richEditorPattern->contentChange_ = false;
richEditorPattern->keyboardAvoidance_ = true;
EXPECT_EQ(richEditorPattern->GetCrossOverHeight(), 0.0f);
richEditorPattern->contentChange_ = false;
richEditorPattern->keyboardAvoidance_ = false;
EXPECT_EQ(richEditorPattern->GetCrossOverHeight(), 0.0f);
richEditorPattern->contentChange_ = true;
richEditorPattern->keyboardAvoidance_ = false;
EXPECT_EQ(richEditorPattern->GetCrossOverHeight(), 0.0f);
AceApplicationInfo::GetInstance().SetApiTargetVersion(backupApiVersion);
}
/**
* @tc.name: RemoveEmptySpanNodes001
* @tc.desc: test RemoveEmptySpanNodes

View File

@ -1353,4 +1353,246 @@ HWTEST_F(RichEditorPatternTestOneNg, InsertSpanByBackData001, TestSize.Level1)
EXPECT_EQ(richEditorPattern->operationRecords_.size(), start + 2);
richEditorPattern->ClearOperationRecords();
}
/**
* @tc.name: IsShowAIWrite001
* @tc.desc: test IsShowAIWrite
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestOneNg, IsShowAIWrite001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
auto richEditorController = richEditorPattern->GetRichEditorController();
ASSERT_NE(richEditorController, nullptr);
TextSpanOptions options;
options.value = INIT_VALUE_3;
richEditorController->AddTextSpan(options);
richEditorPattern->textSelector_.Update(0, 5);
auto mockContainer = MockContainer::Current();
mockContainer->SetIsScenceBoardWindow(true);
auto result = richEditorPattern->IsShowAIWrite();
EXPECT_FALSE(result);
}
/**
* @tc.name: IsShowAIWrite002
* @tc.desc: test IsShowAIWrite
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestOneNg, IsShowAIWrite002, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
auto richEditorController = richEditorPattern->GetRichEditorController();
ASSERT_NE(richEditorController, nullptr);
TextSpanOptions options;
options.value = INIT_VALUE_3;
richEditorController->AddTextSpan(options);
richEditorPattern->textSelector_.Update(0, 5);
MockContainer::TearDown();
auto result = richEditorPattern->IsShowAIWrite();
EXPECT_FALSE(result);
}
/**
* @tc.name: IsShowAIWrite003
* @tc.desc: test IsShowAIWrite
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestOneNg, IsShowAIWrite003, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
auto richEditorController = richEditorPattern->GetRichEditorController();
ASSERT_NE(richEditorController, nullptr);
TextSpanOptions options;
options.value = INIT_VALUE_3;
richEditorController->AddTextSpan(options);
richEditorPattern->textSelector_.Update(0, 5);
richEditorPattern->copyOption_ = CopyOptions::Local;
auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
ASSERT_NE(themeManager, nullptr);
PipelineBase::GetCurrentContext()->themeManager_ = themeManager;
auto theme = AceType::MakeRefPtr<RichEditorTheme>();
EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<RichEditorTheme>()));
auto result = richEditorPattern->IsShowAIWrite();
EXPECT_FALSE(result);
}
/**
* @tc.name: IsShowAIWrite004
* @tc.desc: test IsShowAIWrite
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestOneNg, IsShowAIWrite004, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
auto richEditorController = richEditorPattern->GetRichEditorController();
ASSERT_NE(richEditorController, nullptr);
TextSpanOptions options;
options.value = INIT_VALUE_3;
richEditorController->AddTextSpan(options);
richEditorPattern->textSelector_.Update(0, 5);
richEditorPattern->copyOption_ = CopyOptions::Local;
auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
ASSERT_NE(themeManager, nullptr);
PipelineBase::GetCurrentContext()->themeManager_ = themeManager;
auto theme = AceType::MakeRefPtr<RichEditorTheme>();
EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
theme->aiWriteBundleName_ = "bundleName";
auto result = richEditorPattern->IsShowAIWrite();
EXPECT_EQ("", richEditorPattern->aiWriteAdapter_->GetBundleName());
EXPECT_FALSE(result);
}
/**
* @tc.name: IsShowAIWrite005
* @tc.desc: test IsShowAIWrite
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestOneNg, IsShowAIWrite005, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
auto richEditorController = richEditorPattern->GetRichEditorController();
ASSERT_NE(richEditorController, nullptr);
TextSpanOptions options;
options.value = INIT_VALUE_3;
richEditorController->AddTextSpan(options);
richEditorPattern->textSelector_.Update(0, 5);
richEditorPattern->copyOption_ = CopyOptions::Local;
auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
ASSERT_NE(themeManager, nullptr);
PipelineBase::GetCurrentContext()->themeManager_ = themeManager;
auto theme = AceType::MakeRefPtr<RichEditorTheme>();
EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
theme->aiWriteBundleName_ = "bundleName";
theme->aiWriteAbilityName_ = "abilityName";
auto result = richEditorPattern->IsShowAIWrite();
EXPECT_EQ("bundleName", richEditorPattern->aiWriteAdapter_->GetBundleName());
EXPECT_EQ("abilityName", richEditorPattern->aiWriteAdapter_->GetAbilityName());
EXPECT_FALSE(result);
}
/**
* @tc.name: IsShowAIWrite006
* @tc.desc: test IsShowAIWrite
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestOneNg, IsShowAIWrite006, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
auto richEditorController = richEditorPattern->GetRichEditorController();
ASSERT_NE(richEditorController, nullptr);
TextSpanOptions options;
options.value = INIT_VALUE_3;
richEditorController->AddTextSpan(options);
richEditorPattern->textSelector_.Update(0, 5);
richEditorPattern->copyOption_ = CopyOptions::Local;
auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
ASSERT_NE(themeManager, nullptr);
PipelineBase::GetCurrentContext()->themeManager_ = themeManager;
auto theme = AceType::MakeRefPtr<RichEditorTheme>();
EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
theme->aiWriteBundleName_ = "bundleName";
theme->aiWriteAbilityName_ = "abilityName";
theme->aiWriteIsSupport_ = "true";
auto result = richEditorPattern->IsShowAIWrite();
EXPECT_EQ("bundleName", richEditorPattern->aiWriteAdapter_->GetBundleName());
EXPECT_EQ("abilityName", richEditorPattern->aiWriteAdapter_->GetAbilityName());
EXPECT_TRUE(result);
}
/**
* @tc.name: GetAIWriteInfo001
* @tc.desc: test GetAIWriteInfo
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestOneNg, GetAIWriteInfo001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
auto richEditorController = richEditorPattern->GetRichEditorController();
ASSERT_NE(richEditorController, nullptr);
TextSpanOptions options;
options.value = INIT_VALUE_3;
richEditorController->AddTextSpan(options);
richEditorPattern->textSelector_.Update(0, 5);
richEditorPattern->textForDisplay_ = "testtesttest";
AIWriteInfo info;
richEditorPattern->GetAIWriteInfo(info);
EXPECT_EQ(info.selectStart, 0);
EXPECT_EQ(info.selectEnd, 5);
EXPECT_EQ(info.selectLength, 5);
EXPECT_EQ(info.firstHandle, richEditorPattern->textSelector_.firstHandle.ToString());
EXPECT_EQ(info.secondHandle, richEditorPattern->textSelector_.secondHandle.ToString());
RefPtr<SpanString> spanString = SpanString::DecodeTlv(info.selectBuffer);
ASSERT_NE(spanString, nullptr);
auto textContent = spanString->GetString();
EXPECT_EQ(textContent.empty(), false);
}
/**
* @tc.name: AIDeleteComb001
* @tc.desc: test AIDeleteComb
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestOneNg, AIDeleteComb001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
auto spanString = AceType::MakeRefPtr<SpanString>("");
richEditorPattern->textSelector_ = TextSelector(0, 6);
EXPECT_TRUE(richEditorPattern->textSelector_.IsValid());
richEditorPattern->InsertSpanByBackData(spanString);
EXPECT_FALSE(richEditorPattern->textSelector_.IsValid());
richEditorPattern->ClearOperationRecords();
richEditorPattern->placeholderSpansMap_["![id1]"] = AceType::MakeRefPtr<SpanItem>();
spanString = AceType::MakeRefPtr<SpanString>("test![id1]");
auto start = richEditorPattern->operationRecords_.size();
richEditorPattern->InsertSpanByBackData(spanString);
EXPECT_EQ(richEditorPattern->operationRecords_.size(), start + 2);
richEditorPattern->ClearOperationRecords();
}
/**
* @tc.name: HandleOnDeleteComb001
* @tc.desc: test HandleOnDeleteComb
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestOneNg, HandleOnDeleteComb001, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
auto spanItem = AceType::MakeRefPtr<SpanItem>();
spanItem->rangeStart = 2;
spanItem->position = 10;
spanItem->unicode = 1;
richEditorPattern->spans_.push_back(spanItem);
richEditorPattern->caretPosition_ = 6;
auto ret = richEditorPattern->HandleOnDeleteComb(true);
EXPECT_TRUE(ret);
}
} // namespace OHOS::Ace::NG

View File

@ -1365,6 +1365,23 @@ HWTEST_F(RichEditorPatternTestThreeNg, AdjustIndexSkipLineSeparator002, TestSize
EXPECT_FALSE(ret);
}
/**
* @tc.name: AdjustIndexSkipLineSeparator003
* @tc.desc: test AdjustIndexSkipLineSeparator
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestThreeNg, AdjustIndexSkipLineSeparator003, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
int32_t currentPosition = 10;
RefPtr<SpanItem> spanItem = AceType::MakeRefPtr<SpanItem>();
spanItem->content = "AdjustInd\nxSkipLineSeparator";
richEditorPattern->spans_.push_back(spanItem);
EXPECT_TRUE(richEditorPattern->AdjustIndexSkipLineSeparator(currentPosition));
}
/**
* @tc.name: IsResponseRegionExpandingNeededForStylus001
* @tc.desc: test testInput text IsResponseRegionExpandingNeededForStylus001
@ -1399,4 +1416,176 @@ HWTEST_F(RichEditorPatternTestThreeNg, IsResponseRegionExpandingNeededForStylus0
ret = richEditorPattern->IsResponseRegionExpandingNeededForStylus(touchEvent);
EXPECT_FALSE(ret);
}
/**
* @tc.name: InsertValueOperation
* @tc.desc: test InsertValueOperation
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestThreeNg, InsertValueOperation, TestSize.Level2)
{
auto richEditorPattern = GetRichEditorPattern();
ASSERT_NE(richEditorPattern, nullptr);
RichEditorPattern::OperationRecord firstRecord;
firstRecord.addText = "first Record helloWorld";
firstRecord.deleteText = "helloWorld";
richEditorPattern->operationRecords_.emplace_back(firstRecord);
richEditorPattern->redoOperationRecords_.clear();
for (uint32_t count = 0; count < RECORD_MAX_LENGTH; ++count) {
RichEditorPattern::OperationRecord emptyRecord;
richEditorPattern->redoOperationRecords_.emplace_back(emptyRecord);
}
richEditorPattern->HandleOnUndoAction();
EXPECT_TRUE(richEditorPattern->operationRecords_.empty());
struct UpdateSpanStyle typingStyle;
TextStyle textStyle(5);
richEditorPattern->SetTypingStyle(typingStyle, textStyle);
RichEditorPattern::OperationRecord secondRecord;
secondRecord.addText = "second Record helloWorld";
secondRecord.deleteCaretPostion = 3;
richEditorPattern->operationRecords_.clear();
richEditorPattern->operationRecords_.emplace_back(secondRecord);
richEditorPattern->HandleOnUndoAction();
EXPECT_TRUE(richEditorPattern->operationRecords_.empty());
}
/**
* @tc.name: CursorMoveUp001
* @tc.desc: test CursorMoveUp
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestThreeNg, CursorMoveUp001, TestSize.Level1)
{
auto richEditorPattern = GetRichEditorPattern();
ASSERT_NE(richEditorPattern, nullptr);
AddSpan("hello1");
richEditorPattern->caretPosition_ = 1;
EXPECT_TRUE(richEditorPattern->CursorMoveUp());
}
/**
* @tc.name: CursorMoveUp002
* @tc.desc: test CursorMoveUp
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestThreeNg, CursorMoveUp002, TestSize.Level1)
{
auto richEditorPattern = GetRichEditorPattern();
ASSERT_NE(richEditorPattern, nullptr);
AddSpan("hello1");
richEditorPattern->caretPosition_ = 1;
OffsetF paintOffset = { -10, 1 };
richEditorPattern->richTextRect_.SetOffset(paintOffset);
EXPECT_TRUE(richEditorPattern->CursorMoveUp());
}
/**
* @tc.name: CursorMoveDown
* @tc.desc: test CursorMoveDown
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestThreeNg, CursorMoveDown, TestSize.Level1)
{
auto richEditorPattern = GetRichEditorPattern();
ASSERT_NE(richEditorPattern, nullptr);
AddSpan("hello1");
richEditorPattern->caretPosition_ = 1;
OffsetF paintOffset = { -10, 1 };
richEditorPattern->richTextRect_.SetOffset(paintOffset);
EXPECT_TRUE(richEditorPattern->CursorMoveDown());
}
/**
* @tc.name: HandleBlurEvent
* @tc.desc: test HandleBlurEvent
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestThreeNg, HandleBlurEvent, TestSize.Level1)
{
auto richEditorPattern = GetRichEditorPattern();
ASSERT_NE(richEditorPattern, nullptr);
WeakPtr<Pattern> pattern;
richEditorPattern->magnifierController_ = nullptr;
richEditorPattern->textSelector_.Update(3, 4);
richEditorPattern->HandleBlurEvent();
EXPECT_FALSE(richEditorPattern->isMoveCaretAnywhere_);
}
/**
* @tc.name: FireOnSelectionChange001
* @tc.desc: test FireOnSelectionChange
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestThreeNg, FireOnSelectionChange001, TestSize.Level0)
{
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
int32_t start = 1;
int32_t end = 1;
bool isForced = true;
richEditorPattern->caretTwinkling_ = true;
richEditorPattern->selectOverlay_->isSingleHandle_ = true;
auto range = richEditorPattern->lastSelectionRange_;
richEditorPattern->FireOnSelectionChange(start, end, isForced);
EXPECT_FALSE(richEditorPattern->lastSelectionRange_ == range);
}
/**
* @tc.name: FireOnSelectionChange002
* @tc.desc: test FireOnSelectionChange
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestThreeNg, FireOnSelectionChange002, TestSize.Level0)
{
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
int32_t start = 1;
int32_t end = 1;
bool isForced = true;
richEditorPattern->caretTwinkling_ = false;
richEditorPattern->selectOverlay_->isSingleHandle_ = true;
auto range = richEditorPattern->lastSelectionRange_;
richEditorPattern->FireOnSelectionChange(start, end, isForced);
EXPECT_FALSE(richEditorPattern->lastSelectionRange_ == range);
}
/**
* @tc.name: FireOnSelectionChange003
* @tc.desc: test FireOnSelectionChange
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestThreeNg, FireOnSelectionChange003, TestSize.Level0)
{
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
int32_t start = 1;
int32_t end = 1;
bool isForced = true;
richEditorPattern->caretTwinkling_ = false;
richEditorPattern->selectOverlay_->isSingleHandle_ = false;
auto range = richEditorPattern->lastSelectionRange_;
richEditorPattern->FireOnSelectionChange(start, end, isForced);
EXPECT_TRUE(richEditorPattern->lastSelectionRange_ == range);
}
/**
* @tc.name: SetTypingStyle001
* @tc.desc: test SetTypingStyle
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestThreeNg, SetTypingStyle001, TestSize.Level0)
{
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
UpdateSpanStyle typingStyle;
TextStyle textStyle;
auto spanItem = AceType::MakeRefPtr<SpanItem>();
richEditorPattern->spans_.emplace_back(spanItem);
richEditorPattern->previewTextRecord_.previewContent = "";
auto layout = richEditorNode_->layoutProperty_;
richEditorPattern->SetTypingStyle(typingStyle, textStyle);
EXPECT_TRUE(layout == richEditorNode_->layoutProperty_);
}
} // namespace OHOS::Ace::NG

View File

@ -494,6 +494,65 @@ HWTEST_F(RichEditorPatternTestTwoNg, UpdateSelectionByTouchMove001, TestSize.Lev
EXPECT_TRUE(richEditorPattern->isShowMenu_);
}
/**
* @tc.name: UpdateSelectionByTouchMove002
* @tc.desc: test UpdateSelectionByTouchMove
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestTwoNg, UpdateSelectionByTouchMove002, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->isEditing_ = true;
richEditorPattern->isSpanStringMode_ = true;
richEditorPattern->styledString_ = AceType::MakeRefPtr<MutableSpanString>(INIT_VALUE_1);
Offset touchOffset(20.0f, 20.0f);
richEditorPattern->UpdateSelectionByTouchMove(touchOffset);
ASSERT_NE(richEditorPattern->magnifierController_, nullptr);
EXPECT_EQ(touchOffset.GetX(), richEditorPattern->magnifierController_->localOffset_.GetX());
EXPECT_EQ(touchOffset.GetY(), richEditorPattern->magnifierController_->localOffset_.GetY());
EXPECT_TRUE(richEditorPattern->magnifierController_->magnifierNodeExist_);
}
/**
* @tc.name: UpdateSelectionByTouchMove003
* @tc.desc: test UpdateSelectionByTouchMove
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestTwoNg, UpdateSelectionByTouchMove003, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->isEditing_ = true;
richEditorPattern->isSpanStringMode_ = true;
richEditorPattern->styledString_ = AceType::MakeRefPtr<MutableSpanString>(INIT_VALUE_1);
Offset touchOffset(20.0f, 20.0f);
richEditorPattern->magnifierController_ = nullptr;
richEditorPattern->UpdateSelectionByTouchMove(touchOffset);
EXPECT_TRUE(richEditorPattern->isShowMenu_);
}
/**
* @tc.name: UpdateSelectionByTouchMove004
* @tc.desc: test UpdateSelectionByTouchMove
* @tc.type: FUNC
*/
HWTEST_F(RichEditorPatternTestTwoNg, UpdateSelectionByTouchMove004, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
richEditorPattern->isEditing_ = true;
richEditorPattern->isSpanStringMode_ = true;
richEditorPattern->textSelector_.Update(0, 10);
richEditorPattern->styledString_ = AceType::MakeRefPtr<MutableSpanString>(INIT_VALUE_1);
Offset touchOffset(20.0f, 20.0f);
richEditorPattern->UpdateSelectionByTouchMove(touchOffset);
EXPECT_TRUE(richEditorPattern->isShowMenu_);
}
/**
* @tc.name: GetSelectedMaxWidth001
* @tc.desc: test GetSelectedMaxWidth

View File

@ -950,6 +950,37 @@ HWTEST_F(RichEditorStyledStringTestNg, CopySpanStyle003, TestSize.Level1)
EXPECT_EQ(target->fontStyle->GetFontSize(), FONT_SIZE_VALUE);
}
/**
* @tc.name: CopySpanStyle004
* @tc.desc: test CopySpanStyle
* @tc.type: FUNC
*/
HWTEST_F(RichEditorStyledStringTestNg, CopySpanStyle004, TestSize.Level1)
{
ASSERT_NE(richEditorNode_, nullptr);
auto richEditorPattern = richEditorNode_->GetPattern<RichEditorPattern>();
ASSERT_NE(richEditorPattern, nullptr);
auto layoutAlgorithm = AceType::DynamicCast<RichEditorLayoutAlgorithm>(richEditorPattern->CreateLayoutAlgorithm());
ASSERT_NE(layoutAlgorithm, nullptr);
auto source = AceType::MakeRefPtr<SpanItem>();
auto target = AceType::MakeRefPtr<SpanItem>();
LeadingMargin leadingMargin;
source->textLineStyle->UpdateLeadingMargin(leadingMargin);
source->fontStyle->UpdateFontSize(FONT_SIZE_VALUE);
source->textLineStyle->UpdateLineHeight(LINE_HEIGHT_VALUE);
TextStyle style;
style.SetLineHeight(LINE_HEIGHT_VALUE);
style.SetLetterSpacing(LETTER_SPACING);
style.SetFontFeatures(TEXT_FONTFEATURE);
style.SetFontSize(FONT_SIZE_VALUE);
layoutAlgorithm->typingTextStyle_ = style;
layoutAlgorithm->CopySpanStyle(source, target);
EXPECT_EQ(target->fontStyle->GetFontSize(), FONT_SIZE_VALUE);
}
/**
* @tc.name: GetSelection001
* @tc.desc: test GetSelection