1 /*
2 * Copyright (c) 2024 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
20 #include "test/mock/base/mock_drag_window.h"
21 #include "test/mock/core/common/mock_container.h"
22 #include "test/mock/core/common/mock_interaction_interface.h"
23 #include "test/mock/core/pipeline/mock_pipeline_context.h"
24
25 #include "base/image/pixel_map.h"
26 #include "base/memory/ace_type.h"
27 #include "base/memory/referenced.h"
28 #include "base/subwindow/subwindow_manager.h"
29 #include "core/common/interaction/interaction_interface.h"
30 #include "core/components/common/layout/grid_system_manager.h"
31 #include "core/components/theme/blur_style_theme.h"
32 #include "core/components_ng/base/frame_node.h"
33 #include "core/components_ng/base/geometry_node.h"
34 #include "core/components_ng/base/ui_node.h"
35 #include "core/components_ng/event/event_hub.h"
36 #include "core/components_ng/manager/drag_drop/drag_drop_func_wrapper.h"
37 #include "core/components_ng/manager/drag_drop/drag_drop_manager.h"
38 #include "core/components_ng/manager/drag_drop/drag_drop_proxy.h"
39
40 using namespace testing;
41 using namespace testing::ext;
42 namespace OHOS::Ace::NG {
43 namespace {
44 RefPtr<DragWindow> MOCK_DRAG_WINDOW;
45 } // namespace
46
47 class DragDropFuncWrapperTestNgCoverage : public testing::Test {
48 public:
49 static void SetUpTestCase();
50 static void TearDownTestCase();
51 };
52
SetUpTestCase()53 void DragDropFuncWrapperTestNgCoverage::SetUpTestCase()
54 {
55 MockPipelineContext::SetUp();
56 MockContainer::SetUp();
57 MOCK_DRAG_WINDOW = DragWindow::CreateDragWindow("", 0, 0, 0, 0);
58 }
59
TearDownTestCase()60 void DragDropFuncWrapperTestNgCoverage::TearDownTestCase()
61 {
62 MockPipelineContext::TearDown();
63 MockContainer::TearDown();
64 MOCK_DRAG_WINDOW = nullptr;
65 }
66
67 /**
68 * @tc.name: DragDropFuncWrapperTestNgCoverage001
69 * @tc.desc: Test DecideWhetherToStopDragging with valid parameters
70 * @tc.type: FUNC
71 * @tc.author:
72 */
73 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage001, TestSize.Level1)
74 {
75 PointerEvent pointerEvent;
76 std::string extraParams = "test";
77 int32_t currentPointerId = 1;
78 int32_t containerId = 100;
79
80 auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
81 ASSERT_NE(pipelineContext, nullptr);
82 auto manager = pipelineContext->GetDragDropManager();
83 ASSERT_NE(manager, nullptr);
84 manager->SetDraggingPressedState(false);
85
86 DragDropFuncWrapper::DecideWhetherToStopDragging(pointerEvent, extraParams, currentPointerId, containerId);
87
88 EXPECT_FALSE(manager->IsDraggingPressed(currentPointerId));
89 }
90
91 /**
92 * @tc.name: DragDropFuncWrapperTestNgCoverage002
93 * @tc.desc: Test DecideWhetherToStopDragging with invalid containerId
94 * @tc.type: FUNC
95 * @tc.author:
96 */
97 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage002, TestSize.Level1)
98 {
99 PointerEvent pointerEvent;
100 std::string extraParams = "test";
101 int32_t currentPointerId = 1;
102 int32_t invalidContainerId = -1;
103
104 DragDropFuncWrapper::DecideWhetherToStopDragging(pointerEvent, extraParams, currentPointerId, invalidContainerId);
105
106 // No assertion needed as it should safely exit with CHECK_NULL_VOID
107 }
108
109 /**
110 * @tc.name: DragDropFuncWrapperTestNgCoverage003
111 * @tc.desc: Test UpdateDragPreviewOptionsFromModifier with various opacity values
112 * @tc.type: FUNC
113 * @tc.author:
114 */
115 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage003, TestSize.Level1)
116 {
__anon4daed6f40202(WeakPtr<FrameNode> frameNode) 117 auto applyOnNodeSync = [](WeakPtr<FrameNode> frameNode) {
118 auto node = frameNode.Upgrade();
119 CHECK_NULL_VOID(node);
120 node->GetRenderContext()->UpdateOpacity(0.5f);
121 };
122
123 DragPreviewOption option;
124 DragDropFuncWrapper::UpdateDragPreviewOptionsFromModifier(applyOnNodeSync, option);
125
126 EXPECT_EQ(option.options.opacity, 0.5f);
127 }
128
129 /**
130 * @tc.name: DragDropFuncWrapperTestNgCoverage004
131 * @tc.desc: Test UpdateDragPreviewOptionsFromModifier with default opacity
132 * @tc.type: FUNC
133 * @tc.author:
134 */
135 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage004, TestSize.Level1)
136 {
__anon4daed6f40302(WeakPtr<FrameNode> frameNode) 137 auto applyOnNodeSync = [](WeakPtr<FrameNode> frameNode) {
138 auto node = frameNode.Upgrade();
139 CHECK_NULL_VOID(node);
140 node->GetRenderContext()->UpdateOpacity(10.0f); // Invalid value
141 };
142
143 DragPreviewOption option;
144 DragDropFuncWrapper::UpdateDragPreviewOptionsFromModifier(applyOnNodeSync, option);
145
146 EXPECT_EQ(option.options.opacity, 0.95f); // Default opacity
147 }
148
149 /**
150 * @tc.name: DragDropFuncWrapperTestNgCoverage005
151 * @tc.desc: Test UpdatePreviewOptionDefaultAttr without default shadow and radius
152 * @tc.type: FUNC
153 * @tc.author:
154 */
155 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage005, TestSize.Level1)
156 {
157 DragPreviewOption option;
158 option.isDefaultShadowEnabled = false;
159 option.isDefaultRadiusEnabled = false;
160
161 DragDropFuncWrapper::UpdatePreviewOptionDefaultAttr(option);
162
163 EXPECT_EQ(option.options.opacity, 0.95f);
164 EXPECT_FALSE(option.options.shadow.has_value());
165 EXPECT_FALSE(option.options.borderRadius.has_value());
166 }
167
168 /**
169 * @tc.name: DragDropFuncWrapperTestNgCoverage006
170 * @tc.desc: Test PrepareRadiusParametersForDragData with empty radius
171 * @tc.type: FUNC
172 * @tc.author:
173 */
174 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage006, TestSize.Level1)
175 {
176 DragPreviewOption option;
177 option.options.borderRadius = std::nullopt;
178
179 auto arkExtraInfoJson = std::make_unique<JsonValue>();
180 DragDropFuncWrapper::PrepareRadiusParametersForDragData(arkExtraInfoJson, option);
181
182 // No assertion needed as it should safely exit with CHECK_NULL_VOID
183 }
184
185 /**
186 * @tc.name: DragDropFuncWrapperTestNgCoverage007
187 * @tc.desc: Test PrepareShadowParametersForDragData with empty shadow
188 * @tc.type: FUNC
189 * @tc.author:
190 */
191 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage007, TestSize.Level1)
192 {
193 DragPreviewOption option;
194 option.options.shadow = std::nullopt;
195
196 auto arkExtraInfoJson = std::make_unique<JsonValue>();
197 DragDropFuncWrapper::PrepareShadowParametersForDragData(arkExtraInfoJson, option);
198
199 EXPECT_FALSE(arkExtraInfoJson->GetBool("shadow_enable"));
200 }
201
202 /**
203 * @tc.name: DragDropFuncWrapperTestNgCoverage008
204 * @tc.desc: Test GetDefaultShadow with invalid pipeline context
205 * @tc.type: FUNC
206 * @tc.author:
207 */
208 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage008, TestSize.Level1)
209 {
210 auto shadow = DragDropFuncWrapper::GetDefaultShadow();
211 EXPECT_FALSE(shadow.has_value());
212 }
213
214 /**
215 * @tc.name: DragDropFuncWrapperTestNgCoverage009
216 * @tc.desc: Test RadiusToSigma with valid radius
217 * @tc.type: FUNC
218 * @tc.author:
219 */
220 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage009, TestSize.Level1)
221 {
222 float radius = 5.0f;
223 float sigma = DragDropFuncWrapper::RadiusToSigma(radius);
224 EXPECT_GT(sigma, 0.0f);
225 }
226
227 /**
228 * @tc.name: DragDropFuncWrapperTestNgCoverage010
229 * @tc.desc: Test RadiusToSigma with zero radius
230 * @tc.type: FUNC
231 * @tc.author:
232 */
233 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage010, TestSize.Level1)
234 {
235 float radius = 0.0f;
236 float sigma = DragDropFuncWrapper::RadiusToSigma(radius);
237 EXPECT_EQ(sigma, 0.0f);
238 }
239
240 /**
241 * @tc.name: DragDropFuncWrapperTestNgCoverage011
242 * @tc.desc: Test BrulStyleToEffection with invalid pipeline context
243 * @tc.type: FUNC
244 * @tc.author:
245 */
246 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage011, TestSize.Level1)
247 {
248 BlurStyleOption blurStyleOp;
249 blurStyleOp.blurStyle = BlurStyle::BACKGROUND_THICK;
250 blurStyleOp.scale = 0.5;
251 blurStyleOp.colorMode = ThemeColorMode::LIGHT;
252
253 auto effection = DragDropFuncWrapper::BrulStyleToEffection(blurStyleOp);
254 EXPECT_FALSE(effection.has_value());
255 }
256
257 /**
258 * @tc.name: DragDropFuncWrapperTestNgCoverage012
259 * @tc.desc: Test BrulStyleToEffection with invalid blurStyleOp
260 * @tc.type: FUNC
261 * @tc.author:
262 */
263 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage012, TestSize.Level1)
264 {
265 std::optional<BlurStyleOption> blurStyleOp = std::nullopt;
266
267 auto effection = DragDropFuncWrapper::BrulStyleToEffection(blurStyleOp);
268 EXPECT_FALSE(effection.has_value());
269 }
270
271 /**
272 * @tc.name: DragDropFuncWrapperTestNgCoverage013
273 * @tc.desc: Test UpdatePreviewOptionDefaultAttr with default shadow and radius
274 * @tc.type: FUNC
275 * @tc.author:
276 */
277 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage013, TestSize.Level1)
278 {
279 DragPreviewOption option;
280 option.isDefaultShadowEnabled = true;
281 option.isDefaultRadiusEnabled = true;
282
283 DragDropFuncWrapper::UpdatePreviewOptionDefaultAttr(option);
284
285 EXPECT_EQ(option.options.opacity, 0.95f);
286 EXPECT_EQ(option.options.shadow, DragDropFuncWrapper::GetDefaultShadow());
287 EXPECT_EQ(option.options.borderRadius, DragDropFuncWrapper::GetDefaultBorderRadius());
288 }
289
290 /**
291 * @tc.name: DragDropFuncWrapperTestNgCoverage014
292 * @tc.desc: Test UpdateExtraInfo with blur background effect
293 * @tc.type: FUNC
294 * @tc.author:
295 */
296 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage014, TestSize.Level1)
297 {
298 DragPreviewOption option;
299 option.options.opacity = 0.8f;
300 option.options.blurbgEffect.backGroundEffect = EffectOption();
301
302 auto arkExtraInfoJson = std::make_unique<JsonValue>();
303 DragDropFuncWrapper::UpdateExtraInfo(arkExtraInfoJson, option);
304
305 EXPECT_EQ(arkExtraInfoJson->GetDouble("dip_opacity"), 0);
306 }
307
308 /**
309 * @tc.name: DragDropFuncWrapperTestNgCoverage015
310 * @tc.desc: Test PrepareRadiusParametersForDragData with valid radius
311 * @tc.type: FUNC
312 * @tc.author:
313 */
314 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage015, TestSize.Level1)
315 {
316 DragPreviewOption option;
317 option.options.borderRadius->radiusTopLeft = 12.0_vp;
318 option.options.borderRadius->radiusTopRight = 12.0_vp;
319 option.options.borderRadius->radiusBottomRight = 12.0_vp;
320 option.options.borderRadius->radiusBottomLeft = 12.0_vp;
321
322 auto arkExtraInfoJson = std::make_unique<JsonValue>();
323 DragDropFuncWrapper::PrepareRadiusParametersForDragData(arkExtraInfoJson, option);
324
325 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_corner_radius1"), 0);
326 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_corner_radius2"), 0);
327 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_corner_radius3"), 0);
328 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_corner_radius4"), 0);
329 }
330
331 /**
332 * @tc.name: DragDropFuncWrapperTestNgCoverage016
333 * @tc.desc: Test PrepareShadowParametersForDragData with valid shadow
334 * @tc.type: FUNC
335 * @tc.author:
336 */
337 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage016, TestSize.Level1)
338 {
339 DragPreviewOption option;
340 Shadow shadow;
341 shadow.SetIsFilled(true);
342 option.options.shadow = shadow;
343
344 auto arkExtraInfoJson = std::make_unique<JsonValue>();
345 DragDropFuncWrapper::PrepareShadowParametersForDragData(arkExtraInfoJson, option);
346
347 EXPECT_FALSE(arkExtraInfoJson->GetBool("shadow_enable"));
348 }
349
350 /**
351 * @tc.name: DragDropFuncWrapperTestNgCoverage017
352 * @tc.desc: Test ParseShadowInfo with valid shadow
353 * @tc.type: FUNC
354 * @tc.author:
355 */
356 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage017, TestSize.Level1)
357 {
358 Shadow shadow;
359 shadow.SetIsFilled(true);
360 shadow.SetOffset(Offset(5, 5));
361 shadow.SetBlurRadius(10.0);
362 shadow.SetColor(Color::FromARGB(255, 255, 0, 0));
363
364 auto arkExtraInfoJson = std::make_unique<JsonValue>();
365 DragDropFuncWrapper::ParseShadowInfo(shadow, arkExtraInfoJson);
366
367 EXPECT_FALSE(arkExtraInfoJson->GetBool("shadow_is_filled"));
368 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_shadow_OffsetX"), 0);
369 EXPECT_EQ(arkExtraInfoJson->GetDouble("drag_shadow_OffsetY"), 0);
370 }
371
372 /**
373 * @tc.name: DragDropFuncWrapperTestNgCoverage018
374 * @tc.desc: Test GetDefaultShadow with valid pipeline context
375 * @tc.type: FUNC
376 * @tc.author:
377 */
378 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage018, TestSize.Level1)
379 {
380 auto shadow = DragDropFuncWrapper::GetDefaultShadow();
381 EXPECT_FALSE(shadow.has_value());
382 }
383
384 /**
385 * @tc.name: DragDropFuncWrapperTestNgCoverage019
386 * @tc.desc: Test BrulStyleToEffection with valid BlurStyleOption
387 * @tc.type: FUNC
388 * @tc.author:
389 */
390 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage019, TestSize.Level1)
391 {
392 BlurStyleOption blurStyleOp;
393 blurStyleOp.blurStyle = BlurStyle::BACKGROUND_THICK;
394 blurStyleOp.scale = 0.5;
395 blurStyleOp.colorMode = ThemeColorMode::LIGHT;
396
397 auto effection = DragDropFuncWrapper::BrulStyleToEffection(blurStyleOp);
398 EXPECT_FALSE(effection.has_value());
399 }
400
401 /**
402 * @tc.name: DragDropFuncWrapperTestNgCoverage020
403 * @tc.desc: Test DecideWhetherToStopDragging
404 * @tc.type: FUNC
405 * @tc.author:
406 */
407 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage020, TestSize.Level1)
408 {
409 int32_t instanceId = -1;
410 int32_t globalX = -1;
411 int32_t globalY = -1;
412 std::string extraParams;
413 int32_t pointerId = -1;
414
415 ContainerScope scope(instanceId);
416 auto container = Container::CurrentSafely();
417 CHECK_NULL_VOID(container);
418 auto pipelineContext = container->GetPipelineContext();
419 CHECK_NULL_VOID(pipelineContext);
420 auto taskExecutor = container->GetTaskExecutor();
421 CHECK_NULL_VOID(taskExecutor);
422
423 taskExecutor->PostTask(
__anon4daed6f40402() 424 [instanceId, globalX, globalY, extraParams, pointerId, context = pipelineContext]() {
425 context->OnDragEvent({globalX, globalY }, DragEventAction::DRAG_EVENT_START_FOR_CONTROLLER);
426 NG::DragDropFuncWrapper::DecideWhetherToStopDragging(
427 { globalX, globalY }, extraParams, pointerId, instanceId);
428 },
429 TaskExecutor::TaskType::UI, "ArkUIDragHandleDragEventStart");
430 EXPECT_EQ(instanceId, -1);
431 }
432
433 /**
434 * @tc.name: DragDropFuncWrapperTestNgCoverage021
435 * @tc.desc: Test UpdateDragPreviewOptionsFromModifier with shadow has value
436 * @tc.type: FUNC
437 * @tc.author:
438 */
439 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage021, TestSize.Level1)
440 {
441 /**
442 * @tc.steps: step1. construct a lambda function, set drag preview opacity is 0.3f
443 */
444 std::optional<Shadow> shadowVal;
__anon4daed6f40502(WeakPtr<NG::FrameNode> node) 445 auto applyOnNodeSync = [shadowVal](WeakPtr<NG::FrameNode> node) {
446 auto frameNode = node.Upgrade();
447 Dimension dimen(2.0);
448 BlurBackGroundInfo bgBackEffect = {{dimen, 1.0f, 1.0f, Color::TRANSPARENT,
449 AdaptiveColor::DEFAULT, {{2.0f, 2.0f}}}};
450 std::optional<BorderRadiusProperty> borderRadiusVal;
451 OptionsAfterApplied optionTmp = {0, shadowVal, "test", borderRadiusVal, {bgBackEffect}};
452 DragPreviewOption dragPreviewInfos;
453 dragPreviewInfos.options = optionTmp;
454 frameNode->SetDragPreviewOptions(dragPreviewInfos);
455 };
456
457 /**
458 * @tc.steps: step2. construct a DragPreviewOption object
459 */
460 NG::DragPreviewOption option;
461
462 /**
463 * @tc.steps: step3. call UpdateDragPreviewOptionsFromModifier
464 * @tc.expected: step3. option.options.shadow is equal to shadowVal.
465 */
466 NG::DragDropFuncWrapper::UpdateDragPreviewOptionsFromModifier(applyOnNodeSync, option);
467 EXPECT_EQ(1, 1);
468 }
469
470
471 /**
472 * @tc.name: DragDropFuncWrapperTestNgCoverage022
473 * @tc.desc: Test PrepareShadowParametersForDragData with Invalid shadow
474 * @tc.type: FUNC
475 * @tc.author:
476 */
477 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage022, TestSize.Level1)
478 {
479 DragPreviewOption option;
480 Shadow shadow;
481 shadow.SetIsFilled(true);
482 shadow.SetOffset(Offset(5, 5));
483 shadow.SetBlurRadius(10.0);
484 shadow.SetColor(Color::FromARGB(255, 255, 0, 0));
485 option.options.shadow = shadow;
486
487 auto arkExtraInfoJson = std::make_unique<JsonValue>();
488 DragDropFuncWrapper::PrepareShadowParametersForDragData(arkExtraInfoJson, option);
489
490 EXPECT_TRUE(arkExtraInfoJson->GetValue("shadow_enable"));
491 }
492
493
494 /**
495 * @tc.name: DragDropFuncWrapperTestNgCoverage023
496 * @tc.desc: Test PrepareShadowParametersForDragData with empty shadow
497 * @tc.type: FUNC
498 * @tc.author:
499 */
500 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage023, TestSize.Level1)
501 {
502 /**
503 * @tc.steps: step1. Create frameNode.
504 */
505 auto frameNode = FrameNode::CreateFrameNode(
506 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
507 /**
508 * @tc.steps: step2. Test GetDefaultBorderRadius
509 */
510 NG::DragPreviewOption dragPreviewOptions { false, false, false, false, true };
511 dragPreviewOptions.options.borderRadius = DragDropFuncWrapper::GetDefaultBorderRadius();
512 frameNode->SetDragPreviewOptions(dragPreviewOptions);
513 auto dragPreviewOption = frameNode->GetDragPreviewOption();
514 auto borderRadius = dragPreviewOption.options.borderRadius;
515 EXPECT_EQ(borderRadius.value().radiusTopLeft.value().Value(), 12.0);
516 EXPECT_EQ(borderRadius.value().radiusTopRight.value().Value(), 12.0);
517 EXPECT_EQ(borderRadius.value().radiusBottomRight.value().Value(), 12.0);
518 EXPECT_EQ(borderRadius.value().radiusBottomLeft.value().Value(), 12.0);
519 /**
520 * @tc.steps: step3. Test PrepareRadiusParametersForDragData
521 */
522 auto arkExtraInfoJson = JsonUtil::Create(true);
523 DragDropFuncWrapper::PrepareRadiusParametersForDragData(arkExtraInfoJson, dragPreviewOption);
524 auto radiusTopLeft = arkExtraInfoJson->GetDouble("drag_corner_radius1", -1);
525 auto radiusTopRight = arkExtraInfoJson->GetDouble("drag_corner_radius2", -1);
526 auto radiusBottomRight = arkExtraInfoJson->GetDouble("drag_corner_radius3", -1);
527 auto radiusBottomLeft = arkExtraInfoJson->GetDouble("drag_corner_radius4", -1);
528 EXPECT_EQ(radiusTopLeft, 12.0);
529 EXPECT_EQ(radiusTopRight, 12.0);
530 EXPECT_EQ(radiusBottomRight, 12.0);
531 EXPECT_EQ(radiusBottomLeft, 12.0);
532 }
533
534 /**
535 * @tc.name: DragDropFuncWrapperTestNgCoverage024
536 * @tc.desc: Test PrepareRadiusParametersForDragData with valid radius
537 * @tc.type: FUNC
538 * @tc.author:
539 */
540 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage024, TestSize.Level1)
541 {
542 /**
543 * @tc.steps: step1. Create frameNode.
544 */
545 auto frameNode = FrameNode::CreateFrameNode(
546 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
547 /**
548 * @tc.steps: step2. Test GetDefaultBorderRadius
549 */
550 NG::DragPreviewOption dragPreviewOptions { false, false, false, false, true };
551 dragPreviewOptions.options.borderRadius = DragDropFuncWrapper::GetDefaultBorderRadius();
552 frameNode->SetDragPreviewOptions(dragPreviewOptions);
553 auto dragPreviewOption = frameNode->GetDragPreviewOption();
554 dragPreviewOption.options.borderRadius->radiusTopLeft = std::nullopt;
555 dragPreviewOption.options.borderRadius->radiusTopRight = std::nullopt;
556 dragPreviewOption.options.borderRadius->radiusBottomRight = std::nullopt;
557 dragPreviewOption.options.borderRadius->radiusBottomLeft = std::nullopt;
558 /**
559 * @tc.steps: step3. Test PrepareRadiusParametersForDragData
560 */
561 auto arkExtraInfoJson = JsonUtil::Create(true);
562 DragDropFuncWrapper::PrepareRadiusParametersForDragData(arkExtraInfoJson, dragPreviewOption);
563 auto radiusTopLeft = arkExtraInfoJson->GetDouble("drag_corner_radius1", -1);
564 auto radiusTopRight = arkExtraInfoJson->GetDouble("drag_corner_radius2", -1);
565 auto radiusBottomRight = arkExtraInfoJson->GetDouble("drag_corner_radius3", -1);
566 auto radiusBottomLeft = arkExtraInfoJson->GetDouble("drag_corner_radius4", -1);
567 EXPECT_EQ(radiusTopLeft, -1);
568 EXPECT_EQ(radiusTopRight, -1);
569 EXPECT_EQ(radiusBottomRight, -1);
570 EXPECT_EQ(radiusBottomLeft, -1);
571 }
572
573 /**
574 * @tc.name: DragDropFuncWrapperTestNgCoverage026
575 * @tc.desc: Test UpdateExtraInfo with invalid radius
576 * @tc.type: FUNC
577 * @tc.author:
578 */
579 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage026, TestSize.Level1)
580 {
581 DragPreviewOption option;
582 option.options.opacity = 0.8f;
583 option.options.blurbgEffect.backGroundEffect = EffectOption();
584 option.options.blurbgEffect.backGroundEffect.radius.SetValue(1.0F);
585
586 auto arkExtraInfoJson = std::make_unique<JsonValue>();
587 DragDropFuncWrapper::UpdateExtraInfo(arkExtraInfoJson, option);
588
589 EXPECT_EQ(arkExtraInfoJson->GetDouble("dip_opacity"), 0);
590 }
591 /**
592 * @tc.name: DragDropFuncWrapperTestNgCoverage027
593 * @tc.desc: Test UpdateDragPreviewOptionsFromModifier with BackgroundEffect values
594 * @tc.type: FUNC
595 * @tc.author:
596 */
597 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage027, TestSize.Level1)
598 {
__anon4daed6f40602(WeakPtr<FrameNode> frameNode) 599 auto applyOnNodeSync = [](WeakPtr<FrameNode> frameNode) {
600 auto node = frameNode.Upgrade();
601 CHECK_NULL_VOID(node);
602 CalcDimension radius;
603 radius.SetValue(80.0f);
604 Color color = Color::FromARGB(13, 255, 255, 255);
605 EffectOption effoption = { radius, 1.0, 1.08, color };
606 node->GetRenderContext()->UpdateBackgroundEffect(effoption);
607 };
608
609 DragPreviewOption option;
610 DragDropFuncWrapper::UpdateDragPreviewOptionsFromModifier(applyOnNodeSync, option);
611
612 EXPECT_FALSE(option.options.blurbgEffect.backGroundEffect.radius.IsValid());
613 }
614
615 /**
616 * @tc.name: DragDropFuncWrapperTestNgCoverage028
617 * @tc.desc: Test UpdateDragPreviewOptionsFromModifier with BackShadow ,BorderRadius,without,bgEffect,with
618 * BackBlurStyle ;
619 * @tc.type: FUNC
620 * @tc.author:
621 */
622 HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage028, TestSize.Level1)
623 {
__anon4daed6f40702(WeakPtr<FrameNode> frameNode) 624 auto applyOnNodeSync = [](WeakPtr<FrameNode> frameNode) {
625 auto node = frameNode.Upgrade();
626 CHECK_NULL_VOID(node);
627 Shadow shadow;
628 shadow.SetIsFilled(true);
629 shadow.SetOffset(Offset(5, 5));
630 shadow.SetBlurRadius(10.0);
631 shadow.SetColor(Color::FromARGB(255, 255, 0, 0));
632 BlurStyleOption styleOption;
633 styleOption.blurStyle = BlurStyle::COMPONENT_THICK;
634 styleOption.scale = 0.5;
635 styleOption.colorMode = ThemeColorMode::LIGHT;
636 BorderRadiusProperty borderRadius;
637 borderRadius.SetRadius(Dimension(50.0));
638 node->GetRenderContext()->UpdateBorderRadius(borderRadius);
639 node->GetRenderContext()->UpdateBackShadow(shadow);
640 node->GetRenderContext()->UpdateBackBlurStyle(styleOption);
641 node->GetRenderContext()->UpdateBackgroundEffect(std::nullopt);
642
643
644 };
645
646 DragPreviewOption option;
647 DragDropFuncWrapper::UpdateDragPreviewOptionsFromModifier(applyOnNodeSync, option);
648
649 EXPECT_TRUE(option.options.shadow.has_value());
650 EXPECT_TRUE(option.options.borderRadius.has_value());
651 EXPECT_FALSE(option.options.blurbgEffect.backGroundEffect.radius.IsValid());
652 }
653 } // namespace OHOS::Ace::NG
654