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 #include <algorithm>
16 #include <cstdint>
17 #include <iostream>
18 #include <memory>
19 #include <string>
20 #include <type_traits>
21 #include <vector>
22
23 #include "gtest/gtest.h"
24
25 // Add the following two macro definitions to test the private and protected method.
26 #define private public
27 #define protected public
28 #include "common_constants.h"
29 #include "mock_schedule_task.h"
30 #include "test/mock/base/mock_mouse_style.h"
31 #include "test/mock/base/mock_task_executor.h"
32 #include "test/mock/core/common/mock_container.h"
33 #include "test/mock/core/common/mock_font_manager.h"
34 #include "test/mock/core/common/mock_frontend.h"
35 #include "test/mock/core/common/mock_theme_manager.h"
36 #include "test/mock/core/common/mock_window.h"
37 #include "test/mock/core/pattern/mock_pattern.h"
38 #include "test/mock/core/render/mock_render_context.h"
39
40 #include "base/json/json_util.h"
41 #include "base/log/dump_log.h"
42 #include "base/log/frame_report.h"
43 #include "base/longframe/long_frame_report.h"
44 #include "base/memory/ace_type.h"
45 #include "base/memory/referenced.h"
46 #include "base/utils/system_properties.h"
47 #include "core/common/ace_application_info.h"
48 #include "core/common/ace_engine.h"
49 #include "core/common/event_manager.h"
50 #include "core/common/font_manager.h"
51 #include "core/common/window_animation_config.h"
52 #include "core/components/common/layout/constants.h"
53 #include "core/components_ng/base/frame_node.h"
54 #include "core/components_ng/event/event_hub.h"
55 #include "core/components_ng/event/focus_hub.h"
56 #include "core/components_ng/pattern/bubble/bubble_pattern.h"
57 #include "core/components_ng/pattern/button/button_event_hub.h"
58 #include "core/components_ng/pattern/container_modal/container_modal_pattern.h"
59 #include "core/components_ng/pattern/custom/custom_node.h"
60 #include "core/components_ng/pattern/image/image_layout_property.h"
61 #include "core/components_ng/pattern/navigation/navigation_group_node.h"
62 #include "core/components_ng/pattern/navigation/title_bar_node.h"
63 #include "core/components_ng/pattern/navrouter/navdestination_group_node.h"
64 #include "core/components_ng/pattern/text/text_pattern.h"
65 #include "core/components_ng/pattern/text_field/text_field_manager.h"
66 #include "core/components_ng/pattern/text_field/text_field_pattern.h"
67 #include "core/components_ng/property/safe_area_insets.h"
68 #include "core/components_ng/render/drawing_forward.h"
69 #include "core/event/mouse_event.h"
70 #include "core/pipeline/base/element_register.h"
71 #include "core/pipeline_ng/pipeline_context.h"
72
73 using namespace testing;
74 using namespace testing::ext;
75
76 namespace OHOS::Ace {
77 namespace NG {
78 namespace {
79 constexpr int32_t DEFAULT_INSTANCE_ID = 0;
80 constexpr int32_t DEFAULT_INT0 = 0;
81 constexpr int32_t DEFAULT_INT1 = 1;
82 constexpr int32_t DEFAULT_INT3 = 3;
83 constexpr int32_t DEFAULT_INT10 = 10;
84 constexpr int32_t DEFAULT_RESTORE_ID0 = 100;
85 constexpr int32_t DEFAULT_RESTORE_ID1 = 101;
86 constexpr int32_t DEFAULT_RESTORE_ID2 = 102;
87 constexpr int32_t NOT_REGISTER_ID = 307;
88 constexpr uint32_t DEFAULT_SIZE1 = 1;
89 constexpr uint32_t DEFAULT_SIZE2 = 2;
90 constexpr uint32_t DEFAULT_SIZE3 = 3;
91 constexpr uint32_t FRAME_COUNT = 10;
92 constexpr uint64_t NANO_TIME_STAMP = 10;
93 constexpr uint64_t DEFAULT_UINT64_1 = 39;
94 constexpr uint64_t DEFAULT_UINT64_2 = 41;
95 constexpr double DEFAULT_DOUBLE0 = 0.0;
96 constexpr double DEFAULT_DOUBLE1 = 1.0;
97 constexpr double DEFAULT_DOUBLE2 = 2.0;
98 constexpr double DEFAULT_DOUBLE4 = 4.0;
99 constexpr int32_t CLOSE_BUTTON_INDEX = 5;
100 const std::string TEST_TAG("test");
101 const std::string ACCESS_TAG("-accessibility");
102 const std::string TEST_FORM_INFO("test_info");
103 const int64_t RENDER_EVENT_ID = 10;
104 constexpr int32_t EXCEPTIONAL_CURSOR = 99;
105 } // namespace
106
107 class PipelineContextTestNg : public testing::Test {
108 public:
109 static void ResetEventFlag(int32_t testFlag);
110 static bool GetEventFlag(int32_t testFlag);
111 static void SetUpTestSuite();
112 static void TearDownTestSuite();
113 static void CreateCycleDirtyNode(int cycle, bool& flagUpdate);
114
115 private:
116 static ElementIdType frameNodeId_;
117 static ElementIdType customNodeId_;
118 static RefPtr<FrameNode> frameNode_;
119 static RefPtr<CustomNode> customNode_;
120 static RefPtr<PipelineContext> context_;
121 };
122
123 ElementIdType PipelineContextTestNg::frameNodeId_ = 0;
124 ElementIdType PipelineContextTestNg::customNodeId_ = 0;
125 RefPtr<FrameNode> PipelineContextTestNg::frameNode_ = nullptr;
126 RefPtr<CustomNode> PipelineContextTestNg::customNode_ = nullptr;
127 RefPtr<PipelineContext> PipelineContextTestNg::context_ = nullptr;
128
ResetEventFlag(int32_t testFlag)129 void PipelineContextTestNg::ResetEventFlag(int32_t testFlag)
130 {
131 auto flag = context_->eventManager_->GetInstanceId();
132 context_->eventManager_->SetInstanceId(flag & (~testFlag));
133 }
134
GetEventFlag(int32_t testFlag)135 bool PipelineContextTestNg::GetEventFlag(int32_t testFlag)
136 {
137 auto flag = context_->eventManager_->GetInstanceId();
138 return flag & testFlag;
139 }
140
SetUpTestSuite()141 void PipelineContextTestNg::SetUpTestSuite()
142 {
143 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
144 customNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
145 frameNode_ = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
146 // AddUINode is called in the function.
147 customNode_ = CustomNode::CreateCustomNode(customNodeId_, TEST_TAG);
148 ElementRegister::GetInstance()->AddUINode(frameNode_);
149 auto window = std::make_shared<MockWindow>();
150 EXPECT_CALL(*window, RequestFrame()).Times(AnyNumber());
151 EXPECT_CALL(*window, FlushTasks()).Times(AnyNumber());
152 EXPECT_CALL(*window, OnHide()).Times(AnyNumber());
153 EXPECT_CALL(*window, RecordFrameTime(_, _)).Times(AnyNumber());
154 EXPECT_CALL(*window, OnShow()).Times(AnyNumber());
155 EXPECT_CALL(*window, FlushAnimation(NANO_TIME_STAMP))
156 .Times(AtLeast(1))
157 .WillOnce(testing::Return(true))
158 .WillRepeatedly(testing::Return(false));
159 EXPECT_CALL(*window, FlushModifier()).Times(AtLeast(1));
160 EXPECT_CALL(*window, SetRootFrameNode(_)).Times(AnyNumber());
161 context_ = AceType::MakeRefPtr<PipelineContext>(
162 window, AceType::MakeRefPtr<MockTaskExecutor>(), nullptr, nullptr, DEFAULT_INSTANCE_ID);
163 context_->SetEventManager(AceType::MakeRefPtr<EventManager>());
164 MockContainer::SetUp();
165 MockContainer::Current()->pipelineContext_ = context_;
166 }
167
TearDownTestSuite()168 void PipelineContextTestNg::TearDownTestSuite()
169 {
170 context_->window_.reset();
171 MockContainer::TearDown();
172 }
173
CreateCycleDirtyNode(int cycle,bool & flagUpdate)174 void PipelineContextTestNg::CreateCycleDirtyNode(int cycle, bool& flagUpdate)
175 {
176 if (cycle <= 0) {
177 return;
178 }
179 cycle -= 1;
180 auto customNodeTemp = CustomNode::CreateCustomNode(customNodeId_ + cycle + 100, TEST_TAG);
181 customNodeTemp->SetUpdateFunction([cycle, &flagUpdate]() {
182 PipelineContextTestNg::CreateCycleDirtyNode(cycle, flagUpdate);
183 flagUpdate = !flagUpdate;
184 });
185 context_->AddDirtyCustomNode(customNodeTemp);
186 }
187
188 /**
189 * @tc.name: PipelineContextTestNg001
190 * @tc.desc: Test the function FlushDirtyNodeUpdate.
191 * @tc.type: FUNC
192 */
193 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg001, TestSize.Level1)
194 {
195 /**
196 * @tc.steps1: initialize parameters.
197 * @tc.expected: All pointer is non-null.
198 */
199 ASSERT_NE(context_, nullptr);
200 bool flagUpdate = false;
__anon695700410302() 201 customNode_->SetUpdateFunction([&flagUpdate]() { flagUpdate = true; });
202 context_->AddDirtyCustomNode(customNode_);
203
204 /**
205 * @tc.steps2: Call the function FlushDirtyNodeUpdate.
206 * @tc.expected: The flagUpdate is changed to true.
207 */
208 context_->FlushDirtyNodeUpdate();
209 EXPECT_TRUE(flagUpdate);
210
211 /**
212 * @tc.steps2: Call the function FlushDirtyNodeUpdate.
213 * @tc.expected: The flagUpdate is true.
214 * @tc.expected: The dirtyNodes is not empty.
215 */
216 auto customNode_1 = CustomNode::CreateCustomNode(customNodeId_ + 20, TEST_TAG);
__anon695700410402() 217 customNode_1->SetUpdateFunction([&flagUpdate]() { CreateCycleDirtyNode(5, flagUpdate); });
218 context_->AddDirtyCustomNode(customNode_1);
219 context_->AddDirtyCustomNode(frameNode_);
220 context_->FlushDirtyNodeUpdate();
221 EXPECT_TRUE(flagUpdate);
222 EXPECT_FALSE(context_->dirtyNodes_.empty());
223 context_->dirtyNodes_.clear();
224 }
225
226 /**
227 * @tc.name: PipelineContextTestNg002
228 * @tc.desc: Test the function FlushVsync, AddVisibleAreaChangeNode, HandleVisibleAreaChangeEvent and .
229 * @tc.type: FUNC
230 */
231 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg002, TestSize.Level1)
232 {
233 /**
234 * @tc.steps1: initialize parameters.
235 * @tc.expected: All pointer is non-null.
236 */
237 ASSERT_NE(context_, nullptr);
238 context_->SetupRootElement();
239
240 /**
241 * @tc.steps2: Call the function AddOnAreaChangeNode.
242 */
243 context_->onVisibleAreaChangeNodeIds_.clear();
244 context_->AddOnAreaChangeNode(frameNode_->GetId());
245 context_->AddOnAreaChangeNode(customNode_->GetId());
246 context_->AddOnAreaChangeNode(ElementRegister::UndefinedElementId);
247
248 /**
249 * @tc.steps3: Call the function AddVisibleAreaChangeNode.
250 * @tc.expected: The drawDelegate_ is null.
251 */
252 context_->onAreaChangeNodeIds_.clear();
253 context_->onAreaChangeNodeIds_.emplace(NOT_REGISTER_ID);
254 context_->onAreaChangeNodeIds_.emplace(customNode_->nodeId_);
255 context_->AddVisibleAreaChangeNode(frameNode_, DEFAULT_DOUBLE1, nullptr);
256 context_->AddVisibleAreaChangeNode(frameNode_, DEFAULT_DOUBLE1, nullptr, false);
257 EXPECT_EQ(context_->onVisibleAreaChangeNodeIds_.size(), DEFAULT_SIZE1);
258 context_->onVisibleAreaChangeNodeIds_.emplace(customNode_->GetId());
259 context_->onVisibleAreaChangeNodeIds_.emplace(ElementRegister::UndefinedElementId);
260 EXPECT_EQ(context_->onVisibleAreaChangeNodeIds_.size(), DEFAULT_SIZE3);
261
262 /**
263 * @tc.steps4: Call the function FlushVsync with isEtsCard=false.
264 * @tc.expected: The drawDelegate_ is null.
265 */
266 context_->onShow_ = false;
267 context_->SetIsFormRender(false);
268 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
269 EXPECT_EQ(context_->drawDelegate_, nullptr);
270
271 /**
272 * @tc.steps5: Call the function FlushVsync with isEtsCard=false.
273 * @tc.expected: The drawDelegate_ is non-null.
274 */
275 context_->onFocus_ = false;
276 context_->onAreaChangeNodeIds_.clear();
277 context_->SetDrawDelegate(std::make_unique<DrawDelegate>());
278 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
279 EXPECT_NE(context_->drawDelegate_, nullptr);
280 /**
281 * @tc.steps6: Call the function FlushVsync with isEtsCard=false
282 and processName equals to "".
283 * @tc.expected: The drawDelegate_ is non-null.
284 */
285 AceApplicationInfo::GetInstance().processName_ = "";
286 context_->onShow_ = true;
287 context_->onFocus_ = true;
288 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
289 EXPECT_NE(context_->drawDelegate_, nullptr);
290 }
291
292 /**
293 * @tc.name: PipelineContextTestNg003
294 * @tc.desc: Test the function FlushVsync and functions FlushLayoutTask and FlushRenderTask of the UITaskScheduler.
295 * @tc.type: FUNC
296 */
297 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg003, TestSize.Level1)
298 {
299 /**
300 * @tc.steps1: initialize parameters.
301 * @tc.expected: All pointer is non-null.
302 */
303 ASSERT_NE(context_, nullptr);
304 context_->SetupRootElement();
305
306 /**
307 * @tc.steps2: Add dirty layout and render nodes to taskScheduler_ to test functions
308 * FlushLayoutTask and FlushRenderTask of the UITaskScheduler.
309 */
310 context_->taskScheduler_->AddDirtyLayoutNode(frameNode_);
311 context_->taskScheduler_->AddDirtyRenderNode(frameNode_);
312 context_->taskScheduler_->dirtyRenderNodes_[frameNode_->GetPageId()].emplace(nullptr);
313
314 /**
315 * @tc.steps3: Call the function FlushVsync with isEtsCard=true.
316 * @tc.expected: The drawDelegate_ is null.
317 */
318 context_->onShow_ = true;
319 context_->onFocus_ = false;
320 context_->SetIsFormRender(true);
321 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
322 EXPECT_EQ(context_->drawDelegate_, nullptr);
323
324 /**
325 * @tc.steps4: Call the function FlushVsync with isEtsCard=true.
326 * @tc.expected: The drawDelegate_ is non-null.
327 */
328 context_->onFocus_ = true;
329 context_->SetDrawDelegate(std::make_unique<DrawDelegate>());
330 context_->FlushVsync(NANO_TIME_STAMP, FRAME_COUNT);
331 EXPECT_EQ(context_->drawDelegate_, nullptr);
332 }
333
334 /**
335 * @tc.name: PipelineContextTestNg004
336 * @tc.desc: Test the function FlushAnimation.
337 * @tc.type: FUNC
338 */
339 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg004, TestSize.Level1)
340 {
341 /**
342 * @tc.steps1: initialize parameters.
343 * @tc.expected: All pointer is non-null.
344 */
345 ASSERT_NE(context_, nullptr);
346
347 /**
348 * @tc.steps2: Call the function FlushAnimation with empty scheduleTasks_.
349 * @tc.expected: The scheduleTasks_ is null.
350 */
351 context_->FlushAnimation(NANO_TIME_STAMP);
352 EXPECT_TRUE(context_->scheduleTasks_.empty());
353
354 /**
355 * @tc.steps3: Call the function FlushAnimation with unempty scheduleTasks_.
356 * @tc.expected: The nanoTimestamp of scheduleTask is equal to NANO_TIME_STAMP.
357 */
358 auto scheduleTask = AceType::MakeRefPtr<MockScheduleTask>();
359 EXPECT_NE(scheduleTask->GetNanoTimestamp(), NANO_TIME_STAMP);
360 context_->AddScheduleTask(scheduleTask);
361 context_->AddScheduleTask(nullptr);
362 context_->FlushAnimation(NANO_TIME_STAMP);
363 EXPECT_EQ(scheduleTask->GetNanoTimestamp(), DEFAULT_INT0);
364 }
365
366 /**
367 * @tc.name: PipelineContextTestNg005
368 * @tc.desc: Test the function FlushFocus and RequestDefaultFocus.
369 * @tc.type: FUNC
370 */
371 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg005, TestSize.Level1)
372 {
373 /**
374 * @tc.steps1: initialize parameters.
375 * @tc.expected: All pointer is non-null.
376 */
377 ASSERT_NE(context_, nullptr);
378 context_->SetupRootElement();
379
380 /**
381 * @tc.steps2: Call the function FlushFocus.
382 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
383 */
384 context_->FlushFocus();
385 EXPECT_EQ(context_->dirtyFocusNode_.Upgrade(), nullptr);
386 /**
387 * @tc.steps2: Init a frameNode and SetFocusType with Node, Add dirty focus and call FlushFocus
388 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
389 */
390 auto eventHub = frameNode_->GetEventHub<EventHub>();
391 ASSERT_NE(eventHub, nullptr);
392 auto focusHub = eventHub->GetOrCreateFocusHub();
393 ASSERT_NE(focusHub, nullptr);
394 focusHub->SetFocusType(FocusType::NODE);
395 context_->AddDirtyFocus(frameNode_);
396 auto dirtyFocusNode = context_->dirtyFocusNode_.Upgrade();
397 ASSERT_NE(dirtyFocusNode, nullptr);
398 EXPECT_EQ(dirtyFocusNode->GetFocusType(), FocusType::NODE);
399 context_->FlushFocus();
400 EXPECT_EQ(context_->dirtyFocusNode_.Upgrade(), nullptr);
401 /**
402 * @tc.steps3: Init a new frameNode and SetFocusType with Node.
403 Add dirty focus, free focusHub_ and call FlushFocus
404 * @tc.expected: The dirtyFocusNode_ is changed to nullptr.
405 */
406 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
407 frameNode_ = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
408 eventHub = frameNode_->GetEventHub<EventHub>();
409 ASSERT_NE(eventHub, nullptr);
410 focusHub = eventHub->GetOrCreateFocusHub();
411 ASSERT_NE(focusHub, nullptr);
412 focusHub->SetFocusType(FocusType::NODE);
413 context_->AddDirtyFocus(frameNode_);
414 dirtyFocusNode = context_->dirtyFocusNode_.Upgrade();
415 ASSERT_NE(dirtyFocusNode, nullptr);
416 EXPECT_EQ(dirtyFocusNode->GetFocusType(), FocusType::NODE);
417 frameNode_->eventHub_->focusHub_ = nullptr;
418 context_->FlushFocus();
419 EXPECT_EQ(context_->dirtyFocusNode_.Upgrade(), nullptr);
420
421 /**
422 * @tc.steps5: set stageManager_ and stageNode_, stageNode_'s child,
423 create frameNode_1's focusHub and call SetIsDefaultHasFocused with true
424 * @tc.expected: RequestDefaultFocus returns false.
425 */
426 context_->stageManager_->stageNode_ = frameNode_;
427 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
428 auto frameNode_1 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
429 frameNode_->children_.push_back(frameNode_1);
430 focusHub = frameNode_1->eventHub_->GetOrCreateFocusHub();
431 focusHub->SetIsDefaultHasFocused(true);
432 EXPECT_FALSE(context_->RequestDefaultFocus(focusHub));
433 /**
434 * @tc.steps6: call SetIsDefaultHasFocused with false and create a new frameNode
435 init frameNode_2's focusHub
436 * @tc.expected: RequestDefaultFocus returns true while IsFocusableWholePath return true
437 RequestDefaultFocus returns false while IsFocusableWholePath return false.
438 */
439 focusHub->SetFocusType(FocusType::SCOPE);
440 focusHub->focusable_ = true;
441 focusHub->SetIsDefaultHasFocused(false);
442 auto frameNodeId_2 = ElementRegister::GetInstance()->MakeUniqueId();
443 auto frameNode_2 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_2, nullptr);
444 frameNode_1->children_.push_back(frameNode_2);
445 frameNode_2->parent_ = frameNode_1;
446 auto newFocusHub = frameNode_2->eventHub_->GetOrCreateFocusHub();
447 newFocusHub->SetIsDefaultFocus(true);
448 newFocusHub->SetFocusType(FocusType::NODE);
449 frameNode_2->eventHub_->enabled_ = true;
450 newFocusHub->focusable_ = true;
451 newFocusHub->parentFocusable_ = true;
452 EXPECT_TRUE(context_->RequestDefaultFocus(focusHub));
453 focusHub->SetIsDefaultHasFocused(false);
454 focusHub->currentFocus_ = false;
455 focusHub->focusable_ = false;
456 newFocusHub->currentFocus_ = false;
457 newFocusHub->focusable_ = false;
458 EXPECT_FALSE(context_->RequestDefaultFocus(focusHub));
459
460 /**
461 * @tc.steps7: Create a new frameNode and call AddDirtyDefaultFocus
462 * @tc.expected: dirtyDefaultFocusNode_ is null
463 */
464 auto frameNodeId_3 = ElementRegister::GetInstance()->MakeUniqueId();
465 auto frameNode_3 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_3, nullptr);
466 eventHub = frameNode_3->GetEventHub<EventHub>();
467 eventHub->SetEnabled(true);
468
469 focusHub = eventHub->GetOrCreateFocusHub();
470 focusHub->SetFocusType(FocusType::NODE);
471 focusHub->SetIsDefaultFocus(true);
472
473 context_->AddDirtyDefaultFocus(frameNode_3);
474 EXPECT_FALSE(context_->dirtyDefaultFocusNode_.Invalid());
475 context_->FlushFocus();
476 EXPECT_TRUE(context_->dirtyDefaultFocusNode_.Invalid());
477 EXPECT_FALSE(context_->dirtyFocusNode_.Upgrade());
478 EXPECT_FALSE(context_->dirtyFocusScope_.Upgrade());
479
480 auto frameNodeId_4 = ElementRegister::GetInstance()->MakeUniqueId();
481 auto frameNode_4 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_4, nullptr);
482 auto eventHubRoot = frameNode_4->GetEventHub<EventHub>();
483 auto focusHubRoot = eventHubRoot->GetOrCreateFocusHub();
484 focusHubRoot->currentFocus_ = true;
485 focusHub->SetFocusType(FocusType::NODE);
486
487 context_->rootNode_ = frameNode_4;
488 context_->FlushFocus();
489 EXPECT_TRUE(focusHubRoot->IsCurrentFocus());
490 }
491
492 /**
493 * @tc.name: PipelineContextTestNg006
494 * @tc.desc: Test the function FlushBuildFinishCallbacks.
495 * @tc.type: FUNC
496 */
497 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg006, TestSize.Level1)
498 {
499 /**
500 * @tc.steps1: initialize parameters.
501 * @tc.expected: All pointer is non-null.
502 */
503 ASSERT_NE(context_, nullptr);
504 bool flagCbk = false;
505 context_->AddBuildFinishCallBack(nullptr);
__anon695700410502() 506 context_->AddBuildFinishCallBack([&flagCbk]() { flagCbk = true; });
507
508 /**
509 * @tc.steps2: Call the function FlushBuildFinishCallbacks.
510 * @tc.expected: The flagCbk is changed to true.
511 */
512 context_->FlushBuildFinishCallbacks();
513 EXPECT_TRUE(flagCbk);
514 }
515
516 /**
517 * @tc.name: PipelineContextTestNg007
518 * @tc.desc: Test the function SetupRootElement.
519 * @tc.type: FUNC
520 */
521 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg007, TestSize.Level1)
522 {
523 /**
524 * @tc.steps1: initialize parameters.
525 * @tc.expected: All pointer is non-null.
526 */
527 ASSERT_NE(context_, nullptr);
528 context_->windowManager_ = AceType::MakeRefPtr<WindowManager>();
529 /**
530 * @tc.steps2: Call the function SetupRootElement with isJsCard_ = true.
531 * @tc.expected: The stageManager_ is non-null.
532 */
533 context_->SetIsJsCard(true);
534 context_->windowModal_ = WindowModal::NORMAL;
535 context_->SetupRootElement();
536 EXPECT_NE(context_->stageManager_, nullptr);
537
538 /**
539 * @tc.steps3: Call the function SetupRootElement with isJsCard_ = false.
540 * @tc.expected: The stageManager_ is non-null.
541 */
542 context_->SetIsJsCard(false);
543 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
544 context_->SetupRootElement();
545 EXPECT_NE(context_->stageManager_, nullptr);
546 }
547
548 /**
549 * @tc.name: PipelineContextTestNg008
550 * @tc.desc: Test the function SetupSubRootElement.
551 * @tc.type: FUNC
552 */
553 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg008, TestSize.Level1)
554 {
555 /**
556 * @tc.steps1: initialize parameters.
557 * @tc.expected: All pointer is non-null.
558 */
559 ASSERT_NE(context_, nullptr);
560
561 /**
562 * @tc.steps2: Call the function SetupSubRootElement with isJsCard_ = true.
563 * @tc.expected: The stageManager_ is non-null.
564 */
565 context_->SetIsJsCard(true);
566 context_->SetupSubRootElement();
567 EXPECT_NE(context_->stageManager_, nullptr);
568
569 /**
570 * @tc.steps3: Call the function SetupSubRootElement with isJsCard_ = false.
571 * @tc.expected: The stageManager_ is non-null.
572 */
573 context_->SetIsJsCard(false);
574 context_->SetupSubRootElement();
575 EXPECT_NE(context_->stageManager_, nullptr);
576 }
577
578 /**
579 * @tc.name: PipelineContextTestNg009
580 * @tc.desc: Test the function OnSurfaceChanged.
581 * @tc.type: FUNC
582 */
583 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg009, TestSize.Level1)
584 {
585 /**
586 * @tc.steps1: initialize parameters.
587 * @tc.expected: All pointer is non-null.
588 */
589 ASSERT_NE(context_, nullptr);
590 context_->rootWidth_ = DEFAULT_INT10;
591 context_->rootHeight_ = DEFAULT_INT10;
592 bool flagCbk = false;
593
594 /**
595 * @tc.steps2: Call the function OnSurfaceChanged with DEFAULT_INT10.
596 * @tc.expected: The flagCbk is changed to true.
597 */
598 context_->SetForegroundCalled(true);
__anon695700410602() 599 context_->SetNextFrameLayoutCallback([&flagCbk]() { flagCbk = !flagCbk; });
600 context_->OnSurfaceChanged(DEFAULT_INT10, DEFAULT_INT10, WindowSizeChangeReason::CUSTOM_ANIMATION);
601 EXPECT_TRUE(flagCbk);
602
603 /**
604 * @tc.steps3: Call the function OnSurfaceChanged with width = 1, height = 1 and weakFrontend_ = null.
605 * @tc.expected: The flagCbk is not changed.
606 */
607 context_->OnSurfaceChanged(DEFAULT_INT1, DEFAULT_INT1);
608 EXPECT_TRUE(flagCbk);
609
610 /**
611 * @tc.steps4: Call the function OnSurfaceDensityChanged with width = 1, height = 1 and weakFrontend_ != null.
612 * @tc.expected: The width_ and height_ of frontend is changed to DEFAULT_INT1.
613 */
614 auto frontend = AceType::MakeRefPtr<MockFrontend>();
615 context_->weakFrontend_ = frontend;
616 context_->OnSurfaceChanged(DEFAULT_INT1, DEFAULT_INT1);
617 EXPECT_EQ(frontend->GetWidth(), DEFAULT_INT1);
618 EXPECT_EQ(frontend->GetHeight(), DEFAULT_INT1);
619 context_->weakFrontend_.Reset();
620 }
621
622 /**
623 * @tc.name: PipelineContextTestNg010
624 * @tc.desc: Test the function OnSurfaceDensityChanged.
625 * @tc.type: FUNC
626 */
627 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg010, TestSize.Level1)
628 {
629 /**
630 * @tc.steps1: initialize parameters.
631 * @tc.expected: All pointer is non-null.
632 */
633 ASSERT_NE(context_, nullptr);
634 context_->density_ = DEFAULT_DOUBLE1;
635 context_->dipScale_ = DEFAULT_DOUBLE1;
636
637 /**
638 * @tc.steps2: Call the function OnSurfaceDensityChanged with viewScale_ = 0.0.
639 * @tc.expected: The density_ is changed to density.
640 */
641 context_->viewScale_ = 0.0;
642 context_->OnSurfaceDensityChanged(DEFAULT_DOUBLE4);
643 EXPECT_DOUBLE_EQ(context_->GetDensity(), DEFAULT_DOUBLE4);
644 EXPECT_DOUBLE_EQ(context_->GetDipScale(), DEFAULT_DOUBLE1);
645
646 /**
647 * @tc.steps3: Call the function OnSurfaceDensityChanged with viewScale_ = 0.0.
648 * @tc.expected: The density_ is changed to density.
649 */
650 context_->viewScale_ = DEFAULT_DOUBLE2;
651 context_->OnSurfaceDensityChanged(DEFAULT_DOUBLE4);
652 EXPECT_DOUBLE_EQ(context_->GetDensity(), DEFAULT_DOUBLE4);
653 EXPECT_DOUBLE_EQ(context_->GetDipScale(), DEFAULT_DOUBLE2);
654 }
655
656 /**
657 * @tc.name: PipelineContextTestNg011
658 * @tc.desc: Test the function AddDirtyFocus.
659 * @tc.type: FUNC
660 */
661 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg011, TestSize.Level1)
662 {
663 /**
664 * @tc.steps1: initialize parameters.
665 * @tc.expected: All pointer is non-null.
666 */
667 ASSERT_NE(context_, nullptr);
668 auto eventHub = frameNode_->GetEventHub<EventHub>();
669 ASSERT_NE(eventHub, nullptr);
670 auto focusHub = eventHub->GetOrCreateFocusHub();
671 ASSERT_NE(focusHub, nullptr);
672
673 /**
674 * @tc.steps2: Call the function AddDirtyFocus with FocusType::NODE.
675 * @tc.expected: The FocusType of dirtyFocusNode_ is changed to FocusType::NODE.
676 */
677 focusHub->SetFocusType(FocusType::NODE);
678 context_->AddDirtyFocus(frameNode_);
679 auto dirtyFocusNode = context_->dirtyFocusNode_.Upgrade();
680 ASSERT_NE(dirtyFocusNode, nullptr);
681 EXPECT_EQ(dirtyFocusNode->GetFocusType(), FocusType::NODE);
682
683 /**
684 * @tc.steps3: Call the function OnSurfaceDensityChanged with FocusType::SCOPE.
685 * @tc.expected: The FocusType of dirtyFocusScope_ is changed to FocusType::SCOPE.
686 */
687 focusHub->SetFocusType(FocusType::SCOPE);
688 context_->AddDirtyFocus(frameNode_);
689 auto dirtyFocusScope = context_->dirtyFocusScope_.Upgrade();
690 ASSERT_NE(dirtyFocusScope, nullptr);
691 EXPECT_EQ(dirtyFocusScope->GetFocusType(), FocusType::SCOPE);
692 }
693
694 /**
695 * @tc.name: PipelineContextTestNg012
696 * @tc.desc: Test functions WindowFocus and FlushWindowFocusChangedCallback.
697 * @tc.type: FUNC
698 */
699 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg012, TestSize.Level1)
700 {
701 /**
702 * @tc.steps1: initialize parameters.
703 * @tc.expected: All pointer is non-null.
704 */
705 ASSERT_NE(context_, nullptr);
706 context_->SetupRootElement();
707 context_->onWindowFocusChangedCallbacks_.clear();
708 context_->AddWindowFocusChangedCallback(ElementRegister::UndefinedElementId);
709 context_->AddWindowFocusChangedCallback(frameNodeId_);
710 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE2);
711
712 /**
713 * @tc.steps2: Call the function WindowFocus with "true" and onShow_ = true.
714 * @tc.expected: The onFocus_ is changed to true and the size of onWindowFocusChangedCallbacks_ is change to 1.
715 */
716 context_->onShow_ = true;
717 context_->WindowFocus(true);
718 EXPECT_TRUE(context_->onFocus_);
719 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
720
721 /**
722 * @tc.steps3: Call the function WindowFocus with "true" and onShow_ = false.
723 * @tc.expected: The onFocus_ is changed to true and the size of onWindowFocusChangedCallbacks_ is change to 1.
724 */
725 context_->onShow_ = false;
726 context_->WindowFocus(true);
727 EXPECT_TRUE(context_->onFocus_);
728 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
729
730 /**
731 * @tc.steps4: Call the function WindowFocus with "false" and onShow_ = true.
732 * @tc.expected: The onFocus_ is changed to false.
733 */
734 context_->onShow_ = true;
735 context_->WindowFocus(false);
736 EXPECT_FALSE(context_->onFocus_);
737 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
738
739 /**
740 * @tc.steps5: Call the function WindowFocus with "false" and onShow_ = false.
741 * @tc.expected: The onFocus_ is changed to false.
742 */
743 context_->onShow_ = false;
744 context_->WindowFocus(false);
745 EXPECT_FALSE(context_->onFocus_);
746 EXPECT_EQ(context_->onWindowFocusChangedCallbacks_.size(), DEFAULT_SIZE1);
747 }
748
749 /**
750 * @tc.name: PipelineContextTestNg013
751 * @tc.desc: Test the function NotifyMemoryLevel.
752 * @tc.type: FUNC
753 */
754 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg013, TestSize.Level1)
755 {
756 /**
757 * @tc.steps1: initialize parameters.
758 * @tc.expected: All pointer is non-null.
759 */
760 ASSERT_NE(context_, nullptr);
761 context_->nodesToNotifyMemoryLevel_.clear();
762 context_->AddNodesToNotifyMemoryLevel(ElementRegister::UndefinedElementId);
763 context_->AddNodesToNotifyMemoryLevel(customNodeId_);
764 EXPECT_EQ(context_->nodesToNotifyMemoryLevel_.size(), DEFAULT_SIZE2);
765
766 /**
767 * @tc.steps2: Call the function NotifyMemoryLevel with "1".
768 * @tc.expected: The size of nodesToNotifyMemoryLevel_ is change to 1.
769 */
770 context_->NotifyMemoryLevel(DEFAULT_INT1);
771 EXPECT_EQ(context_->nodesToNotifyMemoryLevel_.size(), DEFAULT_SIZE1);
772
773 /**
774 * @tc.steps3: Call the function NotifyMemoryLevel with "1".
775 * @tc.expected: The NOT_REGISTER_ID in nodesToNotifyMemoryLevel_ is erased.
776 */
777 context_->AddNodesToNotifyMemoryLevel(NOT_REGISTER_ID);
778 context_->NotifyMemoryLevel(DEFAULT_INT1);
779 auto iter =
780 find(context_->nodesToNotifyMemoryLevel_.begin(), context_->nodesToNotifyMemoryLevel_.end(), NOT_REGISTER_ID);
781 EXPECT_EQ(iter, context_->nodesToNotifyMemoryLevel_.end());
782 }
783
784 /**
785 * @tc.name: PipelineContextTestNg014
786 * @tc.desc: Test the function OnIdle.
787 * @tc.type: FUNC
788 */
789 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg014, TestSize.Level1)
790 {
791 /**
792 * @tc.steps1: initialize parameters.
793 * @tc.expected: All pointer is non-null.
794 */
795 ASSERT_NE(context_, nullptr);
796 bool flagCbk = false;
797
798 /**
799 * @tc.steps2: Call the function OnIdle.
800 * @tc.expected: The value of flagCbk remains unchanged.
801 */
__anon695700410702(int64_t, bool) 802 context_->AddPredictTask([&flagCbk](int64_t, bool) { flagCbk = true; });
803 context_->OnIdle(0);
804 EXPECT_FALSE(flagCbk);
805
806 /**
807 * @tc.steps3: Call the function OnIdle.
808 * @tc.expected: The flagCbk is changed to true.
809 */
810 context_->OnIdle(NANO_TIME_STAMP);
811 EXPECT_TRUE(flagCbk);
812 }
813
814 /**
815 * @tc.name: PipelineContextTestNg015
816 * @tc.desc: Test the function Finish.
817 * @tc.type: FUNC
818 */
819 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg015, TestSize.Level1)
820 {
821 /**
822 * @tc.steps1: initialize parameters.
823 * @tc.expected: All pointer is non-null.
824 */
825 ASSERT_NE(context_, nullptr);
826 bool flagCbk = false;
827
828 /**
829 * @tc.steps2: Call the function Finish.
830 * @tc.expected: The value of flagCbk remains unchanged.
831 */
832 context_->SetFinishEventHandler(nullptr);
833 context_->Finish(false);
834 EXPECT_FALSE(flagCbk);
835
836 /**
837 * @tc.steps3: Call the function Finish.
838 * @tc.expected: The flagCbk is changed to true.
839 */
__anon695700410802() 840 context_->SetFinishEventHandler([&flagCbk]() { flagCbk = true; });
841 context_->Finish(false);
842 EXPECT_TRUE(flagCbk);
843 }
844
845 /**
846 * @tc.name: PipelineContextTestNg016
847 * @tc.desc: Test functions OnShow, OnHide and FlushWindowStateChangedCallback.
848 * @tc.type: FUNC
849 */
850 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg016, TestSize.Level1)
851 {
852 /**
853 * @tc.steps1: initialize parameters.
854 * @tc.expected: All pointer is non-null.
855 */
856 ASSERT_NE(context_, nullptr);
857 context_->SetupRootElement();
858 context_->onWindowStateChangedCallbacks_.clear();
859 context_->AddWindowStateChangedCallback(ElementRegister::UndefinedElementId);
860 context_->AddWindowStateChangedCallback(customNodeId_);
861 EXPECT_EQ(context_->onWindowStateChangedCallbacks_.size(), DEFAULT_SIZE2);
862
863 /**
864 * @tc.steps2: Call the function OnShow.
865 * @tc.expected: The onShow_ is changed to true and the size of onWindowStateChangedCallbacks_ is change to 1.
866 */
867 context_->OnShow();
868 EXPECT_TRUE(context_->onShow_);
869 EXPECT_EQ(context_->onWindowStateChangedCallbacks_.size(), DEFAULT_SIZE1);
870
871 /**
872 * @tc.steps3: Call the function OnHide.
873 * @tc.expected: The onShow_ is changed to false.
874 */
875 context_->OnHide();
876 EXPECT_FALSE(context_->onShow_);
877 EXPECT_EQ(context_->onWindowStateChangedCallbacks_.size(), DEFAULT_SIZE1);
878 }
879
880 /**
881 * @tc.name: PipelineContextTestNg017
882 * @tc.desc: Test functions OnDragEvent.
883 * @tc.type: FUNC
884 */
885 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg017, TestSize.Level1)
886 {
887 /**
888 * @tc.steps1: initialize parameters.
889 * @tc.expected: All pointer is non-null.
890 */
891 ASSERT_NE(context_, nullptr);
892 context_->SetupRootElement();
893 auto manager = context_->GetDragDropManager();
894 ASSERT_NE(manager, nullptr);
895 auto frameNodeId_017 = ElementRegister::GetInstance()->MakeUniqueId();
896 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_017, nullptr);
897 ASSERT_NE(frameNode, nullptr);
898 manager->AddDragFrameNode(frameNode->GetId(), frameNode);
899
900 /**
901 * @tc.steps2: Call the function OnDragEvent with isDragged_=true, currentId_=DEFAULT_INT1 and DRAG_EVENT_END.
902 * @tc.expected: The currentId_ is equal to DEFAULT_INT1.
903 */
904 manager->isDragged_ = true;
905 manager->currentId_ = DEFAULT_INT1;
906 context_->OnDragEvent({ DEFAULT_INT1, DEFAULT_INT1 }, DragEventAction::DRAG_EVENT_END);
907 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
908
909 /**
910 * @tc.steps2: Call the function OnDragEvent with isDragged_=true, currentId_=DEFAULT_INT1 and DRAG_EVENT_MOVE.
911 * @tc.expected: The currentId_ is equal to DEFAULT_INT1.
912 */
913 manager->isDragged_ = true;
914 manager->currentId_ = DEFAULT_INT1;
915 context_->OnDragEvent({ DEFAULT_INT1, DEFAULT_INT1 }, DragEventAction::DRAG_EVENT_MOVE);
916 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
917
918 /**
919 * @tc.steps3: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_END.
920 * @tc.expected: The currentId_ is equal to DEFAULT_INT1.
921 */
922 manager->isDragged_ = false;
923 manager->currentId_ = DEFAULT_INT1;
924 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_END);
925 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
926
927 /**
928 * @tc.steps4: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_MOVE.
929 * @tc.expected: The currentId_ is changed to DEFAULT_INT10.
930 */
931 manager->isDragged_ = false;
932 manager->currentId_ = DEFAULT_INT1;
933 context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_MOVE);
934 EXPECT_EQ(manager->currentId_, DEFAULT_INT1);
935 }
936
937 /**
938 * @tc.name: PipelineContextTestNg018
939 * @tc.desc: Test the function ShowContainerTitle.
940 * @tc.type: FUNC
941 */
942 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg018, TestSize.Level1)
943 {
944 /**
945 * @tc.steps1: initialize parameters.
946 * @tc.expected: All pointer is non-null.
947 */
948 ASSERT_NE(context_, nullptr);
949 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
950 context_->SetupRootElement();
951 ASSERT_NE(context_->rootNode_, nullptr);
952 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
953 ASSERT_NE(containerNode, nullptr);
954 auto pattern = containerNode->GetPattern<ContainerModalPattern>();
955 ASSERT_NE(containerNode, nullptr);
956
957 /**
958 * @tc.steps2: Call the function ShowContainerTitle with windowModal_ = WindowModal::DIALOG_MODAL.
959 * @tc.expected: The moveX_ is unchanged.
960 */
961 pattern->moveX_ = DEFAULT_DOUBLE2;
962 context_->windowModal_ = WindowModal::DIALOG_MODAL;
963 context_->ShowContainerTitle(true);
964 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
965
966 /**
967 * @tc.steps3: Call the function ShowContainerTitle with windowModal_ = WindowModal::CONTAINER_MODAL.
968 * @tc.expected: The moveX_ is unchanged.
969 */
970 pattern->moveX_ = DEFAULT_DOUBLE2;
971 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
972 context_->ShowContainerTitle(true);
973 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
974 }
975
976 /**
977 * @tc.name: PipelineContextTestNg019
978 * @tc.desc: Test the function SetAppTitle.
979 * @tc.type: FUNC
980 */
981 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg019, TestSize.Level1)
982 {
983 /**
984 * @tc.steps1: initialize parameters.
985 * @tc.expected: All pointer is non-null.
986 */
987 ASSERT_NE(context_, nullptr);
988 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
989 context_->SetupRootElement();
990 ASSERT_NE(context_->rootNode_, nullptr);
991 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
992 ASSERT_NE(containerNode, nullptr);
993 auto pattern = containerNode->GetPattern<ContainerModalPattern>();
994 ASSERT_NE(containerNode, nullptr);
995
996 /**
997 * @tc.steps2: Call the function ShowContainerTitle with windowModal_ = WindowModal::DIALOG_MODAL.
998 * @tc.expected: The moveX_ is unchanged.
999 */
1000 pattern->moveX_ = DEFAULT_DOUBLE2;
1001 context_->windowModal_ = WindowModal::DIALOG_MODAL;
1002 context_->SetAppTitle(TEST_TAG);
1003 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
1004
1005 /**
1006 * @tc.steps3: Call the function ShowContainerTitle with windowModal_ = WindowModal::CONTAINER_MODAL.
1007 * @tc.expected: The moveX_ is unchanged.
1008 */
1009 pattern->moveX_ = DEFAULT_DOUBLE2;
1010 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
1011 context_->SetAppTitle(TEST_TAG);
1012 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
1013 }
1014
1015 /**
1016 * @tc.name: PipelineContextTestNg020
1017 * @tc.desc: Test the function SetAppIcon.
1018 * @tc.type: FUNC
1019 */
1020 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg020, TestSize.Level1)
1021 {
1022 /**
1023 * @tc.steps1: initialize parameters.
1024 * @tc.expected: All pointer is non-null.
1025 */
1026 ASSERT_NE(context_, nullptr);
1027 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
1028 context_->SetupRootElement();
1029 ASSERT_NE(context_->rootNode_, nullptr);
1030 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
1031 ASSERT_NE(containerNode, nullptr);
1032 auto pattern = containerNode->GetPattern<ContainerModalPattern>();
1033 ASSERT_NE(containerNode, nullptr);
1034
1035 /**
1036 * @tc.steps2: Call the function SetAppIcon with windowModal_ = WindowModal::DIALOG_MODAL.
1037 * @tc.expected: The moveX_ is unchanged.
1038 */
1039 pattern->moveX_ = DEFAULT_DOUBLE2;
1040 context_->windowModal_ = WindowModal::DIALOG_MODAL;
1041 context_->SetAppIcon(nullptr);
1042 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
1043
1044 /**
1045 * @tc.steps3: Call the function SetAppIcon with windowModal_ = WindowModal::CONTAINER_MODAL.
1046 * @tc.expected: The moveX_ is unchanged.
1047 */
1048 pattern->moveX_ = DEFAULT_DOUBLE2;
1049 context_->windowModal_ = WindowModal::CONTAINER_MODAL;
1050 context_->SetAppIcon(nullptr);
1051 EXPECT_DOUBLE_EQ(pattern->moveX_, DEFAULT_DOUBLE2);
1052 }
1053
1054 /**
1055 * @tc.name: PipelineContextTestNg021
1056 * @tc.desc: Test the function OnAxisEvent.
1057 * @tc.type: FUNC
1058 */
1059 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg021, TestSize.Level1)
1060 {
1061 /**
1062 * @tc.steps1: initialize parameters.
1063 * @tc.expected: All pointer is non-null.
1064 */
1065 ASSERT_NE(context_, nullptr);
1066 AxisEvent event;
1067 event.x = DEFAULT_DOUBLE1;
1068 context_->viewScale_ = DEFAULT_DOUBLE1;
1069
1070 /**
1071 * @tc.steps2: Call the function OnAxisEvent with action = AxisAction::BEGIN.
1072 * @tc.expected: The instanceId is changed to 4.
1073 */
1074 event.action = AxisAction::BEGIN;
1075 ResetEventFlag(TOUCH_TEST_FLAG | AXIS_TEST_FLAG);
1076 context_->OnAxisEvent(event);
1077 EXPECT_FALSE(GetEventFlag(TOUCH_TEST_FLAG));
1078 EXPECT_FALSE(GetEventFlag(AXIS_TEST_FLAG));
1079
1080 /**
1081 * @tc.steps3: Call the function OnAxisEvent with action = AxisAction::UPDATE.
1082 * @tc.expected: The instanceId is changed to 3.
1083 */
1084 event.action = AxisAction::UPDATE;
1085 ResetEventFlag(TOUCH_TEST_FLAG | AXIS_TEST_FLAG);
1086 context_->OnAxisEvent(event);
1087 EXPECT_FALSE(GetEventFlag(TOUCH_TEST_FLAG));
1088 EXPECT_FALSE(GetEventFlag(AXIS_TEST_FLAG));
1089
1090 /**
1091 * @tc.steps4: Call the function OnAxisEvent with action = AxisAction::END.
1092 * @tc.expected: The instanceId is changed to 1.
1093 */
1094 event.action = AxisAction::END;
1095 ResetEventFlag(TOUCH_TEST_FLAG | AXIS_TEST_FLAG);
1096 context_->OnAxisEvent(event);
1097 EXPECT_FALSE(GetEventFlag(TOUCH_TEST_FLAG));
1098 EXPECT_FALSE(GetEventFlag(AXIS_TEST_FLAG));
1099 }
1100
1101 /**
1102 * @tc.name: PipelineContextTestNg022
1103 * @tc.desc: Test the function OnKeyEvent.
1104 * @tc.type: FUNC
1105 */
1106 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg022, TestSize.Level1)
1107 {
1108 /**
1109 * @tc.steps1: initialize parameters.
1110 * @tc.expected: All pointer is non-null.
1111 */
1112 ASSERT_NE(context_, nullptr);
1113 context_->SetupRootElement();
1114 auto eventManager = context_->GetDragDropManager();
1115 ASSERT_NE(eventManager, nullptr);
1116 auto frameNodeId_022 = ElementRegister::GetInstance()->MakeUniqueId();
1117 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_022, nullptr);
1118 ASSERT_NE(frameNode, nullptr);
1119 eventManager->AddDragFrameNode(frameNode->GetId(), frameNode);
1120 KeyEvent event;
1121
1122 /**
1123 * @tc.steps2: Call the function OnKeyEvent with isFocusActive_ = false, action = KeyAction::DOWN and
1124 # pressedCodes = { KeyCode::KEY_TAB }.
1125 * @tc.expected: The return value of OnKeyEvent is true.
1126 */
1127 context_->SetIsFocusActive(false);
1128 event.action = KeyAction::DOWN;
1129 event.code = KeyCode::KEY_TAB;
1130 event.pressedCodes = { KeyCode::KEY_TAB };
1131 EXPECT_FALSE(context_->OnKeyEvent(event));
1132 EXPECT_TRUE(context_->GetIsFocusActive());
1133
1134 /**
1135 * @tc.steps3: Call the function OnKeyEvent with isFocusActive_ = false, action = KeyAction::DOWN and
1136 # pressedCodes = { KeyCode::KEY_DPAD_UP }.
1137 * @tc.expected: The return value of OnKeyEvent is true.
1138 */
1139 context_->SetIsFocusActive(false);
1140 event.pressedCodes = { KeyCode::KEY_DPAD_UP };
1141 event.code = KeyCode::KEY_DPAD_UP;
1142 EXPECT_FALSE(context_->OnKeyEvent(event));
1143 EXPECT_FALSE(context_->GetIsFocusActive());
1144
1145 /**
1146 * @tc.steps4: Call the function OnKeyEvent with isFocusActive_ = false, action = KeyAction::UP and
1147 # pressedCodes = { KeyCode::KEY_CLEAR }.
1148 * @tc.expected: The return value of OnKeyEvent is true.
1149 */
1150 context_->SetIsFocusActive(false);
1151 event.action = KeyAction::UP;
1152 event.code = KeyCode::KEY_CLEAR;
1153 event.pressedCodes = { KeyCode::KEY_CLEAR };
1154 EXPECT_FALSE(context_->OnKeyEvent(event));
1155 EXPECT_FALSE(context_->GetIsFocusActive());
1156
1157 /**
1158 * @tc.steps4: Call the function OnKeyEvent with isFocusActive_ = true, action = KeyAction::UP and
1159 # pressedCodes = { KeyCode::KEY_CLEAR }.
1160 * @tc.expected: The return value of OnKeyEvent is false.
1161 */
1162 context_->SetIsFocusActive(true);
1163 event.action = KeyAction::UP;
1164 event.code = KeyCode::KEY_CLEAR;
1165 event.pressedCodes = { KeyCode::KEY_CLEAR };
1166 EXPECT_FALSE(context_->OnKeyEvent(event));
1167 EXPECT_TRUE(context_->GetIsFocusActive());
1168
1169 /**
1170 * @tc.steps5: Call the function OnKeyEvent with isFocusActive_ = true, action = KeyAction::UP and
1171 # pressedCodes = { KeyCode::KEY_CLEAR }.
1172 * @tc.expected: The return value of OnKeyEvent is false.
1173 */
1174 context_->rootNode_.Reset();
1175 context_->SetIsFocusActive(true);
1176 event.action = KeyAction::DOWN;
1177 event.code = KeyCode::KEY_ESCAPE;
1178 event.pressedCodes = { KeyCode::KEY_ESCAPE };
1179
1180 auto pageNodeId = ElementRegister::GetInstance()->MakeUniqueId();
1181 auto pageNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, pageNodeId, nullptr);
1182 auto childNodeId = ElementRegister::GetInstance()->MakeUniqueId();
1183 auto childNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, childNodeId, nullptr);
1184 pageNode->AddChild(childNode);
1185 context_->stageManager_->stageNode_ = pageNode;
1186 EXPECT_FALSE(context_->OnKeyEvent(event));
1187 EXPECT_FALSE(context_->dragDropManager_->isDragCancel_);
1188 }
1189
1190 /**
1191 * @tc.name: PipelineContextTestNg023
1192 * @tc.desc: Test the function OnMouseEvent.
1193 * @tc.type: FUNC
1194 */
1195 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg023, TestSize.Level1)
1196 {
1197 /**
1198 * @tc.steps1: initialize parameters.
1199 * @tc.expected: All pointer is non-null.
1200 */
1201 ASSERT_NE(context_, nullptr);
1202 context_->SetupRootElement();
1203 MouseEvent event;
1204
1205 /**
1206 * @tc.steps2: Call the function OnMouseEvent with action = MouseAction::HOVER
1207 * and button = MouseButton::BACK_BUTTON.
1208 * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1209 */
1210 event.action = MouseAction::HOVER;
1211 event.button = MouseButton::BACK_BUTTON;
1212 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1213 context_->OnMouseEvent(event);
1214 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1215
1216 /**
1217 * @tc.steps3: Call the function OnMouseEvent with action = MouseAction::RELEASE
1218 * and button = MouseButton::LEFT_BUTTON.
1219 * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1220 */
1221 event.action = MouseAction::RELEASE;
1222 event.button = MouseButton::LEFT_BUTTON;
1223 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1224 context_->OnMouseEvent(event);
1225 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1226
1227 /**
1228 * @tc.steps4: Call the function OnMouseEvent with action = MouseAction::PRESS
1229 * and button = MouseButton::LEFT_BUTTON.
1230 * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1231 */
1232 event.action = MouseAction::PRESS;
1233 event.button = MouseButton::LEFT_BUTTON;
1234 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1235 context_->OnMouseEvent(event);
1236 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1237
1238 /**
1239 * @tc.steps5: Call the function OnMouseEvent with action = MouseAction::MOVE
1240 * and button = MouseButton::LEFT_BUTTON.
1241 * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1242 */
1243 event.action = MouseAction::MOVE;
1244 event.button = MouseButton::LEFT_BUTTON;
1245 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1246 context_->OnMouseEvent(event);
1247 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1248
1249 /**
1250 * @tc.steps6: Call the function OnMouseEvent with action = MouseAction::RELEASE
1251 * and pressedButtons = MOUSE_PRESS_LEFT.
1252 * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1253 */
1254 event.button = MouseButton::BACK_BUTTON;
1255 event.action = MouseAction::RELEASE;
1256 event.pressedButtons = MOUSE_PRESS_LEFT;
1257 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1258 context_->OnMouseEvent(event);
1259 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1260
1261 /**
1262 * @tc.steps7: Call the function OnMouseEvent with action = MouseAction::PRESS
1263 * and pressedButtons = MOUSE_PRESS_LEFT.
1264 * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1265 */
1266 event.action = MouseAction::PRESS;
1267 event.pressedButtons = MOUSE_PRESS_LEFT;
1268 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1269 context_->OnMouseEvent(event);
1270 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1271
1272 /**
1273 * @tc.steps8: Call the function OnMouseEvent with action = MouseAction::MOVE
1274 * and pressedButtons = MOUSE_PRESS_LEFT.
1275 * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1276 */
1277 event.action = MouseAction::MOVE;
1278 event.pressedButtons = MOUSE_PRESS_LEFT;
1279 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1280 context_->OnMouseEvent(event);
1281 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1282
1283 /**
1284 * @tc.steps9: Call the function OnMouseEvent with action = MouseAction::MOVE
1285 * and pressedButtons = MOUSE_PRESS_LEFT.
1286 * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1287 */
1288 event.button = MouseButton::RIGHT_BUTTON;
1289 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1290 context_->OnMouseEvent(event);
1291 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1292
1293 /**
1294 * @tc.steps9: Call the function OnMouseEvent with action = MouseAction::MOVE
1295 * and pressedButtons = MOUSE_PRESS_LEFT.
1296 * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1297 */
1298 event.button = MouseButton::RIGHT_BUTTON;
1299 event.action = MouseAction::PRESS;
1300 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1301 context_->OnMouseEvent(event);
1302 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1303 }
1304
1305 /**
1306 * @tc.name: PipelineContextTestNg024
1307 * @tc.desc: Test the function FlushTouchEvents.
1308 * @tc.type: FUNC
1309 */
1310 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg024, TestSize.Level1)
1311 {
1312 /**
1313 * @tc.steps1: initialize parameters.
1314 * @tc.expected: All pointer is non-null.
1315 */
1316 ASSERT_NE(context_, nullptr);
1317 context_->SetupRootElement();
1318 TouchEvent event;
1319 context_->touchEvents_.clear();
1320
1321 /**
1322 * @tc.steps2: Call the function FlushTouchEvents with empty touchEvents_.
1323 * @tc.expected: The function DispatchTouchEvent of eventManager_ is not called.
1324 */
1325 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1326 context_->FlushTouchEvents();
1327 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1328
1329 /**
1330 * @tc.steps3: Call the function FlushTouchEvents with unempty touchEvents_.
1331 * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1332 */
1333 context_->touchEvents_.push_back(event);
1334 context_->touchEvents_.push_back(event);
1335 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1336 context_->FlushTouchEvents();
1337 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1338
1339 /**
1340 * @tc.steps4: Call the function FlushTouchEvents with unempty touchEvents_.
1341 * @tc.expected: The function DispatchTouchEvent of eventManager_ is called.
1342 */
1343 TouchEvent event2;
1344 event2.id = 1;
1345 context_->touchEvents_.push_back(event);
1346 context_->touchEvents_.push_back(event2);
1347 ResetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG);
1348 context_->FlushTouchEvents();
1349 EXPECT_FALSE(GetEventFlag(DISPATCH_TOUCH_EVENT_TOUCH_EVENT_FLAG));
1350 }
1351
1352 /**
1353 * @tc.name: PipelineContextTestNg025
1354 * @tc.desc: Test the function OnDumpInfo.
1355 * @tc.type: FUNC
1356 */
1357 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg025, TestSize.Level1)
1358 {
1359 /**
1360 * @tc.steps1: initialize parameters.
1361 * @tc.expected: All pointer is non-null.
1362 */
1363 ASSERT_NE(context_, nullptr);
1364 context_->SetupRootElement();
1365
1366 std::unique_ptr<std::ostream> ostream = std::make_unique<std::ostringstream>();
1367 ASSERT_NE(ostream, nullptr);
1368 DumpLog::GetInstance().SetDumpFile(std::move(ostream));
1369 /**
1370 * @tc.steps2: init a vector with some string params and
1371 call OnDumpInfo with every param array.
1372 * @tc.expected: The return value is same as the expectation.
1373 */
1374 std::vector<std::vector<std::string>> params = { { "-element", "-lastpage" }, { "-element", "non-lastpage" },
1375 { "-element" }, { "-focus" }, { ACCESS_TAG }, { "-inspector" }, { "-render" }, { "-layer" }, { "-frontend" },
1376 { "-multimodal" }, { "-rotation", "1", "2", "3" }, { "-animationscale", "1", "2", "3" },
1377 { "-velocityscale", "1", "2", "3" }, { "-scrollfriction", "1", "2", "3" }, { "-threadstuck", "1", "2", "3" },
1378 { "-rotation" }, { "-animationscale" }, { "-velocityscale" }, { "-scrollfriction" }, { "-threadstuck" },
1379 { "test" } };
1380 int turn = 0;
1381 for (; turn < params.size(); turn++) {
1382 EXPECT_TRUE(context_->OnDumpInfo(params[turn]));
1383 }
1384 }
1385
1386 /**
1387 * @tc.name: PipelineContextTestNg026
1388 * @tc.desc: Test the function OnBackPressed.
1389 * @tc.type: FUNC
1390 */
1391 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg026, 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
1400 /**
1401 * @tc.steps2: Call the function OnBackPressed with weakFrontend_ is null.
1402 * @tc.expected: The return value of function is false.
1403 */
1404 context_->weakFrontend_.Reset();
1405 EXPECT_FALSE(context_->OnBackPressed());
1406
1407 /**
1408 * @tc.steps3: Call the function OnBackPressed with the return value of
1409 * fullScreenManager_->RequestFullScreen is true.
1410 * @tc.expected: The return value of function is true.
1411 */
1412 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1413 EXPECT_CALL(*frontend, OnBackPressed()).WillRepeatedly(testing::Return(true));
1414 context_->weakFrontend_ = frontend;
1415 auto frameNodeId = ElementRegister::GetInstance()->MakeUniqueId();
1416 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId, nullptr);
1417 context_->fullScreenManager_->RequestFullScreen(frameNode); // Set the return value of OnBackPressed to true;
1418 EXPECT_TRUE(context_->OnBackPressed());
1419
1420 /**
1421 * @tc.steps4: Call the function OnBackPressed with the return value of
1422 * fullScreenManager_->RequestFullScreen is true.
1423 * @tc.expected: The return value of function is true.
1424 */
1425 // Set the return value of OnBackPressed of fullScreenManager_ to true;
1426 context_->fullScreenManager_->ExitFullScreen(frameNode);
1427 EXPECT_TRUE(context_->OnBackPressed());
1428
1429 /**
1430 * @tc.steps5: Call the function OnBackPressed with the return value of
1431 * overlayManager_->RemoveOverlay is true.
1432 * @tc.expected: The return value of function is true.
1433 */
1434 // Set the return value of RemoveOverlay of overlayManager_ to true;
1435 context_->overlayManager_->CloseDialog(frameNode_);
1436 EXPECT_TRUE(context_->OnBackPressed());
1437
1438 /**
1439 * @tc.steps6: Call the function OnBackPressed with the return value of
1440 * overlayManager_->RemoveOverlay is true.
1441 * @tc.expected: The return value of function is true.
1442 */
1443 // Set the return value of RemoveOverlay of overlayManager_ to true;
1444 context_->overlayManager_->CloseDialog(frameNode);
1445 EXPECT_TRUE(context_->OnBackPressed());
1446 }
1447
1448 /**
1449 * @tc.name: PipelineContextTestNg027
1450 * @tc.desc: Test functions StartWindowSizeChangeAnimate and SetRootRect.
1451 * @tc.type: FUNC
1452 */
1453 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg027, TestSize.Level1)
1454 {
1455 /**
1456 * @tc.steps1: initialize parameters.
1457 * @tc.expected: All pointer is non-null.
1458 */
1459 ASSERT_NE(context_, nullptr);
1460 EXPECT_CALL(*(MockWindow*)(context_->window_.get()), SetDrawTextAsBitmap(_)).Times(AnyNumber());
1461 context_->SetupRootElement();
1462 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1463 auto& windowConfig = frontend->GetWindowConfig();
1464 windowConfig.designWidth = DEFAULT_INT1;
1465 context_->weakFrontend_ = frontend;
1466
1467 /**
1468 * @tc.steps2: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::RECOVER.
1469 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1470 */
1471 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1472 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::RECOVER);
1473 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1474
1475 /**
1476 * @tc.steps3: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::MAXIMIZE.
1477 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1478 */
1479 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1480 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::MAXIMIZE);
1481 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1482
1483 /**
1484 * @tc.steps4: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::ROTATION.
1485 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1486 */
1487 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1488 auto manager = AceType::MakeRefPtr<TextFieldManagerNG>();
1489 context_->SetTextFieldManager(manager);
1490 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::ROTATION);
1491 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1492
1493 /**
1494 * @tc.steps5: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::UNDEFINED.
1495 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1496 */
1497 context_->designWidthScale_ = DEFAULT_DOUBLE0;
1498 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::UNDEFINED);
1499 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_INT3);
1500
1501 /**
1502 * @tc.steps5: Call the function StartWindowSizeChangeAnimate with WindowSizeChangeReason::UNDEFINED.
1503 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT3.
1504 */
1505 SystemProperties::windowAnimationEnabled_ = false;
1506 context_->rootNode_->geometryNode_->frame_.rect_.y_ = 3.0;
1507 context_->StartWindowSizeChangeAnimate(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::UNDEFINED);
1508 EXPECT_EQ(context_->rootNode_->GetGeometryNode()->GetFrameOffset().GetY(), 0);
1509 }
1510
1511 /**
1512 * @tc.name: PipelineContextTestNg028
1513 * @tc.desc: Test functions OnVirtualKeyboardHeightChange and SetRootRect.
1514 * @tc.type: FUNC
1515 */
1516 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg028, TestSize.Level1)
1517 {
1518 /**
1519 * @tc.steps1: initialize parameters.
1520 * @tc.expected: All pointer is non-null.
1521 */
1522 ASSERT_NE(context_, nullptr);
1523 context_->SetupRootElement();
1524 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1525 auto& windowConfig = frontend->GetWindowConfig();
1526 windowConfig.designWidth = DEFAULT_INT1;
1527 context_->weakFrontend_ = frontend;
1528 context_->SetTextFieldManager(AceType::MakeRefPtr<TextFieldManagerNG>());
1529
1530 /**
1531 * @tc.steps2: Call the function OnVirtualKeyboardHeightChange with DEFAULT_DOUBLE1.
1532 * @tc.expected: The designWidthScale_ is changed to DEFAULT_INT0.
1533 */
1534 context_->designWidthScale_ = DEFAULT_DOUBLE1;
1535 context_->OnVirtualKeyboardHeightChange(DEFAULT_DOUBLE1);
1536 EXPECT_DOUBLE_EQ(context_->designWidthScale_, DEFAULT_DOUBLE1);
1537 EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), 0);
1538
1539 /**
1540 * @tc.steps3: init data and Call the function OnVirtualKeyboardHeightChange
1541 when textFieldManager_ is null.
1542 * @tc.expected: the return is same as expectation.
1543 */
1544 context_->textFieldManager_ = nullptr;
1545
1546 // the first arg is rootHeight_, the second arg is the parameter of function,
1547 // the third arg is the expectation returns
1548 std::vector<std::vector<int>> params = { { 200, 400, -300 }, { -200, 100, -100 }, { -200, -300, 300 },
1549 { 200, 0, 0 } };
1550 for (int turn = 0; turn < params.size(); turn++) {
1551 context_->rootHeight_ = params[turn][0];
1552 context_->OnVirtualKeyboardHeightChange(params[turn][1]);
1553 EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), params[turn][2]);
1554 }
1555 /**
1556 * @tc.steps4: init data and Call the function OnVirtualKeyboardHeightChange
1557 when textFieldManager_ is not null.
1558 * @tc.expected: the return is same as expectation.
1559 */
1560 auto manager = AceType::MakeRefPtr<TextFieldManagerNG>();
1561 context_->textFieldManager_ = manager;
1562 ASSERT_NE(context_->rootNode_, nullptr);
1563
1564 // the first arg is manager->height_, the second arg is manager->position_.deltaY_
1565 // the third arg is rootHeight_, the forth arg is context_->rootNode_->geometryNode_->frame_.rect_.y_
1566 // the fifth arg is the parameter of function, the sixth arg is the expectation returns
1567 params = { { 10, 100, 300, 0, 50, 0 }, { 10, 100, 300, 100, 100, 0 }, { 30, 100, 300, 100, 50, 0 },
1568 { 50, 290, 400, 100, 200, -95 }, { -1000, 290, 400, 100, 200, 100 } };
1569 for (int turn = 0; turn < params.size(); turn++) {
1570 manager->height_ = params[turn][0];
1571 manager->position_.deltaY_ = params[turn][1];
1572 context_->rootHeight_ = params[turn][2];
1573 context_->rootNode_->geometryNode_->frame_.rect_.y_ = params[turn][3];
1574 context_->safeAreaManager_->UpdateKeyboardOffset(params[turn][3]);
1575 context_->OnVirtualKeyboardHeightChange(params[turn][4]);
1576 EXPECT_EQ(context_->safeAreaManager_->GetKeyboardOffset(), params[turn][5]);
1577 }
1578 }
1579
1580 /**
1581 * @tc.name: PipelineContextTestNg029
1582 * @tc.desc: Test ThemeManager and SharedImageManager multithread.
1583 * @tc.type: FUNC
1584 */
1585 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg029, TestSize.Level1)
1586 {
1587 std::vector<std::thread> threads;
1588 for (int i = 0; i < 20; ++i) {
__anon695700410902() 1589 threads.emplace_back(std::thread([]() { context_->GetOrCreateSharedImageManager(); }));
1590 }
1591 for (auto&& thread : threads) {
1592 thread.join();
1593 }
1594
1595 threads.clear();
1596 for (int i = 0; i < 20; ++i) {
1597 if (i == 10) {
1598 context_->SetThemeManager(AceType::MakeRefPtr<MockThemeManager>());
1599 } else {
__anon695700410a02() 1600 threads.emplace_back(std::thread([]() { context_->GetThemeManager(); }));
1601 }
1602 }
1603 for (auto&& thread : threads) {
1604 thread.join();
1605 }
1606 EXPECT_TRUE(context_->GetThemeManager());
1607 }
1608
1609 /**
1610 * @tc.name: PipelineContextTestNg030
1611 * @tc.desc: Test RestoreNodeInfo, GetStoredNodeInfo, StoreNode and GetRestoreInfo.
1612 * @tc.type: FUNC
1613 */
1614 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg030, TestSize.Level1)
1615 {
1616 /**
1617 * @tc.steps1: init a mockPattern.
1618 * @tc.expected: some calls by mockPattern.
1619 */
1620 RefPtr<MockPattern> mockPattern_ = AceType::MakeRefPtr<MockPattern>();
1621 Mock::AllowLeak(mockPattern_.rawPtr_);
1622 EXPECT_CALL(*mockPattern_, ProvideRestoreInfo())
1623 .Times(AnyNumber())
1624 .WillRepeatedly(testing::Return("Default restore info"));
1625 EXPECT_CALL(*mockPattern_, GetContextParam()).Times(AnyNumber()).WillRepeatedly(testing::Return(std::nullopt));
1626 EXPECT_CALL(*mockPattern_, CreatePaintProperty())
1627 .Times(AnyNumber())
1628 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<PaintProperty>()));
1629 EXPECT_CALL(*mockPattern_, CreateLayoutProperty())
1630 .Times(AnyNumber())
1631 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<LayoutProperty>()));
1632 EXPECT_CALL(*mockPattern_, CreateEventHub())
1633 .Times(AnyNumber())
1634 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<EventHub>()));
1635 EXPECT_CALL(*mockPattern_, CreateAccessibilityProperty())
1636 .Times(AnyNumber())
1637 .WillRepeatedly(testing::Return(AceType::MakeRefPtr<AccessibilityProperty>()));
1638 EXPECT_CALL(*mockPattern_, OnAttachToFrameNode()).Times(AnyNumber());
1639 EXPECT_CALL(*mockPattern_, OnDetachFromFrameNode(_)).Times(AnyNumber());
1640
1641 /**
1642 * @tc.steps2: init a patternCreator and Create frameNodes and call StoreNode.
1643 * @tc.expected: StoreNode success.
1644 */
__anon695700410b02() 1645 auto patternCreator_ = [&mockPattern_]() { return mockPattern_; };
1646 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1647 auto frameNode_1 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
1648 ASSERT_NE(context_, nullptr);
1649 context_->StoreNode(DEFAULT_RESTORE_ID0, frameNode_1);
1650 EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID0], frameNode_1);
1651 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1652 auto frameNode_2 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, patternCreator_);
1653 context_->StoreNode(DEFAULT_RESTORE_ID0, frameNode_2);
1654 EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID0], frameNode_2);
1655 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1656 auto frameNode_3 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
1657 context_->StoreNode(DEFAULT_RESTORE_ID1, frameNode_3);
1658 EXPECT_EQ(context_->storeNode_[DEFAULT_RESTORE_ID1], frameNode_3);
1659 context_->storeNode_[DEFAULT_RESTORE_ID2] = nullptr;
1660
1661 /**
1662 * @tc.steps3: call RestoreNodeInfo with nullptr.
1663 * @tc.expected: restoreNodeInfo_ is empty.
1664 */
1665 auto jsonNodeInfo = context_->GetStoredNodeInfo();
1666 context_->RestoreNodeInfo(jsonNodeInfo->GetChild());
1667 EXPECT_TRUE(context_->restoreNodeInfo_.empty());
1668
1669 /**
1670 * @tc.steps4: call GetStoredNodeInfo and RestoreNodeInfo.
1671 * @tc.expected: restoreNodeInfo_ is not empty.
1672 */
1673 context_->RestoreNodeInfo(std::move(jsonNodeInfo));
1674 EXPECT_FALSE(context_->restoreNodeInfo_.empty());
1675
1676 /**
1677 * @tc.steps5: call GetRestoreInfo.
1678 * @tc.expected: restoreInfo is not "Default restore info".
1679 DEFAULT_RESTORE_ID0:"Default restore info" is moved from restoreNodeInfo_.
1680 */
1681 std::string restoreInfo;
1682 auto rt = context_->GetRestoreInfo(DEFAULT_RESTORE_ID0, restoreInfo);
1683 EXPECT_EQ(restoreInfo, "Default restore info");
1684 EXPECT_TRUE(rt);
1685 rt = context_->GetRestoreInfo(DEFAULT_RESTORE_ID0, restoreInfo);
1686 EXPECT_FALSE(rt);
1687 auto iter1 = context_->restoreNodeInfo_.find(DEFAULT_RESTORE_ID0);
1688 EXPECT_EQ(iter1, context_->restoreNodeInfo_.end());
1689 }
1690
1691 /**
1692 * @tc.name: PipelineContextTestNg031
1693 * @tc.desc: Test OnTouchEvent.
1694 * @tc.type: FUNC
1695 */
1696 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg031, TestSize.Level1)
1697 {
1698 /**
1699 * @tc.steps1: initialize parameters.
1700 * @tc.expected: All pointer is non-null.
1701 */
1702 ASSERT_NE(context_, nullptr);
1703 TouchEvent point_;
1704 /**
1705 * @tc.steps2: create callback and call OnTouchEvent.
1706 * @tc.expected: flag is false.
1707 */
1708 bool flag = false;
1709 context_->OnTouchEvent(point_, true);
1710 EXPECT_FALSE(flag);
1711 /**
1712 * @tc.steps3: call OnTouchEvent with second arg is false.
1713 * @tc.expected: hasIdleTasks_ is true.
1714 */
1715 point_.type = TouchType::UNKNOWN;
1716 context_->OnTouchEvent(point_, false);
1717 EXPECT_TRUE(context_->hasIdleTasks_);
1718 /**
1719 * @tc.steps4: change touch type and call OnTouchEvent with second arg is false.
1720 * @tc.expected: hasIdleTasks_ is true.
1721 */
1722 point_.type = TouchType::UP;
1723 context_->OnTouchEvent(point_, false);
1724 EXPECT_TRUE(context_->hasIdleTasks_);
1725 }
1726
1727 /**
1728 * @tc.name: PipelineContextTestNg032
1729 * @tc.desc: Test OnSurfacePositionChanged RegisterSurfacePositionChangedCallback
1730 * UnregisterSurfacePositionChangedCallback.
1731 * @tc.type: FUNC
1732 */
1733 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg032, TestSize.Level1)
1734 {
1735 /**
1736 * @tc.steps1: initialize parameters and call RegisterSurfacePositionChangedCallback with null.
1737 * @tc.expected: rt is 0.
1738 */
1739 ASSERT_NE(context_, nullptr);
1740 int32_t rt = context_->RegisterSurfacePositionChangedCallback(nullptr);
1741 EXPECT_EQ(rt, 0);
1742 /**
1743 * @tc.steps2: init a callback, register it and change map memory.
1744 then call OnSurfacePositionChanged.
1745 * @tc.expected: flag is true.
1746 */
1747 bool flag = false;
__anon695700410c02(int32_t input_1, int32_t input_2) 1748 auto callback_1 = [&flag](int32_t input_1, int32_t input_2) { flag = !flag; };
1749 rt = context_->RegisterSurfacePositionChangedCallback(std::move(callback_1));
1750 context_->surfacePositionChangedCallbackMap_[100] = nullptr;
1751 context_->OnSurfacePositionChanged(0, 0);
1752 EXPECT_TRUE(flag);
1753 /**
1754 * @tc.steps2: call UnregisterSurfacePositionChangedCallback.
1755 then call OnSurfacePositionChanged.
1756 * @tc.expected: flag is true.
1757 */
1758 context_->UnregisterSurfacePositionChangedCallback(rt);
1759 context_->OnSurfacePositionChanged(0, 0);
1760 EXPECT_TRUE(flag);
1761 }
1762
1763 /**
1764 * @tc.name: PipelineContextTestNg035
1765 * @tc.desc: Test ChangeMouseStyle.
1766 * @tc.type: FUNC
1767 */
1768 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg035, TestSize.Level1)
1769 {
1770 /**
1771 * @tc.steps1: initialize parameters set mouseStyleNodeId.
1772 * @tc.expected: ChangePointerStyle will be called.
1773 * @tc.steps1: call ChangeMouseStyle.
1774 */
1775 ASSERT_NE(context_, nullptr);
1776 context_->onFocus_ = true;
1777 context_->mouseStyleNodeId_ = 0;
1778 auto mouseStyle_ = AceType::DynamicCast<MockMouseStyle>(MouseStyle::CreateMouseStyle().rawPtr_);
1779 EXPECT_CALL(*mouseStyle_, ChangePointerStyle(_, _)).Times(AnyNumber());
1780 context_->ChangeMouseStyle(0, MouseFormat::DEFAULT);
1781 }
1782
1783 /**
1784 * @tc.name: PipelineContextTestNg036
1785 * @tc.desc: Test RequestFocus.
1786 * @tc.type: FUNC
1787 */
1788 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg036, TestSize.Level1)
1789 {
1790 /**
1791 * @tc.steps1: initialize parameters and make sure pointers are not null.
1792 */
1793 ASSERT_NE(context_, nullptr);
1794 ASSERT_NE(frameNode_, nullptr);
1795 context_->rootNode_ = frameNode_;
1796 auto eventHub = frameNode_->GetEventHub<EventHub>();
1797 ASSERT_NE(eventHub, nullptr);
1798 auto focusHub = eventHub->GetOrCreateFocusHub();
1799 ASSERT_NE(focusHub, nullptr);
1800 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
1801 auto frameNode_1 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr);
1802
1803 /**
1804 * @tc.steps2: set host_and call UpdateInspectorId.
1805 * @tc.expect: focusNode is not null .
1806 */
1807 eventHub->host_ = frameNode_1;
1808 frameNode_1->UpdateInspectorId("123");
1809 auto focusNode = focusHub->GetChildFocusNodeById("123");
1810 ASSERT_NE(focusNode, nullptr);
1811
1812 /**
1813 * @tc.steps3: change host_,focusType_,enabled_,
1814 focusable_,parentFocusable_,currentFocus_
1815 */
1816 auto eventHub1 = frameNode_1->GetEventHub<EventHub>();
1817 eventHub1->host_ = nullptr;
1818 focusHub->focusType_ = FocusType::NODE;
1819 eventHub->enabled_ = true;
1820 focusHub->focusable_ = true;
1821 focusHub->parentFocusable_ = true;
1822 focusHub->currentFocus_ = true;
1823
1824 /**
1825 * @tc.steps4: change isSubPipeline_ and call RequestFocus with empty string
1826 * @tc.expect: RequestFocus empty string return false.
1827 */
1828 context_->isSubPipeline_ = true;
1829 auto rt = context_->RequestFocus("");
1830 EXPECT_FALSE(rt);
1831
1832 /**
1833 * @tc.steps4: change isSubPipeline_ and call RequestFocus with 123
1834 * @tc.expect: RequestFocus 123 success.
1835 */
1836 context_->isSubPipeline_ = true;
1837 rt = context_->RequestFocus("123");
1838 EXPECT_TRUE(rt);
1839
1840 /**
1841 * @tc.steps4: change isSubPipeline_ and call RequestFocus with empty string
1842 * @tc.expect: RequestFocus empty string return false.
1843 */
1844 context_->isSubPipeline_ = false;
1845 rt = context_->RequestFocus("");
1846 EXPECT_FALSE(rt);
1847
1848 /**
1849 * @tc.steps4: change isSubPipeline_ and call RequestFocus with 123
1850 * @tc.expect: RequestFocus 123 success.
1851 */
1852 context_->isSubPipeline_ = false;
1853 rt = context_->RequestFocus("123");
1854 EXPECT_TRUE(rt);
1855 }
1856
1857 /**
1858 * @tc.name: PipelineContextTestNg037
1859 * @tc.desc: Test ExecuteSurfaceChangedCallbacks.
1860 * @tc.type: FUNC
1861 */
1862 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg037, TestSize.Level1)
1863 {
1864 /**
1865 * @tc.steps1: initialize parameters and make sure pointers are not null.
1866 set flag and creat callback then set into surfaceChangedCallbackMap_.
1867 call ExecuteSurfaceChangedCallbacks.
1868 * @tc.expect: flag turns true.
1869 */
1870 ASSERT_NE(context_, nullptr);
1871 bool flag = false;
1872 auto callback = [&flag](int32_t input_1, int32_t input_2, int32_t input_3, int32_t input_4,
__anon695700410d02(int32_t input_1, int32_t input_2, int32_t input_3, int32_t input_4, WindowSizeChangeReason type) 1873 WindowSizeChangeReason type) { flag = !flag; };
1874 context_->surfaceChangedCallbackMap_[0] = callback;
1875 context_->surfaceChangedCallbackMap_[1] = nullptr;
1876 context_->ExecuteSurfaceChangedCallbacks(0, 0, WindowSizeChangeReason::ROTATION);
1877 EXPECT_TRUE(flag);
1878 }
1879
1880 /**
1881 * @tc.name: PipelineContextTestNg038
1882 * @tc.desc: Test FlushWindowSizeChangeCallback.
1883 * @tc.type: FUNC
1884 */
1885 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg038, TestSize.Level1)
1886 {
1887 /**
1888 * @tc.steps1: initialize parameters and make sure pointers are not null.
1889 set onWindowSizeChangeCallbacks_.
1890 * @tc.expect: the value 314 has been erased.
1891 */
1892 ASSERT_NE(context_, nullptr);
1893 context_->onWindowSizeChangeCallbacks_.emplace_back(314);
1894 ASSERT_NE(frameNode_, nullptr);
1895 context_->onWindowSizeChangeCallbacks_.emplace_back(frameNode_->GetId());
1896 context_->FlushWindowSizeChangeCallback(0, 0, WindowSizeChangeReason::UNDEFINED);
1897 EXPECT_EQ(context_->onWindowSizeChangeCallbacks_.size(), 1);
1898 }
1899
1900 /**
1901 * @tc.name: PipelineContextTestNg039
1902 * @tc.desc: Test GetCurrentFrameInfo.
1903 * @tc.type: FUNC
1904 */
1905 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg039, TestSize.Level1)
1906 {
1907 /**
1908 * @tc.steps1: initialize parameters and make sure pointers are not null.
1909 set dumpFrameCount_ and dumpFrameInfos_.
1910 * @tc.expect: the return value of GetCurrentFrameInfo is null.
1911 */
1912 ASSERT_NE(context_, nullptr);
1913 SystemProperties::dumpFrameCount_ = 1;
1914 context_->dumpFrameInfos_.push_back({});
1915 auto rt = context_->GetCurrentFrameInfo(DEFAULT_UINT64_1, DEFAULT_UINT64_2);
1916 EXPECT_NE(rt, nullptr);
1917 }
1918
1919 /**
1920 * @tc.name: PipelineContextTestNg040
1921 * @tc.desc: Test SetContainerButtonHide function.
1922 * @tc.type: FUNC
1923 */
1924 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg040, TestSize.Level1)
1925 {
1926 /**
1927 * @tc.steps1: initialize root node and containerModal node.
1928 * @tc.expected: root node and containerModal node are not null.
1929 */
1930 ASSERT_NE(context_, nullptr);
1931 context_->SetWindowModal(WindowModal::CONTAINER_MODAL);
1932 ASSERT_NE(context_->window_, nullptr);
1933 context_->SetupRootElement();
1934 ASSERT_NE(context_->GetRootElement(), nullptr);
1935 auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
1936 ASSERT_NE(containerNode, nullptr);
1937 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
1938 ASSERT_NE(containerPattern, nullptr);
1939 /**
1940 * @tc.steps2: call SetContainerButtonHide with params true, true, false.
1941 * @tc.expected: depends on first param, hideSplitButton value is true.
1942 */
1943 context_->SetContainerButtonHide(true, true, false);
1944 EXPECT_TRUE(containerPattern->hideSplitButton_ == true);
1945 /**
1946 * @tc.steps3: call SetContainerButtonHide with params false, true, false.
1947 * @tc.expected: depends on first param, hideSplitButton value is false.
1948 */
1949 context_->SetContainerButtonHide(false, true, false);
1950 EXPECT_TRUE(containerPattern->hideSplitButton_ == false);
1951
1952 /**
1953 * @tc.steps4: call SetContainerButtonHide with params false, true, false.
1954 * @tc.expected: cover branch windowModal_ is not CONTAINER_MODAL
1955 */
1956 context_->SetWindowModal(WindowModal::DIALOG_MODAL);
1957 context_->SetContainerButtonHide(false, true, false);
1958 EXPECT_FALSE(containerPattern->hideSplitButton_);
1959 }
1960
1961 /**
1962 * @tc.name: PipelineContextTestNg041
1963 * @tc.desc: Test the function OnLayoutCompleted.
1964 * @tc.type: FUNC
1965 */
1966 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg041, TestSize.Level1)
1967 {
1968 /**
1969 * @tc.steps1: initialize parameters.
1970 * @tc.expected: frontend-ptr is non-null.
1971 */
1972 ContainerScope scope(DEFAULT_INSTANCE_ID);
1973 ASSERT_NE(context_, nullptr);
1974 auto frontend = AceType::MakeRefPtr<MockFrontend>();
1975 context_->weakFrontend_ = frontend;
1976
1977 /**
1978 * @tc.steps2: test the function OnLayoutCompleted by TEST_TAG.
1979 * @tc.expected: frontend componentId_ is TEST_TAG
1980 */
1981 context_->OnLayoutCompleted(TEST_TAG);
1982 EXPECT_EQ(frontend->GetComponentId(), TEST_TAG);
1983 context_->weakFrontend_.Reset();
1984 }
1985
1986 /**
1987 * @tc.name: PipelineContextTestNg042
1988 * @tc.desc: Test the function OnDrawCompleted.
1989 * @tc.type: FUNC
1990 */
1991 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg042, TestSize.Level1)
1992 {
1993 /**
1994 * @tc.steps1: initialize parameters.
1995 * @tc.expected: frontend-ptr is non-null.
1996 */
1997
1998 ContainerScope scope(DEFAULT_INSTANCE_ID);
1999 ASSERT_NE(context_, nullptr);
2000 auto frontend = AceType::MakeRefPtr<MockFrontend>();
2001 context_->weakFrontend_ = frontend;
2002
2003 /**
2004 * @tc.steps4: test the function OnDrawCompleted by TEST_TAG.
2005 * @tc.expected: frontend componentId_ is TEST_TAG
2006 */
2007 context_->OnDrawCompleted(TEST_TAG);
2008 EXPECT_EQ(frontend->GetComponentId(), TEST_TAG);
2009 context_->weakFrontend_.Reset();
2010 }
2011
2012 /**
2013 * @tc.name: UITaskSchedulerTestNg001
2014 * @tc.desc: Test FlushLayoutTask.
2015 * @tc.type: FUNC
2016 */
2017 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg001, TestSize.Level1)
2018 {
2019 /**
2020 * @tc.steps1: Create taskScheduler.
2021 */
2022 UITaskScheduler taskScheduler;
2023
2024 /**
2025 * @tc.steps2: Create frameInfo and StartRecordFrameInfo.
2026 */
2027 FrameInfo frameInfo;
2028 taskScheduler.StartRecordFrameInfo(&frameInfo);
2029
2030 /**
2031 * @tc.steps3: Create some frameNode.
2032 */
2033 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, 1, nullptr);
2034 frameNode->SetInDestroying();
2035 auto frameNode2 = FrameNode::GetOrCreateFrameNode(TEST_TAG, 2, nullptr);
2036
2037 /**
2038 * @tc.steps4: Calling FlushLayoutTask with no layout.
2039 * @tc.expected: frame info not record.
2040 */
2041 taskScheduler.FlushLayoutTask(false);
2042 EXPECT_EQ(frameInfo.layoutInfos_.size(), 0);
2043
2044 /**
2045 * @tc.steps5: add some layoutNode and recall FlushLayoutTask with false .
2046 * @tc.expected: frame info not record.
2047 */
2048 taskScheduler.AddDirtyLayoutNode(frameNode);
2049 taskScheduler.AddDirtyLayoutNode(frameNode2);
2050 taskScheduler.FlushLayoutTask(false);
2051 EXPECT_EQ(frameInfo.layoutInfos_.size(), 1);
2052
2053 /**
2054 * @tc.steps6: add layoutNode again and set isLayoutDirtyMarked_ true and recall FlushLayoutTask with false .
2055 * @tc.expected: frame info record true frameInfo.layoutInfos_.size is 2.
2056 */
2057 taskScheduler.AddDirtyLayoutNode(frameNode2);
2058 frameNode2->isLayoutDirtyMarked_ = true;
2059 taskScheduler.FlushLayoutTask(false);
2060 EXPECT_EQ(frameInfo.layoutInfos_.size(), 2);
2061
2062 /**
2063 * @tc.steps7: add layoutNode again and call FlushLayoutTask with true .
2064 * @tc.expected: frame info record true frameInfo.layoutInfos_.size is 3.
2065 */
2066 taskScheduler.AddDirtyLayoutNode(frameNode2);
2067 frameNode2->isLayoutDirtyMarked_ = true;
2068 taskScheduler.FlushLayoutTask(true);
2069 EXPECT_EQ(frameInfo.layoutInfos_.size(), 3);
2070
2071 /**
2072 * @tc.steps8: finish FinishRecordFrameInfo and do step7.
2073 * @tc.expected: frame info stop record frameInfo.layoutInfos_.size is 3.
2074 */
2075 taskScheduler.FinishRecordFrameInfo();
2076 taskScheduler.AddDirtyLayoutNode(frameNode2);
2077 frameNode2->isLayoutDirtyMarked_ = true;
2078 taskScheduler.FlushLayoutTask(true);
2079 EXPECT_EQ(frameInfo.layoutInfos_.size(), 3);
2080 }
2081
2082 /**
2083 * @tc.name: UITaskSchedulerTestNg002
2084 * @tc.desc: Test FlushAfterLayoutTask.
2085 * @tc.type: FUNC
2086 */
2087 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg002, TestSize.Level1)
2088 {
2089 /**
2090 * @tc.steps1: Create taskScheduler.
2091 */
2092 UITaskScheduler taskScheduler;
2093
2094 /**
2095 * @tc.steps2: Call FlushAfterLayoutTask.
2096 */
2097 taskScheduler.FlushAfterLayoutTask();
2098
2099 /**
2100 * @tc.steps3: Call AddAfterLayoutTask.
2101 * @tc.expected: afterLayoutTasks_ in the taskScheduler size is 2.
2102 */
__anon695700410e02() 2103 taskScheduler.AddAfterLayoutTask([]() {});
2104 taskScheduler.AddAfterLayoutTask(nullptr);
2105 EXPECT_EQ(taskScheduler.afterLayoutTasks_.size(), 2);
2106
2107 /**
2108 * @tc.steps4: Call FlushTask.
2109 * @tc.expected: afterLayoutTasks_ in the taskScheduler size is 0.
2110 */
2111 taskScheduler.FlushTask();
2112 EXPECT_EQ(taskScheduler.afterLayoutTasks_.size(), 0);
2113 }
2114
2115 /**
2116 * @tc.name: UITaskSchedulerTestNg003
2117 * @tc.desc: Test FlushAfterLayoutTask.
2118 * @tc.type: FUNC
2119 */
2120 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg003, TestSize.Level1)
2121 {
2122 /**
2123 * @tc.steps1: Create taskScheduler.
2124 */
2125 UITaskScheduler taskScheduler;
2126
2127 /**
2128 * @tc.steps2: Call FlushPredictTask.
2129 */
2130 taskScheduler.FlushPredictTask(0);
2131
2132 /**
2133 * @tc.steps3: Call AddPredictTask.
2134 * @tc.expected: predictTask_ in the taskScheduler size is 2.
2135 */
__anon695700410f02(int64_t, bool) 2136 taskScheduler.AddPredictTask([](int64_t, bool) {});
2137 taskScheduler.AddPredictTask(nullptr);
2138 EXPECT_EQ(taskScheduler.predictTask_.size(), 2);
2139
2140 /**
2141 * @tc.steps4: Call FlushPredictTask.
2142 * @tc.expected: predictTask_ in the taskScheduler size is 0.
2143 */
2144 taskScheduler.FlushPredictTask(0);
2145 EXPECT_EQ(taskScheduler.predictTask_.size(), 0);
2146 }
2147
2148 /**
2149 * @tc.name: UITaskSchedulerTestNg004
2150 * @tc.desc: Test NeedAdditionalLayout.
2151 * @tc.type: FUNC
2152 */
2153 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg004, TestSize.Level1)
2154 {
2155 /**
2156 * @tc.steps1: Create taskScheduler.
2157 */
2158 UITaskScheduler taskScheduler;
2159
2160 /**
2161 * @tc.steps2: Create some frameNode and configure the required parameters.
2162 */
2163 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, 1, nullptr);
2164 frameNode->layoutProperty_ = nullptr;
2165 auto frameNode2 = FrameNode::GetOrCreateFrameNode(TEST_TAG, 2, nullptr);
2166
2167 /**
2168 * @tc.steps3: Call AddDirtyLayoutNode with different parameters.
2169 * @tc.expected: NeedAdditionalLayout return false.
2170 */
2171 taskScheduler.AddDirtyLayoutNode(frameNode);
2172 taskScheduler.AddDirtyLayoutNode(frameNode2);
2173 EXPECT_FALSE(taskScheduler.NeedAdditionalLayout());
2174
2175 /**
2176 * @tc.steps4: Create a appropriate node and recall AddDirtyLayoutNode.
2177 * @tc.expected: NeedAdditionalLayout return true.
2178 */
2179 auto frameNode3 = FrameNode::GetOrCreateFrameNode(TEST_TAG, 3, nullptr);
2180 auto geometryTransition = AceType::MakeRefPtr<NG::GeometryTransition>("test", frameNode3);
2181 geometryTransition->hasOutAnim_ = true;
2182 geometryTransition->inNode_ = frameNode2;
2183 geometryTransition->outNode_ = frameNode3;
2184 frameNode3->GetLayoutProperty()->geometryTransition_ = geometryTransition;
2185 taskScheduler.AddDirtyLayoutNode(frameNode3);
2186 EXPECT_TRUE(taskScheduler.NeedAdditionalLayout());
2187 taskScheduler.CleanUp();
2188 }
2189
2190 /**
2191 * @tc.name: UITaskSchedulerTestNg005
2192 * @tc.desc: Test FlushRenderTask.
2193 * @tc.type: FUNC
2194 */
2195 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg005, TestSize.Level1)
2196 {
2197 /**
2198 * @tc.steps1: Create taskScheduler.
2199 */
2200 UITaskScheduler taskScheduler;
2201
2202 /**
2203 * @tc.steps2: Create frameInfo and StartRecordFrameInfo.
2204 */
2205 FrameInfo frameInfo;
2206 taskScheduler.StartRecordFrameInfo(&frameInfo);
2207
2208 /**
2209 * @tc.steps3: Create some frameNode.
2210 */
2211 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, 1, nullptr);
2212 frameNode->SetInDestroying();
2213 taskScheduler.dirtyRenderNodes_[1].emplace(nullptr);
2214 auto pattern = AceType::MakeRefPtr<BubblePattern>();
2215 auto frameNode2 = FrameNode::CreateFrameNode(TEST_TAG, 2, pattern);
2216
2217 /**
2218 * @tc.steps4: Calling FlushRenderTask with no layout.
2219 * @tc.expected: frame info not record.
2220 */
2221 taskScheduler.FlushRenderTask(false);
2222
2223 /**
2224 * @tc.steps5: add some layoutNode and recall FlushRenderTask with false .
2225 * @tc.expected: frame info not record.
2226 */
2227 taskScheduler.AddDirtyRenderNode(frameNode);
2228 taskScheduler.AddDirtyRenderNode(frameNode2);
2229 taskScheduler.FlushRenderTask(false);
2230 EXPECT_EQ(frameInfo.renderInfos_.size(), 0);
2231
2232 /**
2233 * @tc.steps6: add renderNode again and set isRenderDirtyMarked_ true and recall FlushRenderTask with false.
2234 * @tc.expected: frame info record true frameInfo.renderInfos_.size is 1.
2235 */
2236 frameNode2->isRenderDirtyMarked_ = true;
2237 pattern->AttachToFrameNode(frameNode2);
2238 taskScheduler.AddDirtyRenderNode(frameNode2);
2239 taskScheduler.FlushRenderTask(false);
2240 EXPECT_EQ(frameInfo.renderInfos_.size(), 1);
2241
2242 /**
2243 * @tc.steps7: add layoutNode again and call FlushRenderTask with true and stop record info .
2244 * @tc.expected: frame info record true frameInfo.renderInfos_.size is 1.
2245 */
2246 frameNode2->isRenderDirtyMarked_ = true;
2247 taskScheduler.AddDirtyRenderNode(frameNode2);
2248 taskScheduler.FinishRecordFrameInfo();
2249 taskScheduler.FlushRenderTask(true);
2250 EXPECT_EQ(frameInfo.renderInfos_.size(), 1);
2251 }
2252
2253 /**
2254 * @tc.name: UITaskSchedulerTestNg002
2255 * @tc.desc: Test FlushAfterLayoutTask.
2256 * @tc.type: FUNC
2257 */
2258 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg006, TestSize.Level1)
2259 {
2260 /**
2261 * @tc.steps1: Create taskScheduler.
2262 */
2263 UITaskScheduler taskScheduler;
2264
2265 /**
2266 * @tc.steps2: Call FlushAfterLayoutTask.
2267 */
2268 taskScheduler.FlushAfterLayoutTask();
2269
2270 /**
2271 * @tc.steps3: Call AddAfterLayoutTask.
2272 * @tc.expected: afterLayoutTasks_ in the taskScheduler size is 2.
2273 */
__anon695700411002() 2274 taskScheduler.AddPersistAfterLayoutTask([]() {});
2275 taskScheduler.AddPersistAfterLayoutTask(nullptr);
2276 EXPECT_EQ(taskScheduler.persistAfterLayoutTasks_.size(), 2);
2277
2278 /**
2279 * @tc.steps4: Call FlushTask.
2280 * @tc.expected: afterLayoutTasks_ in the taskScheduler size is 0.
2281 */
2282 taskScheduler.FlushTask();
2283 EXPECT_EQ(taskScheduler.afterLayoutTasks_.size(), 0);
2284 }
2285
2286 /**
2287 * @tc.name: PipelineContextTestNg043
2288 * @tc.desc: Test SetCloseButtonStatus function.
2289 * @tc.type: FUNC
2290 */
2291 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg043, TestSize.Level1)
2292 {
2293 /**
2294 * @tc.steps1: initialize root node and containerModal node.
2295 * @tc.expected: root node and containerModal node are not null.
2296 */
2297 ASSERT_NE(context_, nullptr);
2298 context_->SetWindowModal(WindowModal::CONTAINER_MODAL);
2299 ASSERT_NE(context_->window_, nullptr);
2300 context_->SetupRootElement();
2301 ASSERT_NE(context_->GetRootElement(), nullptr);
2302 auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
2303 ASSERT_NE(containerNode, nullptr);
2304 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
2305 ASSERT_NE(containerPattern, nullptr);
2306 auto columNode = AceType::DynamicCast<FrameNode>(containerNode->GetChildren().front());
2307 CHECK_NULL_VOID(columNode);
2308 auto titleNode = AceType::DynamicCast<FrameNode>(columNode->GetChildren().front());
2309 CHECK_NULL_VOID(titleNode);
2310 auto closeButton = AceType::DynamicCast<FrameNode>(titleNode->GetChildAtIndex(CLOSE_BUTTON_INDEX));
2311 CHECK_NULL_VOID(closeButton);
2312 auto buttonEvent = closeButton->GetEventHub<ButtonEventHub>();
2313 CHECK_NULL_VOID(buttonEvent);
2314 /**
2315 * @tc.steps2: call SetCloseButtonStatus with params true.
2316 * @tc.expected: CloseButton IsEnabled return true.
2317 */
2318 context_->SetCloseButtonStatus(true);
2319 EXPECT_EQ(buttonEvent->IsEnabled(), true);
2320 /**
2321 * @tc.steps3: call SetCloseButtonStatus with params false.
2322 * @tc.expected: CloseButton IsEnabled return false.
2323 */
2324 context_->SetCloseButtonStatus(false);
2325 EXPECT_EQ(buttonEvent->IsEnabled(), false);
2326 }
2327
2328 /**
2329 * @tc.name: PipelineContextTestNg044
2330 * @tc.desc: Test the function FlushAnimation.
2331 * @tc.type: FUNC
2332 */
2333 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg044, TestSize.Level1)
2334 {
2335 /**
2336 * @tc.steps1: initialize parameters.
2337 * @tc.expected: All pointer is non-null.
2338 */
2339 ASSERT_NE(context_, nullptr);
2340
2341 /**
2342 * @tc.steps2: Call the function FlushAnimation with unempty scheduleTasks_.
2343 * @tc.expected: The nanoTimestamp of scheduleTask is equal to NANO_TIME_STAMP.
2344 */
2345 auto scheduleTask = AceType::MakeRefPtr<MockScheduleTask>();
2346 EXPECT_NE(scheduleTask->GetNanoTimestamp(), NANO_TIME_STAMP);
2347
2348 /**
2349 * @tc.steps3: Call the function AddScheduleTask.
2350 * @tc.expected: The scheduleTasks_ has the task id.
2351 */
2352 auto id = context_->AddScheduleTask(scheduleTask);
2353 EXPECT_EQ(context_->scheduleTasks_.count(id), 1);
2354
2355 /**
2356 * @tc.steps4: Call the function RemoveScheduleTask.
2357 * @tc.expected: The scheduleTasks_ does not have the task id.
2358 */
2359 context_->RemoveScheduleTask(id);
2360 EXPECT_EQ(context_->scheduleTasks_.count(id), 0);
2361 }
2362
2363 /**
2364 * @tc.name: PipelineContextTestNg045
2365 * @tc.desc: Test the function FlushAnimation.
2366 * @tc.type: FUNC
2367 */
2368 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg045, TestSize.Level1)
2369 {
2370 /**
2371 * @tc.steps1: initialize parameters.
2372 * @tc.expected: All pointer is non-null.
2373 */
2374 ASSERT_NE(context_, nullptr);
2375 ASSERT_TRUE(context_->needRenderNode_.empty());
2376 /**
2377 * @tc.steps2: Call the function FlushAnimation with unempty scheduleTasks_.
2378 * @tc.expected: The nanoTimestamp of scheduleTask is equal to NANO_TIME_STAMP.
2379 */
2380 auto pattern = AceType::MakeRefPtr<BubblePattern>();
2381 auto frameNode = FrameNode::CreateFrameNode(TEST_TAG, 3, pattern);
2382 context_->SetNeedRenderNode(frameNode);
2383 EXPECT_EQ(context_->needRenderNode_.count(frameNode), 1);
2384
2385 /**
2386 * @tc.steps3: Call the function FlushPipelineImmediately.
2387 * @tc.expected: The nanoTimestamp of scheduleTask is equal to NANO_TIME_STAMP.
2388 */
2389 context_->FlushPipelineImmediately();
2390 EXPECT_TRUE(context_->isRebuildFinished_);
2391 }
2392
2393 /**
2394 * @tc.name: PipelineContextTestNg046
2395 * @tc.desc: Test the function AddAnimationClosure and FlushAnimationClosure.
2396 * @tc.type: FUNC
2397 */
2398 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg046, TestSize.Level1)
2399 {
2400 /**
2401 * @tc.steps1: initialize parameters.
2402 * @tc.expected: All pointer is non-null.
2403 */
2404 ASSERT_NE(context_, nullptr);
2405 /**
2406 * @tc.steps2: call AddAnimationClosure.
2407 * @tc.expected: The animationClosuresList_ has 1 element.
2408 */
__anon695700411102() 2409 auto mockAnimation = []() -> void {};
2410 context_->AddAnimationClosure(mockAnimation);
2411 EXPECT_EQ(context_->animationClosuresList_.size(), 1);
2412 /**
2413 * @tc.steps3: call FlushAnimationClosure.
2414 * @tc.expected: The animationClosuresList_ has 1 element.
2415 */
2416 context_->FlushAnimationClosure();
2417 EXPECT_TRUE(context_->animationClosuresList_.empty());
2418 }
2419
2420 /**
2421 * @tc.name: PipelineContextTestNg046
2422 * @tc.desc: Test the function GetStageManager.
2423 * @tc.type: FUNC
2424 */
2425 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg047, TestSize.Level1)
2426 {
2427 /**
2428 * @tc.steps1: initialize parameters.
2429 * @tc.expected: All pointer is non-null.
2430 */
2431 ASSERT_NE(context_, nullptr);
2432 /**
2433 * @tc.steps2: call GetStageManager.
2434 * @tc.expected: The stageManager is not null.
2435 */
2436 context_->SetupRootElement();
2437 auto stageManager = context_->GetStageManager();
2438 EXPECT_NE(stageManager, nullptr);
2439 }
2440
2441 /**
2442 * @tc.name: PipelineContextTestNg048
2443 * @tc.desc: Test the function GetSelectOverlayManager.
2444 * @tc.type: FUNC
2445 */
2446 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg048, TestSize.Level1)
2447 {
2448 /**
2449 * @tc.steps1: initialize parameters.
2450 * @tc.expected: All pointer is non-null.
2451 */
2452 ASSERT_NE(context_, nullptr);
2453 /**
2454 * @tc.steps2: call SetupRootElement.
2455 * @tc.expected: The selectOverlayManager is not null.
2456 */
2457 context_->SetupRootElement();
2458 auto selectOverlayManager = context_->GetSelectOverlayManager();
2459 EXPECT_NE(selectOverlayManager, nullptr);
2460 }
2461
2462 /**
2463 * @tc.name: PipelineContextTestNg049
2464 * @tc.desc: Test the function GetFullScreenManager.
2465 * @tc.type: FUNC
2466 */
2467 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg049, TestSize.Level1)
2468 {
2469 /**
2470 * @tc.steps1: initialize parameters.
2471 * @tc.expected: All pointer is non-null.
2472 */
2473 ASSERT_NE(context_, nullptr);
2474 /**
2475 * @tc.steps2: call GetFullScreenManager.
2476 * @tc.expected: The fullScreenManager is not null.
2477 */
2478 context_->SetupRootElement();
2479 auto fullScreenManager = context_->GetFullScreenManager();
2480 EXPECT_NE(fullScreenManager, nullptr);
2481 }
2482
2483 /**
2484 * @tc.name: PipelineContextTestNg050
2485 * @tc.desc: Test the function UpdateSystemSafeArea and UpdateCutoutSafeArea.
2486 * @tc.type: FUNC
2487 */
2488 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg050, TestSize.Level1)
2489 {
2490 /**
2491 * @tc.steps1: initialize parameters.
2492 * @tc.expected: All pointer is non-null.
2493 */
2494 ASSERT_NE(context_, nullptr);
2495 /**
2496 * @tc.steps2: call AddAnimationClosure.
2497 * @tc.expected: The GetFullScreenManager is not null.
2498 */
2499 context_->SetMinPlatformVersion(10);
2500 SafeAreaInsets::Inset left { 0, 1 };
2501 SafeAreaInsets::Inset top { 0, 2 };
2502 SafeAreaInsets::Inset right { 0, 3 };
2503 SafeAreaInsets::Inset bottom { 0, 4 };
2504 SafeAreaInsets safeAreaInsets(left, top, right, bottom);
2505 context_->UpdateSystemSafeArea(safeAreaInsets);
2506 EXPECT_EQ(context_->safeAreaManager_->systemSafeArea_, safeAreaInsets);
2507
2508 context_->UpdateCutoutSafeArea(safeAreaInsets);
2509 EXPECT_NE(context_->safeAreaManager_->cutoutSafeArea_, safeAreaInsets);
2510 }
2511
2512 /**
2513 * @tc.name: PipelineContextTestNg051
2514 * @tc.desc: Test the function SetIgnoreViewSafeArea.
2515 * @tc.type: FUNC
2516 */
2517 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg051, TestSize.Level1)
2518 {
2519 /**
2520 * @tc.steps1: initialize parameters.
2521 * @tc.expected: All pointer is non-null.
2522 */
2523 ASSERT_NE(context_, nullptr);
2524 /**
2525 * @tc.steps2: call SetIgnoreViewSafeArea.
2526 * @tc.expected: The ignoreSafeArea_ is true.
2527 */
2528 context_->safeAreaManager_->ignoreSafeArea_ = false;
2529 context_->SetIgnoreViewSafeArea(true);
2530 EXPECT_TRUE(context_->safeAreaManager_->ignoreSafeArea_);
2531 }
2532
2533 /**
2534 * @tc.name: PipelineContextTestNg052
2535 * @tc.desc: Test the function SyncSafeArea.
2536 * @tc.type: FUNC
2537 */
2538 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg052, TestSize.Level1)
2539 {
2540 /**
2541 * @tc.steps1: initialize parameters.
2542 * @tc.expected: All pointer is non-null.
2543 */
2544 ASSERT_NE(context_, nullptr);
2545 /**
2546 * @tc.steps2: call SyncSafeArea.
2547 * @tc.expected: The isLayoutDirtyMarked_ is true.
2548 */
2549 context_->SetupRootElement();
2550 auto frameNodeId = ElementRegister::GetInstance()->MakeUniqueId();
2551 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId, nullptr);
2552 context_->safeAreaManager_->AddGeoRestoreNode(frameNode);
2553 context_->SyncSafeArea(false);
2554 EXPECT_TRUE(frameNode->isLayoutDirtyMarked_);
2555 }
2556
2557 /**
2558 * @tc.name: PipelineContextTestNg053
2559 * @tc.desc: Test the function FindNavigationNodeToHandleBack.
2560 * @tc.type: FUNC
2561 */
2562 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg053, TestSize.Level1)
2563 {
2564 /**
2565 * @tc.steps1: initialize parameters.
2566 * @tc.expected: All pointer is non-null.
2567 */
2568 ASSERT_NE(context_, nullptr);
2569 /**
2570 * @tc.steps2: call FindNavigationNodeToHandleBack.
2571 * @tc.expected: The ret is nullptr.
2572 */
2573 context_->SetupRootElement();
2574 auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
2575 auto node = NavigationGroupNode::GetOrCreateGroupNode(TEST_TAG, nodeId, nullptr);
2576
2577 auto childId = ElementRegister::GetInstance()->MakeUniqueId();
2578 auto childNode = NavigationGroupNode::GetOrCreateFrameNode(TEST_TAG, childId, nullptr);
2579 node->AddChild(childNode);
2580 EXPECT_EQ(context_->FindNavigationNodeToHandleBack(node), nullptr);
2581 }
2582
2583 /**
2584 * @tc.name: PipelineContextTestNg054
2585 * @tc.desc: Test the function AddAfterLayoutTask and AddAfterRenderTask.
2586 * @tc.type: FUNC
2587 */
2588 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg054, TestSize.Level1)
2589 {
2590 /**
2591 * @tc.steps1: initialize parameters.
2592 * @tc.expected: All pointer is non-null.
2593 */
2594 ASSERT_NE(context_, nullptr);
2595 /**
2596 * @tc.steps2: call AddAfterLayoutTask.
2597 * @tc.expected: The afterLayoutTasks_ size is 1.
2598 */
2599 context_->SetupRootElement();
__anon695700411202() 2600 context_->AddAfterLayoutTask([]() -> void {});
2601 EXPECT_EQ(context_->taskScheduler_->afterLayoutTasks_.size(), 1);
2602 /**
2603 * @tc.steps3: call AddAfterLayoutTask.
2604 * @tc.expected: The afterLayoutTasks_ size is 1.
2605 */
__anon695700411302() 2606 context_->AddAfterRenderTask([]() -> void {});
2607 EXPECT_EQ(context_->taskScheduler_->afterRenderTasks_.size(), 1);
2608 }
2609
2610 /**
2611 * @tc.name: PipelineContextTestNg055
2612 * @tc.desc: Test the function AddFontNodeNG and RemoveFontNodeNG.
2613 * @tc.type: FUNC
2614 */
2615 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg055, TestSize.Level1)
2616 {
2617 /**
2618 * @tc.steps1: initialize parameters.
2619 * @tc.expected: All pointer is non-null.
2620 */
2621 ASSERT_NE(context_, nullptr);
2622 /**
2623 * @tc.steps2: call AddFontNodeNG.
2624 * @tc.expected: fontNodesNG_.size() is 1.
2625 */
2626 context_->SetupRootElement();
2627 context_->fontManager_ = AceType::MakeRefPtr<MockFontManager>();
2628 auto fontNodeId = ElementRegister::GetInstance()->MakeUniqueId();
2629 auto fontNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, fontNodeId, nullptr);
2630 context_->AddFontNodeNG(fontNode);
2631 EXPECT_EQ(context_->GetFontManager()->fontNodesNG_.size(), 1);
2632 /**
2633 * @tc.steps2: call RemoveFontNodeNG.
2634 * @tc.expected: fontNodesNG_.size() is 0.
2635 */
2636 context_->RemoveFontNodeNG(fontNode);
2637 EXPECT_EQ(context_->GetFontManager()->fontNodesNG_.size(), 0);
2638 }
2639
2640 /**
2641 * @tc.name: PipelineContextTestNg056
2642 * @tc.desc: Test the function AddFontNodeNG and RemoveFontNodeNG.
2643 * @tc.type: FUNC
2644 */
2645 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg056, TestSize.Level1)
2646 {
2647 /**
2648 * @tc.steps1: initialize parameters.
2649 * @tc.expected: All pointer is non-null.
2650 */
2651 ASSERT_NE(context_, nullptr);
2652 /**
2653 * @tc.steps2: call IsWindowSceneConsumed.
2654 * @tc.expected: The return is false.
2655 */
2656 context_->SetupRootElement();
2657 EXPECT_FALSE(context_->IsWindowSceneConsumed());
2658 /**
2659 * @tc.steps2: call SetWindowSceneConsumed(true) and IsWindowSceneConsumed.
2660 * @tc.expected: The return is true.
2661 */
2662 context_->SetWindowSceneConsumed(true);
2663 EXPECT_TRUE(context_->IsWindowSceneConsumed());
2664 }
2665
2666 /**
2667 * @tc.name: PipelineContextTestNg057
2668 * @tc.desc: Test the function AddFontNodeNG and RemoveFontNodeNG.
2669 * @tc.type: FUNC
2670 */
2671 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg057, TestSize.Level1)
2672 {
2673 /**
2674 * @tc.steps1: initialize parameters.
2675 * @tc.expected: All pointer is non-null.
2676 */
2677 ASSERT_NE(context_, nullptr);
2678
2679 auto needRenderNodeId = ElementRegister::GetInstance()->MakeUniqueId();
2680 auto needRenderNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, needRenderNodeId, nullptr);
2681 context_->SetNeedRenderNode(needRenderNode);
2682 EXPECT_EQ(context_->needRenderNode_.count(needRenderNode), 1);
2683 context_->InspectDrew();
2684 EXPECT_EQ(context_->needRenderNode_.count(needRenderNode), 0);
2685 }
2686
2687 /**
2688 * @tc.name: PipelineContextTestNg058
2689 * @tc.desc: Test the function FlushMouseEventG.
2690 * @tc.type: FUNC
2691 */
2692 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg058, TestSize.Level1)
2693 {
2694 /**
2695 * @tc.steps1: initialize parameters.
2696 * @tc.expected: pointer is non-null.
2697 */
2698 ASSERT_NE(context_, nullptr);
2699
2700 /**
2701 * @tc.steps2: Call the function FlushMouseEvent with default action.
2702 * @tc.expected: The function is called and cover branch mouseAction is not WINDOW_LEAVE.
2703 */
2704 context_->FlushMouseEvent();
2705 auto result = context_->lastMouseEvent_->action == MouseAction::WINDOW_LEAVE;
2706 EXPECT_FALSE(result);
2707
2708 /**
2709 * @tc.steps3: Call the function FlushMouseEvent with lastMouseEvent_ is nullptr.
2710 * @tc.expected: The function is called and cover branch lastMouseEvent_ is nullptr.
2711 */
2712 context_->lastMouseEvent_ = nullptr;
2713 context_->FlushMouseEvent();
2714 EXPECT_EQ(context_->lastMouseEvent_, nullptr);
2715
2716 /**
2717 * @tc.steps4: Call the function FlushMouseEvent with mouseAction is WINDOW_LEAVE.
2718 * @tc.expected: The function is called and cover branch mouseAction is WINDOW_LEAVE.
2719 */
2720 context_->lastMouseEvent_ = std::make_unique<MouseEvent>();
2721 context_->lastMouseEvent_->action = MouseAction::WINDOW_LEAVE;
2722 context_->FlushMouseEvent();
2723 result = context_->lastMouseEvent_->action == MouseAction::WINDOW_LEAVE;
2724 EXPECT_TRUE(result);
2725 }
2726
2727 /**
2728 * @tc.name: PipelineContextTestNg059
2729 * @tc.desc: Test the function OnIdle.
2730 * @tc.type: FUNC
2731 */
2732 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg059, TestSize.Level1)
2733 {
2734 /**
2735 * @tc.steps1: initialize parameters.
2736 * @tc.expected: All pointer is non-null.
2737 */
2738 ASSERT_NE(context_, nullptr);
2739
2740 /**
2741 * @tc.steps2: Call the function OnIdle with canUseLongPredictTask_.
2742 * @tc.expected: called OnIdle and cover branch canUseLongPredictTask_ is true.
2743 */
2744 context_->canUseLongPredictTask_ = true;
2745 context_->OnIdle(1);
2746 EXPECT_TRUE(context_->touchEvents_.empty());
2747
2748 /**
2749 * @tc.steps3: Call the function OnIdle with touchEvents_ is not empty.
2750 * @tc.expected: The value of flagCbk changed.
2751 */
2752 bool flagCbk = false;
__anon695700411402(int64_t, bool) 2753 context_->AddPredictTask([&flagCbk](int64_t, bool) { flagCbk = true; });
2754 TouchEvent event;
2755 event.id = RENDER_EVENT_ID;
2756 context_->touchEvents_.push_back(event);
2757 context_->canUseLongPredictTask_ = true;
2758 context_->OnIdle(2);
2759 EXPECT_TRUE(flagCbk);
2760 }
2761
2762 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg060, TestSize.Level1)
2763 {
2764 /**
2765 * @tc.steps1: initialize parameters.
2766 * @tc.expected: All pointer is non-null.
2767 */
2768 ASSERT_NE(context_, nullptr);
2769 context_->SetupRootElement();
2770 auto frontend = AceType::MakeRefPtr<MockFrontend>();
2771 auto& windowConfig = frontend->GetWindowConfig();
2772 windowConfig.designWidth = DEFAULT_INT1;
2773 context_->weakFrontend_ = frontend;
2774 context_->SetTextFieldManager(AceType::MakeRefPtr<TextFieldManagerNG>());
2775
2776 /**
2777 * @tc.steps2: Set EnableAvoidKeyboardMode is true.
2778 * @tc.expected: get KeyboardSafeAreaEnabled is true.
2779 */
2780 context_->SetEnableKeyBoardAvoidMode(true);
2781 EXPECT_TRUE(context_->GetSafeAreaManager()->KeyboardSafeAreaEnabled());
2782
2783 /**
2784 * @tc.steps3: set root height and change virtual keyboard height.
2785 * @tc.expected: Resize the root height after virtual keyboard change.
2786 */
2787
2788 auto containerNode = AceType::DynamicCast<FrameNode>(context_->GetRootElement()->GetChildren().front());
2789 ASSERT_NE(containerNode, nullptr);
2790 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
2791 ASSERT_NE(containerPattern, nullptr);
2792 auto columNode = AceType::DynamicCast<FrameNode>(containerNode->GetChildren().front());
2793 CHECK_NULL_VOID(columNode);
2794
2795 std::vector<std::vector<int>> params = { { 100, 400, 100 }, { 300, 100, 300 }, { 400, -300, 400 },
2796 { 200, 0, 200 } };
2797 for (int turn = 0; turn < params.size(); turn++) {
2798 context_->rootHeight_ = params[turn][0];
2799 context_->OnVirtualKeyboardHeightChange(params[turn][1]);
2800 EXPECT_EQ(context_->GetRootHeight(), params[turn][2]);
2801 }
2802 }
2803 /**
2804 * @tc.name: PipelineContextTestNg061
2805 * @tc.desc: Test the function WindowUnFocus.
2806 * @tc.type: FUNC
2807 */
2808 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg061, TestSize.Level1)
2809 {
2810 /**
2811 * @tc.steps1: initialize parameters.
2812 * @tc.expected: All pointer is non-null.
2813 */
2814 ASSERT_NE(context_, nullptr);
2815 context_->SetupRootElement();
2816 ASSERT_NE(context_->rootNode_, nullptr);
2817 auto containerNode = AceType::DynamicCast<FrameNode>(context_->rootNode_->GetChildren().front());
2818 auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
2819
2820 /**
2821 * @tc.steps3: Call the function WindowUnFocus with WindowFocus(true).
2822 * @tc.expected: containerPattern isFocus_ is true.
2823 */
2824 containerPattern->isFocus_ = true;
2825 containerPattern->OnWindowForceUnfocused();
2826 EXPECT_TRUE(containerPattern->isFocus_);
2827
2828 /**
2829 * @tc.steps2: Call the function WindowUnFocus with WindowFocus(false).
2830 * @tc.expected: containerPattern isFocus_ is false.
2831 */
2832 containerPattern->WindowFocus(false);
2833 containerPattern->OnWindowForceUnfocused();
2834 EXPECT_FALSE(containerPattern->isFocus_);
2835 }
2836
2837 /**
2838 * @tc.name: PipelineContextTestNg062
2839 * @tc.desc: Test the function SetCursor.
2840 * @tc.type: FUNC
2841 */
2842 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg062, TestSize.Level1)
2843 {
2844 /**
2845 * @tc.steps1: initialize parameters.
2846 * @tc.expected: All pointer is non-null.
2847 */
2848 ASSERT_NE(context_, nullptr);
2849 ASSERT_NE(context_->GetWindow(), nullptr);
2850 ASSERT_EQ(context_->GetWindow()->cursor_, MouseFormat::DEFAULT);
2851
2852 /**
2853 * @tc.steps2: set cursor with an exceptional value.
2854 * @tc.expected: context_->cursor_ is MouseFormat::DEFAULT.
2855 */
2856 context_->SetCursor(EXCEPTIONAL_CURSOR);
2857 ASSERT_NE(context_->GetWindow(), nullptr);
2858 ASSERT_EQ(context_->GetWindow()->cursor_, MouseFormat::DEFAULT);
2859
2860 /**
2861 * @tc.steps3: set cursor with a normal value.
2862 * @tc.expected: context_->cursor_ is correct value.
2863 */
2864 context_->SetCursor(static_cast<int32_t>(MouseFormat::EAST));
2865 ASSERT_NE(context_->GetWindow(), nullptr);
2866 ASSERT_EQ(context_->GetWindow()->cursor_, MouseFormat::EAST);
2867
2868 /**
2869 * @tc.steps4: restore mouse style.
2870 * @tc.expected: context_->cursor_ is MouseFormat::DEFAULT.
2871 */
2872 context_->RestoreDefault();
2873 ASSERT_NE(context_->GetWindow(), nullptr);
2874 ASSERT_EQ(context_->GetWindow()->cursor_, MouseFormat::DEFAULT);
2875 }
2876
2877 /**
2878 * @tc.name: PipelineContextTestNg063
2879 * @tc.desc: Test the function OpenFrontendAnimation and CloseFrontendAnimation.
2880 * @tc.type: FUNC
2881 */
2882 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg063, TestSize.Level1)
2883 {
2884 decltype(context_->pendingFrontendAnimation_) temp;
2885 std::swap(context_->pendingFrontendAnimation_, temp);
2886 /**
2887 * @tc.steps1: Call CloseFrontAnimation directly.
2888 * @tc.expected: No animation is generated. The pending flag stack is empty.
2889 */
2890 context_->CloseFrontendAnimation();
2891 EXPECT_EQ(context_->pendingFrontendAnimation_.size(), 0);
2892 /**
2893 * @tc.steps2: Call OpenFrontendAnimation.
2894 * @tc.expected: A pending flag is pushed to the stack.
2895 */
2896 AnimationOption option(Curves::EASE, 1000);
2897 context_->OpenFrontendAnimation(option, option.GetCurve(), nullptr);
2898 EXPECT_EQ(context_->pendingFrontendAnimation_.size(), 1);
2899 /**
2900 * @tc.steps3: Call CloseFrontendAnimation after OpenFrontendAnimation.
2901 * @tc.expected: The pending flag is out of stack.
2902 */
2903 context_->CloseFrontendAnimation();
2904 EXPECT_EQ(context_->pendingFrontendAnimation_.size(), 0);
2905 }
2906
2907 /**
2908 * @tc.name: PipelineContextTestNg064
2909 * @tc.desc: Test history and current.
2910 * @tc.type: FUNC
2911 */
2912 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg064, TestSize.Level1)
2913 {
2914 /**
2915 * @tc.steps1: history and current timestamps are equal to nanoTimeStamp
2916 * @tc.expected: Expect the result to be (0.0, 0.0)
2917 */
2918 std::tuple<float, float, uint64_t> history_fs = std::make_tuple(1.0f, 1.0f, 1000);
2919 std::tuple<float, float, uint64_t> current_fs = std::make_tuple(2.0f, 2.0f, 2000);
2920 uint64_t nanoTimeStampFs = 1000;
2921 auto result_fs = context_->LinearInterpolation(history_fs, current_fs, nanoTimeStampFs);
2922 EXPECT_EQ(result_fs, std::make_pair(0.0f, 0.0f));
2923
2924 /**
2925 * @tc.steps2: history and current timestamps are equal to nanoTimeStamp
2926 * @tc.expected: Expect the result to be (0.0, 0.0)
2927 */
2928 std::tuple<float, float, uint64_t> history_se = std::make_tuple(1.0f, 1.0f, 2000);
2929 std::tuple<float, float, uint64_t> current_se = std::make_tuple(2.0f, 2.0f, 1000);
2930 uint64_t nanoTimeStampSe = 1500;
2931 auto result_se = context_->LinearInterpolation(history_se, current_se, nanoTimeStampSe);
2932 EXPECT_EQ(result_se, std::make_pair(0.0f, 0.0f));
2933
2934 /**
2935 * @tc.steps3: history and current timestamps are equal to nanoTimeStamp
2936 * @tc.expected: Expect the result to be (1.75, 1.75)
2937 */
2938 std::tuple<float, float, uint64_t> history_th = std::make_tuple(1.0f, 1.0f, 1000);
2939 std::tuple<float, float, uint64_t> current_th = std::make_tuple(2.0f, 2.0f, 3000);
2940 uint64_t nanoTimeStampTh = 2500;
2941 auto result_th = context_->LinearInterpolation(history_th, current_th, nanoTimeStampTh);
2942 EXPECT_EQ(result_th, std::make_pair(1.75f, 1.75f));
2943
2944 /**
2945 * @tc.steps4: nanoTimeStamp is less than history timestamp
2946 * @tc.expected: Expect the result to be (0.0, 0.0)
2947 */
2948 std::tuple<float, float, uint64_t> history_for = std::make_tuple(1.0f, 1.0f, 1000);
2949 std::tuple<float, float, uint64_t> current_for = std::make_tuple(2.0f, 2.0f, 2000);
2950 uint64_t nanoTimeStampFor = 500;
2951 auto result_for = context_->LinearInterpolation(history_for, current_for, nanoTimeStampFor);
2952 EXPECT_EQ(result_for, std::make_pair(0.0f, 0.0f));
2953
2954 /**
2955 * @tc.steps5: nanoTimeStamp is less than current timestamp
2956 * @tc.expected: Expect non-zero value
2957 */
2958 std::tuple<float, float, uint64_t> history_fie = std::make_tuple(1.0f, 1.0f, 1000);
2959 std::tuple<float, float, uint64_t> current_fie = std::make_tuple(2.0f, 2.0f, 2000);
2960 uint64_t nanoTimeStampFie = 1500;
2961 auto result_fie = context_->LinearInterpolation(history_fie, current_fie, nanoTimeStampFie);
2962 EXPECT_NE(result_fie, std::make_pair(0.0f, 0.0f));
2963
2964 /**
2965 * @tc.steps6: nanoTimeStamp is greater than current timestamp
2966 * @tc.expected: Expect non-zero value
2967 */
2968 std::tuple<float, float, uint64_t> history_six = std::make_tuple(1.0f, 1.0f, 1000);
2969 std::tuple<float, float, uint64_t> current_six = std::make_tuple(2.0f, 2.0f, 2000);
2970 uint64_t nanoTimeStampSix = 2500;
2971 auto result_six = context_->LinearInterpolation(history_six, current_six, nanoTimeStampSix);
2972 EXPECT_NE(result_six, std::make_pair(0.0f, 0.0f));
2973 }
2974
2975 /**
2976 * @tc.name: PipelineContextTestNg065
2977 * @tc.desc: Test history and current.
2978 * @tc.type: FUNC
2979 */
2980 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg065, TestSize.Level1)
2981 {
2982 std::vector<TouchEvent> emptyHistory;
2983 std::vector<TouchEvent> emptyCurrent;
2984 uint64_t nanoTimeStamp = 1234567890;
2985 bool isScreen = true;
2986 std::pair<float, float> result = context_->GetResampleCoord(emptyHistory, emptyCurrent, nanoTimeStamp, isScreen);
2987 EXPECT_FLOAT_EQ(0.0f, result.first);
2988 EXPECT_FLOAT_EQ(0.0f, result.second);
2989 }
2990
2991 /**
2992 * @tc.name: PipelineContextTestNg066
2993 * @tc.desc: Test history and current.
2994 * @tc.type: FUNC
2995 */
2996 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg066, TestSize.Level1)
2997 {
2998 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000));
2999 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000));
3000 auto timeStampThree = TimeStamp(std::chrono::nanoseconds(3000));
3001 auto timeStampFour = TimeStamp(std::chrono::nanoseconds(4000));
3002 std::vector<TouchEvent> history;
3003 history.push_back(TouchEvent { .x = 100.0f, .y = 200.0f, .time = timeStampAce });
3004 history.push_back(TouchEvent { .x = 150.0f, .y = 250.0f, .time = timeStampTwo });
3005 std::vector<TouchEvent> current;
3006 current.push_back(TouchEvent { .x = 200.0f, .y = 300.0f, .time = timeStampThree });
3007 current.push_back(TouchEvent { .x = 250.0f, .y = 350.0f, .time = timeStampFour });
3008
3009 auto resampledCoord = context_->GetResampleCoord(history, current, 2500, true);
3010
3011 ASSERT_FLOAT_EQ(0.0f, std::get<0>(resampledCoord));
3012 ASSERT_FLOAT_EQ(0.0f, std::get<1>(resampledCoord));
3013 }
3014
3015 /**
3016 * @tc.name: PipelineContextTestNg067
3017 * @tc.desc: Test history and current.
3018 * @tc.type: FUNC
3019 */
3020 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg067, TestSize.Level1)
3021 {
3022 std::vector<TouchEvent> history;
3023 std::vector<TouchEvent> current;
3024
3025 auto resampledCoord = context_->GetResampleCoord(history, current, 2500, true);
3026
3027 ASSERT_FLOAT_EQ(0.0f, std::get<0>(resampledCoord));
3028 ASSERT_FLOAT_EQ(0.0f, std::get<1>(resampledCoord));
3029 }
3030
3031 /**
3032 * @tc.name: PipelineContextTestNg068
3033 * @tc.desc: Test history and current.
3034 * @tc.type: FUNC
3035 */
3036 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg068, TestSize.Level1)
3037 {
3038 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000));
3039 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000));
3040 std::vector<TouchEvent> current;
3041 current.push_back(TouchEvent { .x = 100.0f, .y = 200.0f, .time = timeStampAce });
3042 current.push_back(TouchEvent { .x = 150.0f, .y = 250.0f, .time = timeStampTwo });
3043 uint64_t nanoTimeStamp = 1500;
3044
3045 TouchEvent latestPoint = context_->GetLatestPoint(current, nanoTimeStamp);
3046
3047 ASSERT_FLOAT_EQ(100.0f, latestPoint.x);
3048 ASSERT_FLOAT_EQ(200.0f, latestPoint.y);
3049 }
3050
3051 /**
3052 * @tc.name: PipelineContextTestNg069
3053 * @tc.desc: Test history and current.
3054 * @tc.type: FUNC
3055 */
3056 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg069, TestSize.Level1)
3057 {
3058 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000));
3059 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000));
3060 auto timeStampThree = TimeStamp(std::chrono::nanoseconds(3000));
3061 auto timeStampFour = TimeStamp(std::chrono::nanoseconds(4000));
3062 std::vector<TouchEvent> history;
3063 history.push_back(TouchEvent { .x = 100.0f, .y = 200.0f, .time = timeStampAce });
3064 history.push_back(TouchEvent { .x = 150.0f, .y = 250.0f, .time = timeStampTwo });
3065 std::vector<TouchEvent> current;
3066 current.push_back(TouchEvent { .x = 200.0f, .y = 300.0f, .time = timeStampThree });
3067 current.push_back(TouchEvent { .x = 250.0f, .y = 350.0f, .time = timeStampFour });
3068 uint64_t nanoTimeStamp = 2500;
3069
3070 TouchEvent resampledTouchEvent = context_->GetResampleTouchEvent(history, current, nanoTimeStamp);
3071
3072 ASSERT_FLOAT_EQ(175.0f, resampledTouchEvent.x);
3073 ASSERT_FLOAT_EQ(275.0f, resampledTouchEvent.y);
3074 }
3075
3076 /**
3077 * @tc.name: PipelineContextTestNg070
3078 * @tc.desc: Test GetLatestPoint.
3079 * @tc.type: FUNC
3080 */
3081 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg070, TestSize.Level1)
3082 {
3083 std::vector<TouchEvent> events;
3084
3085 TouchEvent event;
3086 event.time = TimeStamp(std::chrono::nanoseconds(1000));
3087 events.push_back(event);
3088
3089 TouchEvent result = context_->GetLatestPoint(events, 1000);
3090 ASSERT_EQ(static_cast<uint64_t>(result.time.time_since_epoch().count()), 1000);
3091 }
3092
3093 /**
3094 * @tc.name: PipelineContextTestNg071
3095 * @tc.desc: Test GetLatestPoint.
3096 * @tc.type: FUNC
3097 */
3098 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg071, TestSize.Level1)
3099 {
3100 std::vector<TouchEvent> events;
3101
3102 TouchEvent eventAce;
3103 eventAce.time = TimeStamp(std::chrono::nanoseconds(2000));
3104 events.push_back(eventAce);
3105
3106 TouchEvent eventTwo;
3107 eventTwo.time = TimeStamp(std::chrono::nanoseconds(3000));
3108 events.push_back(eventTwo);
3109
3110 uint64_t nanoTimeStamp = 1500;
3111
3112 TouchEvent result = context_->GetLatestPoint(events, nanoTimeStamp);
3113 ASSERT_GT(static_cast<uint64_t>(result.time.time_since_epoch().count()), nanoTimeStamp);
3114 }
3115
3116 /**
3117 * @tc.name: PipelineContextTestNg072
3118 * @tc.desc: Test GetLatestPoint.
3119 * @tc.type: FUNC
3120 */
3121 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg072, TestSize.Level1)
3122 {
3123 std::vector<TouchEvent> events;
3124
3125 TouchEvent eventAce;
3126 eventAce.time = TimeStamp(std::chrono::nanoseconds(500));
3127 events.push_back(eventAce);
3128
3129 TouchEvent eventTwo;
3130 eventTwo.time = TimeStamp(std::chrono::nanoseconds(1000));
3131 events.push_back(eventTwo);
3132
3133 uint64_t nanoTimeStamp = 1500;
3134
3135 TouchEvent result = context_->GetLatestPoint(events, nanoTimeStamp);
3136 ASSERT_LT(static_cast<uint64_t>(result.time.time_since_epoch().count()), nanoTimeStamp);
3137 }
3138 } // namespace NG
3139 } // namespace OHOS::Ace
3140