1 /*
2 * Copyright (c) 2021-2022 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 "gtest/gtest.h"
17
18 #include "frameworks/bridge/common/utils/utils.h"
19 #include "frameworks/bridge/js_frontend/engine/quickjs/animation_bridge.h"
20 #include "frameworks/core/animation/curve.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24 namespace OHOS::Ace::Framework {
25
26 namespace {
27
28 const int32_t ANIMATION_ITERATIONS_DEFAULT = 1;
29 const double ANIMATION_DURATIONS_DEFAULT = 3000;
30 const double ANIMATION_DELAY_DEFAULT = 1000;
31 const std::string TRANSFORM_ORIGIN_DEFAULT_FROM = "left top";
32 const std::string TRANSFORM_ORIGIN_DEFAULT_TO = "right center";
33 const std::string TRANSFORM_SCALE_DEFAULT_FROM = "1";
34 const std::string TRANSFORM_TRANSLATE_DEFAULT_FROM = "50";
35 const std::string TRANSFORM_ROTATE_DEFAULT_FROM = "0";
36 const std::string TRANSFORM_SCALE_DEFAULT_TO = "3";
37 const std::string TRANSFORM_TRANSLATE_DEFAULT_TO = "100";
38 const std::string TRANSFORM_ROTATE_DEFAULT_TO = "360";
39 const std::string ANIMATION_HEIGHT_DEFAULT = "150";
40 const std::string ANIMATION_OFFSET_FROM = "0.0";
41 const std::string ANIMATION_OFFSET_MIDDLE = "50.0";
42 const std::string ANIMATION_OFFSET_TO = "100.0";
43 const std::string ANIMATION_WIDTH_DEFAULT = "200";
44 const std::string ANIMATION_OPACITY_DEFAULT = "1";
45 const std::string ANIMATION_COLOR_DEFAULT = "#ff0000";
46 const std::string ANIMATION_EASING_DEFAULT = "linear";
47 const std::string ANIMATION_FILL_DEFAULT = "forwards";
48 const std::string ANIMATION_EASING_ANTICIPATE = "anticipate";
49 const std::string ANIMATION_EASING_CUBIC = "cubic-bezier(0.0, 0.0, 0.0, 1.0)";
50
51 const std::string TRANSFORM_ORIGIN_TEST = ""
52 "[ "
53 " [ "
54 " { "
55 " \"transformOrigin\": \"left top\" "
56 " }, "
57 " { "
58 " \"transformOrigin\": \"right center\" "
59 " } "
60 " ] "
61 "]";
62
63 const std::string TRANSFORM_TEST = ""
64 "[ "
65 " [ "
66 " { "
67 " \"transform\": { "
68 " \"translate\": \"50\", "
69 " \"rotate\": \"0\" , "
70 " \"scale\": \"1\" "
71 " } "
72 " }, "
73 " { "
74 " \"transform\": { "
75 " \"translate\": \"100\", "
76 " \"rotate\": \"360\" , "
77 " \"scale\" : \"3\" "
78 " } "
79 " } "
80 " ] "
81 "]";
82
83 const std::string HEIGHT_WIDTH_TEST = ""
84 "[ "
85 " [ "
86 " { "
87 " \"height\": \"150\", "
88 " \"width\": \"200\" "
89 " }, "
90 " { "
91 " \"height\": \"150\", "
92 " \"width\": \"200\" "
93 " } "
94 " ] "
95 "]";
96
97 const std::string OPACITY_COLOR_TEST = ""
98 "[ "
99 " [ "
100 " { "
101 " \"opacity\": \"1\", "
102 " \"backgroundColor\": \"#ff0000\" "
103 " }, "
104 " { "
105 " \"opacity\": \"1\", "
106 " \"backgroundColor\": \"#ff0000\" "
107 " } "
108 " ] "
109 "]";
110
111 const std::string OPTIONS_TEST = ""
112 "[ "
113 " [ "
114 " { "
115 " }, "
116 " { "
117 " } "
118 " ], "
119 " { "
120 " \"duration\": 3000, "
121 " \"easing\": \"linear\", "
122 " \"delay\": 1000, "
123 " \"fill\": \"forwards\", "
124 " \"iterations\": 1, "
125 " \"direction\": \"alternate\" "
126 " } "
127 "]";
128
129 const std::string ANTICIPATE_CURVE_TEST = ""
130 "[ "
131 " [ "
132 " { "
133 " }, "
134 " { "
135 " } "
136 " ], "
137 " { "
138 " \"duration\": 3000, "
139 " \"easing\": \"anticipate\","
140 " \"delay\": 1000, "
141 " \"fill\": \"forwards\", "
142 " \"iterations\": 1 "
143 " } "
144 "]";
145
146 const std::string CUBIC_CURVE_TEST = ""
147 "[ "
148 " [ "
149 " { "
150 " }, "
151 " { "
152 " } "
153 " ], "
154 " { "
155 " \"duration\": 3000, "
156 " \"easing\": \"cubic-bezier(0.0, 0.0, 0.0, 1.0)\","
157 " \"delay\": 1000, "
158 " \"fill\": \"forwards\", "
159 " \"iterations\": 1 "
160 " } "
161 "]";
162
163 const std::string NO_OFFSET_TEST = ""
164 "[ "
165 " [ "
166 " { "
167 " \"height\": \"150\" "
168 " }, "
169 " { "
170 " \"height\": \"150\" "
171 " } "
172 " ] "
173 "]";
174
175 const std::string MULTI_ANIMATION_TEST = ""
176 "[ "
177 " [ "
178 " { "
179 " \"height\": \"150\", "
180 " \"opacity\": \"1\" "
181 " }, "
182 " { "
183 " \"height\": \"150\", "
184 " \"opacity\": \"1\", "
185 " \"offset\": \"0.5\" "
186 " }, "
187 " { "
188 " \"height\": \"150\", "
189 " \"opacity\": \"1\" "
190 " } "
191 " ] "
192 "]";
193
194 const std::string SERIAL_ANIMATION_TEST = ""
195 "[ "
196 " [ "
197 " { "
198 " \"height\": \"150\", "
199 " \"offset\": \"0.0\" "
200 " }, "
201 " { "
202 " \"height\": \"150\", "
203 " \"offset\": \"0.5\" "
204 " }, "
205 " { "
206 " \"height\": \"150\", "
207 " \"offset\": \"1.0\" "
208 " } "
209 " ] "
210 "]";
211
212 const std::string SERIAL_TRANSFORM_TEST = ""
213 "[ "
214 " [ "
215 " { "
216 " \"transform\": { "
217 " \"translate\": \"50\", "
218 " \"scale\": \"1\" "
219 " }, "
220 " \"offset\": \"0.0\" "
221 " }, "
222 " { "
223 " \"transform\": { "
224 " \"translate\": \"100\", "
225 " \"scale\" : \"3\" "
226 " }, "
227 " \"offset\": \"1.0\" "
228 " } "
229 " ] "
230 "]";
231
232 const std::string ERROR_OFFSET_TEST = ""
233 "[ "
234 " [ "
235 " { "
236 " \"height\": \"150\" "
237 " }, "
238 " { "
239 " \"height\": \"150\", "
240 " \"offset\": \"0.5\" "
241 " }, "
242 " { "
243 " \"height\": \"150\", "
244 " \"offset\": \"0.7\" "
245 " } "
246 " ] "
247 "]";
248
249 } // namespace
250
251 class AnimationDomTest : public testing::Test, public BaseAnimationBridgeUtils {
252 public:
253 static void SetUpTestCase();
254 static void TearDownTestCase();
255 void SetUp() override;
256 void TearDown() override;
257 };
258
SetUpTestCase()259 void AnimationDomTest::SetUpTestCase() {}
TearDownTestCase()260 void AnimationDomTest::TearDownTestCase() {}
SetUp()261 void AnimationDomTest::SetUp() {}
TearDown()262 void AnimationDomTest::TearDown() {}
263
264 /**
265 * @tc.name: AnimationDomTest001
266 * @tc.desc: Animation JS api parse
267 * @tc.type: FUNC
268 * @tc.require: issueI5IYA3
269 */
270 HWTEST_F(AnimationDomTest, AnimationDomTest001, TestSize.Level1)
271 {
272 /**
273 * @tc.steps: step1. parse the param of transformOrigin.
274 */
275 std::vector<std::unordered_map<std::string, std::string>> animationFrames;
276 JsParseAnimationFrames(TRANSFORM_ORIGIN_TEST, animationFrames);
277
278 /**
279 * @tc.steps: step2. get the transformOrigin from the map.
280 */
281 auto transformOriginForm = animationFrames[0].find(DOM_TRANSFORM_ORIGIN)->second;
282 auto transformOriginTo = animationFrames[1].find(DOM_TRANSFORM_ORIGIN)->second;
283
284 /**
285 * @tc.steps: step3. Judge whether the parameter resolution is successful.
286 * @tc.expected: step3. The value of transformOrigin is as expected.
287 */
288 EXPECT_EQ(TRANSFORM_ORIGIN_DEFAULT_FROM, transformOriginForm);
289 EXPECT_EQ(TRANSFORM_ORIGIN_DEFAULT_TO, transformOriginTo);
290 }
291
292 /**
293 * @tc.name: AnimationDomTest002
294 * @tc.desc: Animation JS api parse
295 * @tc.type: FUNC
296 * @tc.require: issueI5IZTL
297 */
298 HWTEST_F(AnimationDomTest, AnimationDomTest002, TestSize.Level1)
299 {
300 /**
301 * @tc.steps: step1. parse the param of transform.
302 */
303 std::vector<std::unordered_map<std::string, std::string>> animationFrames;
304 JsParseAnimationFrames(TRANSFORM_TEST, animationFrames);
305
306 /**
307 * @tc.steps: step2. get the transform from the map.
308 */
309
310 EXPECT_TRUE(animationFrames.size() == 2);
311 auto transformFrom = animationFrames[0].find(DOM_TRANSFORM);
312 auto transformTo = animationFrames[1].find(DOM_TRANSFORM);
313
314 /**
315 * @tc.steps: step3. Judge whether the parameter resolution is successful.
316 * @tc.expected: step3. The value of transform is as expected.
317 */
318 EXPECT_TRUE(transformFrom != animationFrames[0].end());
319 EXPECT_TRUE(transformTo != animationFrames[1].end());
320 }
321
322 /**
323 * @tc.name: AnimationDomTest003
324 * @tc.desc: Animation JS api parse
325 * @tc.type: FUNC
326 * @tc.require: issueI5JQ36
327 */
328 HWTEST_F(AnimationDomTest, AnimationDomTest003, TestSize.Level1)
329 {
330 /**
331 * @tc.steps: step1. parse the param of height and width.
332 */
333 std::vector<std::unordered_map<std::string, std::string>> animationFrames;
334 JsParseAnimationFrames(HEIGHT_WIDTH_TEST, animationFrames);
335
336 /**
337 * @tc.steps: step2. get the params from the map.
338 */
339 auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
340 auto widthForm = animationFrames[0].find(DOM_ANIMATION_WIDTH)->second;
341 auto heightTo = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
342 auto widthTo = animationFrames[1].find(DOM_ANIMATION_WIDTH)->second;
343
344 /**
345 * @tc.steps: step3. Judge whether the parameter resolution is successful.
346 * @tc.expected: step3. The value of the params are as expected.
347 */
348 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
349 EXPECT_EQ(ANIMATION_WIDTH_DEFAULT, widthForm);
350 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
351 EXPECT_EQ(ANIMATION_WIDTH_DEFAULT, widthTo);
352 }
353
354 /**
355 * @tc.name: AnimationDomTest004
356 * @tc.desc: Animation JS api parse
357 * @tc.type: FUNC
358 */
359 HWTEST_F(AnimationDomTest, AnimationDomTest004, TestSize.Level1)
360 {
361 /**
362 * @tc.steps: step1. parse the param of opacity and color.
363 */
364 std::vector<std::unordered_map<std::string, std::string>> animationFrames;
365 JsParseAnimationFrames(OPACITY_COLOR_TEST, animationFrames);
366
367 /**
368 * @tc.steps: step2. get the params from the map.
369 */
370 auto opacityForm = animationFrames[0].find(DOM_ANIMATION_OPACITY)->second;
371 auto colorForm = animationFrames[0].find(DOM_ANIMATION_COLOR)->second;
372 auto opacityTo = animationFrames[1].find(DOM_ANIMATION_OPACITY)->second;
373 auto colorTo = animationFrames[1].find(DOM_ANIMATION_COLOR)->second;
374
375 /**
376 * @tc.steps: step3. Judge whether the parameter resolution is successful.
377 * @tc.expected: step3. The value of the params are as expected.
378 */
379 EXPECT_EQ(ANIMATION_OPACITY_DEFAULT, opacityForm);
380 EXPECT_EQ(ANIMATION_COLOR_DEFAULT, colorForm);
381 EXPECT_EQ(ANIMATION_OPACITY_DEFAULT, opacityTo);
382 EXPECT_EQ(ANIMATION_COLOR_DEFAULT, colorTo);
383 }
384
385 /**
386 * @tc.name: AnimationDomTest005
387 * @tc.desc: Animation JS api parse
388 * @tc.type: FUNC
389 */
390 HWTEST_F(AnimationDomTest, AnimationDomTest005, TestSize.Level1)
391 {
392 /**
393 * @tc.steps: step1. parse the param of options.
394 */
395 int32_t iterations = 0;
396 std::unordered_map<std::string, double> animationDoubleOptions;
397 std::unordered_map<std::string, std::string> animationStringOptions;
398 JsParseAnimationOptions(OPTIONS_TEST, iterations, animationDoubleOptions, animationStringOptions);
399
400 /**
401 * @tc.steps: step2. get the params from the map.
402 */
403 auto easing = animationStringOptions.find(DOM_ANIMATION_EASING)->second;
404 auto fill = animationStringOptions.find(DOM_ANIMATION_FILL)->second;
405 auto duration = animationDoubleOptions.find(DOM_ANIMATION_DURATION_API)->second;
406 auto delay = animationDoubleOptions.find(DOM_ANIMATION_DELAY_API)->second;
407
408 /**
409 * @tc.steps: step3. Judge whether the parameter resolution is successful.
410 * @tc.expected: step3. The value of the params are as expected.
411 */
412 EXPECT_EQ(ANIMATION_ITERATIONS_DEFAULT, iterations);
413 EXPECT_EQ(ANIMATION_DURATIONS_DEFAULT, duration);
414 EXPECT_EQ(ANIMATION_DELAY_DEFAULT, delay);
415 EXPECT_EQ(ANIMATION_EASING_DEFAULT, easing);
416 EXPECT_EQ(ANIMATION_FILL_DEFAULT, fill);
417 }
418
419 /**
420 * @tc.name: AnimationDomTest006
421 * @tc.desc: Serial animation JS api parse
422 * @tc.type: FUNC
423 */
424 HWTEST_F(AnimationDomTest, AnimationDomTest006, TestSize.Level1)
425 {
426 /**
427 * @tc.steps: step1. parse the param.
428 */
429 std::vector<std::unordered_map<std::string, std::string>> animationFrames;
430 JsParseAnimationFrames(NO_OFFSET_TEST, animationFrames);
431
432 /**
433 * @tc.steps: step2. get the params from the map.
434 */
435 auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
436 auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET)->second;
437 auto heightTo = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
438 auto offsetTo = animationFrames[1].find(DOM_ANIMATION_OFFSET)->second;
439
440 /**
441 * @tc.steps: step3. Judge whether the parameter resolution is successful.
442 * @tc.expected: step3. The value of the params are as expected.
443 */
444 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
445
446 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_FROM), StringToDouble(offsetFrom)));
447 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
448 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_TO), StringToDouble(offsetTo)));
449 }
450
451 /**
452 * @tc.name: AnimationDomTest007
453 * @tc.desc: Serial animation JS api parse
454 * @tc.type: FUNC
455 */
456 HWTEST_F(AnimationDomTest, AnimationDomTest007, TestSize.Level1)
457 {
458 /**
459 * @tc.steps: step1. parse the param.
460 */
461 std::vector<std::unordered_map<std::string, std::string>> animationFrames;
462 JsParseAnimationFrames(MULTI_ANIMATION_TEST, animationFrames);
463
464 /**
465 * @tc.steps: step2. get the params from the map.
466 */
467 auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
468 auto opacityFrom = animationFrames[0].find(DOM_ANIMATION_OPACITY)->second;
469 auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET)->second;
470 auto heightMiddle = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
471 auto opacityMiddle = animationFrames[1].find(DOM_ANIMATION_OPACITY)->second;
472 auto offsetMiddle = animationFrames[1].find(DOM_ANIMATION_OFFSET)->second;
473 auto heightTo = animationFrames[2].find(DOM_ANIMATION_HEIGHT)->second;
474 auto opacityTo = animationFrames[2].find(DOM_ANIMATION_OPACITY)->second;
475 auto offsetTo = animationFrames[2].find(DOM_ANIMATION_OFFSET)->second;
476
477 /**
478 * @tc.steps: step3. Judge whether the parameter resolution is successful.
479 * @tc.expected: step3. The value of the params are as expected.
480 */
481 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
482 EXPECT_EQ(ANIMATION_OPACITY_DEFAULT, opacityFrom);
483 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_FROM), StringToDouble(offsetFrom)));
484 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightMiddle);
485 EXPECT_EQ(ANIMATION_OPACITY_DEFAULT, opacityMiddle);
486 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_MIDDLE), StringToDouble(offsetMiddle)));
487 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
488 EXPECT_EQ(ANIMATION_OPACITY_DEFAULT, opacityTo);
489 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_TO), StringToDouble(offsetTo)));
490 }
491
492 /**
493 * @tc.name: AnimationDomTest008
494 * @tc.desc: Serial animation JS api parse
495 * @tc.type: FUNC
496 */
497 HWTEST_F(AnimationDomTest, AnimationDomTest008, TestSize.Level1)
498 {
499 /**
500 * @tc.steps: step1. parse the param.
501 */
502 std::vector<std::unordered_map<std::string, std::string>> animationFrames;
503 JsParseAnimationFrames(SERIAL_ANIMATION_TEST, animationFrames);
504
505 /**
506 * @tc.steps: step2. get the params from the map.
507 */
508 auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
509 auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET)->second;
510 auto heightMiddle = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
511 auto offsetMiddle = animationFrames[1].find(DOM_ANIMATION_OFFSET)->second;
512 auto heightTo = animationFrames[2].find(DOM_ANIMATION_HEIGHT)->second;
513 auto offsetTo = animationFrames[2].find(DOM_ANIMATION_OFFSET)->second;
514
515 /**
516 * @tc.steps: step3. Judge whether the parameter resolution is successful.
517 * @tc.expected: step3. The value of the params are as expected.
518 */
519 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
520 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_FROM), StringToDouble(offsetFrom)));
521 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightMiddle);
522 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_MIDDLE), StringToDouble(offsetMiddle)));
523 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
524 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_TO), StringToDouble(offsetTo)));
525 }
526
527 /**
528 * @tc.name: AnimationDomTest009
529 * @tc.desc: Serial animation JS api parse
530 * @tc.type: FUNC
531 */
532 HWTEST_F(AnimationDomTest, AnimationDomTest009, TestSize.Level1)
533 {
534 /**
535 * @tc.steps: step1. parse the param.
536 */
537 std::vector<std::unordered_map<std::string, std::string>> animationFrames;
538 JsParseAnimationFrames(HEIGHT_WIDTH_TEST, animationFrames);
539
540 /**
541 * @tc.steps: step2. get the params from the map.
542 */
543 auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
544 auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET)->second;
545 auto heightTo = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
546 auto offsetTo = animationFrames[1].find(DOM_ANIMATION_OFFSET)->second;
547
548 /**
549 * @tc.steps: step3. Judge whether the parameter resolution is successful.
550 * @tc.expected: step3. The value of the params are as expected.
551 */
552 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
553 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_FROM), StringToDouble(offsetFrom)));
554 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
555 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_TO), StringToDouble(offsetTo)));
556 }
557
558 /**
559 * @tc.name: AnimationDomTest010
560 * @tc.desc: Serial animation JS api parse
561 * @tc.type: FUNC
562 */
563 HWTEST_F(AnimationDomTest, AnimationDomTest010, TestSize.Level1)
564 {
565 /**
566 * @tc.steps: step1. parse the param.
567 */
568 std::vector<std::unordered_map<std::string, std::string>> animationFrames;
569 JsParseAnimationFrames(SERIAL_TRANSFORM_TEST, animationFrames);
570
571 /**
572 * @tc.steps: step2. get the params from the map.
573 */
574 EXPECT_TRUE(animationFrames.size() == 2);
575 auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET);
576 EXPECT_TRUE(offsetFrom != animationFrames[0].end());
577 auto offsetTo = animationFrames[1].find(DOM_ANIMATION_OFFSET);
578 EXPECT_TRUE(offsetTo != animationFrames[1].end());
579
580 /**
581 * @tc.steps: step3. Judge whether the parameter resolution is successful.
582 * @tc.expected: step3. The value of the params are as expected.
583 */
584 EXPECT_EQ(StringToDouble(offsetFrom->second), StringToDouble(ANIMATION_OFFSET_FROM));
585 EXPECT_EQ(StringToDouble(offsetTo->second), StringToDouble(ANIMATION_OFFSET_TO));
586 }
587
588 /**
589 * @tc.name: AnimationDomTest011
590 * @tc.desc: Serial animation JS api parse
591 * @tc.type: FUNC
592 */
593 HWTEST_F(AnimationDomTest, AnimationDomTest011, TestSize.Level1)
594 {
595 /**
596 * @tc.steps: step1. parse the param.
597 */
598 std::vector<std::unordered_map<std::string, std::string>> animationFrames;
599 JsParseAnimationFrames(ERROR_OFFSET_TEST, animationFrames);
600
601 /**
602 * @tc.steps: step2. get the params from the map.
603 */
604 auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
605 auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET)->second;
606
607 auto heightMiddle = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
608 auto offsetMiddle = animationFrames[1].find(DOM_ANIMATION_OFFSET)->second;
609
610 auto heightTo = animationFrames[2].find(DOM_ANIMATION_HEIGHT)->second;
611 auto offsetTo = animationFrames[2].find(DOM_ANIMATION_OFFSET)->second;
612
613 /**
614 * @tc.steps: step3. Judge whether the parameter resolution is successful.
615 * @tc.expected: step3. The value of the params are as expected.
616 */
617 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
618 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_FROM), StringToDouble(offsetFrom)));
619
620 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightMiddle);
621 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_MIDDLE), StringToDouble(offsetMiddle)));
622
623 EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
624 EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_TO), StringToDouble(offsetTo)));
625 }
626
627 /**
628 * @tc.name: AnimationDomTest012
629 * @tc.desc: backgroundPosition parse
630 * @tc.type: FUNC
631 */
632 HWTEST_F(AnimationDomTest, AnimationDomTest012, TestSize.Level1)
633 {
634 /**
635 * @tc.steps: step1. parse the param.
636 * @tc.expected: step2. The value of the params are as expected.
637 */
638 BackgroundImagePosition backgroundImagePosition;
639 EXPECT_TRUE(ParseBackgroundImagePosition("10% 20%", backgroundImagePosition));
640 EXPECT_EQ(10, backgroundImagePosition.GetSizeValueX());
641 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
642 EXPECT_EQ(20, backgroundImagePosition.GetSizeValueY());
643 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
644 }
645
646 /**
647 * @tc.name: AnimationDomTest013
648 * @tc.desc: backgroundPosition parse
649 * @tc.type: FUNC
650 */
651 HWTEST_F(AnimationDomTest, AnimationDomTest013, TestSize.Level1)
652 {
653 /**
654 * @tc.steps: step1. parse the param.
655 * @tc.expected: step2. The value of the params are as expected.
656 */
657 BackgroundImagePosition backgroundImagePosition;
658 EXPECT_TRUE(ParseBackgroundImagePosition("10%", backgroundImagePosition));
659 EXPECT_EQ(10, backgroundImagePosition.GetSizeValueX());
660 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
661 EXPECT_EQ(50, backgroundImagePosition.GetSizeValueY());
662 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
663
664 /**
665 * @tc.steps: step3. parse the param.
666 * @tc.expected: step4. The value of the params are as expected.
667 */
668 EXPECT_TRUE(ParseBackgroundImagePosition("10% 100px", backgroundImagePosition));
669 EXPECT_EQ(10, backgroundImagePosition.GetSizeValueX());
670 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
671 EXPECT_EQ(100, backgroundImagePosition.GetSizeValueY());
672 EXPECT_EQ(BackgroundImagePositionType::PX, backgroundImagePosition.GetSizeTypeY());
673
674 /**
675 * @tc.steps: step5. parse the param.
676 * @tc.expected: step6. The value of the params are as expected.
677 */
678 EXPECT_TRUE(ParseBackgroundImagePosition(" 30px 45% ", backgroundImagePosition));
679 EXPECT_EQ(30, backgroundImagePosition.GetSizeValueX());
680 EXPECT_EQ(BackgroundImagePositionType::PX, backgroundImagePosition.GetSizeTypeX());
681 EXPECT_EQ(45, backgroundImagePosition.GetSizeValueY());
682 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
683 }
684
685 /**
686 * @tc.name: AnimationDomTest014
687 * @tc.desc: backgroundPosition parse
688 * @tc.type: FUNC
689 */
690 HWTEST_F(AnimationDomTest, AnimationDomTest014, TestSize.Level1)
691 {
692 BackgroundImagePosition backgroundImagePosition;
693 /**
694 * @tc.steps: step1. parse the param.
695 * @tc.expected: step2. The value of the params are as expected.
696 */
697 EXPECT_TRUE(ParseBackgroundImagePosition("left", backgroundImagePosition));
698 EXPECT_EQ(0, backgroundImagePosition.GetSizeValueX());
699 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
700 EXPECT_EQ(50, backgroundImagePosition.GetSizeValueY());
701 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
702
703 /**
704 * @tc.steps: step3. parse the param.
705 * @tc.expected: step4. The value of the params are as expected.
706 */
707 EXPECT_TRUE(ParseBackgroundImagePosition("bottom", backgroundImagePosition));
708 EXPECT_EQ(50, backgroundImagePosition.GetSizeValueX());
709 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
710 EXPECT_EQ(100, backgroundImagePosition.GetSizeValueY());
711 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
712
713 /**
714 * @tc.steps: step5. parse the param.
715 * @tc.expected: step6. The value of the params are as expected.
716 */
717 EXPECT_TRUE(ParseBackgroundImagePosition("right bottom", backgroundImagePosition));
718 EXPECT_EQ(100, backgroundImagePosition.GetSizeValueX());
719 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
720 EXPECT_EQ(100, backgroundImagePosition.GetSizeValueY());
721 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
722
723 /**
724 * @tc.steps: step7. parse the param.
725 * @tc.expected: step8. The value of the params are as expected.
726 */
727 EXPECT_TRUE(ParseBackgroundImagePosition("bottom right", backgroundImagePosition));
728 EXPECT_EQ(100, backgroundImagePosition.GetSizeValueX());
729 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
730 EXPECT_EQ(100, backgroundImagePosition.GetSizeValueY());
731 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
732
733 /**
734 * @tc.steps: step9. parse the param.
735 * @tc.expected: step10. The value of the params are as expected.
736 */
737 EXPECT_TRUE(ParseBackgroundImagePosition("center 50px", backgroundImagePosition));
738 EXPECT_EQ(50, backgroundImagePosition.GetSizeValueX());
739 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
740 EXPECT_EQ(50, backgroundImagePosition.GetSizeValueY());
741 EXPECT_EQ(BackgroundImagePositionType::PX, backgroundImagePosition.GetSizeTypeY());
742
743 /**
744 * @tc.steps: step11. parse the param.
745 * @tc.expected: step12. The value of the params are as expected.
746 */
747 EXPECT_TRUE(ParseBackgroundImagePosition("70px bottom", backgroundImagePosition));
748 EXPECT_EQ(70, backgroundImagePosition.GetSizeValueX());
749 EXPECT_EQ(BackgroundImagePositionType::PX, backgroundImagePosition.GetSizeTypeX());
750 EXPECT_EQ(100, backgroundImagePosition.GetSizeValueY());
751 EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
752 }
753
754 /**
755 * @tc.name: AnimationDomTest015
756 * @tc.desc: Animation JS api parse
757 * @tc.type: FUNC
758 */
759 HWTEST_F(AnimationDomTest, AnimationDomTest015, TestSize.Level1)
760 {
761 /**
762 * @tc.steps: step1. parse the param of options.
763 */
764 int32_t iterations = 0;
765 std::unordered_map<std::string, double> animationDoubleOptions;
766 std::unordered_map<std::string, std::string> animationStringOptions;
767 JsParseAnimationOptions(OPTIONS_TEST, iterations, animationDoubleOptions, animationStringOptions);
768
769 /**
770 * @tc.steps: step2. get the params from the map.
771 */
772 auto direction = animationStringOptions.find(DOM_ANIMATION_DIRECTION_API)->second;
773
774 /**
775 * @tc.steps: step3. Judge whether the parameter resolution is successful.
776 * @tc.expected: step3. The value of the params are as expected.
777 */
778 EXPECT_EQ(DOM_ANIMATION_DIRECTION_ALTERNATE, direction);
779 }
780
781 /**
782 * @tc.name: AnimationDomCurveTest002
783 * @tc.desc: Animation JS api parse
784 * @tc.type: FUNC
785 */
786 HWTEST_F(AnimationDomTest, AnimationDomCurveTest002, TestSize.Level1)
787 {
788 /**
789 * @tc.steps: step1. parse the param of anticipate curve.
790 */
791 int32_t iterations = 0;
792 std::unordered_map<std::string, double> animationDoubleOptions;
793 std::unordered_map<std::string, std::string> animationStringOptions;
794 JsParseAnimationOptions(ANTICIPATE_CURVE_TEST, iterations, animationDoubleOptions, animationStringOptions);
795
796 /**
797 * @tc.steps: step2. get the params from the map.
798 */
799 auto easing = animationStringOptions.find(DOM_ANIMATION_EASING)->second;
800
801 /**
802 * @tc.steps: step3. Judge whether the parameter resolution is successful.
803 * @tc.expected: step3. The value of the params are as expected.
804 */
805 EXPECT_EQ(ANIMATION_EASING_ANTICIPATE, easing);
806 }
807
808 /**
809 * @tc.name: AnimationDomCurveTest003
810 * @tc.desc: Animation JS api parse
811 * @tc.type: FUNC
812 */
813 HWTEST_F(AnimationDomTest, AnimationDomCurveTest003, TestSize.Level1)
814 {
815 /**
816 * @tc.steps: step1. parse the param of cubic curve.
817 */
818 int32_t iterations = 0;
819 std::unordered_map<std::string, double> animationDoubleOptions;
820 std::unordered_map<std::string, std::string> animationStringOptions;
821 JsParseAnimationOptions(CUBIC_CURVE_TEST, iterations, animationDoubleOptions, animationStringOptions);
822
823 /**
824 * @tc.steps: step2. get the params from the map.
825 */
826 auto easing = animationStringOptions.find(DOM_ANIMATION_EASING)->second;
827
828 /**
829 * @tc.steps: step3. Judge whether the parameter resolution is successful.
830 * @tc.expected: step3. The value of the params are as expected.
831 */
832 EXPECT_EQ(ANIMATION_EASING_CUBIC, easing);
833 }
834
835 /**
836 * @tc.name: AnimationDomCurveTest004
837 * @tc.desc: Animation steps parse check
838 * @tc.type: FUNC
839 */
840 HWTEST_F(AnimationDomTest, AnimationDomCurveTest004, TestSize.Level1)
841 {
842 /**
843 * @tc.steps: step1. parse the param of steps curve.
844 * @tc.expected: step1. steps curve parsed success.
845 */
846 auto curve = AceType::DynamicCast<StepsCurve>(CreateCurve("steps(2, start)"));
847 EXPECT_EQ(curve->MoveInternal(0.0), 0.5);
848 }
849
850 } // namespace OHOS::Ace::Framework
851