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 MockContainer::SetUp();
80 MockContainer::Current()->pipelineContext_ = context_;
81
82 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
83 context_->SetThemeManager(themeManager);
84 auto themeConstants = AceType::MakeRefPtr<ThemeConstants>(nullptr);
85 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<ContainerModalTheme>()));
86 EXPECT_CALL(*themeManager, GetThemeConstants()).WillRepeatedly(Return(themeConstants));
87 }
88
TearDownTestSuite()89 void PipelineContextTestNg::TearDownTestSuite()
90 {
91 context_->Destroy();
92 context_->window_.reset();
93 MockContainer::TearDown();
94 }
95
CreateCycleDirtyNode(int cycle,bool & flagUpdate)96 void PipelineContextTestNg::CreateCycleDirtyNode(int cycle, bool& flagUpdate)
97 {
98 if (cycle <= 0) {
99 return;
100 }
101 cycle -= 1;
102 auto customNodeTemp = CustomNode::CreateCustomNode(customNodeId_ + cycle + 100, TEST_TAG);
103 customNodeTemp->SetUpdateFunction([cycle, &flagUpdate]() {
104 PipelineContextTestNg::CreateCycleDirtyNode(cycle, flagUpdate);
105 flagUpdate = !flagUpdate;
106 });
107 context_->AddDirtyCustomNode(customNodeTemp);
108 }
109
110 /**
111 * @tc.name: PipelineContextTestNg001
112 * @tc.desc: Test the function FlushDirtyNodeUpdate.
113 * @tc.type: FUNC
114 */
115 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg001, TestSize.Level1)
116 {
117 /**
118 * @tc.steps1: initialize parameters.
119 * @tc.expected: All pointer is non-null.
120 */
121 ASSERT_NE(context_, nullptr);
122 bool flagUpdate = false;
__anon0f9446780202() 123 customNode_->SetUpdateFunction([&flagUpdate]() { flagUpdate = true; });
124 context_->AddDirtyCustomNode(customNode_);
125
126 /**
127 * @tc.steps2: Call the function FlushDirtyNodeUpdate.
128 * @tc.expected: The flagUpdate is changed to true.
129 */
130 context_->FlushDirtyNodeUpdate();
131 EXPECT_TRUE(flagUpdate);
132
133 /**
134 * @tc.steps2: Call the function FlushDirtyNodeUpdate.
135 * @tc.expected: The flagUpdate is true.
136 * @tc.expected: The dirtyNodes is not empty.
137 */
138 auto customNode_1 = CustomNode::CreateCustomNode(customNodeId_ + 20, TEST_TAG);
__anon0f9446780302() 139 customNode_1->SetUpdateFunction([&flagUpdate]() { CreateCycleDirtyNode(5, flagUpdate); });
140 context_->AddDirtyCustomNode(customNode_1);
141 context_->AddDirtyCustomNode(frameNode_);
142 context_->FlushDirtyNodeUpdate();
143 EXPECT_TRUE(flagUpdate);
144 EXPECT_FALSE(context_->dirtyNodes_.empty());
145 context_->dirtyNodes_.clear();
146 }
147
148 /**
149 * @tc.name: PipelineContextTestNg002
150 * @tc.desc: Test the function FlushVsync, AddVisibleAreaChangeNode, HandleVisibleAreaChangeEvent and .
151 * @tc.type: FUNC
152 */
153 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg002, TestSize.Level1)
154 {
155 /**
156 * @tc.steps1: initialize parameters.
157 * @tc.expected: All pointer is non-null.
158 */
159 ASSERT_NE(context_, nullptr);
160 context_->SetupRootElement();
161
162 /**
163 * @tc.steps2: Call the function AddOnAreaChangeNode.
164 */
165 context_->onVisibleAreaChangeNodeIds_.clear();
166 context_->AddOnAreaChangeNode(frameNode_->GetId());
167 context_->AddOnAreaChangeNode(customNode_->GetId());
168 context_->AddOnAreaChangeNode(ElementRegister::UndefinedElementId);
169
170 /**
171 * @tc.steps3: Call the function AddVisibleAreaChangeNode.
172 * @tc.expected: The drawDelegate_ is null.
173 */
174 context_->onAreaChangeNodeIds_.clear();
175 context_->onAreaChangeNodeIds_.emplace(NOT_REGISTER_ID);
176 context_->onAreaChangeNodeIds_.emplace(customNode_->nodeId_);
177 context_->AddVisibleAreaChangeNode(frameNode_, { DEFAULT_DOUBLE1 }, nullptr);
178 context_->AddVisibleAreaChangeNode(frameNode_, { DEFAULT_DOUBLE1 }, nullptr, false);
179 EXPECT_EQ(context_->onVisibleAreaChangeNodeIds_.size(), DEFAULT_SIZE1);
180 context_->onVisibleAreaChangeNodeIds_.emplace(customNode_->GetId());
181 context_->onVisibleAreaChangeNodeIds_.emplace(ElementRegister::UndefinedElementId);
182 EXPECT_EQ(context_->onVisibleAreaChangeNodeIds_.size(), DEFAULT_SIZE3);
183
184 /**
185 * @tc.steps4: Call the function FlushVsync with isEtsCard=false.
186 * @tc.expected: The drawDelegate_ is null.
187 */
188 context_->onShow_ = false;
189 context_->SetIsFormRender(false);
190 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
191 EXPECT_EQ(context_->drawDelegate_, nullptr);
192
193 /**
194 * @tc.steps5: Call the function FlushVsync with isEtsCard=false.
195 * @tc.expected: The drawDelegate_ is non-null.
196 */
197 context_->onFocus_ = false;
198 context_->onAreaChangeNodeIds_.clear();
199 context_->SetDrawDelegate(std::make_unique<DrawDelegate>());
200 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
201 EXPECT_NE(context_->drawDelegate_, nullptr);
202 /**
203 * @tc.steps6: Call the function FlushVsync with isEtsCard=false
204 and processName equals to "".
205 * @tc.expected: The drawDelegate_ is non-null.
206 */
207 AceApplicationInfo::GetInstance().processName_ = "";
208 context_->onShow_ = true;
209 context_->onFocus_ = true;
210 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
211 EXPECT_NE(context_->drawDelegate_, nullptr);
212 }
213
214 /**
215 * @tc.name: PipelineContextTestNg003
216 * @tc.desc: Test the function FlushVsync and functions FlushLayoutTask and FlushRenderTask of the UITaskScheduler.
217 * @tc.type: FUNC
218 */
219 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg003, TestSize.Level1)
220 {
221 /**
222 * @tc.steps1: initialize parameters.
223 * @tc.expected: All pointer is non-null.
224 */
225 ASSERT_NE(context_, nullptr);
226 context_->SetupRootElement();
227
228 /**
229 * @tc.steps2: Add dirty layout and render nodes to taskScheduler_ to test functions
230 * FlushLayoutTask and FlushRenderTask of the UITaskScheduler.
231 */
232 context_->taskScheduler_->AddDirtyLayoutNode(frameNode_);
233 context_->taskScheduler_->AddDirtyRenderNode(frameNode_);
234 context_->taskScheduler_->dirtyRenderNodes_[frameNode_->GetPageId()].emplace(nullptr);
235
236 /**
237 * @tc.steps3: Call the function FlushVsync with isEtsCard=true.
238 * @tc.expected: The drawDelegate_ is null.
239 */
240 context_->onShow_ = true;
241 context_->onFocus_ = false;
242 context_->SetIsFormRender(true);
243 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
244 EXPECT_EQ(context_->drawDelegate_, nullptr);
245
246 /**
247 * @tc.steps4: Call the function FlushVsync with isEtsCard=true.
248 * @tc.expected: The drawDelegate_ is non-null.
249 */
250 context_->onFocus_ = true;
251 context_->SetDrawDelegate(std::make_unique<DrawDelegate>());
252 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
253 EXPECT_EQ(context_->drawDelegate_, nullptr);
254 }
255
256 /**
257 * @tc.name: PipelineContextTestNg004
258 * @tc.desc: Test the function FlushAnimation.
259 * @tc.type: FUNC
260 */
261 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg004, TestSize.Level1)
262 {
263 /**
264 * @tc.steps1: initialize parameters.
265 * @tc.expected: All pointer is non-null.
266 */
267 ASSERT_NE(context_, nullptr);
268
269 /**
270 * @tc.steps2: Call the function FlushAnimation with empty scheduleTasks_.
271 * @tc.expected: The scheduleTasks_ is null.
272 */
273 context_->FlushAnimation(NANO_TIME_STAMP);
274 EXPECT_TRUE(context_->scheduleTasks_.empty());
275
276 /**
277 * @tc.steps3: Call the function FlushAnimation with unempty scheduleTasks_.
278 * @tc.expected: The nanoTimestamp of scheduleTask is equal to NANO_TIME_STAMP.
279 */
280 auto scheduleTask = AceType::MakeRefPtr<MockScheduleTask>();
281 EXPECT_NE(scheduleTask->GetNanoTimestamp(), NANO_TIME_STAMP);
282 context_->AddScheduleTask(scheduleTask);
283 context_->AddScheduleTask(nullptr);
284 context_->FlushAnimation(NANO_TIME_STAMP);
285 EXPECT_EQ(scheduleTask->GetNanoTimestamp(), DEFAULT_INT0);
286 }
287
288 /**
289 * @tc.name: PipelineContextTestNg005
290 * @tc.desc: Test the function FlushFocus.
291 * @tc.type: FUNC
292 */
293 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg005, TestSize.Level1)
294 {
295 /**
296 * @tc.steps1: initialize parameters.
297 * @tc.expected: All pointer is non-null.
298 */
299 ASSERT_NE(context_, nullptr);
300 context_->SetupRootElement();
301
302 /**
303 * @tc.steps2: Call the function FlushFocus.
304 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
305 */
306 context_->FlushFocus();
307 EXPECT_EQ(context_->dirtyFocusNode_.Upgrade(), nullptr);
308 /**
309 * @tc.steps2: Init a frameNode and SetFocusType with Node, Add dirty focus and call FlushFocus
310 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
311 */
312 auto eventHub = frameNode_->GetEventHub<EventHub>();
313 ASSERT_NE(eventHub, nullptr);
314 auto focusHub = eventHub->GetOrCreateFocusHub();
315 ASSERT_NE(focusHub, nullptr);
316 focusHub->SetFocusType(FocusType::NODE);
317 context_->AddDirtyFocus(frameNode_);
318 auto dirtyFocusNode = context_->dirtyFocusNode_.Upgrade();
319 ASSERT_NE(dirtyFocusNode, nullptr);
320 EXPECT_EQ(dirtyFocusNode->GetFocusType(), FocusType::NODE);
321 context_->FlushFocus();
322 EXPECT_EQ(context_->dirtyFocusNode_.Upgrade(), nullptr);
323 /**
324 * @tc.steps3: Init a new frameNode and SetFocusType with Node.
325 Add dirty focus, free focusHub_ and call FlushFocus
326 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
327 */
328 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
329 frameNode_ = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
330 eventHub = frameNode_->GetEventHub<EventHub>();
331 ASSERT_NE(eventHub, nullptr);
332 focusHub = eventHub->GetOrCreateFocusHub();
333 ASSERT_NE(focusHub, nullptr);
334 focusHub->SetFocusType(FocusType::NODE);
335 context_->AddDirtyFocus(frameNode_);
336 dirtyFocusNode = context_->dirtyFocusNode_.Upgrade();
337 ASSERT_NE(dirtyFocusNode, nullptr);
338 EXPECT_EQ(dirtyFocusNode->GetFocusType(), FocusType::NODE);
339 frameNode_->eventHub_->focusHub_ = nullptr;
340 context_->FlushFocus();
341 EXPECT_EQ(context_->dirtyFocusNode_.Upgrade(), nullptr);
342 }
343
344 /**
345 * @tc.name: PipelineContextTestNg006
346 * @tc.desc: Test the function FlushBuildFinishCallbacks.
347 * @tc.type: FUNC
348 */
349 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg006, TestSize.Level1)
350 {
351 /**
352 * @tc.steps1: initialize parameters.
353 * @tc.expected: All pointer is non-null.
354 */
355 ASSERT_NE(context_, nullptr);
356 bool flagCbk = false;
357 context_->AddBuildFinishCallBack(nullptr);
__anon0f9446780402() 358 context_->AddBuildFinishCallBack([&flagCbk]() { flagCbk = true; });
359
360 /**
361 * @tc.steps2: Call the function FlushBuildFinishCallbacks.
362 * @tc.expected: The flagCbk is changed to true.
363 */
364 context_->FlushBuildFinishCallbacks();
365 EXPECT_TRUE(flagCbk);
366 }
367
368 /**
369 * @tc.name: PipelineContextTestNg007
370 * @tc.desc: Test the function SetupRootElement.
371 * @tc.type: FUNC
372 */
373 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg007, TestSize.Level1)
374 {
375 /**
376 * @tc.steps1: initialize parameters.
377 * @tc.expected: All pointer is non-null.
378 */
379 ASSERT_NE(context_, nullptr);
380 context_->windowManager_ = AceType::MakeRefPtr<WindowManager>();
381 /**
382 * @tc.steps2: Call the function SetupRootElement with isJsCard_ = true.
383 * @tc.expected: The stageManager_ is non-null.
384 */
385 context_->SetIsJsCard(true);
386 context_->windowModal_ = WindowModal::NORMAL;
387 context_->GetContainerModalNode();
388 context_->SetupRootElement();
389 EXPECT_NE(context_->stageManager_, nullptr);
390
391 /**
392 * @tc.steps3: Call the function SetupRootElement with isJsCard_ = false.
393 * @tc.expected: The stageManager_ is non-null.
394 */
395 context_->SetIsJsCard(false);
396 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
397 context_->GetContainerModalNode();
398 context_->SetupRootElement();
399 EXPECT_NE(context_->stageManager_, nullptr);
400 }
401
402 /**
403 * @tc.name: PipelineContextTestNg008
404 * @tc.desc: Test the function SetupSubRootElement.
405 * @tc.type: FUNC
406 */
407 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg008, TestSize.Level1)
408 {
409 /**
410 * @tc.steps1: initialize parameters.
411 * @tc.expected: All pointer is non-null.
412 */
413 ASSERT_NE(context_, nullptr);
414
415 /**
416 * @tc.steps2: Call the function SetupSubRootElement with isJsCard_ = true.
417 * @tc.expected: The stageManager_ is non-null.
418 */
419 context_->SetIsJsCard(true);
420 context_->SetupSubRootElement();
421 EXPECT_NE(context_->stageManager_, nullptr);
422
423 /**
424 * @tc.steps3: Call the function SetupSubRootElement with isJsCard_ = false.
425 * @tc.expected: The stageManager_ is non-null.
426 */
427 context_->SetIsJsCard(false);
428 context_->SetupSubRootElement();
429 EXPECT_NE(context_->stageManager_, nullptr);
430 }
431
432 /**
433 * @tc.name: PipelineContextTestNg009
434 * @tc.desc: Test the function OnSurfaceChanged.
435 * @tc.type: FUNC
436 */
437 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg009, TestSize.Level1)
438 {
439 /**
440 * @tc.steps1: initialize parameters.
441 * @tc.expected: All pointer is non-null.
442 */
443 ASSERT_NE(context_, nullptr);
444 context_->rootWidth_ = DEFAULT_INT10;
445 context_->rootHeight_ = DEFAULT_INT10;
446 bool flagCbk = false;
447
448 /**
449 * @tc.steps2: Call the function OnSurfaceChanged with DEFAULT_INT10.
450 * @tc.expected: The flagCbk is changed to true.
451 */
452 context_->SetForegroundCalled(true);
__anon0f9446780502() 453 context_->SetNextFrameLayoutCallback([&flagCbk]() { flagCbk = !flagCbk; });
454 context_->OnSurfaceChanged(DEFAULT_INT10, DEFAULT_INT10, WindowSizeChangeReason::CUSTOM_ANIMATION);
455 EXPECT_TRUE(flagCbk);
456
457 /**
458 * @tc.steps3: Call the function OnSurfaceChanged with width = 1, height = 1 and weakFrontend_ = null.
459 * @tc.expected: The flagCbk is not changed.
460 */
461 context_->OnSurfaceChanged(DEFAULT_INT1, DEFAULT_INT1);
462 EXPECT_TRUE(flagCbk);
463
464 /**
465 * @tc.steps4: Call the function OnSurfaceDensityChanged with width = 1, height = 1 and weakFrontend_ != null.
466 * @tc.expected: The width_ and height_ of frontend is changed to DEFAULT_INT1.
467 */
468 auto frontend = AceType::MakeRefPtr<MockFrontend>();
469 context_->weakFrontend_ = frontend;
470 context_->OnSurfaceChanged(DEFAULT_INT1, DEFAULT_INT1);
471 EXPECT_EQ(frontend->GetWidth(), DEFAULT_INT1);
472 EXPECT_EQ(frontend->GetHeight(), DEFAULT_INT1);
473 context_->weakFrontend_.Reset();
474 }
475
476 /**
477 * @tc.name: PipelineContextTestNg010
478 * @tc.desc: Test the function OnSurfaceDensityChanged.
479 * @tc.type: FUNC
480 */
481 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg010, TestSize.Level1)
482 {
483 /**
484 * @tc.steps1: initialize parameters.
485 * @tc.expected: All pointer is non-null.
486 */
487 ASSERT_NE(context_, nullptr);
488 context_->density_ = DEFAULT_DOUBLE1;
489 context_->dipScale_ = DEFAULT_DOUBLE1;
490
491 /**
492 * @tc.steps2: Call the function OnSurfaceDensityChanged with viewScale_ = 0.0.
493 * @tc.expected: The density_ is changed to density.
494 */
495 context_->viewScale_ = 0.0;
496 context_->OnSurfaceDensityChanged(DEFAULT_DOUBLE4);
497 EXPECT_DOUBLE_EQ(context_->GetDensity(), DEFAULT_DOUBLE4);
498 EXPECT_DOUBLE_EQ(context_->GetDipScale(), DEFAULT_DOUBLE1);
499
500 /**
501 * @tc.steps3: Call the function OnSurfaceDensityChanged with viewScale_ = 0.0.
502 * @tc.expected: The density_ is changed to density.
503 */
504 context_->viewScale_ = DEFAULT_DOUBLE2;
505 context_->OnSurfaceDensityChanged(DEFAULT_DOUBLE4);
506 EXPECT_DOUBLE_EQ(context_->GetDensity(), DEFAULT_DOUBLE4);
507 EXPECT_DOUBLE_EQ(context_->GetDipScale(), DEFAULT_DOUBLE2);
508 }
509
510 /**
511 * @tc.name: PipelineContextTestNg011
512 * @tc.desc: Test the function AddDirtyFocus.
513 * @tc.type: FUNC
514 */
515 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg011, TestSize.Level1)
516 {
517 /**
518 * @tc.steps1: initialize parameters.
519 * @tc.expected: All pointer is non-null.
520 */
521 ASSERT_NE(context_, nullptr);
522 auto eventHub = frameNode_->GetEventHub<EventHub>();
523 ASSERT_NE(eventHub, nullptr);
524 auto focusHub = eventHub->GetOrCreateFocusHub();
525 ASSERT_NE(focusHub, nullptr);
526
527 /**
528 * @tc.steps2: Call the function AddDirtyFocus with FocusType::NODE.
529 * @tc.expected: The FocusType of dirtyFocusNode_ is changed to FocusType::NODE.
530 */
531 focusHub->SetFocusType(FocusType::NODE);
532 context_->AddDirtyFocus(frameNode_);
533 auto dirtyFocusNode = context_->dirtyFocusNode_.Upgrade();
534 ASSERT_NE(dirtyFocusNode, nullptr);
535 EXPECT_EQ(dirtyFocusNode->GetFocusType(), FocusType::NODE);
536
537 /**
538 * @tc.steps3: Call the function OnSurfaceDensityChanged with FocusType::SCOPE.
539 * @tc.expected: The FocusType of dirtyFocusScope_ is changed to FocusType::SCOPE.
540 */
541 focusHub->SetFocusType(FocusType::SCOPE);
542 context_->AddDirtyFocus(frameNode_);
543 auto dirtyFocusScope = context_->dirtyFocusScope_.Upgrade();
544 ASSERT_NE(dirtyFocusScope, nullptr);
545 EXPECT_EQ(dirtyFocusScope->GetFocusType(), FocusType::SCOPE);
546 }
547
548 /**
549 * @tc.name: PipelineContextTestNg012
550 * @tc.desc: Test functions WindowFocus and FlushWindowFocusChangedCallback.
551 * @tc.type: FUNC
552 */
553 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg012, TestSize.Level1)
554 {
555 /**
556 * @tc.steps1: initialize parameters.
557 * @tc.expected: All pointer is non-null.
558 */
559 ASSERT_NE(context_, nullptr);
560 context_->SetupRootElement();
561 context_->onWindowFocusChangedCallbacks_.clear();
562 context_->AddWindowFocusChangedCallback(ElementRegister::UndefinedElementId);
563 context_->AddWindowFocusChangedCallback(frameNodeId_);
564 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE2);
565
566 /**
567 * @tc.steps2: Call the function WindowFocus with "true" and onShow_ = true.
568 * @tc.expected: The onFocus_ is changed to true and the size of onWindowFocusChangedCallbacks_ is change to 1.
569 */
570 context_->onShow_ = true;
571 context_->WindowFocus(true);
572 EXPECT_TRUE(context_->onFocus_);
573 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
574
575 /**
576 * @tc.steps3: Call the function WindowFocus with "true" and onShow_ = false.
577 * @tc.expected: The onFocus_ is changed to true and the size of onWindowFocusChangedCallbacks_ is change to 1.
578 */
579 context_->onShow_ = false;
580 context_->WindowFocus(true);
581 EXPECT_TRUE(context_->onFocus_);
582 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
583
584 /**
585 * @tc.steps4: Call the function WindowFocus with "false" and onShow_ = true.
586 * @tc.expected: The onFocus_ is changed to false.
587 */
588 context_->onShow_ = true;
589 context_->WindowFocus(false);
590 EXPECT_FALSE(context_->onFocus_);
591 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
592
593 /**
594 * @tc.steps5: Call the function WindowFocus with "false" and onShow_ = false.
595 * @tc.expected: The onFocus_ is changed to false.
596 */
597 context_->onShow_ = false;
598 context_->WindowFocus(false);
599 EXPECT_FALSE(context_->onFocus_);
600 context_->RemoveWindowFocusChangedCallback(0);
601 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
602 }
603
604 /**
605 * @tc.name: PipelineContextTestNg013
606 * @tc.desc: Test the function NotifyMemoryLevel.
607 * @tc.type: FUNC
608 */
609 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg013, TestSize.Level1)
610 {
611 /**
612 * @tc.steps1: initialize parameters.
613 * @tc.expected: All pointer is non-null.
614 */
615 ASSERT_NE(context_, nullptr);
616 context_->nodesToNotifyMemoryLevel_.clear();
617 context_->AddNodesToNotifyMemoryLevel(ElementRegister::UndefinedElementId);
618 context_->AddNodesToNotifyMemoryLevel(customNodeId_);
619 EXPECT_EQ(context_->nodesToNotifyMemoryLevel_.size(), DEFAULT_SIZE2);
620
621 /**
622 * @tc.steps2: Call the function NotifyMemoryLevel with "1".
623 * @tc.expected: The size of nodesToNotifyMemoryLevel_ is change to 1.
624 */
625 context_->NotifyMemoryLevel(DEFAULT_INT1);
626 EXPECT_EQ(context_->nodesToNotifyMemoryLevel_.size(), DEFAULT_SIZE1);
627
628 /**
629 * @tc.steps3: Call the function NotifyMemoryLevel with "1".
630 * @tc.expected: The NOT_REGISTER_ID in nodesToNotifyMemoryLevel_ is erased.
631 */
632 context_->AddNodesToNotifyMemoryLevel(NOT_REGISTER_ID);
633 context_->NotifyMemoryLevel(DEFAULT_INT1);
634 auto iter =
635 find(context_->nodesToNotifyMemoryLevel_.begin(), context_->nodesToNotifyMemoryLevel_.end(), NOT_REGISTER_ID);
636 EXPECT_EQ(iter, context_->nodesToNotifyMemoryLevel_.end());
637 }
638
639 /**
640 * @tc.name: PipelineContextTestNg014
641 * @tc.desc: Test the function OnIdle.
642 * @tc.type: FUNC
643 */
644 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg014, TestSize.Level1)
645 {
646 /**
647 * @tc.steps1: initialize parameters.
648 * @tc.expected: All pointer is non-null.
649 */
650 ASSERT_NE(context_, nullptr);
651 bool flagCbk = false;
652
653 /**
654 * @tc.steps2: Call the function OnIdle.
655 * @tc.expected: The value of flagCbk remains unchanged.
656 */
__anon0f9446780602(int64_t, bool) 657 context_->AddPredictTask([&flagCbk](int64_t, bool) { flagCbk = true; });
658 context_->OnIdle(0);
659 EXPECT_FALSE(flagCbk);
660
661 /**
662 * @tc.steps3: Call the function OnIdle.
663 * @tc.expected: The flagCbk is changed to true.
664 */
665 context_->OnIdle(NANO_TIME_STAMP);
666 EXPECT_TRUE(flagCbk);
667 }
668
669 /**
670 * @tc.name: PipelineContextTestNg015
671 * @tc.desc: Test the function Finish.
672 * @tc.type: FUNC
673 */
674 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg015, TestSize.Level1)
675 {
676 /**
677 * @tc.steps1: initialize parameters.
678 * @tc.expected: All pointer is non-null.
679 */
680 ASSERT_NE(context_, nullptr);
681 bool flagCbk = false;
682
683 /**
684 * @tc.steps2: Call the function Finish.
685 * @tc.expected: The value of flagCbk remains unchanged.
686 */
687 context_->SetFinishEventHandler(nullptr);
688 context_->Finish(false);
689 EXPECT_FALSE(flagCbk);
690
691 /**
692 * @tc.steps3: Call the function Finish.
693 * @tc.expected: The flagCbk is changed to true.
694 */
__anon0f9446780702() 695 context_->SetFinishEventHandler([&flagCbk]() { flagCbk = true; });
696 context_->Finish(false);
697 EXPECT_TRUE(flagCbk);
698 }
699
700 /**
701 * @tc.name: PipelineContextTestNg016
702 * @tc.desc: Test functions OnShow, OnHide and FlushWindowStateChangedCallback.
703 * @tc.type: FUNC
704 */
705 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg016, TestSize.Level1)
706 {
707 /**
708 * @tc.steps1: initialize parameters.
709 * @tc.expected: All pointer is non-null.
710 */
711 ASSERT_NE(context_, nullptr);
712 context_->SetupRootElement();
713 context_->onWindowStateChangedCallbacks_.clear();
714 context_->AddWindowStateChangedCallback(ElementRegister::UndefinedElementId);
715 context_->AddWindowStateChangedCallback(customNodeId_);
716 EXPECT_EQ(context_->onWindowStateChangedCallbacks_.size(), DEFAULT_SIZE2);
717
718 /**
719 * @tc.steps2: Call the function OnShow.
720 * @tc.expected: The onShow_ is changed to true and the size of onWindowStateChangedCallbacks_ is change to 1.
721 */
722 context_->OnShow();
723 EXPECT_TRUE(context_->onShow_);
724 EXPECT_EQ(context_->onWindowStateChangedCallbacks_.size(), DEFAULT_SIZE1);
725
726 /**
727 * @tc.steps3: Call the function OnHide.
728 * @tc.expected: The onShow_ is changed to false.
729 */
730 context_->OnHide();
731 EXPECT_FALSE(context_->onShow_);
732 EXPECT_EQ(context_->onWindowStateChangedCallbacks_.size(), DEFAULT_SIZE1);
733 }
734
735 /**
736 * @tc.name: PipelineContextTestNg017
737 * @tc.desc: Test functions OnDragEvent.
738 * @tc.type: FUNC
739 */
740 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg017, TestSize.Level1)
741 {
742 /**
743 * @tc.steps1: initialize parameters.
744 * @tc.expected: All pointer is non-null.
745 */
746 ASSERT_NE(context_, nullptr);
747 context_->SetupRootElement();
748 auto manager = context_->GetDragDropManager();
749 ASSERT_NE(manager, nullptr);
750 auto frameNodeId_017 = ElementRegister::GetInstance()->MakeUniqueId();
751 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_017, nullptr);
752 ASSERT_NE(frameNode, nullptr);
753 manager->AddDragFrameNode(frameNode->GetId(), frameNode);
754
755 /**
756 * @tc.steps2: Call the function OnDragEvent with isDragged_=true, currentId_=DEFAULT_INT1 and
757 * DRAG_EVENT_START_FOR_CONTROLLER.
758 * @tc.expected: The currentId_ is equal to DEFAULT_INT1.
759 */
760 manager->isDragged_ = true;
761 manager->currentId_ = DEFAULT_INT1;
762 context_->OnDragEvent({ DEFAULT_INT1, DEFAULT_INT1 }, DragEventAction::DRAG_EVENT_START_FOR_CONTROLLER);
763 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
764
765 /**
766 * @tc.steps2: Call the function OnDragEvent with isDragged_=true, currentId_=DEFAULT_INT1 and DRAG_EVENT_OUT.
767 * @tc.expected: The currentId_ is equal to DEFAULT_INT1.
768 */
769 manager->isDragged_ = true;
770 manager->currentId_ = DEFAULT_INT1;
771 context_->OnDragEvent({ DEFAULT_INT1, DEFAULT_INT1 }, DragEventAction::DRAG_EVENT_OUT);
772 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
773
774 /**
775 * @tc.steps3: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_START.
776 * @tc.expected: The currentId_ is equal to DEFAULT_INT1.
777 */
778 manager->isDragged_ = false;
779 manager->currentId_ = DEFAULT_INT1;
780 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_START);
781 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
782
783 /**
784 * @tc.steps4: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_END.
785 * @tc.expected: The currentId_ is changed to DEFAULT_INT10.
786 */
787 manager->isDragged_ = false;
788 manager->currentId_ = DEFAULT_INT1;
789 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_END);
790 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
791
792 /**
793 * @tc.steps4: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_MOVE.
794 * @tc.expected: The currentId_ is changed to DEFAULT_INT10.
795 */
796 manager->isDragged_ = false;
797 manager->currentId_ = DEFAULT_INT1;
798 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_MOVE);
799 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
800 MockContainer::Current()->SetIsScenceBoardWindow(true);
801 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_MOVE);
802 context_->SetIsDragging(false);
803 EXPECT_FALSE(context_->IsDragging());
804 context_->ResetDragging();
805 }
806
807 /**
808 * @tc.name: PipelineContextTestNg018
809 * @tc.desc: Test the function ShowContainerTitle.
810 * @tc.type: FUNC
811 */
812 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg018, TestSize.Level1)
813 {
814 /**
815 * @tc.steps1: initialize parameters.
816 * @tc.expected: All pointer is non-null.
817 */
818 ASSERT_NE(context_, nullptr);
819 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
820 context_->SetupRootElement();
821 ASSERT_NE(context_->rootNode_, nullptr);
822 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
823 ASSERT_NE(containerNode, nullptr);
824 auto pattern = containerNode->GetPattern<ContainerModalPattern>();
825 ASSERT_NE(containerNode, nullptr);
826
827 /**
828 * @tc.steps2: Call the function ShowContainerTitle with windowModal_ = WindowModal::DIALOG_MODAL.
829 * @tc.expected: The moveX_ is unchanged.
830 */
831 pattern->moveX_ = DEFAULT_DOUBLE2;
832 context_->windowModal_ = WindowModal::DIALOG_MODAL;
833 context_->ShowContainerTitle(true);
834 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
835
836 /**
837 * @tc.steps3: Call the function ShowContainerTitle with windowModal_ = WindowModal::CONTAINER_MODAL.
838 * @tc.expected: The moveX_ is unchanged.
839 */
840 pattern->moveX_ = DEFAULT_DOUBLE2;
841 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
842 context_->ShowContainerTitle(true);
843 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
844 }
845
846 /**
847 * @tc.name: PipelineContextTestNg019
848 * @tc.desc: Test the function SetAppTitle.
849 * @tc.type: FUNC
850 */
851 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg019, TestSize.Level1)
852 {
853 /**
854 * @tc.steps1: initialize parameters.
855 * @tc.expected: All pointer is non-null.
856 */
857 ASSERT_NE(context_, nullptr);
858 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
859 context_->SetupRootElement();
860 ASSERT_NE(context_->rootNode_, nullptr);
861 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
862 ASSERT_NE(containerNode, nullptr);
863 auto pattern = containerNode->GetPattern<ContainerModalPattern>();
864 ASSERT_NE(containerNode, nullptr);
865
866 /**
867 * @tc.steps2: Call the function ShowContainerTitle with windowModal_ = WindowModal::DIALOG_MODAL.
868 * @tc.expected: The moveX_ is unchanged.
869 */
870 pattern->moveX_ = DEFAULT_DOUBLE2;
871 context_->windowModal_ = WindowModal::DIALOG_MODAL;
872 context_->SetAppTitle(TEST_TAG);
873 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
874
875 /**
876 * @tc.steps3: Call the function ShowContainerTitle with windowModal_ = WindowModal::CONTAINER_MODAL.
877 * @tc.expected: The moveX_ is unchanged.
878 */
879 pattern->moveX_ = DEFAULT_DOUBLE2;
880 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
881 context_->SetAppTitle(TEST_TAG);
882 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
883 }
884
885 /**
886 * @tc.name: PipelineContextTestNg020
887 * @tc.desc: Test the function SetAppIcon.
888 * @tc.type: FUNC
889 */
890 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg020, TestSize.Level1)
891 {
892 /**
893 * @tc.steps1: initialize parameters.
894 * @tc.expected: All pointer is non-null.
895 */
896 ASSERT_NE(context_, nullptr);
897 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
898 context_->SetupRootElement();
899 ASSERT_NE(context_->rootNode_, nullptr);
900 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
901 ASSERT_NE(containerNode, nullptr);
902 auto pattern = containerNode->GetPattern<ContainerModalPattern>();
903 ASSERT_NE(containerNode, nullptr);
904
905 /**
906 * @tc.steps2: Call the function SetAppIcon with windowModal_ = WindowModal::DIALOG_MODAL.
907 * @tc.expected: The moveX_ is unchanged.
908 */
909 pattern->moveX_ = DEFAULT_DOUBLE2;
910 context_->windowModal_ = WindowModal::DIALOG_MODAL;
911 context_->SetAppIcon(nullptr);
912 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
913
914 /**
915 * @tc.steps3: Call the function SetAppIcon with windowModal_ = WindowModal::CONTAINER_MODAL.
916 * @tc.expected: The moveX_ is unchanged.
917 */
918 pattern->moveX_ = DEFAULT_DOUBLE2;
919 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
920 context_->SetAppIcon(nullptr);
921 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
922 }
923
924 /**
925 * @tc.name: PipelineContextTestNg025
926 * @tc.desc: Test the function OnDumpInfo.
927 * @tc.type: FUNC
928 */
929 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg025, TestSize.Level1)
930 {
931 /**
932 * @tc.steps1: initialize parameters.
933 * @tc.expected: All pointer is non-null.
934 */
935 ASSERT_NE(context_, nullptr);
936 context_->SetupRootElement();
937
938 std::unique_ptr<std::ostream> ostream = std::make_unique<std::ostringstream>();
939 ASSERT_NE(ostream, nullptr);
940 DumpLog::GetInstance().SetDumpFile(std::move(ostream));
941 /**
942 * @tc.steps2: init a vector with some string params and
943 call OnDumpInfo with every param array.
944 * @tc.expected: The return value is same as the expectation.
945 */
946 std::vector<std::vector<std::string>> params = { { "-element", "-lastpage" }, { "-element", "non-lastpage" },
947 { "-element" }, { "-focus" }, { ACCESS_TAG }, { "-inspector" }, { "-render" }, { "-layer" }, { "-frontend" },
948 { "-multimodal" }, { "-rotation", "1", "2", "3" }, { "-animationscale", "1", "2", "3" },
949 { "-velocityscale", "1", "2", "3" }, { "-scrollfriction", "1", "2", "3" }, { "-threadstuck", "1", "2", "3" },
950 { "-rotation" }, { "-animationscale" }, { "-velocityscale" }, { "-scrollfriction" }, { "-threadstuck" },
951 { "test" }, { "-navigation" }, { "-focuswindowscene" }, { "-focusmanager" }, { "-jsdump" }, { "-event" },
952 { "-imagecache" }, { "-imagefilecache" }, { "-allelements" }, { "-default" }, { "-overlay" }, { "--stylus" } };
953 int turn = 0;
954 for (; turn < params.size(); turn++) {
955 EXPECT_TRUE(context_->OnDumpInfo(params[turn]));
956 }
957 }
958
959 /**
960 * @tc.name: PipelineContextTestNg026
961 * @tc.desc: Test the function OnBackPressed.
962 * @tc.type: FUNC
963 */
964 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg026, TestSize.Level1)
965 {
966 /**
967 * @tc.steps1: initialize parameters.
968 * @tc.expected: All pointer is non-null.
969 */
970 ASSERT_NE(context_, nullptr);
971 context_->SetupRootElement();
972
973 /**
974 * @tc.steps2: Call the function OnBackPressed with weakFrontend_ is null.
975 * @tc.expected: The return value of function is false.
976 */
977 context_->weakFrontend_.Reset();
978 EXPECT_FALSE(context_->OnBackPressed());
979
980 /**
981 * @tc.steps3: Call the function OnBackPressed with the return value of
982 * fullScreenManager_->RequestFullScreen is true.
983 * @tc.expected: The return value of function is true.
984 */
985 auto frontend = AceType::MakeRefPtr<MockFrontend>();
986 EXPECT_CALL(*frontend, OnBackPressed()).WillRepeatedly(testing::Return(true));
987 context_->weakFrontend_ = frontend;
988 auto frameNodeId = ElementRegister::GetInstance()->MakeUniqueId();
989 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId, nullptr);
990 context_->fullScreenManager_->RequestFullScreen(frameNode); // Set the return value of OnBackPressed to true;
991 EXPECT_TRUE(context_->OnBackPressed());
992
993 /**
994 * @tc.steps4: Call the function OnBackPressed with the return value of
995 * fullScreenManager_->RequestFullScreen is true.
996 * @tc.expected: The return value of function is true.
997 */
998 // Set the return value of OnBackPressed of fullScreenManager_ to true;
999 context_->fullScreenManager_->ExitFullScreen(frameNode);
1000 EXPECT_TRUE(context_->OnBackPressed());
1001
1002 /**
1003 * @tc.steps5: Call the function OnBackPressed with the return value of
1004 * overlayManager_->RemoveOverlay is true.
1005 * @tc.expected: The return value of function is true.
1006 */
1007 // Set the return value of RemoveOverlay of overlayManager_ to true;
1008 context_->overlayManager_->CloseDialog(frameNode_);
1009 EXPECT_TRUE(context_->OnBackPressed());
1010
1011 /**
1012 * @tc.steps6: Call the function OnBackPressed with the return value of
1013 * overlayManager_->RemoveOverlay is true.
1014 * @tc.expected: The return value of function is true.
1015 */
1016 // Set the return value of RemoveOverlay of overlayManager_ to true;
1017 context_->overlayManager_->CloseDialog(frameNode);
1018 EXPECT_TRUE(context_->OnBackPressed());
1019 }
1020
1021 /**
1022 * @tc.name: PipelineContextTestNg027
1023 * @tc.desc: Test functions StartWindowSizeChangeAnimate and SetRootRect.
1024 * @tc.type: FUNC
1025 */
1026 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg027, TestSize.Level1)
1027 {
1028 /**
1029 * @tc.steps1: initialize parameters.
1030 * @tc.expected: All pointer is non-null.
1031 */
1032 ASSERT_NE(context_, nullptr);
1033 EXPECT_CALL(*(MockWindow*)(context_->window_.get()), SetDrawTextAsBitmap(_)).Times(AnyNumber());
1034 context_->SetupRootElement();
1035 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1036 auto& windowConfig = frontend->GetWindowConfig();
1037 windowConfig.designWidth = DEFAULT_INT1;
1038 context_->weakFrontend_ = frontend;
1039
1040 /**
1041 * @tc.steps2: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::RECOVER.
1042 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1043 */
1044 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1045 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::RECOVER);
1046 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1047
1048 /**
1049 * @tc.steps3: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::MAXIMIZE.
1050 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1051 */
1052 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1053 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::MAXIMIZE);
1054 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1055
1056 /**
1057 * @tc.steps4: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::ROTATION.
1058 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1059 */
1060 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1061 auto manager = AceType::MakeRefPtr<TextFieldManagerNG>();
1062 context_->SetTextFieldManager(manager);
1063 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::ROTATION);
1064 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1065
1066 /**
1067 * @tc.steps5: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::UNDEFINED.
1068 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1069 */
1070 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1071 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::UNDEFINED);
1072 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1073
1074 /**
1075 * @tc.steps5: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::UNDEFINED.
1076 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1077 */
1078 SystemProperties::windowAnimationEnabled_ = false;
1079 context_->rootNode_->geometryNode_->frame_.rect_.y_ = 3.0;
1080 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::UNDEFINED);
1081 EXPECT_EQ(context_->rootNode_->GetGeometryNode()->GetFrameOffset().GetY(), 0);
1082 }
1083
1084 /**
1085 * @tc.name: PipelineContextTestNg028
1086 * @tc.desc: Test functions OnVirtualKeyboardHeightChange and SetRootRect.
1087 * @tc.type: FUNC
1088 */
1089 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg028, TestSize.Level1)
1090 {
1091 /**
1092 * @tc.steps1: initialize parameters.
1093 * @tc.expected: All pointer is non-null.
1094 */
1095 ASSERT_NE(context_, nullptr);
1096 context_->SetupRootElement();
1097 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1098 auto& windowConfig = frontend->GetWindowConfig();
1099 windowConfig.designWidth = DEFAULT_INT1;
1100 context_->weakFrontend_ = frontend;
1101 context_->SetTextFieldManager(AceType::MakeRefPtr<TextFieldManagerNG>());
1102
1103 /**
1104 * @tc.steps2: Call the function OnVirtualKeyboardHeightChange with DEFAULT_DOUBLE1.
1105 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT0.
1106 */
1107 context_->designWidthScale_ = DEFAULT_DOUBLE1;
1108 context_->OnVirtualKeyboardHeightChange(DEFAULT_DOUBLE1);
1109 context_->OnVirtualKeyboardHeightChange(DEFAULT_DOUBLE1, 0, 0);
1110 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_DOUBLE1);
1111 EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), 0);
1112
1113 /**
1114 * @tc.steps3: init data and Call the function OnVirtualKeyboardHeightChange
1115 when textFieldManager_ is null.
1116 * @tc.expected: the return is same as expectation.
1117 */
1118 context_->textFieldManager_ = nullptr;
1119
1120 // the first arg is rootHeight_, the second arg is the parameter of function,
1121 // the third arg is the expectation returns
1122 std::vector<std::vector<int>> params = { { 200, 400, -300 }, { -200, 100, -100 }, { -200, -300, 300 },
1123 { 200, 0, 0 } };
1124 for (int turn = 0; turn < params.size(); turn++) {
1125 context_->rootHeight_ = params[turn][0];
1126 context_->OnVirtualKeyboardHeightChange(params[turn][1]);
1127 context_->OnVirtualKeyboardHeightChange(params[turn][1], 0, 0);
1128 EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), params[turn][2]);
1129 }
1130 /**
1131 * @tc.steps4: init data and Call the function OnVirtualKeyboardHeightChange
1132 when textFieldManager_ is not null.
1133 * @tc.expected: the return is same as expectation.
1134 */
1135 auto manager = AceType::MakeRefPtr<TextFieldManagerNG>();
1136 context_->textFieldManager_ = manager;
1137 ASSERT_NE(context_->rootNode_, nullptr);
1138
1139 // the first arg is manager->height_, the second arg is manager->position_.deltaY_
1140 // the third arg is rootHeight_, the forth arg is context_->rootNode_->geometryNode_->frame_.rect_.y_
1141 // the fifth arg is the parameter of function, the sixth arg is the expectation returns
1142 params = { { 10, 100, 300, 0, 50, 0 }, { 10, 100, 300, 100, 100, 0 }, { 30, 100, 300, 100, 50, 0 },
1143 { 50, 290, 400, 100, 200, -95 }, { -1000, 290, 400, 100, 200, 100 } };
1144 for (int turn = 0; turn < params.size(); turn++) {
1145 manager->height_ = params[turn][0];
1146 manager->position_.deltaY_ = params[turn][1];
1147 context_->rootHeight_ = params[turn][2];
1148 context_->rootNode_->geometryNode_->frame_.rect_.y_ = params[turn][3];
1149 context_->safeAreaManager_->UpdateKeyboardOffset(params[turn][3]);
1150 manager->SetClickPositionOffset(params[turn][3]);
1151 context_->OnVirtualKeyboardHeightChange(params[turn][4]);
1152 context_->OnVirtualKeyboardHeightChange(params[turn][4], 0, 0);
1153 EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), params[turn][5]);
1154 }
1155 }
1156
1157 /**
1158 * @tc.name: PipelineContextTestNg029
1159 * @tc.desc: Test ThemeManager and SharedImageManager multithread.
1160 * @tc.type: FUNC
1161 */
1162 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg029, TestSize.Level1)
1163 {
1164 std::vector<std::thread> threads;
1165 for (int i = 0; i < 20; ++i) {
__anon0f9446780802() 1166 threads.emplace_back(std::thread([]() { context_->GetOrCreateSharedImageManager(); }));
1167 }
1168 for (auto&& thread : threads) {
1169 thread.join();
1170 }
1171
1172 threads.clear();
1173 for (int i = 0; i < 20; ++i) {
1174 if (i == 10) {
1175 context_->SetThemeManager(AceType::MakeRefPtr<MockThemeManager>());
1176 } else {
__anon0f9446780902() 1177 threads.emplace_back(std::thread([]() { context_->GetThemeManager(); }));
1178 }
1179 }
1180 for (auto&& thread : threads) {
1181 thread.join();
1182 }
1183 EXPECT_TRUE(context_->GetThemeManager());
1184 }
1185
1186 /**
1187 * @tc.name: PipelineContextTestNg030
1188 * @tc.desc: Test RestoreNodeInfo, GetStoredNodeInfo, StoreNode and GetRestoreInfo.
1189 * @tc.type: FUNC
1190 */
1191 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg030, TestSize.Level1)
1192 {
1193 /**
1194 * @tc.steps1: init a mockPattern.
1195 * @tc.expected: some calls by mockPattern.
1196 */
1197 RefPtr<MockPattern> mockPattern_ = AceType::MakeRefPtr<MockPattern>();
1198 Mock::AllowLeak(mockPattern_.rawPtr_);
1199 EXPECT_CALL(*mockPattern_, ProvideRestoreInfo())
1200 .Times(AnyNumber())
1201 .WillRepeatedly(testing::Return("Default restore info"));
1202 EXPECT_CALL(*mockPattern_, GetContextParam()).Times(AnyNumber()).WillRepeatedly(testing::Return(std::nullopt));
1203 EXPECT_CALL(*mockPattern_, CreatePaintProperty())
1204 .Times(AnyNumber())
1205 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<PaintProperty>()));
1206 EXPECT_CALL(*mockPattern_, CreateLayoutProperty())
1207 .Times(AnyNumber())
1208 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<LayoutProperty>()));
1209 EXPECT_CALL(*mockPattern_, CreateEventHub())
1210 .Times(AnyNumber())
1211 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<EventHub>()));
1212 EXPECT_CALL(*mockPattern_, CreateAccessibilityProperty())
1213 .Times(AnyNumber())
1214 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<AccessibilityProperty>()));
1215 EXPECT_CALL(*mockPattern_, OnAttachToFrameNode()).Times(AnyNumber());
1216 EXPECT_CALL(*mockPattern_, OnDetachFromFrameNode(_)).Times(AnyNumber());
1217
1218 /**
1219 * @tc.steps2: init a patternCreator and Create frameNodes and call StoreNode.
1220 * @tc.expected: StoreNode success.
1221 */
__anon0f9446780a02() 1222 auto patternCreator_ = [&mockPattern_]() { return mockPattern_; };
1223 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1224 auto frameNode_1 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
1225 ASSERT_NE(context_, nullptr);
1226 context_->StoreNode(DEFAULT_RESTORE_ID0, frameNode_1);
1227 EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID0], frameNode_1);
1228 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1229 auto frameNode_2 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, patternCreator_);
1230 context_->StoreNode(DEFAULT_RESTORE_ID0, frameNode_2);
1231 EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID0], frameNode_2);
1232 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1233 auto frameNode_3 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
1234 context_->StoreNode(DEFAULT_RESTORE_ID1, frameNode_3);
1235 EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID1], frameNode_3);
1236 context_->storeNode_[DEFAULT_RESTORE_ID2] = nullptr;
1237
1238 /**
1239 * @tc.steps3: call RestoreNodeInfo with nullptr.
1240 * @tc.expected: restoreNodeInfo_ is empty.
1241 */
1242 auto jsonNodeInfo = context_->GetStoredNodeInfo();
1243 context_->RestoreNodeInfo(jsonNodeInfo->GetChild());
1244 EXPECT_TRUE(context_->restoreNodeInfo_.empty());
1245
1246 /**
1247 * @tc.steps4: call GetStoredNodeInfo and RestoreNodeInfo.
1248 * @tc.expected: restoreNodeInfo_ is not empty.
1249 */
1250 context_->RestoreNodeInfo(std::move(jsonNodeInfo));
1251 EXPECT_FALSE(context_->restoreNodeInfo_.empty());
1252
1253 /**
1254 * @tc.steps5: call GetRestoreInfo.
1255 * @tc.expected: restoreInfo is not "Default restore info".
1256 DEFAULT_RESTORE_ID0:"Default restore info" is moved from restoreNodeInfo_.
1257 */
1258 std::string restoreInfo;
1259 auto rt = context_->GetRestoreInfo(DEFAULT_RESTORE_ID0, restoreInfo);
1260 EXPECT_EQ(restoreInfo, "Default restore info");
1261 EXPECT_TRUE(rt);
1262 rt = context_->GetRestoreInfo(DEFAULT_RESTORE_ID0, restoreInfo);
1263 EXPECT_FALSE(rt);
1264 auto iter1 = context_->restoreNodeInfo_.find(DEFAULT_RESTORE_ID0);
1265 EXPECT_EQ(iter1, context_->restoreNodeInfo_.end());
1266 }
1267
1268 /**
1269 * @tc.name: PipelineContextTestNg032
1270 * @tc.desc: Test OnSurfacePositionChanged RegisterSurfacePositionChangedCallback
1271 * UnregisterSurfacePositionChangedCallback.
1272 * @tc.type: FUNC
1273 */
1274 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg032, TestSize.Level1)
1275 {
1276 /**
1277 * @tc.steps1: initialize parameters and call RegisterSurfacePositionChangedCallback with null.
1278 * @tc.expected: rt is 0.
1279 */
1280 ASSERT_NE(context_, nullptr);
1281 int32_t rt = context_->RegisterSurfacePositionChangedCallback(nullptr);
1282 EXPECT_EQ(rt, 0);
1283 /**
1284 * @tc.steps2: init a callback, register it and change map memory.
1285 then call OnSurfacePositionChanged.
1286 * @tc.expected: flag is true.
1287 */
1288 bool flag = false;
__anon0f9446780b02(int32_t input_1, int32_t input_2) 1289 auto callback_1 = [&flag](int32_t input_1, int32_t input_2) { flag = !flag; };
1290 rt = context_->RegisterSurfacePositionChangedCallback(std::move(callback_1));
1291 context_->surfacePositionChangedCallbackMap_[100] = nullptr;
1292 context_->OnSurfacePositionChanged(0, 0);
1293 EXPECT_TRUE(flag);
1294 /**
1295 * @tc.steps2: call UnregisterSurfacePositionChangedCallback.
1296 then call OnSurfacePositionChanged.
1297 * @tc.expected: flag is true.
1298 */
1299 context_->UnregisterSurfacePositionChangedCallback(rt);
1300 context_->OnSurfacePositionChanged(0, 0);
1301 EXPECT_TRUE(flag);
1302 }
1303
1304 /**
1305 * @tc.name: PipelineContextTestNg035
1306 * @tc.desc: Test ChangeMouseStyle.
1307 * @tc.type: FUNC
1308 */
1309 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg035, TestSize.Level1)
1310 {
1311 /**
1312 * @tc.steps1: initialize parameters set mouseStyleNodeId.
1313 * @tc.expected: ChangePointerStyle will be called.
1314 * @tc.steps1: call ChangeMouseStyle.
1315 */
1316 ASSERT_NE(context_, nullptr);
1317 context_->onFocus_ = true;
1318 context_->mouseStyleNodeId_ = 0;
1319 auto mouseStyle_ = AceType::DynamicCast<MockMouseStyle>(MouseStyle::CreateMouseStyle().rawPtr_);
1320 EXPECT_CALL(*mouseStyle_, ChangePointerStyle(_, _)).Times(AnyNumber());
1321 context_->ChangeMouseStyle(0, MouseFormat::DEFAULT);
1322 }
1323
1324 /**
1325 * @tc.name: PipelineContextTestNg040
1326 * @tc.desc: Test SetContainerButtonHide function.
1327 * @tc.type: FUNC
1328 */
1329 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg040, TestSize.Level1)
1330 {
1331 /**
1332 * @tc.steps1: initialize root node and containerModal node.
1333 * @tc.expected: root node and containerModal node are not null.
1334 */
1335 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1336 context_->SetThemeManager(themeManager);
1337 auto themeConstants = AceType::MakeRefPtr<ThemeConstants>(nullptr);
1338 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<ContainerModalTheme>()));
1339 EXPECT_CALL(*themeManager, GetThemeConstants()).WillRepeatedly(Return(themeConstants));
1340
1341 ASSERT_NE(context_, nullptr);
1342 context_->SetWindowModal(WindowModal::CONTAINER_MODAL);
1343 ASSERT_NE(context_->window_, nullptr);
1344 context_->SetupRootElement();
1345 ASSERT_NE(context_->GetRootElement(), nullptr);
1346 auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
1347 ASSERT_NE(containerNode, nullptr);
1348 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1349 ASSERT_NE(containerPattern, nullptr);
1350 /**
1351 * @tc.steps2: call SetContainerButtonHide with params true, true, false, false.
1352 * @tc.expected: depends on first param, hideSplitButton value is true.
1353 */
1354 context_->SetContainerButtonHide(true, true, false, false);
1355 EXPECT_TRUE(containerPattern->hideSplitButton_ == true);
1356 /**
1357 * @tc.steps3: call SetContainerButtonHide with params false, true, false, false.
1358 * @tc.expected: depends on first param, hideSplitButton value is false.
1359 */
1360 context_->SetContainerButtonHide(false, true, false, false);
1361 EXPECT_TRUE(containerPattern->hideSplitButton_ == false);
1362
1363 /**
1364 * @tc.steps4: call SetContainerButtonHide with params false, true, false, false.
1365 * @tc.expected: cover branch windowModal_ is not CONTAINER_MODAL
1366 */
1367 context_->SetWindowModal(WindowModal::DIALOG_MODAL);
1368 context_->SetContainerButtonHide(false, true, false, false);
1369 EXPECT_FALSE(containerPattern->hideSplitButton_);
1370 }
1371
1372 /**
1373 * @tc.name: PipelineContextTestNg043
1374 * @tc.desc: Test SetCloseButtonStatus function.
1375 * @tc.type: FUNC
1376 */
1377 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg043, TestSize.Level1)
1378 {
1379 /**
1380 * @tc.steps1: initialize root node and containerModal node.
1381 * @tc.expected: root node and containerModal node are not null.
1382 */
1383 ASSERT_NE(context_, nullptr);
1384 context_->SetWindowModal(WindowModal::CONTAINER_MODAL);
1385 ASSERT_NE(context_->window_, nullptr);
1386 context_->SetupRootElement();
1387 ASSERT_NE(context_->GetRootElement(), nullptr);
1388 auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
1389 ASSERT_NE(containerNode, nullptr);
1390 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1391 ASSERT_NE(containerPattern, nullptr);
1392 auto columNode = AceType::DynamicCast<FrameNode>(containerNode->GetChildren().front());
1393 CHECK_NULL_VOID(columNode);
1394 auto titleNode = AceType::DynamicCast<FrameNode>(columNode->GetChildren().front());
1395 CHECK_NULL_VOID(titleNode);
1396 auto closeButton = AceType::DynamicCast<FrameNode>(titleNode->GetChildAtIndex(CLOSE_BUTTON_INDEX));
1397 CHECK_NULL_VOID(closeButton);
1398 auto buttonEvent = closeButton->GetEventHub<ButtonEventHub>();
1399 CHECK_NULL_VOID(buttonEvent);
1400 /**
1401 * @tc.steps2: call SetCloseButtonStatus with params true.
1402 * @tc.expected: CloseButton IsEnabled return true.
1403 */
1404 context_->SetCloseButtonStatus(true);
1405 EXPECT_EQ(buttonEvent->IsEnabled(), true);
1406 /**
1407 * @tc.steps3: call SetCloseButtonStatus with params false.
1408 * @tc.expected: CloseButton IsEnabled return false.
1409 */
1410 context_->SetCloseButtonStatus(false);
1411 EXPECT_EQ(buttonEvent->IsEnabled(), false);
1412 }
1413
1414 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg060, TestSize.Level1)
1415 {
1416 /**
1417 * @tc.steps1: initialize parameters.
1418 * @tc.expected: All pointer is non-null.
1419 */
1420 ASSERT_NE(context_, nullptr);
1421 context_->SetupRootElement();
1422 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1423 auto& windowConfig = frontend->GetWindowConfig();
1424 windowConfig.designWidth = DEFAULT_INT1;
1425 context_->weakFrontend_ = frontend;
1426 context_->SetTextFieldManager(AceType::MakeRefPtr<TextFieldManagerNG>());
1427
1428 /**
1429 * @tc.steps2: Set EnableAvoidKeyboardMode is true.
1430 * @tc.expected: get KeyboardSafeAreaEnabled is true.
1431 */
1432 context_->SetEnableKeyBoardAvoidMode(KeyBoardAvoidMode::RESIZE);
1433 EXPECT_TRUE(context_->GetSafeAreaManager()->KeyboardSafeAreaEnabled());
1434
1435 /**
1436 * @tc.steps3: set root height and change virtual keyboard height.
1437 * @tc.expected: Resize the root height after virtual keyboard change.
1438 */
1439
1440 auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
1441 ASSERT_NE(containerNode, nullptr);
1442 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1443 ASSERT_NE(containerPattern, nullptr);
1444 auto columNode = AceType::DynamicCast<FrameNode>(containerNode->GetChildren().front());
1445 CHECK_NULL_VOID(columNode);
1446
1447 std::vector<std::vector<int>> params = { { 100, 400, 100 }, { 300, 100, 300 }, { 400, -300, 400 },
1448 { 200, 0, 200 } };
1449 for (int turn = 0; turn < params.size(); turn++) {
1450 context_->rootHeight_ = params[turn][0];
1451 context_->OnVirtualKeyboardHeightChange(params[turn][1]);
1452 EXPECT_EQ(context_->GetRootHeight(), params[turn][2]);
1453 }
1454 }
1455 /**
1456 * @tc.name: PipelineContextTestNg061
1457 * @tc.desc: Test the function WindowUnFocus.
1458 * @tc.type: FUNC
1459 */
1460 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg061, TestSize.Level1)
1461 {
1462 /**
1463 * @tc.steps1: initialize parameters.
1464 * @tc.expected: All pointer is non-null.
1465 */
1466 ASSERT_NE(context_, nullptr);
1467 context_->SetupRootElement();
1468 ASSERT_NE(context_->rootNode_, nullptr);
1469 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
1470 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1471
1472 /**
1473 * @tc.steps3: Call the function WindowUnFocus with WindowFocus(true).
1474 * @tc.expected: containerPattern isFocus_ is true.
1475 */
1476 containerPattern->isFocus_ = true;
1477 containerPattern->OnWindowForceUnfocused();
1478 EXPECT_TRUE(containerPattern->isFocus_);
1479
1480 /**
1481 * @tc.steps2: Call the function WindowUnFocus with WindowFocus(false).
1482 * @tc.expected: containerPattern isFocus_ is false.
1483 */
1484 containerPattern->WindowFocus(false);
1485 containerPattern->OnWindowForceUnfocused();
1486 EXPECT_FALSE(containerPattern->isFocus_);
1487 }
1488
1489 /**
1490 * @tc.name: PipelineContextTestNg088
1491 * @tc.desc: Test the function FlushRequestFocus.
1492 * @tc.type: FUNC
1493 */
1494 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg088, TestSize.Level1)
1495 {
1496 /**
1497 * @tc.steps1: initialize parameters.
1498 * @tc.expected: All pointer is non-null.
1499 */
1500 ASSERT_NE(context_, nullptr);
1501 context_->SetupRootElement();
1502
1503 /**
1504 * @tc.steps2: Call the function FlushRequestFocus.
1505 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
1506 */
1507 context_->FlushRequestFocus();
1508 EXPECT_EQ(context_->dirtyRequestFocusNode_.Upgrade(), nullptr);
1509 context_->dirtyRequestFocusNode_ = frameNode_;
1510 EXPECT_NE(context_->dirtyRequestFocusNode_.Upgrade(), nullptr);
1511 }
1512
1513 /**
1514 * @tc.name: PipelineContextTestNg089
1515 * @tc.desc: Test the function FlushFocusScroll.
1516 * @tc.type: FUNC
1517 */
1518 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg089, TestSize.Level1)
1519 {
1520 /**
1521 * @tc.steps1: initialize parameters.
1522 * @tc.expected: All pointer is non-null.
1523 */
1524 ASSERT_NE(context_, nullptr);
1525 context_->SetupRootElement();
1526
1527 /**
1528 * @tc.steps2: Call the function FlushRequestFocus.
1529 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
1530 */
1531 context_->focusManager_.Reset();
1532 context_->FlushFocusScroll();
1533 EXPECT_EQ(context_->focusManager_, nullptr);
1534 context_->GetOrCreateFocusManager();
1535 EXPECT_NE(context_->focusManager_, nullptr);
1536 }
1537
1538 /**
1539 * @tc.name: PipelineContextTestNg090
1540 * @tc.desc: Test the function FlushFocusView.
1541 * @tc.type: FUNC
1542 */
1543 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg090, TestSize.Level1)
1544 {
1545 /**
1546 * @tc.steps1: initialize parameters and call FlushFocusView.
1547 * @tc.expected: All pointer is non-null.
1548 */
1549 ASSERT_NE(context_, nullptr);
1550 context_->SetupRootElement();
1551 context_->SetupSubRootElement();
1552
1553 context_->FlushFocusView();
1554 EXPECT_NE(context_->focusManager_, nullptr);
1555 }
1556
1557 /**
1558 * @tc.name: PipelineContextTestNg091
1559 * @tc.desc: Test the function SendEventToAccessibilityWithNode.
1560 * @tc.type: FUNC
1561 */
1562 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg091, TestSize.Level1)
1563 {
1564 /**
1565 * @tc.steps1: initialize parameters.
1566 * @tc.expected: All pointer is non-null.
1567 */
1568 ASSERT_NE(context_, nullptr);
1569 context_->SetupRootElement();
1570
1571 /**
1572 * @tc.steps2: Call the function FlushRequestFocus.
1573 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
1574 */
1575 AccessibilityEvent event;
1576 event.windowChangeTypes = WindowUpdateType::WINDOW_UPDATE_ACTIVE;
1577 event.type = AccessibilityEventType::PAGE_CHANGE;
1578 auto frameNodeId_091 = ElementRegister::GetInstance()->MakeUniqueId();
1579 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_091, nullptr);
1580 CHECK_NULL_VOID(frameNode);
1581 context_->SendEventToAccessibilityWithNode(event, frameNode);
1582 bool accessibilityEnabled = AceApplicationInfo::GetInstance().IsAccessibilityEnabled();
1583 EXPECT_FALSE(accessibilityEnabled);
1584
1585 AceApplicationInfo::GetInstance().SetAccessibilityEnabled(true);
1586 context_->SendEventToAccessibilityWithNode(event, frameNode);
1587 accessibilityEnabled = AceApplicationInfo::GetInstance().IsAccessibilityEnabled();
1588 EXPECT_TRUE(accessibilityEnabled);
1589 }
1590
1591 /**
1592 * @tc.name: PipelineContextTestNg092
1593 * @tc.desc: Test the function GetContainerModalButtonsRect.
1594 * @tc.type: FUNC
1595 */
1596 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg092, TestSize.Level1)
1597 {
1598 /**
1599 * @tc.steps1: initialize parameters.
1600 * @tc.expected: All pointer is non-null.
1601 */
1602 ASSERT_NE(context_, nullptr);
1603 std::vector<Ace::RectF> rects;
1604 context_->TriggerOverlayNodePositionsUpdateCallback(rects);
__anon0f9446780c02(std::vector<Ace::RectF> rect) 1605 context_->RegisterOverlayNodePositionsUpdateCallback([](std::vector<Ace::RectF> rect) {});
1606 context_->TriggerOverlayNodePositionsUpdateCallback(rects);
1607 context_->windowManager_ = AceType::MakeRefPtr<WindowManager>();
1608 context_->windowModal_ = WindowModal::NORMAL;
1609 NG::RectF containerModal;
1610 NG::RectF buttons;
1611 context_->GetCustomTitleHeight();
1612 bool callbackTriggered = false;
__anon0f9446780d02(RectF&, RectF&) 1613 auto callback = [&callbackTriggered](RectF&, RectF&) { callbackTriggered = true; };
1614 context_->SubscribeContainerModalButtonsRectChange(std::move(callback));
1615 EXPECT_FALSE(context_->GetContainerModalButtonsRect(containerModal, buttons));
1616 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
1617 context_->SubscribeContainerModalButtonsRectChange(std::move(callback));
1618 EXPECT_FALSE(context_->GetContainerModalButtonsRect(containerModal, buttons));
1619 }
1620
1621 /**
1622 * @tc.name: PipelineContextTestNg093
1623 * @tc.desc: Test the function PrintVsyncInfoIfNeed.
1624 * @tc.type: FUNC
1625 */
1626 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg093, TestSize.Level1)
1627 {
1628 /**
1629 * @tc.steps1: initialize parameters.
1630 * @tc.expected: All pointer is non-null.
1631 */
1632 ASSERT_NE(context_, nullptr);
1633 ASSERT_NE(context_->GetWindow(), nullptr);
1634 EXPECT_FALSE(context_->PrintVsyncInfoIfNeed());
1635
1636 std::list<FrameInfo> dumpFrameInfos;
1637 FrameInfo frameInfo;
1638 dumpFrameInfos.push_back(frameInfo);
1639 context_->dumpFrameInfos_ = dumpFrameInfos;
1640 EXPECT_FALSE(context_->PrintVsyncInfoIfNeed());
1641 context_->dumpFrameInfos_.back().frameRecvTime_ = -1;
1642 EXPECT_FALSE(context_->PrintVsyncInfoIfNeed());
1643 context_->dumpFrameInfos_.clear();
1644 }
1645
1646 /**
1647 * @tc.name: PipelineContextTestNg094
1648 * @tc.desc: Test the function ChangeDarkModeBrightness.
1649 * @tc.type: FUNC
1650 */
1651 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg094, TestSize.Level1)
1652 {
1653 /**
1654 * @tc.steps1: initialize parameters.
1655 * @tc.expected: All pointer is non-null.
1656 */
1657 ASSERT_NE(context_, nullptr);
1658 context_->windowManager_ = AceType::MakeRefPtr<WindowManager>();
1659
1660 SystemProperties::SetColorMode(ColorMode::DARK);
1661 context_->SetAppBgColor(Color::BLACK);
1662 context_->ChangeDarkModeBrightness();
1663 context_->SetIsJsCard(true);
1664 context_->ChangeDarkModeBrightness();
1665 MockContainer::Current()->SetIsFormRender(true);
1666 context_->ChangeDarkModeBrightness();
1667 MockContainer::Current()->SetIsDynamicRender(true);
1668 context_->ChangeDarkModeBrightness();
1669 MockContainer::Current()->SetIsUIExtensionWindow(true);
1670 context_->ChangeDarkModeBrightness();
1671 context_->SetAppBgColor(Color::BLUE);
1672 context_->ChangeDarkModeBrightness();
1673 SystemProperties::SetColorMode(ColorMode::COLOR_MODE_UNDEFINED);
1674 context_->ChangeDarkModeBrightness();
1675 EXPECT_NE(context_->stageManager_, nullptr);
1676 }
1677 } // namespace NG
1678 } // namespace OHOS::Ace
1679