• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "gmock/gmock.h"
17 #include "gtest/gtest.h"
18 
19 #define private public
20 #define protected public
21 
22 #include "adapter/ohos/entrance/ace_container.h"
23 #include "base/log/dump_log.h"
24 #include "frameworks/core/accessibility/utils/accessibility_manager_utils.h"
25 #include "interfaces/inner_api/ace_kit/src/view/ui_context_impl.h"
26 
27 using namespace OHOS::Accessibility;
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS::Ace {
32 } // namespace OHOS::Ace
33 
34 namespace OHOS::Ace::NG {
35 namespace {
36 } // namespace
37 
38 
39 class AccessibilityManagerUtilsTest : public testing::Test {
40 public:
41     static void SetUpTestCase();
42     static void TearDownTestCase();
43 protected:
44     const int32_t CONTAINER_ID_1 = 100;
45     const int32_t CONTAINER_ID_2 = 200;
46     const int32_t PAGE_ID_1 = 1;
47     const int32_t PAGE_ID_2 = 2;
48 
49     AccessibilityEvent eventA_ { .nodeId = 1};
50     AccessibilityEvent eventB_ { .nodeId = 2};
51     AccessibilityEvent eventC_ { .nodeId = 3};
52 };
53 
SetUpTestCase()54 void AccessibilityManagerUtilsTest::SetUpTestCase()
55 {
56     std::unique_ptr<std::ostream> ostream = std::make_unique<std::ostringstream>();
57     ASSERT_NE(ostream, nullptr);
58     DumpLog::GetInstance().SetDumpFile(std::move(ostream));
59 }
60 
TearDownTestCase()61 void AccessibilityManagerUtilsTest::TearDownTestCase()
62 {
63 }
64 
65 /**
66  * @tc.name: AccessibilityManagerUtilsTest001
67  * @tc.desc: controller.Add
68  * @tc.type: FUNC
69  */
70 HWTEST_F(AccessibilityManagerUtilsTest, AccessibilityManagerUtilsTest001, TestSize.Level1)
71 {
72     /**
73      * @tc.steps: step1. construct JsAccessibilityManager
74      */
75     PageEventController controller;
76     auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
77     auto context = AceType::MakeRefPtr<NG::PipelineContext>();
78     CHECK_NULL_VOID(frameNode);
79     CHECK_NULL_VOID(context);
80     context->instanceId_ = 1;
81     frameNode->AttachContext(AceType::RawPtr(context), false);
82     /**
83     * @tc.steps: step2. add controller with instanceId 1.
84     * @tc.expected: Check instanceId 1 is not empty , other instanceId is empty.
85     */
86     controller.Add(frameNode);
87     EXPECT_FALSE(controller.CheckEmpty(1));
88     EXPECT_TRUE(controller.CheckEmpty(2));
89 }
90 
91 /**
92  * @tc.name: AccessibilityManagerUtilsTest002
93  * @tc.desc: AddMultipleNodes
94  * @tc.type: FUNC
95  */
96 HWTEST_F(AccessibilityManagerUtilsTest, AccessibilityManagerUtilsTest002, TestSize.Level1)
97 {
98     /**
99      * @tc.steps: step1. construct JsAccessibilityManager
100      */
101     PageEventController controller;
102     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
103     auto context1 = AceType::MakeRefPtr<NG::PipelineContext>();
104     CHECK_NULL_VOID(frameNode1);
105     CHECK_NULL_VOID(context1);
106     context1->instanceId_ = 1;
107     frameNode1->AttachContext(AceType::RawPtr(context1), false);
108 
109     auto frameNode2 = FrameNode::CreateFrameNode("framenode", 2, AceType::MakeRefPtr<Pattern>(), false);
110     auto context2 = AceType::MakeRefPtr<NG::PipelineContext>();
111     CHECK_NULL_VOID(frameNode2);
112     CHECK_NULL_VOID(context2);
113     context2->instanceId_ = 2;
114     frameNode2->AttachContext(AceType::RawPtr(context2), false);
115 
116     auto frameNode3 = FrameNode::CreateFrameNode("framenode", 3, AceType::MakeRefPtr<Pattern>(), false);
117     auto context3 = AceType::MakeRefPtr<NG::PipelineContext>();
118     CHECK_NULL_VOID(frameNode3);
119     CHECK_NULL_VOID(context3);
120     context3->instanceId_ = 3;
121     frameNode3->AttachContext(AceType::RawPtr(context3), false);
122 
123     /**
124     * @tc.steps: step2. add controller with three different node.
125     * @tc.expected: all node can be checked in controller.
126     */
127     controller.Add(frameNode1);
128     controller.Add(frameNode2);
129     controller.Add(frameNode3);
130     EXPECT_TRUE(controller.CheckNode(frameNode1, false));
131     EXPECT_TRUE(controller.CheckNode(frameNode2, false));
132     EXPECT_TRUE(controller.CheckNode(frameNode3, false));
133 }
134 
135 /**
136  * @tc.name: AccessibilityManagerUtilsTest003
137  * @tc.desc: CheckExistingNode
138  * @tc.type: FUNC
139  */
140 HWTEST_F(AccessibilityManagerUtilsTest, AccessibilityManagerUtilsTest003, TestSize.Level1)
141 {
142     /**
143      * @tc.steps: step1. construct JsAccessibilityManager
144      */
145     PageEventController controller;
146     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
147     auto context1 = AceType::MakeRefPtr<NG::PipelineContext>();
148     CHECK_NULL_VOID(frameNode1);
149     CHECK_NULL_VOID(context1);
150     context1->instanceId_ = 1;
151     frameNode1->AttachContext(AceType::RawPtr(context1), false);
152 
153     auto frameNode2 = FrameNode::CreateFrameNode("framenode", 2, AceType::MakeRefPtr<Pattern>(), false);
154     auto context2 = AceType::MakeRefPtr<NG::PipelineContext>();
155     CHECK_NULL_VOID(frameNode2);
156     CHECK_NULL_VOID(context2);
157     context2->instanceId_ = 2;
158     frameNode2->AttachContext(AceType::RawPtr(context2), false);
159 
160     /**
161     * @tc.steps: step2. add controller one node .
162     * @tc.expected: only added node can be checked in controller.
163     */
164     controller.Add(frameNode1);
165     EXPECT_TRUE(controller.CheckNode(frameNode1, false));
166     EXPECT_FALSE(controller.CheckNode(frameNode2, false));
167 }
168 
169 
170 /**
171  * @tc.name: AccessibilityManagerUtilsTest004
172  * @tc.desc: DeleteNodeOnCheck
173  * @tc.type: FUNC
174  */
175 HWTEST_F(AccessibilityManagerUtilsTest, AccessibilityManagerUtilsTest004, TestSize.Level1)
176 {
177     /**
178      * @tc.steps: step1. construct JsAccessibilityManager
179      */
180     PageEventController controller;
181     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
182     auto context1 = AceType::MakeRefPtr<NG::PipelineContext>();
183     CHECK_NULL_VOID(frameNode1);
184     CHECK_NULL_VOID(context1);
185     context1->instanceId_ = 1;
186     frameNode1->AttachContext(AceType::RawPtr(context1), false);
187 
188     /**
189     * @tc.steps: step2. add controller one node and check node with delete process .
190     * @tc.expected: the first time can be checked and turns to empty after checking process.
191     */
192     controller.Add(frameNode1);
193     EXPECT_TRUE(controller.CheckNode(frameNode1, true));
194     EXPECT_FALSE(controller.CheckNode(frameNode1, false));
195     EXPECT_TRUE(controller.CheckEmpty(1));
196 }
197 
198 /**
199  * @tc.name: AccessibilityManagerUtilsTest005
200  * @tc.desc: UpdateClearsInvalidNodes
201  * @tc.type: FUNC
202  */
203 HWTEST_F(AccessibilityManagerUtilsTest, AccessibilityManagerUtilsTest005, TestSize.Level1)
204 {
205     /**
206      * @tc.steps: step1. construct JsAccessibilityManager
207      */
208     PageEventController controller;
209 
210     {
211         auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
212         auto context1 = AceType::MakeRefPtr<NG::PipelineContext>();
213         CHECK_NULL_VOID(frameNode1);
214         CHECK_NULL_VOID(context1);
215         context1->instanceId_ = 1;
216         frameNode1->AttachContext(AceType::RawPtr(context1), false);
217         controller.Add(frameNode1);
218     }
219 
220     /**
221     * @tc.steps: step2. update and check node  when node is null.
222     * @tc.expected: update can delete null node and  controller will be empty.
223     */
224     controller.Update();
225     EXPECT_TRUE(controller.CheckEmpty(3));
226 }
227 
228 /**
229  * @tc.name: AccessibilityManagerUtilsTest006
230  * @tc.desc: UpdateKeepsValidNodes
231  * @tc.type: FUNC
232  */
233 HWTEST_F(AccessibilityManagerUtilsTest, AccessibilityManagerUtilsTest006, TestSize.Level1)
234 {
235     /**
236      * @tc.steps: step1. construct JsAccessibilityManager
237      */
238     PageEventController controller;
239     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
240     auto context1 = AceType::MakeRefPtr<NG::PipelineContext>();
241     CHECK_NULL_VOID(frameNode1);
242     CHECK_NULL_VOID(context1);
243     context1->instanceId_ = 1;
244     frameNode1->AttachContext(AceType::RawPtr(context1), false);
245 
246     /**
247     * @tc.steps: step2. update and check node  when node is Valid.
248     * @tc.expected: update will not delete null node and  controller is not empty.
249     */
250     controller.Add(frameNode1);
251     controller.Update();
252     EXPECT_TRUE(controller.CheckNode(frameNode1, false));
253 }
254 
255 /**
256  * @tc.name: AccessibilityManagerUtilsTest007
257  * @tc.desc: CheckEmptyForNonExistingContainer
258  * @tc.type: FUNC
259  */
260 HWTEST_F(AccessibilityManagerUtilsTest, AccessibilityManagerUtilsTest007, TestSize.Level1)
261 {
262     /**
263      * @tc.steps: step1. construct JsAccessibilityManager
264      */
265     PageEventController controller;
266     /**
267     * @tc.steps: step2. controller keeps empty when containerId is large.
268     * @tc.expected: controller keeps empty.
269     */
270     EXPECT_TRUE(controller.CheckEmpty(999));
271 }
272 
273 /**
274  * @tc.name: AccessibilityManagerUtilsTest008
275  * @tc.desc: MultipleContainerManagement
276  * @tc.type: FUNC
277  */
278 HWTEST_F(AccessibilityManagerUtilsTest, AccessibilityManagerUtilsTest008, TestSize.Level1)
279 {
280     /**
281      * @tc.steps: step1. construct JsAccessibilityManager
282      */
283     PageEventController controller;
284     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
285     auto context1 = AceType::MakeRefPtr<NG::PipelineContext>();
286     CHECK_NULL_VOID(frameNode1);
287     CHECK_NULL_VOID(context1);
288     context1->instanceId_ = 1;
289     frameNode1->AttachContext(AceType::RawPtr(context1), false);
290 
291     auto frameNode2 = FrameNode::CreateFrameNode("framenode", 2, AceType::MakeRefPtr<Pattern>(), false);
292     auto context2 = AceType::MakeRefPtr<NG::PipelineContext>();
293     CHECK_NULL_VOID(frameNode2);
294     CHECK_NULL_VOID(context2);
295     context2->instanceId_ = 3;
296     frameNode2->AttachContext(AceType::RawPtr(context2), false);
297     /**
298     * @tc.steps: step2. add nodes with different containerID.
299     * @tc.expected: the correct containerID check will not be empty, wrong containerID will be empty.
300     */
301     controller.Add(frameNode1);
302     controller.Add(frameNode2);
303     EXPECT_FALSE(controller.CheckEmpty(1));
304     EXPECT_TRUE(controller.CheckEmpty(2));
305     EXPECT_FALSE(controller.CheckEmpty(3));
306 }
307 
308 /**
309  * @tc.name: AccessibilityManagerUtilsTest009
310  * @tc.desc: AddSameNodeMultipleTimes
311  * @tc.type: FUNC
312  */
313 HWTEST_F(AccessibilityManagerUtilsTest, AccessibilityManagerUtilsTest009, TestSize.Level1)
314 {
315     /**
316      * @tc.steps: step1. construct JsAccessibilityManager
317      */
318     PageEventController controller;
319     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
320     auto context1 = AceType::MakeRefPtr<NG::PipelineContext>();
321     CHECK_NULL_VOID(frameNode1);
322     CHECK_NULL_VOID(context1);
323     context1->instanceId_ = 1;
324     frameNode1->AttachContext(AceType::RawPtr(context1), false);
325 
326     /**
327     * @tc.steps: step2. add same node with multiple times.
328     * @tc.expected: Check instanceId 1 is not empty , other instanceId is empty.
329     */
330     controller.Add(frameNode1);
331     controller.Add(frameNode1);
332     EXPECT_TRUE(controller.CheckNode(frameNode1, true));
333     EXPECT_FALSE(controller.CheckNode(frameNode1, false));
334 }
335 
336 /**
337  * @tc.name: AccessibilityManagerUtilsTest010
338  * @tc.desc: CrossContainerOperations
339  * @tc.type: FUNC
340  */
341 HWTEST_F(AccessibilityManagerUtilsTest, AccessibilityManagerUtilsTest010, TestSize.Level1)
342 {
343     /**
344      * @tc.steps: step1. construct JsAccessibilityManager
345      */
346     PageEventController controller;
347     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
348     auto context1 = AceType::MakeRefPtr<NG::PipelineContext>();
349     CHECK_NULL_VOID(frameNode1);
350     CHECK_NULL_VOID(context1);
351     context1->instanceId_ = 1;
352     frameNode1->AttachContext(AceType::RawPtr(context1), false);
353     auto frameNode2 = FrameNode::CreateFrameNode("framenode", 2, AceType::MakeRefPtr<Pattern>(), false);
354     auto context2 = AceType::MakeRefPtr<NG::PipelineContext>();
355     CHECK_NULL_VOID(frameNode2);
356     CHECK_NULL_VOID(context2);
357     context2->instanceId_ = 2;
358     frameNode2->AttachContext(AceType::RawPtr(context2), false);
359     /**
360     * @tc.steps: step2. add controller with instanceId 1.
361     * @tc.expected: check node with delete process will delete nodes, next time check will be empty.
362     */
363     controller.Add(frameNode1);
364     controller.Add(frameNode2);
365     EXPECT_TRUE(controller.CheckNode(frameNode1, true));
366     EXPECT_TRUE(controller.CheckNode(frameNode2, false));
367 }
368 
369 /**
370  * @tc.name: AddToHoverTransparentCallbackList010
371  * @tc.desc: AddToHoverTransparentCallbackList
372  * @tc.type: FUNC
373  */
374 HWTEST_F(AccessibilityManagerUtilsTest, AddToHoverTransparentCallbackList010, TestSize.Level1)
375 {
376     /**
377      * @tc.steps: step1. construct HoverTransparentCallbackController.
378      */
379     HoverTransparentCallbackController controller;
380     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
381     auto context1 = AceType::MakeRefPtr<NG::PipelineContext>();
382     ASSERT_NE(frameNode1, nullptr);
383     ASSERT_NE(context1, nullptr);
384     context1->instanceId_ = 1;
385     frameNode1->AttachContext(AceType::RawPtr(context1), false);
386 
387     /**
388     * @tc.steps: step2. not add controller.
389     * @tc.expected: check controller_ is empty.
390     */
391     EXPECT_TRUE(controller.CheckHoverTransparentCallbackListEmpty(1));
392 
393     /**
394     * @tc.steps: step3. add controller with instanceId 1.
395     * @tc.expected: check IsInHoverTransparentCallbackList return true.
396     */
397     controller.AddToHoverTransparentCallbackList(frameNode1);
398     EXPECT_TRUE(controller.IsInHoverTransparentCallbackList(frameNode1));
399 
400     /**
401     * @tc.steps: step4. Call CheckHoverTransparentCallbackListEmpty function.
402     * @tc.expected: check CheckHoverTransparentCallbackListEmpty return false.
403     */
404     EXPECT_FALSE(controller.CheckHoverTransparentCallbackListEmpty(1));
405 }
406 
407 
408 /**
409  * @tc.name: PageEventControllerTest011
410  * @tc.desc: controller page event test basic event addition and existence checks
411  * @tc.type: FUNC
412  */
413 HWTEST_F(AccessibilityManagerUtilsTest, PageEventControllerTest011, TestSize.Level1)
414 {
415     PageEventController controller;
416     // Initial state should have no events
417     EXPECT_FALSE(controller.HasAnyAccessibilityEvent(CONTAINER_ID_1));
418     EXPECT_FALSE(controller.HasAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1));
419 
420     // Add event to container1/page1
421     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1, eventA_);
422 
423     // Verify existence
424     EXPECT_TRUE(controller.HasAnyAccessibilityEvent(CONTAINER_ID_1));
425     EXPECT_TRUE(controller.HasAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1));
426     EXPECT_FALSE(controller.HasAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_2)); // Different page
427 
428     // Add second event to container1/page2
429     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_2, eventB_);
430     EXPECT_TRUE(controller.HasAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_2));
431 }
432 
433 /**
434  * @tc.name: PageEventControllerTest012
435  * @tc.desc: controller page event Test container isolation
436  * @tc.type: FUNC
437  */
438 HWTEST_F(AccessibilityManagerUtilsTest, PageEventControllerTest012, TestSize.Level1)
439 {
440     PageEventController controller;
441     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1, eventA_);
442     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1, eventB_);
443     controller.AddAccessibilityEvent(CONTAINER_ID_2, PAGE_ID_1, eventC_);
444 
445     // Verify container isolation
446     EXPECT_TRUE(controller.HasAnyAccessibilityEvent(CONTAINER_ID_1));
447     EXPECT_TRUE(controller.HasAnyAccessibilityEvent(CONTAINER_ID_2));
448     EXPECT_FALSE(controller.HasAnyAccessibilityEvent(999)); // Non-existent container
449 }
450 
451 /**
452  * @tc.name: PageEventControllerTest013
453  * @tc.desc: controller page event Test releasing events for a specific page
454  * @tc.type: FUNC
455  */
456 HWTEST_F(AccessibilityManagerUtilsTest, PageEventControllerTest013, TestSize.Level1)
457 {
458     PageEventController controller;
459     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1, eventA_);
460     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1, eventB_);
461     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_2, eventC_);
462 
463     std::list<std::pair<int32_t, AccessibilityEvent>> releasedEvents;
464 
465     // Release all events for page1
466     controller.ReleaseAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1, releasedEvents);
467 
468     // Verify released events
469     ASSERT_EQ(releasedEvents.size(), 2);
470     EXPECT_EQ(releasedEvents.front().first, PAGE_ID_1);
471     EXPECT_EQ(releasedEvents.front().second.nodeId, eventA_.nodeId);
472     releasedEvents.pop_front();
473     EXPECT_EQ(releasedEvents.front().second.nodeId, eventB_.nodeId);
474 
475     // Verify container state
476     EXPECT_TRUE(controller.HasAnyAccessibilityEvent(CONTAINER_ID_1)); // page2 still has events
477     EXPECT_FALSE(controller.HasAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1));
478     EXPECT_TRUE(controller.HasAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_2));
479 }
480 
481 /**
482  * @tc.name: PageEventControllerTest014
483  * @tc.desc: controller page event Test releasing all events for a container
484  * @tc.type: FUNC
485  */
486 HWTEST_F(AccessibilityManagerUtilsTest, PageEventControllerTest014, TestSize.Level1)
487 {
488     PageEventController controller;
489     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1, eventA_);
490     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_2, eventB_);
491     controller.AddAccessibilityEvent(CONTAINER_ID_2, PAGE_ID_1, eventC_);
492 
493     std::list<std::pair<int32_t, AccessibilityEvent>> releasedEvents;
494 
495     // Release entire container1
496     controller.ReleaseAllAccessibilityEvent(CONTAINER_ID_1, releasedEvents);
497 
498     // Verify released events
499     ASSERT_EQ(releasedEvents.size(), 2);
500     auto it = releasedEvents.begin();
501     EXPECT_EQ(it->first, PAGE_ID_1);
502     EXPECT_EQ(it->second.nodeId, eventA_.nodeId);
503     ++it;
504     EXPECT_EQ(it->first, PAGE_ID_2);
505     EXPECT_EQ(it->second.nodeId, eventB_.nodeId);
506 
507     // Verify container state
508     EXPECT_FALSE(controller.HasAnyAccessibilityEvent(CONTAINER_ID_1));
509     EXPECT_TRUE(controller.HasAnyAccessibilityEvent(CONTAINER_ID_2)); // Other container should remain
510 }
511 
512 /**
513  * @tc.name: PageEventControllerTest015
514  * @tc.desc: controller page event Test edge cases and invalid operations
515  * @tc.type: FUNC
516  */
517 HWTEST_F(AccessibilityManagerUtilsTest, PageEventControllerTest015, TestSize.Level1)
518 {
519     PageEventController controller;
520     std::list<std::pair<int32_t, AccessibilityEvent>> releasedEvents;
521 
522     // Release non-existent container
523     controller.ReleaseAccessibilityEvent(999, 1, releasedEvents);
524     EXPECT_TRUE(releasedEvents.empty());
525 
526     // Release non-existent page in existing container
527     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1, eventA_);
528     controller.ReleaseAccessibilityEvent(CONTAINER_ID_1, 999, releasedEvents); // Non-existent page
529     EXPECT_TRUE(releasedEvents.empty()); // Should release nothing
530     EXPECT_TRUE(controller.HasAnyAccessibilityEvent(CONTAINER_ID_1));
531 
532     // Test automatic container cleanup
533     controller.AddAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1, eventA_);
534     controller.ReleaseAccessibilityEvent(CONTAINER_ID_1, PAGE_ID_1, releasedEvents);
535     EXPECT_FALSE(controller.HasAnyAccessibilityEvent(CONTAINER_ID_1)); // Container should be auto-removed
536 }
537 
538 /**
539  * @tc.name: PageEventControllerTest016
540  * @tc.desc: test DeleteInstanceControllerByInstance
541  * @tc.type: FUNC
542  */
543 HWTEST_F(AccessibilityManagerUtilsTest, PageEventControllerTest016, TestSize.Level1)
544 {
545     /**
546      * @tc.steps: step1. construct JsAccessibilityManager
547      */
548     PageEventController controller;
549     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), false);
550     auto context1 = AceType::MakeRefPtr<NG::PipelineContext>();
551     CHECK_NULL_VOID(frameNode1);
552     CHECK_NULL_VOID(context1);
553     context1->instanceId_ = 1;
554     frameNode1->AttachContext(AceType::RawPtr(context1), false);
555     auto frameNode2 = FrameNode::CreateFrameNode("framenode", 2, AceType::MakeRefPtr<Pattern>(), false);
556     auto context2 = AceType::MakeRefPtr<NG::PipelineContext>();
557     CHECK_NULL_VOID(frameNode2);
558     CHECK_NULL_VOID(context2);
559     context2->instanceId_ = 2;
560     frameNode2->AttachContext(AceType::RawPtr(context2), false);
561     /**
562     * @tc.steps: step2. add controller with instanceId.
563     * @tc.expected: delete with instanceid 1.
564     */
565     controller.Add(frameNode1);
566     controller.Add(frameNode2);
567 
568     controller.DeleteInstanceControllerByInstance(1);
569     EXPECT_TRUE(controller.CheckEmpty(1));
570     EXPECT_FALSE(controller.CheckEmpty(2));
571 }
572 } // namespace OHOS::Ace::NG