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 "base/subwindow/subwindow_manager.h"
27 #include "core/common/ace_engine.h"
28 #include "core/components_ng/base/view_abstract_model_ng.h"
29 #include "core/components_ng/pattern/button/button_pattern.h"
30 #include "core/components_ng/pattern/container_modal/container_modal_pattern.h"
31 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
32 #include "core/components_ng/pattern/menu/menu_view.h"
33 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
34 #include "core/components_ng/pattern/navrouter/navdestination_pattern.h"
35 #include "core/components_ng/pattern/overlay/sheet_manager.h"
36 #include "core/components_ng/pattern/overlay/sheet_style.h"
37 #include "core/components_ng/pattern/root/root_pattern.h"
38 #include "core/components_ng/pattern/stage/page_pattern.h"
39 #include "core/components_ng/pattern/text/text_pattern.h"
40
41 #undef private
42 using namespace testing;
43 using namespace testing::ext;
44
45 namespace OHOS::Ace::NG {
46 namespace {
47 ViewAbstractModelNG viewAbstractModelNG;
48 RefPtr<MockTaskExecutor> MOCK_TASK_EXECUTOR;
49 int32_t flag = 0;
50 const std::string TEST_TEXT_HINT = "testTextHint";
51 constexpr int32_t TEST_NODE_ID = 1;
52 }; // namespace
53
54 class ViewAbstractModelTestNg : public testing::Test {
55 public:
56 static void SetUpTestSuite();
57 static void TearDownTestCase();
58 };
59
SetUpTestSuite()60 void ViewAbstractModelTestNg::SetUpTestSuite()
61 {
62 MockPipelineContext::SetUp();
63 MockContainer::SetUp();
64 MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
65 MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
66 MockContainer::Current()->pipelineContext_->taskExecutor_ = MockContainer::Current()->taskExecutor_;
67 }
TearDownTestCase()68 void ViewAbstractModelTestNg::TearDownTestCase()
69 {
70 MockPipelineContext::TearDown();
71 MockContainer::TearDown();
72 ViewStackProcessor::GetInstance()->ClearStack();
73 }
74
75 /**
76 * @tc.name: ViewAbstractModelTestNg001
77 * @tc.desc: Test the GetSheetContext of View_Abstract_model_ng
78 * @tc.type: FUNC
79 */
80 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg001, TestSize.Level1)
81 {
82 /**
83 * @tc.steps: step1. Build sheetStyle instanceId is empty.
84 */
85 SheetStyle style;
86 auto testContext1 = viewAbstractModelNG.GetSheetContext(style);
87 EXPECT_NE(testContext1, nullptr);
88
89 /**
90 * @tc.steps: step2. Build sheetStyle instanceId is 100001.
91 */
92 style.instanceId = 100001;
93 /**
94 * @tc.steps: step3. Build an AceEngine.
95 */
96 AceEngine& aceEngine = AceEngine::Get();
97
98 /**
99 * @tc.steps: step4. Add Container.
100 * @tc.expected: Add Container success.
101 */
102 aceEngine.AddContainer(style.instanceId.value(), MockContainer::container_);
103 EXPECT_NE(aceEngine.GetContainer(style.instanceId.value()), nullptr);
104 /**
105 * @tc.expected: context is not nullptr.
106 */
107 auto testContext2 = viewAbstractModelNG.GetSheetContext(style);
108 EXPECT_NE(testContext2, nullptr);
109 }
110
111 /**
112 * @tc.name: BindSheetShowInPageTest1
113 * @tc.desc: Test the composition of sheet parent nodes when page will show in page
114 * @tc.type: FUNC
115 */
116 HWTEST_F(ViewAbstractModelTestNg, BindSheetShowInPageTest1, TestSize.Level1)
117 {
118 // pagelevel Node is Page Node
119 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
120 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
121 auto column = FrameNode::CreateFrameNode(
122 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
123 auto targetNode = FrameNode::CreateFrameNode(
124 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
125 targetNode->MountToParent(column);
126 column->MountToParent(pageNode);
127 ViewStackProcessor::GetInstance()->Push(targetNode);
128 NG::SheetStyle sheetStyle;
129 sheetStyle.showInPage = true;
130 viewAbstractModelNG.BindSheet(false, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
131 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
132 auto pagePatern = pageNode->GetPattern<PagePattern>();
133 ASSERT_NE(pagePatern, nullptr);
134 auto overlay1 = pagePatern->GetOverlayManager();
135 EXPECT_EQ(overlay1, nullptr);
136 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
137 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
138 auto overlay2 = pagePatern->GetOverlayManager();
139 EXPECT_NE(overlay2, nullptr);
140 EXPECT_FALSE(!targetNode->RootNodeIsPage());
141 EXPECT_EQ(targetNode->GetRootNodeId(), pageNode->GetId());
142 }
143
144 /**
145 * @tc.name: BindSheetShowInPageTest2
146 * @tc.desc: Test the composition of sheet parent nodes when page will show in navDestination page
147 * @tc.type: FUNC
148 */
149 HWTEST_F(ViewAbstractModelTestNg, BindSheetShowInPageTest2, TestSize.Level1)
150 {
151 // pagelevel Node is navDestination Node
152 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
153 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
154 auto column = FrameNode::CreateFrameNode(
155 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
156 auto navDestinaion = FrameNode::CreateFrameNode(V2::NAVDESTINATION_VIEW_ETS_TAG,
157 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<NavDestinationPattern>());
158 auto targetNode = FrameNode::CreateFrameNode(
159 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
160 targetNode->MountToParent(navDestinaion);
161 navDestinaion->MountToParent(column);
162 column->MountToParent(pageNode);
163 ViewStackProcessor::GetInstance()->Push(targetNode);
164 NG::SheetStyle sheetStyle;
165 sheetStyle.showInPage = true;
166 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
167 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
168 auto navPatern = navDestinaion->GetPattern<NavDestinationPattern>();
169 ASSERT_NE(navPatern, nullptr);
170 auto overlay = navPatern->GetOverlayManager();
171 EXPECT_NE(overlay, nullptr);
172 EXPECT_TRUE(!targetNode->RootNodeIsPage());
173 EXPECT_EQ(targetNode->GetRootNodeId(), navDestinaion->GetId());
174 EXPECT_TRUE(!pageNode->RootNodeIsPage());
175 EXPECT_EQ(pageNode->GetRootNodeId(), targetNode->GetRootNodeId());
176 }
177
178 /**
179 * @tc.name: GetOverlayFromPageTest
180 * @tc.desc: set sheetStyle.showInPage.value_or(false) to endter FindPageNodeOverlay
181 * and targetNode->GetRootNodeId() > 0 to enter GetOverlayFromPage
182 * @tc.type: FUNC
183 */
184 HWTEST_F(ViewAbstractModelTestNg, GetOverlayFromPageTest, TestSize.Level1)
185 {
186 // pagelevel Node is navDestination Node
187 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
188 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
189 auto column = FrameNode::CreateFrameNode(
190 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
191 auto navDestinaion = FrameNode::CreateFrameNode(V2::NAVDESTINATION_VIEW_ETS_TAG,
192 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<NavDestinationPattern>());
193 auto targetNode = FrameNode::CreateFrameNode(
194 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
195 targetNode->MountToParent(navDestinaion);
196 targetNode->SetRootNodeId(1);
197 navDestinaion->MountToParent(column);
198 column->MountToParent(pageNode);
199 ViewStackProcessor::GetInstance()->Push(targetNode);
200 NG::SheetStyle sheetStyle;
201 sheetStyle.showInPage = true;
202 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
203 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
204
205 sheetStyle.showInPage = false;
206 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
207 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
208
209 sheetStyle.showInPage = false;
210 viewAbstractModelNG.BindSheet(false, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
211 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
212
213 auto navPatern = navDestinaion->GetPattern<NavDestinationPattern>();
214 ASSERT_NE(navPatern, nullptr);
215 auto overlay = navPatern->GetOverlayManager();
216 EXPECT_EQ(overlay, nullptr);
217 EXPECT_FALSE(!targetNode->RootNodeIsPage());
218 EXPECT_EQ(targetNode->GetRootNodeId(), 1);
219 EXPECT_FALSE(!pageNode->RootNodeIsPage());
220 EXPECT_NE(pageNode->GetRootNodeId(), targetNode->GetRootNodeId());
221 }
222
223 /**
224 * @tc.name: BindContextMenuTest
225 * @tc.desc: Test the BindContextMenu method with various parameters and conditions
226 * @tc.type: FUNC
227 */
228 HWTEST_F(ViewAbstractModelTestNg, BindContextMenuTest, TestSize.Level1)
229 {
230 std::function<void()> buildFunc = nullptr;
231 std::function<void()> previewBuildFunc = nullptr;
232 MenuParam menuParam;
233
234 /**
235 * @tc.steps: subwindow is null and does not enter BindContextMenuSingle.
236 */
237 SubwindowManager::GetInstance()->RemoveSubwindow(Container::CurrentId(), SubwindowType::TYPE_MENU);
238 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
239 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
240
241 /**
242 * @tc.steps: entering BindContextMenuSingle with subwindow null, menuParam.isShow true, and buildFunc not null.
243 */
244 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
245 menuParam.isShow = true;
__anonaaf173eb0202() 246 buildFunc = []() {};
247 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
248 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
249
250 /**
251 * @tc.steps: entering BindContextMenuSingle with subwindow null, menuParam.isShow true, and buildFunc null.
252 */
253 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
254 menuParam.isShow = true;
255 buildFunc = nullptr;
256 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
257 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
258
259 /**
260 * @tc.steps: BindContextMenuSingle with subwindow null, menuParam.isShow false, and buildFunc not null.
261 */
262 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
263 menuParam.isShow = false;
__anonaaf173eb0302() 264 buildFunc = []() {};
265 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
266 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
267
268 /**
269 * @tc.steps: entering BindContextMenuSingle with subwindow null, menuParam.isShow false, and buildFunc null.
270 */
271 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
272 menuParam.isShow = false;
273 buildFunc = nullptr;
274 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
275 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
276
277 /**
278 * @tc.steps: subwindow is null and does not enter BindContextMenuSingle, with type == ResponseType::RIGHT_CLICK.
279 */
280 menuParam.contextMenuRegisterType = ContextMenuRegisterType::NORMAL_TYPE;
281 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
282 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
283
284 /**
285 * @tc.steps: subwindow is null and does not enter BindContextMenuSingle, with type == ResponseType::LONG_PRESS.
286 */
287 viewAbstractModelNG.BindContextMenu(ResponseType::LONG_PRESS, buildFunc, menuParam, previewBuildFunc);
288 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
289
290 /**
291 * @tc.steps: subwindow is not null.
292 */
293 auto subwindow = Subwindow::CreateSubwindow(Container::CurrentId());
294 SubwindowManager::GetInstance()->AddSubwindow(Container::CurrentId(), subwindow);
295 viewAbstractModelNG.BindContextMenu(ResponseType::LONG_PRESS, buildFunc, menuParam, previewBuildFunc);
296 ASSERT_NE(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
297 }
298
299 /**
300 * @tc.name: ViewAbstractModelTestNg003
301 * @tc.desc: Test the BindDragWithContextMenuParams of View_Abstract_model_ng
302 * @tc.type: FUNC
303 */
304 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg003, TestSize.Level1)
305 {
306 MenuParam menuParam;
307 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
308 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
309 ASSERT_NE(pageNode, nullptr);
310 auto column = FrameNode::CreateFrameNode(
311 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
312 ASSERT_NE(column, nullptr);
313 auto navDestinaion = FrameNode::CreateFrameNode(V2::NAVDESTINATION_VIEW_ETS_TAG,
314 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<NavDestinationPattern>());
315 ASSERT_NE(navDestinaion, nullptr);
316 auto targetNode = FrameNode::CreateFrameNode(
317 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
318 ASSERT_NE(targetNode, nullptr);
319 targetNode->MountToParent(navDestinaion);
320 targetNode->SetRootNodeId(1);
321 navDestinaion->MountToParent(column);
322 column->MountToParent(pageNode);
323 ViewStackProcessor::GetInstance()->Push(targetNode);
324 viewAbstractModelNG.BindDragWithContextMenuParams(menuParam);
325 EXPECT_NE(pageNode, nullptr);
326 }
327
328 /**
329 * @tc.name: ViewAbstractModelTestNg004
330 * @tc.desc: Test the BindMenu
331 * @tc.type: FUNC
332 */
333 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg004, TestSize.Level1)
334 {
335 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
336 ASSERT_NE(mainNode, nullptr);
337 ViewStackProcessor::GetInstance()->Push(mainNode);
338 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
339 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
340 auto theme = AceType::MakeRefPtr<SelectTheme>();
341 theme->expandDisplay_ = true;
342 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
343 auto container = Container::Current();
344 ASSERT_NE(container, nullptr);
345 auto pipelineContext = container->GetPipelineContext();
346 ASSERT_NE(pipelineContext, nullptr);
347
348 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anonaaf173eb0402() 349 std::function<void()> flagFunc = []() { flag++; };
350 std::vector<NG::OptionParam> params = {};
351 std::function<void()> buildFunc;
352 MenuParam menuParam;
353 menuParam.isShow = true;
354 menuParam.isShowInSubWindow = true;
355 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
356 menuParam.isShowInSubWindow = false;
__anonaaf173eb0502() 357 buildFunc = []() { flag++; };
358 menuParam.hapticFeedbackMode = HapticFeedbackMode::ENABLED;
359 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
360 params.push_back(OptionParam());
361 menuParam.setShow = true;
362 menuParam.hapticFeedbackMode = HapticFeedbackMode::AUTO;
363 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
364 EXPECT_NE(mainNode, nullptr);
365 }
366
367 /**
368 * @tc.name: ViewAbstractModelTestNg005
369 * @tc.desc: Test the BindMenu
370 * @tc.type: FUNC
371 */
372 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg005, TestSize.Level1)
373 {
374 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
375 ASSERT_NE(mainNode, nullptr);
376 ViewStackProcessor::GetInstance()->Push(mainNode);
377 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
378 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
379 auto theme = AceType::MakeRefPtr<SelectTheme>();
380 theme->expandDisplay_ = false;
381 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
382 auto container = Container::Current();
383 ASSERT_NE(container, nullptr);
384 auto pipelineContext = container->GetPipelineContext();
385 ASSERT_NE(pipelineContext, nullptr);
386 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
387 auto overlayManager = context->GetOverlayManager();
388 ASSERT_NE(overlayManager, nullptr);
389 auto menuNode = overlayManager->GetMenuNode(1);
390 if (menuNode) {
391 auto wrapperPattern = menuNode->GetPattern<MenuWrapperPattern>();
392 if (wrapperPattern) {
393 wrapperPattern->SetMenuStatus(MenuStatus::SHOW);
394 }
395 }
396 std::vector<NG::OptionParam> params = {};
397 std::function<void()> buildFunc;
398 MenuParam menuParam;
399 menuParam.isShow = true;
400 menuParam.isShowInSubWindow = true;
401 menuParam.hasTransitionEffect = false;
402 menuParam.setShow = true;
403 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
404 menuParam.isShowInSubWindow = false;
405 menuParam.hasTransitionEffect = true;
406 menuParam.isShow = false;
__anonaaf173eb0602() 407 buildFunc = []() { flag++; };
408 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
409 params.push_back(OptionParam());
410 menuParam.setShow = false;
411 menuParam.isShow = false;
412 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
413 if (menuNode) {
414 auto wrapperPattern = menuNode->GetPattern<MenuWrapperPattern>();
415 if (wrapperPattern) {
416 wrapperPattern->SetMenuStatus(MenuStatus::INIT);
417 }
418 }
419 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
420 EXPECT_NE(mainNode, nullptr);
421 }
422
423 /**
424 * @tc.name: ViewAbstractModelTestNg006
425 * @tc.desc: Test the BindContextMenu
426 * @tc.type: FUNC
427 */
428 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg006, TestSize.Level1)
429 {
430 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
431 ASSERT_NE(mainNode, nullptr);
432 ViewStackProcessor::GetInstance()->Push(mainNode);
433 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
434 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
435 auto theme = AceType::MakeRefPtr<SelectTheme>();
436 theme->expandDisplay_ = false;
437 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
438 auto container = Container::Current();
439 ASSERT_NE(container, nullptr);
440 auto pipelineContext = container->GetPipelineContext();
441 ASSERT_NE(pipelineContext, nullptr);
442 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
443 ASSERT_NE(context, nullptr);
444 auto containerId = pipelineContext->GetInstanceId();
445 AceEngine& aceEngine = AceEngine::Get();
446 aceEngine.AddContainer(containerId, MockContainer::container_);
447 aceEngine.AddContainer(containerId, MockContainer::container_);
448 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anonaaf173eb0702() 449 std::function<void()> flagFunc = []() { flag++; };
450 std::vector<NG::OptionParam> params = {};
451 std::function<void()> buildFunc;
452 MenuParam menuParam;
453 std::function<void()> previewBuildFunc = nullptr;
454 auto type = ResponseType::RIGHT_CLICK;
__anonaaf173eb0802() 455 buildFunc = []() { flag++; };
456 params.push_back(OptionParam());
457 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
458 EXPECT_NE(mainNode, nullptr);
459 }
460
461 /**
462 * @tc.name: ViewAbstractModelTestNg007
463 * @tc.desc: Test the BindContextMenu
464 * @tc.type: FUNC
465 */
466 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg007, TestSize.Level1)
467 {
468 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
469 ASSERT_NE(mainNode, nullptr);
470 ViewStackProcessor::GetInstance()->Push(mainNode);
471 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
472 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
473 auto theme = AceType::MakeRefPtr<SelectTheme>();
474 theme->expandDisplay_ = true;
475 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
476 auto container = Container::Current();
477 ASSERT_NE(container, nullptr);
478 auto pipelineContext = container->GetPipelineContext();
479 ASSERT_NE(pipelineContext, nullptr);
480 auto containerId = pipelineContext->GetInstanceId();
481 AceEngine& aceEngine = AceEngine::Get();
482 aceEngine.AddContainer(containerId, MockContainer::container_);
483 aceEngine.AddContainer(containerId, MockContainer::container_);
484 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anonaaf173eb0902() 485 std::function<void()> flagFunc = []() { flag++; };
486 std::vector<NG::OptionParam> params = {};
487 std::function<void()> buildFunc;
488 MenuParam menuParam;
489 std::function<void()> previewBuildFunc = nullptr;
490 auto type = ResponseType::RIGHT_CLICK;
491 menuParam.isShowInSubWindow = false;
__anonaaf173eb0a02() 492 buildFunc = []() { flag++; };
493 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
494 EXPECT_NE(mainNode, nullptr);
495 }
496
497 /**
498 * @tc.name: ViewAbstractModelTestNg008
499 * @tc.desc: Test the BindContextMenu
500 * @tc.type: FUNC
501 */
502 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg008, TestSize.Level1)
503 {
504 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 9, AceType::MakeRefPtr<Pattern>(), true);
505 ASSERT_NE(mainNode, nullptr);
506 ViewStackProcessor::GetInstance()->Push(mainNode);
507 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
508 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
509 auto theme = AceType::MakeRefPtr<SelectTheme>();
510 theme->expandDisplay_ = false;
511 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
512 auto container = Container::Current();
513 ASSERT_NE(container, nullptr);
514 auto pipelineContext = container->GetPipelineContext();
515 ASSERT_NE(pipelineContext, nullptr);
516 auto containerId = pipelineContext->GetInstanceId();
517 AceEngine& aceEngine = AceEngine::Get();
518 aceEngine.AddContainer(containerId, MockContainer::container_);
519 aceEngine.AddContainer(containerId, MockContainer::container_);
520 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anonaaf173eb0b02() 521 std::function<void()> flagFunc = []() { flag++; };
522 std::vector<NG::OptionParam> params = {};
523 std::function<void()> buildFunc;
524 MenuParam menuParam;
525 std::function<void()> previewBuildFunc = nullptr;
526 auto type = ResponseType::RIGHT_CLICK;
527 menuParam.isShowInSubWindow = false;
528 menuParam.hasTransitionEffect = true;
529 menuParam.isShow = false;
__anonaaf173eb0c02() 530 buildFunc = []() { flag++; };
531 params.push_back(OptionParam());
532 menuParam.setShow = false;
533 menuParam.isShow = false;
534 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
535 EXPECT_NE(mainNode, nullptr);
536 }
537
538 /**
539 * @tc.name: ViewAbstractModelTestNg009
540 * @tc.desc: Test the BindContextMenu
541 * @tc.type: FUNC
542 */
543 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg009, TestSize.Level1)
544 {
545 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 6, AceType::MakeRefPtr<Pattern>(), true);
546 ASSERT_NE(mainNode, nullptr);
547 ViewStackProcessor::GetInstance()->Push(mainNode);
548 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
549 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
550 auto theme = AceType::MakeRefPtr<SelectTheme>();
551 theme->expandDisplay_ = true;
552 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
553 auto container = Container::Current();
554 ASSERT_NE(container, nullptr);
555 auto pipelineContext = container->GetPipelineContext();
556 ASSERT_NE(pipelineContext, nullptr);
557 auto containerId = pipelineContext->GetInstanceId();
558 AceEngine& aceEngine = AceEngine::Get();
559 aceEngine.AddContainer(containerId, MockContainer::container_);
560 aceEngine.AddContainer(containerId, MockContainer::container_);
561 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anonaaf173eb0d02() 562 std::function<void()> flagFunc = []() { flag++; };
563 std::vector<NG::OptionParam> params = {};
564 std::function<void()> buildFunc;
565 MenuParam menuParam;
566 std::function<void()> previewBuildFunc = nullptr;
567 auto type = ResponseType::LONG_PRESS;
568 menuParam.isShowInSubWindow = false;
569 menuParam.previewMode = MenuPreviewMode::IMAGE;
__anonaaf173eb0e02() 570 buildFunc = []() { flag++; };
571 menuParam.isShowHoverImage = false;
572 menuParam.hapticFeedbackMode = HapticFeedbackMode::ENABLED;
573 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
574 menuParam.hapticFeedbackMode = HapticFeedbackMode::AUTO;
575 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
576 menuParam.previewMode = MenuPreviewMode::NONE;
577 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
578 menuParam.hapticFeedbackMode = HapticFeedbackMode::ENABLED;
579 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
580 EXPECT_NE(mainNode, nullptr);
581 }
582
583 /**
584 * @tc.name: ViewAbstractModelTestNg010
585 * @tc.desc: Test the BindContextMenu
586 * @tc.type: FUNC
587 */
588 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg010, TestSize.Level1)
589 {
590 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 6, AceType::MakeRefPtr<Pattern>(), true);
591 ASSERT_NE(mainNode, nullptr);
592 ViewStackProcessor::GetInstance()->Push(mainNode);
593 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
594 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
595 auto theme = AceType::MakeRefPtr<SelectTheme>();
596 theme->expandDisplay_ = true;
597 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
598 auto container = Container::Current();
599 ASSERT_NE(container, nullptr);
600 auto pipelineContext = container->GetPipelineContext();
601 ASSERT_NE(pipelineContext, nullptr);
602 auto containerId = pipelineContext->GetInstanceId();
603 AceEngine& aceEngine = AceEngine::Get();
604 aceEngine.AddContainer(containerId, MockContainer::container_);
605 aceEngine.AddContainer(containerId, MockContainer::container_);
__anonaaf173eb0f02() 606 std::function<void()> flagFunc = []() { flag++; };
607 std::vector<NG::OptionParam> params = {};
608 std::function<void()> buildFunc;
609 MenuParam menuParam;
610 std::function<void()> previewBuildFunc = nullptr;
611 auto type = ResponseType::LONG_PRESS;
612 menuParam.isShowInSubWindow = false;
613 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
614 menuParam.previewMode = MenuPreviewMode::NONE;
__anonaaf173eb1002() 615 buildFunc = []() { flag++; };
616 menuParam.isShowHoverImage = true;
617 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
618 EXPECT_NE(mainNode, nullptr);
619 }
620
621 /**
622 * @tc.name: ViewAbstractModelTestNg011
623 * @tc.desc: Test the BindContextMenuSingle and CreateCustomMenuWithPreview
624 * @tc.type: FUNC
625 */
626 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg011, TestSize.Level1)
627 {
628 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 6, AceType::MakeRefPtr<Pattern>(), true);
629 ASSERT_NE(mainNode, nullptr);
630 ViewStackProcessor::GetInstance()->Push(mainNode);
631 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
632 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
633 auto theme = AceType::MakeRefPtr<SelectTheme>();
634 theme->expandDisplay_ = true;
635 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
636 auto container = Container::Current();
637 ASSERT_NE(container, nullptr);
638 auto pipelineContext = container->GetPipelineContext();
639 ASSERT_NE(pipelineContext, nullptr);
640 auto containerId = pipelineContext->GetInstanceId();
641 AceEngine& aceEngine = AceEngine::Get();
642 aceEngine.AddContainer(containerId, MockContainer::container_);
643 aceEngine.AddContainer(containerId, MockContainer::container_);
__anonaaf173eb1102() 644 std::function<void()> flagFunc = []() { flag++; };
645 std::vector<NG::OptionParam> params = {};
646 std::function<void()> buildFunc;
647 MenuParam menuParam;
648 std::function<void()> previewBuildFunc = nullptr;
649 auto type = ResponseType::LONG_PRESS;
650 menuParam.isShowInSubWindow = false;
651 menuParam.previewMode = MenuPreviewMode::IMAGE;
__anonaaf173eb1202() 652 buildFunc = []() { flag++; };
653 menuParam.isShowHoverImage = false;
654 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
655 menuParam.isShow = true;
656
657 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
658 menuParam.previewMode = MenuPreviewMode::CUSTOM;
659 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
660 menuParam.isShow = false;
661 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
662 menuParam.isShow = true;
663 buildFunc = nullptr;
664 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
665 EXPECT_NE(mainNode, nullptr);
666 }
667
668 /**
669 * @tc.name: ViewAbstractModelTestNg012
670 * @tc.desc: Test the BindContextMenu
671 * @tc.type: FUNC
672 */
673 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg012, TestSize.Level1)
674 {
675 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 9, AceType::MakeRefPtr<Pattern>(), true);
676 ASSERT_NE(mainNode, nullptr);
677 ViewStackProcessor::GetInstance()->Push(mainNode);
678 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
679 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
680 auto theme = AceType::MakeRefPtr<SelectTheme>();
681 theme->expandDisplay_ = false;
682 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
683 auto container = Container::Current();
684 ASSERT_NE(container, nullptr);
685 auto pipelineContext = container->GetPipelineContext();
686 ASSERT_NE(pipelineContext, nullptr);
687 auto containerId = pipelineContext->GetInstanceId();
688 AceEngine& aceEngine = AceEngine::Get();
689 aceEngine.AddContainer(containerId, MockContainer::container_);
690 aceEngine.AddContainer(containerId, MockContainer::container_);
__anonaaf173eb1302() 691 std::function<void()> flagFunc = []() { flag++; };
692 std::vector<NG::OptionParam> params = {};
693 std::function<void()> buildFunc;
694 MenuParam menuParam;
695 std::function<void()> previewBuildFunc = nullptr;
696 auto type = ResponseType::RIGHT_CLICK;
697 menuParam.isShowInSubWindow = false;
698 menuParam.hasTransitionEffect = true;
699 menuParam.isShow = false;
__anonaaf173eb1402() 700 buildFunc = []() { flag++; };
701 params.push_back(OptionParam());
702 menuParam.setShow = false;
703 menuParam.isShow = false;
704 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
705 auto targetNode1 = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
706 for (const auto& destroyCallback : targetNode1->destroyCallbacksMap_) {
707 if (destroyCallback.second) {
708 destroyCallback.second();
709 }
710 }
711 EXPECT_NE(mainNode, nullptr);
712 }
713
714 /**
715 * @tc.name: ViewAbstractModelTestNg013
716 * @tc.desc: Test the BindContextMenu
717 * @tc.type: FUNC
718 */
719 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg013, TestSize.Level1)
720 {
721 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 9, AceType::MakeRefPtr<Pattern>(), true);
722 ASSERT_NE(mainNode, nullptr);
723 ViewStackProcessor::GetInstance()->Push(mainNode);
724 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
725 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
726 auto theme = AceType::MakeRefPtr<SelectTheme>();
727 theme->expandDisplay_ = true;
728 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
729 auto container = Container::Current();
730 ASSERT_NE(container, nullptr);
731 auto pipelineContext = container->GetPipelineContext();
732 ASSERT_NE(pipelineContext, nullptr);
733 auto containerId = pipelineContext->GetInstanceId();
734 AceEngine& aceEngine = AceEngine::Get();
735 aceEngine.AddContainer(containerId, MockContainer::container_);
736 aceEngine.AddContainer(containerId, MockContainer::container_);
__anonaaf173eb1502() 737 std::function<void()> flagFunc = []() { flag++; };
738 std::vector<NG::OptionParam> params = {};
739 std::function<void()> buildFunc;
740 MenuParam menuParam;
741 std::function<void()> previewBuildFunc = nullptr;
742 auto type = ResponseType::RIGHT_CLICK;
743 menuParam.isShowInSubWindow = false;
744 menuParam.hasTransitionEffect = true;
745 menuParam.isShow = false;
__anonaaf173eb1602() 746 buildFunc = []() { flag++; };
747 params.push_back(OptionParam());
748 menuParam.setShow = false;
749 menuParam.isShow = false;
750 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
751 auto targetNode1 = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
752 for (const auto& destroyCallback : targetNode1->destroyCallbacksMap_) {
753 if (destroyCallback.second) {
754 destroyCallback.second();
755 }
756 }
757 EXPECT_NE(mainNode, nullptr);
758 }
759
760 /**
761 * @tc.name: ViewAbstractModelTestNg014
762 * @tc.desc: Test the composition of sheet parent nodes when page will show in page
763 * @tc.type: FUNC
764 */
765 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg014, TestSize.Level1)
766 {
767 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
768 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
769 ASSERT_NE(pageNode, nullptr);
770 auto column = FrameNode::CreateFrameNode(
771 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
772 ASSERT_NE(column, nullptr);
773 auto targetNode = FrameNode::CreateFrameNode(
774 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
775 ASSERT_NE(targetNode, nullptr);
776 targetNode->MountToParent(column);
777 column->MountToParent(pageNode);
778 ViewStackProcessor::GetInstance()->Push(targetNode);
779 NG::SheetStyle sheetStyle;
780 sheetStyle.showInPage = true;
781 viewAbstractModelNG.BindSheet(false, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
782 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
783 auto pagePatern = pageNode->GetPattern<PagePattern>();
784 ASSERT_NE(pagePatern, nullptr);
785 auto overlay1 = pagePatern->GetOverlayManager();
786 EXPECT_EQ(overlay1, nullptr);
787 auto container = Container::Current();
788 ASSERT_NE(container, nullptr);
789 auto pipelineContext = container->GetPipelineContext();
790 ASSERT_NE(pipelineContext, nullptr);
791 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
792 ASSERT_NE(context, nullptr);
793 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
794 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
795 sheetStyle.showInPage = false;
796 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
797 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
798 auto targetNode1 = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
799 for (const auto& destroyCallback : targetNode1->destroyCallbacksMap_) {
800 if (destroyCallback.second) {
801 destroyCallback.second();
802 }
803 }
804 auto overlay2 = pagePatern->GetOverlayManager();
805 EXPECT_NE(overlay2, nullptr);
806 EXPECT_FALSE(!targetNode->RootNodeIsPage());
807 EXPECT_EQ(targetNode->GetRootNodeId(), pageNode->GetId());
808 }
809
810 /**
811 * @tc.name: ViewAbstractModelTestNg015
812 * @tc.desc: Test the BindContextMenu
813 * @tc.type: FUNC
814 */
815 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg015, TestSize.Level1)
816 {
817 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
818 ASSERT_NE(mainNode, nullptr);
819 ViewStackProcessor::GetInstance()->Push(mainNode);
820 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
821 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
822 auto theme = AceType::MakeRefPtr<SelectTheme>();
823 theme->expandDisplay_ = false;
824 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
825 auto container = Container::Current();
826 ASSERT_NE(container, nullptr);
827 auto pipelineContext = container->GetPipelineContext();
828 ASSERT_NE(pipelineContext, nullptr);
829 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
830 ASSERT_NE(context, nullptr);
831 auto overlayManager = context->GetOverlayManager();
832 ASSERT_NE(overlayManager, nullptr);
833 auto containerId = pipelineContext->GetInstanceId();
834 AceEngine& aceEngine = AceEngine::Get();
835 aceEngine.AddContainer(containerId, MockContainer::container_);
836 aceEngine.AddContainer(containerId, MockContainer::container_);
__anonaaf173eb1702() 837 std::function<void()> flagFunc = []() { flag++; };
838 std::vector<NG::OptionParam> params = {};
839 std::function<void()> buildFunc;
840 MenuParam menuParam;
841 std::function<void()> previewBuildFunc = nullptr;
842 auto type = ResponseType::RIGHT_CLICK;
__anonaaf173eb1802() 843 buildFunc = []() { flag++; };
844 params.push_back(OptionParam());
845 auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
846 auto targetId = targetNode->GetId();
847 auto menu =
848 FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
849 overlayManager->menuMap_[targetId] = menu;
850 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
851 EXPECT_NE(mainNode, nullptr);
852 }
853
854 /**
855 * @tc.name: ViewAbstractModelTestNg016
856 * @tc.desc: Test the BindContextMenu
857 * @tc.type: FUNC
858 */
859 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg016, TestSize.Level1)
860 {
861 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
862 ASSERT_NE(mainNode, nullptr);
863 ViewStackProcessor::GetInstance()->Push(mainNode);
864 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
865 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
866 auto theme = AceType::MakeRefPtr<SelectTheme>();
867 theme->expandDisplay_ = false;
868 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
869 auto container = Container::Current();
870 auto pipelineContext = container->GetPipelineContext();
871 ASSERT_NE(pipelineContext, nullptr);
872 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
873 auto overlayManager = context->GetOverlayManager();
874 ASSERT_NE(overlayManager, nullptr);
875 auto containerId = pipelineContext->GetInstanceId();
876 AceEngine& aceEngine = AceEngine::Get();
877 aceEngine.AddContainer(containerId, MockContainer::container_);
__anonaaf173eb1902() 878 std::function<void()> buildFunc = []() { flag++; };
879 MenuParam menuParam;
880 std::function<void()> previewBuildFunc = nullptr;
881 auto type = ResponseType::RIGHT_CLICK;
882 auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
883 auto targetId = targetNode->GetId();
884 auto menu =
885 FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
886 overlayManager->menuMap_[targetId] = menu;
887 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
888 auto inputHub = targetNode->GetOrCreateInputEventHub();
889 auto mouseEventActuator_ = inputHub->mouseEventActuator_;
890 auto Events = mouseEventActuator_->inputEvents_;
891 MouseInfo mouseInfo;
892 for (const auto& callback : Events) {
893 (*callback)(mouseInfo);
894 }
895 mouseInfo.button_ = MouseButton::RIGHT_BUTTON;
896 for (const auto& callback : Events) {
897 (*callback)(mouseInfo);
898 }
899 mouseInfo.action_ = MouseAction::RELEASE;
900 for (const auto& callback : Events) {
901 (*callback)(mouseInfo);
902 }
903 mouseInfo.button_ = MouseButton::LEFT_BUTTON;
904 for (const auto& callback : Events) {
905 (*callback)(mouseInfo);
906 }
907 EXPECT_NE(mainNode, nullptr);
908 }
909
910 /**
911 * @tc.name: ViewAbstractModelTestNg017
912 * @tc.desc: Test the BindContextMenu
913 * @tc.type: FUNC
914 */
915 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg017, TestSize.Level1)
916 {
917 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
918 ASSERT_NE(mainNode, nullptr);
919 ViewStackProcessor::GetInstance()->Push(mainNode);
920 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
921 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
922 auto theme = AceType::MakeRefPtr<SelectTheme>();
923 theme->expandDisplay_ = false;
924 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
925 auto container = Container::Current();
926 ASSERT_NE(container, nullptr);
927 auto pipelineContext = container->GetPipelineContext();
928 ASSERT_NE(pipelineContext, nullptr);
929 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
930 ASSERT_NE(context, nullptr);
931 auto overlayManager = context->GetOverlayManager();
932 ASSERT_NE(overlayManager, nullptr);
933 auto containerId = pipelineContext->GetInstanceId();
934 AceEngine& aceEngine = AceEngine::Get();
935 aceEngine.AddContainer(containerId, MockContainer::container_);
__anonaaf173eb1a02() 936 std::function<void()> buildFunc = []() { flag++; };
937 MenuParam menuParam;
938 std::function<void()> previewBuildFunc = nullptr;
939 auto type = ResponseType::LONG_PRESS;
940 auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
941 auto targetId = targetNode->GetId();
942 auto menu =
943 FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
944 overlayManager->menuMap_[targetId] = menu;
945 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
946 auto hub = targetNode->GetOrCreateGestureEventHub();
947 auto longPressEventActuator = hub->longPressEventActuator_;
948 auto Events = longPressEventActuator->longPressEvent_;
949 GestureEvent info;
950 const auto& callback = Events;
951 (*callback)(info);
952 auto pipelineContext1 = NG::PipelineContext::GetCurrentContext();
953 auto dragDropManager = pipelineContext1->GetDragDropManager();
954 dragDropManager->dragDropState_ = DragDropMgrState::DRAGGING;
955 (*callback)(info);
956 dragDropManager->dragDropState_ = DragDropMgrState::ABOUT_TO_PREVIEW;
957 (*callback)(info);
958 dragDropManager->dragDropState_ = DragDropMgrState::IDLE;
959 EXPECT_NE(mainNode, nullptr);
960 }
961
962 /**
963 * @tc.name: ViewAbstractModelTestNg018
964 * @tc.desc: Test the BindContextMenu
965 * @tc.type: FUNC
966 */
967 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg018, TestSize.Level1)
968 {
969 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
970 ASSERT_NE(mainNode, nullptr);
971 ViewStackProcessor::GetInstance()->Push(mainNode);
972 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
973 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
974 auto theme = AceType::MakeRefPtr<SelectTheme>();
975 theme->expandDisplay_ = false;
976 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
977 auto container = Container::Current();
978 auto pipelineContext = container->GetPipelineContext();
979 ASSERT_NE(pipelineContext, nullptr);
980 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
981 auto overlayManager = context->GetOverlayManager();
982 ASSERT_NE(overlayManager, nullptr);
983 auto containerId = pipelineContext->GetInstanceId();
984 AceEngine& aceEngine = AceEngine::Get();
985 aceEngine.AddContainer(containerId, MockContainer::container_);
__anonaaf173eb1b02() 986 std::function<void()> buildFunc = []() { flag++; };
987 MenuParam menuParam;
988 menuParam.previewMode = MenuPreviewMode::IMAGE;
989 menuParam.isShowHoverImage = true;
990 std::function<void()> previewBuildFunc = nullptr;
991 auto type = ResponseType::LONG_PRESS;
992 auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
993 auto targetId = targetNode->GetId();
994 auto menu =
995 FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
996 overlayManager->menuMap_[targetId] = menu;
997 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
998 auto hub = targetNode->GetOrCreateGestureEventHub();
999 auto longPressEventActuator = hub->longPressEventActuator_;
1000 auto Events = longPressEventActuator->longPressEvent_;
1001 GestureEvent info;
1002 const auto& callback = Events;
1003 (*callback)(info);
1004 auto focusHub = targetNode->GetOrCreateFocusHub();
1005 KeyEvent event;
1006 focusHub->ProcessOnKeyEventInternal(event);
1007 event.action = KeyAction::DOWN;
1008 focusHub->ProcessOnKeyEventInternal(event);
1009 event.keyIntention = KeyIntention::INTENTION_MENU;
1010 focusHub->ProcessOnKeyEventInternal(event);
1011 event.code = KeyCode::KEY_MENU;
1012 menuParam.placement = Placement::BOTTOM_LEFT;
1013 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
1014 focusHub->ProcessOnKeyEventInternal(event);
1015 EXPECT_NE(mainNode, nullptr);
1016 }
1017
1018 /**
1019 * @tc.name: ViewAbstractModelTestNg019
1020 * @tc.desc: Test the BindBackground
1021 * @tc.type: FUNC
1022 */
1023 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg019, TestSize.Level1)
1024 {
1025 /**
1026 * @tc.steps: step1. create main frame node and push into view abstract.
1027 */
1028 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1029 ASSERT_NE(mainNode, nullptr);
1030 ViewStackProcessor::GetInstance()->Push(mainNode);
1031
1032 /**
1033 * @tc.steps: step2. init theme, pipeline and container.
1034 */
1035 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1036 ASSERT_NE(themeManager, nullptr);
__anonaaf173eb1c02(ThemeType type) 1037 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1038 if (type == SheetTheme::TypeId()) {
1039 return AceType::MakeRefPtr<SheetTheme>();
1040 } else {
1041 return nullptr;
1042 }
1043 });
1044 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1045 auto container = Container::Current();
1046 ASSERT_NE(container, nullptr);
1047 auto pipelineContext = container->GetPipelineContext();
1048 ASSERT_NE(pipelineContext, nullptr);
1049 auto containerId = pipelineContext->GetInstanceId();
1050 AceEngine& aceEngine = AceEngine::Get();
1051 aceEngine.AddContainer(containerId, MockContainer::container_);
1052
1053 /**
1054 * @tc.steps: step3. init background build func and alignment.
1055 * @tc.expected: background function and alignment is successfully set.
1056 */
1057 auto mainFrameNode = AceType::WeakClaim(ViewStackProcessor::GetInstance()->GetMainFrameNode());
1058 Alignment alignment = Alignment::CENTER;
__anonaaf173eb1d02() 1059 auto buildFunc = [mainFrameNode] () {
1060 flag++;
1061 };
1062 viewAbstractModelNG.BindBackground(std::move(buildFunc), alignment);
1063 auto targetNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1064 ASSERT_NE(targetNode, nullptr);
1065 auto renderContext = targetNode->GetRenderContext();
1066 ASSERT_NE(renderContext, nullptr);
1067 auto backgroundAlign = renderContext->GetBackgroundAlign().value_or(Alignment::BOTTOM_CENTER);
1068 ASSERT_EQ(backgroundAlign, alignment);
1069
1070 /**
1071 * @tc.steps: step4. update background build func and alignment.
1072 * @tc.expected: background function and alignment is successfully set.
1073 */
1074 alignment = Alignment::TOP_CENTER;
1075 viewAbstractModelNG.BindBackground(std::move(buildFunc), alignment);
1076 backgroundAlign = renderContext->GetBackgroundAlign().value_or(Alignment::BOTTOM_CENTER);
1077 ASSERT_EQ(backgroundAlign, alignment);
1078 }
1079
1080 /**
1081 * @tc.name: ViewAbstractModelTestNg020
1082 * @tc.desc: Test the DismissSheet
1083 * @tc.type: FUNC
1084 */
1085 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg020, TestSize.Level1)
1086 {
1087 /**
1088 * @tc.steps: step1. setup environment.
1089 */
1090 MockPipelineContext::SetUp();
1091 RefPtr<FrameNode> stageMainNode = AceType::MakeRefPtr<FrameNode>("STAGE", -1, AceType::MakeRefPtr<Pattern>());
1092 ASSERT_NE(stageMainNode, nullptr);
1093 auto stageManager = AceType::MakeRefPtr<StageManager>(stageMainNode);
1094 MockPipelineContext::GetCurrent()->stageManager_ = stageManager;
1095 MockContainer::SetUp();
1096 MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1097 MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1098 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1099 ASSERT_NE(themeManager, nullptr);
__anonaaf173eb1e02(ThemeType type) 1100 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1101 if (type == SheetTheme::TypeId()) {
1102 return AceType::MakeRefPtr<SheetTheme>();
1103 } else {
1104 return nullptr;
1105 }
1106 });
1107 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1108
1109 /**
1110 * @tc.steps: step2. create target node.
1111 */
1112 auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1113 ElementRegister::GetInstance()->MakeUniqueId(),
__anonaaf173eb1f02() 1114 []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1115 ASSERT_NE(targetNode, nullptr);
1116 ViewStackProcessor::GetInstance()->Push(targetNode);
1117 auto stageNode = FrameNode::CreateFrameNode(
1118 V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1119 ASSERT_NE(stageNode, nullptr);
1120 auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
1121 ASSERT_NE(rootNode, nullptr);
1122 stageNode->MountToParent(rootNode);
1123 targetNode->MountToParent(stageNode);
1124 rootNode->MarkDirtyNode();
1125
1126 /**
1127 * @tc.steps: step3. create sheetNode, get sheetPattern.
1128 */
1129 bool isShow = true;
__anonaaf173eb2002() 1130 auto builderFunc = []() -> RefPtr<UINode> {
1131 auto frameNode =
1132 FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1133 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1134 CHECK_NULL_RETURN(frameNode, nullptr);
1135 auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1136 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1137 CHECK_NULL_RETURN(childFrameNode, nullptr);
1138 frameNode->AddChild(childFrameNode);
1139 return frameNode;
1140 };
__anonaaf173eb2302() 1141 auto buildTitleNodeFunc = []() -> RefPtr<UINode> {
1142 auto frameNode =
1143 FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1144 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1145 CHECK_NULL_RETURN(frameNode, nullptr);
1146 auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG,
1147 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<TextPattern>(); });
1148 CHECK_NULL_RETURN(childFrameNode, nullptr);
1149 frameNode->AddChild(childFrameNode);
1150 return frameNode;
1151 };
1152 SheetStyle sheetStyle;
1153 if (!sheetStyle.sheetHeight.sheetMode.has_value()) {
1154 sheetStyle.sheetHeight.sheetMode = SheetMode::MEDIUM;
1155 }
1156 if (!sheetStyle.showDragBar.has_value()) {
1157 sheetStyle.showDragBar = true;
1158 }
1159 auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
1160 ASSERT_NE(overlayManager, nullptr);
1161 overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle,
1162 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode);
1163 EXPECT_FALSE(overlayManager->modalStack_.empty());
1164
1165
1166 /**
1167 * @tc.steps: step4. set dismiss sheet id.
1168 */
1169 auto topSheetNode = overlayManager->modalStack_.top().Upgrade();
1170 ASSERT_NE(topSheetNode, nullptr);
1171 auto nodeId = topSheetNode->GetId();
1172 SheetManager::GetInstance().SetDismissSheet(nodeId);
1173 viewAbstractModelNG.DismissSheet();
1174 }
1175
1176 /**
1177 * @tc.name: ViewAbstractModelTestNg021
1178 * @tc.desc: Test the SheetSpringBack
1179 * @tc.type: FUNC
1180 */
1181 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg021, TestSize.Level1)
1182 {
1183 /**
1184 * @tc.steps: step1. setup environment.
1185 */
1186 MockPipelineContext::SetUp();
1187 RefPtr<FrameNode> stageMainNode = AceType::MakeRefPtr<FrameNode>("STAGE", -1, AceType::MakeRefPtr<Pattern>());
1188 ASSERT_NE(stageMainNode, nullptr);
1189 auto stageManager = AceType::MakeRefPtr<StageManager>(stageMainNode);
1190 MockPipelineContext::GetCurrent()->stageManager_ = stageManager;
1191 MockContainer::SetUp();
1192 MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1193 MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1194 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1195 ASSERT_NE(themeManager, nullptr);
__anonaaf173eb2602(ThemeType type) 1196 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1197 if (type == SheetTheme::TypeId()) {
1198 return AceType::MakeRefPtr<SheetTheme>();
1199 } else {
1200 return nullptr;
1201 }
1202 });
1203 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1204
1205 /**
1206 * @tc.steps: step2. create target node.
1207 */
1208 auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1209 ElementRegister::GetInstance()->MakeUniqueId(),
__anonaaf173eb2702() 1210 []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1211 ASSERT_NE(targetNode, nullptr);
1212 ViewStackProcessor::GetInstance()->Push(targetNode);
1213 auto stageNode = FrameNode::CreateFrameNode(
1214 V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1215 ASSERT_NE(stageNode, nullptr);
1216 auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
1217 ASSERT_NE(rootNode, nullptr);
1218 stageNode->MountToParent(rootNode);
1219 targetNode->MountToParent(stageNode);
1220 rootNode->MarkDirtyNode();
1221
1222 /**
1223 * @tc.steps: step3. create sheetNode, get sheetPattern.
1224 */
1225 bool isShow = true;
__anonaaf173eb2802() 1226 auto builderFunc = []() -> RefPtr<UINode> {
1227 auto frameNode =
1228 FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1229 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1230 CHECK_NULL_RETURN(frameNode, nullptr);
1231 auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1232 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1233 CHECK_NULL_RETURN(childFrameNode, nullptr);
1234 frameNode->AddChild(childFrameNode);
1235 return frameNode;
1236 };
__anonaaf173eb2b02() 1237 auto buildTitleNodeFunc = []() -> RefPtr<UINode> {
1238 auto frameNode =
1239 FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1240 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1241 CHECK_NULL_RETURN(frameNode, nullptr);
1242 auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG,
1243 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<TextPattern>(); });
1244 CHECK_NULL_RETURN(childFrameNode, nullptr);
1245 frameNode->AddChild(childFrameNode);
1246 return frameNode;
1247 };
1248 SheetStyle sheetStyle;
1249 if (!sheetStyle.sheetHeight.sheetMode.has_value()) {
1250 sheetStyle.sheetHeight.sheetMode = SheetMode::MEDIUM;
1251 }
1252 if (!sheetStyle.showDragBar.has_value()) {
1253 sheetStyle.showDragBar = true;
1254 }
1255 auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
1256 ASSERT_NE(overlayManager, nullptr);
1257 overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc), std::move(buildTitleNodeFunc), sheetStyle,
1258 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode);
1259 EXPECT_FALSE(overlayManager->modalStack_.empty());
1260
1261
1262 /**
1263 * @tc.steps: step4. set dismiss sheet id.
1264 */
1265 auto topSheetNode = overlayManager->modalStack_.top().Upgrade();
1266 ASSERT_NE(topSheetNode, nullptr);
1267 auto nodeId = topSheetNode->GetId();
1268 SheetManager::GetInstance().SetDismissSheet(nodeId);
1269 viewAbstractModelNG.SheetSpringBack();
1270 }
1271
1272 /**
1273 * @tc.name: ViewAbstractModelTestNg022
1274 * @tc.desc: Test the DismissContentCover
1275 * @tc.type: FUNC
1276 */
1277 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg022, TestSize.Level1)
1278 {
1279 /**
1280 * @tc.steps: step1. create target node.
1281 */
1282 auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1283 ElementRegister::GetInstance()->MakeUniqueId(),
__anonaaf173eb2e02() 1284 []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1285 ASSERT_NE(targetNode, nullptr);
1286 ViewStackProcessor::GetInstance()->Push(targetNode);
1287 auto stageNode = FrameNode::CreateFrameNode(
1288 V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1289 ASSERT_NE(stageNode, nullptr);
1290 auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
1291 ASSERT_NE(rootNode, nullptr);
1292 stageNode->MountToParent(rootNode);
1293 targetNode->MountToParent(stageNode);
1294 rootNode->MarkDirtyNode();
1295
1296 /**
1297 * @tc.steps: step2. setup environment.
1298 */
1299 MockPipelineContext::SetUp();
1300 RefPtr<FrameNode> stageMainNode = AceType::MakeRefPtr<FrameNode>("STAGE", -1, AceType::MakeRefPtr<Pattern>());
1301 ASSERT_NE(stageMainNode, nullptr);
1302 auto stageManager = AceType::MakeRefPtr<StageManager>(stageMainNode);
1303 MockPipelineContext::GetCurrent()->stageManager_ = stageManager;
1304 MockContainer::SetUp();
1305 MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1306 MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1307 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1308 ASSERT_NE(themeManager, nullptr);
__anonaaf173eb2f02(ThemeType type) 1309 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1310 if (type == SheetTheme::TypeId()) {
1311 return AceType::MakeRefPtr<SheetTheme>();
1312 } else {
1313 return nullptr;
1314 }
1315 });
1316 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1317
1318 /**
1319 * @tc.steps: step3. create modal page node.
1320 */
__anonaaf173eb3002() 1321 auto builderFunc = []() -> RefPtr<UINode> {
1322 auto frameNode =
1323 FrameNode::GetOrCreateFrameNode(V2::COLUMN_COMPONENT_TAG,
1324 ElementRegister::GetInstance()->MakeUniqueId(),
1325 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1326 CHECK_NULL_RETURN(frameNode, nullptr);
1327 auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1328 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1329 CHECK_NULL_RETURN(childFrameNode, nullptr);
1330 frameNode->AddChild(childFrameNode);
1331 return frameNode;
1332 };
1333
1334 /**
1335 * @tc.steps: step4. create modal node and call DismissContentCover.
1336 * @tc.expected: destroy modal page successfully
1337 */
1338 ModalStyle modalStyle;
1339 bool isShow = true;
1340 // auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
1341 auto container = MockContainer::Current();
1342 ASSERT_NE(container, nullptr);
1343 auto pipelineContext = container->GetPipelineContext();
1344 ASSERT_NE(pipelineContext, nullptr);
1345 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
1346 ASSERT_NE(context, nullptr);
1347 auto overlayManager = context->GetOverlayManager();
1348 ASSERT_NE(overlayManager, nullptr);
1349 overlayManager->OnBindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr,
1350 nullptr, ContentCoverParam(), targetNode);
1351 EXPECT_FALSE(overlayManager->modalStack_.empty());
1352 auto topModalNode = overlayManager->modalStack_.top().Upgrade();
1353 ASSERT_NE(topModalNode, nullptr);
1354 auto topModalPattern = topModalNode->GetPattern<ModalPresentationPattern>();
1355 ASSERT_NE(topModalPattern, nullptr);
1356 auto targetId = topModalPattern->GetTargetId();
1357 overlayManager->SetDismissTarget(DismissTarget(targetId));
1358 viewAbstractModelNG.DismissContentCover();
1359 EXPECT_TRUE(overlayManager->modalStack_.empty());
1360 }
1361
1362 /**
1363 * @tc.name: ViewAbstractModelTestNg023
1364 * @tc.desc: Test the BindContentCover
1365 * @tc.type: FUNC
1366 */
1367 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg023, TestSize.Level1)
1368 {
1369 /**
1370 * @tc.steps: step1. create target node.
1371 */
1372 auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1373 ElementRegister::GetInstance()->MakeUniqueId(),
__anonaaf173eb3302() 1374 []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1375 ASSERT_NE(targetNode, nullptr);
1376 ViewStackProcessor::GetInstance()->Push(targetNode);
1377 auto stageNode = FrameNode::CreateFrameNode(
1378 V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1379 ASSERT_NE(stageNode, nullptr);
1380 auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
1381 ASSERT_NE(rootNode, nullptr);
1382 stageNode->MountToParent(rootNode);
1383 targetNode->MountToParent(stageNode);
1384 rootNode->MarkDirtyNode();
1385
1386 /**
1387 * @tc.steps: step2. setup environment.
1388 */
1389 MockPipelineContext::SetUp();
1390 RefPtr<FrameNode> stageMainNode = AceType::MakeRefPtr<FrameNode>("STAGE", -1, AceType::MakeRefPtr<Pattern>());
1391 ASSERT_NE(stageMainNode, nullptr);
1392 auto stageManager = AceType::MakeRefPtr<StageManager>(stageMainNode);
1393 MockPipelineContext::GetCurrent()->stageManager_ = stageManager;
1394 MockContainer::SetUp();
1395 MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1396 MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1397 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1398 ASSERT_NE(themeManager, nullptr);
__anonaaf173eb3402(ThemeType type) 1399 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1400 if (type == SheetTheme::TypeId()) {
1401 return AceType::MakeRefPtr<SheetTheme>();
1402 } else {
1403 return nullptr;
1404 }
1405 });
1406 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1407
1408 /**
1409 * @tc.steps: step3. create modal page node.
1410 */
__anonaaf173eb3502() 1411 auto builderFunc = []() -> RefPtr<UINode> {
1412 auto frameNode =
1413 FrameNode::GetOrCreateFrameNode(V2::COLUMN_COMPONENT_TAG,
1414 ElementRegister::GetInstance()->MakeUniqueId(),
1415 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
1416 CHECK_NULL_RETURN(frameNode, nullptr);
1417 auto childFrameNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
1418 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
1419 CHECK_NULL_RETURN(childFrameNode, nullptr);
1420 frameNode->AddChild(childFrameNode);
1421 return frameNode;
1422 };
1423
1424 /**
1425 * @tc.steps: step4. create modal node and get modal node, get pattern.
1426 * @tc.expected: related flag is false.
1427 */
1428 ModalStyle modalStyle;
1429 bool isShow = true;
__anonaaf173eb3802(int32_t info) 1430 std::function<void(int32_t info)> onWillDismiss = [](int32_t info) {};
1431 RefPtr<NG::ChainedTransitionEffect> effect = AceType::MakeRefPtr<NG::ChainedOpacityEffect>(1.0);
1432 // auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
1433 auto container = MockContainer::Current();
1434 ASSERT_NE(container, nullptr);
1435 auto pipelineContext = container->GetPipelineContext();
1436 ASSERT_NE(pipelineContext, nullptr);
1437 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
1438 ASSERT_NE(context, nullptr);
1439 auto overlayManager = context->GetOverlayManager();
1440 ASSERT_NE(overlayManager, nullptr);
1441 overlayManager->OnBindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr, nullptr,
1442 nullptr, ContentCoverParam(), targetNode);
1443 EXPECT_FALSE(overlayManager->modalStack_.empty());
1444 auto topModalNode = overlayManager->modalStack_.top().Upgrade();
1445 ASSERT_NE(topModalNode, nullptr);
1446 auto topModalPattern = topModalNode->GetPattern<ModalPresentationPattern>();
1447 ASSERT_NE(topModalPattern, nullptr);
1448 EXPECT_EQ(topModalPattern->HasOnWillDismiss(), false);
1449 EXPECT_EQ(topModalPattern->HasTransitionEffect(), false);
1450
1451 /**
1452 * @tc.steps: step5. create modal node and call BindContentCover.
1453 * @tc.expected: related flag is true.
1454 */
1455 ContentCoverParam contentCoverParam;
1456 contentCoverParam.onWillDismiss = onWillDismiss;
1457 contentCoverParam.transitionEffect = std::move(effect);
1458 viewAbstractModelNG.BindContentCover(isShow, nullptr, std::move(builderFunc), modalStyle, nullptr, nullptr,
1459 nullptr, nullptr, contentCoverParam);
1460 topModalNode = overlayManager->modalStack_.top().Upgrade();
1461 topModalPattern = topModalNode->GetPattern<ModalPresentationPattern>();
1462 EXPECT_EQ(topModalPattern->HasOnWillDismiss(), true);
1463 EXPECT_EQ(topModalPattern->HasTransitionEffect(), true);
1464 }
1465
1466 /**
1467 * @tc.name: SetBackgroundOptions001
1468 * @tc.desc: Test the background options
1469 * @tc.type: FUNC
1470 */
1471 HWTEST_F(ViewAbstractModelTestNg, SetBackgroundOptions001, TestSize.Level1)
1472 {
1473 /**
1474 * @tc.steps: step1. create main frame node and push into view abstract.
1475 */
1476 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1477 ASSERT_NE(mainNode, nullptr);
1478 ViewStackProcessor::GetInstance()->Push(mainNode);
1479
1480 /**
1481 * @tc.steps: step2. init theme, pipeline and container.
1482 */
1483 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1484 ASSERT_NE(themeManager, nullptr);
__anonaaf173eb3902(ThemeType type) 1485 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1486 if (type == SheetTheme::TypeId()) {
1487 return AceType::MakeRefPtr<SheetTheme>();
1488 } else {
1489 return nullptr;
1490 }
1491 });
1492 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1493 auto container = Container::Current();
1494 ASSERT_NE(container, nullptr);
1495 auto pipelineContext = container->GetPipelineContext();
1496 ASSERT_NE(pipelineContext, nullptr);
1497 auto containerId = pipelineContext->GetInstanceId();
1498 AceEngine& aceEngine = AceEngine::Get();
1499 aceEngine.AddContainer(containerId, MockContainer::container_);
1500
1501 /**
1502 * @tc.steps: step3. init background build func and alignment.
1503 * @tc.expected: background function is successfully set.
1504 */
1505 auto mainFrameNode = AceType::WeakClaim(ViewStackProcessor::GetInstance()->GetMainFrameNode());
1506 Alignment alignment = Alignment::CENTER;
__anonaaf173eb3a02() 1507 auto buildFunc = [mainFrameNode]() { flag++; };
1508 viewAbstractModelNG.SetBackground(std::move(buildFunc));
1509 auto targetNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1510 ASSERT_NE(targetNode, nullptr);
1511 EXPECT_NE(targetNode->builderFunc_, nullptr);
1512
1513 /**
1514 * @tc.steps: step4. update background alignment.
1515 * @tc.expected: background alignment is successfully set.
1516 */
1517 auto renderContext = targetNode->GetRenderContext();
1518 ASSERT_NE(renderContext, nullptr);
1519 alignment = Alignment::TOP_CENTER;
1520 viewAbstractModelNG.SetBackgroundAlign(alignment);
1521 auto backgroundAlign = renderContext->GetBackgroundAlign().value_or(Alignment::BOTTOM_CENTER);
1522 EXPECT_EQ(backgroundAlign, alignment);
1523
1524 /**
1525 * @tc.steps: step5. update background color.
1526 * @tc.expected: background alignment is successfully set.
1527 */
1528 Color color = Color::BLUE;
1529 viewAbstractModelNG.SetCustomBackgroundColor(color);
1530 auto customBackgroundColor = renderContext->GetCustomBackgroundColor().value_or(Color::TRANSPARENT);
1531 EXPECT_EQ(customBackgroundColor.GetValue(), color.GetValue());
1532
1533 /**
1534 * @tc.steps: step6. update background flags.
1535 * @tc.expected: background flags is successfully set.
1536 */
1537 viewAbstractModelNG.SetIsTransitionBackground(true);
1538 EXPECT_TRUE(renderContext->GetIsTransitionBackground().value_or(false));
1539 viewAbstractModelNG.SetIsBuilderBackground(true);
1540 EXPECT_TRUE(renderContext->GetBuilderBackgroundFlag().value_or(false));
1541
1542 /**
1543 * @tc.steps: step7. update background ignoresLayoutSafeAreaEdges.
1544 * @tc.expected: background ignoresLayoutSafeAreaEdges is successfully set.
1545 */
1546 viewAbstractModelNG.SetBackgroundIgnoresLayoutSafeAreaEdges(NG::LAYOUT_SAFE_AREA_EDGE_ALL);
1547 auto layoutProp = targetNode->GetLayoutProperty();
1548 ASSERT_NE(layoutProp, nullptr);
1549 EXPECT_EQ(layoutProp->GetBackgroundIgnoresLayoutSafeAreaEdges(), NG::LAYOUT_SAFE_AREA_EDGE_ALL);
1550 }
1551
1552 /**
1553 * @tc.name: SetAccessibilitySelected001
1554 * @tc.desc: Test the SetAccessibilitySelected
1555 * @tc.type: FUNC
1556 */
1557 HWTEST_F(ViewAbstractModelTestNg, SetAccessibilitySelected001, TestSize.Level1)
1558 {
1559 bool selected = true;
1560 bool resetValue = true;
1561 std::string tag = "uiNode1";
1562 int32_t nodeId = 1;
1563 auto frameNode = FrameNode::CreateFrameNode(
1564 tag, nodeId, AceType::MakeRefPtr<Pattern>());
1565 NG::ViewStackProcessor::GetInstance()->elementsStack_.push(frameNode);
1566 viewAbstractModelNG.SetAccessibilitySelected(selected, resetValue);
1567 EXPECT_FALSE(
1568 NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()->accessibilityProperty_->isSelected_.has_value());
1569
1570 resetValue = false;
1571 viewAbstractModelNG.SetAccessibilitySelected(selected, resetValue);
1572 EXPECT_EQ(
1573 NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()->accessibilityProperty_->isSelected_, selected);
1574 }
1575
1576 /**
1577 * @tc.name: SetAccessibilityChecked001
1578 * @tc.desc: Test the SetAccessibilityChecked
1579 * @tc.type: FUNC
1580 */
1581 HWTEST_F(ViewAbstractModelTestNg, SetAccessibilityChecked001, TestSize.Level1)
1582 {
1583 bool checked = true;
1584 bool resetValue = true;
1585 std::string tag = "uiNode1";
1586 int32_t nodeId = 1;
1587 auto frameNode = FrameNode::CreateFrameNode(
1588 tag, nodeId, AceType::MakeRefPtr<Pattern>());
1589 NG::ViewStackProcessor::GetInstance()->elementsStack_.push(frameNode);
1590 viewAbstractModelNG.SetAccessibilityChecked(checked, resetValue);
1591 EXPECT_FALSE(
1592 NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()->accessibilityProperty_->checkedType_.has_value());
1593
1594 resetValue = false;
1595 viewAbstractModelNG.SetAccessibilityChecked(checked, resetValue);
1596 EXPECT_EQ(
1597 NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()->accessibilityProperty_->checkedType_, checked);
1598 }
1599
1600 /**
1601 * @tc.name: SetAccessibilityScrollTriggerable001
1602 * @tc.desc: Test the SetAccessibilityScrollTriggerable
1603 * @tc.type: FUNC
1604 */
1605 HWTEST_F(ViewAbstractModelTestNg, SetAccessibilityScrollTriggerable001, TestSize.Level1)
1606 {
1607 bool triggerable = true;
1608 bool resetValue = true;
1609 std::string tag = "uiNode1";
1610 int32_t nodeId = 1;
1611 auto frameNode = FrameNode::CreateFrameNode(
1612 tag, nodeId, AceType::MakeRefPtr<Pattern>());
1613 NG::ViewStackProcessor::GetInstance()->elementsStack_.push(frameNode);
1614 viewAbstractModelNG.SetAccessibilityScrollTriggerable(triggerable, resetValue);
1615 EXPECT_TRUE(
1616 NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()->accessibilityProperty_->isUserScrollTriggerable_);
1617
1618 resetValue = false;
1619 viewAbstractModelNG.SetAccessibilityScrollTriggerable(triggerable, resetValue);
1620 EXPECT_TRUE(
1621 NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()->accessibilityProperty_->isUserScrollTriggerable_);
1622 }
1623
1624 /**
1625 * @tc.name: SetAccessibilityRole001
1626 * @tc.desc: Test the SetAccessibilityRole
1627 * @tc.type: FUNC
1628 */
1629 HWTEST_F(ViewAbstractModelTestNg, SetAccessibilityRole001, TestSize.Level1)
1630 {
1631 std::string role = "testRole";
1632 bool resetValue = true;
1633 std::string tag = "uiNode1";
1634 int32_t nodeId = 1;
1635 auto frameNode = FrameNode::CreateFrameNode(
1636 tag, nodeId, AceType::MakeRefPtr<Pattern>());
1637 NG::ViewStackProcessor::GetInstance()->elementsStack_.push(frameNode);
1638 viewAbstractModelNG.SetAccessibilityRole(role, resetValue);
1639 EXPECT_EQ(
1640 NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()->accessibilityProperty_->accessibilityCustomRole_,
1641 "");
1642
1643 resetValue = false;
1644 viewAbstractModelNG.SetAccessibilityRole(role, resetValue);
1645 EXPECT_EQ(
1646 NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()->accessibilityProperty_->accessibilityCustomRole_,
1647 role);
1648 }
1649
1650 /**
1651 * @tc.name: SetAccessibilityUseSamePage001
1652 * @tc.desc: Test the SetAccessibilityUseSamePage
1653 * @tc.type: FUNC
1654 */
1655 HWTEST_F(ViewAbstractModelTestNg, SetAccessibilityUseSamePage001, TestSize.Level1)
1656 {
1657 std::string tag = "uiNode1";
1658 std::string pageMode = "pageMode";
1659 int32_t nodeId = 1;
1660 FrameNode frameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
1661 frameNode.accessibilityProperty_->SetAccessibilitySamePage(pageMode);
1662
1663 viewAbstractModelNG.SetAccessibilityUseSamePage(&frameNode, pageMode);
1664 EXPECT_EQ(frameNode.accessibilityProperty_->accessibilityUseSamePage_, pageMode);
1665
1666 pageMode = "testMode";
1667 viewAbstractModelNG.SetAccessibilityUseSamePage(&frameNode, pageMode);
1668 EXPECT_EQ(frameNode.accessibilityProperty_->accessibilityUseSamePage_, pageMode);
1669 }
1670
1671 /**
1672 * @tc.name: SetAccessibilitySelected002
1673 * @tc.desc: Test the SetAccessibilitySelected
1674 * @tc.type: FUNC
1675 */
1676 HWTEST_F(ViewAbstractModelTestNg, SetAccessibilitySelected002, TestSize.Level1)
1677 {
1678 std::string tag = "uiNode1";
1679 bool selected = true;
1680 bool resetValue = true;
1681 int32_t nodeId = 1;
1682 FrameNode frameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
1683 frameNode.accessibilityProperty_->SetUserSelected(selected);
1684
1685 viewAbstractModelNG.SetAccessibilitySelected(&frameNode, selected, resetValue);
1686 EXPECT_EQ(frameNode.accessibilityProperty_->isSelected_.has_value(), false);
1687
1688 resetValue = false;
1689 viewAbstractModelNG.SetAccessibilitySelected(&frameNode, selected, resetValue);
1690 EXPECT_EQ(frameNode.accessibilityProperty_->isSelected_, selected);
1691 }
1692
1693 /**
1694 * @tc.name: SetAccessibilityChecked002
1695 * @tc.desc: Test the SetAccessibilityChecked
1696 * @tc.type: FUNC
1697 */
1698 HWTEST_F(ViewAbstractModelTestNg, SetAccessibilityChecked002, TestSize.Level1)
1699 {
1700 std::string tag = "uiNode1";
1701 bool checked = true;
1702 bool resetValue = true;
1703 int32_t nodeId = 1;
1704 FrameNode frameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
1705
1706 frameNode.accessibilityProperty_->SetUserCheckedType(checked);
1707 viewAbstractModelNG.SetAccessibilityChecked(&frameNode, checked, resetValue);
1708 EXPECT_EQ(frameNode.accessibilityProperty_->checkedType_.has_value(), false);
1709
1710 resetValue = false;
1711 viewAbstractModelNG.SetAccessibilityChecked(&frameNode, checked, resetValue);
1712 EXPECT_EQ(frameNode.accessibilityProperty_->checkedType_, checked);
1713 }
1714
1715 /**
1716 * @tc.name: SetAccessibilityScrollTriggerable002
1717 * @tc.desc: Test the SetAccessibilityScrollTriggerable
1718 * @tc.type: FUNC
1719 */
1720 HWTEST_F(ViewAbstractModelTestNg, SetAccessibilityScrollTriggerable002, TestSize.Level1)
1721 {
1722 std::string tag = "uiNode1";
1723 bool triggerable = false;
1724 bool resetValue = true;
1725 int32_t nodeId = 1;
1726 FrameNode frameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
1727 frameNode.accessibilityProperty_->SetUserScrollTriggerable(triggerable);
1728 viewAbstractModelNG.SetAccessibilityScrollTriggerable(&frameNode, triggerable, resetValue);
1729 EXPECT_NE(frameNode.accessibilityProperty_->isUserScrollTriggerable_, triggerable);
1730
1731 resetValue = false;
1732 viewAbstractModelNG.SetAccessibilityScrollTriggerable(&frameNode, triggerable, resetValue);
1733 EXPECT_EQ(frameNode.accessibilityProperty_->isUserScrollTriggerable_, triggerable);
1734 }
1735
1736 /**
1737 * @tc.name: SetAccessibilityRole002
1738 * @tc.desc: Test the SetAccessibilityRole
1739 * @tc.type: FUNC
1740 */
1741 HWTEST_F(ViewAbstractModelTestNg, SetAccessibilityRole002, TestSize.Level1)
1742 {
1743 std::string tag = "uiNode1";
1744 std::string role = "testRole";
1745 bool resetValue = true;
1746 int32_t nodeId = 1;
1747 FrameNode frameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
1748 frameNode.accessibilityProperty_->SetAccessibilityCustomRole(role);
1749 viewAbstractModelNG.SetAccessibilityRole(&frameNode, role, resetValue);
1750 EXPECT_NE(frameNode.accessibilityProperty_->accessibilityCustomRole_, role);
1751
1752 resetValue = false;
1753 viewAbstractModelNG.SetAccessibilityRole(&frameNode, role, resetValue);
1754 EXPECT_EQ(frameNode.accessibilityProperty_->accessibilityCustomRole_, role);
1755 }
1756
1757 /**
1758 * @tc.name: SetAccessibilityTextHint001
1759 * @tc.desc: Test the SetAccessibilityTextHint
1760 * @tc.type: FUNC
1761 */
1762 HWTEST_F(ViewAbstractModelTestNg, SetAccessibilityTextHint001, TestSize.Level1)
1763 {
1764 std::string tag = "uiNode1";
1765 int32_t nodeId = 1;
1766 FrameNode frameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
1767 auto accessibilityProperty = frameNode.GetAccessibilityProperty<NG::AccessibilityProperty>();
1768 ASSERT_NE(accessibilityProperty, nullptr);
1769 accessibilityProperty->SetAccessibilityTextHint(TEST_TEXT_HINT);
1770
1771 viewAbstractModelNG.SetAccessibilityTextHint(&frameNode, "");
1772 EXPECT_EQ(accessibilityProperty->textTypeHint_, "");
1773
1774 viewAbstractModelNG.SetAccessibilityTextHint(&frameNode, TEST_TEXT_HINT);
1775 EXPECT_EQ(accessibilityProperty->textTypeHint_, TEST_TEXT_HINT);
1776 }
1777
1778 /**
1779 * @tc.name: SetToolbarBuilder
1780 * @tc.desc: Test the SetToolbarBuilder
1781 * @tc.type: FUNC
1782 */
1783 HWTEST_F(ViewAbstractModelTestNg, SetToolbarBuilder001, TestSize.Level1)
1784 {
1785 auto pipeline = AceType::DynamicCast<PipelineContext>(MockPipelineContext::GetCurrent());
1786 auto rootNode = pipeline->rootNode_;
1787 ASSERT_NE(rootNode, nullptr);
1788
1789 auto containerModalNode =
1790 FrameNode::CreateFrameNode("ContainerModal", 1, AceType::MakeRefPtr<ContainerModalPattern>());
1791 rootNode->AddChild(containerModalNode, 0);
1792 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true);
1793 ASSERT_NE(mainNode, nullptr);
1794 ViewStackProcessor::GetInstance()->Push(mainNode);
1795 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1796 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1797 auto theme = AceType::MakeRefPtr<SelectTheme>();
1798 theme->expandDisplay_ = true;
1799 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
1800 auto container = Container::Current();
1801 ASSERT_NE(container, nullptr);
1802 viewAbstractModelNG.SetToolbarBuilder(nullptr);
1803 bool ret = mainNode->removeToolbarItemCallbacks_.size() > 0;
1804 EXPECT_FALSE(ret);
1805 rootNode->RemoveChild(containerModalNode);
1806 }
1807
1808 /**
1809 * @tc.name: SetToolbarBuilder
1810 * @tc.desc: Test the SetToolbarBuilder
1811 * @tc.type: FUNC
1812 */
1813 HWTEST_F(ViewAbstractModelTestNg, SetToolbarBuilder002, TestSize.Level1)
1814 {
1815 auto pipeline = AceType::DynamicCast<PipelineContext>(MockPipelineContext::GetCurrent());
1816 auto rootNode = pipeline->rootNode_;
1817 ASSERT_NE(rootNode, nullptr);
1818
1819 auto containerModalNode =
1820 FrameNode::CreateFrameNode("ContainerModal", 1, AceType::MakeRefPtr<ContainerModalPattern>());
1821 rootNode->AddChild(containerModalNode, 0);
1822 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true);
1823 ASSERT_NE(mainNode, nullptr);
1824 ViewStackProcessor::GetInstance()->Push(mainNode);
1825 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1826 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1827 auto theme = AceType::MakeRefPtr<SelectTheme>();
1828 theme->expandDisplay_ = true;
1829 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
1830 auto container = Container::Current();
1831 ASSERT_NE(container, nullptr);
1832
__anonaaf173eb3b02() 1833 auto builderFunc = []() -> RefPtr<UINode> {
1834 auto* stack = ViewStackProcessor::GetInstance();
1835 auto frameNode = FrameNode::GetOrCreateFrameNode(
1836 V2::TOOLBAR_ETS_TAG, 11, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(false); });
1837 if (stack) {
1838 stack->Push(frameNode);
1839 }
1840 return frameNode ? frameNode : nullptr;
1841 };
1842 viewAbstractModelNG.SetToolbarBuilder(std::move(builderFunc));
1843 bool ret = mainNode->removeToolbarItemCallbacks_.size() > 0;
1844 EXPECT_TRUE(ret);
1845 rootNode->RemoveChild(containerModalNode);
1846 }
1847
1848 /**
1849 * @tc.name: BindContextMenuTest2
1850 * @tc.desc: Test the BindContextMenu
1851 * @tc.type: FUNC
1852 */
1853 HWTEST_F(ViewAbstractModelTestNg, BindContextMenuTest2, TestSize.Level1)
1854 {
1855 std::function<void()> buildFunc = nullptr;
1856 std::function<void()> previewBuildFunc = nullptr;
1857 MenuParam menuParam;
1858 menuParam.contextMenuRegisterType = ContextMenuRegisterType::NORMAL_TYPE;
1859 menuParam.anchorPosition = {10, 20};
1860 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
1861 EXPECT_NE(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
1862
1863 viewAbstractModelNG.BindContextMenu(ResponseType::LONG_PRESS, buildFunc, menuParam, previewBuildFunc);
1864 EXPECT_NE(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
1865 }
1866
1867 /**
1868 * @tc.name: BindMenuTest
1869 * @tc.desc: Test the BindMenu
1870 * @tc.type: FUNC
1871 */
1872 HWTEST_F(ViewAbstractModelTestNg, BindMenuTest, TestSize.Level1)
1873 {
1874 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1875 ASSERT_NE(mainNode, nullptr);
1876 ViewStackProcessor::GetInstance()->Push(mainNode);
1877 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1878 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1879 auto theme = AceType::MakeRefPtr<SelectTheme>();
1880 ASSERT_NE(theme, nullptr);
1881 theme->expandDisplay_ = true;
1882 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
1883 auto container = Container::Current();
1884 ASSERT_NE(container, nullptr);
1885 auto pipelineContext = container->GetPipelineContext();
1886 ASSERT_NE(pipelineContext, nullptr);
1887 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
1888
1889 std::vector<NG::OptionParam> params = {};
1890 std::function<void()> buildFunc;
1891 MenuParam menuParam;
1892 menuParam.setShow = true;
1893 menuParam.anchorPosition = {10, 20};
1894 menuParam.isShow = true;
1895 menuParam.isShowInSubWindow = true;
__anonaaf173eb3d02() 1896 buildFunc = []() { flag++; };
1897 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
1898 EXPECT_NE(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode(), nullptr);
1899
1900 params.push_back(OptionParam());
1901 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
1902 EXPECT_NE(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode(), nullptr);
1903 }
1904
1905 /**
1906 * @tc.name: BindDragWithContextMenuParamsTest003
1907 * @tc.desc: Verify IsNotNeedShowPreview returns correct result for different menu binding combinations.
1908 * @tc.type: FUNC
1909 */
1910 HWTEST_F(ViewAbstractModelTestNg, BindDragWithContextMenuParamsTest003, TestSize.Level1)
1911 {
1912 std::string tag = "uiNode3";
1913 FrameNode frameNode(tag, TEST_NODE_ID, AceType::MakeRefPtr<Pattern>());
1914 auto gestureHub = frameNode.GetOrCreateGestureEventHub();
1915 ASSERT_NE(gestureHub, nullptr);
1916
1917 /**
1918 * @tc.steps: step1. Set isBindCustomMenu = true, isShow = true
1919 * @tc.expected: IsNotNeedShowPreview returns true
1920 */
1921 gestureHub->SetBindMenuStatus(true, true, MenuPreviewMode::IMAGE);
1922 auto bindStatus1 = gestureHub->GetBindMenuStatus();
1923 EXPECT_TRUE(bindStatus1.IsNotNeedShowPreview());
1924
1925 /**
1926 * @tc.steps: step2. Set isBindCustomMenu = true, isShow = false
1927 * @tc.expected: IsNotNeedShowPreview returns false
1928 */
1929 gestureHub->SetBindMenuStatus(true, false, MenuPreviewMode::CUSTOM);
1930 auto bindStatus2 = gestureHub->GetBindMenuStatus();
1931 EXPECT_FALSE(bindStatus2.IsNotNeedShowPreview());
1932
1933 /**
1934 * @tc.steps: step3. Set isBindLongPressMenu = true
1935 * @tc.expected: IsNotNeedShowPreview returns true
1936 */
1937 gestureHub->SetBindMenuStatus(false, false, MenuPreviewMode::CUSTOM);
1938 auto bindStatus3 = gestureHub->GetBindMenuStatus();
1939 EXPECT_TRUE(bindStatus3.IsNotNeedShowPreview());
1940
1941 /**
1942 * @tc.steps: step4. Clear state and verify IsNotNeedShowPreview returns false
1943 * @tc.expected: IsNotNeedShowPreview returns false
1944 */
1945 gestureHub->SetBindMenuStatus(false, false, MenuPreviewMode::NONE);
1946 gestureHub->bindMenuStatus_.isBindCustomMenu = false;
1947 gestureHub->bindMenuStatus_.isBindLongPressMenu = false;
1948 auto bindStatus4 = gestureHub->GetBindMenuStatus();
1949 EXPECT_FALSE(bindStatus4.IsNotNeedShowPreview());
1950 }
1951
1952 /**
1953 * @tc.name: CheckSkipMenuShowTest
1954 * @tc.desc: Test the CheckSkipMenuShow
1955 * @tc.type: FUNC
1956 */
1957 HWTEST_F(ViewAbstractModelTestNg, CheckSkipMenuShowTest, TestSize.Level1)
1958 {
1959 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1960 ASSERT_NE(mainNode, nullptr);
1961 ViewStackProcessor::GetInstance()->Push(mainNode);
1962 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1963 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1964 auto theme = AceType::MakeRefPtr<SelectTheme>();
1965 ASSERT_NE(theme, nullptr);
1966 theme->expandDisplay_ = true;
1967 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
1968 auto container = Container::Current();
1969 ASSERT_NE(container, nullptr);
1970 auto pipelineContext = container->GetPipelineContext();
1971 ASSERT_NE(pipelineContext, nullptr);
1972 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
1973 /**
1974 * @tc.expected: CheckSkipMenuShow returns false
1975 */
1976 auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
1977 ASSERT_NE(targetNode, nullptr);
1978 EXPECT_FALSE(viewAbstractModelNG.CheckSkipMenuShow(targetNode));
1979 }
1980
1981 /**
1982 * @tc.name: CheckMenuIsShowTest001
1983 * @tc.desc: Test the CheckMenuIsShow
1984 * @tc.type: FUNC
1985 */
1986 HWTEST_F(ViewAbstractModelTestNg, CheckMenuIsShowTest001, TestSize.Level1)
1987 {
1988 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1989 ASSERT_NE(mainNode, nullptr);
1990 ViewStackProcessor::GetInstance()->Push(mainNode);
1991 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1992 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1993 auto theme = AceType::MakeRefPtr<SelectTheme>();
1994 ASSERT_NE(theme, nullptr);
1995 theme->expandDisplay_ = true;
1996 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
1997 auto container = Container::Current();
1998 ASSERT_NE(container, nullptr);
1999 auto pipelineContext = container->GetPipelineContext();
2000 ASSERT_NE(pipelineContext, nullptr);
2001 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
2002
2003 /**
2004 * @tc.steps: step1. Set setShow = true, isShow = false
2005 * @tc.expected: CheckMenuIsShow returns true
2006 */
2007 MenuParam menuParam;
2008 menuParam.hasTransitionEffect = true;
2009 menuParam.setShow = true;
2010 menuParam.isShow = false;
2011 auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
2012 ASSERT_NE(targetNode, nullptr);
2013 auto targetId = targetNode->GetId();
2014 EXPECT_TRUE(viewAbstractModelNG.CheckMenuIsShow(menuParam, targetId, targetNode));
2015 }
2016
2017 /**
2018 * @tc.name: PopupTypeStrTest001
2019 * @tc.desc: Test the PopupTypeStr
2020 * @tc.type: FUNC
2021 */
2022 HWTEST_F(ViewAbstractModelTestNg, PopupTypeStrTest001, TestSize.Level1)
2023 {
2024 auto type = PopupType::POPUPTYPE_TEXTCOLOR;
2025 EXPECT_EQ(viewAbstractModelNG.PopupTypeStr(type), "TextColor");
2026
2027 type = PopupType::POPUPTYPE_POPUPCOLOR;
2028 EXPECT_EQ(viewAbstractModelNG.PopupTypeStr(type), "PopupColor");
2029
2030 type = PopupType::POPUPTYPE_MASKCOLOR;
2031 EXPECT_EQ(viewAbstractModelNG.PopupTypeStr(type), "MaskColor");
2032 }
2033
2034 /**
2035 * @tc.name: BindDragWithContextMenuParamsTest001
2036 * @tc.desc: Test the BindDragWithContextMenuParams
2037 * @tc.type: FUNC
2038 */
2039 HWTEST_F(ViewAbstractModelTestNg, BindDragWithContextMenuParamsTest001, TestSize.Level1)
2040 {
2041 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
2042 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
2043 ASSERT_NE(pageNode, nullptr);
2044 auto column = FrameNode::CreateFrameNode(
2045 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
2046 ASSERT_NE(column, nullptr);
2047 auto navDestinaion = FrameNode::CreateFrameNode(V2::NAVDESTINATION_VIEW_ETS_TAG,
2048 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<NavDestinationPattern>());
2049 ASSERT_NE(navDestinaion, nullptr);
2050 auto targetNode = FrameNode::CreateFrameNode(
2051 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
2052 ASSERT_NE(targetNode, nullptr);
2053 targetNode->MountToParent(navDestinaion);
2054 targetNode->SetRootNodeId(1);
2055 navDestinaion->MountToParent(column);
2056 column->MountToParent(pageNode);
2057 ViewStackProcessor::GetInstance()->Push(targetNode);
2058 /**
2059 * @tc.steps: step1. Set contextMenuRegisterType = CUSTOM_TYPE, menuBindType = RIGHT_CLICK
2060 * @tc.expected: isBindCustomMenu returns true
2061 */
2062 MenuParam menuParam;
2063 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
2064 menuParam.menuBindType = MenuBindingType::RIGHT_CLICK;
2065 viewAbstractModelNG.BindDragWithContextMenuParams(menuParam);
2066 EXPECT_EQ(targetNode->GetOrCreateGestureEventHub()->bindMenuStatus_.isBindCustomMenu, true);
2067 }
2068
2069 /**
2070 * @tc.name: BindContextMenuTest001
2071 * @tc.desc: Test the BindContextMenu
2072 */
2073 HWTEST_F(ViewAbstractModelTestNg, BindContextMenuTest001, TestSize.Level1)
2074 {
2075 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2076 ASSERT_NE(mainNode, nullptr);
2077 ViewStackProcessor::GetInstance()->Push(mainNode);
2078 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
2079 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
2080 auto theme = AceType::MakeRefPtr<SelectTheme>();
2081 theme->expandDisplay_ = false;
2082 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
2083 auto container = Container::Current();
2084 ASSERT_NE(container, nullptr);
2085 auto pipelineContext = container->GetPipelineContext();
2086 ASSERT_NE(pipelineContext, nullptr);
2087 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
2088 ASSERT_NE(context, nullptr);
2089 auto containerId = pipelineContext->GetInstanceId();
2090 AceEngine& aceEngine = AceEngine::Get();
2091 aceEngine.AddContainer(containerId, MockContainer::container_);
2092 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
2093
2094 MenuParam menuParam;
2095 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
2096 menuParam.isShow = false;
2097 menuParam.menuBindType = MenuBindingType::RIGHT_CLICK;
2098 std::function<void()> buildFunc;
2099 std::function<void()> previewBuildFunc = nullptr;
2100 auto type = ResponseType::RIGHT_CLICK;
__anonaaf173eb3e02() 2101 buildFunc = []() { flag++; };
2102
2103 /**
2104 * @tc.steps: step1. Set isShow = false, menuBindType = RIGHT_CLICK
2105 * @tc.expected: subwindow is not nullptr
2106 */
2107 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
2108 EXPECT_NE(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
2109
2110 /**
2111 * @tc.steps: step1. Set isShow = true, menuBindType = RIGHT_CLICK
2112 * @tc.expected: subwindow is not nullptr
2113 */
2114 menuParam.isShow = true;
2115 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
2116 EXPECT_NE(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
2117 }
2118 } // namespace OHOS::Ace::NG
2119