• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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: AR000DQ20L
269  * @tc.author: jiachunhui
270  */
271 HWTEST_F(AnimationDomTest, AnimationDomTest001, TestSize.Level1)
272 {
273     /**
274      * @tc.steps: step1. parse the param of transformOrigin.
275      */
276     std::vector<std::unordered_map<std::string, std::string>> animationFrames;
277     JsParseAnimationFrames(TRANSFORM_ORIGIN_TEST, animationFrames);
278 
279     /**
280      * @tc.steps: step2. get the transformOrigin from the map.
281      */
282     auto transformOriginForm = animationFrames[0].find(DOM_TRANSFORM_ORIGIN)->second;
283     auto transformOriginTo = animationFrames[1].find(DOM_TRANSFORM_ORIGIN)->second;
284 
285     /**
286      * @tc.steps: step3. Judge whether the parameter resolution is successful.
287      * @tc.expected: step3. The value of transformOrigin is as expected.
288      */
289     EXPECT_EQ(TRANSFORM_ORIGIN_DEFAULT_FROM, transformOriginForm);
290     EXPECT_EQ(TRANSFORM_ORIGIN_DEFAULT_TO, transformOriginTo);
291 }
292 
293 /**
294  * @tc.name: AnimationDomTest002
295  * @tc.desc: Animation JS api parse
296  * @tc.type: FUNC
297  * @tc.require: AR000DQ20M
298  * @tc.author: jiachunhui
299  */
300 HWTEST_F(AnimationDomTest, AnimationDomTest002, TestSize.Level1)
301 {
302     /**
303      * @tc.steps: step1. parse the param of transform.
304      */
305     std::vector<std::unordered_map<std::string, std::string>> animationFrames;
306     JsParseAnimationFrames(TRANSFORM_TEST, animationFrames);
307 
308     /**
309      * @tc.steps: step2. get the transform from the map.
310      */
311 
312     EXPECT_TRUE(animationFrames.size() == 2);
313     auto transformFrom = animationFrames[0].find(DOM_TRANSFORM);
314     auto transformTo = animationFrames[1].find(DOM_TRANSFORM);
315 
316     /**
317      * @tc.steps: step3. Judge whether the parameter resolution is successful.
318      * @tc.expected: step3. The value of transform is as expected.
319      */
320     EXPECT_TRUE(transformFrom != animationFrames[0].end());
321     EXPECT_TRUE(transformTo != animationFrames[1].end());
322 }
323 
324 /**
325  * @tc.name: AnimationDomTest003
326  * @tc.desc: Animation JS api parse
327  * @tc.type: FUNC
328  * @tc.require: AR000DQ20M
329  * @tc.author: jiachunhui
330  */
331 HWTEST_F(AnimationDomTest, AnimationDomTest003, TestSize.Level1)
332 {
333     /**
334      * @tc.steps: step1. parse the param of height and width.
335      */
336     std::vector<std::unordered_map<std::string, std::string>> animationFrames;
337     JsParseAnimationFrames(HEIGHT_WIDTH_TEST, animationFrames);
338 
339     /**
340      * @tc.steps: step2. get the params from the map.
341      */
342     auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
343     auto widthForm = animationFrames[0].find(DOM_ANIMATION_WIDTH)->second;
344     auto heightTo = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
345     auto widthTo = animationFrames[1].find(DOM_ANIMATION_WIDTH)->second;
346 
347     /**
348      * @tc.steps: step3. Judge whether the parameter resolution is successful.
349      * @tc.expected: step3. The value of the params are as expected.
350      */
351     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
352     EXPECT_EQ(ANIMATION_WIDTH_DEFAULT, widthForm);
353     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
354     EXPECT_EQ(ANIMATION_WIDTH_DEFAULT, widthTo);
355 }
356 
357 /**
358  * @tc.name: AnimationDomTest004
359  * @tc.desc: Animation JS api parse
360  * @tc.type: FUNC
361  * @tc.require: AR000DQ20M
362  * @tc.author: jiachunhui
363  */
364 HWTEST_F(AnimationDomTest, AnimationDomTest004, TestSize.Level1)
365 {
366     /**
367      * @tc.steps: step1. parse the param of opacity and color.
368      */
369     std::vector<std::unordered_map<std::string, std::string>> animationFrames;
370     JsParseAnimationFrames(OPACITY_COLOR_TEST, animationFrames);
371 
372     /**
373      * @tc.steps: step2. get the params from the map.
374      */
375     auto opacityForm = animationFrames[0].find(DOM_ANIMATION_OPACITY)->second;
376     auto colorForm = animationFrames[0].find(DOM_ANIMATION_COLOR)->second;
377     auto opacityTo = animationFrames[1].find(DOM_ANIMATION_OPACITY)->second;
378     auto colorTo = animationFrames[1].find(DOM_ANIMATION_COLOR)->second;
379 
380     /**
381      * @tc.steps: step3. Judge whether the parameter resolution is successful.
382      * @tc.expected: step3. The value of the params are as expected.
383      */
384     EXPECT_EQ(ANIMATION_OPACITY_DEFAULT, opacityForm);
385     EXPECT_EQ(ANIMATION_COLOR_DEFAULT, colorForm);
386     EXPECT_EQ(ANIMATION_OPACITY_DEFAULT, opacityTo);
387     EXPECT_EQ(ANIMATION_COLOR_DEFAULT, colorTo);
388 }
389 
390 /**
391  * @tc.name: AnimationDomTest005
392  * @tc.desc: Animation JS api parse
393  * @tc.type: FUNC
394  * @tc.require: AR000DQ20K
395  * @tc.author: jiachunhui
396  */
397 HWTEST_F(AnimationDomTest, AnimationDomTest005, TestSize.Level1)
398 {
399     /**
400      * @tc.steps: step1. parse the param of options.
401      */
402     int32_t iterations = 0;
403     std::unordered_map<std::string, double> animationDoubleOptions;
404     std::unordered_map<std::string, std::string> animationStringOptions;
405     JsParseAnimationOptions(OPTIONS_TEST, iterations, animationDoubleOptions, animationStringOptions);
406 
407     /**
408      * @tc.steps: step2. get the params from the map.
409      */
410     auto easing = animationStringOptions.find(DOM_ANIMATION_EASING)->second;
411     auto fill = animationStringOptions.find(DOM_ANIMATION_FILL)->second;
412     auto duration = animationDoubleOptions.find(DOM_ANIMATION_DURATION_API)->second;
413     auto delay = animationDoubleOptions.find(DOM_ANIMATION_DELAY_API)->second;
414 
415     /**
416      * @tc.steps: step3. Judge whether the parameter resolution is successful.
417      * @tc.expected: step3. The value of the params are as expected.
418      */
419     EXPECT_EQ(ANIMATION_ITERATIONS_DEFAULT, iterations);
420     EXPECT_EQ(ANIMATION_DURATIONS_DEFAULT, duration);
421     EXPECT_EQ(ANIMATION_DELAY_DEFAULT, delay);
422     EXPECT_EQ(ANIMATION_EASING_DEFAULT, easing);
423     EXPECT_EQ(ANIMATION_FILL_DEFAULT, fill);
424 }
425 
426 /**
427  * @tc.name: AnimationDomTest006
428  * @tc.desc: Serial animation JS api parse
429  * @tc.type: FUNC
430  * @tc.require: AR000DQ2V6
431  * @tc.author: jiangdayuan
432  */
433 HWTEST_F(AnimationDomTest, AnimationDomTest006, TestSize.Level1)
434 {
435     /**
436      * @tc.steps: step1. parse the param.
437      */
438     std::vector<std::unordered_map<std::string, std::string>> animationFrames;
439     JsParseAnimationFrames(NO_OFFSET_TEST, animationFrames);
440 
441     /**
442      * @tc.steps: step2. get the params from the map.
443      */
444     auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
445     auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET)->second;
446     auto heightTo = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
447     auto offsetTo = animationFrames[1].find(DOM_ANIMATION_OFFSET)->second;
448 
449     /**
450      * @tc.steps: step3. Judge whether the parameter resolution is successful.
451      * @tc.expected: step3. The value of the params are as expected.
452      */
453     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
454 
455     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_FROM), StringToDouble(offsetFrom)));
456     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
457     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_TO), StringToDouble(offsetTo)));
458 }
459 
460 /**
461  * @tc.name: AnimationDomTest007
462  * @tc.desc: Serial animation JS api parse
463  * @tc.type: FUNC
464  * @tc.require: AR000DQ20O
465  * @tc.author: jiangdayuan
466  */
467 HWTEST_F(AnimationDomTest, AnimationDomTest007, TestSize.Level1)
468 {
469     /**
470      * @tc.steps: step1. parse the param.
471      */
472     std::vector<std::unordered_map<std::string, std::string>> animationFrames;
473     JsParseAnimationFrames(MULTI_ANIMATION_TEST, animationFrames);
474 
475     /**
476      * @tc.steps: step2. get the params from the map.
477      */
478     auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
479     auto opacityFrom = animationFrames[0].find(DOM_ANIMATION_OPACITY)->second;
480     auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET)->second;
481     auto heightMiddle = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
482     auto opacityMiddle = animationFrames[1].find(DOM_ANIMATION_OPACITY)->second;
483     auto offsetMiddle = animationFrames[1].find(DOM_ANIMATION_OFFSET)->second;
484     auto heightTo = animationFrames[2].find(DOM_ANIMATION_HEIGHT)->second;
485     auto opacityTo = animationFrames[2].find(DOM_ANIMATION_OPACITY)->second;
486     auto offsetTo = animationFrames[2].find(DOM_ANIMATION_OFFSET)->second;
487 
488     /**
489      * @tc.steps: step3. Judge whether the parameter resolution is successful.
490      * @tc.expected: step3. The value of the params are as expected.
491      */
492     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
493     EXPECT_EQ(ANIMATION_OPACITY_DEFAULT, opacityFrom);
494     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_FROM), StringToDouble(offsetFrom)));
495     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightMiddle);
496     EXPECT_EQ(ANIMATION_OPACITY_DEFAULT, opacityMiddle);
497     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_MIDDLE), StringToDouble(offsetMiddle)));
498     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
499     EXPECT_EQ(ANIMATION_OPACITY_DEFAULT, opacityTo);
500     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_TO), StringToDouble(offsetTo)));
501 }
502 
503 /**
504  * @tc.name: AnimationDomTest008
505  * @tc.desc: Serial animation JS api parse
506  * @tc.type: FUNC
507  * @tc.require: AR000DQ20P
508  * @tc.author: jiangdayuan
509  */
510 HWTEST_F(AnimationDomTest, AnimationDomTest008, TestSize.Level1)
511 {
512     /**
513      * @tc.steps: step1. parse the param.
514      */
515     std::vector<std::unordered_map<std::string, std::string>> animationFrames;
516     JsParseAnimationFrames(SERIAL_ANIMATION_TEST, animationFrames);
517 
518     /**
519      * @tc.steps: step2. get the params from the map.
520      */
521     auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
522     auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET)->second;
523     auto heightMiddle = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
524     auto offsetMiddle = animationFrames[1].find(DOM_ANIMATION_OFFSET)->second;
525     auto heightTo = animationFrames[2].find(DOM_ANIMATION_HEIGHT)->second;
526     auto offsetTo = animationFrames[2].find(DOM_ANIMATION_OFFSET)->second;
527 
528     /**
529      * @tc.steps: step3. Judge whether the parameter resolution is successful.
530      * @tc.expected: step3. The value of the params are as expected.
531      */
532     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
533     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_FROM), StringToDouble(offsetFrom)));
534     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightMiddle);
535     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_MIDDLE), StringToDouble(offsetMiddle)));
536     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
537     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_TO), StringToDouble(offsetTo)));
538 }
539 
540 /**
541  * @tc.name: AnimationDomTest009
542  * @tc.desc: Serial animation JS api parse
543  * @tc.type: FUNC
544  * @tc.require: AR000DQ20Q
545  * @tc.author: jiangdayuan
546  */
547 HWTEST_F(AnimationDomTest, AnimationDomTest009, TestSize.Level1)
548 {
549     /**
550      * @tc.steps: step1. parse the param.
551      */
552     std::vector<std::unordered_map<std::string, std::string>> animationFrames;
553     JsParseAnimationFrames(HEIGHT_WIDTH_TEST, animationFrames);
554 
555     /**
556      * @tc.steps: step2. get the params from the map.
557      */
558     auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
559     auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET)->second;
560     auto heightTo = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
561     auto offsetTo = animationFrames[1].find(DOM_ANIMATION_OFFSET)->second;
562 
563     /**
564      * @tc.steps: step3. Judge whether the parameter resolution is successful.
565      * @tc.expected: step3. The value of the params are as expected.
566      */
567     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
568     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_FROM), StringToDouble(offsetFrom)));
569     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
570     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_TO), StringToDouble(offsetTo)));
571 }
572 
573 /**
574  * @tc.name: AnimationDomTest010
575  * @tc.desc: Serial animation JS api parse
576  * @tc.type: FUNC
577  * @tc.require: AR000DQ20Q
578  * @tc.author: jiangdayuan
579  */
580 HWTEST_F(AnimationDomTest, AnimationDomTest010, TestSize.Level1)
581 {
582     /**
583      * @tc.steps: step1. parse the param.
584      */
585     std::vector<std::unordered_map<std::string, std::string>> animationFrames;
586     JsParseAnimationFrames(SERIAL_TRANSFORM_TEST, animationFrames);
587 
588     /**
589      * @tc.steps: step2. get the params from the map.
590      */
591     EXPECT_TRUE(animationFrames.size() == 2);
592     auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET);
593     EXPECT_TRUE(offsetFrom != animationFrames[0].end());
594     auto offsetTo = animationFrames[1].find(DOM_ANIMATION_OFFSET);
595     EXPECT_TRUE(offsetTo != animationFrames[1].end());
596 
597     /**
598      * @tc.steps: step3. Judge whether the parameter resolution is successful.
599      * @tc.expected: step3. The value of the params are as expected.
600      */
601     EXPECT_EQ(StringToDouble(offsetFrom->second), StringToDouble(ANIMATION_OFFSET_FROM));
602     EXPECT_EQ(StringToDouble(offsetTo->second), StringToDouble(ANIMATION_OFFSET_TO));
603 }
604 
605 /**
606  * @tc.name: AnimationDomTest011
607  * @tc.desc: Serial animation JS api parse
608  * @tc.type: FUNC
609  * @tc.require: AR000DQ20Q
610  * @tc.author: jiangdayuan
611  */
612 HWTEST_F(AnimationDomTest, AnimationDomTest011, TestSize.Level1)
613 {
614     /**
615      * @tc.steps: step1. parse the param.
616      */
617     std::vector<std::unordered_map<std::string, std::string>> animationFrames;
618     JsParseAnimationFrames(ERROR_OFFSET_TEST, animationFrames);
619 
620     /**
621      * @tc.steps: step2. get the params from the map.
622      */
623     auto heightForm = animationFrames[0].find(DOM_ANIMATION_HEIGHT)->second;
624     auto offsetFrom = animationFrames[0].find(DOM_ANIMATION_OFFSET)->second;
625 
626     auto heightMiddle = animationFrames[1].find(DOM_ANIMATION_HEIGHT)->second;
627     auto offsetMiddle = animationFrames[1].find(DOM_ANIMATION_OFFSET)->second;
628 
629     auto heightTo = animationFrames[2].find(DOM_ANIMATION_HEIGHT)->second;
630     auto offsetTo = animationFrames[2].find(DOM_ANIMATION_OFFSET)->second;
631 
632     /**
633      * @tc.steps: step3. Judge whether the parameter resolution is successful.
634      * @tc.expected: step3. The value of the params are as expected.
635      */
636     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightForm);
637     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_FROM), StringToDouble(offsetFrom)));
638 
639     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightMiddle);
640     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_MIDDLE), StringToDouble(offsetMiddle)));
641 
642     EXPECT_EQ(ANIMATION_HEIGHT_DEFAULT, heightTo);
643     EXPECT_TRUE(NearEqual(StringToDouble(ANIMATION_OFFSET_TO), StringToDouble(offsetTo)));
644 }
645 
646 /**
647  * @tc.name: AnimationDomTest012
648  * @tc.desc: backgroundPosition parse
649  * @tc.type: FUNC
650  * @tc.require: AR000FL0U9
651  * @tc.author: zhouzebin
652  */
653 HWTEST_F(AnimationDomTest, AnimationDomTest012, TestSize.Level1)
654 {
655     /**
656      * @tc.steps: step1. parse the param.
657      * @tc.expected: step2. The value of the params are as expected.
658      */
659     BackgroundImagePosition backgroundImagePosition;
660     EXPECT_TRUE(ParseBackgroundImagePosition("10% 20%", backgroundImagePosition));
661     EXPECT_EQ(10, backgroundImagePosition.GetSizeValueX());
662     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
663     EXPECT_EQ(20, backgroundImagePosition.GetSizeValueY());
664     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
665 }
666 
667 /**
668  * @tc.name: AnimationDomTest013
669  * @tc.desc: backgroundPosition parse
670  * @tc.type: FUNC
671  * @tc.require: AR000FL0U9
672  * @tc.author: zhouzebin
673  */
674 HWTEST_F(AnimationDomTest, AnimationDomTest013, TestSize.Level1)
675 {
676     /**
677      * @tc.steps: step1. parse the param.
678      * @tc.expected: step2. The value of the params are as expected.
679      */
680     BackgroundImagePosition backgroundImagePosition;
681     EXPECT_TRUE(ParseBackgroundImagePosition("10%", backgroundImagePosition));
682     EXPECT_EQ(10, backgroundImagePosition.GetSizeValueX());
683     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
684     EXPECT_EQ(50, backgroundImagePosition.GetSizeValueY());
685     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
686 
687     /**
688      * @tc.steps: step3. parse the param.
689      * @tc.expected: step4. The value of the params are as expected.
690      */
691     EXPECT_TRUE(ParseBackgroundImagePosition("10% 100px", backgroundImagePosition));
692     EXPECT_EQ(10, backgroundImagePosition.GetSizeValueX());
693     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
694     EXPECT_EQ(100, backgroundImagePosition.GetSizeValueY());
695     EXPECT_EQ(BackgroundImagePositionType::PX, backgroundImagePosition.GetSizeTypeY());
696 
697     /**
698      * @tc.steps: step5. parse the param.
699      * @tc.expected: step6. The value of the params are as expected.
700      */
701     EXPECT_TRUE(ParseBackgroundImagePosition(" 30px   45% ", backgroundImagePosition));
702     EXPECT_EQ(30, backgroundImagePosition.GetSizeValueX());
703     EXPECT_EQ(BackgroundImagePositionType::PX, backgroundImagePosition.GetSizeTypeX());
704     EXPECT_EQ(45, backgroundImagePosition.GetSizeValueY());
705     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
706 }
707 
708 /**
709  * @tc.name: AnimationDomTest014
710  * @tc.desc: backgroundPosition parse
711  * @tc.type: FUNC
712  * @tc.require: AR000FL0U9
713  * @tc.author: zhouzebin
714  */
715 HWTEST_F(AnimationDomTest, AnimationDomTest014, TestSize.Level1)
716 {
717     BackgroundImagePosition backgroundImagePosition;
718     /**
719      * @tc.steps: step1. parse the param.
720      * @tc.expected: step2. The value of the params are as expected.
721      */
722     EXPECT_TRUE(ParseBackgroundImagePosition("left", backgroundImagePosition));
723     EXPECT_EQ(0, backgroundImagePosition.GetSizeValueX());
724     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
725     EXPECT_EQ(50, backgroundImagePosition.GetSizeValueY());
726     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
727 
728     /**
729      * @tc.steps: step3. parse the param.
730      * @tc.expected: step4. The value of the params are as expected.
731      */
732     EXPECT_TRUE(ParseBackgroundImagePosition("bottom", backgroundImagePosition));
733     EXPECT_EQ(50, backgroundImagePosition.GetSizeValueX());
734     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
735     EXPECT_EQ(100, backgroundImagePosition.GetSizeValueY());
736     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
737 
738     /**
739      * @tc.steps: step5. parse the param.
740      * @tc.expected: step6. The value of the params are as expected.
741      */
742     EXPECT_TRUE(ParseBackgroundImagePosition("right bottom", backgroundImagePosition));
743     EXPECT_EQ(100, backgroundImagePosition.GetSizeValueX());
744     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
745     EXPECT_EQ(100, backgroundImagePosition.GetSizeValueY());
746     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
747 
748     /**
749      * @tc.steps: step7. parse the param.
750      * @tc.expected: step8. The value of the params are as expected.
751      */
752     EXPECT_TRUE(ParseBackgroundImagePosition("bottom right", backgroundImagePosition));
753     EXPECT_EQ(100, backgroundImagePosition.GetSizeValueX());
754     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
755     EXPECT_EQ(100, backgroundImagePosition.GetSizeValueY());
756     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
757 
758     /**
759      * @tc.steps: step9. parse the param.
760      * @tc.expected: step10. The value of the params are as expected.
761      */
762     EXPECT_TRUE(ParseBackgroundImagePosition("center 50px", backgroundImagePosition));
763     EXPECT_EQ(50, backgroundImagePosition.GetSizeValueX());
764     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeX());
765     EXPECT_EQ(50, backgroundImagePosition.GetSizeValueY());
766     EXPECT_EQ(BackgroundImagePositionType::PX, backgroundImagePosition.GetSizeTypeY());
767 
768     /**
769      * @tc.steps: step11. parse the param.
770      * @tc.expected: step12. The value of the params are as expected.
771      */
772     EXPECT_TRUE(ParseBackgroundImagePosition("70px bottom", backgroundImagePosition));
773     EXPECT_EQ(70, backgroundImagePosition.GetSizeValueX());
774     EXPECT_EQ(BackgroundImagePositionType::PX, backgroundImagePosition.GetSizeTypeX());
775     EXPECT_EQ(100, backgroundImagePosition.GetSizeValueY());
776     EXPECT_EQ(BackgroundImagePositionType::PERCENT, backgroundImagePosition.GetSizeTypeY());
777 }
778 
779 /**
780  * @tc.name: AnimationDomTest015
781  * @tc.desc: Animation JS api parse
782  * @tc.type: FUNC
783  * @tc.require: AR000FL0U7
784  * @tc.author: zhouzebin
785  */
786 HWTEST_F(AnimationDomTest, AnimationDomTest015, TestSize.Level1)
787 {
788     /**
789      * @tc.steps: step1. parse the param of options.
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(OPTIONS_TEST, iterations, animationDoubleOptions, animationStringOptions);
795 
796     /**
797      * @tc.steps: step2. get the params from the map.
798      */
799     auto direction = animationStringOptions.find(DOM_ANIMATION_DIRECTION_API)->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(DOM_ANIMATION_DIRECTION_ALTERNATE, direction);
806 }
807 
808 /**
809  * @tc.name: AnimationDomCurveTest002
810  * @tc.desc: Animation JS api parse
811  * @tc.type: FUNC
812  * @tc.require: AR000DQ2SB
813  * @tc.author: jiachunhui
814  */
815 HWTEST_F(AnimationDomTest, AnimationDomCurveTest002, TestSize.Level1)
816 {
817     /**
818      * @tc.steps: step1. parse the param of anticipate curve.
819      */
820     int32_t iterations = 0;
821     std::unordered_map<std::string, double> animationDoubleOptions;
822     std::unordered_map<std::string, std::string> animationStringOptions;
823     JsParseAnimationOptions(ANTICIPATE_CURVE_TEST, iterations, animationDoubleOptions, animationStringOptions);
824 
825     /**
826      * @tc.steps: step2. get the params from the map.
827      */
828     auto easing = animationStringOptions.find(DOM_ANIMATION_EASING)->second;
829 
830     /**
831      * @tc.steps: step3. Judge whether the parameter resolution is successful.
832      * @tc.expected: step3. The value of the params are as expected.
833      */
834     EXPECT_EQ(ANIMATION_EASING_ANTICIPATE, easing);
835 }
836 
837 /**
838  * @tc.name: AnimationDomCurveTest003
839  * @tc.desc: Animation JS api parse
840  * @tc.type: FUNC
841  * @tc.require: AR000DQ1VC
842  * @tc.author: jiachunhui
843  */
844 HWTEST_F(AnimationDomTest, AnimationDomCurveTest003, TestSize.Level1)
845 {
846     /**
847      * @tc.steps: step1. parse the param of cubic curve.
848      */
849     int32_t iterations = 0;
850     std::unordered_map<std::string, double> animationDoubleOptions;
851     std::unordered_map<std::string, std::string> animationStringOptions;
852     JsParseAnimationOptions(CUBIC_CURVE_TEST, iterations, animationDoubleOptions, animationStringOptions);
853 
854     /**
855      * @tc.steps: step2. get the params from the map.
856      */
857     auto easing = animationStringOptions.find(DOM_ANIMATION_EASING)->second;
858 
859     /**
860      * @tc.steps: step3. Judge whether the parameter resolution is successful.
861      * @tc.expected: step3. The value of the params are as expected.
862      */
863     EXPECT_EQ(ANIMATION_EASING_CUBIC, easing);
864 }
865 
866 /**
867  * @tc.name: AnimationDomCurveTest004
868  * @tc.desc: Animation steps parse check
869  * @tc.type: FUNC
870  * @tc.require: AR000DQ1VC
871  * @tc.author: zhouzebin
872  */
873 HWTEST_F(AnimationDomTest, AnimationDomCurveTest004, TestSize.Level1)
874 {
875     /**
876      * @tc.steps: step1. parse the param of steps curve.
877      * @tc.expected: step1. steps curve parsed success.
878      */
879     auto curve = AceType::DynamicCast<StepsCurve>(CreateCurve("steps(2, start)"));
880     EXPECT_EQ(curve->MoveInternal(0.0), 0.5);
881 }
882 
883 } // namespace OHOS::Ace::Framework
884