• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 iSoftStone Information Technology (Group) 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 #include "gtest/gtest.h"
16 #define protected public
17 #define private public
18 
19 #include "test/mock/base/mock_subwindow.h"
20 #include "test/mock/base/mock_task_executor.h"
21 #include "test/mock/core/common/mock_container.h"
22 #include "test/mock/core/common/mock_theme_manager.h"
23 #include "test/mock/core/pipeline/mock_pipeline_context.h"
24 
25 #include "base/memory/referenced.h"
26 #include "core/common/ace_engine.h"
27 #include "core/components_ng/base/view_abstract_model_ng.h"
28 #include "core/components_ng/pattern/button/button_pattern.h"
29 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
30 #include "core/components_ng/pattern/menu/menu_view.h"
31 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
32 #include "core/components_ng/pattern/navrouter/navdestination_pattern.h"
33 #include "core/components_ng/pattern/overlay/sheet_manager.h"
34 #include "core/components_ng/pattern/overlay/sheet_style.h"
35 #include "core/components_ng/pattern/root/root_pattern.h"
36 #include "core/components_ng/pattern/stage/page_pattern.h"
37 #include "core/components_ng/pattern/text/text_pattern.h"
38 
39 #undef private
40 using namespace testing;
41 using namespace testing::ext;
42 
43 namespace OHOS::Ace::NG {
44 namespace {
45     ViewAbstractModelNG viewAbstractModelNG;
46     RefPtr<MockTaskExecutor> MOCK_TASK_EXECUTOR;
47     int32_t flag = 0;
48 }; // namespace
49 
50 class ViewAbstractModelTestNg : public testing::Test {
51 public:
52     static void SetUpTestSuite();
53     static void TearDownTestCase();
54 };
55 
SetUpTestSuite()56 void ViewAbstractModelTestNg::SetUpTestSuite()
57 {
58     MockPipelineContext::SetUp();
59     MockContainer::SetUp();
60     MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
61     MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
62     MockContainer::Current()->pipelineContext_->taskExecutor_ = MockContainer::Current()->taskExecutor_;
63 }
TearDownTestCase()64 void ViewAbstractModelTestNg::TearDownTestCase()
65 {
66     MockPipelineContext::TearDown();
67     MockContainer::TearDown();
68 }
69 
70 /**
71  * @tc.name: ViewAbstractModelTestNg001
72  * @tc.desc: Test the GetSheetContext of View_Abstract_model_ng
73  * @tc.type: FUNC
74  */
75 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg001, TestSize.Level1)
76 {
77     /**
78      * @tc.steps: step1. Build sheetStyle instanceId is empty.
79      */
80     SheetStyle style;
81     auto testContext1 = viewAbstractModelNG.GetSheetContext(style);
82     EXPECT_NE(testContext1, nullptr);
83 
84     /**
85      * @tc.steps: step2. Build sheetStyle instanceId is 100001.
86      */
87     style.instanceId = 100001;
88     /**
89      * @tc.steps: step3. Build an AceEngine.
90      */
91     AceEngine& aceEngine = AceEngine::Get();
92 
93     /**
94      * @tc.steps: step4. Add Container.
95      * @tc.expected: Add Container success.
96      */
97     aceEngine.AddContainer(style.instanceId.value(), MockContainer::container_);
98     EXPECT_NE(aceEngine.GetContainer(style.instanceId.value()), nullptr);
99     /**
100      * @tc.expected: context is not nullptr.
101      */
102     auto testContext2 = viewAbstractModelNG.GetSheetContext(style);
103     EXPECT_NE(testContext2, nullptr);
104 }
105 
106 /**
107  * @tc.name: BindSheetShowInPageTest1
108  * @tc.desc: Test the composition of sheet parent nodes when page will show in page
109  * @tc.type: FUNC
110  */
111 HWTEST_F(ViewAbstractModelTestNg, BindSheetShowInPageTest1, TestSize.Level1)
112 {
113     // pagelevel Node is Page Node
114     auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
115         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
116     auto column = FrameNode::CreateFrameNode(
117         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
118     auto targetNode = FrameNode::CreateFrameNode(
119         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
120     targetNode->MountToParent(column);
121     column->MountToParent(pageNode);
122     ViewStackProcessor::GetInstance()->Push(targetNode);
123     NG::SheetStyle sheetStyle;
124     sheetStyle.showInPage = true;
125     viewAbstractModelNG.BindSheet(false, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
126         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
127     auto pagePatern = pageNode->GetPattern<PagePattern>();
128     ASSERT_NE(pagePatern, nullptr);
129     auto overlay1 = pagePatern->GetOverlayManager();
130     EXPECT_EQ(overlay1, nullptr);
131     viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
132         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
133     auto overlay2 = pagePatern->GetOverlayManager();
134     EXPECT_NE(overlay2, nullptr);
135     EXPECT_FALSE(!targetNode->RootNodeIsPage());
136     EXPECT_EQ(targetNode->GetRootNodeId(), pageNode->GetId());
137 }
138 
139 /**
140  * @tc.name: BindSheetShowInPageTest2
141  * @tc.desc: Test the composition of sheet parent nodes when page will show in navDestination page
142  * @tc.type: FUNC
143  */
144 HWTEST_F(ViewAbstractModelTestNg, BindSheetShowInPageTest2, TestSize.Level1)
145 {
146     // pagelevel Node is navDestination Node
147     auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
148         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
149     auto column = FrameNode::CreateFrameNode(
150         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
151     auto navDestinaion = FrameNode::CreateFrameNode(V2::NAVDESTINATION_VIEW_ETS_TAG,
152         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<NavDestinationPattern>());
153     auto targetNode = FrameNode::CreateFrameNode(
154         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
155     targetNode->MountToParent(navDestinaion);
156     navDestinaion->MountToParent(column);
157     column->MountToParent(pageNode);
158     ViewStackProcessor::GetInstance()->Push(targetNode);
159     NG::SheetStyle sheetStyle;
160     sheetStyle.showInPage = true;
161     viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
162         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
163     auto navPatern = navDestinaion->GetPattern<NavDestinationPattern>();
164     ASSERT_NE(navPatern, nullptr);
165     auto overlay = navPatern->GetOverlayManager();
166     EXPECT_NE(overlay, nullptr);
167     EXPECT_TRUE(!targetNode->RootNodeIsPage());
168     EXPECT_EQ(targetNode->GetRootNodeId(), navDestinaion->GetId());
169     EXPECT_TRUE(!pageNode->RootNodeIsPage());
170     EXPECT_EQ(pageNode->GetRootNodeId(), targetNode->GetRootNodeId());
171 }
172 
173 /**
174  * @tc.name: GetOverlayFromPageTest
175  * @tc.desc: set sheetStyle.showInPage.value_or(false) to endter FindPageNodeOverlay
176  *           and targetNode->GetRootNodeId() > 0 to enter GetOverlayFromPage
177  * @tc.type: FUNC
178  */
179 HWTEST_F(ViewAbstractModelTestNg, GetOverlayFromPageTest, TestSize.Level1)
180 {
181     // pagelevel Node is navDestination Node
182     auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
183         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
184     auto column = FrameNode::CreateFrameNode(
185         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
186     auto navDestinaion = FrameNode::CreateFrameNode(V2::NAVDESTINATION_VIEW_ETS_TAG,
187         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<NavDestinationPattern>());
188     auto targetNode = FrameNode::CreateFrameNode(
189         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
190     targetNode->MountToParent(navDestinaion);
191     targetNode->SetRootNodeId(1);
192     navDestinaion->MountToParent(column);
193     column->MountToParent(pageNode);
194     ViewStackProcessor::GetInstance()->Push(targetNode);
195     NG::SheetStyle sheetStyle;
196     sheetStyle.showInPage = true;
197     viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
198         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
199 
200     sheetStyle.showInPage = false;
201     viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
202         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
203 
204     sheetStyle.showInPage = false;
205     viewAbstractModelNG.BindSheet(false, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
206         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
207 
208     auto navPatern = navDestinaion->GetPattern<NavDestinationPattern>();
209     ASSERT_NE(navPatern, nullptr);
210     auto overlay = navPatern->GetOverlayManager();
211     EXPECT_EQ(overlay, nullptr);
212     EXPECT_FALSE(!targetNode->RootNodeIsPage());
213     EXPECT_EQ(targetNode->GetRootNodeId(), 1);
214     EXPECT_FALSE(!pageNode->RootNodeIsPage());
215     EXPECT_NE(pageNode->GetRootNodeId(), targetNode->GetRootNodeId());
216 }
217 
218 /**
219  * @tc.name: BindContextMenuTest
220  * @tc.desc: Test the BindContextMenu method with various parameters and conditions
221  * @tc.type: FUNC
222  */
223 HWTEST_F(ViewAbstractModelTestNg, BindContextMenuTest, TestSize.Level1)
224 {
225     std::function<void()> buildFunc = nullptr;
226     std::function<void()> previewBuildFunc = nullptr;
227     MenuParam menuParam;
228 
229     /**
230      * @tc.steps: subwindow is null and does not enter BindContextMenuSingle.
231      */
232     SubwindowManager::GetInstance()->RemoveSubwindow(Container::CurrentId(), SubwindowType::TYPE_MENU);
233     viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
234     ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
235 
236     /**
237      * @tc.steps: entering BindContextMenuSingle with subwindow null, menuParam.isShow true, and buildFunc not null.
238      */
239     menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
240     menuParam.isShow = true;
__anon568f92490202() 241     buildFunc = []() {};
242     viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
243     ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
244 
245     /**
246      * @tc.steps: entering BindContextMenuSingle with subwindow null, menuParam.isShow true, and buildFunc null.
247      */
248     menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
249     menuParam.isShow = true;
250     buildFunc = nullptr;
251     viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
252     ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
253 
254     /**
255      * @tc.steps: BindContextMenuSingle with subwindow null, menuParam.isShow false, and buildFunc not null.
256      */
257     menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
258     menuParam.isShow = false;
__anon568f92490302() 259     buildFunc = []() {};
260     viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
261     ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
262 
263     /**
264      * @tc.steps: entering BindContextMenuSingle with subwindow null, menuParam.isShow false, and buildFunc null.
265      */
266     menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
267     menuParam.isShow = false;
268     buildFunc = nullptr;
269     viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
270     ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
271 
272     /**
273      * @tc.steps: subwindow is null and does not enter BindContextMenuSingle, with type == ResponseType::RIGHT_CLICK.
274      */
275     menuParam.contextMenuRegisterType = ContextMenuRegisterType::NORMAL_TYPE;
276     viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
277     ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
278 
279     /**
280      * @tc.steps: subwindow is null and does not enter BindContextMenuSingle, with type == ResponseType::LONG_PRESS.
281      */
282     viewAbstractModelNG.BindContextMenu(ResponseType::LONG_PRESS, buildFunc, menuParam, previewBuildFunc);
283     ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
284 
285     /**
286      * @tc.steps: subwindow is not null.
287      */
288     auto subwindow = Subwindow::CreateSubwindow(Container::CurrentId());
289     SubwindowManager::GetInstance()->AddSubwindow(Container::CurrentId(), subwindow);
290     viewAbstractModelNG.BindContextMenu(ResponseType::LONG_PRESS, buildFunc, menuParam, previewBuildFunc);
291     ASSERT_NE(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
292 }
293 
294 /**
295  * @tc.name: ViewAbstractModelTestNg003
296  * @tc.desc: Test the BindDragWithContextMenuParams of View_Abstract_model_ng
297  * @tc.type: FUNC
298  */
299 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg003, TestSize.Level1)
300 {
301     MenuParam menuParam;
302     auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
303         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
304     ASSERT_NE(pageNode, nullptr);
305     auto column = FrameNode::CreateFrameNode(
306         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
307     ASSERT_NE(column, nullptr);
308     auto navDestinaion = FrameNode::CreateFrameNode(V2::NAVDESTINATION_VIEW_ETS_TAG,
309         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<NavDestinationPattern>());
310     ASSERT_NE(navDestinaion, nullptr);
311     auto targetNode = FrameNode::CreateFrameNode(
312         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
313     ASSERT_NE(targetNode, nullptr);
314     targetNode->MountToParent(navDestinaion);
315     targetNode->SetRootNodeId(1);
316     navDestinaion->MountToParent(column);
317     column->MountToParent(pageNode);
318     ViewStackProcessor::GetInstance()->Push(targetNode);
319     viewAbstractModelNG.BindDragWithContextMenuParams(menuParam);
320     EXPECT_NE(pageNode, nullptr);
321 }
322 
323 /**
324  * @tc.name: ViewAbstractModelTestNg004
325  * @tc.desc: Test the BindMenu
326  * @tc.type: FUNC
327  */
328 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg004, TestSize.Level1)
329 {
330     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
331     ASSERT_NE(mainNode, nullptr);
332     ViewStackProcessor::GetInstance()->Push(mainNode);
333     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
334     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
335     auto theme = AceType::MakeRefPtr<SelectTheme>();
336     theme->expandDisplay_ = true;
337     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
338     auto container = Container::Current();
339     ASSERT_NE(container, nullptr);
340     auto pipelineContext = container->GetPipelineContext();
341     ASSERT_NE(pipelineContext, nullptr);
342 
343     ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anon568f92490402() 344     std::function<void()> flagFunc = []() { flag++; };
345     std::vector<NG::OptionParam> params = {};
346     std::function<void()> buildFunc;
347     MenuParam menuParam;
348     menuParam.isShow = true;
349     menuParam.isShowInSubWindow = true;
350     viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
351     menuParam.isShowInSubWindow = false;
__anon568f92490502() 352     buildFunc = []() { flag++; };
353     menuParam.hapticFeedbackMode = HapticFeedbackMode::ENABLED;
354     viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
355     params.push_back(OptionParam());
356     menuParam.setShow = true;
357     menuParam.hapticFeedbackMode = HapticFeedbackMode::AUTO;
358     viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
359     EXPECT_NE(mainNode, nullptr);
360 }
361 
362 /**
363  * @tc.name: ViewAbstractModelTestNg005
364  * @tc.desc: Test the BindMenu
365  * @tc.type: FUNC
366  */
367 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg005, TestSize.Level1)
368 {
369     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
370     ASSERT_NE(mainNode, nullptr);
371     ViewStackProcessor::GetInstance()->Push(mainNode);
372     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
373     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
374     auto theme = AceType::MakeRefPtr<SelectTheme>();
375     theme->expandDisplay_ = false;
376     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
377     auto container = Container::Current();
378     ASSERT_NE(container, nullptr);
379     auto pipelineContext = container->GetPipelineContext();
380     ASSERT_NE(pipelineContext, nullptr);
381     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
382     auto overlayManager = context->GetOverlayManager();
383     ASSERT_NE(overlayManager, nullptr);
384     auto menuNode = overlayManager->GetMenuNode(1);
385     if (menuNode) {
386         auto wrapperPattern = menuNode->GetPattern<MenuWrapperPattern>();
387         if (wrapperPattern) {
388             wrapperPattern->SetMenuStatus(MenuStatus::SHOW);
389         }
390     }
391     std::vector<NG::OptionParam> params = {};
392     std::function<void()> buildFunc;
393     MenuParam menuParam;
394     menuParam.isShow = true;
395     menuParam.isShowInSubWindow = true;
396     menuParam.hasTransitionEffect = false;
397     menuParam.setShow = true;
398     viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
399     menuParam.isShowInSubWindow = false;
400     menuParam.hasTransitionEffect = true;
401     menuParam.isShow = false;
__anon568f92490602() 402     buildFunc = []() { flag++; };
403     viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
404     params.push_back(OptionParam());
405     menuParam.setShow = false;
406     menuParam.isShow = false;
407     viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
408     if (menuNode) {
409         auto wrapperPattern = menuNode->GetPattern<MenuWrapperPattern>();
410         if (wrapperPattern) {
411             wrapperPattern->SetMenuStatus(MenuStatus::INIT);
412         }
413     }
414     viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
415     EXPECT_NE(mainNode, nullptr);
416 }
417 
418 /**
419  * @tc.name: ViewAbstractModelTestNg006
420  * @tc.desc: Test the BindContextMenu
421  * @tc.type: FUNC
422  */
423 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg006, TestSize.Level1)
424 {
425     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
426     ASSERT_NE(mainNode, nullptr);
427     ViewStackProcessor::GetInstance()->Push(mainNode);
428     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
429     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
430     auto theme = AceType::MakeRefPtr<SelectTheme>();
431     theme->expandDisplay_ = false;
432     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
433     auto container = Container::Current();
434     ASSERT_NE(container, nullptr);
435     auto pipelineContext = container->GetPipelineContext();
436     ASSERT_NE(pipelineContext, nullptr);
437     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
438     ASSERT_NE(context, nullptr);
439     auto containerId = pipelineContext->GetInstanceId();
440     AceEngine& aceEngine = AceEngine::Get();
441     aceEngine.AddContainer(containerId, MockContainer::container_);
442     aceEngine.AddContainer(containerId, MockContainer::container_);
443     ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anon568f92490702() 444     std::function<void()> flagFunc = []() { flag++; };
445     std::vector<NG::OptionParam> params = {};
446     std::function<void()> buildFunc;
447     MenuParam menuParam;
448     std::function<void()> previewBuildFunc = nullptr;
449     auto type = ResponseType::RIGHT_CLICK;
__anon568f92490802() 450     buildFunc = []() { flag++; };
451     params.push_back(OptionParam());
452     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
453     EXPECT_NE(mainNode, nullptr);
454 }
455 
456 /**
457  * @tc.name: ViewAbstractModelTestNg007
458  * @tc.desc: Test the BindContextMenu
459  * @tc.type: FUNC
460  */
461 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg007, TestSize.Level1)
462 {
463     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
464     ASSERT_NE(mainNode, nullptr);
465     ViewStackProcessor::GetInstance()->Push(mainNode);
466     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
467     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
468     auto theme = AceType::MakeRefPtr<SelectTheme>();
469     theme->expandDisplay_ = true;
470     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
471     auto container = Container::Current();
472     ASSERT_NE(container, nullptr);
473     auto pipelineContext = container->GetPipelineContext();
474     ASSERT_NE(pipelineContext, nullptr);
475     auto containerId = pipelineContext->GetInstanceId();
476     AceEngine& aceEngine = AceEngine::Get();
477     aceEngine.AddContainer(containerId, MockContainer::container_);
478     aceEngine.AddContainer(containerId, MockContainer::container_);
479     ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anon568f92490902() 480     std::function<void()> flagFunc = []() { flag++; };
481     std::vector<NG::OptionParam> params = {};
482     std::function<void()> buildFunc;
483     MenuParam menuParam;
484     std::function<void()> previewBuildFunc = nullptr;
485     auto type = ResponseType::RIGHT_CLICK;
486     menuParam.isShowInSubWindow = false;
__anon568f92490a02() 487     buildFunc = []() { flag++; };
488     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
489     EXPECT_NE(mainNode, nullptr);
490 }
491 
492 /**
493  * @tc.name: ViewAbstractModelTestNg008
494  * @tc.desc: Test the BindContextMenu
495  * @tc.type: FUNC
496  */
497 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg008, TestSize.Level1)
498 {
499     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 9, AceType::MakeRefPtr<Pattern>(), true);
500     ASSERT_NE(mainNode, nullptr);
501     ViewStackProcessor::GetInstance()->Push(mainNode);
502     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
503     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
504     auto theme = AceType::MakeRefPtr<SelectTheme>();
505     theme->expandDisplay_ = false;
506     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
507     auto container = Container::Current();
508     ASSERT_NE(container, nullptr);
509     auto pipelineContext = container->GetPipelineContext();
510     ASSERT_NE(pipelineContext, nullptr);
511     auto containerId = pipelineContext->GetInstanceId();
512     AceEngine& aceEngine = AceEngine::Get();
513     aceEngine.AddContainer(containerId, MockContainer::container_);
514     aceEngine.AddContainer(containerId, MockContainer::container_);
515     ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anon568f92490b02() 516     std::function<void()> flagFunc = []() { flag++; };
517     std::vector<NG::OptionParam> params = {};
518     std::function<void()> buildFunc;
519     MenuParam menuParam;
520     std::function<void()> previewBuildFunc = nullptr;
521     auto type = ResponseType::RIGHT_CLICK;
522     menuParam.isShowInSubWindow = false;
523     menuParam.hasTransitionEffect = true;
524     menuParam.isShow = false;
__anon568f92490c02() 525     buildFunc = []() { flag++; };
526     params.push_back(OptionParam());
527     menuParam.setShow = false;
528     menuParam.isShow = false;
529     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
530     EXPECT_NE(mainNode, nullptr);
531 }
532 
533 /**
534  * @tc.name: ViewAbstractModelTestNg009
535  * @tc.desc: Test the BindContextMenu
536  * @tc.type: FUNC
537  */
538 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg009, TestSize.Level1)
539 {
540     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 6, AceType::MakeRefPtr<Pattern>(), true);
541     ASSERT_NE(mainNode, nullptr);
542     ViewStackProcessor::GetInstance()->Push(mainNode);
543     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
544     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
545     auto theme = AceType::MakeRefPtr<SelectTheme>();
546     theme->expandDisplay_ = true;
547     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
548     auto container = Container::Current();
549     ASSERT_NE(container, nullptr);
550     auto pipelineContext = container->GetPipelineContext();
551     ASSERT_NE(pipelineContext, nullptr);
552     auto containerId = pipelineContext->GetInstanceId();
553     AceEngine& aceEngine = AceEngine::Get();
554     aceEngine.AddContainer(containerId, MockContainer::container_);
555     aceEngine.AddContainer(containerId, MockContainer::container_);
556     ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anon568f92490d02() 557     std::function<void()> flagFunc = []() { flag++; };
558     std::vector<NG::OptionParam> params = {};
559     std::function<void()> buildFunc;
560     MenuParam menuParam;
561     std::function<void()> previewBuildFunc = nullptr;
562     auto type = ResponseType::LONG_PRESS;
563     menuParam.isShowInSubWindow = false;
564     menuParam.previewMode = MenuPreviewMode::IMAGE;
__anon568f92490e02() 565     buildFunc = []() { flag++; };
566     menuParam.isShowHoverImage = false;
567     menuParam.hapticFeedbackMode = HapticFeedbackMode::ENABLED;
568     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
569     menuParam.hapticFeedbackMode = HapticFeedbackMode::AUTO;
570     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
571     menuParam.previewMode = MenuPreviewMode::NONE;
572     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
573     menuParam.hapticFeedbackMode = HapticFeedbackMode::ENABLED;
574     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
575     EXPECT_NE(mainNode, nullptr);
576 }
577 
578 /**
579  * @tc.name: ViewAbstractModelTestNg010
580  * @tc.desc: Test the BindContextMenu
581  * @tc.type: FUNC
582  */
583 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg010, TestSize.Level1)
584 {
585     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 6, AceType::MakeRefPtr<Pattern>(), true);
586     ASSERT_NE(mainNode, nullptr);
587     ViewStackProcessor::GetInstance()->Push(mainNode);
588     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
589     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
590     auto theme = AceType::MakeRefPtr<SelectTheme>();
591     theme->expandDisplay_ = true;
592     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
593     auto container = Container::Current();
594     ASSERT_NE(container, nullptr);
595     auto pipelineContext = container->GetPipelineContext();
596     ASSERT_NE(pipelineContext, nullptr);
597     auto containerId = pipelineContext->GetInstanceId();
598     AceEngine& aceEngine = AceEngine::Get();
599     aceEngine.AddContainer(containerId, MockContainer::container_);
600     aceEngine.AddContainer(containerId, MockContainer::container_);
__anon568f92490f02() 601     std::function<void()> flagFunc = []() { flag++; };
602     std::vector<NG::OptionParam> params = {};
603     std::function<void()> buildFunc;
604     MenuParam menuParam;
605     std::function<void()> previewBuildFunc = nullptr;
606     auto type = ResponseType::LONG_PRESS;
607     menuParam.isShowInSubWindow = false;
608     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
609     menuParam.previewMode = MenuPreviewMode::NONE;
__anon568f92491002() 610     buildFunc = []() { flag++; };
611     menuParam.isShowHoverImage = true;
612     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
613     EXPECT_NE(mainNode, nullptr);
614 }
615 
616 /**
617  * @tc.name: ViewAbstractModelTestNg011
618  * @tc.desc: Test the BindContextMenuSingle and CreateCustomMenuWithPreview
619  * @tc.type: FUNC
620  */
621 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg011, TestSize.Level1)
622 {
623     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 6, AceType::MakeRefPtr<Pattern>(), true);
624     ASSERT_NE(mainNode, nullptr);
625     ViewStackProcessor::GetInstance()->Push(mainNode);
626     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
627     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
628     auto theme = AceType::MakeRefPtr<SelectTheme>();
629     theme->expandDisplay_ = true;
630     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
631     auto container = Container::Current();
632     ASSERT_NE(container, nullptr);
633     auto pipelineContext = container->GetPipelineContext();
634     ASSERT_NE(pipelineContext, nullptr);
635     auto containerId = pipelineContext->GetInstanceId();
636     AceEngine& aceEngine = AceEngine::Get();
637     aceEngine.AddContainer(containerId, MockContainer::container_);
638     aceEngine.AddContainer(containerId, MockContainer::container_);
__anon568f92491102() 639     std::function<void()> flagFunc = []() { flag++; };
640     std::vector<NG::OptionParam> params = {};
641     std::function<void()> buildFunc;
642     MenuParam menuParam;
643     std::function<void()> previewBuildFunc = nullptr;
644     auto type = ResponseType::LONG_PRESS;
645     menuParam.isShowInSubWindow = false;
646     menuParam.previewMode = MenuPreviewMode::IMAGE;
__anon568f92491202() 647     buildFunc = []() { flag++; };
648     menuParam.isShowHoverImage = false;
649     menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
650     menuParam.isShow = true;
651 
652     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
653     menuParam.previewMode = MenuPreviewMode::CUSTOM;
654     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
655     menuParam.isShow = false;
656     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
657     menuParam.isShow = true;
658     buildFunc = nullptr;
659     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
660     EXPECT_NE(mainNode, nullptr);
661 }
662 
663 /**
664  * @tc.name: ViewAbstractModelTestNg012
665  * @tc.desc: Test the BindContextMenu
666  * @tc.type: FUNC
667  */
668 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg012, TestSize.Level1)
669 {
670     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 9, AceType::MakeRefPtr<Pattern>(), true);
671     ASSERT_NE(mainNode, nullptr);
672     ViewStackProcessor::GetInstance()->Push(mainNode);
673     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
674     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
675     auto theme = AceType::MakeRefPtr<SelectTheme>();
676     theme->expandDisplay_ = false;
677     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
678     auto container = Container::Current();
679     ASSERT_NE(container, nullptr);
680     auto pipelineContext = container->GetPipelineContext();
681     ASSERT_NE(pipelineContext, nullptr);
682     auto containerId = pipelineContext->GetInstanceId();
683     AceEngine& aceEngine = AceEngine::Get();
684     aceEngine.AddContainer(containerId, MockContainer::container_);
685     aceEngine.AddContainer(containerId, MockContainer::container_);
__anon568f92491302() 686     std::function<void()> flagFunc = []() { flag++; };
687     std::vector<NG::OptionParam> params = {};
688     std::function<void()> buildFunc;
689     MenuParam menuParam;
690     std::function<void()> previewBuildFunc = nullptr;
691     auto type = ResponseType::RIGHT_CLICK;
692     menuParam.isShowInSubWindow = false;
693     menuParam.hasTransitionEffect = true;
694     menuParam.isShow = false;
__anon568f92491402() 695     buildFunc = []() { flag++; };
696     params.push_back(OptionParam());
697     menuParam.setShow = false;
698     menuParam.isShow = false;
699     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
700     auto targetNode1 = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
701     for (const auto& destroyCallback : targetNode1->destroyCallbacksMap_) {
702         if (destroyCallback.second) {
703             destroyCallback.second();
704         }
705     }
706     EXPECT_NE(mainNode, nullptr);
707 }
708 
709 /**
710  * @tc.name: ViewAbstractModelTestNg013
711  * @tc.desc: Test the BindContextMenu
712  * @tc.type: FUNC
713  */
714 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg013, TestSize.Level1)
715 {
716     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 9, AceType::MakeRefPtr<Pattern>(), true);
717     ASSERT_NE(mainNode, nullptr);
718     ViewStackProcessor::GetInstance()->Push(mainNode);
719     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
720     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
721     auto theme = AceType::MakeRefPtr<SelectTheme>();
722     theme->expandDisplay_ = true;
723     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
724     auto container = Container::Current();
725     ASSERT_NE(container, nullptr);
726     auto pipelineContext = container->GetPipelineContext();
727     ASSERT_NE(pipelineContext, nullptr);
728     auto containerId = pipelineContext->GetInstanceId();
729     AceEngine& aceEngine = AceEngine::Get();
730     aceEngine.AddContainer(containerId, MockContainer::container_);
731     aceEngine.AddContainer(containerId, MockContainer::container_);
__anon568f92491502() 732     std::function<void()> flagFunc = []() { flag++; };
733     std::vector<NG::OptionParam> params = {};
734     std::function<void()> buildFunc;
735     MenuParam menuParam;
736     std::function<void()> previewBuildFunc = nullptr;
737     auto type = ResponseType::RIGHT_CLICK;
738     menuParam.isShowInSubWindow = false;
739     menuParam.hasTransitionEffect = true;
740     menuParam.isShow = false;
__anon568f92491602() 741     buildFunc = []() { flag++; };
742     params.push_back(OptionParam());
743     menuParam.setShow = false;
744     menuParam.isShow = false;
745     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
746     auto targetNode1 = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
747     for (const auto& destroyCallback : targetNode1->destroyCallbacksMap_) {
748         if (destroyCallback.second) {
749             destroyCallback.second();
750         }
751     }
752     EXPECT_NE(mainNode, nullptr);
753 }
754 
755 /**
756  * @tc.name: ViewAbstractModelTestNg014
757  * @tc.desc: Test the composition of sheet parent nodes when page will show in page
758  * @tc.type: FUNC
759  */
760 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg014, TestSize.Level1)
761 {
762     auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
763         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
764     ASSERT_NE(pageNode, nullptr);
765     auto column = FrameNode::CreateFrameNode(
766         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
767     ASSERT_NE(column, nullptr);
768     auto targetNode = FrameNode::CreateFrameNode(
769         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
770     ASSERT_NE(targetNode, nullptr);
771     targetNode->MountToParent(column);
772     column->MountToParent(pageNode);
773     ViewStackProcessor::GetInstance()->Push(targetNode);
774     NG::SheetStyle sheetStyle;
775     sheetStyle.showInPage = true;
776     viewAbstractModelNG.BindSheet(false, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
777         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
778     auto pagePatern = pageNode->GetPattern<PagePattern>();
779     ASSERT_NE(pagePatern, nullptr);
780     auto overlay1 = pagePatern->GetOverlayManager();
781     EXPECT_EQ(overlay1, nullptr);
782     auto container = Container::Current();
783     ASSERT_NE(container, nullptr);
784     auto pipelineContext = container->GetPipelineContext();
785     ASSERT_NE(pipelineContext, nullptr);
786     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
787     ASSERT_NE(context, nullptr);
788     viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
789         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
790     sheetStyle.showInPage = false;
791     viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
792         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
793     auto targetNode1 = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
794     for (const auto& destroyCallback : targetNode1->destroyCallbacksMap_) {
795         if (destroyCallback.second) {
796             destroyCallback.second();
797         }
798     }
799     auto overlay2 = pagePatern->GetOverlayManager();
800     EXPECT_NE(overlay2, nullptr);
801     EXPECT_FALSE(!targetNode->RootNodeIsPage());
802     EXPECT_EQ(targetNode->GetRootNodeId(), pageNode->GetId());
803 }
804 
805 /**
806  * @tc.name: ViewAbstractModelTestNg015
807  * @tc.desc: Test the BindContextMenu
808  * @tc.type: FUNC
809  */
810 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg015, TestSize.Level1)
811 {
812     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
813     ASSERT_NE(mainNode, nullptr);
814     ViewStackProcessor::GetInstance()->Push(mainNode);
815     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
816     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
817     auto theme = AceType::MakeRefPtr<SelectTheme>();
818     theme->expandDisplay_ = false;
819     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
820     auto container = Container::Current();
821     ASSERT_NE(container, nullptr);
822     auto pipelineContext = container->GetPipelineContext();
823     ASSERT_NE(pipelineContext, nullptr);
824     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
825     ASSERT_NE(context, nullptr);
826     auto overlayManager = context->GetOverlayManager();
827     ASSERT_NE(overlayManager, nullptr);
828     auto containerId = pipelineContext->GetInstanceId();
829     AceEngine& aceEngine = AceEngine::Get();
830     aceEngine.AddContainer(containerId, MockContainer::container_);
831     aceEngine.AddContainer(containerId, MockContainer::container_);
__anon568f92491702() 832     std::function<void()> flagFunc = []() { flag++; };
833     std::vector<NG::OptionParam> params = {};
834     std::function<void()> buildFunc;
835     MenuParam menuParam;
836     std::function<void()> previewBuildFunc = nullptr;
837     auto type = ResponseType::RIGHT_CLICK;
__anon568f92491802() 838     buildFunc = []() { flag++; };
839     params.push_back(OptionParam());
840     auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
841     auto targetId = targetNode->GetId();
842     auto menu =
843         FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
844     overlayManager->menuMap_[targetId] = menu;
845     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
846     EXPECT_NE(mainNode, nullptr);
847 }
848 
849 /**
850  * @tc.name: ViewAbstractModelTestNg016
851  * @tc.desc: Test the BindContextMenu
852  * @tc.type: FUNC
853  */
854 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg016, TestSize.Level1)
855 {
856     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
857     ASSERT_NE(mainNode, nullptr);
858     ViewStackProcessor::GetInstance()->Push(mainNode);
859     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
860     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
861     auto theme = AceType::MakeRefPtr<SelectTheme>();
862     theme->expandDisplay_ = false;
863     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
864     auto container = Container::Current();
865     auto pipelineContext = container->GetPipelineContext();
866     ASSERT_NE(pipelineContext, nullptr);
867     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
868     auto overlayManager = context->GetOverlayManager();
869     ASSERT_NE(overlayManager, nullptr);
870     auto containerId = pipelineContext->GetInstanceId();
871     AceEngine& aceEngine = AceEngine::Get();
872     aceEngine.AddContainer(containerId, MockContainer::container_);
__anon568f92491902() 873     std::function<void()> buildFunc = []() { flag++; };
874     MenuParam menuParam;
875     std::function<void()> previewBuildFunc = nullptr;
876     auto type = ResponseType::RIGHT_CLICK;
877     auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
878     auto targetId = targetNode->GetId();
879     auto menu =
880         FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
881     overlayManager->menuMap_[targetId] = menu;
882     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
883     auto inputHub = targetNode->GetOrCreateInputEventHub();
884     auto mouseEventActuator_ = inputHub->mouseEventActuator_;
885     auto Events = mouseEventActuator_->inputEvents_;
886     MouseInfo mouseInfo;
887     for (const auto& callback : Events) {
888         (*callback)(mouseInfo);
889     }
890     mouseInfo.button_ = MouseButton::RIGHT_BUTTON;
891     for (const auto& callback : Events) {
892         (*callback)(mouseInfo);
893     }
894     mouseInfo.action_ = MouseAction::RELEASE;
895     for (const auto& callback : Events) {
896         (*callback)(mouseInfo);
897     }
898     mouseInfo.button_ = MouseButton::LEFT_BUTTON;
899     for (const auto& callback : Events) {
900         (*callback)(mouseInfo);
901     }
902     EXPECT_NE(mainNode, nullptr);
903 }
904 
905 /**
906  * @tc.name: ViewAbstractModelTestNg017
907  * @tc.desc: Test the BindContextMenu
908  * @tc.type: FUNC
909  */
910 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg017, TestSize.Level1)
911 {
912     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
913     ASSERT_NE(mainNode, nullptr);
914     ViewStackProcessor::GetInstance()->Push(mainNode);
915     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
916     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
917     auto theme = AceType::MakeRefPtr<SelectTheme>();
918     theme->expandDisplay_ = false;
919     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
920     auto container = Container::Current();
921     ASSERT_NE(container, nullptr);
922     auto pipelineContext = container->GetPipelineContext();
923     ASSERT_NE(pipelineContext, nullptr);
924     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
925     ASSERT_NE(context, nullptr);
926     auto overlayManager = context->GetOverlayManager();
927     ASSERT_NE(overlayManager, nullptr);
928     auto containerId = pipelineContext->GetInstanceId();
929     AceEngine& aceEngine = AceEngine::Get();
930     aceEngine.AddContainer(containerId, MockContainer::container_);
__anon568f92491a02() 931     std::function<void()> buildFunc = []() { flag++; };
932     MenuParam menuParam;
933     std::function<void()> previewBuildFunc = nullptr;
934     auto type = ResponseType::LONG_PRESS;
935     auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
936     auto targetId = targetNode->GetId();
937     auto menu =
938         FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
939     overlayManager->menuMap_[targetId] = menu;
940     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
941     auto hub = targetNode->GetOrCreateGestureEventHub();
942     auto longPressEventActuator = hub->longPressEventActuator_;
943     auto Events = longPressEventActuator->longPressEvent_;
944     GestureEvent info;
945     const auto& callback = Events;
946     (*callback)(info);
947     auto pipelineContext1 = NG::PipelineContext::GetCurrentContext();
948     auto dragDropManager = pipelineContext1->GetDragDropManager();
949     dragDropManager->dragDropState_ = DragDropMgrState::DRAGGING;
950     (*callback)(info);
951     dragDropManager->dragDropState_ = DragDropMgrState::ABOUT_TO_PREVIEW;
952     (*callback)(info);
953     dragDropManager->dragDropState_ = DragDropMgrState::IDLE;
954     EXPECT_NE(mainNode, nullptr);
955 }
956 
957 /**
958  * @tc.name: ViewAbstractModelTestNg018
959  * @tc.desc: Test the BindContextMenu
960  * @tc.type: FUNC
961  */
962 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg018, TestSize.Level1)
963 {
964     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
965     ASSERT_NE(mainNode, nullptr);
966     ViewStackProcessor::GetInstance()->Push(mainNode);
967     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
968     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
969     auto theme = AceType::MakeRefPtr<SelectTheme>();
970     theme->expandDisplay_ = false;
971     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
972     auto container = Container::Current();
973     auto pipelineContext = container->GetPipelineContext();
974     ASSERT_NE(pipelineContext, nullptr);
975     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
976     auto overlayManager = context->GetOverlayManager();
977     ASSERT_NE(overlayManager, nullptr);
978     auto containerId = pipelineContext->GetInstanceId();
979     AceEngine& aceEngine = AceEngine::Get();
980     aceEngine.AddContainer(containerId, MockContainer::container_);
__anon568f92491b02() 981     std::function<void()> buildFunc = []() { flag++; };
982     MenuParam menuParam;
983     menuParam.previewMode = MenuPreviewMode::IMAGE;
984     menuParam.isShowHoverImage = true;
985     std::function<void()> previewBuildFunc = nullptr;
986     auto type = ResponseType::LONG_PRESS;
987     auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
988     auto targetId = targetNode->GetId();
989     auto menu =
990         FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
991     overlayManager->menuMap_[targetId] = menu;
992     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
993     auto hub = targetNode->GetOrCreateGestureEventHub();
994     auto longPressEventActuator = hub->longPressEventActuator_;
995     auto Events = longPressEventActuator->longPressEvent_;
996     GestureEvent info;
997     const auto& callback = Events;
998     (*callback)(info);
999     auto focusHub = targetNode->GetOrCreateFocusHub();
1000     KeyEvent event;
1001     focusHub->ProcessOnKeyEventInternal(event);
1002     event.action = KeyAction::DOWN;
1003     focusHub->ProcessOnKeyEventInternal(event);
1004     event.keyIntention = KeyIntention::INTENTION_MENU;
1005     focusHub->ProcessOnKeyEventInternal(event);
1006     event.code = KeyCode::KEY_MENU;
1007     menuParam.placement = Placement::BOTTOM_LEFT;
1008     viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
1009     focusHub->ProcessOnKeyEventInternal(event);
1010     EXPECT_NE(mainNode, nullptr);
1011 }
1012 
1013 /**
1014  * @tc.name: ViewAbstractModelTestNg019
1015  * @tc.desc: Test the BindBackground
1016  * @tc.type: FUNC
1017  */
1018 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg019, TestSize.Level1)
1019 {
1020     /**
1021      * @tc.steps: step1. create main frame node and push into view abstract.
1022      */
1023     const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1024     ASSERT_NE(mainNode, nullptr);
1025     ViewStackProcessor::GetInstance()->Push(mainNode);
1026 
1027     /**
1028      * @tc.steps: step2. init theme, pipeline and container.
1029      */
1030     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1031     ASSERT_NE(themeManager, nullptr);
__anon568f92491c02(ThemeType type) 1032     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1033         if (type == SheetTheme::TypeId()) {
1034             return AceType::MakeRefPtr<SheetTheme>();
1035         } else {
1036             return nullptr;
1037         }
1038     });
1039     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1040     auto container = Container::Current();
1041     ASSERT_NE(container, nullptr);
1042     auto pipelineContext = container->GetPipelineContext();
1043     ASSERT_NE(pipelineContext, nullptr);
1044     auto containerId = pipelineContext->GetInstanceId();
1045     AceEngine& aceEngine = AceEngine::Get();
1046     aceEngine.AddContainer(containerId, MockContainer::container_);
1047 
1048     /**
1049      * @tc.steps: step3. init background build func and alignment.
1050      * @tc.expected: background function and alignment is successfully set.
1051      */
1052     auto mainFrameNode = AceType::WeakClaim(ViewStackProcessor::GetInstance()->GetMainFrameNode());
1053     Alignment alignment = Alignment::CENTER;
__anon568f92491d02() 1054     auto buildFunc = [mainFrameNode] () {
1055         flag++;
1056     };
1057     viewAbstractModelNG.BindBackground(std::move(buildFunc), alignment);
1058     auto targetNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1059     ASSERT_NE(targetNode, nullptr);
1060     auto renderContext = targetNode->GetRenderContext();
1061     ASSERT_NE(renderContext, nullptr);
1062     auto backgroundAlign = renderContext->GetBackgroundAlign().value_or(Alignment::BOTTOM_CENTER);
1063     ASSERT_EQ(backgroundAlign, alignment);
1064 
1065     /**
1066      * @tc.steps: step4. update background build func and alignment.
1067      * @tc.expected: background function and alignment is successfully set.
1068      */
1069     alignment = Alignment::TOP_CENTER;
1070     viewAbstractModelNG.BindBackground(std::move(buildFunc), alignment);
1071     backgroundAlign = renderContext->GetBackgroundAlign().value_or(Alignment::BOTTOM_CENTER);
1072     ASSERT_EQ(backgroundAlign, alignment);
1073 }
1074 
1075 /**
1076  * @tc.name: ViewAbstractModelTestNg020
1077  * @tc.desc: Test the DismissSheet
1078  * @tc.type: FUNC
1079  */
1080 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg020, TestSize.Level1)
1081 {
1082     /**
1083      * @tc.steps: step1. setup environment.
1084      */
1085     MockPipelineContext::SetUp();
1086     RefPtr<FrameNode> stageMainNode = AceType::MakeRefPtr<FrameNode>("STAGE", -1, AceType::MakeRefPtr<Pattern>());
1087     ASSERT_NE(stageMainNode, nullptr);
1088     auto stageManager = AceType::MakeRefPtr<StageManager>(stageMainNode);
1089     MockPipelineContext::GetCurrent()->stageManager_ = stageManager;
1090     MockContainer::SetUp();
1091     MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1092     MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1093     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1094     ASSERT_NE(themeManager, nullptr);
__anon568f92491e02(ThemeType type) 1095     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1096         if (type == SheetTheme::TypeId()) {
1097             return AceType::MakeRefPtr<SheetTheme>();
1098         } else {
1099             return nullptr;
1100         }
1101     });
1102     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1103 
1104     /**
1105      * @tc.steps: step2. create target node.
1106      */
1107     auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1108     ElementRegister::GetInstance()->MakeUniqueId(),
__anon568f92491f02() 1109         []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1110     ASSERT_NE(targetNode, nullptr);
1111     ViewStackProcessor::GetInstance()->Push(targetNode);
1112     auto stageNode = FrameNode::CreateFrameNode(
1113         V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1114     ASSERT_NE(stageNode, nullptr);
1115     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
1116     ASSERT_NE(rootNode, nullptr);
1117     stageNode->MountToParent(rootNode);
1118     targetNode->MountToParent(stageNode);
1119     rootNode->MarkDirtyNode();
1120 
1121     /**
1122      * @tc.steps: step3. create sheetNode, get sheetPattern.
1123      */
1124     bool isShow = true;
__anon568f92492002() 1125     auto builderFunc = []() -> RefPtr<UINode> {
1126         auto frameNode =
1127             FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1128                 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1129         CHECK_NULL_RETURN(frameNode, nullptr);
1130         auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1131             ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1132         CHECK_NULL_RETURN(childFrameNode, nullptr);
1133         frameNode->AddChild(childFrameNode);
1134         return frameNode;
1135     };
__anon568f92492302() 1136     auto buildTitleNodeFunc = []() -> RefPtr<UINode> {
1137         auto frameNode =
1138             FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1139                 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1140         CHECK_NULL_RETURN(frameNode, nullptr);
1141         auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG,
1142             ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<TextPattern>(); });
1143         CHECK_NULL_RETURN(childFrameNode, nullptr);
1144         frameNode->AddChild(childFrameNode);
1145         return frameNode;
1146     };
1147     SheetStyle sheetStyle;
1148     if (!sheetStyle.sheetHeight.sheetMode.has_value()) {
1149         sheetStyle.sheetHeight.sheetMode = SheetMode::MEDIUM;
1150     }
1151     if (!sheetStyle.showDragBar.has_value()) {
1152         sheetStyle.showDragBar = true;
1153     }
1154     auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
1155     ASSERT_NE(overlayManager, nullptr);
1156     overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle,
1157         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode);
1158     EXPECT_FALSE(overlayManager->modalStack_.empty());
1159 
1160 
1161     /**
1162      * @tc.steps: step4. set dismiss sheet id.
1163      */
1164     auto topSheetNode = overlayManager->modalStack_.top().Upgrade();
1165     ASSERT_NE(topSheetNode, nullptr);
1166     auto nodeId = topSheetNode->GetId();
1167     SheetManager::GetInstance().SetDismissSheet(nodeId);
1168     viewAbstractModelNG.DismissSheet();
1169 }
1170 
1171 /**
1172  * @tc.name: ViewAbstractModelTestNg021
1173  * @tc.desc: Test the SheetSpringBack
1174  * @tc.type: FUNC
1175  */
1176 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg021, TestSize.Level1)
1177 {
1178     /**
1179      * @tc.steps: step1. setup environment.
1180      */
1181     MockPipelineContext::SetUp();
1182     RefPtr<FrameNode> stageMainNode = AceType::MakeRefPtr<FrameNode>("STAGE", -1, AceType::MakeRefPtr<Pattern>());
1183     ASSERT_NE(stageMainNode, nullptr);
1184     auto stageManager = AceType::MakeRefPtr<StageManager>(stageMainNode);
1185     MockPipelineContext::GetCurrent()->stageManager_ = stageManager;
1186     MockContainer::SetUp();
1187     MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1188     MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1189     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1190     ASSERT_NE(themeManager, nullptr);
__anon568f92492602(ThemeType type) 1191     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1192         if (type == SheetTheme::TypeId()) {
1193             return AceType::MakeRefPtr<SheetTheme>();
1194         } else {
1195             return nullptr;
1196         }
1197     });
1198     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1199 
1200     /**
1201      * @tc.steps: step2. create target node.
1202      */
1203     auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1204     ElementRegister::GetInstance()->MakeUniqueId(),
__anon568f92492702() 1205         []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1206     ASSERT_NE(targetNode, nullptr);
1207     ViewStackProcessor::GetInstance()->Push(targetNode);
1208     auto stageNode = FrameNode::CreateFrameNode(
1209         V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1210     ASSERT_NE(stageNode, nullptr);
1211     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
1212     ASSERT_NE(rootNode, nullptr);
1213     stageNode->MountToParent(rootNode);
1214     targetNode->MountToParent(stageNode);
1215     rootNode->MarkDirtyNode();
1216 
1217     /**
1218      * @tc.steps: step3. create sheetNode, get sheetPattern.
1219      */
1220     bool isShow = true;
__anon568f92492802() 1221     auto builderFunc = []() -> RefPtr<UINode> {
1222         auto frameNode =
1223             FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1224                 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1225         CHECK_NULL_RETURN(frameNode, nullptr);
1226         auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1227             ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1228         CHECK_NULL_RETURN(childFrameNode, nullptr);
1229         frameNode->AddChild(childFrameNode);
1230         return frameNode;
1231     };
__anon568f92492b02() 1232     auto buildTitleNodeFunc = []() -> RefPtr<UINode> {
1233         auto frameNode =
1234             FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1235                 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1236         CHECK_NULL_RETURN(frameNode, nullptr);
1237         auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG,
1238             ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<TextPattern>(); });
1239         CHECK_NULL_RETURN(childFrameNode, nullptr);
1240         frameNode->AddChild(childFrameNode);
1241         return frameNode;
1242     };
1243     SheetStyle sheetStyle;
1244     if (!sheetStyle.sheetHeight.sheetMode.has_value()) {
1245         sheetStyle.sheetHeight.sheetMode = SheetMode::MEDIUM;
1246     }
1247     if (!sheetStyle.showDragBar.has_value()) {
1248         sheetStyle.showDragBar = true;
1249     }
1250     auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
1251     ASSERT_NE(overlayManager, nullptr);
1252     overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle,
1253         nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode);
1254     EXPECT_FALSE(overlayManager->modalStack_.empty());
1255 
1256 
1257     /**
1258      * @tc.steps: step4. set dismiss sheet id.
1259      */
1260     auto topSheetNode = overlayManager->modalStack_.top().Upgrade();
1261     ASSERT_NE(topSheetNode, nullptr);
1262     auto nodeId = topSheetNode->GetId();
1263     SheetManager::GetInstance().SetDismissSheet(nodeId);
1264     viewAbstractModelNG.SheetSpringBack();
1265 }
1266 
1267 /**
1268  * @tc.name: ViewAbstractModelTestNg022
1269  * @tc.desc: Test the DismissContentCover
1270  * @tc.type: FUNC
1271  */
1272 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg022, TestSize.Level1)
1273 {
1274     /**
1275      * @tc.steps: step1. create target node.
1276      */
1277     auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1278     ElementRegister::GetInstance()->MakeUniqueId(),
__anon568f92492e02() 1279         []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1280     ASSERT_NE(targetNode, nullptr);
1281     ViewStackProcessor::GetInstance()->Push(targetNode);
1282     auto stageNode = FrameNode::CreateFrameNode(
1283         V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1284     ASSERT_NE(stageNode, nullptr);
1285     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
1286     ASSERT_NE(rootNode, nullptr);
1287     stageNode->MountToParent(rootNode);
1288     targetNode->MountToParent(stageNode);
1289     rootNode->MarkDirtyNode();
1290 
1291     /**
1292      * @tc.steps: step2. setup environment.
1293      */
1294     MockPipelineContext::SetUp();
1295     RefPtr<FrameNode> stageMainNode = AceType::MakeRefPtr<FrameNode>("STAGE", -1, AceType::MakeRefPtr<Pattern>());
1296     ASSERT_NE(stageMainNode, nullptr);
1297     auto stageManager = AceType::MakeRefPtr<StageManager>(stageMainNode);
1298     MockPipelineContext::GetCurrent()->stageManager_ = stageManager;
1299     MockContainer::SetUp();
1300     MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1301     MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1302     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1303     ASSERT_NE(themeManager, nullptr);
__anon568f92492f02(ThemeType type) 1304     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1305         if (type == SheetTheme::TypeId()) {
1306             return AceType::MakeRefPtr<SheetTheme>();
1307         } else {
1308             return nullptr;
1309         }
1310     });
1311     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1312 
1313     /**
1314      * @tc.steps: step3. create modal page node.
1315      */
__anon568f92493002() 1316     auto builderFunc = []() -> RefPtr<UINode> {
1317         auto frameNode =
1318             FrameNode::GetOrCreateFrameNode(V2::COLUMN_COMPONENT_TAG,
1319             ElementRegister::GetInstance()->MakeUniqueId(),
1320                 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1321         CHECK_NULL_RETURN(frameNode, nullptr);
1322         auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1323             ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1324         CHECK_NULL_RETURN(childFrameNode, nullptr);
1325         frameNode->AddChild(childFrameNode);
1326         return frameNode;
1327     };
1328 
1329     /**
1330      * @tc.steps: step4. create modal node and call DismissContentCover.
1331      * @tc.expected: destroy modal page successfully
1332      */
1333     ModalStyle modalStyle;
1334     bool isShow = true;
1335     // auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
1336     auto container = MockContainer::Current();
1337     ASSERT_NE(container, nullptr);
1338     auto pipelineContext = container->GetPipelineContext();
1339     ASSERT_NE(pipelineContext, nullptr);
1340     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
1341     ASSERT_NE(context, nullptr);
1342     auto overlayManager = context->GetOverlayManager();
1343     ASSERT_NE(overlayManager, nullptr);
1344     overlayManager->OnBindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr,
1345         nullptr, ContentCoverParam(), targetNode);
1346     EXPECT_FALSE(overlayManager->modalStack_.empty());
1347     auto topModalNode = overlayManager->modalStack_.top().Upgrade();
1348     ASSERT_NE(topModalNode, nullptr);
1349     auto topModalPattern = topModalNode->GetPattern<ModalPresentationPattern>();
1350     ASSERT_NE(topModalPattern, nullptr);
1351     auto targetId = topModalPattern->GetTargetId();
1352     overlayManager->SetDismissTarget(DismissTarget(targetId));
1353     viewAbstractModelNG.DismissContentCover();
1354     EXPECT_TRUE(overlayManager->modalStack_.empty());
1355 }
1356 
1357 /**
1358  * @tc.name: ViewAbstractModelTestNg023
1359  * @tc.desc: Test the BindContentCover
1360  * @tc.type: FUNC
1361  */
1362 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg023, TestSize.Level1)
1363 {
1364     /**
1365      * @tc.steps: step1. create target node.
1366      */
1367     auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1368     ElementRegister::GetInstance()->MakeUniqueId(),
__anon568f92493302() 1369         []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1370     ASSERT_NE(targetNode, nullptr);
1371     ViewStackProcessor::GetInstance()->Push(targetNode);
1372     auto stageNode = FrameNode::CreateFrameNode(
1373         V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1374     ASSERT_NE(stageNode, nullptr);
1375     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
1376     ASSERT_NE(rootNode, nullptr);
1377     stageNode->MountToParent(rootNode);
1378     targetNode->MountToParent(stageNode);
1379     rootNode->MarkDirtyNode();
1380 
1381     /**
1382      * @tc.steps: step2. setup environment.
1383      */
1384     MockPipelineContext::SetUp();
1385     RefPtr<FrameNode> stageMainNode = AceType::MakeRefPtr<FrameNode>("STAGE", -1, AceType::MakeRefPtr<Pattern>());
1386     ASSERT_NE(stageMainNode, nullptr);
1387     auto stageManager = AceType::MakeRefPtr<StageManager>(stageMainNode);
1388     MockPipelineContext::GetCurrent()->stageManager_ = stageManager;
1389     MockContainer::SetUp();
1390     MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1391     MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1392     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1393     ASSERT_NE(themeManager, nullptr);
__anon568f92493402(ThemeType type) 1394     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1395         if (type == SheetTheme::TypeId()) {
1396             return AceType::MakeRefPtr<SheetTheme>();
1397         } else {
1398             return nullptr;
1399         }
1400     });
1401     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1402 
1403     /**
1404      * @tc.steps: step3. create modal page node.
1405      */
__anon568f92493502() 1406     auto builderFunc = []() -> RefPtr<UINode> {
1407         auto frameNode =
1408             FrameNode::GetOrCreateFrameNode(V2::COLUMN_COMPONENT_TAG,
1409             ElementRegister::GetInstance()->MakeUniqueId(),
1410                 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1411         CHECK_NULL_RETURN(frameNode, nullptr);
1412         auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1413             ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1414         CHECK_NULL_RETURN(childFrameNode, nullptr);
1415         frameNode->AddChild(childFrameNode);
1416         return frameNode;
1417     };
1418 
1419     /**
1420      * @tc.steps: step4. create modal node and get modal node, get pattern.
1421      * @tc.expected: related flag is false.
1422      */
1423     ModalStyle modalStyle;
1424     bool isShow = true;
__anon568f92493802(int32_t info) 1425     std::function<void(int32_t info)> onWillDismiss = [](int32_t info) {};
1426     RefPtr<NG::ChainedTransitionEffect> effect = AceType::MakeRefPtr<NG::ChainedOpacityEffect>(1.0);
1427     // auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
1428     auto container = MockContainer::Current();
1429     ASSERT_NE(container, nullptr);
1430     auto pipelineContext = container->GetPipelineContext();
1431     ASSERT_NE(pipelineContext, nullptr);
1432     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
1433     ASSERT_NE(context, nullptr);
1434     auto overlayManager = context->GetOverlayManager();
1435     ASSERT_NE(overlayManager, nullptr);
1436     overlayManager->OnBindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr,
1437         nullptr, ContentCoverParam(), targetNode);
1438     EXPECT_FALSE(overlayManager->modalStack_.empty());
1439     auto topModalNode = overlayManager->modalStack_.top().Upgrade();
1440     ASSERT_NE(topModalNode, nullptr);
1441     auto topModalPattern = topModalNode->GetPattern<ModalPresentationPattern>();
1442     ASSERT_NE(topModalPattern, nullptr);
1443     EXPECT_EQ(topModalPattern->HasOnWillDismiss(), false);
1444     EXPECT_EQ(topModalPattern->HasTransitionEffect(), false);
1445 
1446     /**
1447      * @tc.steps: step5. create modal node and call BindContentCover.
1448      * @tc.expected: related flag is true.
1449      */
1450     ContentCoverParam contentCoverParam;
1451     contentCoverParam.onWillDismiss = onWillDismiss;
1452     contentCoverParam.transitionEffect = std::move(effect);
1453     viewAbstractModelNG.BindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr,
1454         nullptr, nullptr, contentCoverParam);
1455     topModalNode = overlayManager->modalStack_.top().Upgrade();
1456     topModalPattern = topModalNode->GetPattern<ModalPresentationPattern>();
1457     EXPECT_EQ(topModalPattern->HasOnWillDismiss(), true);
1458     EXPECT_EQ(topModalPattern->HasTransitionEffect(), true);
1459 }
1460 } // namespace OHOS::Ace::NG