diff --git a/test/mock/core/common/mock_container.h b/test/mock/core/common/mock_container.h index cb3428f8252..7219ef798c5 100644 --- a/test/mock/core/common/mock_container.h +++ b/test/mock/core/common/mock_container.h @@ -43,6 +43,36 @@ public: static RefPtr Current(); static RefPtr GetContainer(int32_t containerId); + void SetIsFormRender(bool isFormRender) override + { + isFormRender_ = isFormRender; + } + + bool IsFormRender() const override + { + return isFormRender_; + } + + bool IsUIExtensionWindow() override + { + return isUIExtensionWindow_; + } + + void SetIsUIExtensionWindow(bool isUIExtensionWindow) + { + isUIExtensionWindow_ = isUIExtensionWindow; + } + + bool IsScenceBoardWindow() override + { + return isScenceBoardWindow_; + } + + void SetIsScenceBoardWindow(bool isScenceBoardWindow) + { + isScenceBoardWindow_ = isScenceBoardWindow; + } + MOCK_METHOD(void, Initialize, (), (override)); MOCK_METHOD(void, Destroy, (), (override)); MOCK_METHOD(int32_t, GetInstanceId, (), (const, override)); @@ -68,6 +98,9 @@ public: private: RefPtr taskExecutor_; RefPtr pipelineContext_; + bool isFormRender_ = false; + bool isUIExtensionWindow_ = false; + bool isScenceBoardWindow_ = false; }; } // namespace OHOS::Ace #endif // FOUNDATION_ACE_TEST_MOCK_CORE_COMMON_MOCK_CONTAINER_H diff --git a/test/unittest/core/pipeline/pipeline_context_test_ng.cpp b/test/unittest/core/pipeline/pipeline_context_test_ng.cpp index 0263532db38..16193f58834 100644 --- a/test/unittest/core/pipeline/pipeline_context_test_ng.cpp +++ b/test/unittest/core/pipeline/pipeline_context_test_ng.cpp @@ -753,29 +753,39 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg017, TestSize.Level1) manager->AddDragFrameNode(frameNode->GetId(), frameNode); /** - * @tc.steps2: Call the function OnDragEvent with isDragged_=true, currentId_=DEFAULT_INT1 and DRAG_EVENT_END. + * @tc.steps2: Call the function OnDragEvent with isDragged_=true, currentId_=DEFAULT_INT1 and + * DRAG_EVENT_START_FOR_CONTROLLER. * @tc.expected: The currentId_ is equal to DEFAULT_INT1. */ manager->isDragged_ = true; manager->currentId_ = DEFAULT_INT1; - context_->OnDragEvent({ DEFAULT_INT1, DEFAULT_INT1 }, DragEventAction::DRAG_EVENT_END); + context_->OnDragEvent({ DEFAULT_INT1, DEFAULT_INT1 }, DragEventAction::DRAG_EVENT_START_FOR_CONTROLLER); EXPECT_EQ(manager->currentId_, DEFAULT_INT1); /** - * @tc.steps2: Call the function OnDragEvent with isDragged_=true, currentId_=DEFAULT_INT1 and DRAG_EVENT_MOVE. + * @tc.steps2: Call the function OnDragEvent with isDragged_=true, currentId_=DEFAULT_INT1 and DRAG_EVENT_OUT. * @tc.expected: The currentId_ is equal to DEFAULT_INT1. */ manager->isDragged_ = true; manager->currentId_ = DEFAULT_INT1; - context_->OnDragEvent({ DEFAULT_INT1, DEFAULT_INT1 }, DragEventAction::DRAG_EVENT_MOVE); + context_->OnDragEvent({ DEFAULT_INT1, DEFAULT_INT1 }, DragEventAction::DRAG_EVENT_OUT); EXPECT_EQ(manager->currentId_, DEFAULT_INT1); /** - * @tc.steps3: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_END. + * @tc.steps3: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_START. * @tc.expected: The currentId_ is equal to DEFAULT_INT1. */ manager->isDragged_ = false; manager->currentId_ = DEFAULT_INT1; + context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_START); + EXPECT_EQ(manager->currentId_, DEFAULT_INT1); + + /** + * @tc.steps4: Call the function OnDragEvent with isDragged_=false, currentId_=DEFAULT_INT1 and DRAG_EVENT_END. + * @tc.expected: The currentId_ is changed to DEFAULT_INT10. + */ + manager->isDragged_ = false; + manager->currentId_ = DEFAULT_INT1; context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_END); EXPECT_EQ(manager->currentId_, DEFAULT_INT1); @@ -787,6 +797,8 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg017, TestSize.Level1) manager->currentId_ = DEFAULT_INT1; context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_MOVE); EXPECT_EQ(manager->currentId_, DEFAULT_INT1); + MockContainer::Current()->SetIsScenceBoardWindow(true); + context_->OnDragEvent({ DEFAULT_INT10, DEFAULT_INT10 }, DragEventAction::DRAG_EVENT_MOVE); context_->SetIsDragging(false); EXPECT_FALSE(context_->IsDragging()); context_->ResetDragging(); @@ -1238,7 +1250,8 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg025, TestSize.Level1) { "-multimodal" }, { "-rotation", "1", "2", "3" }, { "-animationscale", "1", "2", "3" }, { "-velocityscale", "1", "2", "3" }, { "-scrollfriction", "1", "2", "3" }, { "-threadstuck", "1", "2", "3" }, { "-rotation" }, { "-animationscale" }, { "-velocityscale" }, { "-scrollfriction" }, { "-threadstuck" }, - { "test" } }; + { "test" }, { "-navigation" }, { "-focuswindowscene" }, { "-focusmanager" }, { "-jsdump" }, { "-event" }, + { "-imagecache" }, { "-imagefilecache" }, { "-allelements" }, { "-default" }, { "-overlay" }, { "--stylus" } }; int turn = 0; for (; turn < params.size(); turn++) { EXPECT_TRUE(context_->OnDumpInfo(params[turn])); @@ -1926,6 +1939,8 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg092, TestSize.Level1) ASSERT_NE(context_, nullptr); std::vector rects; context_->TriggerOverlayNodePositionsUpdateCallback(rects); + context_->RegisterOverlayNodePositionsUpdateCallback([](std::vector rect) {}); + context_->TriggerOverlayNodePositionsUpdateCallback(rects); context_->windowManager_ = AceType::MakeRefPtr(); context_->windowModal_ = WindowModal::NORMAL; NG::RectF containerModal; @@ -1952,12 +1967,17 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg093, TestSize.Level1) * @tc.expected: All pointer is non-null. */ ASSERT_NE(context_, nullptr); + ASSERT_NE(context_->GetWindow(), nullptr); EXPECT_FALSE(context_->PrintVsyncInfoIfNeed()); - std::list dumpFrameInfos_; + std::list dumpFrameInfos; FrameInfo frameInfo; - dumpFrameInfos_.push_back(frameInfo); + dumpFrameInfos.push_back(frameInfo); + context_->dumpFrameInfos_ = dumpFrameInfos; EXPECT_FALSE(context_->PrintVsyncInfoIfNeed()); + context_->dumpFrameInfos_.back().frameRecvTime_ = -1; + EXPECT_FALSE(context_->PrintVsyncInfoIfNeed()); + context_->dumpFrameInfos_.clear(); } /** @@ -1974,6 +1994,20 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg094, TestSize.Level1) ASSERT_NE(context_, nullptr); context_->windowManager_ = AceType::MakeRefPtr(); + SystemProperties::SetColorMode(ColorMode::DARK); + context_->SetAppBgColor(Color::BLACK); + context_->ChangeDarkModeBrightness(); + context_->SetIsJsCard(true); + context_->ChangeDarkModeBrightness(); + MockContainer::Current()->SetIsFormRender(true); + context_->ChangeDarkModeBrightness(); + MockContainer::Current()->SetIsDynamicRender(true); + context_->ChangeDarkModeBrightness(); + MockContainer::Current()->SetIsUIExtensionWindow(true); + context_->ChangeDarkModeBrightness(); + context_->SetAppBgColor(Color::BLUE); + context_->ChangeDarkModeBrightness(); + SystemProperties::SetColorMode(ColorMode::COLOR_MODE_UNDEFINED); context_->ChangeDarkModeBrightness(); EXPECT_NE(context_->stageManager_, nullptr); } diff --git a/test/unittest/core/pipeline/pipeline_context_test_ng_new.cpp b/test/unittest/core/pipeline/pipeline_context_test_ng_new.cpp index ef366787eec..f0d2236e656 100644 --- a/test/unittest/core/pipeline/pipeline_context_test_ng_new.cpp +++ b/test/unittest/core/pipeline/pipeline_context_test_ng_new.cpp @@ -1354,8 +1354,11 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg076, TestSize.Level1) pipeline->foldStatusChangedCallbackMap_.emplace(2, nullptr); pipeline->foldDisplayModeChangedCallbackMap_.emplace(1, [](FoldDisplayMode foldDisplayMode) {}); pipeline->foldDisplayModeChangedCallbackMap_.emplace(2, nullptr); + pipeline->transformHintChangedCallbackMap_.emplace(1, nullptr); + pipeline->transformHintChangedCallbackMap_.emplace(2, [](uint32_t num) {}); pipeline->OnFoldStatusChange(FoldStatus::EXPAND); pipeline->OnFoldDisplayModeChange(FoldDisplayMode::FULL); + pipeline->OnTransformHintChanged(0); EXPECT_NE(PipelineContext::GetContextByContainerId(0), nullptr); pipeline->AddDirtyPropertyNode(frameNode); EXPECT_TRUE(pipeline->hasIdleTasks_); @@ -1446,18 +1449,19 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg078, TestSize.Level1) */ auto formCallback = [](bool visible) {}; pipeline->ContainerModalUnFocus(); - pipeline->UpdateTitleInTargetPos(false, 0); - pipeline->SetCloseButtonStatus(false); - pipeline->SetContainerModalTitleVisible(false, true); + pipeline->windowModal_ = WindowModal::NORMAL; pipeline->SetContainerModalTitleHeight(0); + pipeline->UpdateTitleInTargetPos(false, 0); + pipeline->SetContainerModalTitleVisible(false, true); + pipeline->SetCloseButtonStatus(false); pipeline->GetContainerModalTitleHeight(); pipeline->windowModal_ = WindowModal::CONTAINER_MODAL; + pipeline->GetContainerModalTitleHeight(); pipeline->ContainerModalUnFocus(); pipeline->UpdateTitleInTargetPos(false, 0); pipeline->SetCloseButtonStatus(true); pipeline->SetContainerModalTitleVisible(true, false); pipeline->SetContainerModalTitleHeight(0); - pipeline->GetContainerModalTitleHeight(); pipeline->SetAppBgColor(Color::BLACK); auto frameNode1 = FrameNode::GetOrCreateFrameNode("test", 6, nullptr); pipeline->activeNode_ = AceType::WeakClaim(AceType::RawPtr(frameNode1)); @@ -1716,7 +1720,7 @@ HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg009, TestSize.Level1) taskScheduler.FlushPersistAfterLayoutTask(); taskScheduler.FlushAfterRenderTask(); taskScheduler.FlushAfterLayoutCallbackInImplicitAnimationTask(); - + /** * @tc.steps3: Call FlushAfterLayoutCallbackInImplicitAnimationTask/FlushTask */ @@ -1778,5 +1782,45 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg097, TestSize.Level1) context_->RegisterTouchEventListener(touchEventCallback); ASSERT_EQ(context_->listenerVector_.size(), 0); } + +/** + * @tc.name: PipelineContextTestNg098 + * @tc.desc: Test the function AddChangedFrameNode + * @tc.type: FUNC + */ +HWTEST_F(PipelineContextTestNg, PipelineContextTestNg098, TestSize.Level1) +{ + /** + * @tc.steps1: AddChangedFrameNode + */ + auto frameNode = AceType::MakeRefPtr("test1", -1, AceType::MakeRefPtr(), false); + context_->AddChangedFrameNode(frameNode); + EXPECT_EQ(context_->changedNodes_.size(), 1); + context_->AddChangedFrameNode(frameNode); + EXPECT_EQ(context_->changedNodes_.size(), 1); + context_->CleanNodeChangeFlag(); + EXPECT_EQ(context_->changedNodes_.size(), 0); +} + +/** + * @tc.name: PipelineContextTestNg099 + * @tc.desc: Test the function AddFrameNodeChangeListener + * @tc.type: FUNC + */ +HWTEST_F(PipelineContextTestNg, PipelineContextTestNg099, TestSize.Level1) +{ + /** + * @tc.steps1: AddFrameNodeChangeListener + */ + auto frameNode = AceType::MakeRefPtr("test1", -1, AceType::MakeRefPtr(), false); + context_->AddFrameNodeChangeListener(frameNode); + context_->FlushNodeChangeFlag(); + EXPECT_EQ(context_->changeInfoListeners_.size(), 1); + context_->AddFrameNodeChangeListener(frameNode); + EXPECT_EQ(context_->changeInfoListeners_.size(), 1); + context_->RemoveFrameNodeChangeListener(frameNode); + context_->FlushNodeChangeFlag(); + EXPECT_EQ(context_->changeInfoListeners_.size(), 0); +} } // namespace NG } // namespace OHOS::Ace