From 7257ec660d99708413a6a957067dad95ccb0a141 Mon Sep 17 00:00:00 2001 From: mengbin Date: Thu, 21 Nov 2024 18:05:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85TextFieldPattern=E7=9A=84TDD?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mengbin --- .../unittest/core/pattern/text_input/BUILD.gn | 1 + .../text_input/text_field_pattern_testsix.cpp | 179 ++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 test/unittest/core/pattern/text_input/text_field_pattern_testsix.cpp diff --git a/test/unittest/core/pattern/text_input/BUILD.gn b/test/unittest/core/pattern/text_input/BUILD.gn index e353101b372..6ae43e6ffd3 100644 --- a/test/unittest/core/pattern/text_input/BUILD.gn +++ b/test/unittest/core/pattern/text_input/BUILD.gn @@ -28,6 +28,7 @@ ace_unittest("TextInputTest") { "text_field_pattern_test.cpp", "text_field_pattern_testfive.cpp", "text_field_pattern_testfour.cpp", + "text_field_pattern_testsix.cpp", "text_field_pattern_testthree.cpp", "text_field_pattern_testtwo.cpp", "text_input_area_model_test.cpp", diff --git a/test/unittest/core/pattern/text_input/text_field_pattern_testsix.cpp b/test/unittest/core/pattern/text_input/text_field_pattern_testsix.cpp new file mode 100644 index 00000000000..e86cbcd147b --- /dev/null +++ b/test/unittest/core/pattern/text_input/text_field_pattern_testsix.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "text_input_base.h" + +#include "core/components_ng/pattern/stage/page_pattern.h" +#include "core/components_v2/inspector/inspector_constants.h" + +namespace OHOS::Ace::NG { + +namespace {} // namespace + +class TextFieldPatternTestSix : public TextInputBases { +public: +}; + +/** + * @tc.name: HandleOnDragStatusCallback001 + * @tc.desc: test testInput text HandleOnDragStatusCallback + * @tc.type: FUNC + */ +HWTEST_F(TextFieldPatternTestSix, HandleOnDragStatusCallback001, TestSize.Level0) +{ + CreateTextField(); + auto notifyDragEvent = AceType::MakeRefPtr(); + pattern_->isCaretTwinkling_ = true; + pattern_->dragRecipientStatus_ = DragStatus::DRAGGING; + pattern_->HandleOnDragStatusCallback(DragEventType::DROP, notifyDragEvent); + ASSERT_FALSE(pattern_->isCaretTwinkling_); + pattern_->isCaretTwinkling_ = true; + pattern_->dragRecipientStatus_ = DragStatus::NONE; + pattern_->HandleOnDragStatusCallback(DragEventType::DROP, notifyDragEvent); + ASSERT_TRUE(pattern_->isCaretTwinkling_); + pattern_->isCaretTwinkling_ = true; + pattern_->HandleOnDragStatusCallback(DragEventType::ENTER, notifyDragEvent); + ASSERT_TRUE(pattern_->isCaretTwinkling_); +} + +/** + * @tc.name: CheckMousePressedOverScrollBar001 + * @tc.desc: test testInput text CheckMousePressedOverScrollBar + * @tc.type: FUNC + */ +HWTEST_F(TextFieldPatternTestSix, CheckMousePressedOverScrollBar001, TestSize.Level0) +{ + CreateTextField(); + GestureEvent info; + ASSERT_FALSE(pattern_->CheckMousePressedOverScrollBar(info)); + info.localLocation_ = Offset(10, 30); + auto scrollBar = AceType::MakeRefPtr(); + scrollBar->isScrollable_ = true; + scrollBar->barRect_ = Rect(0, 0, 12, 40); + pattern_->scrollBar_ = scrollBar; + ASSERT_FALSE(pattern_->CheckMousePressedOverScrollBar(info)); + pattern_->hasMousePressed_ = true; + ASSERT_TRUE(pattern_->CheckMousePressedOverScrollBar(info)); + auto layoutProperty = pattern_->GetLayoutProperty(); + layoutProperty->UpdateDisplayMode(DisplayMode::OFF); + ASSERT_FALSE(pattern_->CheckMousePressedOverScrollBar(info)); +} + +/** + * @tc.name: FillTriggeredStateByType001 + * @tc.desc: test testInput text FillTriggeredStateByType + * @tc.type: FUNC + */ +HWTEST_F(TextFieldPatternTestSix, FillTriggeredStateByType001, TestSize.Level0) +{ + CreateTextField(); + auto parentFrameNode = + FrameNode::GetOrCreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + []() { return AceType::MakeRefPtr(AceType::MakeRefPtr()); }); + frameNode_->SetParent(parentFrameNode); + pattern_->firstAutoFillContainerNode_ = AceType::WeakClaim(AceType::RawPtr(parentFrameNode)); + pattern_->SetAutoFillTriggeredStateByType(AceAutoFillType::ACE_BANK_CARD_NUMBER); + ASSERT_FALSE(pattern_->GetAutoFillTriggeredStateByType(AceAutoFillType::ACE_BANK_CARD_NUMBER)); + + pattern_->SetAutoFillTriggeredStateByType(AceAutoFillType::ACE_PASSWORD); + ASSERT_FALSE(pattern_->GetAutoFillTriggeredStateByType(AceAutoFillType::ACE_PASSWORD)); + + pattern_->SetAutoFillTriggeredStateByType(AceAutoFillType::ACE_NEW_PASSWORD); + ASSERT_FALSE(pattern_->GetAutoFillTriggeredStateByType(AceAutoFillType::ACE_NEW_PASSWORD)); + + auto pipeline = frameNode_->GetContext(); + CHECK_NULL_VOID(pipeline); + auto textFieldManager = AceType::DynamicCast(pipeline->GetTextFieldManager()); + CHECK_NULL_VOID(textFieldManager); + auto passwordFrameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, + ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(); }); + passwordFrameNode->SetParent(parentFrameNode); + auto passwordPattern = passwordFrameNode->GetPattern(); + std::unordered_map nameAndPasswordInfoMap; + TextFieldInfo textFieldInfo; + textFieldInfo.nodeId = frameNode_->GetId(); + nameAndPasswordInfoMap[textFieldInfo.nodeId] = textFieldInfo; + TextFieldInfo textFieldInfo2; + textFieldInfo2.nodeId = passwordFrameNode->GetId(); + textFieldInfo2.inputType = TextInputType::NEW_PASSWORD; + textFieldInfo2.enableAutoFill = true; + nameAndPasswordInfoMap[passwordFrameNode->GetId()] = textFieldInfo2; + std::unordered_map> textFieldInfoMap; + textFieldInfoMap[parentFrameNode->GetId()] = nameAndPasswordInfoMap; + textFieldManager->textFieldInfoMap_ = textFieldInfoMap; + ASSERT_TRUE(textFieldManager->HasAutoFillPasswordNodeInContainer(parentFrameNode->GetId(), frameNode_->GetId())); + pattern_->SetAutoFillTriggeredStateByType(AceAutoFillType::ACE_UNSPECIFIED); + ASSERT_FALSE(pattern_->GetAutoFillTriggeredStateByType(AceAutoFillType::ACE_UNSPECIFIED)); + + pattern_->SetAutoFillTriggeredStateByType(AceAutoFillType::ACE_USER_NAME); + ASSERT_FALSE(pattern_->GetAutoFillTriggeredStateByType(AceAutoFillType::ACE_USER_NAME)); +} + +/** + * @tc.name: GetAutoFillTypeAndMetaData001 + * @tc.desc: test testInput text GetAutoFillTypeAndMetaData + * @tc.type: FUNC + */ +HWTEST_F(TextFieldPatternTestSix, GetAutoFillTypeAndMetaData001, TestSize.Level0) +{ + CreateTextField(); + auto hintToTypeWrap = pattern_->GetAutoFillTypeAndMetaData(false); + ASSERT_EQ(hintToTypeWrap.autoFillType, AceAutoFillType::ACE_UNSPECIFIED); + ASSERT_EQ(hintToTypeWrap.metadata, "{\"type\":\"InputType.Normal\"}"); + + hintToTypeWrap = pattern_->GetAutoFillTypeAndMetaData(true); + ASSERT_EQ(hintToTypeWrap.autoFillType, AceAutoFillType::ACE_UNSPECIFIED); + + auto layoutProperty = frameNode_->GetLayoutProperty(); + layoutProperty->UpdateTextInputType(TextInputType::VISIBLE_PASSWORD); + hintToTypeWrap = pattern_->GetAutoFillTypeAndMetaData(false); + ASSERT_EQ(hintToTypeWrap.autoFillType, AceAutoFillType::ACE_PASSWORD); + + layoutProperty->UpdateTextContentType(TextContentType::NEW_PASSWORD); + hintToTypeWrap = pattern_->GetAutoFillTypeAndMetaData(false); + ASSERT_EQ(hintToTypeWrap.autoFillType, AceAutoFillType::ACE_NEW_PASSWORD); + + auto pipeline = frameNode_->GetContext(); + CHECK_NULL_VOID(pipeline); + auto textFieldManager = AceType::DynamicCast(pipeline->GetTextFieldManager()); + CHECK_NULL_VOID(textFieldManager); + auto passwordFrameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, + ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(); }); + auto parentFrameNode = + FrameNode::GetOrCreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + []() { return AceType::MakeRefPtr(AceType::MakeRefPtr()); }); + frameNode_->SetParent(parentFrameNode); + passwordFrameNode->SetParent(parentFrameNode); + pattern_->firstAutoFillContainerNode_ = AceType::WeakClaim(AceType::RawPtr(parentFrameNode)); + auto passwordPattern = passwordFrameNode->GetPattern(); + std::unordered_map nameAndPasswordInfoMap; + TextFieldInfo textFieldInfo; + textFieldInfo.nodeId = frameNode_->GetId(); + nameAndPasswordInfoMap[textFieldInfo.nodeId] = textFieldInfo; + TextFieldInfo textFieldInfo2; + textFieldInfo2.nodeId = passwordFrameNode->GetId(); + textFieldInfo2.inputType = TextInputType::NEW_PASSWORD; + textFieldInfo2.enableAutoFill = true; + nameAndPasswordInfoMap[passwordFrameNode->GetId()] = textFieldInfo2; + std::unordered_map> textFieldInfoMap; + textFieldInfoMap[parentFrameNode->GetId()] = nameAndPasswordInfoMap; + textFieldManager->textFieldInfoMap_ = textFieldInfoMap; + layoutProperty->UpdateTextInputType(TextInputType::UNSPECIFIED); + layoutProperty->UpdateTextContentType(TextContentType::UNSPECIFIED); + hintToTypeWrap = pattern_->GetAutoFillTypeAndMetaData(true); + ASSERT_EQ(hintToTypeWrap.autoFillType, AceAutoFillType::ACE_UNSPECIFIED); + ASSERT_EQ(hintToTypeWrap.metadata, "{\"type\":\"InputType.Normal\"}"); +} +} // namespace OHOS::Ace::NG \ No newline at end of file