• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
__anon4f3201820202() 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);
__anon4f3201820302() 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);
__anon4f3201820402() 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);
__anon4f3201820502() 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      */
__anon4f3201820602(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      */
__anon4f3201820702() 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: PipelineContextTestNg021
926  * @tc.desc: Test the function OnAxisEvent.
927  * @tc.type: FUNC
928  */
929 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg021, TestSize.Level1)
930 {
931     /**
932      * @tc.steps1: initialize parameters.
933      * @tc.expected: All pointer is non-null.
934      */
935     ASSERT_NE(context_, nullptr);
936     AxisEvent event;
937     event.x = DEFAULT_DOUBLE1;
938     context_->viewScale_ = DEFAULT_DOUBLE1;
939 
940     /**
941      * @tc.steps2: Call the function OnAxisEvent with action = AxisAction::BEGIN.
942      * @tc.expected: The instanceId is changed to 4.
943      */
944     event.action = AxisAction::BEGIN;
945     ResetEventFlag(TOUCH_TEST_FLAG | AXIS_TEST_FLAG);
946     context_->OnAxisEvent(event);
947     EXPECT_FALSE(GetEventFlag(TOUCH_TEST_FLAG));
948     EXPECT_FALSE(GetEventFlag(AXIS_TEST_FLAG));
949 
950     /**
951      * @tc.steps3: Call the function OnAxisEvent with action = AxisAction::UPDATE.
952      * @tc.expected: The instanceId is changed to 3.
953      */
954     event.action = AxisAction::UPDATE;
955     ResetEventFlag(TOUCH_TEST_FLAG | AXIS_TEST_FLAG);
956     context_->OnAxisEvent(event);
957     EXPECT_FALSE(GetEventFlag(TOUCH_TEST_FLAG));
958     EXPECT_FALSE(GetEventFlag(AXIS_TEST_FLAG));
959 
960     /**
961      * @tc.steps4: Call the function OnAxisEvent with action = AxisAction::END.
962      * @tc.expected: The instanceId is changed to 1.
963      */
964     event.action = AxisAction::END;
965     ResetEventFlag(TOUCH_TEST_FLAG | AXIS_TEST_FLAG);
966     context_->OnAxisEvent(event);
967     EXPECT_FALSE(GetEventFlag(TOUCH_TEST_FLAG));
968     EXPECT_FALSE(GetEventFlag(AXIS_TEST_FLAG));
969 }
970 
971 /**
972  * @tc.name: PipelineContextTestNg022
973  * @tc.desc: Test the function OnKeyEvent.
974  * @tc.type: FUNC
975  */
976 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg022, TestSize.Level1)
977 {
978     /**
979      * @tc.steps1: initialize parameters.
980      * @tc.expected: All pointer is non-null.
981      */
982     ASSERT_NE(context_, nullptr);
983     context_->SetupRootElement();
984     auto eventManager = context_->GetDragDropManager();
985     ASSERT_NE(eventManager, nullptr);
986     auto frameNodeId_022 = ElementRegister::GetInstance()->MakeUniqueId();
987     auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_022, nullptr);
988     ASSERT_NE(frameNode, nullptr);
989     eventManager->AddDragFrameNode(frameNode->GetId(), frameNode);
990     KeyEvent event;
991 
992     /**
993      * @tc.steps2: Call the function OnKeyEvent with isFocusActive_ = false, action = KeyAction::DOWN and
994      #             pressedCodes = { KeyCode::KEY_TAB }.
995      * @tc.expected: The return value of OnKeyEvent is true.
996      */
997     context_->SetIsFocusActive(false);
998     event.action = KeyAction::DOWN;
999     event.code = KeyCode::KEY_TAB;
1000     event.pressedCodes = { KeyCode::KEY_TAB };
1001     EXPECT_FALSE(context_->OnNonPointerEvent(event));
1002     EXPECT_TRUE(context_->GetIsFocusActive());
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     EXPECT_FALSE(context_->GetIsFocusActive());
1014 
1015     /**
1016      * @tc.steps4: Call the function OnKeyEvent with isFocusActive_ = false, action = KeyAction::UP and
1017      #             pressedCodes = { KeyCode::KEY_CLEAR }.
1018      * @tc.expected: The return value of OnKeyEvent is true.
1019      */
1020     context_->SetIsFocusActive(false);
1021     event.action = KeyAction::UP;
1022     event.code = KeyCode::KEY_CLEAR;
1023     event.pressedCodes = { KeyCode::KEY_CLEAR };
1024     EXPECT_FALSE(context_->OnNonPointerEvent(event));
1025     EXPECT_FALSE(context_->GetIsFocusActive());
1026 
1027     /**
1028      * @tc.steps4: Call the function OnKeyEvent with isFocusActive_ = true, action = KeyAction::UP and
1029      #             pressedCodes = { KeyCode::KEY_CLEAR }.
1030      * @tc.expected: The return value of OnKeyEvent is false.
1031      */
1032     context_->SetIsFocusActive(true);
1033     event.action = KeyAction::UP;
1034     event.code = KeyCode::KEY_CLEAR;
1035     event.pressedCodes = { KeyCode::KEY_CLEAR };
1036     EXPECT_FALSE(context_->OnNonPointerEvent(event));
1037     EXPECT_TRUE(context_->GetIsFocusActive());
1038 
1039     /**
1040     * @tc.steps5: Call the function OnKeyEvent with isFocusActive_ = true, action = KeyAction::UP and
1041     #             pressedCodes = { KeyCode::KEY_CLEAR }.
1042     * @tc.expected: The return value of OnKeyEvent is false.
1043     */
1044     context_->rootNode_.Reset();
1045     context_->SetIsFocusActive(true);
1046     event.action = KeyAction::DOWN;
1047     event.code = KeyCode::KEY_ESCAPE;
1048     event.pressedCodes = { KeyCode::KEY_ESCAPE };
1049 
1050     auto pageNodeId = ElementRegister::GetInstance()->MakeUniqueId();
1051     auto pageNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, pageNodeId, nullptr);
1052     auto childNodeId = ElementRegister::GetInstance()->MakeUniqueId();
1053     auto childNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, childNodeId, nullptr);
1054     pageNode->AddChild(childNode);
1055     context_->stageManager_->stageNode_ = pageNode;
1056     context_->ReDispatch(event);
1057     EXPECT_FALSE(context_->OnNonPointerEvent(event));
1058     EXPECT_FALSE(context_->dragDropManager_->isDragCancel_);
1059 
1060     event.isPreIme = 1;
1061     EXPECT_FALSE(context_->OnNonPointerEvent(event));
1062 }
1063 
1064 /**
1065  * @tc.name: PipelineContextTestNg023
1066  * @tc.desc: Test the function OnMouseEvent.
1067  * @tc.type: FUNC
1068  */
1069 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg023, TestSize.Level1)
1070 {
1071     /**
1072      * @tc.steps1: initialize parameters.
1073      * @tc.expected: All pointer is non-null.
1074      */
1075     ASSERT_NE(context_, nullptr);
1076     context_->SetupRootElement();
1077     MouseEvent event;
1078 
1079     /**
1080      * @tc.steps2: Call the function OnMouseEvent with action = MouseAction::HOVER
1081      *             and button = MouseButton::BACK_BUTTON.
1082      * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1083      */
1084     event.action = MouseAction::HOVER;
1085     event.button = MouseButton::BACK_BUTTON;
1086     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1087     context_->OnMouseEvent(event);
1088     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1089 
1090     /**
1091      * @tc.steps3: Call the function OnMouseEvent with action = MouseAction::RELEASE
1092      *             and button = MouseButton::LEFT_BUTTON.
1093      * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1094      */
1095     event.action = MouseAction::RELEASE;
1096     event.button = MouseButton::LEFT_BUTTON;
1097     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1098     context_->OnMouseEvent(event);
1099     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1100 
1101     /**
1102      * @tc.steps4: Call the function OnMouseEvent with action = MouseAction::PRESS
1103      *             and button = MouseButton::LEFT_BUTTON.
1104      * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1105      */
1106     event.action = MouseAction::PRESS;
1107     event.button = MouseButton::LEFT_BUTTON;
1108     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1109     context_->OnMouseEvent(event);
1110     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1111 
1112     /**
1113      * @tc.steps5: Call the function OnMouseEvent with action = MouseAction::MOVE
1114      *             and button = MouseButton::LEFT_BUTTON.
1115      * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1116      */
1117     event.action = MouseAction::MOVE;
1118     event.button = MouseButton::LEFT_BUTTON;
1119     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1120     context_->OnMouseEvent(event);
1121     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1122 
1123     /**
1124      * @tc.steps6: Call the function OnMouseEvent with action = MouseAction::RELEASE
1125      *             and pressedButtons = MOUSE_PRESS_LEFT.
1126      * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1127      */
1128     event.button = MouseButton::BACK_BUTTON;
1129     event.action = MouseAction::RELEASE;
1130     event.pressedButtons = MOUSE_PRESS_LEFT;
1131     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1132     context_->OnMouseEvent(event);
1133     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1134 
1135     /**
1136      * @tc.steps7: Call the function OnMouseEvent with action = MouseAction::PRESS
1137      *             and pressedButtons = MOUSE_PRESS_LEFT.
1138      * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1139      */
1140     event.action = MouseAction::PRESS;
1141     event.pressedButtons = MOUSE_PRESS_LEFT;
1142     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1143     context_->OnMouseEvent(event);
1144     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1145 
1146     /**
1147      * @tc.steps8: Call the function OnMouseEvent with action = MouseAction::MOVE
1148      *             and pressedButtons = MOUSE_PRESS_LEFT.
1149      * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1150      */
1151     event.action = MouseAction::MOVE;
1152     event.pressedButtons = MOUSE_PRESS_LEFT;
1153     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1154     context_->OnMouseEvent(event);
1155     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1156 
1157     /**
1158      * @tc.steps9: Call the function OnMouseEvent with action = MouseAction::MOVE
1159      *             and pressedButtons = MOUSE_PRESS_LEFT.
1160      * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1161      */
1162     event.button = MouseButton::RIGHT_BUTTON;
1163     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1164     context_->OnMouseEvent(event);
1165     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1166 
1167     /**
1168      * @tc.steps9: Call the function OnMouseEvent with action = MouseAction::MOVE
1169      *             and pressedButtons = MOUSE_PRESS_LEFT.
1170      * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1171      */
1172     event.button = MouseButton::RIGHT_BUTTON;
1173     event.action = MouseAction::PRESS;
1174     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1175     context_->OnMouseEvent(event);
1176     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1177 }
1178 
1179 /**
1180  * @tc.name: PipelineContextTestNg024
1181  * @tc.desc: Test the function FlushTouchEvents.
1182  * @tc.type: FUNC
1183  */
1184 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg024, TestSize.Level1)
1185 {
1186     /**
1187      * @tc.steps1: initialize parameters.
1188      * @tc.expected: All pointer is non-null.
1189      */
1190     ASSERT_NE(context_, nullptr);
1191     context_->SetupRootElement();
1192     TouchEvent event;
1193     context_->touchEvents_.clear();
1194 
1195     /**
1196      * @tc.steps2: Call the function FlushTouchEvents with empty touchEvents_.
1197      * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1198      */
1199     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1200     context_->FlushTouchEvents();
1201     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1202 
1203     /**
1204      * @tc.steps3: Call the function FlushTouchEvents with unempty touchEvents_.
1205      * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1206      */
1207     context_->touchEvents_.push_back(event);
1208     context_->touchEvents_.push_back(event);
1209     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1210     context_->FlushTouchEvents();
1211     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1212 
1213     /**
1214      * @tc.steps4: Call the function FlushTouchEvents with unempty touchEvents_.
1215      * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1216      */
1217     TouchEvent event2;
1218     event2.id = 1;
1219     context_->touchEvents_.push_back(event);
1220     context_->touchEvents_.push_back(event2);
1221     ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1222     context_->FlushTouchEvents();
1223     EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1224 }
1225 
1226 /**
1227  * @tc.name: PipelineContextTestNg025
1228  * @tc.desc: Test the function OnDumpInfo.
1229  * @tc.type: FUNC
1230  */
1231 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg025, TestSize.Level1)
1232 {
1233     /**
1234      * @tc.steps1: initialize parameters.
1235      * @tc.expected: All pointer is non-null.
1236      */
1237     ASSERT_NE(context_, nullptr);
1238     context_->SetupRootElement();
1239 
1240     std::unique_ptr<std::ostream> ostream = std::make_unique<std::ostringstream>();
1241     ASSERT_NE(ostream, nullptr);
1242     DumpLog::GetInstance().SetDumpFile(std::move(ostream));
1243     /**
1244      * @tc.steps2: init a vector with some string params and
1245                 call OnDumpInfo with every param array.
1246      * @tc.expected: The return value is same as the expectation.
1247      */
1248     std::vector<std::vector<std::string>> params = { { "-element", "-lastpage" }, { "-element", "non-lastpage" },
1249         { "-element" }, { "-focus" }, { ACCESS_TAG }, { "-inspector" }, { "-render" }, { "-layer" }, { "-frontend" },
1250         { "-multimodal" }, { "-rotation", "1", "2", "3" }, { "-animationscale", "1", "2", "3" },
1251         { "-velocityscale", "1", "2", "3" }, { "-scrollfriction", "1", "2", "3" }, { "-threadstuck", "1", "2", "3" },
1252         { "-rotation" }, { "-animationscale" }, { "-velocityscale" }, { "-scrollfriction" }, { "-threadstuck" },
1253         { "test" }, { "-navigation" }, { "-focuswindowscene" }, { "-focusmanager" }, { "-jsdump" }, { "-event" },
1254         { "-imagecache" }, { "-imagefilecache" }, { "-allelements" }, { "-default" }, { "-overlay" }, { "--stylus" } };
1255     int turn = 0;
1256     for (; turn < params.size(); turn++) {
1257         EXPECT_TRUE(context_->OnDumpInfo(params[turn]));
1258     }
1259 }
1260 
1261 /**
1262  * @tc.name: PipelineContextTestNg026
1263  * @tc.desc: Test the function OnBackPressed.
1264  * @tc.type: FUNC
1265  */
1266 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg026, TestSize.Level1)
1267 {
1268     /**
1269      * @tc.steps1: initialize parameters.
1270      * @tc.expected: All pointer is non-null.
1271      */
1272     ASSERT_NE(context_, nullptr);
1273     context_->SetupRootElement();
1274 
1275     /**
1276      * @tc.steps2: Call the function OnBackPressed with weakFrontend_ is null.
1277      * @tc.expected: The return value of function is false.
1278      */
1279     context_->weakFrontend_.Reset();
1280     EXPECT_FALSE(context_->OnBackPressed());
1281 
1282     /**
1283      * @tc.steps3: Call the function OnBackPressed with the return value of
1284      *             fullScreenManager_->RequestFullScreen is true.
1285      * @tc.expected: The return value of function is true.
1286      */
1287     auto frontend = AceType::MakeRefPtr<MockFrontend>();
1288     EXPECT_CALL(*frontend, OnBackPressed()).WillRepeatedly(testing::Return(true));
1289     context_->weakFrontend_ = frontend;
1290     auto frameNodeId = ElementRegister::GetInstance()->MakeUniqueId();
1291     auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId, nullptr);
1292     context_->fullScreenManager_->RequestFullScreen(frameNode); // Set the return value of OnBackPressed to true;
1293     EXPECT_TRUE(context_->OnBackPressed());
1294 
1295     /**
1296      * @tc.steps4: Call the function OnBackPressed with the return value of
1297      *             fullScreenManager_->RequestFullScreen is true.
1298      * @tc.expected: The return value of function is true.
1299      */
1300     // Set the return value of OnBackPressed of fullScreenManager_ to true;
1301     context_->fullScreenManager_->ExitFullScreen(frameNode);
1302     EXPECT_TRUE(context_->OnBackPressed());
1303 
1304     /**
1305      * @tc.steps5: Call the function OnBackPressed with the return value of
1306      *             overlayManager_->RemoveOverlay is true.
1307      * @tc.expected: The return value of function is true.
1308      */
1309     // Set the return value of RemoveOverlay of overlayManager_ to true;
1310     context_->overlayManager_->CloseDialog(frameNode_);
1311     EXPECT_TRUE(context_->OnBackPressed());
1312 
1313     /**
1314      * @tc.steps6: Call the function OnBackPressed with the return value of
1315      *             overlayManager_->RemoveOverlay is true.
1316      * @tc.expected: The return value of function is true.
1317      */
1318     // Set the return value of RemoveOverlay of overlayManager_ to true;
1319     context_->overlayManager_->CloseDialog(frameNode);
1320     EXPECT_TRUE(context_->OnBackPressed());
1321 }
1322 
1323 /**
1324  * @tc.name: PipelineContextTestNg027
1325  * @tc.desc: Test functions StartWindowSizeChangeAnimate and SetRootRect.
1326  * @tc.type: FUNC
1327  */
1328 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg027, TestSize.Level1)
1329 {
1330     /**
1331      * @tc.steps1: initialize parameters.
1332      * @tc.expected: All pointer is non-null.
1333      */
1334     ASSERT_NE(context_, nullptr);
1335     EXPECT_CALL(*(MockWindow*)(context_->window_.get()), SetDrawTextAsBitmap(_)).Times(AnyNumber());
1336     context_->SetupRootElement();
1337     auto frontend = AceType::MakeRefPtr<MockFrontend>();
1338     auto& windowConfig = frontend->GetWindowConfig();
1339     windowConfig.designWidth = DEFAULT_INT1;
1340     context_->weakFrontend_ = frontend;
1341 
1342     /**
1343      * @tc.steps2: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::RECOVER.
1344      * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1345      */
1346     context_->designWidthScale_ = DEFAULT_DOUBLE0;
1347     context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::RECOVER);
1348     EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1349 
1350     /**
1351      * @tc.steps3: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::MAXIMIZE.
1352      * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1353      */
1354     context_->designWidthScale_ = DEFAULT_DOUBLE0;
1355     context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::MAXIMIZE);
1356     EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1357 
1358     /**
1359      * @tc.steps4: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::ROTATION.
1360      * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1361      */
1362     context_->designWidthScale_ = DEFAULT_DOUBLE0;
1363     auto manager = AceType::MakeRefPtr<TextFieldManagerNG>();
1364     context_->SetTextFieldManager(manager);
1365     context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::ROTATION);
1366     EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1367 
1368     /**
1369      * @tc.steps5: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::UNDEFINED.
1370      * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1371      */
1372     context_->designWidthScale_ = DEFAULT_DOUBLE0;
1373     context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::UNDEFINED);
1374     EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1375 
1376     /**
1377      * @tc.steps5: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::UNDEFINED.
1378      * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1379      */
1380     SystemProperties::windowAnimationEnabled_ = false;
1381     context_->rootNode_->geometryNode_->frame_.rect_.y_ = 3.0;
1382     context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::UNDEFINED);
1383     EXPECT_EQ(context_->rootNode_->GetGeometryNode()->GetFrameOffset().GetY(), 0);
1384 }
1385 
1386 /**
1387  * @tc.name: PipelineContextTestNg028
1388  * @tc.desc: Test functions OnVirtualKeyboardHeightChange and SetRootRect.
1389  * @tc.type: FUNC
1390  */
1391 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg028, TestSize.Level1)
1392 {
1393     /**
1394      * @tc.steps1: initialize parameters.
1395      * @tc.expected: All pointer is non-null.
1396      */
1397     ASSERT_NE(context_, nullptr);
1398     context_->SetupRootElement();
1399     auto frontend = AceType::MakeRefPtr<MockFrontend>();
1400     auto& windowConfig = frontend->GetWindowConfig();
1401     windowConfig.designWidth = DEFAULT_INT1;
1402     context_->weakFrontend_ = frontend;
1403     context_->SetTextFieldManager(AceType::MakeRefPtr<TextFieldManagerNG>());
1404 
1405     /**
1406      * @tc.steps2: Call the function OnVirtualKeyboardHeightChange with DEFAULT_DOUBLE1.
1407      * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT0.
1408      */
1409     context_->designWidthScale_ = DEFAULT_DOUBLE1;
1410     context_->OnVirtualKeyboardHeightChange(DEFAULT_DOUBLE1);
1411     context_->OnVirtualKeyboardHeightChange(DEFAULT_DOUBLE1, 0, 0);
1412     EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_DOUBLE1);
1413     EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), 0);
1414 
1415     /**
1416      * @tc.steps3: init data and Call the function OnVirtualKeyboardHeightChange
1417                     when textFieldManager_ is null.
1418      * @tc.expected: the return is same as expectation.
1419      */
1420     context_->textFieldManager_ = nullptr;
1421 
1422     // the first arg is rootHeight_, the second arg is the parameter of function,
1423     // the third arg is the expectation returns
1424     std::vector<std::vector<int>> params = { { 200, 400, -300 }, { -200, 100, -100 }, { -200, -300, 300 },
1425         { 200, 0, 0 } };
1426     for (int turn = 0; turn < params.size(); turn++) {
1427         context_->rootHeight_ = params[turn][0];
1428         context_->OnVirtualKeyboardHeightChange(params[turn][1]);
1429         context_->OnVirtualKeyboardHeightChange(params[turn][1], 0, 0);
1430         EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), params[turn][2]);
1431     }
1432     /**
1433      * @tc.steps4: init data and Call the function OnVirtualKeyboardHeightChange
1434                     when textFieldManager_ is not null.
1435      * @tc.expected: the return is same as expectation.
1436      */
1437     auto manager = AceType::MakeRefPtr<TextFieldManagerNG>();
1438     context_->textFieldManager_ = manager;
1439     ASSERT_NE(context_->rootNode_, nullptr);
1440 
1441     // the first arg is manager->height_, the second arg is manager->position_.deltaY_
1442     // the third arg is rootHeight_, the forth arg is context_->rootNode_->geometryNode_->frame_.rect_.y_
1443     // the fifth arg is the parameter of function, the sixth arg is the expectation returns
1444     params = { { 10, 100, 300, 0, 50, 0 }, { 10, 100, 300, 100, 100, 0 }, { 30, 100, 300, 100, 50, 0 },
1445         { 50, 290, 400, 100, 200, -95 }, { -1000, 290, 400, 100, 200, 100 } };
1446     for (int turn = 0; turn < params.size(); turn++) {
1447         manager->height_ = params[turn][0];
1448         manager->position_.deltaY_ = params[turn][1];
1449         context_->rootHeight_ = params[turn][2];
1450         context_->rootNode_->geometryNode_->frame_.rect_.y_ = params[turn][3];
1451         context_->safeAreaManager_->UpdateKeyboardOffset(params[turn][3]);
1452         manager->SetClickPositionOffset(params[turn][3]);
1453         context_->OnVirtualKeyboardHeightChange(params[turn][4]);
1454         context_->OnVirtualKeyboardHeightChange(params[turn][4], 0, 0);
1455         EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), params[turn][5]);
1456     }
1457 }
1458 
1459 /**
1460  * @tc.name: PipelineContextTestNg029
1461  * @tc.desc: Test ThemeManager and SharedImageManager multithread.
1462  * @tc.type: FUNC
1463  */
1464 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg029, TestSize.Level1)
1465 {
1466     std::vector<std::thread> threads;
1467     for (int i = 0; i < 20; ++i) {
__anon4f3201820802() 1468         threads.emplace_back(std::thread([]() { context_->GetOrCreateSharedImageManager(); }));
1469     }
1470     for (auto&& thread : threads) {
1471         thread.join();
1472     }
1473 
1474     threads.clear();
1475     for (int i = 0; i < 20; ++i) {
1476         if (i == 10) {
1477             context_->SetThemeManager(AceType::MakeRefPtr<MockThemeManager>());
1478         } else {
__anon4f3201820902() 1479             threads.emplace_back(std::thread([]() { context_->GetThemeManager(); }));
1480         }
1481     }
1482     for (auto&& thread : threads) {
1483         thread.join();
1484     }
1485     EXPECT_TRUE(context_->GetThemeManager());
1486 }
1487 
1488 /**
1489  * @tc.name: PipelineContextTestNg030
1490  * @tc.desc: Test RestoreNodeInfo, GetStoredNodeInfo, StoreNode and GetRestoreInfo.
1491  * @tc.type: FUNC
1492  */
1493 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg030, TestSize.Level1)
1494 {
1495     /**
1496      * @tc.steps1: init a mockPattern.
1497      * @tc.expected: some calls by mockPattern.
1498      */
1499     RefPtr<MockPattern> mockPattern_ = AceType::MakeRefPtr<MockPattern>();
1500     Mock::AllowLeak(mockPattern_.rawPtr_);
1501     EXPECT_CALL(*mockPattern_, ProvideRestoreInfo())
1502         .Times(AnyNumber())
1503         .WillRepeatedly(testing::Return("Default restore info"));
1504     EXPECT_CALL(*mockPattern_, GetContextParam()).Times(AnyNumber()).WillRepeatedly(testing::Return(std::nullopt));
1505     EXPECT_CALL(*mockPattern_, CreatePaintProperty())
1506         .Times(AnyNumber())
1507         .WillRepeatedly(testing::Return(AceType::MakeRefPtr<PaintProperty>()));
1508     EXPECT_CALL(*mockPattern_, CreateLayoutProperty())
1509         .Times(AnyNumber())
1510         .WillRepeatedly(testing::Return(AceType::MakeRefPtr<LayoutProperty>()));
1511     EXPECT_CALL(*mockPattern_, CreateEventHub())
1512         .Times(AnyNumber())
1513         .WillRepeatedly(testing::Return(AceType::MakeRefPtr<EventHub>()));
1514     EXPECT_CALL(*mockPattern_, CreateAccessibilityProperty())
1515         .Times(AnyNumber())
1516         .WillRepeatedly(testing::Return(AceType::MakeRefPtr<AccessibilityProperty>()));
1517     EXPECT_CALL(*mockPattern_, OnAttachToFrameNode()).Times(AnyNumber());
1518     EXPECT_CALL(*mockPattern_, OnDetachFromFrameNode(_)).Times(AnyNumber());
1519 
1520     /**
1521      * @tc.steps2: init a patternCreator and Create frameNodes and call StoreNode.
1522      * @tc.expected: StoreNode success.
1523      */
__anon4f3201820a02() 1524     auto patternCreator_ = [&mockPattern_]() { return mockPattern_; };
1525     frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1526     auto frameNode_1 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
1527     ASSERT_NE(context_, nullptr);
1528     context_->StoreNode(DEFAULT_RESTORE_ID0, frameNode_1);
1529     EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID0], frameNode_1);
1530     frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1531     auto frameNode_2 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, patternCreator_);
1532     context_->StoreNode(DEFAULT_RESTORE_ID0, frameNode_2);
1533     EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID0], frameNode_2);
1534     frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1535     auto frameNode_3 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
1536     context_->StoreNode(DEFAULT_RESTORE_ID1, frameNode_3);
1537     EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID1], frameNode_3);
1538     context_->storeNode_[DEFAULT_RESTORE_ID2] = nullptr;
1539 
1540     /**
1541      * @tc.steps3: call RestoreNodeInfo with nullptr.
1542      * @tc.expected: restoreNodeInfo_ is empty.
1543      */
1544     auto jsonNodeInfo = context_->GetStoredNodeInfo();
1545     context_->RestoreNodeInfo(jsonNodeInfo->GetChild());
1546     EXPECT_TRUE(context_->restoreNodeInfo_.empty());
1547 
1548     /**
1549      * @tc.steps4: call GetStoredNodeInfo and RestoreNodeInfo.
1550      * @tc.expected: restoreNodeInfo_ is not empty.
1551      */
1552     context_->RestoreNodeInfo(std::move(jsonNodeInfo));
1553     EXPECT_FALSE(context_->restoreNodeInfo_.empty());
1554 
1555     /**
1556      * @tc.steps5: call GetRestoreInfo.
1557      * @tc.expected: restoreInfo is not "Default restore info".
1558                     DEFAULT_RESTORE_ID0:"Default restore info" is moved from restoreNodeInfo_.
1559      */
1560     std::string restoreInfo;
1561     auto rt = context_->GetRestoreInfo(DEFAULT_RESTORE_ID0, restoreInfo);
1562     EXPECT_EQ(restoreInfo, "Default restore info");
1563     EXPECT_TRUE(rt);
1564     rt = context_->GetRestoreInfo(DEFAULT_RESTORE_ID0, restoreInfo);
1565     EXPECT_FALSE(rt);
1566     auto iter1 = context_->restoreNodeInfo_.find(DEFAULT_RESTORE_ID0);
1567     EXPECT_EQ(iter1, context_->restoreNodeInfo_.end());
1568 }
1569 
1570 /**
1571  * @tc.name: PipelineContextTestNg032
1572  * @tc.desc: Test OnSurfacePositionChanged RegisterSurfacePositionChangedCallback
1573  * UnregisterSurfacePositionChangedCallback.
1574  * @tc.type: FUNC
1575  */
1576 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg032, TestSize.Level1)
1577 {
1578     /**
1579      * @tc.steps1: initialize parameters and call RegisterSurfacePositionChangedCallback with null.
1580      * @tc.expected: rt is 0.
1581      */
1582     ASSERT_NE(context_, nullptr);
1583     int32_t rt = context_->RegisterSurfacePositionChangedCallback(nullptr);
1584     EXPECT_EQ(rt, 0);
1585     /**
1586      * @tc.steps2: init a callback, register it and change map memory.
1587                 then call OnSurfacePositionChanged.
1588      * @tc.expected: flag is true.
1589      */
1590     bool flag = false;
__anon4f3201820b02(int32_t input_1, int32_t input_2) 1591     auto callback_1 = [&flag](int32_t input_1, int32_t input_2) { flag = !flag; };
1592     rt = context_->RegisterSurfacePositionChangedCallback(std::move(callback_1));
1593     context_->surfacePositionChangedCallbackMap_[100] = nullptr;
1594     context_->OnSurfacePositionChanged(0, 0);
1595     EXPECT_TRUE(flag);
1596     /**
1597      * @tc.steps2: call UnregisterSurfacePositionChangedCallback.
1598                 then call OnSurfacePositionChanged.
1599      * @tc.expected: flag is true.
1600      */
1601     context_->UnregisterSurfacePositionChangedCallback(rt);
1602     context_->OnSurfacePositionChanged(0, 0);
1603     EXPECT_TRUE(flag);
1604 }
1605 
1606 /**
1607  * @tc.name: PipelineContextTestNg040
1608  * @tc.desc: Test SetContainerButtonHide function.
1609  * @tc.type: FUNC
1610  */
1611 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg040, TestSize.Level1)
1612 {
1613     /**
1614      * @tc.steps1: initialize root node and containerModal node.
1615      * @tc.expected: root node and containerModal node are not null.
1616      */
1617     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1618     context_->SetThemeManager(themeManager);
1619     auto themeConstants = AceType::MakeRefPtr<ThemeConstants>(nullptr);
1620     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<ContainerModalTheme>()));
1621     EXPECT_CALL(*themeManager, GetThemeConstants()).WillRepeatedly(Return(themeConstants));
1622 
1623     ASSERT_NE(context_, nullptr);
1624     context_->SetWindowModal(WindowModal::CONTAINER_MODAL);
1625     ASSERT_NE(context_->window_, nullptr);
1626     context_->SetupRootElement();
1627     ASSERT_NE(context_->GetRootElement(), nullptr);
1628     auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
1629     ASSERT_NE(containerNode, nullptr);
1630     auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1631     ASSERT_NE(containerPattern, nullptr);
1632     /**
1633      * @tc.steps2: call SetContainerButtonHide with params true, true, false, false.
1634      * @tc.expected: depends on first param, hideSplitButton value is true.
1635      */
1636     context_->SetContainerButtonHide(true, true, false, false);
1637     EXPECT_TRUE(containerPattern->hideSplitButton_ == true);
1638     /**
1639      * @tc.steps3: call SetContainerButtonHide with params false, true, false, false.
1640      * @tc.expected: depends on first param, hideSplitButton value is false.
1641      */
1642     context_->SetContainerButtonHide(false, true, false, false);
1643     EXPECT_TRUE(containerPattern->hideSplitButton_ == false);
1644 
1645     /**
1646      * @tc.steps4: call SetContainerButtonHide with params false, true, false, false.
1647      * @tc.expected: cover branch windowModal_ is not CONTAINER_MODAL
1648      */
1649     context_->SetWindowModal(WindowModal::DIALOG_MODAL);
1650     context_->SetContainerButtonHide(false, true, false, false);
1651     EXPECT_FALSE(containerPattern->hideSplitButton_);
1652 }
1653 
1654 /**
1655  * @tc.name: PipelineContextTestNg043
1656  * @tc.desc: Test SetCloseButtonStatus function.
1657  * @tc.type: FUNC
1658  */
1659 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg043, TestSize.Level1)
1660 {
1661     /**
1662      * @tc.steps1: initialize root node and containerModal node.
1663      * @tc.expected: root node and containerModal node are not null.
1664      */
1665     ASSERT_NE(context_, nullptr);
1666     context_->SetWindowModal(WindowModal::CONTAINER_MODAL);
1667     ASSERT_NE(context_->window_, nullptr);
1668     context_->SetupRootElement();
1669     ASSERT_NE(context_->GetRootElement(), nullptr);
1670     auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
1671     ASSERT_NE(containerNode, nullptr);
1672     auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1673     ASSERT_NE(containerPattern, nullptr);
1674     auto columNode = AceType::DynamicCast<FrameNode>(containerNode->GetChildren().front());
1675     CHECK_NULL_VOID(columNode);
1676     auto titleNode = AceType::DynamicCast<FrameNode>(columNode->GetChildren().front());
1677     CHECK_NULL_VOID(titleNode);
1678     auto closeButton = AceType::DynamicCast<FrameNode>(titleNode->GetChildAtIndex(CLOSE_BUTTON_INDEX));
1679     CHECK_NULL_VOID(closeButton);
1680     auto buttonEvent = closeButton->GetEventHub<ButtonEventHub>();
1681     CHECK_NULL_VOID(buttonEvent);
1682     /**
1683      * @tc.steps2: call SetCloseButtonStatus with params true.
1684      * @tc.expected: CloseButton IsEnabled return true.
1685      */
1686     context_->SetCloseButtonStatus(true);
1687     EXPECT_EQ(buttonEvent->IsEnabled(), true);
1688     /**
1689      * @tc.steps3: call SetCloseButtonStatus with params false.
1690      * @tc.expected: CloseButton IsEnabled return false.
1691      */
1692     context_->SetCloseButtonStatus(false);
1693     EXPECT_EQ(buttonEvent->IsEnabled(), false);
1694 }
1695 
1696 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg060, TestSize.Level1)
1697 {
1698     /**
1699      * @tc.steps1: initialize parameters.
1700      * @tc.expected: All pointer is non-null.
1701      */
1702     ASSERT_NE(context_, nullptr);
1703     context_->SetupRootElement();
1704     auto frontend = AceType::MakeRefPtr<MockFrontend>();
1705     auto& windowConfig = frontend->GetWindowConfig();
1706     windowConfig.designWidth = DEFAULT_INT1;
1707     context_->weakFrontend_ = frontend;
1708     context_->SetTextFieldManager(AceType::MakeRefPtr<TextFieldManagerNG>());
1709 
1710     /**
1711      * @tc.steps2: Set EnableAvoidKeyboardMode is true.
1712      * @tc.expected: get KeyboardSafeAreaEnabled is true.
1713      */
1714     context_->SetEnableKeyBoardAvoidMode(KeyBoardAvoidMode::RESIZE);
1715     EXPECT_TRUE(context_->GetSafeAreaManager()->KeyboardSafeAreaEnabled());
1716 
1717     /**
1718      * @tc.steps3: set root height and change virtual keyboard height.
1719      * @tc.expected: Resize the root height after virtual keyboard change.
1720      */
1721 
1722     auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
1723     ASSERT_NE(containerNode, nullptr);
1724     auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1725     ASSERT_NE(containerPattern, nullptr);
1726     auto columNode = AceType::DynamicCast<FrameNode>(containerNode->GetChildren().front());
1727     CHECK_NULL_VOID(columNode);
1728 
1729     std::vector<std::vector<int>> params = { { 100, 400, 100 }, { 300, 100, 300 }, { 400, -300, 400 },
1730         { 200, 0, 200 } };
1731     for (int turn = 0; turn < params.size(); turn++) {
1732         context_->rootHeight_ = params[turn][0];
1733         context_->OnVirtualKeyboardHeightChange(params[turn][1]);
1734         EXPECT_EQ(context_->GetRootHeight(), params[turn][2]);
1735     }
1736 }
1737 /**
1738  * @tc.name: PipelineContextTestNg061
1739  * @tc.desc: Test the function WindowUnFocus.
1740  * @tc.type: FUNC
1741  */
1742 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg061, TestSize.Level1)
1743 {
1744     /**
1745      * @tc.steps1: initialize parameters.
1746      * @tc.expected: All pointer is non-null.
1747      */
1748     ASSERT_NE(context_, nullptr);
1749     context_->SetupRootElement();
1750     ASSERT_NE(context_->rootNode_, nullptr);
1751     auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
1752     auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1753 
1754     /**
1755      * @tc.steps3: Call the function WindowUnFocus with WindowFocus(true).
1756      * @tc.expected: containerPattern isFocus_ is true.
1757      */
1758     containerPattern->isFocus_ = true;
1759     containerPattern->OnWindowForceUnfocused();
1760     EXPECT_TRUE(containerPattern->isFocus_);
1761 
1762     /**
1763      * @tc.steps2: Call the function WindowUnFocus with WindowFocus(false).
1764      * @tc.expected: containerPattern isFocus_ is false.
1765      */
1766     containerPattern->WindowFocus(false);
1767     containerPattern->OnWindowForceUnfocused();
1768     EXPECT_FALSE(containerPattern->isFocus_);
1769 }
1770 
1771 /**
1772  * @tc.name: PipelineContextTestNg088
1773  * @tc.desc: Test the function FlushRequestFocus.
1774  * @tc.type: FUNC
1775  */
1776 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg088, TestSize.Level1)
1777 {
1778     /**
1779      * @tc.steps1: initialize parameters.
1780      * @tc.expected: All pointer is non-null.
1781      */
1782     ASSERT_NE(context_, nullptr);
1783     context_->SetupRootElement();
1784 
1785     /**
1786      * @tc.steps2: Call the function FlushRequestFocus.
1787      * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
1788      */
1789     context_->FlushRequestFocus();
1790     EXPECT_EQ(context_->dirtyRequestFocusNode_.Upgrade(), nullptr);
1791     context_->dirtyRequestFocusNode_ = frameNode_;
1792     EXPECT_NE(context_->dirtyRequestFocusNode_.Upgrade(), nullptr);
1793 }
1794 
1795 /**
1796  * @tc.name: PipelineContextTestNg089
1797  * @tc.desc: Test the function FlushFocusScroll.
1798  * @tc.type: FUNC
1799  */
1800 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg089, TestSize.Level1)
1801 {
1802     /**
1803      * @tc.steps1: initialize parameters.
1804      * @tc.expected: All pointer is non-null.
1805      */
1806     ASSERT_NE(context_, nullptr);
1807     context_->SetupRootElement();
1808 
1809     /**
1810      * @tc.steps2: Call the function FlushRequestFocus.
1811      * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
1812      */
1813     context_->focusManager_.Reset();
1814     context_->FlushFocusScroll();
1815     EXPECT_EQ(context_->focusManager_, nullptr);
1816     context_->GetOrCreateFocusManager();
1817     EXPECT_NE(context_->focusManager_, nullptr);
1818 }
1819 
1820 /**
1821  * @tc.name: PipelineContextTestNg090
1822  * @tc.desc: Test the function FlushFocusView.
1823  * @tc.type: FUNC
1824  */
1825 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg090, TestSize.Level1)
1826 {
1827     /**
1828      * @tc.steps1: initialize parameters and call FlushFocusView.
1829      * @tc.expected: All pointer is non-null.
1830      */
1831     ASSERT_NE(context_, nullptr);
1832     context_->SetupRootElement();
1833     context_->SetupSubRootElement();
1834 
1835     context_->FlushFocusView();
1836     EXPECT_NE(context_->focusManager_, nullptr);
1837 }
1838 
1839 /**
1840  * @tc.name: PipelineContextTestNg091
1841  * @tc.desc: Test the function SendEventToAccessibilityWithNode.
1842  * @tc.type: FUNC
1843  */
1844 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg091, TestSize.Level1)
1845 {
1846     /**
1847      * @tc.steps1: initialize parameters.
1848      * @tc.expected: All pointer is non-null.
1849      */
1850     ASSERT_NE(context_, nullptr);
1851     context_->SetupRootElement();
1852 
1853     /**
1854      * @tc.steps2: Call the function FlushRequestFocus.
1855      * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
1856      */
1857     AccessibilityEvent event;
1858     event.windowChangeTypes = WindowUpdateType::WINDOW_UPDATE_ACTIVE;
1859     event.type = AccessibilityEventType::PAGE_CHANGE;
1860     auto frameNodeId_091 = ElementRegister::GetInstance()->MakeUniqueId();
1861     auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_091, nullptr);
1862     CHECK_NULL_VOID(frameNode);
1863     context_->SendEventToAccessibilityWithNode(event, frameNode);
1864     bool accessibilityEnabled = AceApplicationInfo::GetInstance().IsAccessibilityEnabled();
1865     EXPECT_FALSE(accessibilityEnabled);
1866 
1867     AceApplicationInfo::GetInstance().SetAccessibilityEnabled(true);
1868     context_->SendEventToAccessibilityWithNode(event, frameNode);
1869     accessibilityEnabled = AceApplicationInfo::GetInstance().IsAccessibilityEnabled();
1870     EXPECT_TRUE(accessibilityEnabled);
1871 }
1872 
1873 /**
1874  * @tc.name: PipelineContextTestNg092
1875  * @tc.desc: Test the function GetContainerModalButtonsRect.
1876  * @tc.type: FUNC
1877  */
1878 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg092, TestSize.Level1)
1879 {
1880     /**
1881      * @tc.steps1: initialize parameters.
1882      * @tc.expected: All pointer is non-null.
1883      */
1884     ASSERT_NE(context_, nullptr);
1885     std::vector<Ace::RectF> rects;
1886     context_->TriggerOverlayNodePositionsUpdateCallback(rects);
__anon4f3201820c02(std::vector<Ace::RectF> rect) 1887     context_->RegisterOverlayNodePositionsUpdateCallback([](std::vector<Ace::RectF> rect) {});
1888     context_->TriggerOverlayNodePositionsUpdateCallback(rects);
1889     context_->windowManager_ = AceType::MakeRefPtr<WindowManager>();
1890     context_->windowModal_ = WindowModal::NORMAL;
1891     NG::RectF containerModal;
1892     NG::RectF buttons;
1893     context_->GetCustomTitleHeight();
1894     bool callbackTriggered = false;
__anon4f3201820d02(RectF&, RectF&) 1895     auto callback = [&callbackTriggered](RectF&, RectF&) { callbackTriggered = true; };
1896     context_->SubscribeContainerModalButtonsRectChange(std::move(callback));
1897     EXPECT_FALSE(context_->GetContainerModalButtonsRect(containerModal, buttons));
1898     context_->windowModal_ = WindowModal::CONTAINER_MODAL;
1899     context_->SubscribeContainerModalButtonsRectChange(std::move(callback));
1900     EXPECT_FALSE(context_->GetContainerModalButtonsRect(containerModal, buttons));
1901 }
1902 
1903 /**
1904  * @tc.name: PipelineContextTestNg093
1905  * @tc.desc: Test the function PrintVsyncInfoIfNeed.
1906  * @tc.type: FUNC
1907  */
1908 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg093, TestSize.Level1)
1909 {
1910     /**
1911      * @tc.steps1: initialize parameters.
1912      * @tc.expected: All pointer is non-null.
1913      */
1914     ASSERT_NE(context_, nullptr);
1915     ASSERT_NE(context_->GetWindow(), nullptr);
1916     EXPECT_FALSE(context_->PrintVsyncInfoIfNeed());
1917 
1918     std::list<FrameInfo> dumpFrameInfos;
1919     FrameInfo frameInfo;
1920     dumpFrameInfos.push_back(frameInfo);
1921     context_->dumpFrameInfos_ = dumpFrameInfos;
1922     EXPECT_FALSE(context_->PrintVsyncInfoIfNeed());
1923     context_->dumpFrameInfos_.back().frameRecvTime_ = -1;
1924     EXPECT_FALSE(context_->PrintVsyncInfoIfNeed());
1925     context_->dumpFrameInfos_.clear();
1926 }
1927 
1928 /**
1929  * @tc.name: PipelineContextTestNg094
1930  * @tc.desc: Test the function ChangeDarkModeBrightness.
1931  * @tc.type: FUNC
1932  */
1933 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg094, TestSize.Level1)
1934 {
1935     /**
1936      * @tc.steps1: initialize parameters.
1937      * @tc.expected: All pointer is non-null.
1938      */
1939     ASSERT_NE(context_, nullptr);
1940     context_->windowManager_ = AceType::MakeRefPtr<WindowManager>();
1941 
1942     SystemProperties::SetColorMode(ColorMode::DARK);
1943     context_->SetAppBgColor(Color::BLACK);
1944     context_->ChangeDarkModeBrightness();
1945     context_->SetIsJsCard(true);
1946     context_->ChangeDarkModeBrightness();
1947     MockContainer::Current()->SetIsFormRender(true);
1948     context_->ChangeDarkModeBrightness();
1949     MockContainer::Current()->SetIsDynamicRender(true);
1950     context_->ChangeDarkModeBrightness();
1951     MockContainer::Current()->SetIsUIExtensionWindow(true);
1952     context_->ChangeDarkModeBrightness();
1953     context_->SetAppBgColor(Color::BLUE);
1954     context_->ChangeDarkModeBrightness();
1955     SystemProperties::SetColorMode(ColorMode::COLOR_MODE_UNDEFINED);
1956     context_->ChangeDarkModeBrightness();
1957     EXPECT_NE(context_->stageManager_, nullptr);
1958 }
1959 } // namespace NG
1960 } // namespace OHOS::Ace
1961