1 /*
2  * Copyright (c) 2022-2023 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 <type_traits>
17 #include "gtest/gtest.h"
18 
19 #define private public
20 #define protected public
21 
22 #include "base/memory/ace_type.h"
23 #include "test/mock/base/mock_pixel_map.h"
24 #include "test/mock/core/common/mock_container.h"
25 #include "test/mock/core/common/mock_theme_manager.h"
26 #include "test/mock/core/pipeline/mock_pipeline_context.h"
27 #include "test/mock/core/render/mock_render_context.h"
28 #include "test/mock/core/rosen/mock_canvas.h"
29 #include "test/mock/core/rosen/testing_canvas.h"
30 
31 #include "core/components/common/layout/constants.h"
32 #include "core/components/common/layout/grid_system_manager.h"
33 #include "core/components/common/properties/shadow_config.h"
34 #include "core/components/container_modal/container_modal_constants.h"
35 #include "core/components/select/select_theme.h"
36 #include "core/components/theme/shadow_theme.h"
37 #include "core/components_ng/base/view_stack_processor.h"
38 #include "core/components_ng/pattern/image/image_layout_property.h"
39 #include "core/components_ng/pattern/image/image_pattern.h"
40 #include "core/components_ng/pattern/menu/menu_item/menu_item_model_ng.h"
41 #include "core/components_ng/pattern/menu/menu_item/menu_item_pattern.h"
42 #include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_pattern.h"
43 #include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_view.h"
44 #include "core/components_ng/pattern/menu/menu_model_ng.h"
45 #include "core/components_ng/pattern/menu/menu_pattern.h"
46 #include "core/components_ng/pattern/menu/menu_theme.h"
47 #include "core/components_ng/pattern/menu/menu_view.h"
48 #include "core/components_ng/pattern/menu/multi_menu_layout_algorithm.h"
49 #include "core/components_ng/pattern/menu/preview/menu_preview_layout_algorithm.h"
50 #include "core/components_ng/pattern/menu/preview/menu_preview_pattern.h"
51 #include "core/components_ng/pattern/menu/sub_menu_layout_algorithm.h"
52 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
53 #include "core/components_ng/pattern/pattern.h"
54 #include "core/components_ng/pattern/root/root_pattern.h"
55 #include "core/components_ng/pattern/scroll/scroll_pattern.h"
56 #include "core/components_ng/pattern/text/text_layout_property.h"
57 #include "core/components_ng/pattern/text/text_pattern.h"
58 #include "core/components_ng/property/border_property.h"
59 #include "core/components_ng/property/measure_property.h"
60 #include "core/components_ng/syntax/lazy_for_each_model.h"
61 #include "core/components_ng/syntax/lazy_layout_wrapper_builder.h"
62 #include "core/event/touch_event.h"
63 
64 using namespace testing;
65 using namespace testing::ext;
66 using namespace OHOS::Ace::Framework;
67 
68 namespace OHOS::Ace::NG {
69 namespace {
70 const InspectorFilter filter;
71 constexpr int32_t TARGET_ID = 3;
72 constexpr MenuType TYPE = MenuType::MENU;
73 constexpr int32_t SELECTED_INDEX = 10;
74 constexpr float CURRENT_OFFSET = -0.5f;
75 const std::string EMPTY_TEXT = "";
76 const std::string TEXT_TAG = "text";
77 const std::string MENU_TAG = "menu";
78 const std::string MENU_ITEM_TEXT = "menuItem";
79 const std::string MENU_ITEM_GROUP_TEXT = "menuItemGroup";
80 const std::string MENU_TOUCH_EVENT_TYPE = "1";
81 const DirtySwapConfig configDirtySwap = { false, false, false, false, true, false };
82 const std::string IMAGE_SRC_URL = "file://data/data/com.example.test/res/example.svg";
83 
84 constexpr float FULL_SCREEN_WIDTH = 720.0f;
85 constexpr float FULL_SCREEN_HEIGHT = 1136.0f;
86 constexpr float TARGET_SIZE_WIDTH = 100.0f;
87 constexpr float TARGET_SIZE_HEIGHT = 100.0f;
88 constexpr float MENU_SIZE_WIDTH = 150.0f;
89 constexpr float MENU_SIZE_HEIGHT = 150.0f;
90 constexpr double MENU_OFFSET_X = 10.0;
91 constexpr double MENU_OFFSET_Y = 10.0;
92 constexpr float MENU_ITEM_SIZE_WIDTH = 100.0f;
93 constexpr float MENU_ITEM_SIZE_HEIGHT = 50.0f;
94 constexpr float GREATER_WINDOW_MENU_HEIGHT = 1190.0f;
95 constexpr float CONST_FLOAT_ZREO = 0.0f;
96 
97 constexpr float OFFSET_THIRD = 200.0f;
98 constexpr int NODEID = 1;
99 const SizeF FULL_SCREEN_SIZE(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
100 const Dimension CONTAINER_OUTER_RADIUS = 16.0_vp;
101 constexpr double DIP_SCALE = 1.5;
102 const std::vector<std::string> FONT_FAMILY_VALUE = {"cursive"};
103 const std::vector<SelectParam> CREATE_VALUE = { { "content1", "icon1" }, { "content2", "" },
104     { "", "icon3" }, { "", "" } };
105 const std::vector<SelectParam> CREATE_VALUE_NEW = { { "content1_new", "" }, { "", "icon4_new" },
106     { "", "" }, { "", "icon4_new" } };
107 const V2::ItemDivider ITEM_DIVIDER = { Dimension(5.f), Dimension(10), Dimension(20), Color(0x000000) };
108 } // namespace
109 class MenuTestNg : public testing::Test {
110 public:
111     static void SetUpTestCase();
112     static void TearDownTestCase();
113     void SetUp() override;
114     void TearDown() override;
115     void MockPipelineContextGetTheme();
116     void InitMenuTestNg();
117     void InitMenuItemTestNg();
118     PaintWrapper* GetPaintWrapper(RefPtr<MenuPaintProperty> paintProperty);
119     RefPtr<FrameNode> GetPreviewMenuWrapper(
120         SizeF itemSize = SizeF(0.0f, 0.0f), std::optional<MenuPreviewAnimationOptions> scaleOptions = std::nullopt);
121     RefPtr<FrameNode> menuFrameNode_;
122     RefPtr<MenuAccessibilityProperty> menuAccessibilityProperty_;
123     RefPtr<FrameNode> menuItemFrameNode_;
124     RefPtr<MenuItemPattern> menuItemPattern_;
125     RefPtr<MenuItemAccessibilityProperty> menuItemAccessibilityProperty_;
126 };
127 
SetUpTestCase()128 void MenuTestNg::SetUpTestCase() {}
129 
TearDownTestCase()130 void MenuTestNg::TearDownTestCase() {}
131 
SetUp()132 void MenuTestNg::SetUp()
133 {
134     MockPipelineContext::SetUp();
135     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
136     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
137     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<SelectTheme>()));
138     MockContainer::SetUp();
139 }
140 
TearDown()141 void MenuTestNg::TearDown()
142 {
143     MockPipelineContext::TearDown();
144     menuFrameNode_ = nullptr;
145     menuAccessibilityProperty_ = nullptr;
146     menuItemFrameNode_ = nullptr;
147     menuItemPattern_ = nullptr;
148     menuItemAccessibilityProperty_ = nullptr;
149     SystemProperties::SetDeviceType(DeviceType::PHONE);
150     ScreenSystemManager::GetInstance().dipScale_ = 1.0;
151     SystemProperties::orientation_ = DeviceOrientation::PORTRAIT;
152     MockContainer::TearDown();
153 }
154 
MockPipelineContextGetTheme()155 void MenuTestNg::MockPipelineContextGetTheme()
156 {
157     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
158     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
159     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
160         if (type == TextTheme::TypeId()) {
161             return AceType::MakeRefPtr<TextTheme>();
162         } else if (type == IconTheme::TypeId()) {
163             return AceType::MakeRefPtr<IconTheme>();
164         } else if (type == SelectTheme::TypeId()) {
165             return AceType::MakeRefPtr<SelectTheme>();
166         } else {
167             return AceType::MakeRefPtr<MenuTheme>();
168         }
169     });
170 }
171 
InitMenuTestNg()172 void MenuTestNg::InitMenuTestNg()
173 {
174     menuFrameNode_ = FrameNode::GetOrCreateFrameNode(V2::MENU_TAG, ViewStackProcessor::GetInstance()->ClaimNodeId(),
175         []() { return AceType::MakeRefPtr<MenuPattern>(TARGET_ID, "", TYPE); });
176     ASSERT_NE(menuFrameNode_, nullptr);
177 
178     menuAccessibilityProperty_ = menuFrameNode_->GetAccessibilityProperty<MenuAccessibilityProperty>();
179     ASSERT_NE(menuAccessibilityProperty_, nullptr);
180 }
181 
InitMenuItemTestNg()182 void MenuTestNg::InitMenuItemTestNg()
183 {
184     menuItemFrameNode_ = FrameNode::GetOrCreateFrameNode(V2::MENU_ITEM_ETS_TAG,
185         ViewStackProcessor::GetInstance()->ClaimNodeId(), []() { return AceType::MakeRefPtr<MenuItemPattern>(); });
186     ASSERT_NE(menuItemFrameNode_, nullptr);
187 
188     menuItemPattern_ = menuItemFrameNode_->GetPattern<MenuItemPattern>();
189     ASSERT_NE(menuItemPattern_, nullptr);
190 
191     menuItemAccessibilityProperty_ = menuItemFrameNode_->GetAccessibilityProperty<MenuItemAccessibilityProperty>();
192     ASSERT_NE(menuItemAccessibilityProperty_, nullptr);
193 }
194 
GetPaintWrapper(RefPtr<MenuPaintProperty> paintProperty)195 PaintWrapper* MenuTestNg::GetPaintWrapper(RefPtr<MenuPaintProperty> paintProperty)
196 {
197     WeakPtr<RenderContext> renderContext;
198     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
199     PaintWrapper* paintWrapper = new PaintWrapper(renderContext, geometryNode, paintProperty);
200     return paintWrapper;
201 }
202 
GetPreviewMenuWrapper(SizeF itemSize,std::optional<MenuPreviewAnimationOptions> scaleOptions)203 RefPtr<FrameNode> MenuTestNg::GetPreviewMenuWrapper(
204     SizeF itemSize, std::optional<MenuPreviewAnimationOptions> scaleOptions)
205 {
206     auto rootNode = FrameNode::CreateFrameNode(
207         V2::ROOT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<RootPattern>());
208     CHECK_NULL_RETURN(rootNode, nullptr);
209     auto targetNode = FrameNode::CreateFrameNode(
210         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
211     CHECK_NULL_RETURN(targetNode, nullptr);
212     auto textNode = FrameNode::CreateFrameNode(
213         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
214     CHECK_NULL_RETURN(textNode, nullptr);
215     if (!(LessOrEqual(itemSize.Width(), 0.0) || LessOrEqual(itemSize.Height(), 0.0))) {
216         auto itemGeometryNode = textNode->GetGeometryNode();
217         CHECK_NULL_RETURN(itemGeometryNode, nullptr);
218         itemGeometryNode->SetFrameSize(itemSize);
219     }
220     targetNode->MountToParent(rootNode);
221     MenuParam menuParam;
222     menuParam.type = MenuType::CONTEXT_MENU;
223     menuParam.previewMode = MenuPreviewMode::CUSTOM;
224     if (scaleOptions != std::nullopt) {
225         menuParam.previewAnimationOptions = scaleOptions.value();
226     }
227     auto customNode = FrameNode::CreateFrameNode(
228         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
229     CHECK_NULL_RETURN(customNode, nullptr);
230     auto customGeometryNode = customNode->GetGeometryNode();
231     CHECK_NULL_RETURN(customGeometryNode, nullptr);
232     customGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
233     auto menuWrapperNode =
234         MenuView::Create(textNode, targetNode->GetId(), V2::TEXT_ETS_TAG, menuParam, true, customNode);
235     return menuWrapperNode;
236 }
237 
238 /**
239  * @tc.name: PerformActionTest001
240  * @tc.desc: MenuItem Accessibility PerformAction test Select and ClearSelection.
241  * @tc.type: FUNC
242  */
243 HWTEST_F(MenuTestNg, PerformActionTest001, TestSize.Level1)
244 {
245     /**
246      * @tc.steps: step1. Create menu, get menu frameNode and pattern, set callback function.
247      * @tc.expected: FrameNode and pattern is not null, related function is called.
248      */
249     MenuItemProperties itemOption;
250     itemOption.content = "content";
251     MenuItemModelNG MneuItemModelInstance;
252     MneuItemModelInstance.Create(itemOption);
253     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
254     ASSERT_NE(frameNode, nullptr);
255     auto menuItemPattern = frameNode->GetPattern<MenuItemPattern>();
256     ASSERT_NE(menuItemPattern, nullptr);
257     auto menuItemEventHub = frameNode->GetEventHub<MenuItemEventHub>();
258     ASSERT_NE(menuItemEventHub, nullptr);
259     auto menuItemAccessibilityProperty = frameNode->GetAccessibilityProperty<MenuItemAccessibilityProperty>();
260     ASSERT_NE(menuItemAccessibilityProperty, nullptr);
261     menuItemPattern->SetAccessibilityAction();
262 
263     /**
264      * @tc.steps: step2. When selectedChangeEvent onChange and subBuilder is null, call the callback function in
265      *                   menuItemAccessibilityProperty.
266      * @tc.expected: Related function is called.
267      */
268     EXPECT_TRUE(menuItemAccessibilityProperty->ActActionSelect());
269 
270     /**
271      * @tc.steps: step3. When selectedChangeEvent onChange and subBuilder is not null, call the callback function in
272      *                   menuItemAccessibilityProperty.
273      * @tc.expected: Related function is called.
274      */
275     bool isSelected = false;
__anonf8e8e2060502(bool select) 276     auto changeEvent = [&isSelected](bool select) { isSelected = select; };
277     menuItemEventHub->SetSelectedChangeEvent(changeEvent);
278     menuItemEventHub->SetOnChange(changeEvent);
__anonf8e8e2060602() 279     auto subBuilder = []() {};
280     menuItemPattern->SetSubBuilder(subBuilder);
281     EXPECT_TRUE(menuItemAccessibilityProperty->ActActionSelect());
282 }
283 
284 /**
285  * @tc.name: PerformActionTest002
286  * @tc.desc: Menu Accessibility PerformAction test ScrollForward and ScrollBackward.
287  * @tc.type: FUNC
288  */
289 HWTEST_F(MenuTestNg, PerformActionTest002, TestSize.Level1)
290 {
291     /**
292      * @tc.steps: step1. Create menu, get menu frameNode and pattern, set callback function.
293      * @tc.expected: FrameNode and pattern is not null, related function is called.
294      */
295     MenuModelNG model;
296     model.Create();
297     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
298     ASSERT_NE(frameNode, nullptr);
299     auto menuPattern = frameNode->GetPattern<MenuPattern>();
300     ASSERT_NE(menuPattern, nullptr);
301     auto menuAccessibilityProperty = frameNode->GetAccessibilityProperty<MenuAccessibilityProperty>();
302     ASSERT_NE(menuAccessibilityProperty, nullptr);
303     menuPattern->SetAccessibilityAction();
304 
305     /**
306      * @tc.steps: step2. When firstChild is null, call the callback function in menuAccessibilityProperty.
307      * @tc.expected: Related function is called.
308      */
309     EXPECT_TRUE(menuAccessibilityProperty->ActActionScrollForward());
310     EXPECT_TRUE(menuAccessibilityProperty->ActActionScrollBackward());
311 
312     /**
313      * @tc.steps: step3. When firstChild is not null and firstChild tag is SCROLL_ETS_TAG, call the callback function in
314      *                   menuAccessibilityProperty.
315      * @tc.expected: Related function is called.
316      */
317     auto scrollPattern = AceType::MakeRefPtr<ScrollPattern>();
318     ASSERT_NE(scrollPattern, nullptr);
319     scrollPattern->SetAxis(Axis::VERTICAL);
320     scrollPattern->scrollableDistance_ = 1.0f;
321     auto scroll =
322         FrameNode::CreateFrameNode(V2::SCROLL_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), scrollPattern);
323     ASSERT_NE(scroll, nullptr);
324     scroll->MountToParent(frameNode, 0);
325     scroll->MarkModifyDone();
326     EXPECT_TRUE(menuAccessibilityProperty->ActActionScrollForward());
327     EXPECT_TRUE(menuAccessibilityProperty->ActActionScrollBackward());
328 
329     /**
330      * @tc.steps: step4. When firstChild is not null and firstChild tag is not SCROLL_ETS_TAG, call the callback
331      *                   function in menuAccessibilityProperty.
332      * @tc.expected: Related function is called.
333      */
334     auto textNode = FrameNode::CreateFrameNode(
335         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
336     ASSERT_NE(textNode, nullptr);
337     textNode->MountToParent(frameNode, 0);
338     textNode->MarkModifyDone();
339     EXPECT_TRUE(menuAccessibilityProperty->ActActionScrollForward());
340     EXPECT_TRUE(menuAccessibilityProperty->ActActionScrollBackward());
341 }
342 
343 /**
344  * @tc.name: PerformActionTest003
345  * @tc.desc: MenuItem Accessibility PerformAction test Select and ClearSelection.
346  * @tc.type: FUNC
347  */
348 HWTEST_F(MenuTestNg, PerformActionTest003, TestSize.Level1)
349 {
350     MenuItemProperties itemOption;
351     itemOption.content = "content";
352     MenuItemModelNG MneuItemModelInstance;
353     MneuItemModelInstance.Create(itemOption);
354     auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
355     ASSERT_NE(frameNode, nullptr);
356     auto menuItemPattern = frameNode->GetPattern<MenuItemPattern>();
357     ASSERT_NE(menuItemPattern, nullptr);
358     auto menuItemAccessibilityProperty = frameNode->GetAccessibilityProperty<MenuItemAccessibilityProperty>();
359     ASSERT_NE(menuItemAccessibilityProperty, nullptr);
360     bool isSelected = true;
361     menuItemPattern->isSelected_ = false;
362     menuItemPattern->MarkIsSelected(isSelected);
363     EXPECT_TRUE(menuItemAccessibilityProperty->ActActionSelect());
364 }
365 
366 /**
367  * @tc.name: MenuAccessibilityEventTestNg001
368  * @tc.desc: Test Click Event for Option of Menu.
369  */
370 HWTEST_F(MenuTestNg, MenuAccessibilityEventTestNg001, TestSize.Level1)
371 {
372     /**
373      * @tc.steps: step1. Create Option for Menu.
374      */
375     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::OPTION_ETS_TAG,
__anonf8e8e2060702() 376         ViewStackProcessor::GetInstance()->ClaimNodeId(), []() { return AceType::MakeRefPtr<OptionPattern>(0); });
377     ASSERT_NE(frameNode, nullptr);
378     auto optionPattern = frameNode->GetPattern<OptionPattern>();
379     ASSERT_NE(optionPattern, nullptr);
380 
381     /**
382      * @tc.steps: step2. set callback function.
383      */
384     int testIndex = SELECTED_INDEX;
__anonf8e8e2060802(int index) 385     auto selectFunc = [optionPattern, testIndex](int index) { optionPattern->index_ = testIndex; };
386     auto optionEventHub = frameNode->GetEventHub<OptionEventHub>();
387     optionEventHub->SetOnSelect(selectFunc);
388     optionPattern->RegisterOnClick();
389 
390     /**
391      * @tc.steps: step3. call callback function.
392      * @tc.expected: index_ is SELECTED_INDEX.
393      */
394     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
395     auto clickEventActuator = gestureHub->clickEventActuator_;
396     ASSERT_NE(clickEventActuator, nullptr);
397     auto event = clickEventActuator->GetClickEvent();
398     ASSERT_NE(event, nullptr);
399     GestureEvent gestureEvent;
400     event(gestureEvent);
401     EXPECT_EQ(optionPattern->index_, SELECTED_INDEX);
402 }
403 
404 /**
405  * @tc.name: DesktopMenuPattern001
406  * @tc.desc: Test MenuPattern onModifyDone, switch between DesktopMenu and regular menu.
407  */
408 HWTEST_F(MenuTestNg, DesktopMenuPattern001, TestSize.Level1)
409 {
410     MenuModelNG model;
411     model.Create();
412     auto menu1 = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
413     ASSERT_NE(menu1, nullptr);
414     model.Create();
415     auto menu2 = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
416     auto container = FrameNode::CreateFrameNode("", -1, AceType::MakeRefPtr<MenuPattern>(-1, "", MenuType::MENU));
417     auto mockScroll = FrameNode::CreateFrameNode("", -1, AceType::MakeRefPtr<Pattern>());
418     mockScroll->MountToParent(container);
419     menu1->MountToParent(mockScroll);
420     menu2->MountToParent(mockScroll);
421 
422     auto pattern1 = menu1->GetPattern<InnerMenuPattern>();
423     auto pattern2 = menu2->GetPattern<InnerMenuPattern>();
424     auto containerPattern = container->GetPattern<MenuPattern>();
425     containerPattern->OnModifyDone();
426     pattern1->OnModifyDone();
427     pattern2->OnModifyDone();
428     pattern1->BeforeCreateLayoutWrapper();
429     pattern2->BeforeCreateLayoutWrapper();
430     EXPECT_EQ(pattern1->type_, MenuType::DESKTOP_MENU);
431     EXPECT_EQ(pattern2->type_, MenuType::DESKTOP_MENU);
432     EXPECT_EQ(container->GetRenderContext()->GetBackShadow(), ShadowConfig::NoneShadow);
433 
434     mockScroll->RemoveChildAtIndex(1);
435     pattern1->OnModifyDone();
436     pattern1->BeforeCreateLayoutWrapper();
437     containerPattern->OnModifyDone();
438     EXPECT_EQ(pattern1->type_, MenuType::MULTI_MENU);
439     Shadow shadow;
440     pattern1->GetShadowFromTheme(ShadowStyle::OuterDefaultMD, shadow);
441     EXPECT_EQ(container->GetRenderContext()->GetBackShadow(), shadow);
442 }
443 
444 /**
445  * @tc.name: MenuAccessibilityPropertyIsScrollable001
446  * @tc.desc: Test menuAccessibilityProperty::IsScrollable
447  * @tc.type: FUNC
448  */
449 HWTEST_F(MenuTestNg, MenuAccessibilityPropertyIsScrollable001, TestSize.Level1)
450 {
451     InitMenuTestNg();
452     EXPECT_FALSE(menuAccessibilityProperty_->IsScrollable());
453 
454     auto scrollPattern = AceType::MakeRefPtr<ScrollPattern>();
455     ASSERT_NE(scrollPattern, nullptr);
456     scrollPattern->SetAxis(Axis::VERTICAL);
457     scrollPattern->scrollableDistance_ = 1.0f;
458     auto scroll =
459         FrameNode::CreateFrameNode(V2::SCROLL_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), scrollPattern);
460     ASSERT_NE(scroll, nullptr);
461     scroll->MountToParent(menuFrameNode_, 0);
462     scroll->MarkModifyDone();
463     EXPECT_TRUE(menuAccessibilityProperty_->IsScrollable());
464 
465     scrollPattern->SetAxis(Axis::NONE);
466     EXPECT_FALSE(menuAccessibilityProperty_->IsScrollable());
467     scrollPattern->scrollableDistance_ = 0.0f;
468     EXPECT_FALSE(menuAccessibilityProperty_->IsScrollable());
469     /**
470      * @tc.steps: step1. Create Menu and test firstchild not SCROLL.
471      */
472     RefPtr<FrameNode> menuNode =
473         FrameNode::GetOrCreateFrameNode(V2::MENU_TAG, ViewStackProcessor::GetInstance()->ClaimNodeId(),
__anonf8e8e2060902() 474             []() { return AceType::MakeRefPtr<MenuPattern>(TARGET_ID, "", TYPE); });
475     ASSERT_NE(menuNode, nullptr);
476     RefPtr<MenuAccessibilityProperty> menuAccessibility =
477         menuNode->GetAccessibilityProperty<MenuAccessibilityProperty>();
478     ASSERT_NE(menuAccessibility, nullptr);
479     auto textNode = FrameNode::CreateFrameNode(
480         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
481     ASSERT_NE(textNode, nullptr);
482     textNode->MountToParent(menuNode, 0);
483     EXPECT_FALSE(menuAccessibility->IsScrollable());
484 }
485 
486 /**
487  * @tc.name: MenuAccessibilityPropertyGetSupportAction001
488  * @tc.desc: Test MenuAccessibilityProperty::SetSpecificSupportAction
489  * @tc.type: FUNC
490  */
491 HWTEST_F(MenuTestNg, MenuAccessibilityPropertyGetSupportAction001, TestSize.Level1)
492 {
493     InitMenuTestNg();
494     auto scrollPattern = AceType::MakeRefPtr<ScrollPattern>();
495     ASSERT_NE(scrollPattern, nullptr);
496     scrollPattern->SetAxis(Axis::VERTICAL);
497     scrollPattern->scrollableDistance_ = 1.0f;
498     scrollPattern->currentOffset_ = CURRENT_OFFSET;
499     auto scroll =
500         FrameNode::CreateFrameNode(V2::SCROLL_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), scrollPattern);
501     ASSERT_NE(scroll, nullptr);
502     scroll->MountToParent(menuFrameNode_, 0);
503 
504     menuAccessibilityProperty_->ResetSupportAction();
505     std::unordered_set<AceAction> supportAceActions = menuAccessibilityProperty_->GetSupportAction();
506     uint64_t actions = 0, expectActions = 0;
507     expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_SCROLL_FORWARD);
508     expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_SCROLL_BACKWARD);
509     for (auto action : supportAceActions) {
510         actions |= 1UL << static_cast<uint32_t>(action);
511     }
512     EXPECT_EQ(actions, expectActions);
513     /**
514      * @tc.steps: step1. test IsAtTop and IsAtBottom.
515      */
516     scrollPattern->scrollableDistance_ = -1.0;
517     scrollPattern->currentOffset_ = 0.0f;
518     menuAccessibilityProperty_->SetSpecificSupportAction();
519     expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_SCROLL_FORWARD);
520     EXPECT_EQ(menuAccessibilityProperty_->supportActions_, expectActions);
521     expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_SCROLL_BACKWARD);
522     scrollPattern->SetAxis(Axis::NONE);
523     scrollPattern->scrollableDistance_ = 0.0f;
524     menuAccessibilityProperty_->SetSpecificSupportAction();
525     EXPECT_EQ(menuAccessibilityProperty_->supportActions_, expectActions);
526     /**
527      * @tc.steps: step2. Create Menu and test firstchild not SCROLL.
528      */
529     RefPtr<FrameNode> menuNode =
530         FrameNode::GetOrCreateFrameNode(V2::MENU_TAG, ViewStackProcessor::GetInstance()->ClaimNodeId(),
__anonf8e8e2060a02() 531             []() { return AceType::MakeRefPtr<MenuPattern>(TARGET_ID, "", TYPE); });
532     ASSERT_NE(menuNode, nullptr);
533     RefPtr<MenuAccessibilityProperty> menuAccessibility =
534         menuNode->GetAccessibilityProperty<MenuAccessibilityProperty>();
535     ASSERT_NE(menuAccessibility, nullptr);
536     menuAccessibility->SetSpecificSupportAction();
537     auto textNode = FrameNode::CreateFrameNode(
538         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
539     ASSERT_NE(textNode, nullptr);
540     textNode->MountToParent(menuNode, 0);
541     menuAccessibility->SetSpecificSupportAction();
542     EXPECT_EQ(menuAccessibility->supportActions_, (0));
543 }
544 
545 /**
546  * @tc.name: MenuLayoutPropertyTestNg001
547  * @tc.desc: Verify GetPositionOffset.
548  * @tc.type: FUNC
549  */
550 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg001, TestSize.Level1)
551 {
552     MenuLayoutProperty property;
553     EXPECT_FALSE(property.GetPositionOffset().has_value());
554     property.UpdatePositionOffset(OffsetF(25.0f, 30.0f));
555     ASSERT_TRUE(property.GetPositionOffset().has_value());
556     EXPECT_EQ(property.GetPositionOffset().value(), OffsetF(25.0f, 30.0f));
557 }
558 
559 /**
560  * @tc.name: MenuLayoutPropertyTestNg002
561  * @tc.desc: Verify GetTitle.
562  * @tc.type: FUNC
563  */
564 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg002, TestSize.Level1)
565 {
566     MenuLayoutProperty property;
567     EXPECT_FALSE(property.GetTitle().has_value());
568     property.UpdateTitle("title");
569     ASSERT_TRUE(property.GetTitle().has_value());
570     EXPECT_EQ(property.GetTitle().value(), "title");
571 }
572 
573 /**
574  * @tc.name: MenuLayoutPropertyTestNg003
575  * @tc.desc: Verify GetFontSize.
576  * @tc.type: FUNC
577  */
578 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg003, TestSize.Level1)
579 {
580     MenuLayoutProperty property;
581     EXPECT_FALSE(property.GetFontSize().has_value());
582     property.UpdateFontSize(Dimension(25.0f));
583     ASSERT_TRUE(property.GetFontSize().has_value());
584     EXPECT_EQ(property.GetFontSize().value(), Dimension(25.0f));
585 }
586 
587 /**
588  * @tc.name: MenuLayoutPropertyTestNg004
589  * @tc.desc: Verify GetFontColor.
590  * @tc.type: FUNC
591  */
592 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg004, TestSize.Level1)
593 {
594     MenuLayoutProperty property;
595     EXPECT_FALSE(property.GetFontColor().has_value());
596     property.UpdateFontColor(Color::RED);
597     ASSERT_TRUE(property.GetFontColor().has_value());
598     EXPECT_EQ(property.GetFontColor().value(), Color::RED);
599 }
600 
601 /**
602  * @tc.name: MenuLayoutPropertyTestNg005
603  * @tc.desc: Verify GetFontWeight.
604  * @tc.type: FUNC
605  */
606 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg005, TestSize.Level1)
607 {
608     MenuLayoutProperty property;
609     EXPECT_FALSE(property.GetFontWeight().has_value());
610     property.UpdateFontWeight(FontWeight::BOLD);
611     ASSERT_TRUE(property.GetFontWeight().has_value());
612     EXPECT_EQ(property.GetFontWeight().value(), FontWeight::BOLD);
613 }
614 
615 /**
616  * @tc.name: MenuLayoutPropertyTestNg006
617  * @tc.desc: Verify GetMenuOffset.
618  * @tc.type: FUNC
619  */
620 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg006, TestSize.Level1)
621 {
622     MenuLayoutProperty property;
623     EXPECT_FALSE(property.GetMenuOffset().has_value());
624     property.UpdateMenuOffset(OffsetF(25.0f, 30.0f));
625     ASSERT_TRUE(property.GetMenuOffset().has_value());
626     EXPECT_EQ(property.GetMenuOffset().value(), OffsetF(25.0f, 30.0f));
627 }
628 
629 /**
630  * @tc.name: MenuLayoutPropertyTestNg007
631  * @tc.desc: Verify Reset.
632  * @tc.type: FUNC
633  */
634 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg007, TestSize.Level1)
635 {
636     MenuLayoutProperty property;
637     property.UpdateMenuOffset(OffsetF(25.0f, 30.0f));
638     property.UpdatePositionOffset(OffsetF(25.0f, 30.0f));
639     property.UpdateTitle("title");
640     property.UpdateFontSize(Dimension(25.0f));
641     property.UpdateFontColor(Color::RED);
642     property.UpdateFontWeight(FontWeight::BOLD);
643     property.UpdateAlignType(MenuAlignType::START);
644     property.UpdateOffset(DimensionOffset(Dimension(0, DimensionUnit::VP), Dimension(0, DimensionUnit::VP)));
645     EXPECT_TRUE(property.GetMenuOffset().has_value());
646     EXPECT_TRUE(property.GetPositionOffset().has_value());
647     EXPECT_TRUE(property.GetTitle().has_value());
648     EXPECT_TRUE(property.GetFontSize().has_value());
649     EXPECT_TRUE(property.GetFontColor().has_value());
650     EXPECT_TRUE(property.GetFontWeight().has_value());
651     EXPECT_TRUE(property.GetAlignType().has_value());
652     EXPECT_TRUE(property.GetOffset().has_value());
653     property.Reset();
654     EXPECT_FALSE(property.GetMenuOffset().has_value());
655     EXPECT_FALSE(property.GetPositionOffset().has_value());
656     EXPECT_FALSE(property.GetTitle().has_value());
657     EXPECT_FALSE(property.GetFontSize().has_value());
658     EXPECT_FALSE(property.GetFontColor().has_value());
659     EXPECT_FALSE(property.GetFontWeight().has_value());
660     EXPECT_FALSE(property.GetAlignType().has_value());
661     EXPECT_FALSE(property.GetOffset().has_value());
662 }
663 
664 /**
665  * @tc.name: MenuLayoutPropertyTestNg008
666  * @tc.desc: Verify Clone.
667  * @tc.type: FUNC
668  */
669 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg008, TestSize.Level1)
670 {
671     MenuLayoutProperty property;
672     property.UpdateMenuOffset(OffsetF(25.0f, 30.0f));
673     property.UpdatePositionOffset(OffsetF(25.0f, 30.0f));
674     property.UpdateTitle("title");
675     property.UpdateFontSize(Dimension(25.0f));
676     property.UpdateFontColor(Color::RED);
677     property.UpdateFontWeight(FontWeight::BOLD);
678     property.UpdateAlignType(MenuAlignType::START);
679     property.UpdateOffset(DimensionOffset(Dimension(10.0, DimensionUnit::VP), Dimension(10.0, DimensionUnit::VP)));
680 
681     auto cloneProperty = AceType::DynamicCast<MenuLayoutProperty>(property.Clone());
682     ASSERT_NE(cloneProperty, nullptr);
683     EXPECT_EQ(property.GetMenuOffset().value(), cloneProperty->GetMenuOffset().value());
684     EXPECT_EQ(property.GetPositionOffset().value(), cloneProperty->GetPositionOffset().value());
685     EXPECT_EQ(property.GetTitle().value(), cloneProperty->GetTitle().value());
686     EXPECT_EQ(property.GetFontSize().value(), cloneProperty->GetFontSize().value());
687     EXPECT_EQ(property.GetFontColor().value(), cloneProperty->GetFontColor().value());
688     EXPECT_EQ(property.GetFontWeight().value(), cloneProperty->GetFontWeight().value());
689     EXPECT_EQ(property.GetAlignType().value(), cloneProperty->GetAlignType().value());
690     EXPECT_EQ(property.GetOffset().value(), cloneProperty->GetOffset().value());
691 }
692 
693 /**
694  * @tc.name: MenuLayoutPropertyTestNg009
695  * @tc.desc: Verify MenuLayoutProperty::ToJsonValue.
696  * @tc.type: FUNC
697  */
698 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg009, TestSize.Level1)
699 {
700     MenuLayoutProperty property;
701     property.UpdateMenuOffset(OffsetF(25.0f, 30.0f));
702     property.UpdatePositionOffset(OffsetF(25.0f, 30.0f));
703     property.UpdateTitle("title");
704     property.UpdateFontSize(Dimension(25.0f));
705     property.UpdateFontColor(Color::RED);
706     property.UpdateFontWeight(FontWeight::BOLD);
707     property.UpdateItemDivider(ITEM_DIVIDER);
708     property.UpdateItemGroupDivider(ITEM_DIVIDER);
709     property.UpdateExpandingMode(SubMenuExpandingMode::EMBEDDED);
710 
711     auto json = JsonUtil::Create(true);
712     property.ToJsonValue(json, filter);
713     auto fontJsonObject = json->GetObject("font");
714     EXPECT_EQ(json->GetString("title"), "title");
715     EXPECT_EQ(json->GetString("offset"), OffsetF(25.0f, 30.0f).ToString());
716     EXPECT_EQ(json->GetString("fontSize"), Dimension(25.0f).ToString());
717     EXPECT_EQ(json->GetString("fontColor"), Color::RED.ColorToString());
718     EXPECT_EQ(fontJsonObject->GetString("weight"), V2::ConvertWrapFontWeightToStirng(FontWeight::BOLD));
719     property.UpdateExpandingMode(SubMenuExpandingMode::STACK);
720     property.ToJsonValue(json, filter);
721     EXPECT_EQ(json->GetString("title"), "title");
722     EXPECT_EQ(json->GetString("offset"), OffsetF(25.0f, 30.0f).ToString());
723     EXPECT_EQ(json->GetString("fontSize"), Dimension(25.0f).ToString());
724     EXPECT_EQ(json->GetString("fontColor"), Color::RED.ColorToString());
725     EXPECT_EQ(fontJsonObject->GetString("weight"), V2::ConvertWrapFontWeightToStirng(FontWeight::BOLD));
726 }
727 
728 /**
729  * @tc.name: MenuLayoutPropertyTestNg010
730  * @tc.desc: Verify ToJsonValue.
731  * @tc.type: FUNC
732  */
733 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg010, TestSize.Level1)
734 {
735     MockPipelineContextGetTheme();
736     std::vector<OptionParam> optionParams;
737     optionParams.emplace_back("MenuItem1", "fakeIcon", nullptr);
738     optionParams.emplace_back("MenuItem2", "", nullptr);
739     MenuParam menuParam;
740     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
741     ASSERT_NE(menuWrapperNode, nullptr);
742     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
743     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
744     ASSERT_NE(menuNode, nullptr);
745     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
746     ASSERT_NE(property, nullptr);
747 
748     auto json = JsonUtil::Create(true);
749     property->ToJsonValue(json, filter);
750     auto itemArray = json->GetValue("bindMenu");
751     ASSERT_EQ(itemArray->GetArraySize(), 2u);
752     auto item1 = itemArray->GetArrayItem(0);
753     EXPECT_EQ(item1->GetString("value"), "MenuItem1");
754     EXPECT_EQ(item1->GetString("icon"), "fakeIcon");
755     auto item2 = itemArray->GetArrayItem(1);
756     EXPECT_EQ(item2->GetString("value"), "MenuItem2");
757     EXPECT_EQ(item2->GetString("icon"), "");
758 }
759 
760 /**
761  * @tc.name: MenuLayoutPropertyTestNg011
762  * @tc.desc: Verify SelectMenuAlignOption AlignType.
763  * @tc.type: FUNC
764  */
765 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg011, TestSize.Level1)
766 {
767     MenuLayoutProperty property;
768     EXPECT_FALSE(property.GetAlignType().has_value());
769     /**
770      * @tc.cases: case1. verify the alignType property.
771      */
772     property.UpdateAlignType(MenuAlignType::CENTER);
773     ASSERT_TRUE(property.GetAlignType().has_value());
774     EXPECT_EQ(property.GetAlignType().value(), MenuAlignType::CENTER);
775 }
776 
777 /**
778  * @tc.name: MenuLayoutPropertyTestNg012
779  * @tc.desc: Verify SelectMenuAlignOption Offset.
780  * @tc.type: FUNC
781  */
782 HWTEST_F(MenuTestNg, MenuLayoutPropertyTestNg012, TestSize.Level1)
783 {
784     MenuLayoutProperty property;
785     EXPECT_FALSE(property.GetOffset().has_value());
786     DimensionOffset offset(Dimension(MENU_OFFSET_X, DimensionUnit::VP), Dimension(MENU_OFFSET_Y, DimensionUnit::VP));
787     /**
788      * @tc.cases: case1. verify the offset property.
789      */
790     property.UpdateOffset(offset);
791     ASSERT_TRUE(property.GetOffset().has_value());
792     EXPECT_EQ(property.GetOffset().value(), offset);
793 }
794 
795 /**
796  * @tc.name: MenuViewTestNgCreate001
797  * @tc.desc: Verify Create.
798  * @tc.type: FUNC
799  */
800 HWTEST_F(MenuTestNg, MenuViewTestNgCreate001, TestSize.Level1)
801 {
802     MockPipelineContextGetTheme();
803     std::vector<OptionParam> optionParams;
804     optionParams.emplace_back("MenuItem1", "fakeIcon", nullptr);
805     optionParams.emplace_back("MenuItem2", "", nullptr);
806     MenuParam menuParam;
807     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
808     ASSERT_NE(menuWrapperNode, nullptr);
809     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
810     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
811     ASSERT_NE(menuNode, nullptr);
812     auto menuPattern = menuNode->GetPattern<MenuPattern>();
813     ASSERT_NE(menuPattern, nullptr);
814     ASSERT_EQ(menuPattern->GetOptions().size(), 2);
815 
816     auto firstOption = menuPattern->GetOptions()[0];
817     ASSERT_NE(firstOption, nullptr);
818     EXPECT_EQ(firstOption->GetTag(), V2::OPTION_ETS_TAG);
819     auto firstPattern = firstOption->GetPattern<OptionPattern>();
820     ASSERT_NE(firstPattern, nullptr);
821     EXPECT_EQ(firstPattern->GetText(), "MenuItem1");
822     EXPECT_EQ(firstPattern->GetIcon(), "fakeIcon");
823     auto secondOption = menuPattern->GetOptions()[1];
824     ASSERT_NE(secondOption, nullptr);
825     EXPECT_EQ(secondOption->GetTag(), V2::OPTION_ETS_TAG);
826     auto secondPattern = secondOption->GetPattern<OptionPattern>();
827     ASSERT_NE(secondPattern, nullptr);
828     EXPECT_EQ(secondPattern->GetText(), "MenuItem2");
829     EXPECT_EQ(secondPattern->GetIcon(), "");
830 }
831 
832 /**
833  * @tc.name: MenuViewTestNgCreate002
834  * @tc.desc: Verify Create.
835  * @tc.type: FUNC
836  */
837 HWTEST_F(MenuTestNg, MenuViewTestNgCreate002, TestSize.Level1)
838 {
839     MockPipelineContextGetTheme();
840     std::vector<OptionParam> optionParams;
841     optionParams.emplace_back("MenuItem1", "fakeIcon", nullptr);
842     optionParams.emplace_back("MenuItem2", "", nullptr);
843     MenuParam menuParam;
844     menuParam.title = "Title";
845     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
846     ASSERT_NE(menuWrapperNode, nullptr);
847     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
848     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
849     ASSERT_NE(menuNode, nullptr);
850     auto menuPattern = menuNode->GetPattern<MenuPattern>();
851     ASSERT_NE(menuPattern, nullptr);
852     menuPattern->OnModifyDone();
853     auto column = menuPattern->GetMenuColumn();
854     ASSERT_NE(column, nullptr);
855     auto children = column->GetChildren();
856     ASSERT_EQ(children.size(), 3);
857     auto titleChild = AceType::DynamicCast<FrameNode>(column->GetChildAtIndex(0));
858     ASSERT_NE(titleChild, nullptr);
859     EXPECT_EQ(titleChild->GetTag(), V2::TEXT_ETS_TAG);
860     auto textProperty = titleChild->GetLayoutProperty<TextLayoutProperty>();
861     ASSERT_NE(textProperty, nullptr);
862     EXPECT_TRUE(textProperty->GetContent().has_value());
863     EXPECT_EQ(textProperty->GetContent().value(), "Title");
864 }
865 
866 /**
867  * @tc.name: MenuViewTestNgCreate003
868  * @tc.desc: Verify Create.
869  * @tc.type: FUNC
870  */
871 HWTEST_F(MenuTestNg, MenuViewTestNgCreate003, TestSize.Level1)
872 {
873     auto textNode = FrameNode::CreateFrameNode(
874         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
875     ASSERT_NE(textNode, nullptr);
876     MenuParam menuParam;
877     menuParam.positionOffset = { 10.0f, 10.0f };
878     auto menuWrapperNode = MenuView::Create(textNode, TARGET_ID, "", menuParam);
879     ASSERT_NE(menuWrapperNode, nullptr);
880     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
881     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
882     ASSERT_NE(menuNode, nullptr);
883     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
884     ASSERT_NE(property, nullptr);
885     EXPECT_TRUE(property->GetPositionOffset().has_value());
886     EXPECT_EQ(property->GetPositionOffset().value(), OffsetF(10.0f, 10.0f));
887 }
888 
889 /**
890  * @tc.name: MenuViewTestNgCreate004
891  * @tc.desc: Verify Create SubMenu.
892  * @tc.type: FUNC
893  */
894 HWTEST_F(MenuTestNg, MenuViewTestNgCreate004, TestSize.Level1)
895 {
896     /**
897      * @tc.steps: step1: create custom node and menu node
898      * @tc.expected: menuNode not null
899      */
900     auto textNode = FrameNode::CreateFrameNode(
901         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
902     ASSERT_NE(textNode, nullptr);
903     MenuParam menuParam;
904     menuParam.positionOffset = { 10.0f, 10.0f };
905     menuParam.type = MenuType::SUB_MENU;
906     auto menuNode = MenuView::Create(textNode, TARGET_ID, "", menuParam);
907     ASSERT_NE(menuNode, nullptr);
908     /**
909      * @tc.steps: step2: get menuNode layoutProperty
910      * @tc.expected: layoutProperty as expected
911      */
912     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
913     ASSERT_NE(property, nullptr);
914     EXPECT_TRUE(property->GetPositionOffset().has_value());
915     EXPECT_EQ(property->GetPositionOffset().value(), OffsetF(10.0f, 10.0f));
916 }
917 
918 /**
919  * @tc.name: MenuViewTestNgSetFontSize001
920  * @tc.desc: Verify SetFontSize.
921  * @tc.type: FUNC
922  */
923 HWTEST_F(MenuTestNg, MenuViewTestNgSetFontSize001, TestSize.Level1)
924 {
925     MockPipelineContextGetTheme();
926     MenuModelNG MneuModelInstance;
927     std::vector<OptionParam> optionParams;
928     optionParams.emplace_back("MenuItem", "", nullptr);
929     MenuParam menuParam;
930     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
931     ASSERT_NE(menuWrapperNode, nullptr);
932     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
933     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
934     ASSERT_NE(menuNode, nullptr);
935     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
936     ASSERT_NE(property, nullptr);
937     ViewStackProcessor::GetInstance()->Push(menuNode);
938     MneuModelInstance.SetFontSize(Dimension(50.0));
939     ASSERT_TRUE(property->GetFontSize().has_value());
940     EXPECT_EQ(property->GetFontSize().value(), Dimension(50.0));
941     ViewStackProcessor::GetInstance()->Finish();
942 }
943 
944 /**
945  * @tc.name: MenuViewTestNgSetFontSize002
946  * @tc.desc: Verify SetFontSize.
947  * @tc.type: FUNC
948  */
949 HWTEST_F(MenuTestNg, MenuViewTestNgSetFontSize002, TestSize.Level1)
950 {
951     MockPipelineContextGetTheme();
952     MenuModelNG MneuModelInstance;
953     std::vector<OptionParam> optionParams;
954     optionParams.emplace_back("MenuItem", "", nullptr);
955     MenuParam menuParam;
956     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
957     ASSERT_NE(menuWrapperNode, nullptr);
958     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
959     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
960     ASSERT_NE(menuNode, nullptr);
961     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
962     ASSERT_NE(property, nullptr);
963     ViewStackProcessor::GetInstance()->Push(menuNode);
964     MneuModelInstance.SetFontSize(Dimension());
965     EXPECT_FALSE(property->GetFontSize().has_value());
966     ViewStackProcessor::GetInstance()->Finish();
967 }
968 
969 /**
970  * @tc.name: MenuViewTestNgSetFontSize003
971  * @tc.desc: Verify SetFontSize.
972  * @tc.type: FUNC
973  */
974 HWTEST_F(MenuTestNg, MenuViewTestNgSetFontSize003, TestSize.Level1)
975 {
976     MockPipelineContextGetTheme();
977     MenuModelNG MneuModelInstance;
978     std::vector<OptionParam> optionParams;
979     optionParams.emplace_back("MenuItem", "", nullptr);
980     MenuParam menuParam;
981     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
982     ASSERT_NE(menuWrapperNode, nullptr);
983     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
984     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
985     ASSERT_NE(menuNode, nullptr);
986     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
987     ASSERT_NE(property, nullptr);
988     MneuModelInstance.SetFontSize(Dimension(50.0));
989     ASSERT_FALSE(property->GetFontSize().has_value());
990 }
991 
992 /**
993  * @tc.name: MenuViewTestNgSetFontColor001
994  * @tc.desc: Verify SetFontColor.
995  * @tc.type: FUNC
996  */
997 HWTEST_F(MenuTestNg, MenuViewTestNgSetFontColor001, TestSize.Level1)
998 {
999     MockPipelineContextGetTheme();
1000     MenuModelNG MneuModelInstance;
1001     std::vector<OptionParam> optionParams;
1002     optionParams.emplace_back("MenuItem", "", nullptr);
1003     MenuParam menuParam;
1004     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
1005     ASSERT_NE(menuWrapperNode, nullptr);
1006     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
1007     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1008     ASSERT_NE(menuNode, nullptr);
1009     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
1010     ASSERT_NE(property, nullptr);
1011     ViewStackProcessor::GetInstance()->Push(menuNode);
1012     MneuModelInstance.SetFontColor(Color::RED);
1013     ASSERT_TRUE(property->GetFontColor().has_value());
1014     EXPECT_EQ(property->GetFontColor().value(), Color::RED);
1015     ViewStackProcessor::GetInstance()->Finish();
1016 }
1017 
1018 /**
1019  * @tc.name: MenuViewTestNgSetFontColor002
1020  * @tc.desc: Verify SetFontColor.
1021  * @tc.type: FUNC
1022  */
1023 HWTEST_F(MenuTestNg, MenuViewTestNgSetFontColor002, TestSize.Level1)
1024 {
1025     MockPipelineContextGetTheme();
1026     MenuModelNG MneuModelInstance;
1027     std::vector<OptionParam> optionParams;
1028     optionParams.emplace_back("MenuItem", "", nullptr);
1029     MenuParam menuParam;
1030     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
1031     ASSERT_NE(menuWrapperNode, nullptr);
1032     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
1033     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1034     ASSERT_NE(menuNode, nullptr);
1035     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
1036     ASSERT_NE(property, nullptr);
1037     MneuModelInstance.SetFontColor(Color::RED);
1038     ASSERT_FALSE(property->GetFontColor().has_value());
1039 }
1040 
1041 /**
1042  * @tc.name: MenuViewTestNgSetFontColor003
1043  * @tc.desc: Verify SetFontColor.
1044  * @tc.type: FUNC
1045  */
1046 HWTEST_F(MenuTestNg, MenuViewTestNgSetFontColor003, TestSize.Level1)
1047 {
1048     MockPipelineContextGetTheme();
1049     MenuModelNG MneuModelInstance;
1050     std::vector<OptionParam> optionParams;
1051     optionParams.emplace_back("MenuItem", "", nullptr);
1052     MenuParam menuParam;
1053     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
1054     ASSERT_NE(menuWrapperNode, nullptr);
1055     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
1056     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1057     ASSERT_NE(menuNode, nullptr);
1058     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
1059     ASSERT_NE(property, nullptr);
1060     ViewStackProcessor::GetInstance()->Push(menuNode);
1061     MneuModelInstance.SetFontColor(Color::RED);
1062     ASSERT_TRUE(property->GetFontColor().has_value());
1063     EXPECT_EQ(property->GetFontColor().value(), Color::RED);
1064     MneuModelInstance.SetFontColor(std::nullopt);
1065     ASSERT_FALSE(property->GetFontColor().has_value());
1066     ViewStackProcessor::GetInstance()->Finish();
1067 }
1068 
1069 /**
1070  * @tc.name: MenuViewTestNgSetFontWeight001
1071  * @tc.desc: Verify SetFontWeight.
1072  * @tc.type: FUNC
1073  */
1074 HWTEST_F(MenuTestNg, MenuViewTestNgSetFontWeight001, TestSize.Level1)
1075 {
1076     MockPipelineContextGetTheme();
1077     MenuModelNG MneuModelInstance;
1078     std::vector<OptionParam> optionParams;
1079     optionParams.emplace_back("MenuItem", "", nullptr);
1080     MenuParam menuParam;
1081     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
1082     ASSERT_NE(menuWrapperNode, nullptr);
1083     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
1084     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1085     ASSERT_NE(menuNode, nullptr);
1086     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
1087     ASSERT_NE(property, nullptr);
1088     ViewStackProcessor::GetInstance()->Push(menuNode);
1089     MneuModelInstance.SetFontWeight(FontWeight::BOLDER);
1090     ASSERT_TRUE(property->GetFontWeight().has_value());
1091     EXPECT_EQ(property->GetFontWeight().value(), FontWeight::BOLDER);
1092     ViewStackProcessor::GetInstance()->Finish();
1093 }
1094 
1095 /**
1096  * @tc.name: MenuViewTestNgSetFontWeight002
1097  * @tc.desc: Verify SetFontWeight.
1098  * @tc.type: FUNC
1099  */
1100 HWTEST_F(MenuTestNg, MenuViewTestNgSetFontWeight002, TestSize.Level1)
1101 {
1102     MockPipelineContextGetTheme();
1103     MenuModelNG MneuModelInstance;
1104     std::vector<OptionParam> optionParams;
1105     optionParams.emplace_back("MenuItem", "", nullptr);
1106     MenuParam menuParam;
1107     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
1108     ASSERT_NE(menuWrapperNode, nullptr);
1109     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
1110     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1111     ASSERT_NE(menuNode, nullptr);
1112     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
1113     ASSERT_NE(property, nullptr);
1114     MneuModelInstance.SetFontWeight(FontWeight::BOLDER);
1115     ASSERT_FALSE(property->GetFontWeight().has_value());
1116 }
1117 
1118 /**
1119  * @tc.name: MenuViewTestNgSetMenuPlacement001
1120  * @tc.desc: Verify SetMenuPlacement.
1121  * @tc.type: FUNC
1122  */
1123 HWTEST_F(MenuTestNg, MenuViewTestNgSetMenuPlacement001, TestSize.Level1)
1124 {
1125     /**
1126      * @tc.steps: step1. create menuWrapperNode with menuItems and set MenuPlacement to Placement::TOP
1127      * @tc.expected: step1. Get menuPlacement is Placement::TOP
1128      */
1129     MockPipelineContextGetTheme();
1130     std::vector<OptionParam> optionParams;
1131     optionParams.emplace_back("MenuItem", "", nullptr);
1132     MenuParam menuParam;
1133     menuParam.placement = OHOS::Ace::Placement::TOP;
1134     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
1135     ASSERT_NE(menuWrapperNode, nullptr);
1136     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
1137     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1138     ASSERT_NE(menuNode, nullptr);
1139     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
1140     ASSERT_NE(property, nullptr);
1141     EXPECT_TRUE(property->GetMenuPlacement().has_value());
1142     EXPECT_EQ(property->GetMenuPlacement().value(), OHOS::Ace::Placement::TOP);
1143 }
1144 
1145 /**
1146  * @tc.name: MenuViewTestNgSetMenuPlacement002
1147  * @tc.desc: Verify SetMenuPlacement.
1148  * @tc.type: FUNC
1149  */
1150 HWTEST_F(MenuTestNg, MenuViewTestNgSetMenuPlacement002, TestSize.Level1)
1151 {
1152     /**
1153      * @tc.steps: step1. create menuWrapperNode with custom node from a builder and set MenuPlacement to
1154      * Placement::BOTTOM
1155      * @tc.expected: step1. Get menuPlacement is Placement::BOTTOM
1156      */
1157     auto textNode = FrameNode::CreateFrameNode(
1158         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
1159     ASSERT_NE(textNode, nullptr);
1160     MenuParam menuParam;
1161     menuParam.placement = OHOS::Ace::Placement::BOTTOM;
1162     menuParam.type = TYPE;
1163     auto menuWrapperNode = MenuView::Create(textNode, TARGET_ID, "", menuParam);
1164     ASSERT_NE(menuWrapperNode, nullptr);
1165     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
1166     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1167     ASSERT_NE(menuNode, nullptr);
1168     auto property = menuNode->GetLayoutProperty<MenuLayoutProperty>();
1169     ASSERT_NE(property, nullptr);
1170     EXPECT_TRUE(property->GetMenuPlacement().has_value());
1171     EXPECT_EQ(property->GetMenuPlacement().value(), OHOS::Ace::Placement::BOTTOM);
1172 }
1173 
1174 /**
1175  * @tc.name: MenuPaintMethodTestNg001
1176  * @tc.desc: Verify MenuPaintMethod::GetOverlayDrawFunction.
1177  * @tc.type: FUNC
1178  */
1179 HWTEST_F(MenuTestNg, MenuPaintMethodTestNg001, TestSize.Level1)
1180 {
1181     /**
1182      * @tc.steps: step1. prepare paint method object.
1183      */
1184     RefPtr<MenuPaintProperty> paintProp = AceType::MakeRefPtr<MenuPaintProperty>();
1185     RefPtr<MenuPaintMethod> paintMethod = AceType::MakeRefPtr<MenuPaintMethod>();
1186     PaintWrapper* paintWrapperNoMenu = GetPaintWrapper(paintProp);
1187     paintMethod->GetOverlayDrawFunction(paintWrapperNoMenu);
1188     delete paintWrapperNoMenu;
1189     paintWrapperNoMenu = nullptr;
1190     Testing::MockCanvas canvas;
1191     EXPECT_CALL(canvas, AttachBrush(_)).WillRepeatedly(ReturnRef(canvas));
1192     EXPECT_CALL(canvas, DrawPath(_)).Times(AtLeast(1));
1193     EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
1194     /**
1195      * @tc.steps: step2. update paint property and excute GetOverlayDrawFunction.
1196      * @tc.expected:  return value are as expected.
1197      */
1198     paintProp->UpdateEnableArrow(true);
1199     paintProp->UpdateArrowPosition(OffsetF(10.0f, 10.0f));
1200     Placement placements[] = { Placement::TOP, Placement::BOTTOM, Placement::RIGHT, Placement::LEFT };
1201     for (Placement placementValue : placements) {
1202         paintProp->UpdateArrowPlacement(placementValue);
1203         PaintWrapper* paintWrapper = GetPaintWrapper(paintProp);
1204         auto result = paintMethod->GetOverlayDrawFunction(paintWrapper);
1205         EXPECT_NE(result, nullptr);
1206         result(canvas);
1207         delete paintWrapper;
1208         paintWrapper = nullptr;
1209     }
1210     /**
1211      * @tc.steps: step3. update enableArrow to false.
1212      * @tc.expected:  return value are as expected.
1213      */
1214     paintProp->UpdateEnableArrow(false);
1215     PaintWrapper* paintWrapper = GetPaintWrapper(paintProp);
1216     auto result = paintMethod->GetOverlayDrawFunction(paintWrapper);
1217     EXPECT_NE(result, nullptr);
1218     result(canvas);
1219     delete paintWrapper;
1220     paintWrapper = nullptr;
1221 }
1222 
1223 /**
1224  * @tc.name: MenuPaintMethodTestNg002
1225  * @tc.desc: Verify MenuPaintMethod::UpdateArrowPath.
1226  * @tc.type: FUNC
1227  */
1228 HWTEST_F(MenuTestNg, MenuPaintMethodTestNg002, TestSize.Level1)
1229 {
1230     /**
1231      * @tc.steps: step1. prepare paint method object.
1232      */
1233     RefPtr<MenuPaintProperty> paintProp = AceType::MakeRefPtr<MenuPaintProperty>();
1234     RefPtr<MenuPaintMethod> paintMethod = AceType::MakeRefPtr<MenuPaintMethod>();
1235     PaintWrapper* paintWrapper = GetPaintWrapper(paintProp);
1236     /**
1237      * @tc.steps: step2. execute functions.
1238      * @tc.expected:  return value are as expected.
1239      */
1240     auto arrowX = 0.0;
1241     auto arrowY = 0.0;
1242     RSPath path;
1243     Placement placements[] = { Placement::TOP, Placement::TOP_RIGHT, Placement::BOTTOM_RIGHT, Placement::RIGHT_TOP,
1244         Placement::LEFT_TOP, Placement::NONE };
1245     for (Placement placementValue : placements) {
1246         paintMethod->UpdateArrowPath(placementValue, arrowX, arrowY, path);
1247     }
1248     auto result = paintMethod->GetOverlayDrawFunction(paintWrapper);
1249     EXPECT_NE(result, nullptr);
1250     delete paintWrapper;
1251     paintWrapper = nullptr;
1252 }
1253 
1254 /**
1255  * @tc.name: OnColorConfigurationUpdate001
1256  * @tc.desc: Test on color configuration update.
1257  * @tc.type: FUNC
1258  */
1259 HWTEST_F(MenuTestNg, OnColorConfigurationUpdate001, TestSize.Level1)
1260 {
1261     MenuModelNG MneuModelInstance;
1262     MenuItemModelNG MneuItemModelInstance;
1263     MneuModelInstance.Create();
1264     auto menuNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1265     ASSERT_NE(menuNode, nullptr);
1266     auto menuPattern = menuNode->GetPattern<MenuPattern>();
1267     ASSERT_NE(menuPattern, nullptr);
1268     auto pipeline = PipelineBase::GetCurrentContext();
1269     CHECK_NULL_VOID(pipeline);
1270     auto menuTheme = pipeline->GetTheme<SelectTheme>();
1271     CHECK_NULL_VOID(menuTheme);
1272     menuTheme->backgroundColor_ = Color::BLACK;
1273     menuPattern->OnColorConfigurationUpdate();
1274     auto renderContext = menuNode->GetRenderContext();
1275     EXPECT_EQ(renderContext->GetBackgroundColor(), Color::BLACK);
1276 }
1277 
1278 /**
1279  * @tc.name: MenuPaintPropertyTestNg001
1280  * @tc.desc: Verify GetEnableArrow.
1281  * @tc.type: FUNC
1282  */
1283 HWTEST_F(MenuTestNg, MenuPaintPropertyTestNg001, TestSize.Level1)
1284 {
1285     /**
1286      * @tc.steps: step1. Build a object MenuPaintProperty.
1287      * @tc.expected: enableArrow has not value.
1288      */
1289     MenuPaintProperty property;
1290     EXPECT_FALSE(property.GetEnableArrow().has_value());
1291     /**
1292      * @tc.steps: step2. update enableArrow
1293      * @tc.expected: enableArrow value are as expected.
1294      */
1295     property.UpdateEnableArrow(true);
1296     ASSERT_TRUE(property.GetEnableArrow().has_value());
1297     EXPECT_TRUE(property.GetEnableArrow().value());
1298 }
1299 
1300 /**
1301  * @tc.name: MenuPaintPropertyTestNg002
1302  * @tc.desc: Verify GetArrowOffset.
1303  * @tc.type: FUNC
1304  */
1305 HWTEST_F(MenuTestNg, MenuPaintPropertyTestNg002, TestSize.Level1)
1306 {
1307     /**
1308      * @tc.steps: step1. Build a object MenuPaintProperty.
1309      * @tc.expected: arrowOffset has not value.
1310      */
1311     MenuPaintProperty property;
1312     EXPECT_FALSE(property.GetArrowOffset().has_value());
1313     /**
1314      * @tc.steps: step2. update arrowOffset
1315      * @tc.expected: arrowOffset value are as expected.
1316      */
1317     property.UpdateArrowOffset(Dimension(10.0f));
1318     ASSERT_TRUE(property.GetArrowOffset().has_value());
1319     EXPECT_EQ(property.GetArrowOffset().value(), Dimension(10.0f));
1320 }
1321 
1322 /**
1323  * @tc.name: MenuPaintPropertyTestNg003
1324  * @tc.desc: Verify GetArrowPosition.
1325  * @tc.type: FUNC
1326  */
1327 HWTEST_F(MenuTestNg, MenuPaintPropertyTestNg003, TestSize.Level1)
1328 {
1329     /**
1330      * @tc.steps: step1. Build a object MenuPaintProperty.
1331      * @tc.expected: arrowPosition has not value.
1332      */
1333     MenuPaintProperty property;
1334     EXPECT_FALSE(property.GetArrowPosition().has_value());
1335     /**
1336      * @tc.steps: step2. update arrowPosition
1337      * @tc.expected: arrowPosition value are as expected.
1338      */
1339     property.UpdateArrowPosition(OffsetF(10.0f, 10.0f));
1340     ASSERT_TRUE(property.GetArrowPosition().has_value());
1341     EXPECT_EQ(property.GetArrowPosition().value(), OffsetF(10.0f, 10.0f));
1342 }
1343 
1344 /**
1345  * @tc.name: MenuPaintPropertyTestNg004
1346  * @tc.desc: Verify GetArrowPlacement.
1347  * @tc.type: FUNC
1348  */
1349 HWTEST_F(MenuTestNg, MenuPaintPropertyTestNg004, TestSize.Level1)
1350 {
1351     /**
1352      * @tc.steps: step1. Build a object MenuPaintProperty.
1353      * @tc.expected: arrowPlacement has not value.
1354      */
1355     MenuPaintProperty property;
1356     EXPECT_FALSE(property.GetArrowPlacement().has_value());
1357     /**
1358      * @tc.steps: step2. update arrowPlacement
1359      * @tc.expected: arrowPlacement value are as expected.
1360      */
1361     property.UpdateArrowPlacement(Placement::TOP);
1362     ASSERT_TRUE(property.GetArrowPlacement().has_value());
1363     EXPECT_EQ(property.GetArrowPlacement().value(), Placement::TOP);
1364 }
1365 
1366 /**
1367  * @tc.name: MenuPaintPropertyTestNg005
1368  * @tc.desc: Verify Reset.
1369  * @tc.type: FUNC
1370  */
1371 HWTEST_F(MenuTestNg, MenuPaintPropertyTestNg005, TestSize.Level1)
1372 {
1373     /**
1374      * @tc.steps: step1. Build a object MenuPaintProperty, update property
1375      * @tc.expected: property value are as expected.
1376      */
1377     MenuPaintProperty property;
1378     property.UpdateEnableArrow(true);
1379     property.UpdateArrowOffset(Dimension(10.0f));
1380     property.UpdateArrowPosition(OffsetF(10.0f, 10.0f));
1381     property.UpdateArrowPlacement(Placement::TOP);
1382     EXPECT_TRUE(property.GetEnableArrow().has_value());
1383     EXPECT_TRUE(property.GetArrowOffset().has_value());
1384     EXPECT_TRUE(property.GetArrowPosition().has_value());
1385     EXPECT_TRUE(property.GetArrowPlacement().has_value());
1386     /**
1387      * @tc.steps: step2. reset property
1388      * @tc.expected: property value are as expected.
1389      */
1390     property.Reset();
1391     EXPECT_FALSE(property.GetEnableArrow().has_value());
1392     EXPECT_FALSE(property.GetArrowOffset().has_value());
1393     EXPECT_FALSE(property.GetArrowPosition().has_value());
1394     EXPECT_FALSE(property.GetArrowPlacement().has_value());
1395 }
1396 
1397 /**
1398  * @tc.name: MenuPaintPropertyTestNg006
1399  * @tc.desc: Verify Clone.
1400  * @tc.type: FUNC
1401  */
1402 HWTEST_F(MenuTestNg, MenuPaintPropertyTestNg006, TestSize.Level1)
1403 {
1404     /**
1405      * @tc.steps: step1. Build a object MenuPaintProperty, update property
1406      */
1407     MenuPaintProperty property;
1408     property.UpdateEnableArrow(true);
1409     property.UpdateArrowOffset(Dimension(10.0f));
1410     property.UpdateArrowPosition(OffsetF(10.0f, 10.0f));
1411     property.UpdateArrowPlacement(Placement::TOP);
1412     /**
1413      * @tc.steps: step2. clone property
1414      * @tc.expected: property value are as expected.
1415      */
1416     auto cloneProperty = AceType::DynamicCast<MenuPaintProperty>(property.Clone());
1417     ASSERT_NE(cloneProperty, nullptr);
1418     EXPECT_EQ(property.GetEnableArrow().value(), cloneProperty->GetEnableArrow().value());
1419     EXPECT_EQ(property.GetArrowOffset().value(), cloneProperty->GetArrowOffset().value());
1420     EXPECT_EQ(property.GetArrowPosition().value(), cloneProperty->GetArrowPosition().value());
1421     EXPECT_EQ(property.GetArrowPlacement().value(), cloneProperty->GetArrowPlacement().value());
1422 }
1423 
1424 /**
1425  * @tc.name: MenuPaintPropertyTestNg007
1426  * @tc.desc: Verify ToJsonValue.
1427  * @tc.type: FUNC
1428  */
1429 HWTEST_F(MenuTestNg, MenuPaintPropertyTestNg007, TestSize.Level1)
1430 {
1431     /**
1432      * @tc.steps: step1. Build a object MenuPaintProperty, update property
1433      */
1434     MenuPaintProperty property;
1435     property.UpdateEnableArrow(true);
1436     property.UpdateArrowOffset(Dimension(10.0f));
1437     property.UpdateArrowPosition(OffsetF(10.0f, 10.0f));
1438     property.UpdateArrowPlacement(Placement::TOP);
1439     /**
1440      * @tc.steps: step2. property to json
1441      * @tc.expected: property jsonValue are as expected.
1442      */
1443     auto json = JsonUtil::Create(true);
1444     property.ToJsonValue(json, filter);
1445     EXPECT_EQ(json->GetString("enableArrow"), V2::ConvertBoolToString(true).c_str());
1446     EXPECT_EQ(json->GetString("arrowOffset"), Dimension(10.0f).ToString().c_str());
1447     EXPECT_EQ(json->GetString("arrowPosition"), OffsetF(10.0f, 10.0f).ToString().c_str());
1448     EXPECT_EQ(json->GetString("arrowPlacement"), property.ConvertPlacementToString(Placement::TOP).c_str());
1449 }
1450 
1451 /**
1452  * @tc.name: MenuPaintPropertyTestNg008
1453  * @tc.desc: Verify ToJsonValue default value.
1454  * @tc.type: FUNC
1455  */
1456 HWTEST_F(MenuTestNg, MenuPaintPropertyTestNg008, TestSize.Level1)
1457 {
1458     /**
1459      * @tc.steps: step1. Build a object MenuPaintProperty
1460      */
1461     MenuPaintProperty property;
1462     /**
1463      * @tc.steps: step2. property to json
1464      * @tc.expected: property jsonValue are as expected.
1465      */
1466     auto json = JsonUtil::Create(true);
1467     property.ToJsonValue(json, filter);
1468     EXPECT_EQ(json->GetString("enableArrow"), V2::ConvertBoolToString(false).c_str());
1469     EXPECT_EQ(json->GetString("arrowOffset"), Dimension(0.0, DimensionUnit::VP).ToString().c_str());
1470     EXPECT_EQ(json->GetString("arrowPosition"), OffsetF(0.0f, 0.0f).ToString().c_str());
1471     EXPECT_EQ(json->GetString("arrowPlacement"), property.ConvertPlacementToString(Placement::NONE).c_str());
1472 }
1473 
1474 /**
1475  * @tc.name: MenuPreviewPatternTestNg0100
1476  * @tc.desc: Test MenuPreviewPattern functions.
1477  * @tc.type: FUNC
1478  */
1479 HWTEST_F(MenuTestNg, MenuPreviewPatternTestNg0100, TestSize.Level1)
1480 {
1481     /**
1482      * @tc.steps: step1. create preview node, then set the initial properties
1483      * @tc.expected: preview node, preview pattern are not null
1484      */
1485     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1486     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1487     RefPtr<MenuTheme> menuTheme = AceType::MakeRefPtr<MenuTheme>();
1488     menuTheme->previewBorderRadius_ = CONTAINER_OUTER_RADIUS;
1489     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme));
1490     auto previewNode = FrameNode::CreateFrameNode(V2::MENU_PREVIEW_ETS_TAG,
1491         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<MenuPreviewPattern>());
1492     ASSERT_NE(previewNode, nullptr);
1493     auto menuWrapperNode = FrameNode::CreateFrameNode(V2::MENU_WRAPPER_ETS_TAG,
1494         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<MenuWrapperPattern>(1));
1495     ASSERT_NE(menuWrapperNode, nullptr);
1496     previewNode->MountToParent(menuWrapperNode);
1497     auto previewPattern = previewNode->GetPattern<MenuPreviewPattern>();
1498     ASSERT_NE(previewPattern, nullptr);
1499     const RefPtr<LayoutWrapperNode> layoutWrapper;
1500     previewPattern->isFirstShow_ = true;
1501 
1502     /**
1503      * @tc.steps: step2. call OnModifyDone and OnDirtyLayoutWrapperSwap
1504      * @tc.expected: borderRadius is CONTAINER_OUTER_RADIUS, isFirstShow_ is false and panEvent is not empty
1505      */
1506     previewPattern->OnModifyDone();
1507     previewPattern->OnDirtyLayoutWrapperSwap(layoutWrapper, configDirtySwap);
1508     auto renderContext = previewNode->GetRenderContext();
1509     ASSERT_NE(renderContext, nullptr);
1510     BorderRadiusProperty borderRadius;
1511     borderRadius.SetRadius(CONTAINER_OUTER_RADIUS);
1512     EXPECT_EQ(renderContext->GetBorderRadius().value(), borderRadius);
1513     EXPECT_FALSE(previewPattern->isFirstShow_);
1514     auto gestureHub = previewNode->GetOrCreateGestureEventHub();
1515     ASSERT_NE(gestureHub, nullptr);
1516     auto menuWrapperPattern = menuWrapperNode->GetPattern<MenuWrapperPattern>();
1517     ASSERT_NE(menuWrapperPattern, nullptr);
1518     menuWrapperPattern->SetMenuStatus(MenuStatus::SHOW);
1519     GestureEvent info;
1520     info.offsetY_ = 1.0;
1521 
1522     /**
1523      * @tc.steps: step3. call pan task
1524      * @tc.expected: menuWrapperPattern's IsHide() is false
1525      */
1526     EXPECT_FALSE(menuWrapperPattern->IsHide());
1527 
1528     /**
1529      * @tc.steps: step4. call SetFirstShow
1530      * @tc.expected: isFirstShow_ is true.
1531      */
1532     previewPattern->SetFirstShow();
1533     EXPECT_TRUE(previewPattern->isFirstShow_);
1534 }
1535 
1536 /**
1537  * @tc.name: MenuPatternTestNg0100
1538  * @tc.desc: Test MenuPattern functions.
1539  * @tc.type: FUNC
1540  */
1541 HWTEST_F(MenuTestNg, MenuPatternTestNg0100, TestSize.Level1)
1542 {
1543     /**
1544      * @tc.steps: step1. create menu node, then set the initial properties
1545      * @tc.expected: menu node, menu pattern are not null
1546      */
1547     MockPipelineContext::GetCurrent()->SetMinPlatformVersion(static_cast<int32_t>(PlatformVersion::VERSION_TWELVE));
1548     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1549     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1550     RefPtr<MenuTheme> menuTheme = AceType::MakeRefPtr<MenuTheme>();
1551     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme));
1552     auto menuNode = FrameNode::CreateFrameNode(V2::MENU_ETS_TAG,
1553         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<MenuPattern>(TARGET_ID, "", TYPE));
1554     ASSERT_NE(menuNode, nullptr);
1555     auto menuWrapperNode = FrameNode::CreateFrameNode(V2::MENU_WRAPPER_ETS_TAG,
1556         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<MenuWrapperPattern>(1));
1557     ASSERT_NE(menuWrapperNode, nullptr);
1558     menuNode->MountToParent(menuWrapperNode);
1559     auto menuPattern = menuNode->GetPattern<MenuPattern>();
1560     ASSERT_NE(menuPattern, nullptr);
1561     const RefPtr<LayoutWrapperNode> layoutWrapper;
1562     menuPattern->isMenuShow_ = true;
1563 
1564     /**
1565      * @tc.steps: step2. call OnModifyDone and OnDirtyLayoutWrapperSwap
1566      * @tc.expected: sMenuShow_ is false and panEvent is not empty
1567      */
1568     menuPattern->OnModifyDone();
1569     menuPattern->OnDirtyLayoutWrapperSwap(layoutWrapper, configDirtySwap);
1570     EXPECT_FALSE(menuPattern->isMenuShow_);
1571 
1572     /**
1573      * @tc.steps: step3. call SetMenuShow
1574      * @tc.expected: isMenuShow_ is true.
1575      */
1576     menuPattern->SetMenuShow();
1577     EXPECT_TRUE(menuPattern->isMenuShow_);
1578 }
1579 
1580 /**
1581  * @tc.name: WidthModifiedBySelectTestNg001
1582  * @tc.desc: Verify the usability of the select modified flag.
1583  * @tc.type: FUNC
1584  */
1585 HWTEST_F(MenuTestNg, WidthModifiedBySelectTestNg001, TestSize.Level1)
1586 {
1587     /**
1588      * @tc.steps: step1. Get menu pattern and set the flag.
1589      * @tc.expected: The flag should be setted successfully.
1590      */
1591     RefPtr<MenuPattern> menuPattern = AceType::MakeRefPtr<MenuPattern>(TARGET_ID, "", TYPE);
1592     menuPattern->SetIsWidthModifiedBySelect(true);
1593     EXPECT_TRUE(menuPattern->IsWidthModifiedBySelect());
1594 }
1595 
1596 /**
1597  * @tc.name: WidthModifiedBySelectTestNg002
1598  * @tc.desc: Verify the usability of the select menu default width property in the select pattern.
1599  * @tc.type: FUNC
1600  */
1601 HWTEST_F(MenuTestNg, WidthModifiedBySelectTestNg002, TestSize.Level1)
1602 {
1603     /**
1604      * @tc.steps: step1. Get the width of select menu without setting it, this case is meant to test the correctness
1605      * of its default value.
1606      * @tc.expected: Default width of select menu should be 0.0.
1607      */
1608     RefPtr<MenuPattern> menuPattern = AceType::MakeRefPtr<MenuPattern>(TARGET_ID, "", TYPE);
1609     auto menuWidth = menuPattern->GetSelectMenuWidth();
1610     ASSERT_NE(menuWidth, 0.0);
1611 }
1612 
1613 /**
1614  * @tc.name: WidthModifiedBySelectTestNg003
1615  * @tc.desc: Verify the usability of the select menu default width property in the select pattern.
1616  * @tc.type: FUNC
1617  */
1618 HWTEST_F(MenuTestNg, WidthModifiedBySelectTestNg003, TestSize.Level1)
1619 {
1620     /**
1621      * @tc.steps: step1. Get the width of select menu without setting it, this case is meant to test the correctness
1622      * of its default value.
1623      * @tc.expected: Default width of select menu should be 0.0.
1624      */
1625     RefPtr<MenuPattern> menuPattern = AceType::MakeRefPtr<MenuPattern>(TARGET_ID, "", TYPE);
1626     ASSERT_NE(menuPattern, nullptr);
1627     auto menuWidth = menuPattern->GetSelectMenuWidth();
1628     ASSERT_NE(menuWidth, 0.0);
1629     menuPattern->ShowMenuDisappearAnimation();
1630 }
1631 
1632 /**
1633  * @tc.name: WidthModifiedBySelectTestNg004
1634  * @tc.desc: Verify the usability of the select menu default width property in the select pattern.
1635  * @tc.type: FUNC
1636  */
1637 HWTEST_F(MenuTestNg, WidthModifiedBySelectTestNg004, TestSize.Level1)
1638 {
1639     /**
1640      * @tc.steps: step1. Get the width of select menu without setting it, this case is meant to test the correctness
1641      * of its default value.
1642      * @tc.expected: Default width of select menu should be 0.0.
1643      */
1644     int32_t setApiVersion = 12;
1645     int32_t rollbackApiVersion = MockContainer::Current()->GetApiTargetVersion();
1646     RefPtr<MenuPattern> menuPattern = AceType::MakeRefPtr<MenuPattern>(TARGET_ID, "", TYPE);
1647     ASSERT_NE(menuPattern, nullptr);
1648     auto menuWidth = menuPattern->GetSelectMenuWidth();
1649     ASSERT_NE(menuWidth, 0.0);
1650     MockContainer::Current()->SetApiTargetVersion(setApiVersion);
1651     menuPattern->ShowMenuDisappearAnimation();
1652     MockContainer::Current()->SetApiTargetVersion(rollbackApiVersion);
1653 }
1654 
1655 /**
1656  * @tc.name: WidthModifiedBySelectTestNg005
1657  * @tc.desc: Verify the usability of the select menu default width property in the select pattern.
1658  * @tc.type: FUNC
1659  */
1660 HWTEST_F(MenuTestNg, WidthModifiedBySelectTestNg005, TestSize.Level1)
1661 {
1662     /**
1663      * @tc.steps: step1. Get the width of select menu without setting it, this case is meant to test the correctness
1664      * of its default value.
1665      * @tc.expected: Default width of select menu should be 0.0.
1666      */
1667     int32_t setApiVersion = 12;
1668     int32_t rollbackApiVersion = MockContainer::Current()->GetApiTargetVersion();
1669     MockContainer::Current()->SetApiTargetVersion(setApiVersion);
1670     ScreenSystemManager::GetInstance().dipScale_ = DIP_SCALE;
1671     ScreenSystemManager::GetInstance().screenWidth_ = FULL_SCREEN_WIDTH;
1672     auto menuWrapperNode = GetPreviewMenuWrapper();
1673     ASSERT_NE(menuWrapperNode, nullptr);
1674     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1675     ASSERT_NE(menuNode, nullptr);
1676     auto menuAlgorithmWrapper = menuNode->GetLayoutAlgorithm();
1677     auto menuGeometryNode = menuNode->GetGeometryNode();
1678     ASSERT_NE(menuGeometryNode, nullptr);
1679     menuGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, GREATER_WINDOW_MENU_HEIGHT));
1680     auto previewNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(1));
1681     auto previewGeometryNode = previewNode->GetGeometryNode();
1682     ASSERT_NE(previewGeometryNode, nullptr);
1683     previewGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
1684     ASSERT_NE(menuAlgorithmWrapper, nullptr);
1685     auto menuAlgorithm = AceType::DynamicCast<MenuLayoutAlgorithm>(menuAlgorithmWrapper->GetLayoutAlgorithm());
1686     ASSERT_NE(menuAlgorithm, nullptr);
1687     auto menuPattern = menuNode->GetPattern<MenuPattern>();
1688     ASSERT_NE(menuPattern, nullptr);
1689 
1690     menuPattern->type_ = MenuType::SUB_MENU;
1691     menuWrapperNode->skipMeasureContent_ = false;
1692     menuPattern->SetMenuShow();
1693     menuPattern->ShowMenuAppearAnimation();
1694     EXPECT_FALSE(menuPattern->OnDirtyLayoutWrapperSwap(menuWrapperNode, configDirtySwap));
1695     MockContainer::Current()->SetApiTargetVersion(rollbackApiVersion);
1696 }
1697 
1698 /**
1699  * @tc.name: WidthModifiedBySelectTestNg006
1700  * @tc.desc: Verify the usability of the select menu default width property in the select pattern.
1701  * @tc.type: FUNC
1702  */
1703 HWTEST_F(MenuTestNg, WidthModifiedBySelectTestNg006, TestSize.Level1)
1704 {
1705     /**
1706      * @tc.steps: step1. Get the width of select menu without setting it, this case is meant to test the correctness
1707      * of its default value.
1708      * @tc.expected: Default width of select menu should be 0.0.
1709      */
1710     ScreenSystemManager::GetInstance().dipScale_ = DIP_SCALE;
1711     ScreenSystemManager::GetInstance().screenWidth_ = FULL_SCREEN_WIDTH;
1712     auto menuWrapperNode = GetPreviewMenuWrapper();
1713     ASSERT_NE(menuWrapperNode, nullptr);
1714     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1715     ASSERT_NE(menuNode, nullptr);
1716     auto menuAlgorithmWrapper = menuNode->GetLayoutAlgorithm();
1717     auto menuGeometryNode = menuNode->GetGeometryNode();
1718     ASSERT_NE(menuGeometryNode, nullptr);
1719     menuGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, GREATER_WINDOW_MENU_HEIGHT));
1720     auto previewNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(1));
1721     auto previewGeometryNode = previewNode->GetGeometryNode();
1722     ASSERT_NE(previewGeometryNode, nullptr);
1723     previewGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
1724     ASSERT_NE(menuAlgorithmWrapper, nullptr);
1725     auto menuAlgorithm = AceType::DynamicCast<MenuLayoutAlgorithm>(menuAlgorithmWrapper->GetLayoutAlgorithm());
1726     ASSERT_NE(menuAlgorithm, nullptr);
1727     auto menuPattern = menuNode->GetPattern<MenuPattern>();
1728     ASSERT_NE(menuPattern, nullptr);
1729 
1730     menuPattern->type_ = MenuType::SUB_MENU;
1731     menuWrapperNode->skipMeasureContent_ = false;
1732     menuPattern->SetMenuShow();
1733     menuPattern->ShowMenuAppearAnimation();
1734     EXPECT_FALSE(menuPattern->OnDirtyLayoutWrapperSwap(menuWrapperNode, configDirtySwap));
1735 }
1736 
1737 /**
1738  * @tc.name: WidthModifiedBySelectTestNg007
1739  * @tc.desc: Verify the usability of the select menu default width property in the select pattern.
1740  * @tc.type: FUNC
1741  */
1742 HWTEST_F(MenuTestNg, WidthModifiedBySelectTestNg007, TestSize.Level1)
1743 {
1744     /**
1745      * @tc.steps: step1. Get the width of select menu without setting it, this case is meant to test the correctness
1746      * of its default value.
1747      * @tc.expected: Default width of select menu should be 0.0.
1748      */
1749     int32_t setApiVersion = 12;
1750     int32_t rollbackApiVersion = MockContainer::Current()->GetApiTargetVersion();
1751     MockContainer::Current()->SetApiTargetVersion(setApiVersion);
1752     ScreenSystemManager::GetInstance().dipScale_ = DIP_SCALE;
1753     ScreenSystemManager::GetInstance().screenWidth_ = FULL_SCREEN_WIDTH;
1754     auto menuWrapperNode = GetPreviewMenuWrapper();
1755     ASSERT_NE(menuWrapperNode, nullptr);
1756     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1757     ASSERT_NE(menuNode, nullptr);
1758     auto menuAlgorithmWrapper = menuNode->GetLayoutAlgorithm();
1759     auto menuGeometryNode = menuNode->GetGeometryNode();
1760     ASSERT_NE(menuGeometryNode, nullptr);
1761     menuGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, GREATER_WINDOW_MENU_HEIGHT));
1762     auto previewNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(1));
1763     auto previewGeometryNode = previewNode->GetGeometryNode();
1764     ASSERT_NE(previewGeometryNode, nullptr);
1765     previewGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
1766     ASSERT_NE(menuAlgorithmWrapper, nullptr);
1767     auto menuAlgorithm = AceType::DynamicCast<MenuLayoutAlgorithm>(menuAlgorithmWrapper->GetLayoutAlgorithm());
1768     ASSERT_NE(menuAlgorithm, nullptr);
1769     auto menuPattern = menuNode->GetPattern<MenuPattern>();
1770     ASSERT_NE(menuPattern, nullptr);
1771 
1772     menuPattern->type_ = MenuType::SUB_MENU;
1773     menuWrapperNode->skipMeasureContent_ = false;
1774     EXPECT_FALSE(menuPattern->OnDirtyLayoutWrapperSwap(menuWrapperNode, configDirtySwap));
1775     menuPattern->SetMenuShow();
1776     auto rollbackPreviewMode = menuPattern->GetPreviewMode();
1777     menuPattern->SetPreviewMode(MenuPreviewMode::NONE);
1778     menuPattern->type_ = MenuType::SELECT_OVERLAY_EXTENSION_MENU;
1779     menuPattern->isExtensionMenuShow_ = false;
1780     menuPattern->ShowMenuAppearAnimation();
1781     menuPattern->SetPreviewMode(rollbackPreviewMode);
1782     MockContainer::Current()->SetApiTargetVersion(rollbackApiVersion);
1783 }
1784 
1785 /**
1786  * @tc.name: WidthModifiedBySelectTestNg008
1787  * @tc.desc: Verify the usability of the select menu default width property in the select pattern.
1788  * @tc.type: FUNC
1789  */
1790 HWTEST_F(MenuTestNg, WidthModifiedBySelectTestNg008, TestSize.Level1)
1791 {
1792     /**
1793      * @tc.steps: step1. Get the width of select menu without setting it, this case is meant to test the correctness
1794      * of its default value.
1795      * @tc.expected: Default width of select menu should be 0.0.
1796      */
1797     ScreenSystemManager::GetInstance().dipScale_ = DIP_SCALE;
1798     ScreenSystemManager::GetInstance().screenWidth_ = FULL_SCREEN_WIDTH;
1799     auto menuWrapperNode = GetPreviewMenuWrapper();
1800     ASSERT_NE(menuWrapperNode, nullptr);
1801     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1802     ASSERT_NE(menuNode, nullptr);
1803     auto menuAlgorithmWrapper = menuNode->GetLayoutAlgorithm();
1804     auto menuGeometryNode = menuNode->GetGeometryNode();
1805     ASSERT_NE(menuGeometryNode, nullptr);
1806     menuGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, GREATER_WINDOW_MENU_HEIGHT));
1807     auto previewNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(1));
1808     auto previewGeometryNode = previewNode->GetGeometryNode();
1809     ASSERT_NE(previewGeometryNode, nullptr);
1810     previewGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
1811     ASSERT_NE(menuAlgorithmWrapper, nullptr);
1812     auto menuAlgorithm = AceType::DynamicCast<MenuLayoutAlgorithm>(menuAlgorithmWrapper->GetLayoutAlgorithm());
1813     ASSERT_NE(menuAlgorithm, nullptr);
1814     auto menuPattern = menuNode->GetPattern<MenuPattern>();
1815     ASSERT_NE(menuPattern, nullptr);
1816 
1817     menuPattern->type_ = MenuType::SUB_MENU;
1818     menuWrapperNode->skipMeasureContent_ = false;
1819     menuPattern->SetPreviewMode(MenuPreviewMode::NONE);
1820     EXPECT_FALSE(menuPattern->OnDirtyLayoutWrapperSwap(menuWrapperNode, configDirtySwap));
1821     menuPattern->SetMenuShow();
1822     auto rollbackPreviewMode = menuPattern->GetPreviewMode();
1823     menuPattern->ShowMenuAppearAnimation();
1824     menuPattern->SetPreviewMode(rollbackPreviewMode);
1825 }
1826 
1827 /**
1828  * @tc.name: WidthModifiedBySelectTestNg009
1829  * @tc.desc: Verify the usability of the select menu default width property in the select pattern.
1830  * @tc.type: FUNC
1831  */
1832 HWTEST_F(MenuTestNg, WidthModifiedBySelectTestNg009, TestSize.Level1)
1833 {
1834     /**
1835      * @tc.steps: step1. Get the width of select menu without setting it, this case is meant to test the correctness
1836      * of its default value.
1837      * @tc.expected: Default width of select menu should be 0.0.
1838      */
1839     int32_t setApiVersion = 12;
1840     int32_t rollbackApiVersion = MockContainer::Current()->GetApiTargetVersion();
1841     MockContainer::Current()->SetApiTargetVersion(setApiVersion);
1842     ScreenSystemManager::GetInstance().dipScale_ = DIP_SCALE;
1843     ScreenSystemManager::GetInstance().screenWidth_ = FULL_SCREEN_WIDTH;
1844     auto menuWrapperNode = GetPreviewMenuWrapper();
1845     ASSERT_NE(menuWrapperNode, nullptr);
1846     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1847     ASSERT_NE(menuNode, nullptr);
1848     auto menuAlgorithmWrapper = menuNode->GetLayoutAlgorithm();
1849     auto menuGeometryNode = menuNode->GetGeometryNode();
1850     ASSERT_NE(menuGeometryNode, nullptr);
1851     menuGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, GREATER_WINDOW_MENU_HEIGHT));
1852     auto previewNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(1));
1853     auto previewGeometryNode = previewNode->GetGeometryNode();
1854     ASSERT_NE(previewGeometryNode, nullptr);
1855     previewGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
1856     ASSERT_NE(menuAlgorithmWrapper, nullptr);
1857     auto menuAlgorithm = AceType::DynamicCast<MenuLayoutAlgorithm>(menuAlgorithmWrapper->GetLayoutAlgorithm());
1858     ASSERT_NE(menuAlgorithm, nullptr);
1859     auto menuPattern = menuNode->GetPattern<MenuPattern>();
1860     ASSERT_NE(menuPattern, nullptr);
1861 
1862     menuPattern->type_ = MenuType::SUB_MENU;
1863     menuWrapperNode->skipMeasureContent_ = false;
1864     menuPattern->SetPreviewMode(MenuPreviewMode::NONE);
1865     EXPECT_FALSE(menuPattern->OnDirtyLayoutWrapperSwap(menuWrapperNode, configDirtySwap));
1866     menuPattern->SetMenuShow();
1867     auto rollbackPreviewMode = menuPattern->GetPreviewMode();
1868     menuPattern->type_ = MenuType::SELECT_OVERLAY_CUSTOM_MENU;
1869     menuPattern->ShowMenuAppearAnimation();
1870     menuPattern->SetPreviewMode(rollbackPreviewMode);
1871     MockContainer::Current()->SetApiTargetVersion(rollbackApiVersion);
1872     EXPECT_FALSE(menuPattern->isExtensionMenuShow_);
1873 }
1874 
1875 /**
1876  * @tc.name: MenuPreviewLayoutAlgorithmTestNg0100
1877  * @tc.desc: Test MenuPreviewLayoutAlgorithm Measure and Layout function.
1878  * @tc.type: FUNC
1879  */
1880 HWTEST_F(MenuTestNg, MenuPreviewLayoutAlgorithmTestNg0100, TestSize.Level1)
1881 {
1882     /**
1883      * @tc.steps: step1. create preview node and menuPreviewLayoutAlgorithm, then set the initial properties
1884      * @tc.expected: preview node, menuPreviewLayoutAlgorithm are not null
1885      */
1886     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1887     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1888     RefPtr<MenuTheme> menuTheme = AceType::MakeRefPtr<MenuTheme>();
1889     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme));
1890     auto previewNode = FrameNode::CreateFrameNode(V2::MENU_PREVIEW_ETS_TAG,
1891         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<MenuPreviewPattern>());
1892     auto previewPattern = previewNode->GetPattern<MenuPreviewPattern>();
1893     ASSERT_NE(previewPattern, nullptr);
1894     RefPtr<MenuPreviewLayoutAlgorithm> menuPreviewlayoutAlgorithm =
1895         AceType::DynamicCast<MenuPreviewLayoutAlgorithm>(previewPattern->CreateLayoutAlgorithm());
1896     ASSERT_NE(menuPreviewlayoutAlgorithm, nullptr);
1897     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1898     ASSERT_NE(geometryNode, nullptr);
1899     auto layoutProp = AceType::MakeRefPtr<LayoutProperty>();
1900     ASSERT_NE(layoutProp, nullptr);
1901     auto layoutWrapper = LayoutWrapperNode(previewNode, geometryNode, layoutProp);
1902     LayoutConstraintF parentLayoutConstraint;
1903     parentLayoutConstraint.maxSize = FULL_SCREEN_SIZE;
1904     parentLayoutConstraint.percentReference = FULL_SCREEN_SIZE;
1905     parentLayoutConstraint.selfIdealSize.SetSize(SizeF(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT));
1906     ASSERT_NE(layoutWrapper.GetLayoutProperty(), nullptr);
1907     layoutWrapper.GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
1908     layoutWrapper.GetLayoutProperty()->UpdateContentConstraint();
1909 
1910     /**
1911      * @tc.steps: step2. create menuPreviewLayoutAlgorithm Measure and Layout functions
1912      * @tc.expected: padding property is PREVIEW_INNER_SECURITY
1913      */
1914     menuPreviewlayoutAlgorithm->Measure(&layoutWrapper);
1915     menuPreviewlayoutAlgorithm->Layout(&layoutWrapper);
1916     PaddingProperty padding;
1917     ASSERT_NE(layoutProp, nullptr);
1918 }
1919 
1920 /**
1921  * @tc.name: MenuLayoutAlgorithmAPI11PaddingTest1
1922  * @tc.desc: Test MenuLayoutAlgorithm InitializePaddingAPI12 function.
1923  * @tc.type: FUNC
1924  */
1925 HWTEST_F(MenuTestNg, MenuLayoutAlgorithmAPI11PaddingTest1, TestSize.Level1)
1926 {
1927     /**
1928      * @tc.steps: step1. create menu item and submenu, set the layering parameter to false and call the
1929      * VerticalLayoutMenuHalfScreen method
1930      * @tc.expected: menu node, MenuLayoutAlgorithm are not null
1931      */
1932     auto itemPattern = AceType::MakeRefPtr<MenuItemPattern>();
1933 
1934     // create parent menu item
1935     auto item = AceType::MakeRefPtr<FrameNode>("MenuItem", -1, itemPattern);
1936     auto itemGeometryNode = item->GetGeometryNode();
1937     ASSERT_TRUE(itemGeometryNode);
1938     item->GetGeometryNode()->SetFrameSize(SizeF(MENU_ITEM_SIZE_WIDTH, MENU_ITEM_SIZE_HEIGHT));
1939     auto menuPattern = AceType::MakeRefPtr<MenuPattern>(-1, "", MenuType::SUB_MENU);
1940     auto Menu = AceType::MakeRefPtr<FrameNode>("", -1, menuPattern);
1941 
1942     // create MenuLayoutAlgorithm
1943     auto algorithm = AceType::DynamicCast<MenuLayoutAlgorithm>(menuPattern->CreateLayoutAlgorithm());
1944     ASSERT_TRUE(algorithm);
1945     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1946     geometryNode->SetFrameSize(SizeF(MENU_SIZE_WIDTH, MENU_SIZE_HEIGHT));
1947     auto layoutProp = AceType::MakeRefPtr<MenuLayoutProperty>();
1948     auto* wrapper = new LayoutWrapperNode(Menu, geometryNode, layoutProp);
1949 
1950     // link menuItem and menu
1951     ASSERT_TRUE(menuPattern);
1952     menuPattern->SetParentMenuItem(item);
1953     item->GetGeometryNode()->SetFrameOffset(OffsetF(MENU_OFFSET_X, MENU_OFFSET_Y));
1954     algorithm->wrapperSize_ = SizeF(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
1955     algorithm->wrapperRect_ = Rect(0, 0, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
1956     auto textNode = FrameNode::CreateFrameNode(
1957         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
1958     ASSERT_NE(textNode, nullptr);
1959     MenuParam menuParam;
1960     menuParam.type = TYPE;
1961     auto menuWrapperNode = MenuView::Create(textNode, TARGET_ID, "", menuParam);
1962     ASSERT_NE(menuWrapperNode, nullptr);
1963     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
1964     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
1965     ASSERT_NE(menuNode, nullptr);
1966     auto menuAlgorithmWrapper = menuNode->GetLayoutAlgorithm();
1967     auto menuGeometryNode = menuNode->GetGeometryNode();
1968     ASSERT_NE(menuGeometryNode, nullptr);
1969     menuGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
1970     SizeF size_f(100, 200);
1971     algorithm->wrapperSize_ = size_f;
1972     algorithm->wrapperRect_ = Rect(0, 0, size_f.Width(), size_f.Height());
1973 
1974     /**
1975      * @tc.steps: step2. call the ModifySubMenuWrapper method.
1976      * @tc.expected: wrapperSize_ is not Data anomalies
1977      */
1978     ASSERT_NE(algorithm->wrapperSize_, SizeF(0, 0));
1979     /**
1980      * @tc.steps: step3. call the InitializePaddingAPI12 method.
1981      * @tc.expected: padding is not zero
1982      */
1983     algorithm->canExpandCurrentWindow_ = true;
1984     auto selectTheme = MockPipelineContext::GetCurrent()->GetTheme<SelectTheme>();
1985     selectTheme->menuMediumMargin_ = 10.0_vp;
1986     algorithm->InitializePaddingAPI12(wrapper);
1987     ASSERT_EQ(algorithm->paddingStart_, 10.0f);
1988     ASSERT_EQ(algorithm->paddingEnd_, 10.0f);
1989     ASSERT_EQ(algorithm->paddingTop_, 0.0f);
1990     ASSERT_EQ(algorithm->paddingBottom_, 0.0f);
1991 }
1992 /**
1993  * @tc.name: MenuLayoutAlgorithmAPI11PaddingTest2
1994  * @tc.desc: Test MenuLayoutAlgorithm InitializePaddingAPI12 function.
1995  * @tc.type: FUNC
1996  */
1997 HWTEST_F(MenuTestNg, MenuLayoutAlgorithmAPI11PaddingTest2, TestSize.Level1)
1998 {
1999     /**
2000      * @tc.steps: step1. create menu item and submenu, set the layering parameter to false and call the
2001      * VerticalLayoutMenuHalfScreen method
2002      * @tc.expected: menu node, MenuLayoutAlgorithm are not null
2003      */
2004     auto itemPattern = AceType::MakeRefPtr<MenuItemPattern>();
2005     // create parent menu item
2006     auto item = AceType::MakeRefPtr<FrameNode>("MenuItem", -1, itemPattern);
2007     auto itemGeometryNode = item->GetGeometryNode();
2008     ASSERT_TRUE(itemGeometryNode);
2009     item->GetGeometryNode()->SetFrameSize(SizeF(MENU_ITEM_SIZE_WIDTH, MENU_ITEM_SIZE_HEIGHT));
2010     auto menuPattern = AceType::MakeRefPtr<MenuPattern>(-1, "", MenuType::SUB_MENU);
2011     auto Menu = AceType::MakeRefPtr<FrameNode>("", -1, menuPattern);
2012     // create MenuLayoutAlgorithm
2013     auto algorithm = AceType::DynamicCast<MenuLayoutAlgorithm>(menuPattern->CreateLayoutAlgorithm());
2014     ASSERT_TRUE(algorithm);
2015     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
2016     geometryNode->SetFrameSize(SizeF(MENU_SIZE_WIDTH, MENU_SIZE_HEIGHT));
2017     auto layoutProp = AceType::MakeRefPtr<MenuLayoutProperty>();
2018     auto* wrapper = new LayoutWrapperNode(Menu, geometryNode, layoutProp);
2019     auto pipeline = PipelineBase::GetCurrentContext();
2020     CHECK_NULL_VOID(pipeline);
2021     auto theme = pipeline->GetTheme<SelectTheme>();
2022     CHECK_NULL_VOID(theme);
2023 
2024     // link menuItem and menu
2025     ASSERT_TRUE(menuPattern);
2026     menuPattern->SetParentMenuItem(item);
2027     item->GetGeometryNode()->SetFrameOffset(OffsetF(MENU_OFFSET_X, MENU_OFFSET_Y));
2028     algorithm->wrapperSize_ = SizeF(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
2029     algorithm->wrapperRect_ = Rect(0, 0, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
2030     auto textNode = FrameNode::CreateFrameNode(
2031         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2032     ASSERT_NE(textNode, nullptr);
2033     MenuParam menuParam;
2034     menuParam.type = TYPE;
2035     auto menuWrapperNode = MenuView::Create(textNode, TARGET_ID, "", menuParam);
2036     ASSERT_NE(menuWrapperNode, nullptr);
2037     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
2038     SizeF size_f(100, 200);
2039     algorithm->wrapperSize_ = size_f;
2040     algorithm->wrapperRect_ = Rect(0, 0, size_f.Width(), size_f.Height());
2041 
2042     /**
2043      * @tc.steps: step2. call the ModifySubMenuWrapper method.
2044      * @tc.expected: wrapperSize_ is not Data anomalies
2045      */
2046     ASSERT_NE(algorithm->wrapperSize_, SizeF(0, 0));
2047     /**
2048      * @tc.steps: step3. call the InitializePaddingAPI12 method.
2049      * @tc.expected: padding is not zero
2050      */
2051     algorithm->canExpandCurrentWindow_ = false;
2052     auto selectTheme = MockPipelineContext::GetCurrent()->GetTheme<SelectTheme>();
2053     selectTheme->outPadding_ = 10.0_vp;
2054     selectTheme->menuLargeMargin_ = 10.0_vp;
2055     algorithm->InitializePaddingAPI12(wrapper);
2056     ASSERT_EQ(algorithm->optionPadding_, 10.0f);
2057     ASSERT_EQ(algorithm->paddingStart_, 10.0f);
2058     ASSERT_EQ(algorithm->paddingEnd_, 10.0f);
2059     ASSERT_EQ(algorithm->paddingTop_, 0.0f);
2060     ASSERT_EQ(algorithm->paddingBottom_, 0.0f);
2061 }
2062 /**
2063  * @tc.name: MenuLayoutAlgorithmAvoidWithPreview
2064  * @tc.desc: Test MenuLayoutAlgorithm LayoutOtherDeviceLeftPreviewRightMenuLessThan function.
2065  * @tc.type: FUNC
2066  */
2067 HWTEST_F(MenuTestNg, MenuLayoutAlgorithmAvoidWithPreview, TestSize.Level1)
2068 {
2069     /**
2070      * @tc.steps: step1. device type is TABLET, create menu node, preview node and menuLayoutAlgorithm, then set the
2071      * initial properties
2072      * @tc.expected: menu node, preview node and menuLayoutAlgorithm are not null
2073      */
2074     ScreenSystemManager::GetInstance().dipScale_ = DIP_SCALE;
2075     ScreenSystemManager::GetInstance().screenWidth_ = FULL_SCREEN_HEIGHT;
2076     auto context = PipelineBase::GetCurrentContext();
2077     if (context) {
2078         context->dipScale_ = DIP_SCALE;
2079     }
2080     SystemProperties::SetDeviceType(DeviceType::TABLET);
2081     auto menuWrapperNode = GetPreviewMenuWrapper();
2082     ASSERT_NE(menuWrapperNode, nullptr);
2083     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
2084     ASSERT_NE(menuNode, nullptr);
2085     auto menuAlgorithmWrapper = menuNode->GetLayoutAlgorithm();
2086     auto menuGeometryNode = menuNode->GetGeometryNode();
2087     ASSERT_NE(menuGeometryNode, nullptr);
2088     menuGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
2089     auto previewNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(1));
2090     auto previewGeometryNode = previewNode->GetGeometryNode();
2091     ASSERT_NE(previewGeometryNode, nullptr);
2092     previewGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, OFFSET_THIRD));
2093     ASSERT_NE(menuAlgorithmWrapper, nullptr);
2094     auto menuAlgorithm = AceType::DynamicCast<MenuLayoutAlgorithm>(menuAlgorithmWrapper->GetLayoutAlgorithm());
2095     ASSERT_NE(menuAlgorithm, nullptr);
2096     menuAlgorithm->wrapperSize_ = SizeF(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH);
2097     menuAlgorithm->targetSize_ = SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT);
2098     menuAlgorithm->targetOffset_ = OffsetF(OFFSET_THIRD, OFFSET_THIRD);
2099     menuAlgorithm->targetSecurity_ = TARGET_SECURITY.ConvertToPx();
2100     menuAlgorithm->previewScale_ = 1.0f;
2101     auto pipelineContext = menuAlgorithm->GetCurrentPipelineContext();
2102     ASSERT_NE(pipelineContext, nullptr);
2103     /**
2104      * @tc.steps: step2. the window can accommodate preview, placement is LEFT_TOP, layout preview and menu
2105      * @tc.expected: menu and preview left border distance TARGET_SECURITY, align the menu with the top border of the
2106      * preview
2107      */
2108     auto layoutProperty = AceType::DynamicCast<MenuLayoutProperty>(menuNode->GetLayoutProperty());
2109     layoutProperty->UpdateMenuPlacement(Placement::RIGHT_TOP);
2110     auto expectMenuOffset = OffsetF(-TARGET_SIZE_WIDTH, -TARGET_SIZE_HEIGHT);
2111     layoutProperty->UpdateMenuPlacement(Placement::LEFT_TOP);
2112     menuAlgorithm->placement_ = Placement::LEFT_TOP;
2113     menuAlgorithm->targetOffset_ = OffsetF(FULL_SCREEN_HEIGHT - OFFSET_THIRD, OFFSET_THIRD);
2114     menuAlgorithm->targetSecurity_ = 10.0f;
2115     previewGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
2116     menuGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
2117     menuAlgorithm->Layout(AceType::RawPtr(menuNode));
2118     EXPECT_EQ(menuGeometryNode->GetFrameOffset(), OffsetF(-TARGET_SIZE_WIDTH, CONST_FLOAT_ZREO));
2119 }
2120 /**
2121  * @tc.name: MenuLayoutAlgorithmNeedArrow
2122  * @tc.desc: Test GetIfNeedArrow
2123  * @tc.type: FUNC
2124  */
2125 HWTEST_F(MenuTestNg, MenuLayoutAlgorithmNeedArrow, TestSize.Level1)
2126 {
2127     /**
2128      * @tc.steps: step1. create menuLayoutAlgorithm
2129      * @tc.expected: menuLayoutAlgorithm is not null
2130      */
2131     auto menuPattern = AceType::MakeRefPtr<MenuPattern>(NODEID, TEXT_TAG, MenuType::CONTEXT_MENU);
2132     auto contextMenu = AceType::MakeRefPtr<FrameNode>(MENU_TAG, -1, menuPattern);
2133     auto menuAlgorithm = AceType::MakeRefPtr<MenuLayoutAlgorithm>(NODEID, TEXT_TAG);
2134     ASSERT_TRUE(menuAlgorithm);
2135     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
2136     auto layoutProp = AceType::MakeRefPtr<MenuLayoutProperty>();
2137     auto* layoutWrapper = new LayoutWrapperNode(contextMenu, geometryNode, layoutProp);
2138     const SizeF menuSize = SizeF(MENU_SIZE_WIDTH, MENU_SIZE_HEIGHT);
2139     /**
2140      * @tc.steps: step2. execute GetIfNeedArrow
2141      * @tc.expected: ifNeedArrow is as expected.
2142      */
2143     menuAlgorithm->GetPaintProperty(layoutWrapper)->UpdateEnableArrow(true);
2144     layoutProp->UpdateMenuPlacement(Placement::LEFT_TOP);
2145     menuAlgorithm->placement_ = Placement::LEFT_TOP;
2146     auto result = menuAlgorithm->GetIfNeedArrow(layoutWrapper, menuSize);
2147     EXPECT_TRUE(result);
2148     layoutProp->UpdateMenuPlacement(Placement::BOTTOM);
2149     menuAlgorithm->placement_ = Placement::BOTTOM;
2150     result = menuAlgorithm->GetIfNeedArrow(layoutWrapper, menuSize);
2151     EXPECT_TRUE(result);
2152 }
2153 
2154 /**
2155  * @tc.name: MenuLayoutAlgorithmNeedArrow002
2156  * @tc.desc: Test GetIfNeedArrow
2157  * @tc.type: FUNC
2158  */
2159 HWTEST_F(MenuTestNg, MenuLayoutAlgorithmNeedArrow002, TestSize.Level1)
2160 {
2161     /**
2162      * @tc.steps: step1. create menuLayoutAlgorithm
2163      * @tc.expected: menuLayoutAlgorithm is not null
2164      */
2165     auto menuPattern = AceType::MakeRefPtr<MenuPattern>(NODEID, TEXT_TAG, MenuType::CONTEXT_MENU);
2166     ASSERT_NE(menuPattern, nullptr);
2167     auto contextMenu = AceType::MakeRefPtr<FrameNode>(MENU_TAG, -1, menuPattern);
2168     auto menuAlgorithm = AceType::MakeRefPtr<MenuLayoutAlgorithm>(NODEID, TEXT_TAG);
2169     ASSERT_TRUE(menuAlgorithm);
2170     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
2171     auto layoutProp = AceType::MakeRefPtr<MenuLayoutProperty>();
2172     auto* layoutWrapper = new LayoutWrapperNode(contextMenu, geometryNode, layoutProp);
2173     const SizeF menuSize = SizeF(MENU_SIZE_WIDTH, MENU_SIZE_HEIGHT);
2174     /**
2175      * @tc.steps: step2. execute GetIfNeedArrow
2176      * @tc.expected: ifNeedArrow is as expected.
2177      */
2178     menuAlgorithm->GetPaintProperty(layoutWrapper)->UpdateEnableArrow(true);
2179     layoutProp->UpdateMenuPlacement(Placement::RIGHT_TOP);
2180     menuAlgorithm->placement_ = Placement::RIGHT_TOP;
2181     auto result = menuAlgorithm->GetIfNeedArrow(layoutWrapper, menuSize);
2182     EXPECT_TRUE(result);
2183     layoutProp->UpdateMenuPlacement(Placement::TOP);
2184     menuAlgorithm->placement_ = Placement::TOP;
2185     result = menuAlgorithm->GetIfNeedArrow(layoutWrapper, menuSize);
2186     EXPECT_TRUE(result);
2187 }
2188 
2189 /**
2190  * @tc.name: MenuLayoutAlgorithmNeedArrow003
2191  * @tc.desc: Test GetIfNeedArrow
2192  * @tc.type: FUNC
2193  */
2194 HWTEST_F(MenuTestNg, MenuLayoutAlgorithmNeedArrow003, TestSize.Level1)
2195 {
2196     /**
2197      * @tc.steps: step1. create menuLayoutAlgorithm
2198      * @tc.expected: menuLayoutAlgorithm is not null
2199      */
2200     auto menuPattern = AceType::MakeRefPtr<MenuPattern>(NODEID, TEXT_TAG, MenuType::CONTEXT_MENU);
2201     ASSERT_NE(menuPattern, nullptr);
2202     auto contextMenu = AceType::MakeRefPtr<FrameNode>(MENU_TAG, -1, menuPattern);
2203     auto menuAlgorithm = AceType::MakeRefPtr<MenuLayoutAlgorithm>(NODEID, TEXT_TAG);
2204     ASSERT_TRUE(menuAlgorithm);
2205     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
2206     auto layoutProp = AceType::MakeRefPtr<MenuLayoutProperty>();
2207     auto* layoutWrapper = new LayoutWrapperNode(contextMenu, geometryNode, layoutProp);
2208     float menuSizeWidthTest = 0.0f;
2209     float menuSizeHeightTest = 0.0f;
2210     const SizeF menuSize = SizeF(menuSizeWidthTest, menuSizeHeightTest);
2211     /**
2212      * @tc.steps: step2. execute GetIfNeedArrow
2213      * @tc.expected: ifNeedArrow is as expected.
2214      */
2215     menuAlgorithm->GetPaintProperty(layoutWrapper)->UpdateEnableArrow(true);
2216     layoutProp->UpdateMenuPlacement(Placement::LEFT_TOP);
2217     menuAlgorithm->placement_ = Placement::LEFT_TOP;
2218     auto result = menuAlgorithm->GetIfNeedArrow(layoutWrapper, menuSize);
2219     EXPECT_FALSE(result);
2220     layoutProp->UpdateMenuPlacement(Placement::BOTTOM);
2221     menuAlgorithm->placement_ = Placement::BOTTOM;
2222     result = menuAlgorithm->GetIfNeedArrow(layoutWrapper, menuSize);
2223     EXPECT_FALSE(result);
2224     layoutProp->UpdateMenuPlacement(Placement::RIGHT_TOP);
2225     menuAlgorithm->placement_ = Placement::RIGHT_TOP;
2226     result = menuAlgorithm->GetIfNeedArrow(layoutWrapper, menuSize);
2227     EXPECT_FALSE(result);
2228     layoutProp->UpdateMenuPlacement(Placement::TOP);
2229     menuAlgorithm->placement_ = Placement::TOP;
2230     result = menuAlgorithm->GetIfNeedArrow(layoutWrapper, menuSize);
2231     EXPECT_FALSE(result);
2232 }
2233 
2234 /**
2235  * @tc.name: MenuViewTestNgTextMaxLines001
2236  * @tc.desc: Verify MenuView's MaxLines.
2237  * @tc.type: FUNC
2238  */
2239 HWTEST_F(MenuTestNg, MenuViewTestNgTextMaxLines001, TestSize.Level1)
2240 {
2241     /**
2242      * @tc.steps: step1. set font scale to 1.75.
2243      */
2244     auto context = MockPipelineContext::GetCurrentContext();
2245     ASSERT_NE(context, nullptr);
2246     context->fontScale_ = 1.75f;
2247 
2248     /**
2249      * @tc.steps: step2. create menu and initialize.
2250      */
2251     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
2252     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
__anonf8e8e2060b02(ThemeType type) 2253     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
2254         if (type == TextTheme::TypeId()) {
2255             return AceType::MakeRefPtr<TextTheme>();
2256         } else if (type == IconTheme::TypeId()) {
2257             return AceType::MakeRefPtr<IconTheme>();
2258         } else if (type == SelectTheme::TypeId()) {
2259             return AceType::MakeRefPtr<SelectTheme>();
2260         } else {
2261             return AceType::MakeRefPtr<MenuTheme>();
2262         }
2263     });
2264     auto pipeline = PipelineBase::GetCurrentContext();
2265     CHECK_NULL_VOID(pipeline);
2266     auto menuTheme = pipeline->GetTheme<MenuTheme>();
2267     CHECK_NULL_VOID(menuTheme);
2268     InitMenuTestNg();
2269     InitMenuItemTestNg();
2270     std::vector<OptionParam> optionParams;
2271     optionParams.emplace_back("MenuItem", "", nullptr);
2272     MenuParam menuParam;
2273     auto menuWrapperNode = MenuView::Create(std::move(optionParams), TARGET_ID, "", TYPE, menuParam);
2274     ASSERT_NE(menuWrapperNode, nullptr);
2275     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
2276     auto menuNode = AceType::DynamicCast<FrameNode>(menuWrapperNode->GetChildAtIndex(0));
2277     ASSERT_NE(menuNode, nullptr);
2278     auto menuPattern = menuNode->GetPattern<MenuPattern>();
2279     ASSERT_NE(menuPattern, nullptr);
2280     menuPattern->OnModifyDone();
2281 
2282     /**
2283      * @tc.steps: step2. get textLayoutProperty and verify maxLines setting.
2284      * @tc.expected: MenuView's maxLines == MenuTheme's maxLines
2285      */
2286     auto column = menuPattern->GetMenuColumn();
2287     ASSERT_NE(column, nullptr);
2288     auto children = column->GetChildren();
2289     ASSERT_EQ(children.size(), 1);
2290     auto optionNode = AceType::DynamicCast<FrameNode>(column->GetChildAtIndex(0));
2291     ASSERT_NE(optionNode, nullptr);
2292     auto optionPattern = optionNode->GetPattern<OptionPattern>();
2293     ASSERT_NE(optionPattern, nullptr);
2294     auto textNode = AceType::DynamicCast<FrameNode>(optionPattern->GetTextNode());
2295     ASSERT_NE(textNode, nullptr);
2296     auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
2297     ASSERT_NE(textLayoutProperty, nullptr);
2298     EXPECT_EQ(textLayoutProperty->GetMaxLines().value(), menuTheme->GetTextMaxLines());
2299 }
2300 
2301 /**
2302  * @tc.name: MenuViewTestNg001
2303  * @tc.desc: Verify UpdateMenuBackgroundEffect.
2304  * @tc.type: FUNC
2305  */
2306 HWTEST_F(MenuTestNg, MenuViewTestNg001, TestSize.Level1)
2307 {
2308     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
2309     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
2310     RefPtr<MenuTheme> menuTheme = AceType::MakeRefPtr<MenuTheme>();
2311     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme));
2312 
2313     auto menuNode = FrameNode::CreateFrameNode(V2::MENU_ETS_TAG,
2314         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<MenuPattern>(TARGET_ID, "", TYPE));
2315     ASSERT_NE(menuNode, nullptr);
2316 
2317     menuTheme->bgBlurEffectEnable_ = 0;
2318     MenuView::UpdateMenuBackgroundEffect(menuNode);
2319 
2320     menuTheme->bgBlurEffectEnable_ = 1;
2321     MenuView::UpdateMenuBackgroundEffect(menuNode);
2322     auto renderContext = menuNode->GetRenderContext();
2323     auto effectOption = renderContext->GetBackgroundEffect();
2324     ASSERT_EQ(effectOption->color, Color::TRANSPARENT);
2325 }
2326 
2327 /**
2328  * @tc.name: MenuViewTestNg002
2329  * @tc.desc: Verify MenuView::Create when symbol not is nullptr.
2330  * @tc.type: FUNC
2331  */
2332 HWTEST_F(MenuTestNg, MenuViewTestNg002, TestSize.Level1)
2333 {
__anonf8e8e2060c02null2334     std::function<void()> action = [] {};
__anonf8e8e2060d02(const WeakPtr<NG::FrameNode>& node) 2335     std::function<void(WeakPtr<NG::FrameNode>)> symbol = [](const WeakPtr<NG::FrameNode>& node) {};
2336     std::vector<OptionParam> optionParams;
2337     optionParams.emplace_back("MenuItem1", "", action);
2338     optionParams.begin()->symbol = symbol;
2339     MenuParam menuParam;
2340     auto menuWrapperNode = MenuView::Create(std::move(optionParams), 1, "", MenuType::MENU, menuParam);
2341     ASSERT_NE(menuWrapperNode, nullptr);
2342     ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1);
2343 }
2344 
2345 /**
2346  * @tc.name: MenuViewTestNg003
2347  * @tc.desc: Verify MenuView::Create.
2348  * @tc.type: FUNC
2349  */
2350 HWTEST_F(MenuTestNg, MenuViewTestNg003, TestSize.Level1)
2351 {
2352     auto textNode = FrameNode::CreateFrameNode(
2353         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2354     ASSERT_NE(textNode, nullptr);
2355     auto customNode = FrameNode::CreateFrameNode(
2356         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2357     ASSERT_NE(customNode, nullptr);
2358     auto customSonNode = FrameNode::CreateFrameNode(
2359         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2360     ASSERT_NE(customSonNode, nullptr);
2361 
2362     MenuParam menuParam;
2363     menuParam.type = MenuType::CONTEXT_MENU;
2364     menuParam.isShowHoverImage = true;
2365     menuParam.previewAnimationOptions = { 0.5f, 2.0f };
2366     menuParam.borderRadius.emplace(Dimension(2));
2367 
2368     MockPipelineContext::GetCurrent()->SetMinPlatformVersion(static_cast<int32_t>(PlatformVersion::VERSION_ELEVEN));
2369     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
2370     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
2371     RefPtr<MenuTheme> menuTheme = AceType::MakeRefPtr<MenuTheme>();
2372     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme));
2373 
2374     auto gestureHub = customNode->GetOrCreateGestureEventHub();
2375     menuTheme->doubleBorderEnable_ = 1;
2376 
2377     auto menuWrapperNode1 = MenuView::Create(textNode, TARGET_ID, "", menuParam, true, customNode);
2378     ASSERT_NE(menuWrapperNode1, nullptr);
2379     ASSERT_EQ(menuWrapperNode1->GetChildren().size(), 2);
2380 
2381     menuTheme->doubleBorderEnable_ = 0;
2382     menuParam.previewAnimationOptions = { 0.5f, 0.0009f };
2383     customSonNode->MountToParent(customNode);
2384     menuParam.previewMode = MenuPreviewMode::CUSTOM;
2385 
2386     auto menuWrapperNode2 = MenuView::Create(textNode, TARGET_ID, "", menuParam, true, customNode);
2387     ASSERT_NE(menuWrapperNode2, nullptr);
2388     ASSERT_EQ(menuWrapperNode2->GetChildren().size(), 2);
2389 }
2390 
2391 /**
2392  * @tc.name: MenuViewTestNg004
2393  * @tc.desc: Verify SetPreviewInfoToMenu with MenuView::Create.
2394  * @tc.type: FUNC
2395  */
2396 HWTEST_F(MenuTestNg, MenuViewTestNg004, TestSize.Level1)
2397 {
2398     auto textNode = FrameNode::CreateFrameNode(
2399         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2400     ASSERT_NE(textNode, nullptr);
2401     auto customNode = FrameNode::CreateFrameNode(
2402         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2403     ASSERT_NE(customNode, nullptr);
2404 
2405     MenuParam menuParam;
2406     menuParam.type = MenuType::CONTEXT_MENU;
2407 
2408     auto targetNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 11, AceType::MakeRefPtr<TextPattern>());
2409     auto targetGestureHub = targetNode->GetOrCreateGestureEventHub();
2410 
2411     targetNode->draggable_ = true;
2412     auto menuWrapperNode1 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode);
2413     ASSERT_NE(menuWrapperNode1, nullptr);
2414     ASSERT_EQ(menuWrapperNode1->GetChildren().size(), 1);
2415 
2416     menuParam.isShowHoverImage = false;
2417     menuParam.previewMode = MenuPreviewMode::CUSTOM;
2418     auto menuWrapperNode2 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode);
2419     ASSERT_NE(menuWrapperNode2, nullptr);
2420     ASSERT_EQ(menuWrapperNode2->GetChildren().size(), 2);
2421 
2422     menuParam.isShowHoverImage = true;
2423     targetNode->GetPattern<TextPattern>()->copyOption_ = CopyOptions::Local;
2424     auto menuWrapperNode3 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode);
2425     ASSERT_NE(menuWrapperNode3, nullptr);
2426     ASSERT_EQ(menuWrapperNode3->GetChildren().size(), 2);
2427 
2428     menuParam.previewMode = MenuPreviewMode::NONE;
2429     targetNode->tag_ = "UINode";
2430     auto menuWrapperNode4 = MenuView::Create(textNode, 11, "UINode", menuParam, true, customNode);
2431     ASSERT_NE(menuWrapperNode4, nullptr);
2432     ASSERT_EQ(menuWrapperNode4->GetChildren().size(), 2);
2433 }
2434 
2435 /**
2436  * @tc.name: MenuViewTestNg005
2437  * @tc.desc: Verify SetFilter with MenuView::Create.
2438  * @tc.type: FUNC
2439  */
2440 HWTEST_F(MenuTestNg, MenuViewTestNg005, TestSize.Level1)
2441 {
2442     auto textNode = FrameNode::CreateFrameNode(
2443         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2444     ASSERT_NE(textNode, nullptr);
2445     auto customNode = FrameNode::CreateFrameNode(
2446         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2447     ASSERT_NE(customNode, nullptr);
2448     auto targetParentNode = FrameNode::CreateFrameNode(
2449         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2450     ASSERT_NE(targetParentNode, nullptr);
2451 
2452     MenuParam menuParam;
2453     menuParam.type = MenuType::CONTEXT_MENU;
2454 
2455     auto targetNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 11, AceType::MakeRefPtr<TextPattern>());
2456     ASSERT_NE(targetNode, nullptr);
2457     auto targetGestureHub = targetNode->GetOrCreateGestureEventHub();
2458 
2459     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
2460     auto pipeline = MockPipelineContext::GetCurrent();
2461     pipeline->SetThemeManager(themeManager);
2462 
2463     MockContainer::SetUp();
2464     auto container = MockContainer::Current();
2465     container->pipelineContext_ = pipeline;
2466 
2467     RefPtr<MenuTheme> menuTheme = AceType::MakeRefPtr<MenuTheme>();
2468     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme));
2469 
2470     targetParentNode->SetDepth(1);
2471     targetNode->SetParent(targetParentNode);
2472 
2473     pipeline->GetTheme<MenuTheme>()->hasFilter_ = true;
2474     targetNode->GetLayoutProperty()->UpdateIsBindOverlay(true);
2475 
2476     auto menuWrapperNode1 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode);
2477     ASSERT_NE(menuWrapperNode1, nullptr);
2478     EXPECT_EQ(menuWrapperNode1->GetChildren().size(), 1);
2479 
2480     auto overlayManager = pipeline->GetOverlayManager();
2481     ASSERT_NE(overlayManager, nullptr);
2482     overlayManager->SetHasFilter(true);
2483     overlayManager->SetIsOnAnimation(true);
2484     container->UpdateCurrent(MIN_SUBCONTAINER_ID);
2485 
2486     auto menuWrapperNode2 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode);
2487     ASSERT_NE(menuWrapperNode2, nullptr);
2488     EXPECT_EQ(menuWrapperNode2->GetChildren().size(), 1);
2489 }
2490 
2491 /**
2492  * @tc.name: MenuViewTestNg006
2493  * @tc.desc: Verify SetPixelMap with MenuView::Create.
2494  * @tc.type: FUNC
2495  */
2496 HWTEST_F(MenuTestNg, MenuViewTestNg006, TestSize.Level1)
2497 {
2498     auto textNode = FrameNode::CreateFrameNode(
2499         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2500     ASSERT_NE(textNode, nullptr);
2501     auto customNode = FrameNode::CreateFrameNode(
2502         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2503     ASSERT_NE(customNode, nullptr);
2504 
2505     MenuParam menuParam;
2506     menuParam.type = MenuType::CONTEXT_MENU;
2507 
2508     auto targetNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 11, AceType::MakeRefPtr<TextPattern>());
2509     ASSERT_NE(targetNode, nullptr);
2510     auto targetGestureHub = targetNode->GetOrCreateGestureEventHub();
2511     auto pixelMap = AceType::MakeRefPtr<MockPixelMap>();
2512 
2513     targetGestureHub->SetPixelMap(pixelMap);
2514 
2515     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
2516     auto pipeline = MockPipelineContext::GetCurrent();
2517     pipeline->SetThemeManager(themeManager);
2518     RefPtr<MenuTheme> menuTheme = AceType::MakeRefPtr<MenuTheme>();
2519     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme));
2520 
2521     auto menuWrapperNode1 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode);
2522     ASSERT_NE(menuWrapperNode1, nullptr);
2523     EXPECT_EQ(menuWrapperNode1->GetChildren().size(), 2);
2524 
2525     menuParam.hasPreviewTransitionEffect = true;
2526 
2527     auto menuWrapperNode2 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode);
2528     ASSERT_NE(menuWrapperNode2, nullptr);
2529     EXPECT_EQ(menuWrapperNode2->GetChildren().size(), 2);
2530 
2531     menuParam.isShowHoverImage = true;
2532     menuParam.hoverImageAnimationOptions = { 1.0f, 1.0f };
2533     menuParam.previewAnimationOptions = { 2.0f, 2.0f };
2534     menuParam.hasPreviewTransitionEffect = false;
2535 
2536     auto menuWrapperNode3 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode);
2537     ASSERT_NE(menuWrapperNode3, nullptr);
2538     EXPECT_EQ(menuWrapperNode3->GetChildren().size(), 2);
2539 
2540     menuParam.previewAnimationOptions = { 1.0f, 2.0f };
2541     auto menuWrapperNode4 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode);
2542     ASSERT_NE(menuWrapperNode4, nullptr);
2543     EXPECT_EQ(menuWrapperNode4->GetChildren().size(), 2);
2544 }
2545 } // namespace OHOS::Ace::NG
2546