1 /*
2 * Copyright (c) 2023 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 <cstddef>
17 #include <cstdint>
18 #include <unistd.h>
19
20 #include "gtest/gtest.h"
21
22 #define private public
23 #define protected public
24 #include "test/mock/base/mock_task_executor.h"
25 #include "test/mock/core/pipeline/mock_pipeline_context.h"
26 #include "test/mock/core/render/mock_render_context.h"
27
28 #include "core/components_ng/event/state_style_manager.h"
29 #include "core/components_ng/pattern/list/list_pattern.h"
30 #include "core/components_ng/pattern/navrouter/navdestination_pattern.h"
31 #include "core/components_ng/pattern/pattern.h"
32 #include "core/components_ng/pattern/swiper/swiper_pattern.h"
33 #include "core/event/ace_events.h"
34
35 using namespace testing;
36 using namespace testing::ext;
37
38 namespace OHOS::Ace::NG {
39 class StateStyleManagerTestNg : public testing::Test {
40 public:
41 static void SetUpTestSuite();
42 static void TearDownTestSuite();
43 void SetUp() override;
44 void TearDown() override;
45 };
46
SetUpTestSuite()47 void StateStyleManagerTestNg::SetUpTestSuite()
48 {
49 GTEST_LOG_(INFO) << "StateStyleManagerTestNg SetUpTestCase";
50 }
51
TearDownTestSuite()52 void StateStyleManagerTestNg::TearDownTestSuite()
53 {
54 GTEST_LOG_(INFO) << "StateStyleManagerTestNg TearDownTestCase";
55 }
56
SetUp()57 void StateStyleManagerTestNg::SetUp()
58 {
59 MockPipelineContext::SetUp();
60 }
61
TearDown()62 void StateStyleManagerTestNg::TearDown()
63 {
64 MockPipelineContext::TearDown();
65 }
66
67 /**
68 * @tc.name: StateStyleTest001
69 * @tc.desc: Create StateStyleManager and execute pressed listener.
70 * @tc.type: FUNC
71 */
72 HWTEST_F(StateStyleManagerTestNg, StateStyleTest001, TestSize.Level1)
73 {
74 /**
75 * @tc.steps: step1. Create state style manger.
76 * @tc.expected: State style pressed listener is valid.
77 */
78 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
79 EXPECT_NE(frameNode, nullptr);
80 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
81 EXPECT_NE(stateStyleMgr, nullptr);
82 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
83 auto callback = stateStyleMgr->GetPressedListener();
84 EXPECT_NE(callback, nullptr);
85
86 /**
87 * @tc.steps: step2. Create touch down event and execute it.
88 * @tc.expected: Should change to pressed state.
89 */
90
91 TouchEventInfo touchEventInfo = TouchEventInfo("touch");
92 TouchLocationInfo touchLocationInfo = TouchLocationInfo(1);
93 touchLocationInfo.SetLocalLocation(Offset(100.0, 100.0));
94 touchLocationInfo.SetTouchType(TouchType::DOWN);
95 touchEventInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
96 touchEventInfo.AddChangedTouchLocationInfo(std::move(touchLocationInfo));
97
98 (*callback)(touchEventInfo);
99 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
100
101 /**
102 * @tc.steps: step3. Create touch up event and execute it.
103 * @tc.expected: Should cancel pressed state.
104 */
105
106 touchLocationInfo.SetTouchType(TouchType::UP);
107 touchEventInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
108 touchEventInfo.AddChangedTouchLocationInfo(std::move(touchLocationInfo));
109
110 (*callback)(touchEventInfo);
111 EXPECT_EQ(false, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
112 }
113
114 /**
115 * @tc.name: StateStyleTest002
116 * @tc.desc: Create StateStyleManager and execute pressed listener when multi fingers.
117 * @tc.type: FUNC
118 */
119 HWTEST_F(StateStyleManagerTestNg, StateStyleTest002, TestSize.Level1)
120 {
121 /**
122 * @tc.steps: step1. Create state style manger.
123 * @tc.expected: State style pressed listener is valid.
124 */
125 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
126 EXPECT_NE(frameNode, nullptr);
127 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
128 EXPECT_NE(stateStyleMgr, nullptr);
129 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
130 auto callback = stateStyleMgr->GetPressedListener();
131 EXPECT_NE(callback, nullptr);
132
133 /**
134 * @tc.steps: step2. One finger touch down.
135 * @tc.expected: Should change to pressed state.
136 */
137
138 TouchEventInfo touchEventInfo = TouchEventInfo("touch");
139 TouchLocationInfo touchLocationInfo1 = TouchLocationInfo(1);
140 touchLocationInfo1.SetLocalLocation(Offset(100.0, 100.0));
141 touchLocationInfo1.SetTouchType(TouchType::DOWN);
142 touchEventInfo.AddTouchLocationInfo(std::move(touchLocationInfo1));
143 touchEventInfo.AddChangedTouchLocationInfo(std::move(touchLocationInfo1));
144
145 (*callback)(touchEventInfo);
146 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
147
148 /**
149 * @tc.steps: step3. One more finger touch down.
150 * @tc.expected: Should hold on pressed state.
151 */
152
153 TouchLocationInfo touchLocationInfo2 = TouchLocationInfo(2);
154 touchLocationInfo2.SetLocalLocation(Offset(100.0, 100.0));
155 touchLocationInfo2.SetTouchType(TouchType::DOWN);
156 touchEventInfo.AddTouchLocationInfo(std::move(touchLocationInfo2));
157 touchEventInfo.AddChangedTouchLocationInfo(std::move(touchLocationInfo2));
158
159 (*callback)(touchEventInfo);
160 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
161
162 /**
163 * @tc.steps: step4. One finger touch up.
164 * @tc.expected: Should hold on pressed state.
165 */
166
167 touchLocationInfo1.SetTouchType(TouchType::UP);
168 touchEventInfo.AddTouchLocationInfo(std::move(touchLocationInfo1));
169 touchEventInfo.AddChangedTouchLocationInfo(std::move(touchLocationInfo1));
170
171 (*callback)(touchEventInfo);
172 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
173
174 /**
175 * @tc.steps: step5. One more finger touch up.
176 * @tc.expected: Should cancel pressed state.
177 */
178
179 touchLocationInfo2.SetTouchType(TouchType::UP);
180 touchEventInfo.AddTouchLocationInfo(std::move(touchLocationInfo2));
181 touchEventInfo.AddChangedTouchLocationInfo(std::move(touchLocationInfo2));
182
183 (*callback)(touchEventInfo);
184 EXPECT_EQ(false, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
185 }
186
187 /**
188 * @tc.name: StateStyleTest003
189 * @tc.desc: Create StateStyleManager and execute its functions.
190 * @tc.type: FUNC
191 */
192 HWTEST_F(StateStyleManagerTestNg, StateStyleTest003, TestSize.Level1)
193 {
194 /**
195 * @tc.steps: step1. Create state style manger.
196 * @tc.expected: Should have no scrolling parent.
197 */
198 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
199 EXPECT_NE(frameNode, nullptr);
200 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
201 EXPECT_NE(stateStyleMgr, nullptr);
202 stateStyleMgr->HandleScrollingParent();
203 bool hasScrollingParent = stateStyleMgr->GetHasScrollingParent();
204 EXPECT_EQ(false, hasScrollingParent);
205
206 /**
207 * @tc.steps: step2. Set parent to current frame node.
208 * @tc.expected: Should have scrolling parent.
209 */
210
211 auto parent = AceType::MakeRefPtr<FrameNode>(V2::LIST_ETS_TAG, -1, AceType::MakeRefPtr<ListPattern>());
212 EXPECT_NE(parent, nullptr);
213 frameNode->SetParent(parent);
214 stateStyleMgr->HandleScrollingParent();
215 hasScrollingParent = stateStyleMgr->GetHasScrollingParent();
216 EXPECT_EQ(true, hasScrollingParent);
217 }
218
219 /**
220 * @tc.name: StateStyleTest004
221 * @tc.desc: Create StateStyleManager and execute its functions.
222 * @tc.type: FUNC
223 */
224 HWTEST_F(StateStyleManagerTestNg, StateStyleTest004, TestSize.Level1)
225 {
226 /**
227 * @tc.steps: step1. Create state style manger.
228 * @tc.expected: State style pressed listener is valid.
229 */
230 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
231 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
232 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
233 auto callback = stateStyleMgr->GetPressedListener();
234 EXPECT_NE(callback, nullptr);
235 auto callback2 = stateStyleMgr->GetPressedListener();
236 EXPECT_EQ(callback, callback2);
237
238 /**
239 * @tc.steps: step2. Create condition that touches.empty() changeTouches.empty()
240 * @tc.expected: State style pressed listener is valid.
241 */
242 EXPECT_EQ(false, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
243 TouchEventInfo touchEventInfo = TouchEventInfo("touch");
244 (*callback)(touchEventInfo);
245 EXPECT_EQ(false, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
246
247 /**
248 * @tc.steps: step3. Create condition that touches.empty()=false changeTouches.empty true
249 * @tc.expected: State style pressed listener is valid.
250 */
251 TouchLocationInfo touchLocationInfo = TouchLocationInfo(1);
252 touchLocationInfo.SetLocalLocation(Offset(100.0, 100.0));
253 touchLocationInfo.SetTouchType(TouchType::CANCEL);
254 touchEventInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
255 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
256 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
257 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
258 (*callback)(touchEventInfo);
259 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
260
261 /**
262 * @tc.steps: step3. Create condition that touches.empty false changeTouches.empty false
263 * @tc.expected: State style pressed listener is valid.
264 */
265 touchEventInfo.AddChangedTouchLocationInfo(std::move(touchLocationInfo));
266 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
267 (*callback)(touchEventInfo);
268 EXPECT_EQ(false, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
269 }
270
271 /**
272 * @tc.name: StateStyleTest005
273 * @tc.desc: Create StateStyleManager and execute its functions.
274 * @tc.type: FUNC
275 */
276 HWTEST_F(StateStyleManagerTestNg, StateStyleTest005, TestSize.Level1)
277 {
278 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
279 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
280 auto callback = stateStyleMgr->GetPressedListener();
281 EXPECT_NE(callback, nullptr);
282 auto callback2 = stateStyleMgr->GetPressedListener();
283 EXPECT_EQ(callback, callback2);
284
285 TouchEventInfo touchEventInfo = TouchEventInfo("touch");
286 TouchLocationInfo touchLocationInfo = TouchLocationInfo(1);
287 touchLocationInfo.SetLocalLocation(Offset(-100.0, -100.0));
288 touchLocationInfo.SetTouchType(TouchType::MOVE);
289 touchEventInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
290 touchEventInfo.AddChangedTouchLocationInfo(std::move(touchLocationInfo));
291 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
292 stateStyleMgr->ResetPressedPendingState();
293 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
294 (*callback)(touchEventInfo);
295 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
296
297 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, false);
298 stateStyleMgr->ResetPressedPendingState();
299 (*callback)(touchEventInfo);
300 EXPECT_EQ(false, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
301 }
302
303 /**
304 * @tc.name: StateStyleTest006
305 * @tc.desc: Test HandleTouchDown function.
306 * @tc.type: FUNC
307 */
308 HWTEST_F(StateStyleManagerTestNg, StateStyleTest006, TestSize.Level1)
309 {
310 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
311 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
312 stateStyleMgr->SetSupportedStates(UI_STATE_NORMAL);
313 stateStyleMgr->HandleTouchDown();
314 EXPECT_EQ(false, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
315
316 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
317 stateStyleMgr->HandleTouchDown();
318 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
319
320 auto parent = AceType::MakeRefPtr<FrameNode>(V2::LIST_ETS_TAG, -1, AceType::MakeRefPtr<ListPattern>());
321 EXPECT_NE(parent, nullptr);
322 frameNode->SetParent(parent);
323 stateStyleMgr->PendingCancelPressedState();
324 EXPECT_EQ(true, stateStyleMgr->IsPressedCancelStatePending());
325 stateStyleMgr->HandleTouchDown();
326 EXPECT_EQ(false, stateStyleMgr->IsPressedCancelStatePending());
327 EXPECT_EQ(true, stateStyleMgr->IsPressedStatePending());
328
329 stateStyleMgr->ResetPressedCancelPendingState();
330 stateStyleMgr->HandleTouchDown();
331 EXPECT_EQ(false, stateStyleMgr->IsPressedCancelStatePending());
332 EXPECT_EQ(true, stateStyleMgr->IsPressedStatePending());
333 }
334
335 /**
336 * @tc.name: StateStyleTest007
337 * @tc.desc: Test HandleTouchUp function.
338 * @tc.type: FUNC
339 */
340 HWTEST_F(StateStyleManagerTestNg, StateStyleTest007, TestSize.Level1)
341 {
342 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
343 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
344 auto parent = AceType::MakeRefPtr<FrameNode>(V2::LIST_ETS_TAG, -1, AceType::MakeRefPtr<ListPattern>());
345 EXPECT_NE(parent, nullptr);
346 frameNode->SetParent(parent);
347
348 stateStyleMgr->PendingPressedState();
349 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
350 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
351 stateStyleMgr->HandleTouchUp();
352 EXPECT_EQ(false, stateStyleMgr->IsPressedStatePending());
353 EXPECT_EQ(true, stateStyleMgr->IsPressedCancelStatePending());
354 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
355
356 stateStyleMgr->ResetPressedPendingState();
357 stateStyleMgr->ResetPressedCancelPendingState();
358 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
359 stateStyleMgr->HandleTouchUp();
360 EXPECT_EQ(false, stateStyleMgr->IsPressedStatePending());
361 EXPECT_EQ(false, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
362
363 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
364 stateStyleMgr->PendingCancelPressedState();
365 stateStyleMgr->HandleTouchUp();
366 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
367 }
368
369 /**
370 * @tc.name: StateStyleTest008
371 * @tc.desc: Test PostPressStyleTask function.
372 * @tc.type: FUNC
373 */
374 HWTEST_F(StateStyleManagerTestNg, StateStyleTest008, TestSize.Level1)
375 {
376 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
377 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
378 stateStyleMgr->PendingPressedState();
379 EXPECT_EQ(true, stateStyleMgr->IsPressedStatePending());
380 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
381 auto context = PipelineContext::GetCurrentContext();
382 ASSERT_NE(context, nullptr);
383 context->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
384 auto taskExecutor = context->GetTaskExecutor();
385 ASSERT_NE(taskExecutor, nullptr);
386 stateStyleMgr->PostPressStyleTask(1);
387 EXPECT_EQ(false, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
388
389 stateStyleMgr->ResetPressedPendingState();
390 stateStyleMgr->ResetPressedCancelPendingState();
391 EXPECT_EQ(false, stateStyleMgr->IsPressedStatePending());
392 stateStyleMgr->PostPressStyleTask(1);
393 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
394 }
395
396 /**
397 * @tc.name: StateStyleTest009
398 * @tc.desc: Test PostPressCancelStyleTask function.
399 * @tc.type: FUNC
400 */
401 HWTEST_F(StateStyleManagerTestNg, StateStyleTest009, TestSize.Level1)
402 {
403 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
404 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
405 auto context = PipelineContext::GetCurrentContext();
406 ASSERT_NE(context, nullptr);
407 context->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
408 auto taskExecutor = context->GetTaskExecutor();
409 ASSERT_NE(taskExecutor, nullptr);
410
411 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
412 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
413
414 stateStyleMgr->PendingPressedState();
415 stateStyleMgr->PendingCancelPressedState();
416 stateStyleMgr->PostPressCancelStyleTask(1);
417 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
418
419 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
420 stateStyleMgr->ResetPressedPendingState();
421 stateStyleMgr->PendingCancelPressedState();
422 stateStyleMgr->PostPressCancelStyleTask(1);
423 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
424
425 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
426 stateStyleMgr->PendingPressedState();
427 stateStyleMgr->ResetPressedCancelPendingState();
428 stateStyleMgr->PostPressCancelStyleTask(1);
429 EXPECT_EQ(true, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
430
431 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
432 stateStyleMgr->ResetPressedPendingState();
433 stateStyleMgr->ResetPressedCancelPendingState();
434 stateStyleMgr->PostPressCancelStyleTask(1);
435 EXPECT_EQ(false, stateStyleMgr->IsCurrentStateOn(UI_STATE_PRESSED));
436 }
437
438 /**
439 * @tc.name: StateStyleTest010
440 * @tc.desc: Test HandleTouchUp function.
441 * @tc.type: FUNC
442 */
443 HWTEST_F(StateStyleManagerTestNg, StateStyleTest010, TestSize.Level1)
444 {
445 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
446 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
447 auto parent = AceType::MakeRefPtr<FrameNode>(V2::LIST_ETS_TAG, -1, AceType::MakeRefPtr<ListPattern>());
448 frameNode->SetParent(parent);
449
450 stateStyleMgr->PendingPressedState();
451 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
452 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
453 stateStyleMgr->hasScrollingParent_ = true;
454 stateStyleMgr->HandleTouchUp();
455 EXPECT_NE(parent, nullptr);
456 }
457
458 /**
459 * @tc.name: StateStyleTest011
460 * @tc.desc: Test CleanScrollingParentListener function.
461 * @tc.type: FUNC
462 */
463 HWTEST_F(StateStyleManagerTestNg, StateStyleTest011, TestSize.Level1)
464 {
465 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
466 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
467 auto parent = AceType::MakeRefPtr<FrameNode>(V2::LIST_ETS_TAG, -1, AceType::MakeRefPtr<ListPattern>());
468 frameNode->SetParent(parent);
469
470 stateStyleMgr->PendingPressedState();
471 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
472 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
473 stateStyleMgr->CleanScrollingParentListener();
474 EXPECT_NE(parent, nullptr);
475 }
476
477 /**
478 * @tc.name: StateStyleTest012
479 * @tc.desc: Test CleanScrollingParentListener function.
480 * @tc.type: FUNC
481 */
482 HWTEST_F(StateStyleManagerTestNg, StateStyleTest012, TestSize.Level1)
483 {
484 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
485 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
486
487 stateStyleMgr->PendingPressedState();
488 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
489 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
490 stateStyleMgr->CleanScrollingParentListener();
491 EXPECT_NE(frameNode, nullptr);
492 }
493
494 /**
495 * @tc.name: StateStyleTest013
496 * @tc.desc: Test CleanScrollingParentListener function.
497 * @tc.type: FUNC
498 */
499 HWTEST_F(StateStyleManagerTestNg, StateStyleTest013, TestSize.Level1)
500 {
501 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
502 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
503 auto pagePattern = AceType::MakeRefPtr<Pattern>();
504 auto pageNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, -1, pagePattern);
505 frameNode->SetParent(pageNode);
506
507 stateStyleMgr->PendingPressedState();
508 stateStyleMgr->SetSupportedStates(UI_STATE_PRESSED);
509 stateStyleMgr->SetCurrentUIState(UI_STATE_PRESSED, true);
510 stateStyleMgr->CleanScrollingParentListener();
511 EXPECT_NE(pageNode, nullptr);
512 }
513
514 /**
515 * @tc.name: StateStyleTest014
516 * @tc.desc: Test Transform function.
517 * @tc.type: FUNC
518 */
519 HWTEST_F(StateStyleManagerTestNg, StateStyleTest014, TestSize.Level1)
520 {
521 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
522 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
523 PointF current = { 1.1f, 1.0f };
524 RefPtr<FrameNode> node;
525 stateStyleMgr->Transform(current, node);
526 EXPECT_NE(frameNode, nullptr);
527 }
528
529 /**
530 * @tc.name: StateStyleTest016
531 * @tc.desc: test FireStateFunc
532 * @tc.type: FUNC
533 */
534 HWTEST_F(StateStyleManagerTestNg, StateStyleTest016, TestSize.Level1)
535 {
536 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
537 RefPtr<CustomNode> customNode =
538 CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), "test");
539 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
540 bool hasScrollingParent = true;
541 auto swiperPattern = AceType::MakeRefPtr<SwiperPattern>();
542 customNode->AddChild(frameNode);
543 stateStyleMgr->FireStateFunc(hasScrollingParent);
544 EXPECT_EQ(true, hasScrollingParent);
545 }
546
547 /**
548 * @tc.name: StateStyleTest017
549 * @tc.desc: test FireStateFunc
550 * @tc.type: FUNC
551 */
552 HWTEST_F(StateStyleManagerTestNg, StateStyleTest017, TestSize.Level1)
553 {
554 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
555 auto contentNode = NavDestinationGroupNode::GetOrCreateGroupNode(
__anon842df57d0102() 556 V2::NAVDESTINATION_VIEW_ETS_TAG, 22, []() { return AceType::MakeRefPtr<NavDestinationPattern>(); });
557 RefPtr<CustomNode> customNode =
558 CustomNode::CreateCustomNode(ElementRegister::GetInstance()->MakeUniqueId(), "test");
559 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
560 bool hasScrollingParent = true;
561 auto popupBasePattern = AceType::MakeRefPtr<PopupBasePattern>();
562 contentNode->pattern_ = popupBasePattern;
563 customNode->SetParent(contentNode);
564 frameNode->SetParent(contentNode);
565 stateStyleMgr->FireStateFunc(hasScrollingParent);
566 EXPECT_EQ(true, hasScrollingParent);
567 }
568
569 /**
570 * @tc.name: StateStyleTest018
571 * @tc.desc: test IsOutOfPressedRegion
572 * @tc.type: FUNC
573 */
574 HWTEST_F(StateStyleManagerTestNg, StateStyleTest021, TestSize.Level1)
575 {
576 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
577 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
578
579 int32_t sourceType = 1;
580 Offset location = {1, 1};
581 bool ret = stateStyleMgr->IsOutOfPressedRegion(sourceType, location);
582 EXPECT_TRUE(ret);
583
584 auto renderContext = AceType::MakeRefPtr<MockRenderContext>();
585 renderContext->rect_ = RectF(0, 0, 10, 10);
586 renderContext->paintRect_ = RectF(0, 0, 10, 10);
587 stateStyleMgr->GetFrameNode()->renderContext_ = renderContext;
588 ret = stateStyleMgr->IsOutOfPressedRegion(sourceType, location);
589 EXPECT_FALSE(ret);
590
591 auto testFrameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, 0, AceType::MakeRefPtr<Pattern>());
592 testFrameNode->renderContext_ = renderContext;
593 stateStyleMgr->GetFrameNode()->SetParent(testFrameNode);
594 ret = stateStyleMgr->IsOutOfPressedRegion(sourceType, location);
595 EXPECT_FALSE(ret);
596 }
597
598 /**
599 * @tc.name: StateStyleTest019
600 * @tc.desc: test IsOutOfPressedRegion
601 * @tc.type: FUNC
602 */
603 HWTEST_F(StateStyleManagerTestNg, StateStyleTest022, TestSize.Level1)
604 {
605 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
606 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
607
608 int32_t sourceType = 1;
609 Offset location = { 1, 1 };
610 bool ret = stateStyleMgr->IsOutOfPressedRegion(sourceType, location);
611 EXPECT_TRUE(ret);
612
613 auto renderContext = AceType::MakeRefPtr<MockRenderContext>();
614 renderContext->rect_ = RectF(0, 0, 10, 10);
615 renderContext->paintRect_ = RectF(0, 0, 10, 10);
616 stateStyleMgr->GetFrameNode()->renderContext_ = renderContext;
617
618 auto testFrameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, 0, AceType::MakeRefPtr<Pattern>());
619 testFrameNode->renderContext_ = nullptr;
620 stateStyleMgr->GetFrameNode()->SetParent(testFrameNode);
621 ret = stateStyleMgr->IsOutOfPressedRegion(sourceType, location);
622 EXPECT_FALSE(ret);
623 }
624
625 /**
626 * @tc.name: StateStyleTest020
627 * @tc.desc: test Transform
628 * @tc.type: FUNC
629 */
630 HWTEST_F(StateStyleManagerTestNg, StateStyleTest023, TestSize.Level1)
631 {
632 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::BUTTON_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
633 auto stateStyleMgr = AceType::MakeRefPtr<StateStyleManager>(frameNode);
634 PointF localPointF = { 0, 0 };
635 RefPtr<FrameNode> node = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
636 WeakPtr<FrameNode> weakNode = AceType::WeakClaim(AceType::RawPtr(node));
637 stateStyleMgr->Transform(localPointF, weakNode);
638 EXPECT_EQ(localPointF.GetX(), 0);
639 EXPECT_EQ(localPointF.GetY(), 0);
640 }
641 } // namespace OHOS::Ace::NG
642