1 /*
2 * Copyright (c) 2022-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 "test/unittest/core/pipeline/pipeline_context_test_ng.h"
17 // Add the following two macro definitions to test the private and protected method.
18 #define private public
19 #define protected public
20 #include "test/mock/base/mock_mouse_style.h"
21 #include "test/mock/base/mock_task_executor.h"
22 #include "test/mock/core/common/mock_container.h"
23 #include "test/mock/core/common/mock_theme_manager.h"
24 #include "test/mock/core/common/mock_window.h"
25 #include "test/mock/core/pattern/mock_pattern.h"
26
27 #include "base/log/dump_log.h"
28 #include "core/components_ng/pattern/button/button_event_hub.h"
29 #include "core/components_ng/pattern/container_modal/container_modal_pattern.h"
30 #include "core/components_ng/pattern/container_modal/container_modal_theme.h"
31 #include "core/components_ng/pattern/text_field/text_field_manager.h"
32
33 using namespace testing;
34 using namespace testing::ext;
35
36 namespace OHOS::Ace {
37 namespace NG {
38 ElementIdType PipelineContextTestNg::frameNodeId_ = 0;
39 ElementIdType PipelineContextTestNg::customNodeId_ = 0;
40 RefPtr<FrameNode> PipelineContextTestNg::frameNode_ = nullptr;
41 RefPtr<CustomNode> PipelineContextTestNg::customNode_ = nullptr;
42 RefPtr<PipelineContext> PipelineContextTestNg::context_ = nullptr;
43
44 constexpr uint64_t LAST_VSYNC_TIME = 1000;
45
ResetEventFlag(int32_t testFlag)46 void PipelineContextTestNg::ResetEventFlag(int32_t testFlag)
47 {
48 auto flag = context_->eventManager_->GetInstanceId();
49 context_->eventManager_->SetInstanceId(flag & (~testFlag));
50 }
51
GetEventFlag(int32_t testFlag)52 bool PipelineContextTestNg::GetEventFlag(int32_t testFlag)
53 {
54 auto flag = context_->eventManager_->GetInstanceId();
55 return flag & testFlag;
56 }
57
SetUpTestSuite()58 void PipelineContextTestNg::SetUpTestSuite()
59 {
60 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
61 customNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
62 frameNode_ = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
63 // AddUINode is called in the function.
64 customNode_ = CustomNode::CreateCustomNode(customNodeId_, TEST_TAG);
65 ElementRegister::GetInstance()->AddUINode(frameNode_);
66 auto window = std::make_shared<MockWindow>();
67 EXPECT_CALL(*window, RequestFrame()).Times(AnyNumber());
68 EXPECT_CALL(*window, FlushTasks(testing::_)).Times(AnyNumber());
69 EXPECT_CALL(*window, OnHide()).Times(AnyNumber());
70 EXPECT_CALL(*window, RecordFrameTime(_, _)).Times(AnyNumber());
71 EXPECT_CALL(*window, OnShow()).Times(AnyNumber());
72 EXPECT_CALL(*window, FlushAnimation(NANO_TIME_STAMP))
73 .Times(AtLeast(1))
74 .WillOnce(testing::Return(true))
75 .WillRepeatedly(testing::Return(false));
76 EXPECT_CALL(*window, FlushModifier()).Times(AtLeast(1));
77 EXPECT_CALL(*window, SetRootFrameNode(_)).Times(AnyNumber());
78 context_ = AceType::MakeRefPtr<PipelineContext>(
79 window, AceType::MakeRefPtr<MockTaskExecutor>(), nullptr, nullptr, DEFAULT_INSTANCE_ID);
80 context_->SetEventManager(AceType::MakeRefPtr<EventManager>());
81 context_->fontManager_ = FontManager::Create();
82 MockContainer::SetUp();
83 MockContainer::Current()->pipelineContext_ = context_;
84
85 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
86 context_->SetThemeManager(themeManager);
87 auto themeConstants = AceType::MakeRefPtr<ThemeConstants>(nullptr);
88 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<ContainerModalTheme>()));
89 EXPECT_CALL(*themeManager, GetThemeConstants()).WillRepeatedly(Return(themeConstants));
90 }
91
TearDownTestSuite()92 void PipelineContextTestNg::TearDownTestSuite()
93 {
94 context_->Destroy();
95 context_->window_.reset();
96 MockContainer::TearDown();
97 }
98
CreateCycleDirtyNode(int cycle,bool & flagUpdate)99 void PipelineContextTestNg::CreateCycleDirtyNode(int cycle, bool& flagUpdate)
100 {
101 if (cycle <= 0) {
102 return;
103 }
104 cycle -= 1;
105 auto customNodeTemp = CustomNode::CreateCustomNode(customNodeId_ + cycle + 100, TEST_TAG);
106 customNodeTemp->SetUpdateFunction([cycle, &flagUpdate]() {
107 PipelineContextTestNg::CreateCycleDirtyNode(cycle, flagUpdate);
108 flagUpdate = !flagUpdate;
109 });
110 context_->AddDirtyCustomNode(customNodeTemp);
111 }
112
113 /**
114 * @tc.name: PipelineContextTestNg001
115 * @tc.desc: Test the function FlushDirtyNodeUpdate.
116 * @tc.type: FUNC
117 */
118 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg001, TestSize.Level1)
119 {
120 /**
121 * @tc.steps1: initialize parameters.
122 * @tc.expected: All pointer is non-null.
123 */
124 ASSERT_NE(context_, nullptr);
125 bool flagUpdate = false;
__anona28bbc620202() 126 customNode_->SetUpdateFunction([&flagUpdate]() { flagUpdate = true; });
127 context_->AddDirtyCustomNode(customNode_);
128
129 /**
130 * @tc.steps2: Call the function FlushDirtyNodeUpdate.
131 * @tc.expected: The flagUpdate is changed to true.
132 */
133 context_->FlushDirtyNodeUpdate();
134 EXPECT_TRUE(flagUpdate);
135
136 /**
137 * @tc.steps2: Call the function FlushDirtyNodeUpdate.
138 * @tc.expected: The flagUpdate is true.
139 * @tc.expected: The dirtyNodes is not empty.
140 */
141 auto customNode_1 = CustomNode::CreateCustomNode(customNodeId_ + 20, TEST_TAG);
__anona28bbc620302() 142 customNode_1->SetUpdateFunction([&flagUpdate]() { CreateCycleDirtyNode(5, flagUpdate); });
143 context_->AddDirtyCustomNode(customNode_1);
144 context_->AddDirtyCustomNode(frameNode_);
145 context_->FlushDirtyNodeUpdate();
146 EXPECT_TRUE(flagUpdate);
147 EXPECT_FALSE(context_->dirtyNodes_.empty());
148 context_->dirtyNodes_.clear();
149 }
150
151 /**
152 * @tc.name: PipelineContextTestNg002
153 * @tc.desc: Test the function FlushVsync, AddVisibleAreaChangeNode, HandleVisibleAreaChangeEvent and .
154 * @tc.type: FUNC
155 */
156 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg002, TestSize.Level1)
157 {
158 /**
159 * @tc.steps1: initialize parameters.
160 * @tc.expected: All pointer is non-null.
161 */
162 ASSERT_NE(context_, nullptr);
163 context_->SetupRootElement();
164
165 /**
166 * @tc.steps2: Call the function AddOnAreaChangeNode.
167 */
168 context_->onVisibleAreaChangeNodeIds_.clear();
169 context_->AddOnAreaChangeNode(frameNode_->GetId());
170 context_->AddOnAreaChangeNode(customNode_->GetId());
171 context_->AddOnAreaChangeNode(ElementRegister::UndefinedElementId);
172
173 /**
174 * @tc.steps3: Call the function AddVisibleAreaChangeNode.
175 * @tc.expected: The drawDelegate_ is null.
176 */
177 context_->onAreaChangeNodeIds_.clear();
178 context_->onAreaChangeNodeIds_.emplace(NOT_REGISTER_ID);
179 context_->onAreaChangeNodeIds_.emplace(customNode_->nodeId_);
180 context_->AddVisibleAreaChangeNode(frameNode_, { DEFAULT_DOUBLE1 }, nullptr);
181 context_->AddVisibleAreaChangeNode(frameNode_, { DEFAULT_DOUBLE1 }, nullptr, false);
182 EXPECT_EQ(context_->onVisibleAreaChangeNodeIds_.size(), DEFAULT_SIZE1);
183 context_->onVisibleAreaChangeNodeIds_.emplace(customNode_->GetId());
184 context_->onVisibleAreaChangeNodeIds_.emplace(ElementRegister::UndefinedElementId);
185 EXPECT_EQ(context_->onVisibleAreaChangeNodeIds_.size(), DEFAULT_SIZE3);
186
187 /**
188 * @tc.steps4: Call the function FlushVsync with isEtsCard=false.
189 * @tc.expected: The drawDelegate_ is null.
190 */
191 context_->onShow_ = false;
192 context_->SetIsFormRender(false);
193 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
194 EXPECT_EQ(context_->drawDelegate_, nullptr);
195
196 /**
197 * @tc.steps5: Call the function FlushVsync with isEtsCard=false.
198 * @tc.expected: The drawDelegate_ is non-null.
199 */
200 context_->onFocus_ = false;
201 context_->onAreaChangeNodeIds_.clear();
202 context_->SetDrawDelegate(std::make_unique<DrawDelegate>());
203 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
204 EXPECT_NE(context_->drawDelegate_, nullptr);
205 /**
206 * @tc.steps6: Call the function FlushVsync with isEtsCard=false
207 and processName equals to "".
208 * @tc.expected: The drawDelegate_ is non-null.
209 */
210 AceApplicationInfo::GetInstance().processName_ = "";
211 context_->onShow_ = true;
212 context_->onFocus_ = true;
213 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
214 EXPECT_NE(context_->drawDelegate_, nullptr);
215 }
216
217 /**
218 * @tc.name: PipelineContextTestNg003
219 * @tc.desc: Test the function FlushVsync and functions FlushLayoutTask and FlushRenderTask of the UITaskScheduler.
220 * @tc.type: FUNC
221 */
222 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg003, TestSize.Level1)
223 {
224 /**
225 * @tc.steps1: initialize parameters.
226 * @tc.expected: All pointer is non-null.
227 */
228 ASSERT_NE(context_, nullptr);
229 context_->SetupRootElement();
230
231 /**
232 * @tc.steps2: Add dirty layout and render nodes to taskScheduler_ to test functions
233 * FlushLayoutTask and FlushRenderTask of the UITaskScheduler.
234 */
235 context_->taskScheduler_->AddDirtyLayoutNode(frameNode_);
236 context_->taskScheduler_->AddDirtyRenderNode(frameNode_);
237 context_->taskScheduler_->dirtyRenderNodes_[frameNode_->GetPageId()].emplace(nullptr);
238
239 /**
240 * @tc.steps3: Call the function FlushVsync with isEtsCard=true.
241 * @tc.expected: The drawDelegate_ is null.
242 */
243 context_->onShow_ = true;
244 context_->onFocus_ = false;
245 context_->SetIsFormRender(true);
246 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
247 EXPECT_EQ(context_->drawDelegate_, nullptr);
248
249 /**
250 * @tc.steps4: Call the function FlushVsync with isEtsCard=true.
251 * @tc.expected: The drawDelegate_ is non-null.
252 */
253 context_->onFocus_ = true;
254 context_->SetDrawDelegate(std::make_unique<DrawDelegate>());
255 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
256 EXPECT_EQ(context_->drawDelegate_, nullptr);
257 }
258
259 /**
260 * @tc.name: PipelineContextTestNg004
261 * @tc.desc: Test the function FlushAnimation.
262 * @tc.type: FUNC
263 */
264 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg004, TestSize.Level1)
265 {
266 /**
267 * @tc.steps1: initialize parameters.
268 * @tc.expected: All pointer is non-null.
269 */
270 ASSERT_NE(context_, nullptr);
271
272 /**
273 * @tc.steps2: Call the function FlushAnimation with empty scheduleTasks_.
274 * @tc.expected: The scheduleTasks_ is null.
275 */
276 context_->FlushAnimation(NANO_TIME_STAMP);
277 EXPECT_TRUE(context_->scheduleTasks_.empty());
278
279 /**
280 * @tc.steps3: Call the function FlushAnimation with unempty scheduleTasks_.
281 * @tc.expected: The nanoTimestamp of scheduleTask is equal to NANO_TIME_STAMP.
282 */
283 auto scheduleTask = AceType::MakeRefPtr<MockScheduleTask>();
284 EXPECT_NE(scheduleTask->GetNanoTimestamp(), NANO_TIME_STAMP);
285 context_->AddScheduleTask(scheduleTask);
286 context_->AddScheduleTask(nullptr);
287 context_->FlushAnimation(NANO_TIME_STAMP);
288 EXPECT_EQ(scheduleTask->GetNanoTimestamp(), DEFAULT_INT0);
289 }
290
291 /**
292 * @tc.name: PipelineContextTestNg005
293 * @tc.desc: Test the function FlushFocus.
294 * @tc.type: FUNC
295 */
296 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg005, TestSize.Level1)
297 {
298 /**
299 * @tc.steps1: initialize parameters.
300 * @tc.expected: All pointer is non-null.
301 */
302 ASSERT_NE(context_, nullptr);
303 context_->SetupRootElement();
304
305 /**
306 * @tc.steps2: Call the function FlushFocus.
307 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
308 */
309 context_->FlushFocus();
310 EXPECT_EQ(context_->dirtyFocusNode_.Upgrade(), nullptr);
311 /**
312 * @tc.steps2: Init a frameNode and SetFocusType with Node, Add dirty focus and call FlushFocus
313 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
314 */
315 auto eventHub = frameNode_->GetOrCreateEventHub<EventHub>();
316 ASSERT_NE(eventHub, nullptr);
317 auto focusHub = eventHub->GetOrCreateFocusHub();
318 ASSERT_NE(focusHub, nullptr);
319 focusHub->SetFocusType(FocusType::NODE);
320 context_->AddDirtyFocus(frameNode_);
321 auto dirtyFocusNode = context_->dirtyFocusNode_.Upgrade();
322 ASSERT_NE(dirtyFocusNode, nullptr);
323 EXPECT_EQ(dirtyFocusNode->GetFocusType(), FocusType::NODE);
324 context_->FlushFocus();
325 EXPECT_EQ(context_->dirtyFocusNode_.Upgrade(), nullptr);
326 /**
327 * @tc.steps3: Init a new frameNode and SetFocusType with Node.
328 Add dirty focus, free focusHub_ and call FlushFocus
329 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
330 */
331 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
332 frameNode_ = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
333 eventHub = frameNode_->GetOrCreateEventHub<EventHub>();
334 ASSERT_NE(eventHub, nullptr);
335 focusHub = eventHub->GetOrCreateFocusHub();
336 ASSERT_NE(focusHub, nullptr);
337 focusHub->SetFocusType(FocusType::NODE);
338 context_->AddDirtyFocus(frameNode_);
339 dirtyFocusNode = context_->dirtyFocusNode_.Upgrade();
340 ASSERT_NE(dirtyFocusNode, nullptr);
341 EXPECT_EQ(dirtyFocusNode->GetFocusType(), FocusType::NODE);
342 frameNode_->focusHub_ = nullptr;
343 context_->FlushFocus();
344 EXPECT_EQ(context_->dirtyFocusNode_.Upgrade(), nullptr);
345 }
346
347 /**
348 * @tc.name: PipelineContextTestNg006
349 * @tc.desc: Test the function FlushBuildFinishCallbacks.
350 * @tc.type: FUNC
351 */
352 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg006, TestSize.Level1)
353 {
354 /**
355 * @tc.steps1: initialize parameters.
356 * @tc.expected: All pointer is non-null.
357 */
358 ASSERT_NE(context_, nullptr);
359 bool flagCbk = false;
360 context_->AddBuildFinishCallBack(nullptr);
__anona28bbc620402() 361 context_->AddBuildFinishCallBack([&flagCbk]() { flagCbk = true; });
362
363 /**
364 * @tc.steps2: Call the function FlushBuildFinishCallbacks.
365 * @tc.expected: The flagCbk is changed to true.
366 */
367 context_->FlushBuildFinishCallbacks();
368 EXPECT_TRUE(flagCbk);
369 }
370
371 /**
372 * @tc.name: PipelineContextTestNg007
373 * @tc.desc: Test the function SetupRootElement.
374 * @tc.type: FUNC
375 */
376 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg007, TestSize.Level1)
377 {
378 /**
379 * @tc.steps1: initialize parameters.
380 * @tc.expected: All pointer is non-null.
381 */
382 ASSERT_NE(context_, nullptr);
383 context_->windowManager_ = AceType::MakeRefPtr<WindowManager>();
384 /**
385 * @tc.steps2: Call the function SetupRootElement with isJsCard_ = true.
386 * @tc.expected: The stageManager_ is non-null.
387 */
388 context_->SetIsJsCard(true);
389 context_->windowModal_ = WindowModal::NORMAL;
390 context_->GetContainerModalNode();
391 context_->SetupRootElement();
392 EXPECT_NE(context_->stageManager_, nullptr);
393
394 /**
395 * @tc.steps3: Call the function SetupRootElement with isJsCard_ = false.
396 * @tc.expected: The stageManager_ is non-null.
397 */
398 context_->SetIsJsCard(false);
399 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
400 context_->GetContainerModalNode();
401 context_->SetupRootElement();
402 EXPECT_NE(context_->stageManager_, nullptr);
403 }
404
405 /**
406 * @tc.name: PipelineContextTestNg008
407 * @tc.desc: Test the function SetupSubRootElement.
408 * @tc.type: FUNC
409 */
410 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg008, TestSize.Level1)
411 {
412 /**
413 * @tc.steps1: initialize parameters.
414 * @tc.expected: All pointer is non-null.
415 */
416 ASSERT_NE(context_, nullptr);
417
418 /**
419 * @tc.steps2: Call the function SetupSubRootElement with isJsCard_ = true.
420 * @tc.expected: The stageManager_ is non-null.
421 */
422 context_->SetIsJsCard(true);
423 context_->SetupSubRootElement();
424 EXPECT_NE(context_->stageManager_, nullptr);
425
426 /**
427 * @tc.steps3: Call the function SetupSubRootElement with isJsCard_ = false.
428 * @tc.expected: The stageManager_ is non-null.
429 */
430 context_->SetIsJsCard(false);
431 context_->SetupSubRootElement();
432 EXPECT_NE(context_->stageManager_, nullptr);
433 }
434
435 /**
436 * @tc.name: PipelineContextTestNg009
437 * @tc.desc: Test the function OnSurfaceChanged.
438 * @tc.type: FUNC
439 */
440 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg009, TestSize.Level1)
441 {
442 /**
443 * @tc.steps1: initialize parameters.
444 * @tc.expected: All pointer is non-null.
445 */
446 ASSERT_NE(context_, nullptr);
447 context_->rootWidth_ = DEFAULT_INT10;
448 context_->rootHeight_ = DEFAULT_INT10;
449 bool flagCbk = false;
450
451 /**
452 * @tc.steps2: Call the function OnSurfaceChanged with DEFAULT_INT10.
453 * @tc.expected: The flagCbk is changed to true.
454 */
455 context_->SetForegroundCalled(true);
__anona28bbc620502() 456 context_->SetNextFrameLayoutCallback([&flagCbk]() { flagCbk = !flagCbk; });
457 context_->OnSurfaceChanged(DEFAULT_INT10, DEFAULT_INT10, WindowSizeChangeReason::CUSTOM_ANIMATION);
458 EXPECT_TRUE(flagCbk);
459
460 /**
461 * @tc.steps3: Call the function OnSurfaceChanged with width = 1, height = 1 and weakFrontend_ = null.
462 * @tc.expected: The flagCbk is not changed.
463 */
464 context_->OnSurfaceChanged(DEFAULT_INT1, DEFAULT_INT1);
465 EXPECT_TRUE(flagCbk);
466
467 /**
468 * @tc.steps4: Call the function OnSurfaceDensityChanged with width = 1, height = 1 and weakFrontend_ != null.
469 * @tc.expected: The width_ and height_ of frontend is changed to DEFAULT_INT1.
470 */
471 auto frontend = AceType::MakeRefPtr<MockFrontend>();
472 context_->weakFrontend_ = frontend;
473 context_->OnSurfaceChanged(DEFAULT_INT1, DEFAULT_INT1);
474 EXPECT_EQ(frontend->GetWidth(), DEFAULT_INT1);
475 EXPECT_EQ(frontend->GetHeight(), DEFAULT_INT1);
476 context_->weakFrontend_.Reset();
477 }
478
479 /**
480 * @tc.name: PipelineContextTestNg010
481 * @tc.desc: Test the function OnSurfaceDensityChanged.
482 * @tc.type: FUNC
483 */
484 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg010, TestSize.Level1)
485 {
486 /**
487 * @tc.steps1: initialize parameters.
488 * @tc.expected: All pointer is non-null.
489 */
490 ASSERT_NE(context_, nullptr);
491 context_->density_ = DEFAULT_DOUBLE1;
492 context_->dipScale_ = DEFAULT_DOUBLE1;
493
494 /**
495 * @tc.steps2: Call the function OnSurfaceDensityChanged with viewScale_ = 0.0.
496 * @tc.expected: The density_ is changed to density.
497 */
498 context_->viewScale_ = 0.0;
499 context_->OnSurfaceDensityChanged(DEFAULT_DOUBLE4);
500 EXPECT_DOUBLE_EQ(context_->GetDensity(), DEFAULT_DOUBLE4);
501 EXPECT_DOUBLE_EQ(context_->GetDipScale(), DEFAULT_DOUBLE1);
502
503 /**
504 * @tc.steps3: Call the function OnSurfaceDensityChanged with viewScale_ = 0.0.
505 * @tc.expected: The density_ is changed to density.
506 */
507 context_->viewScale_ = DEFAULT_DOUBLE2;
508 context_->OnSurfaceDensityChanged(DEFAULT_DOUBLE4);
509 EXPECT_DOUBLE_EQ(context_->GetDensity(), DEFAULT_DOUBLE4);
510 EXPECT_DOUBLE_EQ(context_->GetDipScale(), DEFAULT_DOUBLE2);
511 }
512
513 /**
514 * @tc.name: PipelineContextTestNg011
515 * @tc.desc: Test the function AddDirtyFocus.
516 * @tc.type: FUNC
517 */
518 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg011, TestSize.Level1)
519 {
520 /**
521 * @tc.steps1: initialize parameters.
522 * @tc.expected: All pointer is non-null.
523 */
524 ASSERT_NE(context_, nullptr);
525 auto eventHub = frameNode_->GetOrCreateEventHub<EventHub>();
526 ASSERT_NE(eventHub, nullptr);
527 auto focusHub = eventHub->GetOrCreateFocusHub();
528 ASSERT_NE(focusHub, nullptr);
529
530 /**
531 * @tc.steps2: Call the function AddDirtyFocus with FocusType::NODE.
532 * @tc.expected: The FocusType of dirtyFocusNode_ is changed to FocusType::NODE.
533 */
534 focusHub->SetFocusType(FocusType::NODE);
535 context_->AddDirtyFocus(frameNode_);
536 auto dirtyFocusNode = context_->dirtyFocusNode_.Upgrade();
537 ASSERT_NE(dirtyFocusNode, nullptr);
538 EXPECT_EQ(dirtyFocusNode->GetFocusType(), FocusType::NODE);
539
540 /**
541 * @tc.steps3: Call the function OnSurfaceDensityChanged with FocusType::SCOPE.
542 * @tc.expected: The FocusType of dirtyFocusScope_ is changed to FocusType::SCOPE.
543 */
544 focusHub->SetFocusType(FocusType::SCOPE);
545 context_->AddDirtyFocus(frameNode_);
546 auto dirtyFocusScope = context_->dirtyFocusScope_.Upgrade();
547 ASSERT_NE(dirtyFocusScope, nullptr);
548 EXPECT_EQ(dirtyFocusScope->GetFocusType(), FocusType::SCOPE);
549 }
550
551 /**
552 * @tc.name: PipelineContextTestNg012
553 * @tc.desc: Test functions WindowFocus and FlushWindowFocusChangedCallback.
554 * @tc.type: FUNC
555 */
556 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg012, TestSize.Level1)
557 {
558 /**
559 * @tc.steps1: initialize parameters.
560 * @tc.expected: All pointer is non-null.
561 */
562 ASSERT_NE(context_, nullptr);
563 context_->SetupRootElement();
564 context_->onWindowFocusChangedCallbacks_.clear();
565 context_->AddWindowFocusChangedCallback(ElementRegister::UndefinedElementId);
566 context_->AddWindowFocusChangedCallback(frameNodeId_);
567 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE2);
568
569 /**
570 * @tc.steps2: Call the function WindowFocus with "true" and onShow_ = true.
571 * @tc.expected: The onFocus_ is changed to true and the size of onWindowFocusChangedCallbacks_ is change to 1.
572 */
573 context_->onShow_ = true;
574 context_->WindowFocus(true);
575 EXPECT_TRUE(context_->onFocus_);
576 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
577
578 /**
579 * @tc.steps3: Call the function WindowFocus with "true" and onShow_ = false.
580 * @tc.expected: The onFocus_ is changed to true and the size of onWindowFocusChangedCallbacks_ is change to 1.
581 */
582 context_->onShow_ = false;
583 context_->WindowFocus(true);
584 EXPECT_TRUE(context_->onFocus_);
585 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
586
587 /**
588 * @tc.steps4: Call the function WindowFocus with "false" and onShow_ = true.
589 * @tc.expected: The onFocus_ is changed to false.
590 */
591 context_->onShow_ = true;
592 context_->WindowFocus(false);
593 EXPECT_FALSE(context_->onFocus_);
594 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
595
596 /**
597 * @tc.steps5: Call the function WindowFocus with "false" and onShow_ = false.
598 * @tc.expected: The onFocus_ is changed to false.
599 */
600 context_->onShow_ = false;
601 context_->WindowFocus(false);
602 EXPECT_FALSE(context_->onFocus_);
603 context_->RemoveWindowFocusChangedCallback(0);
604 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
605 }
606
607 /**
608 * @tc.name: PipelineContextTestNg013
609 * @tc.desc: Test the function NotifyMemoryLevel.
610 * @tc.type: FUNC
611 */
612 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg013, TestSize.Level1)
613 {
614 /**
615 * @tc.steps1: initialize parameters.
616 * @tc.expected: All pointer is non-null.
617 */
618 ASSERT_NE(context_, nullptr);
619 context_->nodesToNotifyMemoryLevel_.clear();
620 context_->AddNodesToNotifyMemoryLevel(ElementRegister::UndefinedElementId);
621 context_->AddNodesToNotifyMemoryLevel(customNodeId_);
622 EXPECT_EQ(context_->nodesToNotifyMemoryLevel_.size(), DEFAULT_SIZE2);
623
624 /**
625 * @tc.steps2: Call the function NotifyMemoryLevel with "1".
626 * @tc.expected: The size of nodesToNotifyMemoryLevel_ is change to 1.
627 */
628 context_->NotifyMemoryLevel(DEFAULT_INT1);
629 EXPECT_EQ(context_->nodesToNotifyMemoryLevel_.size(), DEFAULT_SIZE1);
630
631 /**
632 * @tc.steps3: Call the function NotifyMemoryLevel with "1".
633 * @tc.expected: The NOT_REGISTER_ID in nodesToNotifyMemoryLevel_ is erased.
634 */
635 context_->AddNodesToNotifyMemoryLevel(NOT_REGISTER_ID);
636 context_->NotifyMemoryLevel(DEFAULT_INT1);
637 auto iter =
638 find(context_->nodesToNotifyMemoryLevel_.begin(), context_->nodesToNotifyMemoryLevel_.end(), NOT_REGISTER_ID);
639 EXPECT_EQ(iter, context_->nodesToNotifyMemoryLevel_.end());
640 }
641
642 /**
643 * @tc.name: PipelineContextTestNg014
644 * @tc.desc: Test the function OnIdle.
645 * @tc.type: FUNC
646 */
647 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg014, TestSize.Level1)
648 {
649 /**
650 * @tc.steps1: initialize parameters.
651 * @tc.expected: All pointer is non-null.
652 */
653 ASSERT_NE(context_, nullptr);
654 bool flagCbk = false;
655
656 /**
657 * @tc.steps2: Call the function OnIdle.
658 * @tc.expected: The value of flagCbk remains unchanged.
659 */
__anona28bbc620602(int64_t, bool) 660 context_->AddPredictTask([&flagCbk](int64_t, bool) { flagCbk = true; });
661 context_->OnIdle(0);
662 EXPECT_FALSE(flagCbk);
663
664 /**
665 * @tc.steps3: Call the function OnIdle.
666 * @tc.expected: The flagCbk is changed to true.
667 */
668 context_->OnIdle(NANO_TIME_STAMP);
669 EXPECT_TRUE(flagCbk);
670 }
671
672 /**
673 * @tc.name: PipelineContextTestNg015
674 * @tc.desc: Test the function Finish.
675 * @tc.type: FUNC
676 */
677 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg015, TestSize.Level1)
678 {
679 /**
680 * @tc.steps1: initialize parameters.
681 * @tc.expected: All pointer is non-null.
682 */
683 ASSERT_NE(context_, nullptr);
684 bool flagCbk = false;
685
686 /**
687 * @tc.steps2: Call the function Finish.
688 * @tc.expected: The value of flagCbk remains unchanged.
689 */
690 context_->SetFinishEventHandler(nullptr);
691 context_->Finish(false);
692 EXPECT_FALSE(flagCbk);
693
694 /**
695 * @tc.steps3: Call the function Finish.
696 * @tc.expected: The flagCbk is changed to true.
697 */
__anona28bbc620702() 698 context_->SetFinishEventHandler([&flagCbk]() { flagCbk = true; });
699 context_->Finish(false);
700 EXPECT_TRUE(flagCbk);
701 }
702
703 /**
704 * @tc.name: PipelineContextTestNg016
705 * @tc.desc: Test functions OnShow, OnHide and FlushWindowStateChangedCallback.
706 * @tc.type: FUNC
707 */
708 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg016, TestSize.Level1)
709 {
710 /**
711 * @tc.steps1: initialize parameters.
712 * @tc.expected: All pointer is non-null.
713 */
714 ASSERT_NE(context_, nullptr);
715 context_->SetupRootElement();
716 context_->onWindowStateChangedCallbacks_.clear();
717 context_->AddWindowStateChangedCallback(ElementRegister::UndefinedElementId);
718 context_->AddWindowStateChangedCallback(customNodeId_);
719 EXPECT_EQ(context_->onWindowStateChangedCallbacks_.size(), DEFAULT_SIZE2);
720
721 /**
722 * @tc.steps2: Call the function OnShow.
723 * @tc.expected: The onShow_ is changed to true and the size of onWindowStateChangedCallbacks_ is change to 1.
724 */
725 context_->OnShow();
726 EXPECT_TRUE(context_->onShow_);
727 EXPECT_EQ(context_->onWindowStateChangedCallbacks_.size(), DEFAULT_SIZE1);
728
729 /**
730 * @tc.steps3: Call the function OnHide.
731 * @tc.expected: The onShow_ is changed to false.
732 */
733 context_->OnHide();
734 EXPECT_FALSE(context_->onShow_);
735 EXPECT_EQ(context_->onWindowStateChangedCallbacks_.size(), DEFAULT_SIZE1);
736 }
737
738 /**
739 * @tc.name: PipelineContextTestNg017
740 * @tc.desc: Test functions OnDragEvent.
741 * @tc.type: FUNC
742 */
743 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg017, TestSize.Level1)
744 {
745 /**
746 * @tc.steps1: initialize parameters.
747 * @tc.expected: All pointer is non-null.
748 */
749 ASSERT_NE(context_, nullptr);
750 context_->SetupRootElement();
751 auto manager = context_->GetDragDropManager();
752 ASSERT_NE(manager, nullptr);
753 auto frameNodeId_017 = ElementRegister::GetInstance()->MakeUniqueId();
754 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_017, nullptr);
755 ASSERT_NE(frameNode, nullptr);
756
757 /**
758 * @tc.steps2: Call the function OnDragEvent with isDragged_=true, currentId_=DEFAULT_INT1 and
759 * DRAG_EVENT_START_FOR_CONTROLLER.
760 * @tc.expected: The currentId_ is equal to DEFAULT_INT1.
761 */
762 manager->isDragged_ = true;
763 manager->currentId_ = DEFAULT_INT1;
764 context_->OnDragEvent({ DEFAULT_INT1, DEFAULT_INT1 }, DragEventAction::DRAG_EVENT_START_FOR_CONTROLLER);
765 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
766
767 /**
768 * @tc.steps2: Call the function OnDragEvent with isDragged_=true, currentId_=DEFAULT_INT1 and DRAG_EVENT_OUT.
769 * @tc.expected: The currentId_ is equal to DEFAULT_INT1.
770 */
771 manager->isDragged_ = true;
772 manager->currentId_ = DEFAULT_INT1;
773 context_->OnDragEvent({ DEFAULT_INT1, DEFAULT_INT1 }, DragEventAction::DRAG_EVENT_OUT);
774 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
775
776 /**
777 * @tc.steps3: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_START.
778 * @tc.expected: The currentId_ is equal to DEFAULT_INT1.
779 */
780 manager->isDragged_ = false;
781 manager->currentId_ = DEFAULT_INT1;
782 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_START);
783 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
784
785 /**
786 * @tc.steps4: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_END.
787 * @tc.expected: The currentId_ is changed to DEFAULT_INT10.
788 */
789 manager->isDragged_ = false;
790 manager->currentId_ = DEFAULT_INT1;
791 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_END);
792 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
793
794 /**
795 * @tc.steps4: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_MOVE.
796 * @tc.expected: The currentId_ is changed to DEFAULT_INT10.
797 */
798 manager->isDragged_ = false;
799 manager->currentId_ = DEFAULT_INT1;
800 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_MOVE);
801 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
802 MockContainer::Current()->SetIsSceneBoardWindow(true);
803 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_MOVE);
804 context_->SetIsDragging(false);
805 EXPECT_FALSE(context_->IsDragging());
806 context_->ResetDragging();
807
808 /**
809 * @tc.steps5: Call the function OnDragEvent with DRAG_EVENT_PULL_CANCEL.
810 * @tc.expected: The dragDropState_ is changed to DragDropMgrState::IDLE.
811 */
812 manager->dragDropState_ = DragDropMgrState::DRAGGING;
813 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_PULL_CANCEL);
814 EXPECT_EQ(manager->dragDropState_, DragDropMgrState::IDLE);
815
816 /**
817 * @tc.steps6: Call the function OnDragEvent with DRAG_EVENT_PULL_THROW.
818 * @tc.expected: The isWindowConsumed_ is changed to false.
819 */
820 manager->isWindowConsumed_ = true;
821 MockContainer::Current()->SetIsSceneBoardWindow(false);
822 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_PULL_THROW);
823 EXPECT_EQ(manager->isWindowConsumed_, false);
824 }
825
826 /**
827 * @tc.name: PipelineContextTestNg018
828 * @tc.desc: Test the function ShowContainerTitle.
829 * @tc.type: FUNC
830 */
831 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg018, TestSize.Level1)
832 {
833 /**
834 * @tc.steps1: initialize parameters.
835 * @tc.expected: All pointer is non-null.
836 */
837 ASSERT_NE(context_, nullptr);
838 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
839 context_->SetupRootElement();
840 ASSERT_NE(context_->rootNode_, nullptr);
841 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
842 ASSERT_NE(containerNode, nullptr);
843 auto pattern = containerNode->GetPattern<ContainerModalPattern>();
844 ASSERT_NE(containerNode, nullptr);
845
846 /**
847 * @tc.steps2: Call the function ShowContainerTitle with windowModal_ = WindowModal::DIALOG_MODAL.
848 * @tc.expected: The moveX_ is unchanged.
849 */
850 pattern->moveX_ = DEFAULT_DOUBLE2;
851 context_->windowModal_ = WindowModal::DIALOG_MODAL;
852 context_->ShowContainerTitle(true);
853 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
854
855 /**
856 * @tc.steps3: Call the function ShowContainerTitle with windowModal_ = WindowModal::CONTAINER_MODAL.
857 * @tc.expected: The moveX_ is unchanged.
858 */
859 pattern->moveX_ = DEFAULT_DOUBLE2;
860 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
861 context_->ShowContainerTitle(true);
862 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
863 }
864
865 /**
866 * @tc.name: PipelineContextTestNg019
867 * @tc.desc: Test the function SetAppTitle.
868 * @tc.type: FUNC
869 */
870 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg019, TestSize.Level1)
871 {
872 /**
873 * @tc.steps1: initialize parameters.
874 * @tc.expected: All pointer is non-null.
875 */
876 ASSERT_NE(context_, nullptr);
877 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
878 context_->SetupRootElement();
879 ASSERT_NE(context_->rootNode_, nullptr);
880 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
881 ASSERT_NE(containerNode, nullptr);
882 auto pattern = containerNode->GetPattern<ContainerModalPattern>();
883 ASSERT_NE(containerNode, nullptr);
884
885 /**
886 * @tc.steps2: Call the function ShowContainerTitle with windowModal_ = WindowModal::DIALOG_MODAL.
887 * @tc.expected: The moveX_ is unchanged.
888 */
889 pattern->moveX_ = DEFAULT_DOUBLE2;
890 context_->windowModal_ = WindowModal::DIALOG_MODAL;
891 context_->SetAppTitle(TEST_TAG);
892 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
893
894 /**
895 * @tc.steps3: Call the function ShowContainerTitle with windowModal_ = WindowModal::CONTAINER_MODAL.
896 * @tc.expected: The moveX_ is unchanged.
897 */
898 pattern->moveX_ = DEFAULT_DOUBLE2;
899 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
900 context_->SetAppTitle(TEST_TAG);
901 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
902 }
903
904 /**
905 * @tc.name: PipelineContextTestNg020
906 * @tc.desc: Test the function SetAppIcon.
907 * @tc.type: FUNC
908 */
909 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg020, TestSize.Level1)
910 {
911 /**
912 * @tc.steps1: initialize parameters.
913 * @tc.expected: All pointer is non-null.
914 */
915 ASSERT_NE(context_, nullptr);
916 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
917 context_->SetupRootElement();
918 ASSERT_NE(context_->rootNode_, nullptr);
919 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
920 ASSERT_NE(containerNode, nullptr);
921 auto pattern = containerNode->GetPattern<ContainerModalPattern>();
922 ASSERT_NE(containerNode, nullptr);
923
924 /**
925 * @tc.steps2: Call the function SetAppIcon with windowModal_ = WindowModal::DIALOG_MODAL.
926 * @tc.expected: The moveX_ is unchanged.
927 */
928 pattern->moveX_ = DEFAULT_DOUBLE2;
929 context_->windowModal_ = WindowModal::DIALOG_MODAL;
930 context_->SetAppIcon(nullptr);
931 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
932
933 /**
934 * @tc.steps3: Call the function SetAppIcon with windowModal_ = WindowModal::CONTAINER_MODAL.
935 * @tc.expected: The moveX_ is unchanged.
936 */
937 pattern->moveX_ = DEFAULT_DOUBLE2;
938 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
939 context_->SetAppIcon(nullptr);
940 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
941 }
942
943 /**
944 * @tc.name: PipelineContextTestNg021
945 * @tc.desc: Test the function OnAxisEvent.
946 * @tc.type: FUNC
947 */
948 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg021, TestSize.Level1)
949 {
950 /**
951 * @tc.steps1: initialize parameters.
952 * @tc.expected: All pointer is non-null.
953 */
954 ASSERT_NE(context_, nullptr);
955 AxisEvent event;
956 event.x = DEFAULT_DOUBLE1;
957 context_->viewScale_ = DEFAULT_DOUBLE1;
958
959 /**
960 * @tc.steps2: Call the function OnAxisEvent with action = AxisAction::BEGIN.
961 * @tc.expected: The instanceId is changed to 4.
962 */
963 event.action = AxisAction::BEGIN;
964 ResetEventFlag(TOUCH_TEST_FLAG | AXIS_TEST_FLAG);
965 context_->OnAxisEvent(event);
966 EXPECT_FALSE(GetEventFlag(TOUCH_TEST_FLAG));
967 EXPECT_FALSE(GetEventFlag(AXIS_TEST_FLAG));
968
969 /**
970 * @tc.steps3: Call the function OnAxisEvent with action = AxisAction::UPDATE.
971 * @tc.expected: The instanceId is changed to 3.
972 */
973 event.action = AxisAction::UPDATE;
974 ResetEventFlag(TOUCH_TEST_FLAG | AXIS_TEST_FLAG);
975 context_->OnAxisEvent(event);
976 EXPECT_FALSE(GetEventFlag(TOUCH_TEST_FLAG));
977 EXPECT_FALSE(GetEventFlag(AXIS_TEST_FLAG));
978
979 /**
980 * @tc.steps4: Call the function OnAxisEvent with action = AxisAction::END.
981 * @tc.expected: The instanceId is changed to 1.
982 */
983 event.action = AxisAction::END;
984 ResetEventFlag(TOUCH_TEST_FLAG | AXIS_TEST_FLAG);
985 context_->OnAxisEvent(event);
986 EXPECT_FALSE(GetEventFlag(TOUCH_TEST_FLAG));
987 EXPECT_FALSE(GetEventFlag(AXIS_TEST_FLAG));
988 }
989
990 /**
991 * @tc.name: PipelineContextTestNg022
992 * @tc.desc: Test the function OnKeyEvent.
993 * @tc.type: FUNC
994 */
995 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg022, TestSize.Level1)
996 {
997 /**
998 * @tc.steps1: initialize parameters.
999 * @tc.expected: All pointer is non-null.
1000 */
1001 ASSERT_NE(context_, nullptr);
1002 context_->SetupRootElement();
1003 auto eventManager = context_->GetDragDropManager();
1004 ASSERT_NE(eventManager, nullptr);
1005 auto frameNodeId_022 = ElementRegister::GetInstance()->MakeUniqueId();
1006 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_022, nullptr);
1007 ASSERT_NE(frameNode, nullptr);
1008 KeyEvent event;
1009
1010 /**
1011 * @tc.steps2: Call the function OnKeyEvent with isFocusActive_ = false, action = KeyAction::DOWN and
1012 # pressedCodes = { KeyCode::KEY_TAB }.
1013 * @tc.expected: The return value of OnKeyEvent is true.
1014 */
1015 context_->SetIsFocusActive(false);
1016 event.action = KeyAction::DOWN;
1017 event.code = KeyCode::KEY_TAB;
1018 event.pressedCodes = { KeyCode::KEY_TAB };
1019 EXPECT_TRUE(context_->OnNonPointerEvent(event));
1020
1021 /**
1022 * @tc.steps3: Call the function OnKeyEvent with isFocusActive_ = false, action = KeyAction::DOWN and
1023 # pressedCodes = { KeyCode::KEY_DPAD_UP }.
1024 * @tc.expected: The return value of OnKeyEvent is true.
1025 */
1026 context_->SetIsFocusActive(false);
1027 event.pressedCodes = { KeyCode::KEY_DPAD_UP };
1028 event.code = KeyCode::KEY_DPAD_UP;
1029 EXPECT_FALSE(context_->OnNonPointerEvent(event));
1030
1031 /**
1032 * @tc.steps4: Call the function OnKeyEvent with isFocusActive_ = false, action = KeyAction::UP and
1033 # pressedCodes = { KeyCode::KEY_CLEAR }.
1034 * @tc.expected: The return value of OnKeyEvent is true.
1035 */
1036 context_->SetIsFocusActive(false);
1037 event.action = KeyAction::UP;
1038 event.code = KeyCode::KEY_CLEAR;
1039 event.pressedCodes = { KeyCode::KEY_CLEAR };
1040 EXPECT_FALSE(context_->OnNonPointerEvent(event));
1041
1042 /**
1043 * @tc.steps4: Call the function OnKeyEvent with isFocusActive_ = true, action = KeyAction::UP and
1044 # pressedCodes = { KeyCode::KEY_CLEAR }.
1045 * @tc.expected: The return value of OnKeyEvent is false.
1046 */
1047 context_->SetIsFocusActive(true);
1048 event.action = KeyAction::UP;
1049 event.code = KeyCode::KEY_CLEAR;
1050 event.pressedCodes = { KeyCode::KEY_CLEAR };
1051 EXPECT_FALSE(context_->OnNonPointerEvent(event));
1052
1053 /**
1054 * @tc.steps5: Call the function OnKeyEvent with isFocusActive_ = true, action = KeyAction::UP and
1055 # pressedCodes = { KeyCode::KEY_CLEAR }.
1056 * @tc.expected: The return value of OnKeyEvent is false.
1057 */
1058 context_->rootNode_.Reset();
1059 context_->SetIsFocusActive(true);
1060 event.action = KeyAction::DOWN;
1061 event.code = KeyCode::KEY_ESCAPE;
1062 event.pressedCodes = { KeyCode::KEY_ESCAPE };
1063
1064 auto pageNodeId = ElementRegister::GetInstance()->MakeUniqueId();
1065 auto pageNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, pageNodeId, nullptr);
1066 auto childNodeId = ElementRegister::GetInstance()->MakeUniqueId();
1067 auto childNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, childNodeId, nullptr);
1068 pageNode->AddChild(childNode);
1069 context_->stageManager_->stageNode_ = pageNode;
1070 context_->ReDispatch(event);
1071 EXPECT_FALSE(context_->OnNonPointerEvent(event));
1072 EXPECT_FALSE(context_->dragDropManager_->isDragCancel_);
1073
1074 event.isPreIme = 1;
1075 EXPECT_FALSE(context_->OnNonPointerEvent(event));
1076 }
1077
1078 /**
1079 * @tc.name: PipelineContextTestNg024
1080 * @tc.desc: Test the function FlushTouchEvents.
1081 * @tc.type: FUNC
1082 */
1083 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg024, TestSize.Level1)
1084 {
1085 /**
1086 * @tc.steps1: initialize parameters.
1087 * @tc.expected: All pointer is non-null.
1088 */
1089 ASSERT_NE(context_, nullptr);
1090 context_->SetupRootElement();
1091 TouchEvent event;
1092 context_->touchEvents_.clear();
1093
1094 /**
1095 * @tc.steps2: Call the function FlushTouchEvents with empty touchEvents_.
1096 * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1097 */
1098 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1099 context_->FlushTouchEvents();
1100 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1101
1102 /**
1103 * @tc.steps3: Call the function FlushTouchEvents with unempty touchEvents_.
1104 * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1105 */
1106 context_->touchEvents_.push_back(event);
1107 context_->touchEvents_.push_back(event);
1108 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1109 context_->FlushTouchEvents();
1110 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1111
1112 /**
1113 * @tc.steps4: Call the function FlushTouchEvents with unempty touchEvents_.
1114 * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1115 */
1116 TouchEvent event2;
1117 event2.id = 1;
1118 context_->touchEvents_.push_back(event);
1119 context_->touchEvents_.push_back(event2);
1120 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1121 context_->FlushTouchEvents();
1122 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1123 EXPECT_FALSE(context_->touchAccelarate_);
1124 }
1125
1126 /**
1127 * @tc.name: PipelineContextTestNg025
1128 * @tc.desc: Test the function OnDumpInfo.
1129 * @tc.type: FUNC
1130 */
1131 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg025, TestSize.Level1)
1132 {
1133 /**
1134 * @tc.steps1: initialize parameters.
1135 * @tc.expected: All pointer is non-null.
1136 */
1137 ASSERT_NE(context_, nullptr);
1138 context_->SetupRootElement();
1139
1140 std::unique_ptr<std::ostream> ostream = std::make_unique<std::ostringstream>();
1141 ASSERT_NE(ostream, nullptr);
1142 DumpLog::GetInstance().SetDumpFile(std::move(ostream));
1143 /**
1144 * @tc.steps2: init a vector with some string params and
1145 call OnDumpInfo with every param array.
1146 * @tc.expected: The return value is same as the expectation.
1147 */
1148 std::vector<std::vector<std::string>> params = { { "-element", "-lastpage" }, { "-element", "non-lastpage" },
1149 { "-element" }, { "-focus" }, { ACCESS_TAG }, { "-inspector" }, { "-render" }, { "-layer" }, { "-frontend" },
1150 { "-multimodal" }, { "-rotation", "1", "2", "3" }, { "-animationscale", "1", "2", "3" },
1151 { "-velocityscale", "1", "2", "3" }, { "-scrollfriction", "1", "2", "3" }, { "-threadstuck", "1", "2", "3" },
1152 { "-rotation" }, { "-animationscale" }, { "-velocityscale" }, { "-scrollfriction" }, { "-threadstuck" },
1153 { "test" }, { "-navigation" }, { "-focuswindowscene" }, { "-focusmanager" }, { "-jsdump" }, { "-event" },
1154 { "-imagecache" }, { "-imagefilecache" }, { "-allelements" }, { "-default" }, { "-overlay" }, { "--stylus" },
1155 { "-bindaicaller" }};
1156 int turn = 0;
1157 for (; turn < params.size(); turn++) {
1158 EXPECT_TRUE(context_->OnDumpInfo(params[turn]));
1159 }
1160 }
1161
1162 /**
1163 * @tc.name: PipelineContextTestNg026
1164 * @tc.desc: Test the function OnBackPressed.
1165 * @tc.type: FUNC
1166 */
1167 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg026, TestSize.Level1)
1168 {
1169 /**
1170 * @tc.steps1: initialize parameters.
1171 * @tc.expected: All pointer is non-null.
1172 */
1173 ASSERT_NE(context_, nullptr);
1174 context_->SetupRootElement();
1175
1176 /**
1177 * @tc.steps2: Call the function OnBackPressed with weakFrontend_ is null.
1178 * @tc.expected: The return value of function is false.
1179 */
1180 context_->weakFrontend_.Reset();
1181 EXPECT_FALSE(context_->OnBackPressed());
1182
1183 /**
1184 * @tc.steps3: Call the function OnBackPressed with the return value of
1185 * fullScreenManager_->RequestFullScreen is true.
1186 * @tc.expected: The return value of function is true.
1187 */
1188 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1189 EXPECT_CALL(*frontend, OnBackPressed()).WillRepeatedly(testing::Return(true));
1190 context_->weakFrontend_ = frontend;
1191 auto frameNodeId = ElementRegister::GetInstance()->MakeUniqueId();
1192 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId, nullptr);
1193 context_->fullScreenManager_->RequestFullScreen(frameNode); // Set the return value of OnBackPressed to true;
1194 EXPECT_TRUE(context_->OnBackPressed());
1195
1196 /**
1197 * @tc.steps4: Call the function OnBackPressed with the return value of
1198 * fullScreenManager_->RequestFullScreen is true.
1199 * @tc.expected: The return value of function is true.
1200 */
1201 // Set the return value of OnBackPressed of fullScreenManager_ to true;
1202 context_->fullScreenManager_->ExitFullScreen(frameNode);
1203 EXPECT_TRUE(context_->OnBackPressed());
1204
1205 /**
1206 * @tc.steps5: Call the function OnBackPressed with the return value of
1207 * overlayManager_->RemoveOverlay is true.
1208 * @tc.expected: The return value of function is true.
1209 */
1210 // Set the return value of RemoveOverlay of overlayManager_ to true;
1211 context_->overlayManager_->CloseDialog(frameNode_);
1212 EXPECT_TRUE(context_->OnBackPressed());
1213
1214 /**
1215 * @tc.steps6: Call the function OnBackPressed with the return value of
1216 * overlayManager_->RemoveOverlay is true.
1217 * @tc.expected: The return value of function is true.
1218 */
1219 // Set the return value of RemoveOverlay of overlayManager_ to true;
1220 context_->overlayManager_->CloseDialog(frameNode);
1221 EXPECT_TRUE(context_->OnBackPressed());
1222 }
1223
1224 /**
1225 * @tc.name: PipelineContextTestNg027
1226 * @tc.desc: Test functions StartWindowSizeChangeAnimate and SetRootRect.
1227 * @tc.type: FUNC
1228 */
1229 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg027, TestSize.Level1)
1230 {
1231 /**
1232 * @tc.steps1: initialize parameters.
1233 * @tc.expected: All pointer is non-null.
1234 */
1235 ASSERT_NE(context_, nullptr);
1236 EXPECT_CALL(*(MockWindow*)(context_->window_.get()), SetDrawTextAsBitmap(_)).Times(AnyNumber());
1237 context_->SetupRootElement();
1238 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1239 auto& windowConfig = frontend->GetWindowConfig();
1240 windowConfig.designWidth = DEFAULT_INT1;
1241 context_->weakFrontend_ = frontend;
1242
1243 /**
1244 * @tc.steps2: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::RECOVER.
1245 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1246 */
1247 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1248 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::RECOVER);
1249 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1250
1251 /**
1252 * @tc.steps3: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::MAXIMIZE.
1253 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1254 */
1255 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1256 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::MAXIMIZE);
1257 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1258
1259 /**
1260 * @tc.steps4: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::ROTATION.
1261 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1262 */
1263 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1264 auto manager = AceType::MakeRefPtr<TextFieldManagerNG>();
1265 context_->SetTextFieldManager(manager);
1266 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::ROTATION);
1267 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1268
1269 /**
1270 * @tc.steps5: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::UNDEFINED.
1271 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1272 */
1273 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1274 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::UNDEFINED);
1275 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1276
1277 /**
1278 * @tc.steps5: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::UNDEFINED.
1279 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1280 */
1281 SystemProperties::windowAnimationEnabled_ = false;
1282 context_->rootNode_->geometryNode_->frame_.rect_.y_ = 3.0;
1283 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::UNDEFINED);
1284 EXPECT_EQ(context_->rootNode_->GetGeometryNode()->GetFrameOffset().GetY(), 0);
1285 }
1286
1287 /**
1288 * @tc.name: PipelineContextTestNg028
1289 * @tc.desc: Test functions OnVirtualKeyboardHeightChange and SetRootRect.
1290 * @tc.type: FUNC
1291 */
1292 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg028, TestSize.Level1)
1293 {
1294 /**
1295 * @tc.steps1: initialize parameters.
1296 * @tc.expected: All pointer is non-null.
1297 */
1298 ASSERT_NE(context_, nullptr);
1299 context_->SetupRootElement();
1300 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1301 auto& windowConfig = frontend->GetWindowConfig();
1302 windowConfig.designWidth = DEFAULT_INT1;
1303 context_->weakFrontend_ = frontend;
1304 context_->SetTextFieldManager(AceType::MakeRefPtr<TextFieldManagerNG>());
1305
1306 /**
1307 * @tc.steps2: Call the function OnVirtualKeyboardHeightChange with DEFAULT_DOUBLE1.
1308 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT0.
1309 */
1310 context_->designWidthScale_ = DEFAULT_DOUBLE1;
1311 context_->OnVirtualKeyboardHeightChange(DEFAULT_DOUBLE1);
1312 context_->OnVirtualKeyboardHeightChange(DEFAULT_DOUBLE1, 0, 0);
1313 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_DOUBLE1);
1314 EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), 0);
1315
1316 /**
1317 * @tc.steps3: init data and Call the function OnVirtualKeyboardHeightChange
1318 when textFieldManager_ is null.
1319 * @tc.expected: the return is same as expectation.
1320 */
1321 context_->textFieldManager_ = nullptr;
1322
1323 // the first arg is rootHeight_, the second arg is the parameter of function,
1324 // the third arg is the expectation returns
1325 std::vector<std::vector<int>> params = { { 200, 400, -300 }, { -200, 100, -100 }, { -200, -300, 300 } };
1326 for (int turn = 0; turn < params.size(); turn++) {
1327 context_->rootHeight_ = params[turn][0];
1328 context_->OnVirtualKeyboardHeightChange(params[turn][1]);
1329 context_->OnVirtualKeyboardHeightChange(params[turn][1], 0, 0);
1330 EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), params[turn][2]);
1331 }
1332 /**
1333 * @tc.steps4: init data and Call the function OnVirtualKeyboardHeightChange
1334 when textFieldManager_ is not null.
1335 * @tc.expected: the return is same as expectation.
1336 */
1337 auto manager = AceType::MakeRefPtr<TextFieldManagerNG>();
1338 context_->textFieldManager_ = manager;
1339 ASSERT_NE(context_->rootNode_, nullptr);
1340
1341 // the first arg is manager->height_, the second arg is manager->position_.deltaY_
1342 // the third arg is rootHeight_, the forth arg is context_->rootNode_->geometryNode_->frame_.rect_.y_
1343 // the fifth arg is the parameter of function, the sixth arg is the expectation returns
1344 params = { { 10, 100, 300, 0, 50, 0 }, { 10, 100, 300, 100, 100, 0 }, { 30, 100, 300, 100, 50, 0 },
1345 { 50, 290, 400, 100, 200, -95 }, { -1000, 290, 400, 100, 200, 100 } };
1346 for (int turn = 0; turn < params.size(); turn++) {
1347 manager->height_ = params[turn][0];
1348 manager->position_.deltaY_ = params[turn][1];
1349 context_->rootHeight_ = params[turn][2];
1350 context_->rootNode_->geometryNode_->frame_.rect_.y_ = params[turn][3];
1351 context_->safeAreaManager_->UpdateKeyboardOffset(params[turn][3]);
1352 manager->SetClickPositionOffset(params[turn][3]);
1353 context_->OnVirtualKeyboardHeightChange(params[turn][4]);
1354 context_->OnVirtualKeyboardHeightChange(params[turn][4], 0, 0);
1355 EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), params[turn][5]);
1356 }
1357 }
1358
1359 /**
1360 * @tc.name: PipelineContextTestNg029
1361 * @tc.desc: Test ThemeManager and SharedImageManager multithread.
1362 * @tc.type: FUNC
1363 */
1364 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg029, TestSize.Level1)
1365 {
1366 std::vector<std::thread> threads;
1367 for (int i = 0; i < 20; ++i) {
__anona28bbc620802() 1368 threads.emplace_back(std::thread([]() { context_->GetOrCreateSharedImageManager(); }));
1369 }
1370 for (auto&& thread : threads) {
1371 thread.join();
1372 }
1373
1374 threads.clear();
1375 for (int i = 0; i < 20; ++i) {
1376 if (i == 10) {
1377 context_->SetThemeManager(AceType::MakeRefPtr<MockThemeManager>());
1378 } else {
__anona28bbc620902() 1379 threads.emplace_back(std::thread([]() { context_->GetThemeManager(); }));
1380 }
1381 }
1382 for (auto&& thread : threads) {
1383 thread.join();
1384 }
1385 EXPECT_TRUE(context_->GetThemeManager());
1386 }
1387
1388 /**
1389 * @tc.name: PipelineContextTestNg030
1390 * @tc.desc: Test RestoreNodeInfo, GetStoredNodeInfo, StoreNode and GetRestoreInfo.
1391 * @tc.type: FUNC
1392 */
1393 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg030, TestSize.Level1)
1394 {
1395 /**
1396 * @tc.steps1: init a mockPattern.
1397 * @tc.expected: some calls by mockPattern.
1398 */
1399 RefPtr<MockPattern> mockPattern_ = AceType::MakeRefPtr<MockPattern>();
1400 Mock::AllowLeak(mockPattern_.rawPtr_);
1401 EXPECT_CALL(*mockPattern_, ProvideRestoreInfo())
1402 .Times(AnyNumber())
1403 .WillRepeatedly(testing::Return("Default restore info"));
1404 EXPECT_CALL(*mockPattern_, GetContextParam()).Times(AnyNumber()).WillRepeatedly(testing::Return(std::nullopt));
1405 EXPECT_CALL(*mockPattern_, CreatePaintProperty())
1406 .Times(AnyNumber())
1407 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<PaintProperty>()));
1408 EXPECT_CALL(*mockPattern_, CreateLayoutProperty())
1409 .Times(AnyNumber())
1410 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<LayoutProperty>()));
1411 EXPECT_CALL(*mockPattern_, CreateEventHub())
1412 .Times(AnyNumber())
1413 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<EventHub>()));
1414 EXPECT_CALL(*mockPattern_, CreateAccessibilityProperty())
1415 .Times(AnyNumber())
1416 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<AccessibilityProperty>()));
1417 EXPECT_CALL(*mockPattern_, OnAttachToFrameNode()).Times(AnyNumber());
1418 EXPECT_CALL(*mockPattern_, OnDetachFromFrameNode(_)).Times(AnyNumber());
1419
1420 /**
1421 * @tc.steps2: init a patternCreator and Create frameNodes and call StoreNode.
1422 * @tc.expected: StoreNode success.
1423 */
__anona28bbc620a02() 1424 auto patternCreator_ = [&mockPattern_]() { return mockPattern_; };
1425 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1426 auto frameNode_1 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
1427 ASSERT_NE(context_, nullptr);
1428 context_->StoreNode(DEFAULT_RESTORE_ID0, frameNode_1);
1429 EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID0], frameNode_1);
1430 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1431 auto frameNode_2 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, patternCreator_);
1432 context_->StoreNode(DEFAULT_RESTORE_ID0, frameNode_2);
1433 EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID0], frameNode_2);
1434 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1435 auto frameNode_3 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
1436 context_->StoreNode(DEFAULT_RESTORE_ID1, frameNode_3);
1437 EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID1], frameNode_3);
1438 context_->storeNode_[DEFAULT_RESTORE_ID2] = nullptr;
1439
1440 /**
1441 * @tc.steps3: call RestoreNodeInfo with nullptr.
1442 * @tc.expected: restoreNodeInfo_ is empty.
1443 */
1444 auto jsonNodeInfo = context_->GetStoredNodeInfo();
1445 context_->RestoreNodeInfo(jsonNodeInfo->GetChild());
1446 EXPECT_TRUE(context_->restoreNodeInfo_.empty());
1447
1448 /**
1449 * @tc.steps4: call GetStoredNodeInfo and RestoreNodeInfo.
1450 * @tc.expected: restoreNodeInfo_ is not empty.
1451 */
1452 context_->RestoreNodeInfo(std::move(jsonNodeInfo));
1453 EXPECT_FALSE(context_->restoreNodeInfo_.empty());
1454
1455 /**
1456 * @tc.steps5: call GetRestoreInfo.
1457 * @tc.expected: restoreInfo is not "Default restore info".
1458 DEFAULT_RESTORE_ID0:"Default restore info" is moved from restoreNodeInfo_.
1459 */
1460 std::string restoreInfo;
1461 auto rt = context_->GetRestoreInfo(DEFAULT_RESTORE_ID0, restoreInfo);
1462 EXPECT_EQ(restoreInfo, "Default restore info");
1463 EXPECT_TRUE(rt);
1464 rt = context_->GetRestoreInfo(DEFAULT_RESTORE_ID0, restoreInfo);
1465 EXPECT_FALSE(rt);
1466 auto iter1 = context_->restoreNodeInfo_.find(DEFAULT_RESTORE_ID0);
1467 EXPECT_EQ(iter1, context_->restoreNodeInfo_.end());
1468 }
1469
1470 /**
1471 * @tc.name: PipelineContextTestNg032
1472 * @tc.desc: Test OnSurfacePositionChanged RegisterSurfacePositionChangedCallback
1473 * UnregisterSurfacePositionChangedCallback.
1474 * @tc.type: FUNC
1475 */
1476 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg032, TestSize.Level1)
1477 {
1478 /**
1479 * @tc.steps1: initialize parameters and call RegisterSurfacePositionChangedCallback with null.
1480 * @tc.expected: rt is 0.
1481 */
1482 ASSERT_NE(context_, nullptr);
1483 int32_t rt = context_->RegisterSurfacePositionChangedCallback(nullptr);
1484 EXPECT_EQ(rt, 0);
1485 /**
1486 * @tc.steps2: init a callback, register it and change map memory.
1487 then call OnSurfacePositionChanged.
1488 * @tc.expected: flag is true.
1489 */
1490 bool flag = false;
__anona28bbc620b02(int32_t input_1, int32_t input_2) 1491 auto callback_1 = [&flag](int32_t input_1, int32_t input_2) { flag = !flag; };
1492 rt = context_->RegisterSurfacePositionChangedCallback(std::move(callback_1));
1493 context_->surfacePositionChangedCallbackMap_[100] = nullptr;
1494 context_->OnSurfacePositionChanged(0, 0);
1495 EXPECT_TRUE(flag);
1496 /**
1497 * @tc.steps2: call UnregisterSurfacePositionChangedCallback.
1498 then call OnSurfacePositionChanged.
1499 * @tc.expected: flag is true.
1500 */
1501 context_->UnregisterSurfacePositionChangedCallback(rt);
1502 context_->OnSurfacePositionChanged(0, 0);
1503 EXPECT_TRUE(flag);
1504 }
1505
1506 /**
1507 * @tc.name: PipelineContextTestNg040
1508 * @tc.desc: Test SetContainerButtonHide function.
1509 * @tc.type: FUNC
1510 */
1511 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg040, TestSize.Level1)
1512 {
1513 /**
1514 * @tc.steps1: initialize root node and containerModal node.
1515 * @tc.expected: root node and containerModal node are not null.
1516 */
1517 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1518 context_->SetThemeManager(themeManager);
1519 auto themeConstants = AceType::MakeRefPtr<ThemeConstants>(nullptr);
1520 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<ContainerModalTheme>()));
1521 EXPECT_CALL(*themeManager, GetThemeConstants()).WillRepeatedly(Return(themeConstants));
1522
1523 ASSERT_NE(context_, nullptr);
1524 context_->SetWindowModal(WindowModal::CONTAINER_MODAL);
1525 ASSERT_NE(context_->window_, nullptr);
1526 context_->SetupRootElement();
1527 ASSERT_NE(context_->GetRootElement(), nullptr);
1528 auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
1529 ASSERT_NE(containerNode, nullptr);
1530 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1531 ASSERT_NE(containerPattern, nullptr);
1532 /**
1533 * @tc.steps2: call SetContainerButtonHide with params true, true, false, false.
1534 * @tc.expected: depends on first param, hideSplitButton value is true.
1535 */
1536 context_->SetContainerButtonHide(true, true, false, false);
1537 EXPECT_TRUE(containerPattern->hideSplitButton_ == true);
1538 /**
1539 * @tc.steps3: call SetContainerButtonHide with params false, true, false, false.
1540 * @tc.expected: depends on first param, hideSplitButton value is false.
1541 */
1542 context_->SetContainerButtonHide(false, true, false, false);
1543 EXPECT_TRUE(containerPattern->hideSplitButton_ == false);
1544
1545 /**
1546 * @tc.steps4: call SetContainerButtonHide with params false, true, false, false.
1547 * @tc.expected: cover branch windowModal_ is not CONTAINER_MODAL
1548 */
1549 context_->SetWindowModal(WindowModal::DIALOG_MODAL);
1550 context_->SetContainerButtonHide(false, true, false, false);
1551 EXPECT_FALSE(containerPattern->hideSplitButton_);
1552 }
1553
1554 /**
1555 * @tc.name: PipelineContextTestNg043
1556 * @tc.desc: Test SetCloseButtonStatus function.
1557 * @tc.type: FUNC
1558 */
1559 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg043, TestSize.Level1)
1560 {
1561 /**
1562 * @tc.steps1: initialize root node and containerModal node.
1563 * @tc.expected: root node and containerModal node are not null.
1564 */
1565 ASSERT_NE(context_, nullptr);
1566 context_->SetWindowModal(WindowModal::CONTAINER_MODAL);
1567 ASSERT_NE(context_->window_, nullptr);
1568 context_->SetupRootElement();
1569 ASSERT_NE(context_->GetRootElement(), nullptr);
1570 auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
1571 ASSERT_NE(containerNode, nullptr);
1572 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1573 ASSERT_NE(containerPattern, nullptr);
1574 auto columNode = AceType::DynamicCast<FrameNode>(containerNode->GetChildren().front());
1575 CHECK_NULL_VOID(columNode);
1576 auto titleNode = AceType::DynamicCast<FrameNode>(columNode->GetChildren().front());
1577 CHECK_NULL_VOID(titleNode);
1578 auto closeButton = AceType::DynamicCast<FrameNode>(titleNode->GetChildAtIndex(CLOSE_BUTTON_INDEX));
1579 CHECK_NULL_VOID(closeButton);
1580 auto buttonEvent = closeButton->GetOrCreateEventHub<ButtonEventHub>();
1581 CHECK_NULL_VOID(buttonEvent);
1582 /**
1583 * @tc.steps2: call SetCloseButtonStatus with params true.
1584 * @tc.expected: CloseButton IsEnabled return true.
1585 */
1586 context_->SetCloseButtonStatus(true);
1587 EXPECT_EQ(buttonEvent->IsEnabled(), true);
1588 /**
1589 * @tc.steps3: call SetCloseButtonStatus with params false.
1590 * @tc.expected: CloseButton IsEnabled return false.
1591 */
1592 context_->SetCloseButtonStatus(false);
1593 EXPECT_EQ(buttonEvent->IsEnabled(), false);
1594 }
1595
1596 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg060, TestSize.Level1)
1597 {
1598 /**
1599 * @tc.steps1: initialize parameters.
1600 * @tc.expected: All pointer is non-null.
1601 */
1602 ASSERT_NE(context_, nullptr);
1603 context_->SetupRootElement();
1604 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1605 auto& windowConfig = frontend->GetWindowConfig();
1606 windowConfig.designWidth = DEFAULT_INT1;
1607 context_->weakFrontend_ = frontend;
1608 context_->SetTextFieldManager(AceType::MakeRefPtr<TextFieldManagerNG>());
1609
1610 /**
1611 * @tc.steps2: Set EnableAvoidKeyboardMode is true.
1612 * @tc.expected: get KeyboardSafeAreaEnabled is true.
1613 */
1614 context_->SetEnableKeyBoardAvoidMode(KeyBoardAvoidMode::RESIZE);
1615 EXPECT_TRUE(context_->GetSafeAreaManager()->KeyboardSafeAreaEnabled());
1616
1617 /**
1618 * @tc.steps3: set root height and change virtual keyboard height.
1619 * @tc.expected: Resize the root height after virtual keyboard change.
1620 */
1621
1622 auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
1623 ASSERT_NE(containerNode, nullptr);
1624 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1625 ASSERT_NE(containerPattern, nullptr);
1626 auto columNode = AceType::DynamicCast<FrameNode>(containerNode->GetChildren().front());
1627 CHECK_NULL_VOID(columNode);
1628
1629 std::vector<std::vector<int>> params = { { 100, 400, 100 }, { 300, 100, 300 }, { 400, -300, 400 },
1630 { 200, 0, 200 } };
1631 for (int turn = 0; turn < params.size(); turn++) {
1632 context_->rootHeight_ = params[turn][0];
1633 context_->OnVirtualKeyboardHeightChange(params[turn][1]);
1634 EXPECT_EQ(context_->GetRootHeight(), params[turn][2]);
1635 }
1636 }
1637 /**
1638 * @tc.name: PipelineContextTestNg061
1639 * @tc.desc: Test the function WindowUnFocus.
1640 * @tc.type: FUNC
1641 */
1642 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg061, TestSize.Level1)
1643 {
1644 /**
1645 * @tc.steps1: initialize parameters.
1646 * @tc.expected: All pointer is non-null.
1647 */
1648 ASSERT_NE(context_, nullptr);
1649 context_->SetupRootElement();
1650 ASSERT_NE(context_->rootNode_, nullptr);
1651 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
1652 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1653
1654 /**
1655 * @tc.steps3: Call the function WindowUnFocus with WindowFocus(true).
1656 * @tc.expected: containerPattern isFocus_ is true.
1657 */
1658 containerPattern->isFocus_ = true;
1659 containerPattern->OnWindowForceUnfocused();
1660 EXPECT_TRUE(containerPattern->isFocus_);
1661
1662 /**
1663 * @tc.steps2: Call the function WindowUnFocus with WindowFocus(false).
1664 * @tc.expected: containerPattern isFocus_ is false.
1665 */
1666 containerPattern->WindowFocus(false);
1667 containerPattern->OnWindowForceUnfocused();
1668 EXPECT_FALSE(containerPattern->isFocus_);
1669 }
1670
1671 /**
1672 * @tc.name: PipelineContextTestNg088
1673 * @tc.desc: Test the function FlushRequestFocus.
1674 * @tc.type: FUNC
1675 */
1676 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg088, TestSize.Level1)
1677 {
1678 /**
1679 * @tc.steps1: initialize parameters.
1680 * @tc.expected: All pointer is non-null.
1681 */
1682 ASSERT_NE(context_, nullptr);
1683 context_->SetupRootElement();
1684
1685 /**
1686 * @tc.steps2: Call the function FlushRequestFocus.
1687 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
1688 */
1689 context_->FlushRequestFocus();
1690 EXPECT_EQ(context_->dirtyRequestFocusNode_.Upgrade(), nullptr);
1691 context_->dirtyRequestFocusNode_ = frameNode_;
1692 EXPECT_NE(context_->dirtyRequestFocusNode_.Upgrade(), nullptr);
1693 }
1694
1695 /**
1696 * @tc.name: PipelineContextTestNg089
1697 * @tc.desc: Test the function FlushFocusScroll.
1698 * @tc.type: FUNC
1699 */
1700 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg089, TestSize.Level1)
1701 {
1702 /**
1703 * @tc.steps1: initialize parameters.
1704 * @tc.expected: All pointer is non-null.
1705 */
1706 ASSERT_NE(context_, nullptr);
1707 context_->SetupRootElement();
1708
1709 /**
1710 * @tc.steps2: Call the function FlushRequestFocus.
1711 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
1712 */
1713 context_->focusManager_.Reset();
1714 context_->FlushFocusScroll();
1715 EXPECT_EQ(context_->focusManager_, nullptr);
1716 context_->GetOrCreateFocusManager();
1717 EXPECT_NE(context_->focusManager_, nullptr);
1718 }
1719
1720 /**
1721 * @tc.name: PipelineContextTestNg090
1722 * @tc.desc: Test the function FlushFocusView.
1723 * @tc.type: FUNC
1724 */
1725 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg090, TestSize.Level1)
1726 {
1727 /**
1728 * @tc.steps1: initialize parameters and call FlushFocusView.
1729 * @tc.expected: All pointer is non-null.
1730 */
1731 ASSERT_NE(context_, nullptr);
1732 context_->SetupRootElement();
1733 context_->SetupSubRootElement();
1734
1735 context_->FlushFocusView();
1736 EXPECT_NE(context_->focusManager_, nullptr);
1737 }
1738
1739 /**
1740 * @tc.name: PipelineContextTestNg091
1741 * @tc.desc: Test the function SendEventToAccessibilityWithNode.
1742 * @tc.type: FUNC
1743 */
1744 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg091, TestSize.Level1)
1745 {
1746 /**
1747 * @tc.steps1: initialize parameters.
1748 * @tc.expected: All pointer is non-null.
1749 */
1750 ASSERT_NE(context_, nullptr);
1751 context_->SetupRootElement();
1752
1753 /**
1754 * @tc.steps2: Call the function FlushRequestFocus.
1755 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
1756 */
1757 AccessibilityEvent event;
1758 event.windowChangeTypes = WindowUpdateType::WINDOW_UPDATE_ACTIVE;
1759 event.type = AccessibilityEventType::PAGE_CHANGE;
1760 auto frameNodeId_091 = ElementRegister::GetInstance()->MakeUniqueId();
1761 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_091, nullptr);
1762 CHECK_NULL_VOID(frameNode);
1763 context_->SendEventToAccessibilityWithNode(event, frameNode);
1764 bool accessibilityEnabled = AceApplicationInfo::GetInstance().IsAccessibilityEnabled();
1765 EXPECT_FALSE(accessibilityEnabled);
1766
1767 AceApplicationInfo::GetInstance().SetAccessibilityEnabled(true);
1768 context_->SendEventToAccessibilityWithNode(event, frameNode);
1769 accessibilityEnabled = AceApplicationInfo::GetInstance().IsAccessibilityEnabled();
1770 EXPECT_TRUE(accessibilityEnabled);
1771 }
1772
1773 /**
1774 * @tc.name: PipelineContextTestNg092
1775 * @tc.desc: Test the function GetContainerModalButtonsRect.
1776 * @tc.type: FUNC
1777 */
1778 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg092, TestSize.Level1)
1779 {
1780 /**
1781 * @tc.steps1: initialize parameters.
1782 * @tc.expected: All pointer is non-null.
1783 */
1784 ASSERT_NE(context_, nullptr);
1785 std::vector<Ace::RectF> rects;
1786 context_->TriggerOverlayNodePositionsUpdateCallback(rects);
__anona28bbc620c02(std::vector<Ace::RectF> rect) 1787 context_->RegisterOverlayNodePositionsUpdateCallback([](std::vector<Ace::RectF> rect) {});
1788 context_->TriggerOverlayNodePositionsUpdateCallback(rects);
1789 context_->windowManager_ = AceType::MakeRefPtr<WindowManager>();
1790 context_->windowModal_ = WindowModal::NORMAL;
1791 NG::RectF containerModal;
1792 NG::RectF buttons;
1793 context_->GetCustomTitleHeight();
1794 bool callbackTriggered = false;
__anona28bbc620d02(RectF&, RectF&) 1795 auto callback = [&callbackTriggered](RectF&, RectF&) { callbackTriggered = true; };
1796 context_->SubscribeContainerModalButtonsRectChange(std::move(callback));
1797 EXPECT_FALSE(context_->GetContainerModalButtonsRect(containerModal, buttons));
1798 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
1799 context_->SubscribeContainerModalButtonsRectChange(std::move(callback));
1800 EXPECT_FALSE(context_->GetContainerModalButtonsRect(containerModal, buttons));
1801 }
1802
1803 /**
1804 * @tc.name: PipelineContextTestNg093
1805 * @tc.desc: Test the function PrintVsyncInfoIfNeed.
1806 * @tc.type: FUNC
1807 */
1808 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg093, TestSize.Level1)
1809 {
1810 /**
1811 * @tc.steps1: initialize parameters.
1812 * @tc.expected: All pointer is non-null.
1813 */
1814 ASSERT_NE(context_, nullptr);
1815 ASSERT_NE(context_->GetWindow(), nullptr);
1816 EXPECT_FALSE(context_->PrintVsyncInfoIfNeed());
1817
1818 std::list<FrameInfo> dumpFrameInfos;
1819 FrameInfo frameInfo;
1820 dumpFrameInfos.push_back(frameInfo);
1821 context_->dumpFrameInfos_ = dumpFrameInfos;
1822 EXPECT_FALSE(context_->PrintVsyncInfoIfNeed());
1823 context_->dumpFrameInfos_.back().frameRecvTime_ = -1;
1824 EXPECT_FALSE(context_->PrintVsyncInfoIfNeed());
1825 context_->dumpFrameInfos_.clear();
1826 }
1827
1828 /**
1829 * @tc.name: PipelineContextTestNg094
1830 * @tc.desc: Test the function ChangeDarkModeBrightness.
1831 * @tc.type: FUNC
1832 */
1833 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg094, TestSize.Level1)
1834 {
1835 /**
1836 * @tc.steps1: initialize parameters.
1837 * @tc.expected: All pointer is non-null.
1838 */
1839 ASSERT_NE(context_, nullptr);
1840 context_->windowManager_ = AceType::MakeRefPtr<WindowManager>();
1841
1842 MockContainer::SetMockColorMode(ColorMode::DARK);
1843 context_->SetAppBgColor(Color::BLACK);
1844 context_->ChangeDarkModeBrightness();
1845 context_->SetIsJsCard(true);
1846 context_->ChangeDarkModeBrightness();
1847 MockContainer::Current()->SetIsFormRender(true);
1848 context_->ChangeDarkModeBrightness();
1849 MockContainer::Current()->SetIsDynamicRender(true);
1850 context_->ChangeDarkModeBrightness();
1851 MockContainer::Current()->SetIsUIExtensionWindow(true);
1852 context_->ChangeDarkModeBrightness();
1853 auto rsUIDirector = context_->GetRSUIDirector();
1854 context_->RSTransactionBegin(rsUIDirector);
1855 context_->SetAppBgColor(Color::BLUE);
1856 context_->RSTransactionCommit(rsUIDirector);
1857 context_->ChangeDarkModeBrightness();
1858 MockContainer::SetMockColorMode(ColorMode::COLOR_MODE_UNDEFINED);
1859 context_->ChangeDarkModeBrightness();
1860 EXPECT_NE(context_->stageManager_, nullptr);
1861 }
1862
1863 /**
1864 * @tc.name: PipelineContextTestNg101
1865 * @tc.desc: Test the function FlushDirtyPropertyNodes.
1866 * @tc.type: FUNC
1867 */
1868 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg101, TestSize.Level1)
1869 {
1870 /**
1871 * @tc.steps1: initialize parameters.
1872 * @tc.expected: All pointer is non-null.
1873 */
1874 ASSERT_NE(context_, nullptr);
1875
1876 /**
1877 * @tc.steps2: Call the function FlushDirtyPropertyNodes.
1878 * @tc.expected: The dirtyPropertyNodes_ is empty.
1879 */
1880 context_->FlushDirtyPropertyNodes();
1881 EXPECT_TRUE(context_->dirtyPropertyNodes_.empty());
1882 }
1883
1884 /**
1885 * @tc.name: PipelineContextTestNg102
1886 * @tc.desc: Test the MouseHover.
1887 * @tc.type: FUNC
1888 */
1889 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg102, TestSize.Level1)
1890 {
1891 /**
1892 * @tc.steps1: initialize parameters.
1893 */
1894 ASSERT_NE(context_, nullptr);
1895 context_->rootNode_ = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
1896 context_->mouseEvents_.clear();
1897 ASSERT_NE(context_->rootNode_, nullptr);
1898 ASSERT_NE(context_->lastMouseEvent_, nullptr);
1899
1900 /**
1901 * @tc.steps2: Call the function FlushMouseEvent.
1902 */
1903 MouseEvent event;
1904 event.x = 12.345f;
1905 event.y = 12.345f;
1906 context_->mouseEvents_[context_->rootNode_].emplace_back(event);
1907 context_->FlushMouseEvent();
1908 for (const auto& [node, mouseEvents] : context_->mouseEvents_) {
1909 EXPECT_EQ(mouseEvents.size(), 1);
1910 EXPECT_EQ(mouseEvents.back().x, 12.345f);
1911 EXPECT_EQ(mouseEvents.back().y, 12.345f);
1912 }
1913 context_->mouseEvents_.clear();
1914
1915 /**
1916 * @tc.steps2: Call the function FlushMouseEvent.
1917 * @param: set lastMouseEvent_ is not null
1918 */
1919 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(event);
1920 context_->lastMouseEvent_->action = MouseAction::MOVE;
1921 event.x = 54.321f;
1922 event.y = 54.321f;
1923 context_->mouseEvents_[context_->rootNode_].emplace_back(event);
1924 EXPECT_NE(static_cast<int>(context_->lastMouseEvent_->action), 5);
1925 context_->FlushMouseEvent();
1926 for (const auto& [node, mouseEvents] : context_->mouseEvents_) {
1927 EXPECT_EQ(mouseEvents.size(), 0);
1928 }
1929 context_->mouseEvents_.clear();
1930 }
1931
1932 /**
1933 * @tc.name: PipelineContextTestNg103
1934 * @tc.desc: Test the function IsFormRenderExceptDynamicComponent
1935 * @tc.type: FUNC
1936 */
1937 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg103, TestSize.Level1)
1938 {
1939 /**
1940 * @tc.steps1: initialize parameters.
1941 * @tc.expected: All pointer is non-null.
1942 */
1943 ASSERT_NE(context_, nullptr);
1944 context_->minPlatformVersion_ = static_cast<int32_t>(PlatformVersion::VERSION_THIRTEEN);
1945 bool isFormRender = context_->IsFormRenderExceptDynamicComponent();
1946 ASSERT_EQ(isFormRender, true);
1947 }
1948
1949 /**
1950 * @tc.name: IsDirtyLayoutNodesEmpty
1951 * @tc.desc: Test IsDirtyLayoutNodesEmpty.
1952 * @tc.type: FUNC
1953 */
1954 HWTEST_F(PipelineContextTestNg, IsDirtyLayoutNodesEmpty, TestSize.Level1)
1955 {
1956 /**
1957 * @tc.steps1: Create taskScheduler.
1958 */
1959 UITaskScheduler taskScheduler;
1960
1961 /**
1962 * @tc.steps2: Create some frameNode and configure the required parameters.
1963 */
1964 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, 1, nullptr);
1965 frameNode->layoutProperty_ = nullptr;
1966 auto frameNode2 = FrameNode::GetOrCreateFrameNode(TEST_TAG, 2, nullptr);
1967
1968 /**
1969 * @tc.steps3: Call AddDirtyLayoutNode with different parameters.
1970 * @tc.expected: IsDirtyLayoutNodesEmpty return false.
1971 */
1972 taskScheduler.AddDirtyLayoutNode(frameNode);
1973 taskScheduler.AddDirtyLayoutNode(frameNode2);
1974 EXPECT_FALSE(taskScheduler.IsDirtyLayoutNodesEmpty());
1975 context_->dirtyNodes_.clear();
1976 }
1977
1978 /**
1979 * @tc.name: IsDirtyNodesEmpty
1980 * @tc.desc: Test IsDirtyNodesEmpty.
1981 * @tc.type: FUNC
1982 */
1983 HWTEST_F(PipelineContextTestNg, IsDirtyNodesEmpty, TestSize.Level1)
1984 {
1985 /**
1986 * @tc.steps1: initialize parameters.Create taskScheduler.
1987 * @tc.expected: All pointer is non-null.
1988 */
1989 ASSERT_NE(context_, nullptr);
1990 UITaskScheduler taskScheduler;
1991
1992 /**
1993 * @tc.steps2: Call the function IsDirtyNodesEmpty.
1994 * @tc.expected: The dirtyNodes is not empty.
1995 */
1996 auto customNode_1 = CustomNode::CreateCustomNode(customNodeId_ + 20, TEST_TAG);
1997 context_->AddDirtyCustomNode(customNode_1);
1998 EXPECT_FALSE(context_->IsDirtyNodesEmpty());
1999 taskScheduler.dirtyLayoutNodes_.clear();
2000 }
2001
2002 /**
2003 * @tc.name: FlushAnimationDirtysWhenExist
2004 * @tc.desc: Branch: !isDirtyLayoutNodesEmpty && !IsLayouting() && !isReloading_
2005 * Condition: isDirtyLayoutNodesEmpty = false, IsLayouting() = false, isReloading_ = false
2006 * @tc.type: FUNC
2007 */
2008 HWTEST_F(PipelineContextTestNg, FlushAnimationDirtysWhenExist, TestSize.Level1)
2009 {
2010 /**
2011 * @tc.steps1: initialize parameters.Create taskScheduler.
2012 * @tc.expected: All pointer is non-null.
2013 */
2014 ASSERT_NE(context_, nullptr);
2015 UITaskScheduler taskScheduler;
2016
2017 /**
2018 * @tc.steps2: Create some frameNode and configure the required parameters.
2019 */
2020 auto propertyNode01 = FrameNode::GetOrCreateFrameNode(TEST_TAG, 1, nullptr);
2021 auto propertyNode02 = FrameNode::GetOrCreateFrameNode(TEST_TAG, 2, nullptr);
2022
2023 /**
2024 * @tc.steps3: Call AddDirtyPropertyNode with different parameters.
2025 * @tc.expected: IsDirtyLayoutNodesEmpty return false.
2026 */
2027 taskScheduler.AddDirtyLayoutNode(propertyNode01);
2028 taskScheduler.AddDirtyLayoutNode(propertyNode02);
2029 EXPECT_FALSE(context_->IsDirtyLayoutNodesEmpty());
2030
2031 /**
2032 * @tc.steps4: Test FlushAnimationDirtysWhenExist when start animation.
2033 * @tc.expected: IsDirtyLayoutNodesEmpty return false.
2034 */
2035 AnimationOption option = AnimationOption();
2036 option.SetDuration(10);
2037 context_->FlushAnimationDirtysWhenExist(option);
2038 EXPECT_FALSE(context_->IsDirtyLayoutNodesEmpty());
2039
2040 /**
2041 * @tc.steps5: Test FlushAnimationDirtysWhenExist when start infinite animation.
2042 * @tc.expected: IsDirtyLayoutNodesEmpty return false.
2043 */
2044 context_->isReloading_ = false;
2045 taskScheduler.isLayouting_ = false;
2046 option.SetIteration(-1);
2047 context_->FlushAnimationDirtysWhenExist(option);
2048 EXPECT_TRUE(context_->IsDirtyLayoutNodesEmpty());
2049 }
2050
2051 /**
2052 * @tc.name: PipelineContextTestNg110
2053 * @tc.desc: Test UpdateLastMoveEvent.
2054 * @tc.type: FUNC
2055 */
2056 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg110, TestSize.Level1)
2057 {
2058 MouseEvent mouseEvent;
2059 mouseEvent.action = MouseAction::WINDOW_LEAVE;
2060 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(mouseEvent);
2061 context_->UpdateLastMoveEvent(mouseEvent);
2062 EXPECT_EQ(context_->lastMouseEvent_->isMockWindowTransFlag, false);
2063 }
2064
2065 /**
2066 * @tc.name: PipelineContextTestNg111
2067 * @tc.desc: Test UpdateLastMoveEvent.
2068 * @tc.type: FUNC
2069 */
2070 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg111, TestSize.Level1)
2071 {
2072 MouseEvent mouseEvent;
2073 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(mouseEvent);
2074 mouseEvent.targetDisplayId = 10;
2075 mouseEvent.mockFlushEvent = false;
2076 context_->UpdateLastMoveEvent(mouseEvent);
2077 EXPECT_EQ(context_->lastMouseEvent_->isMockWindowTransFlag, false);
2078 EXPECT_EQ(context_->lastMouseEvent_->targetDisplayId, 10);
2079 }
2080
2081 /**
2082 * @tc.name: PipelineContextTestNg112
2083 * @tc.desc: Test SetDisplayWindowRectInfo.
2084 * @tc.type: FUNC
2085 */
2086 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg112, TestSize.Level1)
2087 {
2088 Rect rect;
2089 MouseEvent mouseEvent;
2090 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(mouseEvent);
2091 context_->displayWindowRectInfo_ = rect;
2092 context_->lastMouseEvent_->x = 0.0;
2093 context_->SetDisplayWindowRectInfo(rect);
2094 EXPECT_EQ(context_->lastMouseEvent_->x, 0);
2095 }
2096
2097 /**
2098 * @tc.name: PipelineContextTestNg113
2099 * @tc.desc: Test SetDisplayWindowRectInfo.
2100 * @tc.type: FUNC
2101 */
2102 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg113, TestSize.Level1)
2103 {
2104 Rect rect;
2105 rect.SetLeft(10.0);
2106 MouseEvent mouseEvent;
2107 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(mouseEvent);
2108 context_->lastMouseEvent_->x = 0.0;
2109 context_->displayWindowRectInfo_ = rect;
2110 context_->SetDisplayWindowRectInfo(rect);
2111 EXPECT_EQ(context_->lastMouseEvent_->x, 0.0);
2112 }
2113
2114 /**
2115 * @tc.name: PipelineContextTestNg114
2116 * @tc.desc: Test SetDisplayWindowRectInfo.
2117 * @tc.type: FUNC
2118 */
2119 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg114, TestSize.Level1)
2120 {
2121 Rect rect;
2122 rect.SetLeft(10.0);
2123 MouseEvent mouseEvent;
2124 context_->lastMouseEvent_ = nullptr;
2125 context_->displayWindowRectInfo_ = rect;
2126 context_->SetDisplayWindowRectInfo(rect);
2127 EXPECT_EQ(context_->displayWindowRectInfo_.Left(), rect.Left());
2128 }
2129
2130 /**
2131 * @tc.name: PipelineContextTestNg115
2132 * @tc.desc: Test HandleTouchHoverOut.
2133 * @tc.type: FUNC
2134 */
2135 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg115, TestSize.Level1)
2136 {
2137 TouchEvent event;
2138 event.force = 10.0;
2139 event.sourceTool = SourceTool::UNKNOWN;
2140 context_->lastSourceType_ = SourceType::NONE;
2141 context_->HandleTouchHoverOut(event);
2142 EXPECT_EQ(context_->lastSourceType_, SourceType::NONE);
2143 }
2144
2145 /**
2146 * @tc.name: PipelineContextTestNg116
2147 * @tc.desc: Test HandleTouchHoverOut.
2148 * @tc.type: FUNC
2149 */
2150 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg116, TestSize.Level1)
2151 {
2152 int32_t backupApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion();
2153 AceApplicationInfo::GetInstance().SetApiTargetVersion(static_cast<int32_t>(PlatformVersion::VERSION_TWELVE));
2154 TouchEvent event;
2155 event.force = 10.0;
2156 event.sourceTool = SourceTool::FINGER;
2157 context_->lastSourceType_ = SourceType::NONE;
2158 TouchTestResult testResult;
2159 context_->eventManager_->mouseTestResults_[0] = testResult;
2160 EXPECT_FALSE(context_->eventManager_->mouseTestResults_.empty());
2161 context_->HandleTouchHoverOut(event);
2162 AceApplicationInfo::GetInstance().SetApiTargetVersion(backupApiVersion);
2163 EXPECT_TRUE(context_->eventManager_->mouseTestResults_.empty());
2164 }
2165
2166 /**
2167 * @tc.name: PipelineContextTestNg117
2168 * @tc.desc: Test FlushMouseEventForHover.
2169 * @tc.type: FUNC
2170 */
2171 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg117, TestSize.Level1)
2172 {
2173 context_->SetIsTransFlag(false);
2174 MouseEvent mouseEvent;
2175 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(mouseEvent);
2176 context_->lastMouseEvent_->pointerEvent = nullptr;
2177 context_->FlushMouseEventForHover();
2178 EXPECT_FALSE(context_->lastMouseEvent_->pointerEvent);
2179 }
2180
2181 /**
2182 * @tc.name: PipelineContextTestNg118
2183 * @tc.desc: Test FlushMouseEventForHover.
2184 * @tc.type: FUNC
2185 */
2186 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg118, TestSize.Level1)
2187 {
2188 context_->SetIsTransFlag(true);
2189 context_->lastMouseEvent_ = nullptr;
2190 context_->FlushMouseEventForHover();
2191 EXPECT_FALSE(context_->lastMouseEvent_);
2192 }
2193
2194 /**
2195 * @tc.name: PipelineContextTestNg119
2196 * @tc.desc: Test FlushMouseEventForHover.
2197 * @tc.type: FUNC
2198 */
2199 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg119, TestSize.Level1)
2200 {
2201 MouseEvent mouseEvent;
2202 mouseEvent.sourceType = SourceType::TOUCH_PAD;
2203 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(mouseEvent);
2204 context_->lastMouseEvent_->pointerEvent = nullptr;
2205 context_->SetIsTransFlag(true);
2206 context_->FlushMouseEventForHover();
2207 EXPECT_FALSE(context_->lastMouseEvent_->pointerEvent);
2208 }
2209
2210 /**
2211 * @tc.name: PipelineContextTestNg120
2212 * @tc.desc: Test FlushMouseEventForHover.
2213 * @tc.type: FUNC
2214 */
2215 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg120, TestSize.Level1)
2216 {
2217 MouseEvent mouseEvent;
2218 mouseEvent.sourceType = SourceType::MOUSE;
2219 mouseEvent.action = MouseAction::PRESS;
2220 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(mouseEvent);
2221 context_->lastMouseEvent_->pointerEvent = nullptr;
2222 context_->SetIsTransFlag(true);
2223 context_->FlushMouseEventForHover();
2224 EXPECT_FALSE(context_->lastMouseEvent_->pointerEvent);
2225 }
2226
2227 /**
2228 * @tc.name: PipelineContextTestNg121
2229 * @tc.desc: Test FlushMouseEventForHover.
2230 * @tc.type: FUNC
2231 */
2232 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg121, TestSize.Level1)
2233 {
2234 MouseEvent mouseEvent;
2235 mouseEvent.sourceType = SourceType::MOUSE;
2236 mouseEvent.action = MouseAction::MOVE;
2237 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(mouseEvent);
2238 context_->lastMouseEvent_->pointerEvent = nullptr;
2239 context_->lastSourceType_ = SourceType::TOUCH;
2240 context_->SetIsTransFlag(true);
2241 context_->FlushMouseEventForHover();
2242 EXPECT_FALSE(context_->lastMouseEvent_->pointerEvent);
2243 }
2244
2245 /**
2246 * @tc.name: PipelineContextTestNgForBundleName
2247 * @tc.desc: Test GetBundleName.
2248 * @tc.type: FUNC
2249 */
2250 HWTEST_F(PipelineContextTestNg, PipelineContextTestNgForBundleName, TestSize.Level1)
2251 {
2252 auto bundleName = context_->GetBundleName();
2253 EXPECT_EQ(bundleName, "");
2254 bundleName = MockContainer::CurrentBundleName();
2255 EXPECT_EQ(bundleName, "");
2256 MockContainer::Current()->SetBundleName("test");
2257 bundleName = MockContainer::CurrentBundleName();
2258 EXPECT_EQ(bundleName, "test");
2259 }
2260
2261 /**
2262 * @tc.name: PipelineContextTestNgForWindowRect
2263 * @tc.desc: Test GetCurrentWindowRect.
2264 * @tc.type: FUNC
2265 */
2266 HWTEST_F(PipelineContextTestNg, PipelineContextTestNgForWindowRect, TestSize.Level1)
2267 {
2268 static const uint32_t length = 666;
2269 context_->width_ = length;
2270 context_->height_ = length;
2271 auto rect = context_->GetCurrentWindowRect();
2272 EXPECT_EQ(rect.Width(), length);
2273 EXPECT_EQ(rect.Height(), length);
2274 }
2275
2276 /**
2277 * @tc.name: PipelineContextTestNg122
2278 * @tc.desc: Test FlushMouseEventForHover.
2279 * @tc.type: FUNC
2280 */
2281 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg122, TestSize.Level1)
2282 {
2283 MouseEvent mouseEvent;
2284 mouseEvent.sourceType = SourceType::MOUSE;
2285 mouseEvent.action = MouseAction::MOVE;
2286 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(mouseEvent);
2287 context_->lastMouseEvent_->pointerEvent = nullptr;
2288 context_->lastSourceType_ = SourceType::NONE;
2289 context_->lastMouseEvent_->isMockWindowTransFlag = true;
2290 context_->SetIsTransFlag(true);
2291 context_->FlushMouseEventForHover();
2292 EXPECT_FALSE(context_->lastMouseEvent_->pointerEvent);
2293 }
2294
2295 /**
2296 * @tc.name: PipelineContextTestNg123
2297 * @tc.desc: Test SetIsTransFlag.
2298 * @tc.type: FUNC
2299 */
2300 HWTEST_F(PipelineContextTestNg, SetIsTransFlagTest, TestSize.Level1)
2301 {
2302 context_->SetIsTransFlag(true);
2303 context_->SetIsTransFlag(false);
2304 context_->SetIsTransFlag(true);
2305 EXPECT_TRUE(context_->isTransFlag_);
2306 context_->SetIsTransFlag(false);
2307 context_->SetIsTransFlag(true);
2308 context_->SetIsTransFlag(false);
2309 EXPECT_FALSE(context_->isTransFlag_);
2310 }
2311
2312 /**
2313 * @tc.name: PipelineContextTestNg124
2314 * @tc.desc: Test SetFlushTSUpdates and FlushTSUpdates with a callback.
2315 * @tc.type: FUNC
2316 */
2317 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg124, TestSize.Level1)
2318 {
2319 // Checking for valid context and window
2320 ASSERT_NE(context_, nullptr);
2321 auto mockWindow = (MockWindow*)(context_->window_.get());
2322 ASSERT_NE(mockWindow, nullptr);
2323
2324 // Reset mock expectations
2325 testing::Mock::VerifyAndClearExpectations(mockWindow);
2326 testing::Mock::AllowLeak(mockWindow);
2327
2328 // Callback setup that triggers only one frame request
2329 bool callbackCalled = false;
__anona28bbc620e02(int32_t id) 2330 auto callback = [&callbackCalled](int32_t id) -> bool {
2331 callbackCalled = true;
2332 return false;
2333 };
2334
2335 // Expect RequestFrame when setting the callback
2336 EXPECT_CALL(*mockWindow, RequestFrame()).Times(AnyNumber());
2337 context_->SetFlushTSUpdates(std::move(callback));
2338
2339 // Call FlushTSUpdates and check callback runs
2340 context_->FlushTSUpdates();
2341 EXPECT_TRUE(callbackCalled);
2342 }
2343
2344
2345 /**
2346 * @tc.name: PipelineContextTestNg125
2347 * @tc.desc: Test FlushTSUpdates with callback returning true.
2348 * @tc.type: FUNC
2349 */
2350 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg125, TestSize.Level1)
2351 {
2352 // Checking for valid context and window
2353 ASSERT_NE(context_, nullptr);
2354 auto mockWindow = (MockWindow*)(context_->window_.get());
2355 ASSERT_NE(mockWindow, nullptr);
2356
2357 // Reset mock expectations
2358 testing::Mock::VerifyAndClearExpectations(mockWindow);
2359 testing::Mock::AllowLeak(mockWindow);
2360
2361 // Set up a callback that returns true once
2362 int callbackCount = 0;
__anona28bbc620f02(int32_t id) 2363 auto callback = [&callbackCount](int32_t id) -> bool {
2364 callbackCount++;
2365 return callbackCount == 1;
2366 };
2367
2368 // Expect RequestFrame when setting the callback
2369 EXPECT_CALL(*mockWindow, RequestFrame()).Times(AnyNumber());
2370 context_->SetFlushTSUpdates(std::move(callback));
2371
2372 // Call FlushTSUpdates twice
2373 context_->FlushTSUpdates(); // First call: returns true
2374 context_->FlushTSUpdates(); // Second call: returns false
2375 EXPECT_EQ(callbackCount, 2); // Callback ran twice
2376 }
2377
2378 /**
2379 * @tc.name: PipelineContextTestNg126
2380 * @tc.desc: Test FlushTSUpdates with no callback.
2381 * @tc.type: FUNC
2382 */
2383 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg126, TestSize.Level1)
2384 {
2385 ASSERT_NE(context_, nullptr);
2386 auto mockWindow = (MockWindow*)(context_->window_.get());
2387 ASSERT_NE(mockWindow, nullptr);
2388
2389 // Minimal state reset
2390 context_->SetFlushTSUpdates(nullptr);
2391 context_->dirtyNodes_.clear();
2392 context_->scheduleTasks_.clear();
2393 context_->mouseEvents_.clear();
2394 context_->isReloading_ = false;
2395 context_->onShow_ = false;
2396 context_->onFocus_ = false;
2397 context_->taskScheduler_->dirtyLayoutNodes_.clear();
2398 context_->taskScheduler_->dirtyRenderNodes_.clear();
2399 context_->dirtyPropertyNodes_.clear();
2400
2401 // Reset mock expectations
2402 testing::Mock::VerifyAndClearExpectations(mockWindow);
2403 testing::Mock::AllowLeak(mockWindow);
2404
2405 // Allow RequestFrame calls, similar to SetUpTestSuite
2406 EXPECT_CALL(*mockWindow, RequestFrame()).Times(AnyNumber());
2407
2408 context_->FlushTSUpdates();
2409
2410 // Verify no unexpected side effects
2411 EXPECT_TRUE(context_->scheduleTasks_.empty());
2412 }
2413
2414 /**
2415 * @tc.name: PipelineContextTestNg127
2416 * @tc.desc: Test the function UpdateDVSyncTime.
2417 * @tc.type: FUNC
2418 */
2419 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg127, TestSize.Level1)
2420 {
2421 /**
2422 * @tc.steps1: initialize parameters.
2423 * @tc.expected: All pointer is non-null.
2424 */
2425 ASSERT_NE(context_, nullptr);
2426 ASSERT_NE(context_->GetWindow(), nullptr);
2427 context_->commandTimeUpdate_ = true;
2428 context_->DVSyncChangeTime_ = true;
2429 context_->lastVSyncTime_ = GetSysTimestamp();
2430 std::string abilityName = "test";
2431 context_->UpdateDVSyncTime(100, abilityName, 8333333);
2432
2433 EXPECT_FALSE(context_->commandTimeUpdate_);
2434 }
2435
2436 /**
2437 * @tc.name: PipelineContextTestNg128
2438 * @tc.desc: Test function UpdateDVSyncTime
2439 * @tc.type: FUNC
2440 */
2441 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg128, TestSize.Level1)
2442 {
2443 ASSERT_NE(context_, nullptr);
2444
2445 // Minimal state reset
2446 uint64_t nanoTimestamp = 0;
2447 const std::string& abilityName = "";
2448 uint64_t vsyncPeriod = 0;
2449 context_->lastVSyncTime_ = LAST_VSYNC_TIME;
2450 context_->commandTimeUpdate_ = true;
2451 context_->UpdateDVSyncTime(nanoTimestamp, abilityName, vsyncPeriod);
2452 EXPECT_EQ(context_->commandTimeUpdate_, false);
2453
2454 // Verify no unexpected side effects
2455 nanoTimestamp = LAST_VSYNC_TIME;
2456 context_->commandTimeUpdate_ = true;
2457 context_->lastVSyncTime_ = 0;
2458 context_->DVSyncChangeTime_ = 0;
2459 context_->UpdateDVSyncTime(nanoTimestamp, abilityName, vsyncPeriod);
2460 EXPECT_EQ(context_->commandTimeUpdate_, false);
2461
2462 nanoTimestamp = LAST_VSYNC_TIME;
2463 context_->commandTimeUpdate_ = true;
2464 context_->lastVSyncTime_ = 0;
2465 context_->DVSyncChangeTime_ = GetSysTimestamp() + 16666667;
2466 context_->dvsyncTimeUseCount_ = 6;
2467 context_->UpdateDVSyncTime(nanoTimestamp, abilityName, vsyncPeriod);
2468 EXPECT_EQ(context_->commandTimeUpdate_, false);
2469 }
2470
2471 /**
2472 * @tc.name: PipelineContextTestNg129
2473 * @tc.desc: Test function UpdateDVSyncTime
2474 * @tc.type: FUNC
2475 */
2476 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg129, TestSize.Level1)
2477 {
2478 ASSERT_NE(context_, nullptr);
2479
2480 uint64_t nanoTimestamp = LAST_VSYNC_TIME;
2481 context_->commandTimeUpdate_ = true;
2482 context_->lastVSyncTime_ = 0;
2483 uint64_t vsyncPeriod = 8333333;
2484 const std::string& abilityName = "";
2485 context_->DVSyncChangeTime_ = GetSysTimestamp() + 16666667;
2486 context_->dvsyncTimeUseCount_ = 0;
2487 context_->dvsyncTimeUpdate_ = true;
2488 context_->UpdateDVSyncTime(nanoTimestamp, abilityName, vsyncPeriod);
2489 EXPECT_EQ(context_->commandTimeUpdate_, true);
2490 EXPECT_EQ(context_->dvsyncTimeUpdate_, false);
2491 context_->UpdateDVSyncTime(nanoTimestamp, abilityName, vsyncPeriod);
2492 EXPECT_EQ(context_->dvsyncTimeUpdate_, false);
2493 }
2494 } // namespace NG
2495 } // namespace OHOS::Ace