CustomDialog支撑蒙层自定义能力 tdd

Signed-off-by: limeng <limeng208@huawei.com>
This commit is contained in:
limeng 2023-03-16 10:03:41 +08:00
parent 7d4ca0e61a
commit ce8f90349f
6 changed files with 359 additions and 3 deletions

View File

@ -60,6 +60,7 @@ use_linux = "${current_os}_${current_cpu}" == "linux_x64"
ace_root = "//foundation/arkui/ace_engine"
ace_napi = "//foundation/arkui/napi"
ace_graphic = "//foundation/graphic/graphic_2d"
ace_hitrace = "//base/hiviewdfx/hitrace"
if (!defined(aosp_libs_dir)) {
aosp_libs_dir = "//prebuilts/aosp_prebuilt_libs/asdk_libs"

View File

@ -42,8 +42,13 @@ bool SystemProperties::GetDebugEnabled()
return false;
}
float SystemProperties::GetAnimationScale()
ACE_WEAK_SYM float SystemProperties::GetAnimationScale()
{
return defaultAnimationScale;
}
bool SystemProperties::GetIsUseMemoryMonitor()
{
return false;
}
} // namespace OHOS::Ace

View File

@ -35,7 +35,7 @@ namespace OHOS::Ace::NG {
RefPtr<FrameNode> DialogView::CreateDialogNode(
const DialogProperties& param, const RefPtr<UINode>& customNode = nullptr)
{
auto pipeline = PipelineContext::GetCurrentContext();
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_RETURN(pipeline, nullptr);
auto dialogTheme = pipeline->GetTheme<DialogTheme>();
CHECK_NULL_RETURN(dialogTheme, nullptr);
@ -89,4 +89,4 @@ RefPtr<FrameNode> DialogView::CreateDialogNode(
return dialog;
}
} // namespace OHOS::Ace::NG
} // namespace OHOS::Ace::NG

View File

@ -25,6 +25,7 @@ group("pattern_unittest") {
"common_view:common_view_test_ng",
"container_modal:container_modal_test_ng",
"counter:counter_pattern_test_ng",
"custom_dialog:custom_dialog_test_ng",
"custom_paint:custom_paint_pattern_test_ng",
"data_panel:data_panel_pattern_test_ng",
"dialog:dialog_pattern_test_ng",

View File

@ -0,0 +1,175 @@
# Copyright (c) 2023 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.
import("//build/test.gni")
import("//foundation/arkui/ace_engine/ace_config.gni")
import("$ace_root/frameworks/core/components_ng/components.gni")
ohos_unittest("custom_dialog_test_ng") {
module_out_path = "$test_output_path/dialog"
include_dirs = [
"$ace_hitrace/interfaces/native/innerkits/include/hitrace_meter",
"$ace_graphic/rosen/modules/2d_graphics/src/drawing/engine_adapter",
"$ace_graphic/rosen/modules/2d_engine/rosen_text",
"$ace_graphic/rosen/modules/2d_engine/rosen_text/properties",
"$ace_graphic/rosen/modules/2d_engine",
"$ace_root/frameworks/base/log",
"$ace_root/frameworks/base/geometry",
"$ace_root/frameworks/base/memory",
]
sources = [
# inner
"$ace_root/adapter/ohos/osal/ace_trace.cpp",
"$ace_root/adapter/ohos/osal/log_wrapper.cpp",
"$ace_root/frameworks/base/geometry/dimension.cpp",
"$ace_root/frameworks/base/json/json_util.cpp",
"$ace_root/frameworks/base/log/ace_trace.cpp",
"$ace_root/frameworks/base/memory/memory_monitor.cpp",
"$ace_root/frameworks/base/utils/base_id.cpp",
"$ace_root/frameworks/base/utils/string_expression.cpp",
"$ace_root/frameworks/base/utils/string_utils.cpp",
"$ace_root/frameworks/core/animation/spring_model.cpp",
"$ace_root/frameworks/core/animation/spring_motion.cpp",
"$ace_root/frameworks/core/components/common/layout/grid_column_info.cpp",
"$ace_root/frameworks/core/components/common/layout/grid_container_info.cpp",
"$ace_root/frameworks/core/components/common/layout/grid_system_manager.cpp",
"$ace_root/frameworks/core/components/common/layout/screen_system_manager.cpp",
"$ace_root/frameworks/core/components/common/properties/alignment.cpp",
"$ace_root/frameworks/core/components/common/properties/color.cpp",
"$ace_root/frameworks/core/components_ng/base/geometry_node.cpp",
"$ace_root/frameworks/core/components_ng/event/event_hub.cpp",
"$ace_root/frameworks/core/components_ng/event/state_style_manager.cpp",
"$ace_root/frameworks/core/components_ng/pattern/dialog/dialog_accessibility_property.cpp",
"$ace_root/frameworks/core/components_ng/pattern/dialog/dialog_event_hub.cpp",
"$ace_root/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.cpp",
"$ace_root/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp",
"$ace_root/frameworks/core/components_ng/pattern/dialog/dialog_view.cpp",
"$ace_root/frameworks/core/components_ng/pattern/image/image_layout_algorithm.cpp",
"$ace_root/frameworks/core/components_ng/pattern/image/image_paint_method.cpp",
"$ace_root/frameworks/core/components_ng/pattern/image/image_pattern.cpp",
"$ace_root/frameworks/core/components_ng/pattern/list/list_item_accessibility_property.cpp",
"$ace_root/frameworks/core/components_ng/pattern/list/list_item_event_hub.cpp",
"$ace_root/frameworks/core/components_ng/pattern/list/list_item_layout_algorithm.cpp",
"$ace_root/frameworks/core/components_ng/pattern/list/list_item_layout_property.cpp",
"$ace_root/frameworks/core/components_ng/pattern/list/list_item_pattern.cpp",
"$ace_root/frameworks/core/components_ng/pattern/list/list_layout_property.cpp",
"$ace_root/frameworks/core/components_ng/pattern/text/span_node.cpp",
"$ace_root/frameworks/core/components_ng/pattern/text/text_accessibility_property.cpp",
"$ace_root/frameworks/core/components_ng/pattern/text/text_content_modifier.cpp",
"$ace_root/frameworks/core/components_ng/pattern/text/text_layout_algorithm.cpp",
"$ace_root/frameworks/core/components_ng/pattern/text/text_layout_property.cpp",
"$ace_root/frameworks/core/components_ng/pattern/text/text_overlay_modifier.cpp",
"$ace_root/frameworks/core/components_ng/pattern/text/text_paint_method.cpp",
"$ace_root/frameworks/core/components_ng/pattern/text/text_styles.cpp",
"$ace_root/frameworks/core/components_ng/property/calc_length.cpp",
"$ace_root/frameworks/core/components_ng/property/measure_utils.cpp",
"$ace_root/frameworks/core/components_ng/property/property.cpp",
"$ace_root/frameworks/core/components_v2/inspector/inspector_constants.cpp",
# components_ng_base
"$ace_root/frameworks/core/components_ng/base/frame_node.cpp",
"$ace_root/frameworks/core/components_ng/base/ui_node.cpp",
# components_ng_layout
"$ace_root/frameworks/core/components_ng/layout/box_layout_algorithm.cpp",
"$ace_root/frameworks/core/components_ng/layout/layout_property.cpp",
"$ace_root/frameworks/core/components_ng/layout/layout_wrapper.cpp",
"$ace_root/frameworks/core/components_ng/layout/layout_wrapper_builder.cpp",
# components_ng_property
"$ace_root/frameworks/core/components_ng/property/grid_property.cpp",
# components_ng_pattern
"$ace_root/frameworks/core/components_ng/pattern/grid_container/grid_container_layout_property.cpp",
# components_ng_event
"$ace_root/frameworks/core/components_ng/event/click_event.cpp",
"$ace_root/frameworks/core/components_ng/event/drag_event.cpp",
"$ace_root/frameworks/core/components_ng/event/gesture_event_hub.cpp",
"$ace_root/frameworks/core/components_ng/event/input_event.cpp",
"$ace_root/frameworks/core/components_ng/event/input_event_hub.cpp",
"$ace_root/frameworks/core/components_ng/event/pan_event.cpp",
# components_ng_gestures
"$ace_root/frameworks/core/components_ng/gestures/gesture_referee.cpp",
"$ace_root/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.cpp",
# mock
"$ace_root/frameworks/base/test/mock/mock_animatable_dimension.cpp",
"$ace_root/frameworks/base/test/mock/mock_system_properties.cpp",
"$ace_root/frameworks/core/animation/test/mock/mock_animator.cpp",
"$ace_root/frameworks/core/common/test/mock/mock_ace_application_info.cpp",
"$ace_root/frameworks/core/components_ng/test/event/mock/mock_touch_event.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/animation/mock_geometry_transition.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/base/mock_dump_log.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/base/mock_localization.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/base/mock_view_stack_processor.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/event/mock_focus_hub.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/gesture/recognizers/mock_click_recognizer.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/gesture/recognizers/mock_exclusive_recognizer.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/gesture/recognizers/mock_pan_recognizer.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/gesture/recognizers/mock_parallel_recognizer.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/gesture/recognizers/mock_recognizer_group.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/image_provider/mock_image_loading_context.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/image_provider/mock_image_painter.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/image_provider/mock_image_source_info.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/pattern/button/mock_button_layout_algorithm.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/pattern/button/mock_button_pattern.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/pattern/flex/mock_flex_layout_algorithm.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/pattern/list/mock_list_accessibility_property.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/pattern/list/mock_list_event_hub.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/pattern/list/mock_list_paint_method.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/pattern/list/mock_list_pattern.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/pattern/scrollable/mock_scrollable_pattern.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/pattern/text/mock_text_pattern.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/render/mock_animation_utils.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/render/mock_modifier_adapter.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/render/mock_render_context.cpp",
"$ace_root/frameworks/core/components_ng/test/mock/render/mock_render_context_creator.cpp",
"$ace_root/frameworks/core/components_ng/test/pattern/image/mock_icon_theme.cpp",
"$ace_root/frameworks/core/components_ng/test/pattern/text/mock/mock_text_layout_adapter.cpp",
"$ace_root/frameworks/core/components_ng/test/pattern/text/mock/mock_txt_font_collection.cpp",
"$ace_root/frameworks/core/components_ng/test/pattern/text/mock/mock_txt_paragraph.cpp",
"$ace_root/frameworks/core/pipeline_ng/test/mock/mock_element_register.cpp",
"$ace_root/frameworks/core/pipeline_ng/test/mock/mock_pipeline_base.cpp",
"$ace_root/frameworks/core/pipeline_ng/test/mock/mock_pipeline_context.cpp",
"$ace_root/test/mock/core/common/mock_container.cpp",
"$ace_root/test/unittest/core/pipeline/mock_overlay_manager.cpp",
# self
"custom_dialog_test_ng.cpp",
]
deps = [
"$ace_flutter_engine_root:third_party_flutter_engine_ohos",
"$ace_flutter_engine_root/skia:ace_skia_ohos",
"$ace_graphic/rosen/modules/2d_graphics:2d_graphics",
"$ace_graphic/rosen/modules/render_service_client:librender_service_client",
"$cjson_root:cjson",
"//third_party/googletest:gmock_main",
]
external_deps = [
"hitrace_native:hitrace_meter",
"hiviewdfx_hilog_native:libhilog",
]
configs = [
"$ace_root:ace_config",
"$ace_root:ace_test_config",
"$ace_flutter_engine_root:flutter_config",
"$ace_flutter_engine_root/skia:skia_config",
]
}

View File

@ -0,0 +1,174 @@
/*
* Copyright (c) 2023 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 <optional>
#include "gtest/gtest.h"
#include "core/components_ng/pattern/overlay/overlay_manager.h"
#include "core/components_ng/test/mock/theme/mock_theme_manager.h"
#include "core/components_v2/inspector/inspector_constants.h"
#include "core/pipeline_ng/test/mock/mock_pipeline_base.h"
#define private public
#define protected public
#include "core/components_ng/pattern/dialog/dialog_pattern.h"
#include "core/components_ng/pattern/dialog/dialog_view.h"
#undef private
#undef protected
using namespace testing;
using namespace testing::ext;
namespace OHOS::Ace::NG {
class CustomDialogTestNg : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
void CustomDialogTestNg::SetUpTestCase() {}
void CustomDialogTestNg::TearDownTestCase() {}
void CustomDialogTestNg::SetUp()
{
MockPipelineBase::SetUp();
}
void CustomDialogTestNg::TearDown()
{
MockPipelineBase::TearDown();
}
/**
* @tc.name: CustomDialogTestNg001
* @tc.desc: Verify function CreateDialogNode
* @tc.type: FUNC
*/
HWTEST_F(CustomDialogTestNg, CustomDialogTestNg001, TestSize.Level1)
{
DialogProperties param;
param.maskColor = Color::BLACK;
auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
MockPipelineBase::GetCurrent()->SetThemeManager(themeManager);
EXPECT_CALL(*themeManager, GetTheme(_)).WillOnce(Return(AceType::MakeRefPtr<DialogTheme>()));
auto result = DialogView::CreateDialogNode(param, nullptr);
EXPECT_TRUE(result);
if (result) {
EXPECT_EQ(result->GetRenderContext()->GetBackgroundColorValue(Color::TRANSPARENT).GetValue(),
Color::BLACK.GetValue());
}
}
/**
* @tc.name: CustomDialogTestNg002
* @tc.desc: Verify function CreateDialogNode
* @tc.type: FUNC
*/
HWTEST_F(CustomDialogTestNg, CustomDialogTestNg002, TestSize.Level1)
{
DialogProperties param;
param.maskColor = Color::BLACK;
param.type = DialogType::ALERT_DIALOG;
auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
MockPipelineBase::GetCurrent()->SetThemeManager(themeManager);
EXPECT_CALL(*themeManager, GetTheme(_)).WillOnce(Return(AceType::MakeRefPtr<DialogTheme>()));
auto result = DialogView::CreateDialogNode(param, nullptr);
EXPECT_TRUE(result);
if (result) {
EXPECT_EQ(result->GetRenderContext()->GetBackgroundColorValue(Color::TRANSPARENT).GetValue(),
Color::BLACK.GetValue());
}
}
/**
* @tc.name: CustomDialogTestNg003
* @tc.desc: Verify function CreateDialogNode
* @tc.type: FUNC
*/
HWTEST_F(CustomDialogTestNg, CustomDialogTestNg003, TestSize.Level1)
{
DialogProperties param;
param.maskColor = Color::BLACK;
param.type = DialogType::ACTION_SHEET;
auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
MockPipelineBase::GetCurrent()->SetThemeManager(themeManager);
EXPECT_CALL(*themeManager, GetTheme(_)).WillOnce(Return(AceType::MakeRefPtr<DialogTheme>()));
auto result = DialogView::CreateDialogNode(param, nullptr);
EXPECT_TRUE(result);
if (result) {
EXPECT_EQ(result->GetRenderContext()->GetBackgroundColorValue(Color::TRANSPARENT).GetValue(),
Color::BLACK.GetValue());
}
}
/**
* @tc.name: CustomDialogTestNg004
* @tc.desc: Verify function OpenAnimation and GetOpenAnimation
* @tc.type: FUNC
*/
HWTEST_F(CustomDialogTestNg, CustomDialogTestNg004, TestSize.Level1)
{
DialogProperties param;
AnimationOption animationOption;
animationOption.SetDelay(10);
param.openAnimation = animationOption;
auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
MockPipelineBase::GetCurrent()->SetThemeManager(themeManager);
EXPECT_CALL(*themeManager, GetTheme(_)).WillOnce(Return(AceType::MakeRefPtr<DialogTheme>()));
auto result = DialogView::CreateDialogNode(param, nullptr);
EXPECT_TRUE(result);
if (!result) {
return;
}
auto dialogPattern = result->GetPattern<DialogPattern>();
EXPECT_TRUE(dialogPattern);
if (!dialogPattern) {
return;
}
if (dialogPattern->GetOpenAnimation().has_value()) {
EXPECT_EQ(dialogPattern->GetOpenAnimation().value().GetDelay(), animationOption.GetDelay());
}
}
/**
* @tc.name: CustomDialogTestNg005
* @tc.desc: Verify function SetCloseAnimation and GetCloseAnimation
* @tc.type: FUNC
*/
HWTEST_F(CustomDialogTestNg, CustomDialogTestNg005, TestSize.Level1)
{
DialogProperties param;
AnimationOption animationOption;
animationOption.SetDelay(10);
param.openAnimation = animationOption;
auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
MockPipelineBase::GetCurrent()->SetThemeManager(themeManager);
EXPECT_CALL(*themeManager, GetTheme(_)).WillOnce(Return(AceType::MakeRefPtr<DialogTheme>()));
auto result = DialogView::CreateDialogNode(param, nullptr);
EXPECT_TRUE(result);
if (!result) {
return;
}
auto dialogPattern = result->GetPattern<DialogPattern>();
EXPECT_TRUE(dialogPattern);
if (!dialogPattern) {
return;
}
if (dialogPattern->GetCloseAnimation().has_value()) {
EXPECT_EQ(dialogPattern->GetCloseAnimation().value().GetDelay(), animationOption.GetDelay());
}
}
} // namespace OHOS::Ace::NG