1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <optional>
17
18 #include "gtest/gtest.h"
19 #define private public
20
21 #include "test/mock/core/common/mock_theme_manager.h"
22 #include "test/mock/core/render/mock_render_context.h"
23 #include "test/mock/base/mock_drag_window.h"
24 #include "test/mock/core/common/mock_container.h"
25 #include "test/mock/core/common/mock_interaction_interface.h"
26 #include "test/mock/core/common/mock_udmf.h"
27 #include "test/mock/core/pipeline/mock_pipeline_context.h"
28 #include "test/unittest/core/event/drag_event/drag_event_test_ng_issue_utils.h"
29
30 #include "base/image/pixel_map.h"
31 #include "base/memory/ace_type.h"
32 #include "base/memory/referenced.h"
33 #include "base/subwindow/subwindow_manager.h"
34 #include "core/common/ace_engine.h"
35 #include "core/common/interaction/interaction_interface.h"
36 #include "core/components/common/layout/grid_system_manager.h"
37 #include "core/components/theme/blur_style_theme.h"
38 #include "core/components_ng/base/frame_node.h"
39 #include "core/components_ng/base/geometry_node.h"
40 #include "core/components_ng/base/ui_node.h"
41 #include "core/components_ng/base/view_abstract.h"
42 #include "core/components_ng/event/event_hub.h"
43 #include "core/components_ng/manager/drag_drop/drag_drop_func_wrapper.h"
44 #include "core/components_ng/manager/drag_drop/drag_drop_global_controller.h"
45 #include "core/components_ng/manager/drag_drop/drag_drop_manager.h"
46 #include "core/components_ng/manager/drag_drop/drag_drop_proxy.h"
47 #include "core/components_ng/pattern/grid/grid_item_pattern.h"
48 #include "core/components_ng/pattern/grid/grid_pattern.h"
49 #include "ui/base/geometry/ng/offset_t.h"
50 #include "core/components/select/select_theme.h"
51
52 using namespace testing;
53 using namespace testing::ext;
54 namespace OHOS::Ace::NG {
55 namespace {
56 RefPtr<DragWindow> MOCK_DRAG_WINDOW;
57 constexpr size_t DEFAULT_CHILD_COUNT = 4;
58 constexpr float GRID_WIDTH = 480.0f;
59 constexpr float GRID_HEIGHT = 800.0f;
60 constexpr float ITEM_WIDTH = 120.0f;
61 constexpr float ITEM_HEIGHT = 200.0f;
62 constexpr float OFFSET_WIDTH = 100.0f;
63 constexpr float OFFSET_HEIGHT = 50.0f;
64 constexpr float TINY_RADIUS = 1.0;
65 constexpr float MEDIUM_RADIUS = 12.0;
66 } // namespace
67
68 // test case
69 struct DragMultiCase {
70 bool isAllowDrag = false;
71 bool isSelected = false;
72 bool isMultiSelectionEnabled = false;
73 bool expectResult = false;
74 };
75
76 const std::vector<DragMultiCase> DRAG_MULTI_CASES = {
77 { false, false, false, false},
78 { false, false, true, false},
79 { false, true, false, false},
80 { false, true, true, false},
81 { true, false, false, false},
82 { true, false, true, false},
83 { true, true, false, false},
84 { true, true, true, true},
85 };
86
87 class DragDropFuncWrapperTestNgCoverage : public testing::Test {
88 public:
89 static void SetUpTestCase();
90 static void TearDownTestCase();
91 };
92
SetUpTestCase()93 void DragDropFuncWrapperTestNgCoverage::SetUpTestCase()
94 {
95 MockPipelineContext::SetUp();
96 MockContainer::SetUp();
97 MOCK_DRAG_WINDOW = DragWindow::CreateDragWindow("", 0, 0, 0, 0);
98 }
99
TearDownTestCase()100 void DragDropFuncWrapperTestNgCoverage::TearDownTestCase()
101 {
102 MockPipelineContext::TearDown();
103 MockContainer::TearDown();
104 MOCK_DRAG_WINDOW = nullptr;
105 }
106
CreateGridNodeWithChild(size_t childCount)107 RefPtr<FrameNode> CreateGridNodeWithChild(size_t childCount)
108 {
109 auto frameNode = FrameNode::GetOrCreateFrameNode(V2::GRID_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
110 []() {return AceType::MakeRefPtr<GridPattern>(); });
111 ViewAbstract::SetWidth(Referenced::RawPtr(frameNode), CalcLength(GRID_WIDTH));
112 ViewAbstract::SetHeight(Referenced::RawPtr(frameNode), CalcLength(GRID_HEIGHT));
113
114 for (size_t i = 0; i < childCount; ++i) {
115 auto chidNodeId = ElementRegister::GetInstance()->MakeUniqueId();
116 auto childNode = FrameNode::GetOrCreateFrameNode(V2::GRID_ITEM_ETS_TAG, chidNodeId,
117 []() { return AceType::MakeRefPtr<GridItemPattern>(nullptr, GridItemStyle::NONE); });
118 ViewAbstract::SetWidth(Referenced::RawPtr(childNode), CalcLength(ITEM_WIDTH));
119 ViewAbstract::SetHeight(Referenced::RawPtr(childNode), CalcLength(ITEM_HEIGHT));
120 childNode->MountToParent(frameNode);
121 }
122 return frameNode;
123 }
124
125
ProcessDragItemGroupScene()126 RefPtr<FrameNode> ProcessDragItemGroupScene()
127 {
128 auto gridNode = CreateGridNodeWithChild(DEFAULT_CHILD_COUNT);
129 CHECK_NULL_RETURN(gridNode, nullptr);
130 auto pattern = gridNode->GetPattern<GridPattern>();
131 CHECK_NULL_RETURN(pattern, nullptr);
132 pattern->info_.endIndex_ = DEFAULT_CHILD_COUNT;
133 auto gestureEventHub = gridNode->GetOrCreateGestureEventHub();
134 CHECK_NULL_RETURN(gestureEventHub, nullptr);
135 gestureEventHub->InitDragDropEvent();
136 return gridNode;
137 }
138
SetFrameNodeAllowDrag(RefPtr<FrameNode> & frameNode)139 void SetFrameNodeAllowDrag(RefPtr<FrameNode>& frameNode)
140 {
141 CHECK_NULL_VOID(frameNode);
142 frameNode->draggable_ = true;
143 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
144 CHECK_NULL_VOID(gestureHub);
145 auto eventHub = gestureHub->eventHub_.Upgrade();
146 CHECK_NULL_VOID(eventHub);
147 auto func = [](const RefPtr<OHOS::Ace::DragEvent>&, const std::string&) { return DragDropInfo(); };
148 eventHub->onDragStart_ = func;
149 }
150 /**
151 * @tc.name: DragDropFuncWrapperTestNgCoverage001
152 * @tc.desc: Test DecideWhetherToStopDragging with valid parameters
153 * @tc.type: FUNC
154 * @tc.author:
155 */
156 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage001, TestSize.Level1)
157 {
158 DragPointerEvent pointerEvent;
159 std::string extraParams = "test";
160 int32_t currentPointerId = 1;
161 int32_t containerId = 100;
162
163 auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
164 ASSERT_NE(pipelineContext, nullptr);
165 auto manager = pipelineContext->GetDragDropManager();
166 ASSERT_NE(manager, nullptr);
167 manager->SetDraggingPressedState(false);
168
169 DragDropFuncWrapper::DecideWhetherToStopDragging(pointerEvent, extraParams, currentPointerId, containerId);
170
171 EXPECT_FALSE(manager->IsDraggingPressed(currentPointerId));
172 }
173
174 /**
175 * @tc.name: DragDropFuncWrapperTestNgCoverage002
176 * @tc.desc: Test DecideWhetherToStopDragging with invalid containerId
177 * @tc.type: FUNC
178 * @tc.author:
179 */
180 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage002, TestSize.Level1)
181 {
182 DragPointerEvent pointerEvent;
183 std::string extraParams = "test";
184 int32_t currentPointerId = 1;
185 int32_t invalidContainerId = -1;
186
187 DragDropFuncWrapper::DecideWhetherToStopDragging(pointerEvent, extraParams, currentPointerId, invalidContainerId);
188
189 // No assertion needed as it should safely exit with CHECK_NULL_VOID
190 }
191
192 /**
193 * @tc.name: DragDropFuncWrapperTestNgCoverage003
194 * @tc.desc: Test UpdateDragPreviewOptionsFromModifier with various opacity values
195 * @tc.type: FUNC
196 * @tc.author:
197 */
198 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage003, TestSize.Level1)
199 {
__anonb6e82e360502(WeakPtr<FrameNode> frameNode) 200 auto applyOnNodeSync = [](WeakPtr<FrameNode> frameNode) {
201 auto node = frameNode.Upgrade();
202 CHECK_NULL_VOID(node);
203 node->GetRenderContext()->UpdateOpacity(0.5f);
204 };
205
206 DragPreviewOption option;
207 DragDropFuncWrapper::UpdateDragPreviewOptionsFromModifier(applyOnNodeSync, option);
208
209 EXPECT_EQ(option.options.opacity, 0.5f);
210 }
211
212 /**
213 * @tc.name: DragDropFuncWrapperTestNgCoverage004
214 * @tc.desc: Test UpdateDragPreviewOptionsFromModifier with default opacity
215 * @tc.type: FUNC
216 * @tc.author:
217 */
218 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage004, TestSize.Level1)
219 {
__anonb6e82e360602(WeakPtr<FrameNode> frameNode) 220 auto applyOnNodeSync = [](WeakPtr<FrameNode> frameNode) {
221 auto node = frameNode.Upgrade();
222 CHECK_NULL_VOID(node);
223 node->GetRenderContext()->UpdateOpacity(10.0f); // Invalid value
224 };
225
226 DragPreviewOption option;
227 DragDropFuncWrapper::UpdateDragPreviewOptionsFromModifier(applyOnNodeSync, option);
228
229 EXPECT_EQ(option.options.opacity, 0.95f); // Default opacity
230 }
231
232 /**
233 * @tc.name: DragDropFuncWrapperTestNgCoverage005
234 * @tc.desc: Test UpdatePreviewOptionDefaultAttr without default shadow and radius
235 * @tc.type: FUNC
236 * @tc.author:
237 */
238 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage005, TestSize.Level1)
239 {
240 DragPreviewOption option;
241 option.isDefaultShadowEnabled = false;
242 option.isDefaultRadiusEnabled = false;
243
244 DragDropFuncWrapper::UpdatePreviewOptionDefaultAttr(option);
245
246 EXPECT_EQ(option.options.opacity, 0.95f);
247 EXPECT_FALSE(option.options.shadow.has_value());
248 EXPECT_FALSE(option.options.borderRadius.has_value());
249 }
250
251 /**
252 * @tc.name: DragDropFuncWrapperTestNgCoverage006
253 * @tc.desc: Test PrepareRadiusParametersForDragData with empty radius
254 * @tc.type: FUNC
255 * @tc.author:
256 */
257 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage006, TestSize.Level1)
258 {
259 DragPreviewOption option;
260 option.options.borderRadius = std::nullopt;
261
262 auto arkExtraInfoJson = std::make_unique<JsonValue>();
263 DragDropFuncWrapper::PrepareRadiusParametersForDragData(arkExtraInfoJson, option);
264
265 // No assertion needed as it should safely exit with CHECK_NULL_VOID
266 }
267
268 /**
269 * @tc.name: DragDropFuncWrapperTestNgCoverage007
270 * @tc.desc: Test PrepareShadowParametersForDragData with empty shadow
271 * @tc.type: FUNC
272 * @tc.author:
273 */
274 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage007, TestSize.Level1)
275 {
276 DragPreviewOption option;
277 option.options.shadow = std::nullopt;
278
279 auto arkExtraInfoJson = std::make_unique<JsonValue>();
280 DragDropFuncWrapper::PrepareShadowParametersForDragData(arkExtraInfoJson, option);
281
282 EXPECT_FALSE(arkExtraInfoJson->GetBool("shadow_enable"));
283 }
284
285 /**
286 * @tc.name: DragDropFuncWrapperTestNgCoverage008
287 * @tc.desc: Test GetDefaultShadow with invalid pipeline context
288 * @tc.type: FUNC
289 * @tc.author:
290 */
291 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage008, TestSize.Level1)
292 {
293 auto shadow = DragDropFuncWrapper::GetDefaultShadow();
294 EXPECT_FALSE(shadow.has_value());
295 }
296
297 /**
298 * @tc.name: DragDropFuncWrapperTestNgCoverage009
299 * @tc.desc: Test RadiusToSigma with valid radius
300 * @tc.type: FUNC
301 * @tc.author:
302 */
303 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage009, TestSize.Level1)
304 {
305 float radius = 5.0f;
306 float sigma = DragDropFuncWrapper::RadiusToSigma(radius);
307 EXPECT_GT(sigma, 0.0f);
308 }
309
310 /**
311 * @tc.name: DragDropFuncWrapperTestNgCoverage010
312 * @tc.desc: Test RadiusToSigma with zero radius
313 * @tc.type: FUNC
314 * @tc.author:
315 */
316 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage010, TestSize.Level1)
317 {
318 float radius = 0.0f;
319 float sigma = DragDropFuncWrapper::RadiusToSigma(radius);
320 EXPECT_EQ(sigma, 0.0f);
321 }
322
323 /**
324 * @tc.name: DragDropFuncWrapperTestNgCoverage011
325 * @tc.desc: Test BlurStyleToEffection with invalid pipeline context
326 * @tc.type: FUNC
327 * @tc.author:
328 */
329 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage011, TestSize.Level1)
330 {
331 BlurStyleOption blurStyleOp;
332 blurStyleOp.blurStyle = BlurStyle::BACKGROUND_THICK;
333 blurStyleOp.scale = 0.5;
334 blurStyleOp.colorMode = ThemeColorMode::LIGHT;
335
336 auto effection = DragDropFuncWrapper::BlurStyleToEffection(blurStyleOp);
337 EXPECT_FALSE(effection.has_value());
338 }
339
340 /**
341 * @tc.name: DragDropFuncWrapperTestNgCoverage012
342 * @tc.desc: Test BlurStyleToEffection with invalid blurStyleOp
343 * @tc.type: FUNC
344 * @tc.author:
345 */
346 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage012, TestSize.Level1)
347 {
348 std::optional<BlurStyleOption> blurStyleOp = std::nullopt;
349
350 auto effection = DragDropFuncWrapper::BlurStyleToEffection(blurStyleOp);
351 EXPECT_FALSE(effection.has_value());
352 }
353
354 /**
355 * @tc.name: DragDropFuncWrapperTestNgCoverage013
356 * @tc.desc: Test UpdatePreviewOptionDefaultAttr with default shadow and radius
357 * @tc.type: FUNC
358 * @tc.author:
359 */
360 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage013, TestSize.Level1)
361 {
362 DragPreviewOption option;
363 option.isDefaultShadowEnabled = true;
364 option.isDefaultRadiusEnabled = true;
365
366 DragDropFuncWrapper::UpdatePreviewOptionDefaultAttr(option);
367
368 EXPECT_EQ(option.options.opacity, 0.95f);
369 EXPECT_EQ(option.options.shadow, DragDropFuncWrapper::GetDefaultShadow());
370 EXPECT_EQ(option.options.borderRadius, DragDropFuncWrapper::GetDefaultBorderRadius());
371 }
372
373 /**
374 * @tc.name: DragDropFuncWrapperTestNgCoverage014
375 * @tc.desc: Test UpdateExtraInfo with blur background effect
376 * @tc.type: FUNC
377 * @tc.author:
378 */
379 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage014, TestSize.Level1)
380 {
381 DragPreviewOption option;
382 option.options.opacity = 0.8f;
383 option.options.blurbgEffect.backGroundEffect = EffectOption();
384
385 auto arkExtraInfoJson = std::make_unique<JsonValue>();
386 DragDropFuncWrapper::UpdateExtraInfo(arkExtraInfoJson, option);
387
388 EXPECT_EQ(arkExtraInfoJson->GetDouble("dip_opacity"), 0);
389 }
390
391 /**
392 * @tc.name: DragDropFuncWrapperTestNgCoverage015
393 * @tc.desc: Test PrepareRadiusParametersForDragData with valid radius
394 * @tc.type: FUNC
395 * @tc.author:
396 */
397 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage015, TestSize.Level1)
398 {
399 DragPreviewOption option;
400 option.options.borderRadius->radiusTopLeft = 12.0_vp;
401 option.options.borderRadius->radiusTopRight = 12.0_vp;
402 option.options.borderRadius->radiusBottomRight = 12.0_vp;
403 option.options.borderRadius->radiusBottomLeft = 12.0_vp;
404
405 auto arkExtraInfoJson = std::make_unique<JsonValue>();
406 DragDropFuncWrapper::PrepareRadiusParametersForDragData(arkExtraInfoJson, option);
407
408 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_corner_radius1"), 0);
409 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_corner_radius2"), 0);
410 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_corner_radius3"), 0);
411 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_corner_radius4"), 0);
412 }
413
414 /**
415 * @tc.name: DragDropFuncWrapperTestNgCoverage016
416 * @tc.desc: Test PrepareShadowParametersForDragData with valid shadow
417 * @tc.type: FUNC
418 * @tc.author:
419 */
420 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage016, TestSize.Level1)
421 {
422 DragPreviewOption option;
423 Shadow shadow;
424 shadow.SetIsFilled(true);
425 option.options.shadow = shadow;
426
427 auto arkExtraInfoJson = std::make_unique<JsonValue>();
428 DragDropFuncWrapper::PrepareShadowParametersForDragData(arkExtraInfoJson, option);
429
430 EXPECT_FALSE(arkExtraInfoJson->GetBool("shadow_enable"));
431 }
432
433 /**
434 * @tc.name: DragDropFuncWrapperTestNgCoverage017
435 * @tc.desc: Test ParseShadowInfo with valid shadow
436 * @tc.type: FUNC
437 * @tc.author:
438 */
439 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage017, TestSize.Level1)
440 {
441 Shadow shadow;
442 shadow.SetIsFilled(true);
443 shadow.SetOffset(Offset(5, 5));
444 shadow.SetBlurRadius(10.0);
445 shadow.SetColor(Color::FromARGB(255, 255, 0, 0));
446
447 auto arkExtraInfoJson = std::make_unique<JsonValue>();
448 DragDropFuncWrapper::ParseShadowInfo(shadow, arkExtraInfoJson);
449
450 EXPECT_FALSE(arkExtraInfoJson->GetBool("shadow_is_filled"));
451 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_shadow_OffsetX"), 0);
452 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_shadow_OffsetY"), 0);
453 }
454
455 /**
456 * @tc.name: DragDropFuncWrapperTestNgCoverage018
457 * @tc.desc: Test GetDefaultShadow with valid pipeline context
458 * @tc.type: FUNC
459 * @tc.author:
460 */
461 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage018, TestSize.Level1)
462 {
463 auto shadow = DragDropFuncWrapper::GetDefaultShadow();
464 EXPECT_FALSE(shadow.has_value());
465 }
466
467 /**
468 * @tc.name: DragDropFuncWrapperTestNgCoverage019
469 * @tc.desc: Test BlurStyleToEffection with valid BlurStyleOption
470 * @tc.type: FUNC
471 * @tc.author:
472 */
473 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage019, TestSize.Level1)
474 {
475 BlurStyleOption blurStyleOp;
476 blurStyleOp.blurStyle = BlurStyle::BACKGROUND_THICK;
477 blurStyleOp.scale = 0.5;
478 blurStyleOp.colorMode = ThemeColorMode::LIGHT;
479
480 auto effection = DragDropFuncWrapper::BlurStyleToEffection(blurStyleOp);
481 EXPECT_FALSE(effection.has_value());
482 }
483
484 /**
485 * @tc.name: DragDropFuncWrapperTestNgCoverage020
486 * @tc.desc: Test DecideWhetherToStopDragging
487 * @tc.type: FUNC
488 * @tc.author:
489 */
490 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage020, TestSize.Level1)
491 {
492 int32_t instanceId = -1;
493 int32_t globalX = -1;
494 int32_t globalY = -1;
495 std::string extraParams;
496 int32_t pointerId = -1;
497
498 ContainerScope scope(instanceId);
499 auto container = Container::CurrentSafely();
500 CHECK_NULL_VOID(container);
501 auto pipelineContext = container->GetPipelineContext();
502 CHECK_NULL_VOID(pipelineContext);
503 auto taskExecutor = container->GetTaskExecutor();
504 CHECK_NULL_VOID(taskExecutor);
505
506 taskExecutor->PostTask(
__anonb6e82e360702() 507 [instanceId, globalX, globalY, extraParams, pointerId, context = pipelineContext]() {
508 context->OnDragEvent({globalX, globalY }, DragEventAction::DRAG_EVENT_START_FOR_CONTROLLER);
509 NG::DragDropFuncWrapper::DecideWhetherToStopDragging(
510 { globalX, globalY }, extraParams, pointerId, instanceId);
511 },
512 TaskExecutor::TaskType::UI, "ArkUIDragHandleDragEventStart");
513 EXPECT_EQ(instanceId, -1);
514 }
515
516 /**
517 * @tc.name: DragDropFuncWrapperTestNgCoverage022
518 * @tc.desc: Test PrepareShadowParametersForDragData with Invalid shadow
519 * @tc.type: FUNC
520 * @tc.author:
521 */
522 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage022, TestSize.Level1)
523 {
524 DragPreviewOption option;
525 Shadow shadow;
526 shadow.SetIsFilled(true);
527 shadow.SetOffset(Offset(5, 5));
528 shadow.SetBlurRadius(10.0);
529 shadow.SetColor(Color::FromARGB(255, 255, 0, 0));
530 option.options.shadow = shadow;
531
532 auto arkExtraInfoJson = std::make_unique<JsonValue>();
533 DragDropFuncWrapper::PrepareShadowParametersForDragData(arkExtraInfoJson, option);
534
535 EXPECT_TRUE(arkExtraInfoJson->GetValue("shadow_enable"));
536 }
537
538
539 /**
540 * @tc.name: DragDropFuncWrapperTestNgCoverage023
541 * @tc.desc: Test PrepareShadowParametersForDragData with empty shadow
542 * @tc.type: FUNC
543 * @tc.author:
544 */
545 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage023, TestSize.Level1)
546 {
547 /**
548 * @tc.steps: step1. Create frameNode.
549 */
550 auto frameNode = FrameNode::CreateFrameNode(
551 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
552 /**
553 * @tc.steps: step2. Test GetDefaultBorderRadius
554 */
555 NG::DragPreviewOption dragPreviewOptions { false, false, false, false, true };
556 dragPreviewOptions.options.borderRadius = DragDropFuncWrapper::GetDefaultBorderRadius();
557 frameNode->SetDragPreviewOptions(dragPreviewOptions);
558 auto dragPreviewOption = frameNode->GetDragPreviewOption();
559 auto borderRadius = dragPreviewOption.options.borderRadius;
560 EXPECT_EQ(borderRadius.value().radiusTopLeft.value().Value(), 12.0);
561 EXPECT_EQ(borderRadius.value().radiusTopRight.value().Value(), 12.0);
562 EXPECT_EQ(borderRadius.value().radiusBottomRight.value().Value(), 12.0);
563 EXPECT_EQ(borderRadius.value().radiusBottomLeft.value().Value(), 12.0);
564 /**
565 * @tc.steps: step3. Test PrepareRadiusParametersForDragData
566 */
567 auto arkExtraInfoJson = JsonUtil::Create(true);
568 DragDropFuncWrapper::PrepareRadiusParametersForDragData(arkExtraInfoJson, dragPreviewOption);
569 auto radiusTopLeft = arkExtraInfoJson->GetDouble("drag_corner_radius1", -1);
570 auto radiusTopRight = arkExtraInfoJson->GetDouble("drag_corner_radius2", -1);
571 auto radiusBottomRight = arkExtraInfoJson->GetDouble("drag_corner_radius3", -1);
572 auto radiusBottomLeft = arkExtraInfoJson->GetDouble("drag_corner_radius4", -1);
573 EXPECT_EQ(radiusTopLeft, 12.0);
574 EXPECT_EQ(radiusTopRight, 12.0);
575 EXPECT_EQ(radiusBottomRight, 12.0);
576 EXPECT_EQ(radiusBottomLeft, 12.0);
577 }
578
579 /**
580 * @tc.name: DragDropFuncWrapperTestNgCoverage024
581 * @tc.desc: Test PrepareRadiusParametersForDragData with valid radius
582 * @tc.type: FUNC
583 * @tc.author:
584 */
585 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage024, TestSize.Level1)
586 {
587 /**
588 * @tc.steps: step1. Create frameNode.
589 */
590 auto frameNode = FrameNode::CreateFrameNode(
591 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
592 /**
593 * @tc.steps: step2. Test GetDefaultBorderRadius
594 */
595 NG::DragPreviewOption dragPreviewOptions { false, false, false, false, true };
596 dragPreviewOptions.options.borderRadius = DragDropFuncWrapper::GetDefaultBorderRadius();
597 frameNode->SetDragPreviewOptions(dragPreviewOptions);
598 auto dragPreviewOption = frameNode->GetDragPreviewOption();
599 dragPreviewOption.options.borderRadius->radiusTopLeft = std::nullopt;
600 dragPreviewOption.options.borderRadius->radiusTopRight = std::nullopt;
601 dragPreviewOption.options.borderRadius->radiusBottomRight = std::nullopt;
602 dragPreviewOption.options.borderRadius->radiusBottomLeft = std::nullopt;
603 /**
604 * @tc.steps: step3. Test PrepareRadiusParametersForDragData
605 */
606 auto arkExtraInfoJson = JsonUtil::Create(true);
607 DragDropFuncWrapper::PrepareRadiusParametersForDragData(arkExtraInfoJson, dragPreviewOption);
608 auto radiusTopLeft = arkExtraInfoJson->GetDouble("drag_corner_radius1", -1);
609 auto radiusTopRight = arkExtraInfoJson->GetDouble("drag_corner_radius2", -1);
610 auto radiusBottomRight = arkExtraInfoJson->GetDouble("drag_corner_radius3", -1);
611 auto radiusBottomLeft = arkExtraInfoJson->GetDouble("drag_corner_radius4", -1);
612 EXPECT_EQ(radiusTopLeft, -1);
613 EXPECT_EQ(radiusTopRight, -1);
614 EXPECT_EQ(radiusBottomRight, -1);
615 EXPECT_EQ(radiusBottomLeft, -1);
616 }
617
618 /**
619 * @tc.name: DragDropFuncWrapperTestNgCoverage026
620 * @tc.desc: Test UpdateExtraInfo with invalid radius
621 * @tc.type: FUNC
622 * @tc.author:
623 */
624 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage026, TestSize.Level1)
625 {
626 DragPreviewOption option;
627 option.options.opacity = 0.8f;
628 option.options.blurbgEffect.backGroundEffect = EffectOption();
629 option.options.blurbgEffect.backGroundEffect.radius.SetValue(1.0F);
630
631 auto arkExtraInfoJson = std::make_unique<JsonValue>();
632 DragDropFuncWrapper::UpdateExtraInfo(arkExtraInfoJson, option);
633
634 EXPECT_EQ(arkExtraInfoJson->GetDouble("dip_opacity"), 0);
635 }
636 /**
637 * @tc.name: DragDropFuncWrapperTestNgCoverage027
638 * @tc.desc: Test UpdateDragPreviewOptionsFromModifier with BackgroundEffect values
639 * @tc.type: FUNC
640 * @tc.author:
641 */
642 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage027, TestSize.Level1)
643 {
__anonb6e82e360802(WeakPtr<FrameNode> frameNode) 644 auto applyOnNodeSync = [](WeakPtr<FrameNode> frameNode) {
645 auto node = frameNode.Upgrade();
646 CHECK_NULL_VOID(node);
647 CalcDimension radius;
648 radius.SetValue(80.0f);
649 Color color = Color::FromARGB(13, 255, 255, 255);
650 EffectOption effoption = { radius, 1.0, 1.08, color };
651 node->GetRenderContext()->UpdateBackgroundEffect(effoption);
652 };
653
654 DragPreviewOption option;
655 DragDropFuncWrapper::UpdateDragPreviewOptionsFromModifier(applyOnNodeSync, option);
656
657 EXPECT_TRUE(option.options.blurbgEffect.backGroundEffect.radius.IsValid());
658 }
659
660 /**
661 * @tc.name: DragDropFuncWrapperTestNgCoverage028
662 * @tc.desc: Test UpdateDragPreviewOptionsFromModifier with BackShadow ,BorderRadius,without,bgEffect,with
663 * BackBlurStyle ;
664 * @tc.type: FUNC
665 * @tc.author:
666 */
667 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage028, TestSize.Level1)
668 {
__anonb6e82e360902(WeakPtr<FrameNode> frameNode) 669 auto applyOnNodeSync = [](WeakPtr<FrameNode> frameNode) {
670 auto node = frameNode.Upgrade();
671 CHECK_NULL_VOID(node);
672 Shadow shadow;
673 shadow.SetIsFilled(true);
674 shadow.SetOffset(Offset(5, 5));
675 shadow.SetBlurRadius(10.0);
676 shadow.SetColor(Color::FromARGB(255, 255, 0, 0));
677 BlurStyleOption styleOption;
678 styleOption.blurStyle = BlurStyle::COMPONENT_THICK;
679 styleOption.scale = 0.5;
680 styleOption.colorMode = ThemeColorMode::LIGHT;
681 BorderRadiusProperty borderRadius;
682 borderRadius.SetRadius(Dimension(50.0));
683 node->GetRenderContext()->UpdateBorderRadius(borderRadius);
684 node->GetRenderContext()->UpdateBackShadow(shadow);
685 node->GetRenderContext()->UpdateBackBlurStyle(styleOption);
686 node->GetRenderContext()->UpdateBackgroundEffect(std::nullopt);
687
688
689 };
690
691 DragPreviewOption option;
692 DragDropFuncWrapper::UpdateDragPreviewOptionsFromModifier(applyOnNodeSync, option);
693
694 EXPECT_TRUE(option.options.shadow.has_value());
695 EXPECT_TRUE(option.options.borderRadius.has_value());
696 EXPECT_FALSE(option.options.blurbgEffect.backGroundEffect.radius.IsValid());
697 }
698
699 /**
700 * @tc.name: TestIsSelectedItemNode
701 * @tc.desc: Test IsSelectedItemNode func
702 * @tc.type: FUNC
703 * @tc.author:
704 */
705 HWTEST_F(DragDropFuncWrapperTestNgCoverage, TestIsSelectedItemNode, TestSize.Level1)
706 {
707 int32_t caseNum = 0;
708 for (const auto& testCase : DRAG_MULTI_CASES) {
709 /**
710 * @tc.steps: step1. Create grid with gridItem frame node tree.
711 * @tc.expected: instance is not null.
712 */
713 auto gridNode = ProcessDragItemGroupScene();
714 ASSERT_NE(gridNode, nullptr);
715 auto gridItem = AceType::DynamicCast<FrameNode>(gridNode->GetChildByIndex(0));
716 ASSERT_NE(gridItem, nullptr);
717 auto gridItemPattern = gridItem->GetPattern<GridItemPattern>();
718 ASSERT_NE(gridItemPattern, nullptr);
719
720 /**
721 * @tc.steps: step2. Set GridItemNode selected
722 */
723 gridItemPattern->SetSelected(testCase.isSelected);
724
725 /**
726 * @tc.steps: step3. Set GridItemNode isMultiSelectionEnabled
727 */
728 auto dragPreviewOption = gridItem->GetDragPreviewOption();
729 dragPreviewOption.isMultiSelectionEnabled = testCase.isMultiSelectionEnabled;
730 gridItem->SetDragPreviewOptions(dragPreviewOption);
731
732 /**
733 * @tc.steps: step4. Set GridItemNode isAllowDrag
734 */
735 if (testCase.isAllowDrag) {
736 SetFrameNodeAllowDrag(gridItem);
737 }
738 EXPECT_TRUE(IsDragEventStateEqual(caseNum, DragDropFuncWrapper::IsSelectedItemNode(gridItem),
739 testCase.expectResult));
740 caseNum++;
741 }
742 }
743
744 /**
745 * @tc.name: Test IsBelongToMultiItemNode
746 * @tc.desc: Test IsBelongToMultiItemNode func
747 * @tc.type: FUNC
748 * @tc.author:
749 */
750 HWTEST_F(DragDropFuncWrapperTestNgCoverage, TestIsBelongToMultiItemNode, TestSize.Level1)
751 {
752 /**
753 * @tc.steps: step1. Create grid with gridItem frame node tree.
754 * @tc.expected: instance is not null.
755 */
756 auto gridNode = ProcessDragItemGroupScene();
757 ASSERT_NE(gridNode, nullptr);
758 auto gridItem = AceType::DynamicCast<FrameNode>(gridNode->GetChildByIndex(0));
759 ASSERT_NE(gridItem, nullptr);
760
761 /**
762 * @tc.steps: step2. Create frameNode.
763 * @tc.expected: IsBelongToMultiItemNode return false.
764 */
765 auto frameNode = FrameNode::CreateFrameNode(
766 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
767 ASSERT_NE(frameNode, nullptr);
768 frameNode->MountToParent(gridItem);
769 EXPECT_FALSE(DragDropFuncWrapper::IsBelongToMultiItemNode(frameNode));
770
771 /**
772 * @tc.steps: step3. Set frameNode is selected and allowDrag.
773 * @tc.expected: IsBelongToMultiItemNode return true.
774 */
775 auto gridItemPattern = gridItem->GetPattern<GridItemPattern>();
776 ASSERT_NE(gridItemPattern, nullptr);
777 gridItemPattern->SetSelected(true);
778 auto dragPreviewOption = gridItem->GetDragPreviewOption();
779 dragPreviewOption.isMultiSelectionEnabled = true;
780 gridItem->SetDragPreviewOptions(dragPreviewOption);
781 SetFrameNodeAllowDrag(gridItem);
782
783 EXPECT_TRUE(DragDropFuncWrapper::IsBelongToMultiItemNode(frameNode));
784 }
785
786 /**
787 * @tc.name: Test CheckIsNeedGather
788 * @tc.desc: Test CheckIsNeedGather func
789 * @tc.type: FUNC
790 * @tc.author:
791 */
792 HWTEST_F(DragDropFuncWrapperTestNgCoverage, CheckIsNeedGather, TestSize.Level1)
793 {
794 int32_t caseNum = 0;
795 for (const auto& testCase : DRAG_MULTI_CASES) {
796 /**
797 * @tc.steps: step1. Create grid with gridItem frame node tree.
798 * @tc.expected: instance is not null.
799 */
800 auto gridNode = ProcessDragItemGroupScene();
801 ASSERT_NE(gridNode, nullptr);
802 auto gridItem = AceType::DynamicCast<FrameNode>(gridNode->GetChildByIndex(0));
803 ASSERT_NE(gridItem, nullptr);
804 auto gridItemPattern = gridItem->GetPattern<GridItemPattern>();
805 ASSERT_NE(gridItemPattern, nullptr);
806
807 /**
808 * @tc.steps: step2. Set GridItemNode selected
809 */
810 gridItemPattern->SetSelected(testCase.isSelected);
811
812 /**
813 * @tc.steps: step3. Set GridItemNode isMultiSelectionEnabled
814 */
815 auto dragPreviewOption = gridItem->GetDragPreviewOption();
816 dragPreviewOption.isMultiSelectionEnabled = testCase.isMultiSelectionEnabled;
817 gridItem->SetDragPreviewOptions(dragPreviewOption);
818
819 /**
820 * @tc.steps: step4. Set GridItemNode isAllowDrag
821 */
822 if (testCase.isAllowDrag) {
823 SetFrameNodeAllowDrag(gridItem);
824 }
825 EXPECT_TRUE(IsDragEventStateEqual(caseNum, DragDropFuncWrapper::CheckIsNeedGather(gridItem),
826 testCase.expectResult));
827 caseNum++;
828 }
829 }
830
831 /**
832 * @tc.name: Test FindItemParentNode
833 * @tc.desc: Test FindItemParentNode func
834 * @tc.type: FUNC
835 * @tc.author:
836 */
837 HWTEST_F(DragDropFuncWrapperTestNgCoverage, FindItemParentNode, TestSize.Level1)
838 {
839 /**
840 * @tc.steps: step1. Create grid with gridItem frame node tree.
841 * @tc.expected: instance is not null.
842 * @tc.expected: FindItemParentNode return false.
843 */
844 auto gridNode = ProcessDragItemGroupScene();
845 ASSERT_NE(gridNode, nullptr);
846 auto gridItem = AceType::DynamicCast<FrameNode>(gridNode->GetChildByIndex(0));
847 ASSERT_NE(gridItem, nullptr);
848
849 /**
850 * @tc.steps: step2.run FindItemParentNode func
851 * @tc.expected: FindItemParentNode return gridNode.
852 */
853 SetFrameNodeAllowDrag(gridItem);
854 EXPECT_EQ(DragDropFuncWrapper::FindItemParentNode(gridItem), gridNode);
855
856 /**
857 * @tc.steps: step3.test other class frameNode
858 * @tc.expected: FindItemParentNode return nullptr.
859 */
860 auto frameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonb6e82e360a02() 861 []() {return AceType::MakeRefPtr<Pattern>(); });
862 ASSERT_NE(frameNode, nullptr);
863 frameNode->MountToParent(gridNode);
864 EXPECT_EQ(DragDropFuncWrapper::FindItemParentNode(frameNode), nullptr);
865 }
866
867 /**
868 * @tc.name: Test RequestDragEndPending
869 * @tc.desc: Test RequestDragEndPending func
870 * @tc.type: FUNC
871 * @tc.author:
872 */
873 HWTEST_F(DragDropFuncWrapperTestNgCoverage, RequestDragEndPending, TestSize.Level1)
874 {
875 int32_t requestId = DragDropFuncWrapper::RequestDragEndPending();
876 EXPECT_EQ(requestId, -1);
877
878 DragDropGlobalController::GetInstance().SetIsOnOnDropPhase(true);
879 requestId = DragDropFuncWrapper::RequestDragEndPending();
880 EXPECT_NE(requestId, -1);
881
882 DragDropGlobalController::GetInstance().SetIsOnOnDropPhase(false);
883 requestId = DragDropFuncWrapper::RequestDragEndPending();
884 EXPECT_EQ(requestId, -1);
885 }
886
887 /**
888 * @tc.name: Test NotifyDragResult
889 * @tc.desc: Test NotifyDragResult func
890 * @tc.type: FUNC
891 * @tc.author:
892 */
893 HWTEST_F(DragDropFuncWrapperTestNgCoverage, NotifyDragResult, TestSize.Level1)
894 {
895 int32_t requestId = 1;
896 DragDropGlobalController::GetInstance().requestId_ = 0;
897 int32_t ret = DragDropFuncWrapper::NotifyDragResult(requestId, static_cast<int32_t>(DragRet::DRAG_SUCCESS));
898 EXPECT_EQ(ret, -1);
899 EXPECT_EQ(DragDropGlobalController::GetInstance().dragResult_, DragRet::DRAG_FAIL);
900
901 DragDropGlobalController::GetInstance().SetIsOnOnDropPhase(true);
902 ret = DragDropFuncWrapper::NotifyDragResult(requestId, static_cast<int32_t>(DragRet::DRAG_SUCCESS));
903 EXPECT_EQ(ret, -1);
904 EXPECT_EQ(DragDropGlobalController::GetInstance().dragResult_, DragRet::DRAG_FAIL);
905
906 DragDropGlobalController::GetInstance().requestId_ = requestId;
907 ret = DragDropFuncWrapper::NotifyDragResult(requestId, static_cast<int32_t>(DragRet::DRAG_SUCCESS));
908 EXPECT_EQ(ret, 0);
909 EXPECT_EQ(DragDropGlobalController::GetInstance().dragResult_, DragRet::DRAG_SUCCESS);
910 DragDropGlobalController::GetInstance().SetIsOnOnDropPhase(false);
911 }
912
913 /**
914 * @tc.name: Test NotifyDragEndPendingDone
915 * @tc.desc: Test NotifyDragEndPendingDone func
916 * @tc.type: FUNC
917 * @tc.author:
918 */
919 HWTEST_F(DragDropFuncWrapperTestNgCoverage, NotifyDragEndPendingDone, TestSize.Level1)
920 {
921 int32_t requestId = 1;
922 DragDropGlobalController::GetInstance().requestId_ = 0;
923 DragDropGlobalController::GetInstance().dragResult_ = DragRet::DRAG_SUCCESS;
924 int32_t ret = DragDropFuncWrapper::NotifyDragEndPendingDone(requestId);
925 EXPECT_EQ(ret, -1);
926 EXPECT_EQ(DragDropGlobalController::GetInstance().dragResult_, DragRet::DRAG_SUCCESS);
927
928 DragDropGlobalController::GetInstance().SetIsOnOnDropPhase(true);
929 ret = DragDropFuncWrapper::NotifyDragEndPendingDone(requestId);
930 EXPECT_EQ(ret, -1);
931 EXPECT_EQ(DragDropGlobalController::GetInstance().dragResult_, DragRet::DRAG_SUCCESS);
932
933 DragDropGlobalController::GetInstance().requestId_ = requestId;
934 ret = DragDropFuncWrapper::NotifyDragEndPendingDone(requestId);
935 EXPECT_EQ(ret, 0);
936 EXPECT_EQ(DragDropGlobalController::GetInstance().dragResult_, DragRet::DRAG_FAIL);
937 DragDropGlobalController::GetInstance().SetIsOnOnDropPhase(false);
938 }
939
940 /**
941 * @tc.name: Test GetAnonyString
942 * @tc.desc: Test GetAnonyString func
943 * @tc.type: FUNC
944 * @tc.author:
945 */
946 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetAnonyString, TestSize.Level1)
947 {
948 std::string fullString = "";
949 std::string anonyStr = "";
950 std::string ret = NG::DragDropFuncWrapper::GetAnonyString(fullString);
951 EXPECT_EQ(ret, anonyStr);
952
953 fullString = "test";
954 anonyStr = "t******t";
955 ret = NG::DragDropFuncWrapper::GetAnonyString(fullString);
956 EXPECT_EQ(ret, anonyStr);
957
958 fullString = "testFullString";
959 anonyStr = "test******ring";
960 ret = NG::DragDropFuncWrapper::GetAnonyString(fullString);
961 EXPECT_EQ(ret, anonyStr);
962 }
963
964 /**
965 * @tc.name: Test GetPointerEventAction
966 * @tc.desc: Test GetPointerEventAction func
967 * @tc.type: FUNC
968 * @tc.author:
969 */
970 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetPointerEventAction, TestSize.Level1)
971 {
972 TouchEvent touchPoint;
973 DragPointerEvent event;
974
975 NG::DragDropFuncWrapper::GetPointerEventAction(touchPoint, event);
976 EXPECT_EQ(event.action, PointerAction::UNKNOWN);
977
978 touchPoint.type = TouchType::CANCEL;
979 NG::DragDropFuncWrapper::GetPointerEventAction(touchPoint, event);
980 EXPECT_EQ(event.action, PointerAction::CANCEL);
981
982 touchPoint.type = TouchType::DOWN;
983 NG::DragDropFuncWrapper::GetPointerEventAction(touchPoint, event);
984 EXPECT_EQ(event.action, PointerAction::DOWN);
985
986 touchPoint.type = TouchType::MOVE;
987 NG::DragDropFuncWrapper::GetPointerEventAction(touchPoint, event);
988 EXPECT_EQ(event.action, PointerAction::MOVE);
989
990 touchPoint.type = TouchType::UP;
991 NG::DragDropFuncWrapper::GetPointerEventAction(touchPoint, event);
992 EXPECT_EQ(event.action, PointerAction::UP);
993
994 touchPoint.type = TouchType::PULL_MOVE;
995 NG::DragDropFuncWrapper::GetPointerEventAction(touchPoint, event);
996 EXPECT_EQ(event.action, PointerAction::PULL_MOVE);
997
998 touchPoint.type = TouchType::PULL_UP;
999 NG::DragDropFuncWrapper::GetPointerEventAction(touchPoint, event);
1000 EXPECT_EQ(event.action, PointerAction::PULL_UP);
1001
1002 touchPoint.type = TouchType::PULL_IN_WINDOW;
1003 NG::DragDropFuncWrapper::GetPointerEventAction(touchPoint, event);
1004 EXPECT_EQ(event.action, PointerAction::PULL_IN_WINDOW);
1005
1006 touchPoint.type = TouchType::PULL_OUT_WINDOW;
1007 NG::DragDropFuncWrapper::GetPointerEventAction(touchPoint, event);
1008 EXPECT_EQ(event.action, PointerAction::PULL_OUT_WINDOW);
1009 }
1010
1011 /**
1012 * @tc.name: Test GetFrameNodeByInspectorId
1013 * @tc.desc: Test GetFrameNodeByInspectorId func
1014 * @tc.type: FUNC
1015 * @tc.author:
1016 */
1017 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeByInspectorId, TestSize.Level1)
1018 {
1019 std::string inspectorId = "";
1020 RefPtr<FrameNode> ret = NG::DragDropFuncWrapper::GetFrameNodeByInspectorId(inspectorId);
1021 EXPECT_EQ(ret, nullptr);
1022
1023 inspectorId = "test";
1024 auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG,
1025 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1026 auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
1027 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1028 frameNode->UpdateInspectorId(inspectorId);
1029 auto context = PipelineContext::GetCurrentContext();
1030 context->rootNode_ = rootNode;
1031 rootNode->AddChild(frameNode);
1032 ret = NG::DragDropFuncWrapper::GetFrameNodeByInspectorId(inspectorId);
1033 EXPECT_EQ(ret, frameNode);
1034
1035 frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::GONE);
1036 ret = NG::DragDropFuncWrapper::GetFrameNodeByInspectorId(inspectorId);
1037 EXPECT_EQ(ret, nullptr);
1038
1039 frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::INVISIBLE);
1040 ret = NG::DragDropFuncWrapper::GetFrameNodeByInspectorId(inspectorId);
1041 EXPECT_EQ(ret, nullptr);
1042 }
1043
1044 /**
1045 * @tc.name: Test GetPointRelativeToMainWindow
1046 * @tc.desc: Test GetPointRelativeToMainWindow func
1047 * @tc.type: FUNC
1048 * @tc.author:
1049 */
1050 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetPointRelativeToMainWindow, TestSize.Level1)
1051 {
1052 Point point = { 0, 0 };
1053 OffsetF ret = NG::DragDropFuncWrapper::GetPointRelativeToMainWindow(point);
1054 EXPECT_EQ(ret.GetX(), point.GetX());
1055 EXPECT_EQ(ret.GetY(), point.GetY());
1056 }
1057
1058 /**
1059 * @tc.name: Test GetFrameNodeByKey
1060 * @tc.desc: Test GetFrameNodeByKey func
1061 * @tc.type: FUNC
1062 * @tc.author:
1063 */
1064 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeByKey, TestSize.Level1)
1065 {
1066 auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
1067 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1068 std::string key = "";
1069 RefPtr<FrameNode> ret = NG::DragDropFuncWrapper::GetFrameNodeByKey(frameNode, key);
1070 EXPECT_NE(ret, nullptr);
1071 }
1072
1073 /**
1074 * @tc.name: StartDragAction
1075 * @tc.desc: Test StartDragAction func
1076 * @tc.type: FUNC
1077 * @tc.author:
1078 */
1079 HWTEST_F(DragDropFuncWrapperTestNgCoverage, StartDragAction, TestSize.Level1)
1080 {
1081 auto dragAction = std::make_shared<OHOS::Ace::NG::ArkUIInteralDragAction>();
1082 auto container = Container::Current();
1083 AceEngine& aceEngine = AceEngine::Get();
1084 aceEngine.AddContainer(0, container);
1085 dragAction->instanceId = 0;
1086 int32_t ret = DragDropFuncWrapper::StartDragAction(dragAction);
1087 EXPECT_EQ(ret, -1);
1088
1089 MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1090 aceEngine.AddContainer(1, MockContainer::container_);
1091 dragAction->instanceId = 1;
1092 ret = DragDropFuncWrapper::StartDragAction(dragAction);
1093 EXPECT_EQ(ret, -1);
1094
1095 dragAction->dragState = DragAdapterState::SENDING;
1096 ret = DragDropFuncWrapper::StartDragAction(dragAction);
1097 EXPECT_EQ(ret, -1);
1098
1099 MockContainer::Current()->pipelineContext_->SetIsDragging(true);
1100 ret = DragDropFuncWrapper::StartDragAction(dragAction);
1101 EXPECT_EQ(ret, -1);
1102 }
1103
1104 /**
1105 * @tc.name: HandleOnDragEvent
1106 * @tc.desc: Test HandleOnDragEvent func
1107 * @tc.type: FUNC
1108 * @tc.author:
1109 */
1110 HWTEST_F(DragDropFuncWrapperTestNgCoverage, HandleOnDragEvent, TestSize.Level1)
1111 {
1112 auto dragAction = std::make_shared<OHOS::Ace::NG::ArkUIInteralDragAction>();
1113 MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1114 AceEngine& aceEngine = AceEngine::Get();
1115 aceEngine.AddContainer(0, MockContainer::container_);
1116 dragAction->instanceId = 0;
1117 dragAction->dragState = DragAdapterState::INIT;
1118 DragDropFuncWrapper::HandleOnDragEvent(dragAction);
1119 EXPECT_EQ(dragAction->dragState, DragAdapterState::INIT);
1120
1121 dragAction->dragState = DragAdapterState::SENDING;
1122 DragDropFuncWrapper::HandleOnDragEvent(dragAction);
1123 EXPECT_EQ(dragAction->dragState, DragAdapterState::SUCCESS);
1124 }
1125
1126 /**
1127 * @tc.name: DragDropFuncWrapperTestNgCoverage029
1128 * @tc.desc: Test GetPaintRectCenter Func
1129 * @tc.type: FUNC
1130 * @tc.author:
1131 */
1132 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage029, TestSize.Level1)
1133 {
1134 auto frameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonb6e82e360b02() 1135 []() { return AceType::MakeRefPtr<Pattern>(); });
1136 ASSERT_NE(frameNode, nullptr);
1137 frameNode->parent_ = nullptr;
1138 auto actualResults = DragDropFuncWrapper::GetPaintRectCenter(frameNode, false);
1139 auto context = frameNode->GetRenderContext();
1140 ASSERT_NE(context, nullptr);
1141 auto paintRect = context->GetPaintRectWithoutTransform();
1142 auto offset = paintRect.GetOffset();
1143 PointF pointNode(offset.GetX() + paintRect.Width() / 2.0f, offset.GetY() + paintRect.Height() / 2.0f);
1144 auto expectResult = OffsetF(pointNode.GetX(), pointNode.GetY());
1145 EXPECT_EQ(expectResult, actualResults);
1146 }
1147
1148 /**
1149 * @tc.name: DragDropFuncWrapperTestNgCoverage030
1150 * @tc.desc: Test GetPaintRectCenter Func When checkWindowBoundary Is False IsWindowBoundary() Is True
1151 * @tc.type: FUNC
1152 * @tc.author:
1153 */
1154 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage030, TestSize.Level1)
1155 {
1156 auto frameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonb6e82e360c02() 1157 []() { return AceType::MakeRefPtr<Pattern>(); });
1158 auto frameNodeCopy = FrameNode::GetOrCreateFrameNode(V2::NAVDESTINATION_TITLE_BAR_ETS_TAG,
__anonb6e82e360d02() 1159 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<Pattern>(); });
1160 ASSERT_NE(frameNode, nullptr);
1161 ASSERT_NE(frameNodeCopy, nullptr);
1162 frameNodeCopy->SetWindowBoundary(true);
1163 frameNode->parent_ = frameNodeCopy;
1164 DragDropFuncWrapper::GetPaintRectCenter(frameNode, true);
1165 auto actualResults = DragDropFuncWrapper::GetPaintRectCenter(frameNode, false);
1166 auto context = frameNode->GetRenderContext();
1167 ASSERT_NE(context, nullptr);
1168 auto paintRect = context->GetPaintRectWithoutTransform();
1169 auto offset = paintRect.GetOffset();
1170 PointF pointNode(offset.GetX() + paintRect.Width() / 2.0f, offset.GetY() + paintRect.Height() / 2.0f);
1171 auto expectResult = OffsetF(pointNode.GetX(), pointNode.GetY());
1172 EXPECT_EQ(expectResult, actualResults);
1173 }
1174
1175 /**
1176 * @tc.name: DragDropFuncWrapperTestNgCoverage031
1177 * @tc.desc: Test GetPaintRectCenter Func When checkWindowBoundary Is True IsWindowBoundary() Is False
1178 * @tc.type: FUNC
1179 * @tc.author:
1180 */
1181 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage031, TestSize.Level1)
1182 {
1183 auto frameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonb6e82e360e02() 1184 []() { return AceType::MakeRefPtr<Pattern>(); });
1185 auto frameNodeCopy = FrameNode::GetOrCreateFrameNode(V2::NAVDESTINATION_TITLE_BAR_ETS_TAG,
__anonb6e82e360f02() 1186 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<Pattern>(); });
1187 ASSERT_NE(frameNode, nullptr);
1188 ASSERT_NE(frameNodeCopy, nullptr);
1189 frameNodeCopy->SetWindowBoundary(false);
1190 frameNode->parent_ = frameNodeCopy;
1191 DragDropFuncWrapper::GetPaintRectCenter(frameNode, true);
1192 auto actualResults = DragDropFuncWrapper::GetPaintRectCenter(frameNode, false);
1193 auto context = frameNode->GetRenderContext();
1194 ASSERT_NE(context, nullptr);
1195 auto paintRect = context->GetPaintRectWithoutTransform();
1196 auto offset = paintRect.GetOffset();
1197 PointF pointNode(offset.GetX() + paintRect.Width() / 2.0f, offset.GetY() + paintRect.Height() / 2.0f);
1198 auto expectResult = OffsetF(pointNode.GetX(), pointNode.GetY());
1199 EXPECT_EQ(expectResult, actualResults);
1200 }
1201
1202 /**
1203 * @tc.name: DragDropFuncWrapperTestNgCoverage032
1204 * @tc.desc: Test GetPaintRectCenter Func When checkWindowBoundary Is True IsWindowBoundary() Is True
1205 * @tc.type: FUNC
1206 * @tc.author:
1207 */
1208 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage032, TestSize.Level1)
1209 {
1210 auto frameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonb6e82e361002() 1211 []() { return AceType::MakeRefPtr<Pattern>(); });
1212 auto frameNodeCopy = FrameNode::GetOrCreateFrameNode(V2::NAVDESTINATION_TITLE_BAR_ETS_TAG,
__anonb6e82e361102() 1213 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<Pattern>(); });
1214 ASSERT_NE(frameNode, nullptr);
1215 ASSERT_NE(frameNodeCopy, nullptr);
1216 frameNodeCopy->SetWindowBoundary(true);
1217 frameNode->parent_ = frameNodeCopy;
1218 DragDropFuncWrapper::GetPaintRectCenter(frameNode, false);
1219 auto actualResults = DragDropFuncWrapper::GetPaintRectCenter(frameNode, false);
1220 auto context = frameNode->GetRenderContext();
1221 ASSERT_NE(context, nullptr);
1222 auto paintRect = context->GetPaintRectWithoutTransform();
1223 auto offset = paintRect.GetOffset();
1224 PointF pointNode(offset.GetX() + paintRect.Width() / 2.0f, offset.GetY() + paintRect.Height() / 2.0f);
1225 auto expectResult = OffsetF(pointNode.GetX(), pointNode.GetY());
1226 EXPECT_EQ(expectResult, actualResults);
1227 }
1228
1229 /**
1230 * @tc.name: DragDropFuncWrapperTestNgCoverage033
1231 * @tc.desc: Test GetPaintRectCenter Func When checkWindowBoundary Is True IsWindowBoundary() Is True
1232 * @tc.type: FUNC
1233 * @tc.author:
1234 */
1235 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage033, TestSize.Level1)
1236 {
1237 auto frameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonb6e82e361202() 1238 []() { return AceType::MakeRefPtr<Pattern>(); });
1239 auto frameNodeCopy = FrameNode::GetOrCreateFrameNode(V2::NAVDESTINATION_TITLE_BAR_ETS_TAG,
__anonb6e82e361302() 1240 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<Pattern>(); });
1241 ASSERT_NE(frameNode, nullptr);
1242 ASSERT_NE(frameNodeCopy, nullptr);
1243 frameNodeCopy->SetWindowBoundary(false);
1244 frameNode->parent_ = frameNodeCopy;
1245 DragDropFuncWrapper::GetPaintRectCenter(frameNode, false);
1246 auto actualResults = DragDropFuncWrapper::GetPaintRectCenter(frameNode, false);
1247 auto context = frameNode->GetRenderContext();
1248 ASSERT_NE(context, nullptr);
1249 auto paintRect = context->GetPaintRectWithoutTransform();
1250 auto offset = paintRect.GetOffset();
1251 PointF pointNode(offset.GetX() + paintRect.Width() / 2.0f, offset.GetY() + paintRect.Height() / 2.0f);
1252 auto expectResult = OffsetF(pointNode.GetX(), pointNode.GetY());
1253 EXPECT_EQ(expectResult, actualResults);
1254 }
1255
1256 /**
1257 * @tc.name: DragDropFuncWrapperTestNgCoverage034
1258 * @tc.desc: Test IsExpandDisplay func
1259 * @tc.type: FUNC
1260 * @tc.author:
1261 */
1262 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage034, TestSize.Level1)
1263 {
1264 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1265 ASSERT_NE(themeManager, nullptr);
1266 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1267 auto selectTheme = AceType::MakeRefPtr<SelectTheme>();
1268 ASSERT_NE(selectTheme, nullptr);
1269 selectTheme->expandDisplay_ = true;
1270 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(selectTheme));
1271 auto result = DragDropFuncWrapper::IsExpandDisplay(MockPipelineContext::GetCurrent());
1272 EXPECT_TRUE(result);
1273 }
1274
1275 /**
1276 * @tc.name: DragDropFuncWrapperTestNgCoverage035
1277 * @tc.desc: Test GetPaintRectCenter func
1278 * @tc.type: FUNC
1279 * @tc.author:
1280 */
1281 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage035, TestSize.Level1)
1282 {
1283 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1284 ASSERT_NE(themeManager, nullptr);
1285 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1286 auto selectTheme = AceType::MakeRefPtr<SelectTheme>();
1287 ASSERT_NE(selectTheme, nullptr);
1288 selectTheme->expandDisplay_ = false;
1289 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(selectTheme));
1290 auto result = DragDropFuncWrapper::IsExpandDisplay(MockPipelineContext::GetCurrent());
1291 EXPECT_FALSE(result);
1292 }
1293
1294 /**
1295 * @tc.name: DragDropFuncWrapperTestNgCoverage036
1296 * @tc.desc: Test GetCurrentWindowOffset Func
1297 * @tc.type: FUNC
1298 * @tc.author:
1299 */
1300 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage036, TestSize.Level1)
1301 {
1302 auto context = PipelineBase::GetCurrentContext();
1303 ASSERT_NE(context, nullptr);
1304 auto expectResult = DragDropFuncWrapper::GetCurrentWindowOffset(context);
1305 EXPECT_EQ(OffsetF(), expectResult);
1306 }
1307
1308 /**
1309 * @tc.name: DragDropFuncWrapperTestNgCoverage037
1310 * @tc.desc: Test GetCurrentWindowOffset func
1311 * @tc.type: FUNC
1312 * @tc.author:
1313 */
1314 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage037, TestSize.Level1)
1315 {
1316 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1317 ASSERT_NE(themeManager, nullptr);
1318 auto pipeline = MockPipelineContext::GetCurrent();
1319 ASSERT_NE(pipeline, nullptr);
1320 pipeline->SetThemeManager(themeManager);
1321 auto selectTheme = AceType::MakeRefPtr<SelectTheme>();
1322 ASSERT_NE(pipeline, nullptr);
1323 selectTheme->expandDisplay_ = true;
1324 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(selectTheme));
1325 auto expectResult = DragDropFuncWrapper::GetCurrentWindowOffset(pipeline);
1326 EXPECT_EQ(expectResult, OffsetF());
1327 }
1328
1329 /**
1330 * @tc.name: Test DragDropFuncWrapperTestNgCoverage038
1331 * @tc.desc: Test UpdateNodePositionToWindow func parentNode is nullptr
1332 * @tc.type: FUNC
1333 * @tc.author:
1334 */
1335 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage038, TestSize.Level1)
1336 {
1337 auto frameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonb6e82e361402() 1338 []() { return AceType::MakeRefPtr<Pattern>(); });
1339 auto offset = OffsetF(1.0f, 1.0f);
1340 RefPtr<FrameNode> parentNode = frameNode->GetAncestorNodeOfFrame(true);
1341 EXPECT_EQ(parentNode, nullptr);
1342 frameNode->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1343 ASSERT_NE(frameNode->renderContext_, nullptr);
1344 auto renderContext = frameNode->GetRenderContext();
1345 ASSERT_NE(renderContext, nullptr);
1346 frameNode->renderContext_->UpdatePaintRect(RectT(1.0f, 1.0f, 1.0f, 1.0f));
1347 DragDropFuncWrapper::UpdateNodePositionToWindow(frameNode, offset);
1348 EXPECT_EQ(renderContext->GetPosition(), OffsetT<Dimension>(Dimension(offset.GetX()), Dimension(offset.GetY())));
1349 }
1350
1351 /**
1352 * @tc.name: Test DragDropFuncWrapperTestNgCoverage039
1353 * @tc.desc: Test UpdateNodePositionToWindow func parentNode is not nullptr
1354 * @tc.type: FUNC
1355 * @tc.author:
1356 */
1357 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage039, TestSize.Level1)
1358 {
1359 auto offset = OffsetF(5.0f, 5.0f);
1360 auto frameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonb6e82e361502() 1361 []() { return AceType::MakeRefPtr<Pattern>(); });
1362 ASSERT_NE(frameNode, nullptr);
1363 auto frameNodeCopy = FrameNode::GetOrCreateFrameNode(V2::NAVDESTINATION_TITLE_BAR_ETS_TAG,
__anonb6e82e361602() 1364 ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<Pattern>(); });
1365 ASSERT_NE(frameNodeCopy, nullptr);
1366 frameNode->parent_ = frameNodeCopy;
1367 ASSERT_NE(frameNode->parent_.Upgrade(), nullptr);
1368 frameNode->isWindowBoundary_ = false;
1369 RefPtr<FrameNode> parentNode = frameNode->GetAncestorNodeOfFrame(true);
1370 ASSERT_NE(parentNode, nullptr);
1371 auto renderContext = frameNode->GetRenderContext();
1372 ASSERT_NE(renderContext, nullptr);
1373 frameNode->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1374 ASSERT_NE(frameNode->renderContext_, nullptr);
1375 frameNode->renderContext_->UpdatePaintRect(RectT(3.0f, 2.0f, 3.0f, 4.0f));
1376 DragDropFuncWrapper::UpdateNodePositionToWindow(frameNode, offset);
1377 EXPECT_NE(renderContext->GetPosition(), OffsetT<Dimension>(Dimension(5.0f), Dimension(5.0f)));
1378 }
1379
1380 /**
1381 * @tc.name: Test DragDropFuncWrapperTestNgCoverage040
1382 * @tc.desc: Test HandleBackPressHideMenu
1383 * @tc.type: FUNC
1384 * @tc.author:
1385 */
1386 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage040, TestSize.Level1)
1387 {
1388 auto mainPipeline = PipelineContext::GetMainPipelineContext();
1389 ASSERT_NE(mainPipeline, nullptr);
1390 auto dragDropManager = mainPipeline->GetDragDropManager();
1391 ASSERT_NE(dragDropManager, nullptr);
1392 dragDropManager->SetIsDragNodeNeedClean(false);
1393 auto overlayManager = mainPipeline->GetOverlayManager();
1394 ASSERT_NE(overlayManager, nullptr);
1395 auto gatherNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonb6e82e361702() 1396 []() { return AceType::MakeRefPtr<Pattern>(); });
1397 ASSERT_NE(gatherNode, nullptr);
1398 std::vector<GatherNodeChildInfo> gatherNodeInfo;
1399 overlayManager->MountGatherNodeToRootNode(gatherNode, gatherNodeInfo);
1400 EXPECT_EQ(dragDropManager->IsDragNodeNeedClean(), false);
1401
1402 auto container = MockContainer::Current();
1403 ASSERT_NE(container, nullptr);
1404 container->isUIExtensionWindow_ = false;
1405 DragDropFuncWrapper::HandleBackPressHideMenu();
1406 EXPECT_EQ(dragDropManager->IsDragNodeNeedClean(), true);
1407 EXPECT_EQ(overlayManager->hasGatherNode_, true);
1408
1409 dragDropManager->SetIsDragNodeNeedClean(false);
1410 container->isUIExtensionWindow_ = true;
1411 DragDropFuncWrapper::HandleBackPressHideMenu();
1412 EXPECT_EQ(dragDropManager->IsDragNodeNeedClean(), true);
1413 EXPECT_EQ(overlayManager->hasGatherNode_, false);
1414 }
1415
1416 /**
1417 * @tc.name: DragDropFuncWrapperTestNgCoverage041
1418 * @tc.desc: Test ProcessDragDropData
1419 * @tc.type: FUNC
1420 * @tc.author:
1421 */
1422 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage041, TestSize.Level1)
1423 {
1424 RefPtr<OHOS::Ace::DragEvent> dragEvent = AceType::MakeRefPtr<OHOS::Ace::DragEvent>();
1425 ASSERT_NE(dragEvent, nullptr);
1426 std::string udKey;
1427 DragSummaryInfo dragSummaryInfo;
1428 int32_t ret = -1;
1429 auto mainPipeline = PipelineContext::GetMainPipelineContext();
1430 ASSERT_NE(mainPipeline, nullptr);
1431 auto dragDropManager = mainPipeline->GetDragDropManager();
1432 ASSERT_NE(dragDropManager, nullptr);
1433
1434 EXPECT_EQ(dragEvent->GetData(), nullptr);
1435 EXPECT_EQ(dragEvent->GetDataLoadParams(), nullptr);
1436 auto mockUdmfClient = static_cast<MockUdmfClient*>(UdmfClient::GetInstance());
1437 EXPECT_CALL(*mockUdmfClient, GetSummary(_, _)).WillRepeatedly(Return(0));
1438 DragDropFuncWrapper::ProcessDragDropData(dragEvent, udKey, dragSummaryInfo, ret);
1439 EXPECT_EQ(ret, 0);
1440
1441 auto unifiedData = AceType::MakeRefPtr<MockUnifiedData>();
1442 ASSERT_NE(unifiedData, nullptr);
1443 dragEvent->SetData(unifiedData);
1444 dragEvent->SetUseDataLoadParams(true);
1445 EXPECT_CALL(*unifiedData, GetSize()).WillRepeatedly(testing::Return(0));
1446 ASSERT_NE(dragEvent->GetData(), nullptr);
1447 auto dataLoadParams = AceType::MakeRefPtr<MockDataLoadParams>();
1448 ASSERT_NE(dataLoadParams, nullptr);
1449 EXPECT_CALL(*mockUdmfClient, SetDelayInfo(_, _)).WillRepeatedly(testing::Return(0));
1450 EXPECT_CALL(*mockUdmfClient, SetData(_, _)).WillRepeatedly(testing::Return(0));
1451 dragEvent->SetDataLoadParams(dataLoadParams);
1452 ASSERT_NE(dragEvent->GetDataLoadParams(), nullptr);
1453 DragDropFuncWrapper::ProcessDragDropData(dragEvent, udKey, dragSummaryInfo, ret);
1454 EXPECT_EQ(ret, 0);
1455 EXPECT_EQ(dragEvent->IsUseDataLoadParams(), true);
1456 EXPECT_CALL(*mockUdmfClient, SetDelayInfo(_, _)).WillRepeatedly(testing::Return(1));
1457 DragDropFuncWrapper::ProcessDragDropData(dragEvent, udKey, dragSummaryInfo, ret);
1458 EXPECT_EQ(ret, 0);
1459
1460 dragEvent->SetUseDataLoadParams(false);
1461 DragDropFuncWrapper::ProcessDragDropData(dragEvent, udKey, dragSummaryInfo, ret);
1462 EXPECT_EQ(ret, 0);
1463 EXPECT_EQ(dragEvent->IsUseDataLoadParams(), false);
1464
1465 EXPECT_CALL(*mockUdmfClient, SetDelayInfo(_, _)).WillRepeatedly(testing::Return(1));
1466 EXPECT_CALL(*mockUdmfClient, SetData(_, _)).WillRepeatedly(testing::Return(1));
1467 EXPECT_CALL(*mockUdmfClient, GetSummary(_, _)).WillRepeatedly(Return(1));
1468 DragDropFuncWrapper::ProcessDragDropData(dragEvent, udKey, dragSummaryInfo, ret);
1469 EXPECT_EQ(ret, 1);
1470 }
1471
1472 /**
1473 * @tc.name: Test DragDropFuncWrapperTestNgCoverage042
1474 * @tc.desc: Test EnvelopedDataLoadParams func
1475 * @tc.type: FUNC
1476 * @tc.author:
1477 */
1478 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage042, TestSize.Level1)
1479 {
1480 auto dragAction = std::make_shared<OHOS::Ace::NG::ArkUIInteralDragAction>();
1481 ASSERT_NE(dragAction, nullptr);
1482 std::string udKey;
1483 DragSummaryInfo dragSummaryInfo;
1484 int32_t dataSize = 1;
1485
1486 RefPtr<MockInteractionInterface> mockInteractionInterface = AceType::MakeRefPtr<MockInteractionInterface>();
1487 ASSERT_NE(mockInteractionInterface, nullptr);
1488 EXPECT_CALL(*mockInteractionInterface, GetAppDragSwitchState(_)).WillRepeatedly(testing::Return(1));
1489 RefPtr<MockUnifiedData> unifiedData = AceType::MakeRefPtr<MockUnifiedData>();
1490 ASSERT_NE(unifiedData, nullptr);
1491 dragAction->unifiedData = unifiedData;
1492 dragAction->dataLoadParams = nullptr;
1493 auto mockUdmfClient = static_cast<MockUdmfClient*>(UdmfClient::GetInstance());
1494 EXPECT_CALL(*mockUdmfClient, SetData(_, _)).WillRepeatedly(testing::Return(1));
1495 EXPECT_CALL(*unifiedData, GetSize()).WillRepeatedly(testing::Return(1));
1496 DragDropFuncWrapper::EnvelopedData(dragAction, udKey, dragSummaryInfo, dataSize);
1497 EXPECT_EQ(dataSize, 1);
1498
1499 EXPECT_CALL(*mockUdmfClient, SetData(_, _)).WillRepeatedly(testing::Return(0));
1500 EXPECT_CALL(*unifiedData, GetSize()).WillRepeatedly(testing::Return(5));
1501 EXPECT_CALL(*mockUdmfClient, GetSummary(_, _)).WillRepeatedly(testing::Return(0));
1502 DragDropFuncWrapper::EnvelopedData(dragAction, udKey, dragSummaryInfo, dataSize);
1503 EXPECT_EQ(dataSize, 5);
1504
1505 dragAction->unifiedData = nullptr;
1506 RefPtr<MockDataLoadParams> mockDataLoadParams = AceType::MakeRefPtr<MockDataLoadParams>();
1507 ASSERT_NE(mockDataLoadParams, nullptr);
1508 dragAction->dataLoadParams = mockDataLoadParams;
1509 EXPECT_CALL(*mockUdmfClient, SetDelayInfo(_, _)).WillRepeatedly(testing::Return(1));
1510 DragDropFuncWrapper::EnvelopedData(dragAction, udKey, dragSummaryInfo, dataSize);
1511 EXPECT_EQ(dataSize, 1);
1512
1513 EXPECT_CALL(*mockUdmfClient, SetDelayInfo(_, _)).WillRepeatedly(testing::Return(0));
1514 EXPECT_CALL(*mockDataLoadParams, GetRecordCount()).WillRepeatedly(testing::Return(10));
1515 EXPECT_CALL(*mockUdmfClient, GetSummary(_, _)).WillRepeatedly(testing::Return(1));
1516 DragDropFuncWrapper::EnvelopedData(dragAction, udKey, dragSummaryInfo, dataSize);
1517 EXPECT_EQ(dataSize, 10);
1518
1519 EXPECT_CALL(*mockDataLoadParams, GetRecordCount()).WillRepeatedly(testing::Return(-1));
1520 DragDropFuncWrapper::EnvelopedData(dragAction, udKey, dragSummaryInfo, dataSize);
1521 EXPECT_EQ(dataSize, 1);
1522
1523 EXPECT_CALL(*mockDataLoadParams, GetRecordCount()).WillRepeatedly(testing::Return(0));
1524 DragDropFuncWrapper::EnvelopedData(dragAction, udKey, dragSummaryInfo, dataSize);
1525 EXPECT_EQ(dataSize, 1);
1526
1527 EXPECT_CALL(*mockDataLoadParams, GetRecordCount()).WillRepeatedly(testing::Return(INT32_MAX + 1));
1528 DragDropFuncWrapper::EnvelopedData(dragAction, udKey, dragSummaryInfo, dataSize);
1529 EXPECT_EQ(dataSize, 1);
1530 }
1531
1532 /**
1533 * @tc.name: Test DragDropFuncWrapperTestNgCoverage043
1534 * @tc.desc: Test FindWindowScene func
1535 * @tc.type: FUNC
1536 * @tc.author:
1537 */
1538 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage043, TestSize.Level1)
1539 {
1540 auto rootNode = FrameNode::CreateFrameNode(V2::WINDOW_SCENE_ETS_TAG,
1541 ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
1542 ASSERT_NE(rootNode, nullptr);
1543 auto frameNode1 = FrameNode::CreateFrameNode("framenode", ElementRegister::GetInstance()->MakeUniqueId(),
1544 AceType::MakeRefPtr<Pattern>(), false);
1545 rootNode->AddChild(frameNode1);
1546 ASSERT_NE(frameNode1, nullptr);
1547
1548 auto container = MockContainer::Current();
1549 ASSERT_NE(container, nullptr);
1550 container->isSceneBoardWindow_ = true;
1551
1552 auto windowScene = DragDropFuncWrapper::FindWindowScene(frameNode1);
1553 EXPECT_EQ(windowScene, rootNode);
1554
1555 auto frameNode2 = FrameNode::CreateFrameNode("framenode", ElementRegister::GetInstance()->MakeUniqueId(),
1556 AceType::MakeRefPtr<Pattern>(), false);
1557 frameNode1->AddChild(frameNode2);
1558 ASSERT_NE(frameNode2, nullptr);
1559 windowScene = DragDropFuncWrapper::FindWindowScene(frameNode2);
1560 EXPECT_EQ(windowScene, rootNode);
1561
1562 auto frameNode3 = FrameNode::CreateFrameNode("framenode", ElementRegister::GetInstance()->MakeUniqueId(),
1563 AceType::MakeRefPtr<Pattern>(), false);
1564 ASSERT_NE(frameNode3, nullptr);
1565 windowScene = DragDropFuncWrapper::FindWindowScene(frameNode3);
1566 EXPECT_EQ(windowScene, nullptr);
1567
1568 container->isSceneBoardWindow_ = false;
1569 windowScene = DragDropFuncWrapper::FindWindowScene(frameNode3);
1570 EXPECT_EQ(windowScene, nullptr);
1571 }
1572
1573 /**
1574 * @tc.name: GetFrameNodeOffsetToWindow001
1575 * @tc.desc: Test GetFrameNodeOffsetToWindow with null targetNode
1576 * @tc.type: FUNC
1577 */
1578 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeOffsetToWindow001, TestSize.Level1)
1579 {
1580 RefPtr<FrameNode> targetNode = nullptr;
1581 RefPtr<FrameNode> frameNode = FrameNode::CreateFrameNode(
1582 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1583 ASSERT_NE(frameNode, nullptr);
1584 auto result = DragDropFuncWrapper::GetFrameNodeOffsetToWindow(targetNode, frameNode, OFFSET_WIDTH, OFFSET_HEIGHT);
1585 EXPECT_EQ(result, OffsetF());
1586 }
1587
1588 /**
1589 * @tc.name: GetFrameNodeOffsetToWindow002
1590 * @tc.desc: Test GetFrameNodeOffsetToWindow with null frameNode
1591 * @tc.type: FUNC
1592 */
1593 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeOffsetToWindow002, TestSize.Level1)
1594 {
1595 RefPtr<FrameNode> frameNode = nullptr;
1596 RefPtr<FrameNode> targetNode = FrameNode::CreateFrameNode(
1597 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1598 ASSERT_NE(targetNode, nullptr);
1599 auto result = DragDropFuncWrapper::GetFrameNodeOffsetToWindow(targetNode, frameNode, OFFSET_WIDTH, OFFSET_HEIGHT);
1600 EXPECT_EQ(result, OffsetF());
1601 }
1602
1603 /**
1604 * @tc.name: GetFrameNodeOffsetToWindow003
1605 * @tc.desc: Test GetFrameNodeOffsetToWindow with null renderContext
1606 * @tc.type: FUNC
1607 */
1608 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeOffsetToWindow003, TestSize.Level1)
1609 {
1610 RefPtr<FrameNode> targetNode = FrameNode::CreateFrameNode(
1611 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1612 ASSERT_NE(targetNode, nullptr);
1613 RefPtr<FrameNode> frameNode = FrameNode::CreateFrameNode(
1614 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1615 ASSERT_NE(frameNode, nullptr);
1616 frameNode->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1617 targetNode->renderContext_ = nullptr;
1618 auto result = DragDropFuncWrapper::GetFrameNodeOffsetToWindow(targetNode, frameNode, OFFSET_WIDTH, OFFSET_HEIGHT);
1619 EXPECT_EQ(result, OffsetF());
1620 }
1621
1622 /**
1623 * @tc.name: GetFrameNodeOffsetToWindow004
1624 * @tc.desc: Test GetFrameNodeOffsetToWindow with parentNode exists
1625 * @tc.type: FUNC
1626 */
1627 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeOffsetToWindow004, TestSize.Level1)
1628 {
1629 auto parentNode = FrameNode::CreateFrameNode(
1630 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1631 ASSERT_NE(parentNode, nullptr);
1632 auto targetNode = FrameNode::CreateFrameNode(
1633 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1634 ASSERT_NE(targetNode, nullptr);
1635 auto frameNode = FrameNode::CreateFrameNode(
1636 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1637 ASSERT_NE(frameNode, nullptr);
1638 parentNode->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1639 targetNode->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1640 frameNode->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1641 targetNode->parent_ = parentNode;
1642 auto result = DragDropFuncWrapper::GetFrameNodeOffsetToWindow(targetNode, frameNode, OFFSET_WIDTH, OFFSET_HEIGHT);
1643 EXPECT_NE(result, OffsetF());
1644 }
1645
1646 /**
1647 * @tc.name: GetFrameNodeOffsetToWindow005
1648 * @tc.desc: Test GetFrameNodeOffsetToWindow with parentNode == nullptr
1649 * @tc.type: FUNC
1650 */
1651 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeOffsetToWindow005, TestSize.Level1)
1652 {
1653 auto targetNode = FrameNode::CreateFrameNode(
1654 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1655 ASSERT_NE(targetNode, nullptr);
1656 auto frameNode = FrameNode::CreateFrameNode(
1657 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1658 ASSERT_NE(frameNode, nullptr);
1659 targetNode->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1660 frameNode->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1661 auto result = DragDropFuncWrapper::GetFrameNodeOffsetToWindow(targetNode, frameNode, OFFSET_WIDTH, OFFSET_HEIGHT);
1662 EXPECT_NE(result, OffsetF());
1663 }
1664
1665 /**
1666 * @tc.name: GetFrameNodeByInspectorId001
1667 * @tc.desc: Test GetFrameNodeByInspectorId with empty inspectorId
1668 * @tc.type: FUNC
1669 */
1670 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeByInspectorId001, TestSize.Level1)
1671 {
1672 std::string inspectorId = "";
1673 auto result = DragDropFuncWrapper::GetFrameNodeByInspectorId(inspectorId);
1674 EXPECT_EQ(result, nullptr);
1675 }
1676
1677 /**
1678 * @tc.name: GetFrameNodeByInspectorId002
1679 * @tc.desc: Test GetFrameNodeByInspectorId with inspectorId not found
1680 * @tc.type: FUNC
1681 */
1682 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeByInspectorId002, TestSize.Level1)
1683 {
1684 std::string inspectorId = "not_found_id";
1685 auto context = PipelineContext::GetCurrentContext();
1686 ASSERT_NE(context, nullptr);
1687 auto rootNode = FrameNode::CreateFrameNode(
1688 V2::ROOT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1689 ASSERT_NE(rootNode, nullptr);
1690 context->rootNode_ = rootNode;
1691 auto result = DragDropFuncWrapper::GetFrameNodeByInspectorId(inspectorId);
1692 EXPECT_EQ(result, nullptr);
1693 }
1694
1695 /**
1696 * @tc.name: GetFrameNodeByInspectorId003
1697 * @tc.desc: Test GetFrameNodeByInspectorId with frameNode found but layoutProperty is null
1698 * @tc.type: FUNC
1699 */
1700 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeByInspectorId003, TestSize.Level1)
1701 {
1702 std::string inspectorId = "test_id";
1703 auto rootNode = FrameNode::CreateFrameNode(
1704 V2::ROOT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1705 ASSERT_NE(rootNode, nullptr);
1706 auto frameNode = FrameNode::CreateFrameNode(
1707 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1708 ASSERT_NE(frameNode, nullptr);
1709 frameNode->UpdateInspectorId(inspectorId);
1710 frameNode->layoutProperty_ = nullptr;
1711 rootNode->AddChild(frameNode);
1712
1713 auto context = PipelineContext::GetCurrentContext();
1714 context->rootNode_ = rootNode;
1715
1716 auto result = DragDropFuncWrapper::GetFrameNodeByInspectorId(inspectorId);
1717 EXPECT_EQ(result, nullptr);
1718 }
1719
1720 /**
1721 * @tc.name: GetFrameNodeByInspectorId004
1722 * @tc.desc: Test GetFrameNodeByInspectorId with layoutProperty visibility == INVISIBLE
1723 * @tc.type: FUNC
1724 */
1725 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeByInspectorId004, TestSize.Level1)
1726 {
1727 std::string inspectorId = "test_id";
1728 auto rootNode = FrameNode::CreateFrameNode(
1729 V2::ROOT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1730 ASSERT_NE(rootNode, nullptr);
1731 auto frameNode = FrameNode::CreateFrameNode(
1732 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1733 ASSERT_NE(frameNode, nullptr);
1734 frameNode->UpdateInspectorId(inspectorId);
1735 frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::INVISIBLE);
1736 rootNode->AddChild(frameNode);
1737
1738 auto context = PipelineContext::GetCurrentContext();
1739 context->rootNode_ = rootNode;
1740
1741 auto result = DragDropFuncWrapper::GetFrameNodeByInspectorId(inspectorId);
1742 EXPECT_EQ(result, nullptr);
1743 }
1744
1745 /**
1746 * @tc.name: GetFrameNodeByInspectorId005
1747 * @tc.desc: Test GetFrameNodeByInspectorId with layoutProperty visibility == GONE
1748 * @tc.type: FUNC
1749 */
1750 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeByInspectorId005, TestSize.Level1)
1751 {
1752 std::string inspectorId = "test_id";
1753 auto rootNode = FrameNode::CreateFrameNode(
1754 V2::ROOT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1755 ASSERT_NE(rootNode, nullptr);
1756 auto frameNode = FrameNode::CreateFrameNode(
1757 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1758 ASSERT_NE(frameNode, nullptr);
1759 frameNode->UpdateInspectorId(inspectorId);
1760 frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::GONE);
1761 rootNode->AddChild(frameNode);
1762
1763 auto context = PipelineContext::GetCurrentContext();
1764 context->rootNode_ = rootNode;
1765
1766 auto result = DragDropFuncWrapper::GetFrameNodeByInspectorId(inspectorId);
1767 EXPECT_EQ(result, nullptr);
1768 }
1769
1770 /**
1771 * @tc.name: GetFrameNodeByInspectorId006
1772 * @tc.desc: Test GetFrameNodeByInspectorId with layoutProperty visibility == VISIBLE
1773 * @tc.type: FUNC
1774 */
1775 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetFrameNodeByInspectorId006, TestSize.Level1)
1776 {
1777 std::string inspectorId = "test_id";
1778 auto rootNode = FrameNode::CreateFrameNode(
1779 V2::ROOT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1780 ASSERT_NE(rootNode, nullptr);
1781 auto frameNode = FrameNode::CreateFrameNode(
1782 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1783 ASSERT_NE(frameNode, nullptr);
1784 frameNode->UpdateInspectorId(inspectorId);
1785 frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::VISIBLE);
1786 rootNode->AddChild(frameNode);
1787
1788 auto context = PipelineContext::GetCurrentContext();
1789 context->rootNode_ = rootNode;
1790
1791 auto result = DragDropFuncWrapper::GetFrameNodeByInspectorId(inspectorId);
1792 EXPECT_EQ(result, frameNode);
1793 }
1794
1795 /**
1796 * @tc.name: GetDragFrameNodeBorderRadius001
1797 * @tc.desc: Test GetDragFrameNodeBorderRadius when pixelMap is not null.
1798 * @tc.type: FUNC
1799 */
1800 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetDragFrameNodeBorderRadius001, TestSize.Level1)
1801 {
1802 auto frameNode = FrameNode::CreateFrameNode(
1803 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1804 ASSERT_NE(frameNode, nullptr);
1805 DragDropInfo info;
1806 info.pixelMap = PixelMap::CreatePixelMap(static_cast<void*>(new char[0]));
1807 frameNode->dragPreviewInfo_ = info;
1808
1809 auto radius = DragDropFuncWrapper::GetDragFrameNodeBorderRadius(frameNode);
1810 EXPECT_EQ(radius.radiusTopLeft.value_or(Dimension(TINY_RADIUS)), Dimension(0));
1811 }
1812
1813 /**
1814 * @tc.name: GetDragFrameNodeBorderRadius002
1815 * @tc.desc: Test GetDragFrameNodeBorderRadius when inspectorId is not empty but node cannot be found.
1816 * @tc.type: FUNC
1817 */
1818 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetDragFrameNodeBorderRadius002, TestSize.Level1)
1819 {
1820 auto frameNode = FrameNode::CreateFrameNode(
1821 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1822 ASSERT_NE(frameNode, nullptr);
1823 frameNode->dragPreviewInfo_.inspectorId = "not_exist";
1824
1825 auto radius = DragDropFuncWrapper::GetDragFrameNodeBorderRadius(frameNode);
1826 EXPECT_EQ(radius.radiusTopLeft.value_or(Dimension(TINY_RADIUS)), Dimension(0));
1827 }
1828
1829 /**
1830 * @tc.name: GetDragFrameNodeBorderRadius003
1831 * @tc.desc: Test GetDragFrameNodeBorderRadius when customNode is not null but cannot be cast to FrameNode.
1832 * @tc.type: FUNC
1833 */
1834 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetDragFrameNodeBorderRadius003, TestSize.Level1)
1835 {
1836 auto frameNode = FrameNode::CreateFrameNode(
1837 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1838 ASSERT_NE(frameNode, nullptr);
1839
1840 RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
1841 DragDropInfo info;
1842 info.customNode = customNode;
1843 frameNode->dragPreviewInfo_ = info;
1844
1845 auto radius = DragDropFuncWrapper::GetDragFrameNodeBorderRadius(frameNode);
1846 EXPECT_EQ(radius.radiusTopLeft.value_or(Dimension(TINY_RADIUS)), Dimension(0));
1847 }
1848
1849 /**
1850 * @tc.name: GetDragFrameNodeBorderRadius004
1851 * @tc.desc: Test GetDragFrameNodeBorderRadius when borderRadius is not set, expect default value.
1852 * @tc.type: FUNC
1853 */
1854 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetDragFrameNodeBorderRadius004, TestSize.Level1)
1855 {
1856 auto frameNode = FrameNode::CreateFrameNode(
1857 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1858 ASSERT_NE(frameNode, nullptr);
1859 auto radius = DragDropFuncWrapper::GetDragFrameNodeBorderRadius(frameNode);
1860 EXPECT_EQ(radius.radiusTopLeft.value_or(Dimension(TINY_RADIUS)), Dimension(0));
1861 }
1862
1863 /**
1864 * @tc.name: GetDragFrameNodeBorderRadius005
1865 * @tc.desc: Test GetDragFrameNodeBorderRadius when borderRadius is set, expect the set value to be returned.
1866 * @tc.type: FUNC
1867 */
1868 HWTEST_F(DragDropFuncWrapperTestNgCoverage, GetDragFrameNodeBorderRadius005, TestSize.Level1)
1869 {
1870 auto frameNode = FrameNode::CreateFrameNode(
1871 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
1872 ASSERT_NE(frameNode, nullptr);
1873 auto renderContext = frameNode->GetRenderContext();
1874 ASSERT_NE(renderContext, nullptr);
1875
1876 BorderRadiusProperty radiusInput;
1877 radiusInput.radiusTopLeft = Dimension(MEDIUM_RADIUS);
1878 renderContext->UpdateBorderRadius(radiusInput);
1879
1880 auto radius = DragDropFuncWrapper::GetDragFrameNodeBorderRadius(frameNode);
1881 EXPECT_EQ(radius.radiusTopLeft.value_or(Dimension(0)), Dimension(MEDIUM_RADIUS));
1882 }
1883
1884 /**
1885 * @tc.name: UpdateDragDropInitiatingStatus_NullFrameNode
1886 * @tc.desc: Verify that function early returns when frameNode is null
1887 * @tc.type: FUNC
1888 */
1889 HWTEST_F(DragDropFuncWrapperTestNgCoverage, UpdateDragDropInitiatingStatus001, TestSize.Level1)
1890 {
1891 DragDropGlobalController::GetInstance().UpdateDragDropInitiatingStatus(nullptr, DragDropInitiatingStatus::MOVING);
1892 EXPECT_EQ(DragDropGlobalController::GetInstance().currentDragNode_, nullptr);
1893 }
1894
1895 /**
1896 * @tc.name: UpdateDragDropInitiatingStatus_NonMovingStatus
1897 * @tc.desc: Verify that status other than MOVING does not update currentDragNode_
1898 * @tc.type: FUNC
1899 */
1900 HWTEST_F(DragDropFuncWrapperTestNgCoverage, UpdateDragDropInitiatingStatus002, TestSize.Level1)
1901 {
1902 auto frameNode = FrameNode::CreateFrameNode(V2::ROW_ETS_TAG, 1, AceType::MakeRefPtr<Pattern>());
1903 ASSERT_NE(frameNode, nullptr);
1904 DragDropGlobalController::GetInstance().UpdateDragDropInitiatingStatus(frameNode, DragDropInitiatingStatus::IDLE);
1905 EXPECT_EQ(DragDropGlobalController::GetInstance().currentDragNode_, nullptr);
1906 }
1907
1908 /**
1909 * @tc.name: UpdateDragDropInitiatingStatus_MovingStatus
1910 * @tc.desc: Verify that MOVING status updates currentDragNode_
1911 * @tc.type: FUNC
1912 */
1913 HWTEST_F(DragDropFuncWrapperTestNgCoverage, UpdateDragDropInitiatingStatus003, TestSize.Level1)
1914 {
1915 auto frameNode = FrameNode::CreateFrameNode(V2::ROW_ETS_TAG, 1, AceType::MakeRefPtr<Pattern>());
1916 ASSERT_NE(frameNode, nullptr);
1917 DragDropGlobalController::GetInstance().UpdateDragDropInitiatingStatus(frameNode, DragDropInitiatingStatus::MOVING);
1918 EXPECT_EQ(DragDropGlobalController::GetInstance().currentDragNode_, frameNode);
1919 }
1920 } // namespace OHOS::Ace::NG
1921