diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp index a6d632ea21cf308095b83b7d956e2fb14344cdb9..812c1bcee14e02ac8e9ce3b5d73bf4d75ef7547d 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp @@ -831,7 +831,7 @@ void XComponentPattern::UninitializeAccessibility(FrameNode* frameNode) auto accessibilityManager = pipeline->GetAccessibilityManager(); CHECK_NULL_VOID(accessibilityManager); if (accessibilityManager->IsRegister() && accessibilityChildTreeCallback_) { - accessibilityChildTreeCallback_->OnDeregister(); + OnAccessibilityChildTreeDeregister(frameNode); } accessibilityManager->DeregisterAccessibilityChildTreeCallback(accessibilityId); accessibilityChildTreeCallback_ = nullptr; @@ -886,13 +886,18 @@ bool XComponentPattern::OnAccessibilityChildTreeRegister(uint32_t windowId, int3 return accessibilityManager->RegisterInteractionOperationAsChildTree(registration); } -bool XComponentPattern::OnAccessibilityChildTreeDeregister() +bool XComponentPattern::OnAccessibilityChildTreeDeregister(FrameNode* frameNode) { TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "OnAccessibilityChildTreeDeregister, " "windowId: %{public}u, treeId: %{public}d.", windowId_, treeId_); - auto host = GetHost(); - CHECK_NULL_RETURN(host, false); - auto pipeline = host->GetContextRefPtr(); + RefPtr pipeline; + if (!frameNode) { + auto host = GetHost(); + CHECK_NULL_RETURN(host, false); + pipeline = host->GetContextRefPtr(); + } else { + pipeline = frameNode->GetContextRefPtr(); + } CHECK_NULL_RETURN(pipeline, false); auto accessibilityManager = pipeline->GetAccessibilityManager(); CHECK_NULL_RETURN(accessibilityManager, false); diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h index 54f5db001ccf3fa97265faa1c357fa4031f79a8a..d4e7931b5a4eeb57d9dbdfb94c348ef9ad6c4adf 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h @@ -323,7 +323,7 @@ public: void InitializeAccessibility(); void UninitializeAccessibility(FrameNode* frameNode); bool OnAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId); - bool OnAccessibilityChildTreeDeregister(); + bool OnAccessibilityChildTreeDeregister(FrameNode* frameNode = nullptr); void OnSetAccessibilityChildTree(int32_t childWindowId, int32_t childTreeId); void SetAccessibilityState(bool state) {} RefPtr GetAccessibilitySessionAdapter() override; diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp index 8c223437d2d0c49011e60a0d2c43de7b5fb33dbd..621a52bb70e59c5fd77dcaf4bd007f8bb3568fb2 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp @@ -2062,4 +2062,31 @@ HWTEST_F(XComponentTestTwoNg, InitNativeNodeCallbacksTest, TestSize.Level1) EXPECT_TRUE(pattern->nativeXComponentImpl_->attachNativeNodeCallback_); EXPECT_TRUE(pattern->nativeXComponentImpl_->detachNativeNodeCallback_); } + +/** + * @tc.name: OnAccessibilityChildTreeDeregisterTest001 + * @tc.desc: Test InitNativeNodeCallbacks Func + * @tc.type: FUNC + */ +HWTEST_F(XComponentTestTwoNg, OnAccessibilityChildTreeDeregisterTest001, TestSize.Level1) +{ + /** + * @tc.steps1: initialize parameters. + * @tc.expected: All pointer is non-null. + */ + g_testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE; + g_testProperty.libraryName = XCOMPONENT_LIBRARY_NAME; + auto frameNode = CreateXComponentNode(g_testProperty); + ASSERT_TRUE(frameNode); + auto pattern = frameNode->GetPattern(); + ASSERT_TRUE(pattern); + /** + * @tc.steps2: GetNativeProvider is null ptr + * @tc.expected: OnAccessibilityChildTreeDeregister return false + */ + auto result = pattern->OnAccessibilityChildTreeDeregister(AceType::RawPtr(frameNode)); + ASSERT_FALSE(result); + result = pattern->OnAccessibilityChildTreeDeregister(); + ASSERT_FALSE(result); +} } // namespace OHOS::Ace::NG