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