• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/components/common/layout/constants.h"
19 #include "frameworks/bridge/common/dom/dom_refresh.h"
20 #include "frameworks/bridge/test/unittest/jsfrontend/dom_node_factory.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS::Ace::Framework {
26 namespace {
27 
28 constexpr double LOADING_DISTANCE = 16.0;
29 constexpr double REFRESH_DISTANCE = 64.0;
30 
31 const std::string REFRESH_TEST_001 = ""
32                                      "{                                                          "
33                                      "  \"tag\": \"refresh\"                                     "
34                                      "}";
35 
36 const std::string REFRESH_TEST_002 = ""
37                                      "{                                                          "
38                                      "  \"tag\": \"refresh\",                                    "
39                                      "  \"attr\": [{                                             "
40                                      "                \"offset\" : \"500px\"                     "
41                                      "             }]                                            "
42                                      "}";
43 
44 const std::string REFRESH_TEST_003 = ""
45                                      "{                                                          "
46                                      "  \"tag\": \"refresh\",                                    "
47                                      "  \"attr\": [{                                             "
48                                      "                \"refreshing\" : \"true\"                  "
49                                      "             }]                                            "
50                                      "}";
51 
52 const std::string REFRESH_TEST_004 = ""
53                                      "{                                                          "
54                                      "  \"tag\": \"refresh\",                                    "
55                                      "  \"attr\": [{                                             "
56                                      "                \"lasttime\" : \"true\"                    "
57                                      "             }]                                            "
58                                      "}";
59 
60 const std::string REFRESH_TEST_005 = ""
61                                      "{                                                          "
62                                      "  \"tag\": \"refresh\",                                    "
63                                      "  \"attr\": [{                                             "
64                                      "                \"type\" : \"pulldown\"                    "
65                                      "             }]                                            "
66                                      "}";
67 
68 const std::string REFRESH_TEST_006 = ""
69                                      "{                                                          "
70                                      "  \"tag\": \"refresh\" ,                                   "
71                                      "  \"style\": [{                                            "
72                                      "                \"backgroundColor\" : \"#bbbbbb\"          "
73                                      "             }]                                            "
74                                      "}";
75 
76 const std::string REFRESH_TEST_007 = ""
77                                      "{                                                          "
78                                      "  \"tag\": \"refresh\" ,                                   "
79                                      "  \"style\": [{                                             "
80                                      "                \"progressColor\" : \"#bbbbbb\"            "
81                                      "             }]                                            "
82                                      "}";
83 
84 const std::string REFRESH_TEST_008 = ""
85                                      "{                                                          "
86                                      "  \"tag\": \"refresh\" ,                                   "
87                                      "  \"event\": [                                            "
88                                      "                \"refresh\"            "
89                                      "             ]                                            "
90                                      "}";
91 
92 const std::string REFRESH_TEST_009 = ""
93                                      "{"
94                                      "  \"tag\": \"refresh\" ,"
95                                      "   \"child\":"
96                                      "[{"
97                                      "    \"tag\":\"div\""
98                                      "}]"
99                                      "}";
100 } // namespace
101 
102 class DomRefreshTest : public testing::Test {
103 public:
104     static void SetUpTestCase();
105     static void TearDownTestCase();
106     void SetUp();
107     void TearDown();
108 };
109 
SetUpTestCase()110 void DomRefreshTest::SetUpTestCase() {}
TearDownTestCase()111 void DomRefreshTest::TearDownTestCase() {}
SetUp()112 void DomRefreshTest::SetUp() {}
TearDown()113 void DomRefreshTest::TearDown() {}
114 
115 /**
116  * @tc.name: DomRefreshTest001
117  * @tc.desc: Test refresh node are created as expected.
118  * @tc.type: FUNC
119  * @tc.require: issueI5JQ67
120  */
121 HWTEST_F(DomRefreshTest, DomRefreshTest001, TestSize.Level1)
122 {
123     /**
124      * @tc.steps: step1. Construct string with right fields, then create node with it.
125      * @tc.expected: step1. node are created successfully.
126      */
127     auto refresh = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(REFRESH_TEST_001);
128     ASSERT_TRUE(refresh != nullptr);
129 
130     /**
131      * @tc.steps: step2. Check styles and attributes of created dom node.
132      * @tc.expected: step2. The styles and attributes are as expected.
133      */
134     auto refreshComponent = AceType::DynamicCast<DOMRefresh>(refresh)->GetSpecializedComponent();
135 
136     ASSERT_TRUE(AceType::DynamicCast<RefreshComponent>(refreshComponent)->GetRefreshType() == RefreshType::AUTO);
137     ASSERT_TRUE(AceType::DynamicCast<RefreshComponent>(refreshComponent)->IsRefreshing() == false);
138 }
139 
140 /**
141  * @tc.name: DomRefreshTest002
142  * @tc.desc: Test refresh node are created as expected.
143  * @tc.type: FUNC
144  * @tc.require: issueI5JQ67
145  */
146 HWTEST_F(DomRefreshTest, DomRefreshTest002, TestSize.Level1)
147 {
148     /**
149      * @tc.steps: step1. Construct string with right fields, then create node with it.
150      * @tc.expected: step1. node are created successfully.
151      */
152     auto refresh = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(REFRESH_TEST_002);
153     ASSERT_TRUE(refresh != nullptr);
154 
155     /**
156      * @tc.steps: step2. Check styles and attributes of created dom node.
157      * @tc.expected: step2. The styles and attributes are as expected.
158      */
159     auto refreshComponent = AceType::DynamicCast<DOMRefresh>(refresh)->GetSpecializedComponent();
160 
161     ASSERT_TRUE(AceType::DynamicCast<RefreshComponent>(refreshComponent)->GetIndicatorOffset() ==
162                 Dimension(500.0, DimensionUnit::PX));
163 }
164 
165 /**
166  * @tc.name: DomRefreshTest003
167  * @tc.desc: Test refresh node are created as expected.
168  * @tc.type: FUNC
169  * @tc.require: issueI5JQ67
170  */
171 HWTEST_F(DomRefreshTest, DomRefreshTest003, TestSize.Level1)
172 {
173     /**
174      * @tc.steps: step1. Construct string with right fields, then create node with it.
175      * @tc.expected: step1. node are created successfully.
176      */
177     auto refresh = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(REFRESH_TEST_003);
178     ASSERT_TRUE(refresh != nullptr);
179 
180     /**
181      * @tc.steps: step2. Check styles and attributes of created dom node.
182      * @tc.expected: step2. The styles and attributes are as expected.
183      */
184     auto refreshComponent = AceType::DynamicCast<DOMRefresh>(refresh)->GetSpecializedComponent();
185 
186     ASSERT_TRUE(AceType::DynamicCast<RefreshComponent>(refreshComponent)->IsRefreshing() == true);
187 }
188 
189 /**
190  * @tc.name: DomRefreshTest004
191  * @tc.desc: Test refresh node are created as expected.
192  * @tc.type: FUNC
193  * @tc.require: issueI5JQ2D
194  */
195 HWTEST_F(DomRefreshTest, DomRefreshTest004, TestSize.Level1)
196 {
197     /**
198      * @tc.steps: step1. Construct string with right fields, then create node with it.
199      * @tc.expected: step1. node are created successfully.
200      */
201     auto refresh = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(REFRESH_TEST_004);
202     ASSERT_TRUE(refresh != nullptr);
203 
204     /**
205      * @tc.steps: step2. Check styles and attributes of created dom node.
206      * @tc.expected: step2. The styles and attributes are as expected.
207      */
208     auto refreshComponent = AceType::DynamicCast<DOMRefresh>(refresh)->GetSpecializedComponent();
209     ASSERT_TRUE(AceType::DynamicCast<RefreshComponent>(refreshComponent)->IsShowLastTime() == true);
210 }
211 
212 /**
213  * @tc.name: DomRefreshTest005
214  * @tc.desc: Test refresh node are created as expected.
215  * @tc.type: FUNC
216  * @tc.require: issueI5JQ2D
217  */
218 HWTEST_F(DomRefreshTest, DomRefreshTest005, TestSize.Level1)
219 {
220     /**
221      * @tc.steps: step1. Construct string with right fields, then create node with it.
222      * @tc.expected: step1. node are created successfully.
223      */
224     auto refresh = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(REFRESH_TEST_005);
225     ASSERT_TRUE(refresh != nullptr);
226 
227     /**
228      * @tc.steps: step2. Check styles and attributes of created dom node.
229      * @tc.expected: step2. The styles and attributes are as expected.
230      */
231     auto refreshComponent = AceType::DynamicCast<DOMRefresh>(refresh)->GetSpecializedComponent();
232     ASSERT_TRUE(AceType::DynamicCast<RefreshComponent>(refreshComponent)->GetRefreshType() == RefreshType::PULL_DOWN);
233 }
234 
235 /**
236  * @tc.name: DomRefreshTest006
237  * @tc.desc: Test refresh node are created as expected.
238  * @tc.type: FUNC
239  * @tc.require: issueI5JQ2D
240  */
241 HWTEST_F(DomRefreshTest, DomRefreshTest006, TestSize.Level1)
242 {
243     /**
244      * @tc.steps: step1. Construct string with right fields, then create node with it.
245      * @tc.expected: step1. node are created successfully.
246      */
247     auto refresh = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(REFRESH_TEST_006);
248     ASSERT_TRUE(refresh != nullptr);
249 
250     /**
251      * @tc.steps: step2. Check styles and attributes of created dom node.
252      * @tc.expected: step2. The styles and attributes are as expected.
253      */
254     auto refreshComponent = AceType::DynamicCast<DOMRefresh>(refresh)->GetSpecializedComponent();
255     ASSERT_TRUE(AceType::DynamicCast<RefreshComponent>(refreshComponent)->GetBackgroundColor() == Color(0xffbbbbbb));
256 }
257 
258 /**
259  * @tc.name: DomRefreshTest007
260  * @tc.desc: Test refresh node are created as expected.
261  * @tc.type: FUNC
262  * @tc.require: issueI5JQ2D
263  */
264 HWTEST_F(DomRefreshTest, DomRefreshTest007, TestSize.Level1)
265 {
266     /**
267      * @tc.steps: step1. Construct string with right fields, then create node with it.
268      * @tc.expected: step1. node are created successfully.
269      */
270     auto refresh = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(REFRESH_TEST_007);
271     ASSERT_TRUE(refresh != nullptr);
272 
273     /**
274      * @tc.steps: step2. Check styles and attributes of created dom node.
275      * @tc.expected: step2. The styles and attributes are as expected.
276      */
277     auto refreshComponent = AceType::DynamicCast<DOMRefresh>(refresh)->GetSpecializedComponent();
278     ASSERT_TRUE(AceType::DynamicCast<RefreshComponent>(refreshComponent)->GetProgressColor() == Color(0xffbbbbbb));
279 }
280 
281 /**
282  * @tc.name: DomRefreshTest008
283  * @tc.desc: Test refresh node are created as expected.
284  * @tc.type: FUNC
285  */
286 HWTEST_F(DomRefreshTest, DomRefreshTest008, TestSize.Level1)
287 {
288     /**
289      * @tc.steps: step1. Construct string with right fields, then create node with it.
290      * @tc.expected: step1. node are created successfully.
291      */
292     auto refresh = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(REFRESH_TEST_008);
293     ASSERT_TRUE(refresh != nullptr);
294 
295     /**
296      * @tc.steps: step2. Check styles and attributes of created dom node.
297      * @tc.expected: step2. The styles and attributes are as expected.
298      */
299     auto refreshComponent = AceType::DynamicCast<DOMRefresh>(refresh)->GetSpecializedComponent();
300     EXPECT_EQ(AceType::DynamicCast<RefreshComponent>(refreshComponent)->GetRefreshEventId(),
301         std::to_string(refresh->GetNodeId()));
302 }
303 
304 /**
305  * @tc.name: DomRefreshTest009
306  * @tc.desc: Test refresh node are created as expected.
307  * @tc.type: FUNC
308  */
309 HWTEST_F(DomRefreshTest, DomRefreshTest009, TestSize.Level1)
310 {
311     /**
312      * @tc.steps: step1. Construct string with right fields, then create node with it.
313      * @tc.expected: step1. node are created successfully.
314      */
315     auto refresh = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(REFRESH_TEST_009);
316     ASSERT_TRUE(refresh != nullptr);
317 
318     /**
319      * @tc.steps: step2. Check styles and attributes of created dom node.
320      * @tc.expected: step2. The styles and attributes are as expected.
321      */
322     auto refreshComponent = AceType::DynamicCast<DOMRefresh>(refresh)->GetSpecializedComponent();
323     auto column = AceType::DynamicCast<RefreshComponent>(refreshComponent)->GetChild();
324     ASSERT_TRUE(column != nullptr);
325     ASSERT_EQ(AceType::DynamicCast<ColumnComponent>(column)->GetChildren().size(), 1U);
326 }
327 
328 /**
329  * @tc.name: DomRefreshTest010
330  * @tc.desc: Test refresh node are created as expected.
331  * @tc.type: FUNC
332  */
333 HWTEST_F(DomRefreshTest, DomRefreshTest010, TestSize.Level1)
334 {
335     /**
336      * @tc.steps: step1. Construct string with right fields, then create node with it.
337      * @tc.expected: step1. node are created successfully.
338      */
339     auto refresh = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(REFRESH_TEST_001);
340     ASSERT_TRUE(refresh != nullptr);
341 
342     /**
343      * @tc.steps: step2. Check styles and attributes of created dom node.
344      * @tc.expected: step2. The styles and attributes are as expected.
345      */
346     auto refreshComponent = AceType::DynamicCast<DOMRefresh>(refresh)->GetSpecializedComponent();
347 
348     ASSERT_TRUE(
349         AceType::DynamicCast<RefreshComponent>(refreshComponent)->GetLoadingDistance().Value() == LOADING_DISTANCE);
350     ASSERT_TRUE(
351         AceType::DynamicCast<RefreshComponent>(refreshComponent)->GetRefreshDistance().Value() == REFRESH_DISTANCE);
352 }
353 
354 } // namespace OHOS::Ace::Framework
355