From 05b09c62c8970c50acfbb580ef2643254f63bb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B0=B8=E5=87=AF?= Date: Thu, 22 May 2025 19:50:15 +0800 Subject: [PATCH] dialogtdd1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘永凯 --- test/unittest/core/pattern/dialog/BUILD.gn | 1 + .../dialog/dialog_pattern_test_one.cpp | 207 ++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 test/unittest/core/pattern/dialog/dialog_pattern_test_one.cpp diff --git a/test/unittest/core/pattern/dialog/BUILD.gn b/test/unittest/core/pattern/dialog/BUILD.gn index 9572acb6319..136a3fa8519 100644 --- a/test/unittest/core/pattern/dialog/BUILD.gn +++ b/test/unittest/core/pattern/dialog/BUILD.gn @@ -19,6 +19,7 @@ ace_unittest("dialog_test_ng") { "dialog_layout_test_ng.cpp", "dialog_model_test_ng.cpp", "dialog_pattern_test_ng.cpp", + "dialog_pattern_test_one.cpp", "dialog_test_ng.cpp", ] } diff --git a/test/unittest/core/pattern/dialog/dialog_pattern_test_one.cpp b/test/unittest/core/pattern/dialog/dialog_pattern_test_one.cpp new file mode 100644 index 00000000000..d4a8925b9fa --- /dev/null +++ b/test/unittest/core/pattern/dialog/dialog_pattern_test_one.cpp @@ -0,0 +1,207 @@ +/* + * 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 + +#include "gtest/gtest.h" +#include "test/unittest/core/pattern/image/image_base.h" +#include "ui/base/ace_type.h" + +#include "base/utils/singleton.h" +#include "core/common/display_info.h" +#include "core/components_ng/base/frame_node.h" +#include "core/pipeline/base/constants.h" + +#define private public +#define protected public +#include "test/mock/base/mock_subwindow.h" +#include "test/mock/base/mock_system_properties.h" +#include "test/mock/base/mock_task_executor.h" +#include "test/mock/core/common/mock_container.h" +#include "test/mock/core/common/mock_theme_manager.h" +#include "test/mock/core/pipeline/mock_pipeline_context.h" + +#include "base/log/dump_log.h" +#include "base/subwindow/subwindow_manager.h" +#include "core/common/recorder/event_recorder.h" +#include "core/components/dialog/dialog_properties.h" +#include "core/components/select/select_theme.h" +#include "core/components_ng/base/view_stack_processor.h" +#include "core/components_ng/pattern/action_sheet/action_sheet_model_ng.h" +#include "core/components_ng/pattern/dialog/alert_dialog_model_ng.h" +#include "core/components_ng/pattern/dialog/custom_dialog_controller_model_ng.h" +#include "core/components_ng/pattern/dialog/dialog_event_hub.h" +#include "core/components_ng/pattern/dialog/dialog_layout_algorithm.h" +#include "core/components_ng/pattern/dialog/dialog_pattern.h" +#include "core/components_ng/pattern/dialog/dialog_view.h" +#include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h" +#include "core/components_ng/pattern/navrouter/navdestination_group_node.h" +#include "core/components_ng/pattern/navrouter/navdestination_pattern.h" +#include "core/components_ng/pattern/overlay/dialog_manager.h" +#include "core/components_ng/pattern/overlay/overlay_manager.h" +#include "core/components_ng/pattern/root/root_pattern.h" +#include "core/components_v2/inspector/inspector_constants.h" + +using namespace testing; +using namespace testing::ext; +namespace OHOS::Ace::NG { +namespace {} // namespace + +class DialogPatternOneTestNg : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); +}; + +void DialogPatternOneTestNg::SetUpTestCase() +{ + MockPipelineContext::SetUp(); + RefPtr stageNode = AceType::MakeRefPtr("STAGE", -1, AceType::MakeRefPtr()); + auto stageManager = AceType::MakeRefPtr(stageNode); + MockPipelineContext::GetCurrent()->stageManager_ = stageManager; + auto themeManager = AceType::MakeRefPtr(); + MockContainer::SetUp(); + MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr(); + MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext(); + MockSystemProperties::g_isSuperFoldDisplayDevice = false; + + EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr { + if (type == DialogTheme::TypeId()) { + return AceType::MakeRefPtr(); + } else { + return nullptr; + } + }); + MockPipelineContext::GetCurrent()->SetThemeManager(themeManager); +} + +void DialogPatternOneTestNg::TearDownTestCase() +{ + MockPipelineContext::GetCurrent()->themeManager_ = nullptr; + MockPipelineContext::TearDown(); + MockContainer::TearDown(); +} + +/** + * @tc.name: DialogPatternTestMountUECMask + * @tc.desc: Test SetDialogAccessibilityMountUECMask + * @tc.type: FUNC + */ +HWTEST_F(DialogPatternOneTestNg, DialogPatternTestMountUECMask, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create dialogNode and dialogTheme instance. + * @tc.expected: The dialogNode and dialogNode created successfully. + */ + auto dialogTheme = AceType::MakeRefPtr(); + ASSERT_NE(dialogTheme, nullptr); + RefPtr frameNode = FrameNode::CreateFrameNode( + V2::ALERT_DIALOG_ETS_TAG, 1, AceType::MakeRefPtr(dialogTheme, nullptr)); + ASSERT_NE(frameNode, nullptr); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + /** + * @tc.steps: step2. Invoke Handle functions. + * @tc.expected: These Dump properties are matched. + */ + auto host = AceType::DynamicCast(pattern)->GetHost(); + ASSERT_NE(host, nullptr); + pattern->isUIExtensionSubWindow_ = true; + pattern->dialogProperties_.isModal = false; + pattern->MountUECMask(); + + pattern->dialogProperties_.isModal = true; + pattern->MountUECMask(); +} + +/** + * @tc.name: DialogPatternTestIsWaterfallWindowMode + * @tc.desc: Test IsWaterfallWindowMode + * @tc.type: FUNC + */ +HWTEST_F(DialogPatternOneTestNg, DialogPatternTestIsWaterfallWindowMode, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create dialogNode and dialogTheme instance. + * @tc.expected: The dialogNode and dialogNode created successfully. + */ + auto dialogTheme = AceType::MakeRefPtr(); + ASSERT_NE(dialogTheme, nullptr); + RefPtr frameNode = FrameNode::CreateFrameNode( + V2::ALERT_DIALOG_ETS_TAG, 1, AceType::MakeRefPtr(dialogTheme, nullptr)); + ASSERT_NE(frameNode, nullptr); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + /** + * @tc.steps: step2. Invoke Handle functions. + * @tc.expected: These Dump properties are matched. + */ + MockContainer::container_ = nullptr; + auto container = AceType::DynamicCast(Container::Current()); + ASSERT_EQ(container, nullptr); + EXPECT_FALSE(pattern->IsWaterfallWindowMode()); + + MockContainer::SetUp(); + container = AceType::DynamicCast(Container::Current()); + container->UpdateCurrent(10); + ASSERT_NE(container, nullptr); + container->isSubContainer_ = true; + EXPECT_TRUE(container->IsSubContainer()); + + auto currentId = SubwindowManager::GetInstance()->GetParentContainerId(Container::CurrentId()); + auto subcontainer = AceEngine::Get().GetContainer(currentId); + ASSERT_EQ(subcontainer, nullptr); + EXPECT_FALSE(pattern->IsWaterfallWindowMode()); + + SubwindowManager::GetInstance()->AddParentContainerId(Container::CurrentId(), Container::CurrentId()); + currentId = SubwindowManager::GetInstance()->GetParentContainerId(Container::CurrentId()); + AceEngine::Get().AddContainer(currentId, container); + subcontainer = AceEngine::Get().GetContainer(currentId); + ASSERT_NE(subcontainer, nullptr); + EXPECT_FALSE(pattern->IsWaterfallWindowMode()); + + container->ResetContainer(); +} + +/** + * @tc.name: DialogPatternTestToJsonValue + * @tc.desc: Test ToJsonValue + * @tc.type: FUNC + */ +HWTEST_F(DialogPatternOneTestNg, DialogPatternTestToJsonValue, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create dialogNode and dialogTheme instance. + * @tc.expected: The dialogNode and dialogNode created successfully. + */ + auto dialogTheme = AceType::MakeRefPtr(); + ASSERT_NE(dialogTheme, nullptr); + RefPtr frameNode = FrameNode::CreateFrameNode( + V2::ALERT_DIALOG_ETS_TAG, 1, AceType::MakeRefPtr(dialogTheme, nullptr)); + ASSERT_NE(frameNode, nullptr); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + /** + * @tc.steps: step2. Invoke Handle functions. + * @tc.expected: These Dump properties are matched. + */ + std::unique_ptr jsonPtr = JsonUtil::Create(false); + ASSERT_NE(jsonPtr, nullptr); + auto filterJson = InspectorFilter(); + filterJson.filterFixed = 1; + filterJson.filterExt.clear(); + pattern->ToJsonValue(jsonPtr, filterJson); +} +} // namespace OHOS::Ace::NG -- Gitee