1 /*
2 * Copyright (c) 2024 iSoftStone Information Technology (Group) Co.,Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "gtest/gtest.h"
16 #define protected public
17 #define private public
18
19 #include "test/mock/base/mock_subwindow.h"
20 #include "test/mock/base/mock_task_executor.h"
21 #include "test/mock/core/common/mock_container.h"
22 #include "test/mock/core/common/mock_theme_manager.h"
23 #include "test/mock/core/pipeline/mock_pipeline_context.h"
24
25 #include "base/memory/referenced.h"
26 #include "core/common/ace_engine.h"
27 #include "core/components_ng/base/view_abstract_model_ng.h"
28 #include "core/components_ng/pattern/menu/menu_view.h"
29 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
30 #include "core/components_ng/pattern/navrouter/navdestination_pattern.h"
31 #include "core/components_ng/pattern/overlay/sheet_style.h"
32 #include "core/components_ng/pattern/stage/page_pattern.h"
33
34 #undef private
35 using namespace testing;
36 using namespace testing::ext;
37
38 namespace OHOS::Ace::NG {
39 namespace {
40 ViewAbstractModelNG viewAbstractModelNG;
41 RefPtr<MockTaskExecutor> MOCK_TASK_EXECUTOR;
42 int32_t flag = 0;
43 }; // namespace
44
45 class ViewAbstractModelTestNg : public testing::Test {
46 public:
47 static void SetUpTestSuite();
48 static void TearDownTestCase();
49 };
50
SetUpTestSuite()51 void ViewAbstractModelTestNg::SetUpTestSuite()
52 {
53 MockPipelineContext::SetUp();
54 MockContainer::SetUp();
55 MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
56 MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
57 MockContainer::Current()->pipelineContext_->taskExecutor_ = MockContainer::Current()->taskExecutor_;
58 }
TearDownTestCase()59 void ViewAbstractModelTestNg::TearDownTestCase()
60 {
61 MockPipelineContext::TearDown();
62 MockContainer::TearDown();
63 }
64
65 /**
66 * @tc.name: ViewAbstractModelTestNg001
67 * @tc.desc: Test the GetSheetContext of View_Abstract_model_ng
68 * @tc.type: FUNC
69 */
70 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg001, TestSize.Level1)
71 {
72 /**
73 * @tc.steps: step1. Build sheetStyle instanceId is empty.
74 */
75 SheetStyle style;
76 auto testContext1 = viewAbstractModelNG.GetSheetContext(style);
77 EXPECT_NE(testContext1, nullptr);
78
79 /**
80 * @tc.steps: step2. Build sheetStyle instanceId is 100001.
81 */
82 style.instanceId = 100001;
83 /**
84 * @tc.steps: step3. Build an AceEngine.
85 */
86 AceEngine& aceEngine = AceEngine::Get();
87
88 /**
89 * @tc.steps: step4. Add Container.
90 * @tc.expected: Add Container success.
91 */
92 aceEngine.AddContainer(style.instanceId.value(), MockContainer::container_);
93 EXPECT_NE(aceEngine.GetContainer(style.instanceId.value()), nullptr);
94 /**
95 * @tc.expected: context is not nullptr.
96 */
97 auto testContext2 = viewAbstractModelNG.GetSheetContext(style);
98 EXPECT_NE(testContext2, nullptr);
99 }
100
101 /**
102 * @tc.name: BindSheetShowInPageTest1
103 * @tc.desc: Test the composition of sheet parent nodes when page will show in page
104 * @tc.type: FUNC
105 */
106 HWTEST_F(ViewAbstractModelTestNg, BindSheetShowInPageTest1, TestSize.Level1)
107 {
108 // pagelevel Node is Page Node
109 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
110 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
111 auto column = FrameNode::CreateFrameNode(
112 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
113 auto targetNode = FrameNode::CreateFrameNode(
114 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
115 targetNode->MountToParent(column);
116 column->MountToParent(pageNode);
117 ViewStackProcessor::GetInstance()->Push(targetNode);
118 NG::SheetStyle sheetStyle;
119 sheetStyle.showInPage = true;
120 viewAbstractModelNG.BindSheet(false, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
121 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
122 auto pagePatern = pageNode->GetPattern<PagePattern>();
123 ASSERT_NE(pagePatern, nullptr);
124 auto overlay1 = pagePatern->GetOverlayManager();
125 EXPECT_EQ(overlay1, nullptr);
126 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
127 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
128 auto overlay2 = pagePatern->GetOverlayManager();
129 EXPECT_NE(overlay2, nullptr);
130 EXPECT_FALSE(!targetNode->RootNodeIsPage());
131 EXPECT_EQ(targetNode->GetRootNodeId(), pageNode->GetId());
132 }
133
134 /**
135 * @tc.name: BindSheetShowInPageTest2
136 * @tc.desc: Test the composition of sheet parent nodes when page will show in navDestination page
137 * @tc.type: FUNC
138 */
139 HWTEST_F(ViewAbstractModelTestNg, BindSheetShowInPageTest2, TestSize.Level1)
140 {
141 // pagelevel Node is navDestination Node
142 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
143 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
144 auto column = FrameNode::CreateFrameNode(
145 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
146 auto navDestinaion = FrameNode::CreateFrameNode(V2::NAVDESTINATION_VIEW_ETS_TAG,
147 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<NavDestinationPattern>());
148 auto targetNode = FrameNode::CreateFrameNode(
149 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
150 targetNode->MountToParent(navDestinaion);
151 navDestinaion->MountToParent(column);
152 column->MountToParent(pageNode);
153 ViewStackProcessor::GetInstance()->Push(targetNode);
154 NG::SheetStyle sheetStyle;
155 sheetStyle.showInPage = true;
156 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
157 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
158 auto navPatern = navDestinaion->GetPattern<NavDestinationPattern>();
159 ASSERT_NE(navPatern, nullptr);
160 auto overlay = navPatern->GetOverlayManager();
161 EXPECT_NE(overlay, nullptr);
162 EXPECT_TRUE(!targetNode->RootNodeIsPage());
163 EXPECT_EQ(targetNode->GetRootNodeId(), navDestinaion->GetId());
164 EXPECT_TRUE(!pageNode->RootNodeIsPage());
165 EXPECT_EQ(pageNode->GetRootNodeId(), targetNode->GetRootNodeId());
166 }
167
168 /**
169 * @tc.name: GetOverlayFromPageTest
170 * @tc.desc: set sheetStyle.showInPage.value_or(false) to endter FindPageNodeOverlay
171 * and targetNode->GetRootNodeId() > 0 to enter GetOverlayFromPage
172 * @tc.type: FUNC
173 */
174 HWTEST_F(ViewAbstractModelTestNg, GetOverlayFromPageTest, TestSize.Level1)
175 {
176 // pagelevel Node is navDestination Node
177 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
178 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
179 auto column = FrameNode::CreateFrameNode(
180 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
181 auto navDestinaion = FrameNode::CreateFrameNode(V2::NAVDESTINATION_VIEW_ETS_TAG,
182 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<NavDestinationPattern>());
183 auto targetNode = FrameNode::CreateFrameNode(
184 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
185 targetNode->MountToParent(navDestinaion);
186 targetNode->SetRootNodeId(1);
187 navDestinaion->MountToParent(column);
188 column->MountToParent(pageNode);
189 ViewStackProcessor::GetInstance()->Push(targetNode);
190 NG::SheetStyle sheetStyle;
191 sheetStyle.showInPage = true;
192 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
193 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
194
195 sheetStyle.showInPage = false;
196 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
197 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
198
199 sheetStyle.showInPage = false;
200 viewAbstractModelNG.BindSheet(false, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
201 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
202
203 auto navPatern = navDestinaion->GetPattern<NavDestinationPattern>();
204 ASSERT_NE(navPatern, nullptr);
205 auto overlay = navPatern->GetOverlayManager();
206 EXPECT_EQ(overlay, nullptr);
207 EXPECT_FALSE(!targetNode->RootNodeIsPage());
208 EXPECT_EQ(targetNode->GetRootNodeId(), 1);
209 EXPECT_FALSE(!pageNode->RootNodeIsPage());
210 EXPECT_NE(pageNode->GetRootNodeId(), targetNode->GetRootNodeId());
211 }
212
213 /**
214 * @tc.name: BindContextMenuTest
215 * @tc.desc: Test the BindContextMenu method with various parameters and conditions
216 * @tc.type: FUNC
217 */
218 HWTEST_F(ViewAbstractModelTestNg, BindContextMenuTest, TestSize.Level1)
219 {
220 std::function<void()> buildFunc = nullptr;
221 std::function<void()> previewBuildFunc = nullptr;
222 MenuParam menuParam;
223
224 /**
225 * @tc.steps: subwindow is null and does not enter BindContextMenuSingle.
226 */
227 SubwindowManager::GetInstance()->RemoveSubwindow(Container::CurrentId());
228 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
229 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
230
231 /**
232 * @tc.steps: entering BindContextMenuSingle with subwindow null, menuParam.isShow true, and buildFunc not null.
233 */
234 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
235 menuParam.isShow = true;
__anon496613410202() 236 buildFunc = []() {};
237 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
238 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
239
240 /**
241 * @tc.steps: entering BindContextMenuSingle with subwindow null, menuParam.isShow true, and buildFunc null.
242 */
243 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
244 menuParam.isShow = true;
245 buildFunc = nullptr;
246 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
247 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
248
249 /**
250 * @tc.steps: BindContextMenuSingle with subwindow null, menuParam.isShow false, and buildFunc not null.
251 */
252 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
253 menuParam.isShow = false;
__anon496613410302() 254 buildFunc = []() {};
255 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
256 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
257
258 /**
259 * @tc.steps: entering BindContextMenuSingle with subwindow null, menuParam.isShow false, and buildFunc null.
260 */
261 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
262 menuParam.isShow = false;
263 buildFunc = nullptr;
264 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
265 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
266
267 /**
268 * @tc.steps: subwindow is null and does not enter BindContextMenuSingle, with type == ResponseType::RIGHT_CLICK.
269 */
270 menuParam.contextMenuRegisterType = ContextMenuRegisterType::NORMAL_TYPE;
271 viewAbstractModelNG.BindContextMenu(ResponseType::RIGHT_CLICK, buildFunc, menuParam, previewBuildFunc);
272 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
273
274 /**
275 * @tc.steps: subwindow is null and does not enter BindContextMenuSingle, with type == ResponseType::LONG_PRESS.
276 */
277 viewAbstractModelNG.BindContextMenu(ResponseType::LONG_PRESS, buildFunc, menuParam, previewBuildFunc);
278 ASSERT_EQ(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
279
280 /**
281 * @tc.steps: subwindow is not null.
282 */
283 auto subwindow = Subwindow::CreateSubwindow(Container::CurrentId());
284 SubwindowManager::GetInstance()->AddSubwindow(Container::CurrentId(), subwindow);
285 viewAbstractModelNG.BindContextMenu(ResponseType::LONG_PRESS, buildFunc, menuParam, previewBuildFunc);
286 ASSERT_NE(SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId()), nullptr);
287 }
288
289 /**
290 * @tc.name: ViewAbstractModelTestNg003
291 * @tc.desc: Test the BindDragWithContextMenuParams of View_Abstract_model_ng
292 * @tc.type: FUNC
293 */
294 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg003, TestSize.Level1)
295 {
296 MenuParam menuParam;
297 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
298 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
299 ASSERT_NE(pageNode, nullptr);
300 auto column = FrameNode::CreateFrameNode(
301 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
302 ASSERT_NE(column, nullptr);
303 auto navDestinaion = FrameNode::CreateFrameNode(V2::NAVDESTINATION_VIEW_ETS_TAG,
304 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<NavDestinationPattern>());
305 ASSERT_NE(navDestinaion, nullptr);
306 auto targetNode = FrameNode::CreateFrameNode(
307 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
308 ASSERT_NE(targetNode, nullptr);
309 targetNode->MountToParent(navDestinaion);
310 targetNode->SetRootNodeId(1);
311 navDestinaion->MountToParent(column);
312 column->MountToParent(pageNode);
313 ViewStackProcessor::GetInstance()->Push(targetNode);
314 viewAbstractModelNG.BindDragWithContextMenuParams(menuParam);
315 EXPECT_NE(pageNode, nullptr);
316 }
317
318 /**
319 * @tc.name: ViewAbstractModelTestNg004
320 * @tc.desc: Test the BindMenu
321 * @tc.type: FUNC
322 */
323 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg004, TestSize.Level1)
324 {
325 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
326 ASSERT_NE(mainNode, nullptr);
327 ViewStackProcessor::GetInstance()->Push(mainNode);
328 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
329 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
330 auto theme = AceType::MakeRefPtr<SelectTheme>();
331 theme->expandDisplay_ = true;
332 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
333 auto container = Container::Current();
334 ASSERT_NE(container, nullptr);
335 auto pipelineContext = container->GetPipelineContext();
336 ASSERT_NE(pipelineContext, nullptr);
337
338 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anon496613410402() 339 std::function<void()> flagFunc = []() { flag++; };
340 std::vector<NG::OptionParam> params = {};
341 std::function<void()> buildFunc;
342 MenuParam menuParam;
343 menuParam.isShow = true;
344 menuParam.isShowInSubWindow = true;
345 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
346 menuParam.isShowInSubWindow = false;
__anon496613410502() 347 buildFunc = []() { flag++; };
348 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
349 params.push_back(OptionParam());
350 menuParam.setShow = true;
351 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
352 EXPECT_NE(mainNode, nullptr);
353 }
354
355 /**
356 * @tc.name: ViewAbstractModelTestNg005
357 * @tc.desc: Test the BindMenu
358 * @tc.type: FUNC
359 */
360 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg005, TestSize.Level1)
361 {
362 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
363 ASSERT_NE(mainNode, nullptr);
364 ViewStackProcessor::GetInstance()->Push(mainNode);
365 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
366 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
367 auto theme = AceType::MakeRefPtr<SelectTheme>();
368 theme->expandDisplay_ = false;
369 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
370 auto container = Container::Current();
371 ASSERT_NE(container, nullptr);
372 auto pipelineContext = container->GetPipelineContext();
373 ASSERT_NE(pipelineContext, nullptr);
374 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
375 auto overlayManager = context->GetOverlayManager();
376 ASSERT_NE(overlayManager, nullptr);
377 auto menuNode = overlayManager->GetMenuNode(1);
378 if (menuNode) {
379 auto wrapperPattern = menuNode->GetPattern<MenuWrapperPattern>();
380 if (wrapperPattern) {
381 wrapperPattern->SetMenuStatus(MenuStatus::SHOW);
382 }
383 }
384 std::vector<NG::OptionParam> params = {};
385 std::function<void()> buildFunc;
386 MenuParam menuParam;
387 menuParam.isShow = true;
388 menuParam.isShowInSubWindow = true;
389 menuParam.hasTransitionEffect = false;
390 menuParam.setShow = true;
391 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
392 menuParam.isShowInSubWindow = false;
393 menuParam.hasTransitionEffect = true;
394 menuParam.isShow = false;
__anon496613410602() 395 buildFunc = []() { flag++; };
396 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
397 params.push_back(OptionParam());
398 menuParam.setShow = false;
399 menuParam.isShow = false;
400 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
401 if (menuNode) {
402 auto wrapperPattern = menuNode->GetPattern<MenuWrapperPattern>();
403 if (wrapperPattern) {
404 wrapperPattern->SetMenuStatus(MenuStatus::INIT);
405 }
406 }
407 viewAbstractModelNG.BindMenu(std::move(params), std::move(buildFunc), menuParam);
408 EXPECT_NE(mainNode, nullptr);
409 }
410
411 /**
412 * @tc.name: ViewAbstractModelTestNg006
413 * @tc.desc: Test the BindContextMenu
414 * @tc.type: FUNC
415 */
416 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg006, TestSize.Level1)
417 {
418 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
419 ASSERT_NE(mainNode, nullptr);
420 ViewStackProcessor::GetInstance()->Push(mainNode);
421 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
422 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
423 auto theme = AceType::MakeRefPtr<SelectTheme>();
424 theme->expandDisplay_ = false;
425 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
426 auto container = Container::Current();
427 ASSERT_NE(container, nullptr);
428 auto pipelineContext = container->GetPipelineContext();
429 ASSERT_NE(pipelineContext, nullptr);
430 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
431 ASSERT_NE(context, nullptr);
432 auto containerId = pipelineContext->GetInstanceId();
433 AceEngine& aceEngine = AceEngine::Get();
434 aceEngine.AddContainer(containerId, MockContainer::container_);
435 aceEngine.AddContainer(containerId, MockContainer::container_);
436 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anon496613410702() 437 std::function<void()> flagFunc = []() { flag++; };
438 std::vector<NG::OptionParam> params = {};
439 std::function<void()> buildFunc;
440 MenuParam menuParam;
441 std::function<void()> previewBuildFunc = nullptr;
442 auto type = ResponseType::RIGHT_CLICK;
__anon496613410802() 443 buildFunc = []() { flag++; };
444 params.push_back(OptionParam());
445 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
446 EXPECT_NE(mainNode, nullptr);
447 }
448
449 /**
450 * @tc.name: ViewAbstractModelTestNg007
451 * @tc.desc: Test the BindContextMenu
452 * @tc.type: FUNC
453 */
454 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg007, TestSize.Level1)
455 {
456 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
457 ASSERT_NE(mainNode, nullptr);
458 ViewStackProcessor::GetInstance()->Push(mainNode);
459 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
460 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
461 auto theme = AceType::MakeRefPtr<SelectTheme>();
462 theme->expandDisplay_ = true;
463 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
464 auto container = Container::Current();
465 ASSERT_NE(container, nullptr);
466 auto pipelineContext = container->GetPipelineContext();
467 ASSERT_NE(pipelineContext, nullptr);
468 auto containerId = pipelineContext->GetInstanceId();
469 AceEngine& aceEngine = AceEngine::Get();
470 aceEngine.AddContainer(containerId, MockContainer::container_);
471 aceEngine.AddContainer(containerId, MockContainer::container_);
472 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anon496613410902() 473 std::function<void()> flagFunc = []() { flag++; };
474 std::vector<NG::OptionParam> params = {};
475 std::function<void()> buildFunc;
476 MenuParam menuParam;
477 std::function<void()> previewBuildFunc = nullptr;
478 auto type = ResponseType::RIGHT_CLICK;
479 menuParam.isShowInSubWindow = false;
__anon496613410a02() 480 buildFunc = []() { flag++; };
481 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
482 EXPECT_NE(mainNode, nullptr);
483 }
484
485 /**
486 * @tc.name: ViewAbstractModelTestNg008
487 * @tc.desc: Test the BindContextMenu
488 * @tc.type: FUNC
489 */
490 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg008, TestSize.Level1)
491 {
492 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 9, AceType::MakeRefPtr<Pattern>(), true);
493 ASSERT_NE(mainNode, nullptr);
494 ViewStackProcessor::GetInstance()->Push(mainNode);
495 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
496 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
497 auto theme = AceType::MakeRefPtr<SelectTheme>();
498 theme->expandDisplay_ = false;
499 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
500 auto container = Container::Current();
501 ASSERT_NE(container, nullptr);
502 auto pipelineContext = container->GetPipelineContext();
503 ASSERT_NE(pipelineContext, nullptr);
504 auto containerId = pipelineContext->GetInstanceId();
505 AceEngine& aceEngine = AceEngine::Get();
506 aceEngine.AddContainer(containerId, MockContainer::container_);
507 aceEngine.AddContainer(containerId, MockContainer::container_);
508 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anon496613410b02() 509 std::function<void()> flagFunc = []() { flag++; };
510 std::vector<NG::OptionParam> params = {};
511 std::function<void()> buildFunc;
512 MenuParam menuParam;
513 std::function<void()> previewBuildFunc = nullptr;
514 auto type = ResponseType::RIGHT_CLICK;
515 menuParam.isShowInSubWindow = false;
516 menuParam.hasTransitionEffect = true;
517 menuParam.isShow = false;
__anon496613410c02() 518 buildFunc = []() { flag++; };
519 params.push_back(OptionParam());
520 menuParam.setShow = false;
521 menuParam.isShow = false;
522 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
523 EXPECT_NE(mainNode, nullptr);
524 }
525
526 /**
527 * @tc.name: ViewAbstractModelTestNg009
528 * @tc.desc: Test the BindContextMenu
529 * @tc.type: FUNC
530 */
531 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg009, TestSize.Level1)
532 {
533 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 6, AceType::MakeRefPtr<Pattern>(), true);
534 ASSERT_NE(mainNode, nullptr);
535 ViewStackProcessor::GetInstance()->Push(mainNode);
536 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
537 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
538 auto theme = AceType::MakeRefPtr<SelectTheme>();
539 theme->expandDisplay_ = true;
540 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
541 auto container = Container::Current();
542 ASSERT_NE(container, nullptr);
543 auto pipelineContext = container->GetPipelineContext();
544 ASSERT_NE(pipelineContext, nullptr);
545 auto containerId = pipelineContext->GetInstanceId();
546 AceEngine& aceEngine = AceEngine::Get();
547 aceEngine.AddContainer(containerId, MockContainer::container_);
548 aceEngine.AddContainer(containerId, MockContainer::container_);
549 ASSERT_NE(SubwindowManager::GetInstance(), nullptr);
__anon496613410d02() 550 std::function<void()> flagFunc = []() { flag++; };
551 std::vector<NG::OptionParam> params = {};
552 std::function<void()> buildFunc;
553 MenuParam menuParam;
554 std::function<void()> previewBuildFunc = nullptr;
555 auto type = ResponseType::LONG_PRESS;
556 menuParam.isShowInSubWindow = false;
557 menuParam.previewMode = MenuPreviewMode::IMAGE;
__anon496613410e02() 558 buildFunc = []() { flag++; };
559 menuParam.isShowHoverImage = false;
560 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
561 menuParam.previewMode = MenuPreviewMode::NONE;
562 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
563 EXPECT_NE(mainNode, nullptr);
564 }
565
566 /**
567 * @tc.name: ViewAbstractModelTestNg010
568 * @tc.desc: Test the BindContextMenu
569 * @tc.type: FUNC
570 */
571 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg010, TestSize.Level1)
572 {
573 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 6, AceType::MakeRefPtr<Pattern>(), true);
574 ASSERT_NE(mainNode, nullptr);
575 ViewStackProcessor::GetInstance()->Push(mainNode);
576 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
577 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
578 auto theme = AceType::MakeRefPtr<SelectTheme>();
579 theme->expandDisplay_ = true;
580 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
581 auto container = Container::Current();
582 ASSERT_NE(container, nullptr);
583 auto pipelineContext = container->GetPipelineContext();
584 ASSERT_NE(pipelineContext, nullptr);
585 auto containerId = pipelineContext->GetInstanceId();
586 AceEngine& aceEngine = AceEngine::Get();
587 aceEngine.AddContainer(containerId, MockContainer::container_);
588 aceEngine.AddContainer(containerId, MockContainer::container_);
__anon496613410f02() 589 std::function<void()> flagFunc = []() { flag++; };
590 std::vector<NG::OptionParam> params = {};
591 std::function<void()> buildFunc;
592 MenuParam menuParam;
593 std::function<void()> previewBuildFunc = nullptr;
594 auto type = ResponseType::LONG_PRESS;
595 menuParam.isShowInSubWindow = false;
596 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
597 menuParam.previewMode = MenuPreviewMode::NONE;
__anon496613411002() 598 buildFunc = []() { flag++; };
599 menuParam.isShowHoverImage = true;
600 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
601 EXPECT_NE(mainNode, nullptr);
602 }
603
604 /**
605 * @tc.name: ViewAbstractModelTestNg011
606 * @tc.desc: Test the BindContextMenuSingle and CreateCustomMenuWithPreview
607 * @tc.type: FUNC
608 */
609 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg011, TestSize.Level1)
610 {
611 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 6, AceType::MakeRefPtr<Pattern>(), true);
612 ASSERT_NE(mainNode, nullptr);
613 ViewStackProcessor::GetInstance()->Push(mainNode);
614 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
615 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
616 auto theme = AceType::MakeRefPtr<SelectTheme>();
617 theme->expandDisplay_ = true;
618 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
619 auto container = Container::Current();
620 ASSERT_NE(container, nullptr);
621 auto pipelineContext = container->GetPipelineContext();
622 ASSERT_NE(pipelineContext, nullptr);
623 auto containerId = pipelineContext->GetInstanceId();
624 AceEngine& aceEngine = AceEngine::Get();
625 aceEngine.AddContainer(containerId, MockContainer::container_);
626 aceEngine.AddContainer(containerId, MockContainer::container_);
__anon496613411102() 627 std::function<void()> flagFunc = []() { flag++; };
628 std::vector<NG::OptionParam> params = {};
629 std::function<void()> buildFunc;
630 MenuParam menuParam;
631 std::function<void()> previewBuildFunc = nullptr;
632 auto type = ResponseType::LONG_PRESS;
633 menuParam.isShowInSubWindow = false;
634 menuParam.previewMode = MenuPreviewMode::IMAGE;
__anon496613411202() 635 buildFunc = []() { flag++; };
636 menuParam.isShowHoverImage = false;
637 menuParam.contextMenuRegisterType = ContextMenuRegisterType::CUSTOM_TYPE;
638 menuParam.isShow = true;
639
640 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
641 menuParam.previewMode = MenuPreviewMode::CUSTOM;
642 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
643 menuParam.isShow = false;
644 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
645 menuParam.isShow = true;
646 buildFunc = nullptr;
647 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
648 EXPECT_NE(mainNode, nullptr);
649 }
650
651 /**
652 * @tc.name: ViewAbstractModelTestNg012
653 * @tc.desc: Test the BindContextMenu
654 * @tc.type: FUNC
655 */
656 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg012, TestSize.Level1)
657 {
658 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 9, AceType::MakeRefPtr<Pattern>(), true);
659 ASSERT_NE(mainNode, nullptr);
660 ViewStackProcessor::GetInstance()->Push(mainNode);
661 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
662 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
663 auto theme = AceType::MakeRefPtr<SelectTheme>();
664 theme->expandDisplay_ = false;
665 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
666 auto container = Container::Current();
667 ASSERT_NE(container, nullptr);
668 auto pipelineContext = container->GetPipelineContext();
669 ASSERT_NE(pipelineContext, nullptr);
670 auto containerId = pipelineContext->GetInstanceId();
671 AceEngine& aceEngine = AceEngine::Get();
672 aceEngine.AddContainer(containerId, MockContainer::container_);
673 aceEngine.AddContainer(containerId, MockContainer::container_);
__anon496613411302() 674 std::function<void()> flagFunc = []() { flag++; };
675 std::vector<NG::OptionParam> params = {};
676 std::function<void()> buildFunc;
677 MenuParam menuParam;
678 std::function<void()> previewBuildFunc = nullptr;
679 auto type = ResponseType::RIGHT_CLICK;
680 menuParam.isShowInSubWindow = false;
681 menuParam.hasTransitionEffect = true;
682 menuParam.isShow = false;
__anon496613411402() 683 buildFunc = []() { flag++; };
684 params.push_back(OptionParam());
685 menuParam.setShow = false;
686 menuParam.isShow = false;
687 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
688 auto targetNode1 = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
689 auto callBak = targetNode1->GetDestroyCallback();
690 for (const auto& destroyCallback : targetNode1->GetDestroyCallback()) {
691 destroyCallback();
692 }
693 EXPECT_NE(mainNode, nullptr);
694 }
695
696 /**
697 * @tc.name: ViewAbstractModelTestNg013
698 * @tc.desc: Test the BindContextMenu
699 * @tc.type: FUNC
700 */
701 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg013, TestSize.Level1)
702 {
703 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 9, AceType::MakeRefPtr<Pattern>(), true);
704 ASSERT_NE(mainNode, nullptr);
705 ViewStackProcessor::GetInstance()->Push(mainNode);
706 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
707 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
708 auto theme = AceType::MakeRefPtr<SelectTheme>();
709 theme->expandDisplay_ = true;
710 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
711 auto container = Container::Current();
712 ASSERT_NE(container, nullptr);
713 auto pipelineContext = container->GetPipelineContext();
714 ASSERT_NE(pipelineContext, nullptr);
715 auto containerId = pipelineContext->GetInstanceId();
716 AceEngine& aceEngine = AceEngine::Get();
717 aceEngine.AddContainer(containerId, MockContainer::container_);
718 aceEngine.AddContainer(containerId, MockContainer::container_);
__anon496613411502() 719 std::function<void()> flagFunc = []() { flag++; };
720 std::vector<NG::OptionParam> params = {};
721 std::function<void()> buildFunc;
722 MenuParam menuParam;
723 std::function<void()> previewBuildFunc = nullptr;
724 auto type = ResponseType::RIGHT_CLICK;
725 menuParam.isShowInSubWindow = false;
726 menuParam.hasTransitionEffect = true;
727 menuParam.isShow = false;
__anon496613411602() 728 buildFunc = []() { flag++; };
729 params.push_back(OptionParam());
730 menuParam.setShow = false;
731 menuParam.isShow = false;
732 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
733 auto targetNode1 = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
734 auto callBak = targetNode1->GetDestroyCallback();
735 for (const auto& destroyCallback : targetNode1->GetDestroyCallback()) {
736 destroyCallback();
737 }
738 EXPECT_NE(mainNode, nullptr);
739 }
740
741 /**
742 * @tc.name: ViewAbstractModelTestNg014
743 * @tc.desc: Test the composition of sheet parent nodes when page will show in page
744 * @tc.type: FUNC
745 */
746 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg014, TestSize.Level1)
747 {
748 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
749 AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
750 ASSERT_NE(pageNode, nullptr);
751 auto column = FrameNode::CreateFrameNode(
752 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
753 ASSERT_NE(column, nullptr);
754 auto targetNode = FrameNode::CreateFrameNode(
755 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
756 ASSERT_NE(targetNode, nullptr);
757 targetNode->MountToParent(column);
758 column->MountToParent(pageNode);
759 ViewStackProcessor::GetInstance()->Push(targetNode);
760 NG::SheetStyle sheetStyle;
761 sheetStyle.showInPage = true;
762 viewAbstractModelNG.BindSheet(false, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
763 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
764 auto pagePatern = pageNode->GetPattern<PagePattern>();
765 ASSERT_NE(pagePatern, nullptr);
766 auto overlay1 = pagePatern->GetOverlayManager();
767 EXPECT_EQ(overlay1, nullptr);
768 auto container = Container::Current();
769 ASSERT_NE(container, nullptr);
770 auto pipelineContext = container->GetPipelineContext();
771 ASSERT_NE(pipelineContext, nullptr);
772 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
773 ASSERT_NE(context, nullptr);
774 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
775 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
776 sheetStyle.showInPage = false;
777 viewAbstractModelNG.BindSheet(true, nullptr, nullptr, nullptr, sheetStyle, nullptr, nullptr, nullptr, nullptr,
778 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
779 auto targetNode1 = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
780 for (const auto& destroyCallback : targetNode1->GetDestroyCallback()) {
781 destroyCallback();
782 }
783 auto overlay2 = pagePatern->GetOverlayManager();
784 EXPECT_NE(overlay2, nullptr);
785 EXPECT_FALSE(!targetNode->RootNodeIsPage());
786 EXPECT_EQ(targetNode->GetRootNodeId(), pageNode->GetId());
787 }
788
789 /**
790 * @tc.name: ViewAbstractModelTestNg015
791 * @tc.desc: Test the BindContextMenu
792 * @tc.type: FUNC
793 */
794 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg015, TestSize.Level1)
795 {
796 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
797 ASSERT_NE(mainNode, nullptr);
798 ViewStackProcessor::GetInstance()->Push(mainNode);
799 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
800 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
801 auto theme = AceType::MakeRefPtr<SelectTheme>();
802 theme->expandDisplay_ = false;
803 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
804 auto container = Container::Current();
805 ASSERT_NE(container, nullptr);
806 auto pipelineContext = container->GetPipelineContext();
807 ASSERT_NE(pipelineContext, nullptr);
808 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
809 ASSERT_NE(context, nullptr);
810 auto overlayManager = context->GetOverlayManager();
811 ASSERT_NE(overlayManager, nullptr);
812 auto containerId = pipelineContext->GetInstanceId();
813 AceEngine& aceEngine = AceEngine::Get();
814 aceEngine.AddContainer(containerId, MockContainer::container_);
815 aceEngine.AddContainer(containerId, MockContainer::container_);
__anon496613411702() 816 std::function<void()> flagFunc = []() { flag++; };
817 std::vector<NG::OptionParam> params = {};
818 std::function<void()> buildFunc;
819 MenuParam menuParam;
820 std::function<void()> previewBuildFunc = nullptr;
821 auto type = ResponseType::RIGHT_CLICK;
__anon496613411802() 822 buildFunc = []() { flag++; };
823 params.push_back(OptionParam());
824 auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
825 auto targetId = targetNode->GetId();
826 auto menu =
827 FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
828 overlayManager->menuMap_[targetId] = menu;
829 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
830 EXPECT_NE(mainNode, nullptr);
831 }
832
833 /**
834 * @tc.name: ViewAbstractModelTestNg016
835 * @tc.desc: Test the BindContextMenu
836 * @tc.type: FUNC
837 */
838 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg016, TestSize.Level1)
839 {
840 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
841 ASSERT_NE(mainNode, nullptr);
842 ViewStackProcessor::GetInstance()->Push(mainNode);
843 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
844 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
845 auto theme = AceType::MakeRefPtr<SelectTheme>();
846 theme->expandDisplay_ = false;
847 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
848 auto container = Container::Current();
849 auto pipelineContext = container->GetPipelineContext();
850 ASSERT_NE(pipelineContext, nullptr);
851 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
852 auto overlayManager = context->GetOverlayManager();
853 ASSERT_NE(overlayManager, nullptr);
854 auto containerId = pipelineContext->GetInstanceId();
855 AceEngine& aceEngine = AceEngine::Get();
856 aceEngine.AddContainer(containerId, MockContainer::container_);
__anon496613411902() 857 std::function<void()> buildFunc = []() { flag++; };
858 MenuParam menuParam;
859 std::function<void()> previewBuildFunc = nullptr;
860 auto type = ResponseType::RIGHT_CLICK;
861 auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
862 auto targetId = targetNode->GetId();
863 auto menu =
864 FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
865 overlayManager->menuMap_[targetId] = menu;
866 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
867 auto inputHub = targetNode->GetOrCreateInputEventHub();
868 auto mouseEventActuator_ = inputHub->mouseEventActuator_;
869 auto Events = mouseEventActuator_->inputEvents_;
870 MouseInfo mouseInfo;
871 for (const auto& callback : Events) {
872 (*callback)(mouseInfo);
873 }
874 mouseInfo.button_ = MouseButton::RIGHT_BUTTON;
875 for (const auto& callback : Events) {
876 (*callback)(mouseInfo);
877 }
878 mouseInfo.action_ = MouseAction::RELEASE;
879 for (const auto& callback : Events) {
880 (*callback)(mouseInfo);
881 }
882 mouseInfo.button_ = MouseButton::LEFT_BUTTON;
883 for (const auto& callback : Events) {
884 (*callback)(mouseInfo);
885 }
886 EXPECT_NE(mainNode, nullptr);
887 }
888
889 /**
890 * @tc.name: ViewAbstractModelTestNg017
891 * @tc.desc: Test the BindContextMenu
892 * @tc.type: FUNC
893 */
894 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg017, TestSize.Level1)
895 {
896 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
897 ASSERT_NE(mainNode, nullptr);
898 ViewStackProcessor::GetInstance()->Push(mainNode);
899 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
900 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
901 auto theme = AceType::MakeRefPtr<SelectTheme>();
902 theme->expandDisplay_ = false;
903 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
904 auto container = Container::Current();
905 ASSERT_NE(container, nullptr);
906 auto pipelineContext = container->GetPipelineContext();
907 ASSERT_NE(pipelineContext, nullptr);
908 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
909 ASSERT_NE(context, nullptr);
910 auto overlayManager = context->GetOverlayManager();
911 ASSERT_NE(overlayManager, nullptr);
912 auto containerId = pipelineContext->GetInstanceId();
913 AceEngine& aceEngine = AceEngine::Get();
914 aceEngine.AddContainer(containerId, MockContainer::container_);
__anon496613411a02() 915 std::function<void()> buildFunc = []() { flag++; };
916 MenuParam menuParam;
917 std::function<void()> previewBuildFunc = nullptr;
918 auto type = ResponseType::LONG_PRESS;
919 auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
920 auto targetId = targetNode->GetId();
921 auto menu =
922 FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
923 overlayManager->menuMap_[targetId] = menu;
924 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
925 auto hub = targetNode->GetOrCreateGestureEventHub();
926 auto longPressEventActuator = hub->longPressEventActuator_;
927 auto Events = longPressEventActuator->longPressEvent_;
928 GestureEvent info;
929 const auto& callback = Events;
930 (*callback)(info);
931 auto pipelineContext1 = NG::PipelineContext::GetCurrentContext();
932 auto dragDropManager = pipelineContext1->GetDragDropManager();
933 dragDropManager->dragDropState_ = DragDropMgrState::DRAGGING;
934 (*callback)(info);
935 dragDropManager->dragDropState_ = DragDropMgrState::ABOUT_TO_PREVIEW;
936 (*callback)(info);
937 dragDropManager->dragDropState_ = DragDropMgrState::IDLE;
938 EXPECT_NE(mainNode, nullptr);
939 }
940
941 /**
942 * @tc.name: ViewAbstractModelTestNg018
943 * @tc.desc: Test the BindContextMenu
944 * @tc.type: FUNC
945 */
946 HWTEST_F(ViewAbstractModelTestNg, ViewAbstractModelTestNg018, TestSize.Level1)
947 {
948 const RefPtr<FrameNode> mainNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
949 ASSERT_NE(mainNode, nullptr);
950 ViewStackProcessor::GetInstance()->Push(mainNode);
951 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
952 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
953 auto theme = AceType::MakeRefPtr<SelectTheme>();
954 theme->expandDisplay_ = false;
955 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(theme));
956 auto container = Container::Current();
957 auto pipelineContext = container->GetPipelineContext();
958 ASSERT_NE(pipelineContext, nullptr);
959 auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
960 auto overlayManager = context->GetOverlayManager();
961 ASSERT_NE(overlayManager, nullptr);
962 auto containerId = pipelineContext->GetInstanceId();
963 AceEngine& aceEngine = AceEngine::Get();
964 aceEngine.AddContainer(containerId, MockContainer::container_);
__anon496613411b02() 965 std::function<void()> buildFunc = []() { flag++; };
966 MenuParam menuParam;
967 menuParam.previewMode = MenuPreviewMode::IMAGE;
968 menuParam.isShowHoverImage = true;
969 std::function<void()> previewBuildFunc = nullptr;
970 auto type = ResponseType::LONG_PRESS;
971 auto targetNode = AceType::Claim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
972 auto targetId = targetNode->GetId();
973 auto menu =
974 FrameNode::CreateFrameNode("targetNode", targetId, AceType::MakeRefPtr<MenuWrapperPattern>(targetId), false);
975 overlayManager->menuMap_[targetId] = menu;
976 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
977 auto hub = targetNode->GetOrCreateGestureEventHub();
978 auto longPressEventActuator = hub->longPressEventActuator_;
979 auto Events = longPressEventActuator->longPressEvent_;
980 GestureEvent info;
981 const auto& callback = Events;
982 (*callback)(info);
983 auto focusHub = targetNode->GetOrCreateFocusHub();
984 KeyEvent event;
985 focusHub->ProcessOnKeyEventInternal(event);
986 event.action = KeyAction::DOWN;
987 focusHub->ProcessOnKeyEventInternal(event);
988 event.keyIntention = KeyIntention::INTENTION_MENU;
989 focusHub->ProcessOnKeyEventInternal(event);
990 event.code = KeyCode::KEY_MENU;
991 menuParam.placement = Placement::BOTTOM_LEFT;
992 viewAbstractModelNG.BindContextMenu(type, buildFunc, menuParam, previewBuildFunc);
993 focusHub->ProcessOnKeyEventInternal(event);
994 EXPECT_NE(mainNode, nullptr);
995 }
996 } // namespace OHOS::Ace::NG