1885b47fbSopenharmony_ci/*
2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License.
5885b47fbSopenharmony_ci * You may obtain a copy of the License at
6885b47fbSopenharmony_ci *
7885b47fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8885b47fbSopenharmony_ci *
9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and
13885b47fbSopenharmony_ci * limitations under the License.
14885b47fbSopenharmony_ci */
15885b47fbSopenharmony_ci
16885b47fbSopenharmony_ci#include <gtest/gtest.h>
17885b47fbSopenharmony_ci#include "accessibility_common_helper.h"
18885b47fbSopenharmony_ci#include "accessibility_display_manager.h"
19885b47fbSopenharmony_ci#include "accessibility_element_operator_proxy.h"
20885b47fbSopenharmony_ci#include "accessibility_element_operator_stub.h"
21885b47fbSopenharmony_ci#include "accessibility_mt_helper.h"
22885b47fbSopenharmony_ci#include "accessible_ability_manager_service.h"
23885b47fbSopenharmony_ci#include "accessible_ability_manager_state_observer_proxy.h"
24885b47fbSopenharmony_ci#include "accessible_ability_manager_state_observer_stub.h"
25885b47fbSopenharmony_ci#include "iservice_registry.h"
26885b47fbSopenharmony_ci
27885b47fbSopenharmony_ciusing namespace testing;
28885b47fbSopenharmony_ciusing namespace testing::ext;
29885b47fbSopenharmony_ci
30885b47fbSopenharmony_cinamespace OHOS {
31885b47fbSopenharmony_cinamespace Accessibility {
32885b47fbSopenharmony_ciclass MockAAMSServerTest : public testing::Test {
33885b47fbSopenharmony_cipublic:
34885b47fbSopenharmony_ci    AAMSServerTest()
35885b47fbSopenharmony_ci    {}
36885b47fbSopenharmony_ci    ~AAMSServerTest()
37885b47fbSopenharmony_ci    {}
38885b47fbSopenharmony_ci
39885b47fbSopenharmony_ci    static void SetUpTestCase();
40885b47fbSopenharmony_ci    static void TearDownTestCase();
41885b47fbSopenharmony_ci
42885b47fbSopenharmony_ci    void SetUp() override;
43885b47fbSopenharmony_ci    void TearDown() override;
44885b47fbSopenharmony_ci    void AddAccessibleAbilityConnection();
45885b47fbSopenharmony_ci    void WritefileAll(const char* fname, const char* data);
46885b47fbSopenharmony_ci    sptr<AccessibilityAccountData> accountData_ = nullptr;
47885b47fbSopenharmony_ci    sptr<AccessibleAbilityChannel> aastub_ = nullptr;
48885b47fbSopenharmony_ci    sptr<AppExecFwk::ElementName> elementName_ = nullptr;
49885b47fbSopenharmony_ci    sptr<AccessibleAbilityConnection> AAConnection_ = nullptr;
50885b47fbSopenharmony_ci};
51885b47fbSopenharmony_ci
52885b47fbSopenharmony_civoid AAMSServerTest::SetUpTestCase()
53885b47fbSopenharmony_ci{
54885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest SetUpTestCase";
55885b47fbSopenharmony_ci}
56885b47fbSopenharmony_ci
57885b47fbSopenharmony_civoid AAMSServerTest::TearDownTestCase()
58885b47fbSopenharmony_ci{
59885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest TearDownTestCase";
60885b47fbSopenharmony_ci}
61885b47fbSopenharmony_ci
62885b47fbSopenharmony_civoid AAMSServerTest::SetUp()
63885b47fbSopenharmony_ci{
64885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest SetUp";
65885b47fbSopenharmony_ci
66885b47fbSopenharmony_ci    // Start AAMS
67885b47fbSopenharmony_ci    Singleton<AccessibleAbilityManagerService>::GetInstance().OnStart();
68885b47fbSopenharmony_ci    AccessibilityCommonHelper::GetInstance().WaitForServicePublish();
69885b47fbSopenharmony_ci    Singleton<AccessibleAbilityManagerService>::GetInstance().SwitchedUser(AccessibilityHelper::accountId_);
70885b47fbSopenharmony_ci    sleep(1);
71885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published";
72885b47fbSopenharmony_ci}
73885b47fbSopenharmony_ci
74885b47fbSopenharmony_civoid AAMSServerTest::TearDown()
75885b47fbSopenharmony_ci{
76885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest TearDown";
77885b47fbSopenharmony_ci    AccessibilityHelper::GetInstance().SetTestStub(nullptr);
78885b47fbSopenharmony_ci    AccessibilityHelper::GetInstance().SetTestStateType(-1);
79885b47fbSopenharmony_ci    AccessibilityHelper::GetInstance().SetTestEventType(-1);
80885b47fbSopenharmony_ci    AccessibilityHelper::GetInstance().SetTestWindowChangeTypes(-1);
81885b47fbSopenharmony_ci    AccessibilityHelper::GetInstance().SetTestWindowId(-1);
82885b47fbSopenharmony_ci    Singleton<AccessibleAbilityManagerService>::GetInstance().OnStop();
83885b47fbSopenharmony_ci    accountData_ = nullptr;
84885b47fbSopenharmony_ci    aastub_ = nullptr;
85885b47fbSopenharmony_ci    elementName_ = nullptr;
86885b47fbSopenharmony_ci    AAConnection_ = nullptr;
87885b47fbSopenharmony_ci}
88885b47fbSopenharmony_ci
89885b47fbSopenharmony_civoid AAMSServerTest::WritefileAll(const char* fname, const char* data)
90885b47fbSopenharmony_ci{
91885b47fbSopenharmony_ci    FILE* fp = nullptr;
92885b47fbSopenharmony_ci    if (!(fp = fopen(fname, "w"))) {
93885b47fbSopenharmony_ci        printf("open file %s fail \n", fname);
94885b47fbSopenharmony_ci        return;
95885b47fbSopenharmony_ci    }
96885b47fbSopenharmony_ci
97885b47fbSopenharmony_ci    (void)fprintf(fp, "%s", data);
98885b47fbSopenharmony_ci    (void)fclose(fp);
99885b47fbSopenharmony_ci}
100885b47fbSopenharmony_ci
101885b47fbSopenharmony_civoid AAMSServerTest::AddAccessibleAbilityConnection()
102885b47fbSopenharmony_ci{
103885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest AddAccessibleAbilityConnection";
104885b47fbSopenharmony_ci    // accessibleAbility connection
105885b47fbSopenharmony_ci    AAFwk::Want want;
106885b47fbSopenharmony_ci    AppExecFwk::ElementName name;
107885b47fbSopenharmony_ci    std::string deviceId;
108885b47fbSopenharmony_ci    name.SetAbilityName("com.example.aalisttest.MainAbility");
109885b47fbSopenharmony_ci    name.SetBundleName("com.example.aalisttest");
110885b47fbSopenharmony_ci    want.SetElement(name);
111885b47fbSopenharmony_ci
112885b47fbSopenharmony_ci    AccessibilityAbilityInitParams initParams;
113885b47fbSopenharmony_ci    std::shared_ptr<AccessibilityAbilityInfo> abilityInfo = std::make_shared<AccessibilityAbilityInfo>(initParams);
114885b47fbSopenharmony_ci    abilityInfo->SetAccessibilityAbilityType(AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_ALL);
115885b47fbSopenharmony_ci    accountData_ = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
116885b47fbSopenharmony_ci    AAConnection_ = new AccessibleAbilityConnection(accountData_->GetAccountId(), 0, *abilityInfo);
117885b47fbSopenharmony_ci    elementName_ = new AppExecFwk::ElementName(deviceId, initParams.bundleName, initParams.name);
118885b47fbSopenharmony_ci    aastub_ = new AccessibleAbilityChannel(accountData_->GetAccountId(), abilityInfo->GetId());
119885b47fbSopenharmony_ci    AAConnection_->OnAbilityConnectDoneSync(*elementName_, aastub_);
120885b47fbSopenharmony_ci    accountData_->AddInstalledAbility(*abilityInfo);
121885b47fbSopenharmony_ci    sleep(1);
122885b47fbSopenharmony_ci}
123885b47fbSopenharmony_ci
124885b47fbSopenharmony_ci/**
125885b47fbSopenharmony_ci * @tc.number: AAMS_moduletest_SendEvent_001
126885b47fbSopenharmony_ci * @tc.name: SendEvent
127885b47fbSopenharmony_ci * @tc.desc: Test function SendEvent aams send event to accessibility,and check the parm of event.
128885b47fbSopenharmony_ci *
129885b47fbSopenharmony_ci */
130885b47fbSopenharmony_ciHWTEST_F(AAMSServerTest, SendEvent_001, TestSize.Level1)
131885b47fbSopenharmony_ci{
132885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest SendEvent_001 start";
133885b47fbSopenharmony_ci    // register AA
134885b47fbSopenharmony_ci    AddAccessibleAbilityConnection();
135885b47fbSopenharmony_ci    // make an event
136885b47fbSopenharmony_ci    AccessibilityEventInfo eventInfo;
137885b47fbSopenharmony_ci    eventInfo.SetEventType(EventType::TYPE_WINDOW_UPDATE);
138885b47fbSopenharmony_ci    // aams send event
139885b47fbSopenharmony_ci    Singleton<AccessibleAbilityManagerService>::GetInstance().SendEvent(eventInfo);
140885b47fbSopenharmony_ci    sleep(1);
141885b47fbSopenharmony_ci    // check aa proxy
142885b47fbSopenharmony_ci    EXPECT_EQ(AccessibilityHelper::GetInstance().GetTestEventType(), int(EventType::TYPE_WINDOW_UPDATE));
143885b47fbSopenharmony_ci
144885b47fbSopenharmony_ci    AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
145885b47fbSopenharmony_ci    accountData_->ClearInstalledAbility();
146885b47fbSopenharmony_ci
147885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest SendEvent_001 end";
148885b47fbSopenharmony_ci}
149885b47fbSopenharmony_ci
150885b47fbSopenharmony_ci/**
151885b47fbSopenharmony_ci * @tc.number: AAMS_moduletest_GetAbilityList_001
152885b47fbSopenharmony_ci * @tc.name: GetAbilityList
153885b47fbSopenharmony_ci * @tc.desc: Test function GetAbilityList
154885b47fbSopenharmony_ci * The func with Illegal parameter 1
155885b47fbSopenharmony_ci */
156885b47fbSopenharmony_ciHWTEST_F(AAMSServerTest, GetAbilityList_001, TestSize.Level1)
157885b47fbSopenharmony_ci{
158885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_001 start";
159885b47fbSopenharmony_ci    std::vector<OHOS::Accessibility::AccessibilityAbilityInfo> infos;
160885b47fbSopenharmony_ci    auto &aams = Singleton<AccessibleAbilityManagerService>::GetInstance();
161885b47fbSopenharmony_ci    auto ret = aams.GetAbilityList(0, AbilityStateType::ABILITY_STATE_ENABLE, infos);
162885b47fbSopenharmony_ci    EXPECT_EQ(RET_OK, ret);
163885b47fbSopenharmony_ci    EXPECT_EQ(infos.size(), 0);
164885b47fbSopenharmony_ci
165885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_001 end";
166885b47fbSopenharmony_ci}
167885b47fbSopenharmony_ci
168885b47fbSopenharmony_ci/**
169885b47fbSopenharmony_ci * @tc.number: AAMS_moduletest_GetAbilityList_002
170885b47fbSopenharmony_ci * @tc.name: GetAbilityList
171885b47fbSopenharmony_ci * @tc.desc: Test function GetAbilityList
172885b47fbSopenharmony_ci * Get Enable Ability list.
173885b47fbSopenharmony_ci */
174885b47fbSopenharmony_ciHWTEST_F(AAMSServerTest, GetAbilityList_002, TestSize.Level1)
175885b47fbSopenharmony_ci{
176885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_002 start";
177885b47fbSopenharmony_ci    sleep(1);
178885b47fbSopenharmony_ci    AddAccessibleAbilityConnection();
179885b47fbSopenharmony_ci
180885b47fbSopenharmony_ci    std::vector<OHOS::Accessibility::AccessibilityAbilityInfo> infos;
181885b47fbSopenharmony_ci    Singleton<AccessibleAbilityManagerService>::GetInstance().GetAbilityList(
182885b47fbSopenharmony_ci        AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN, AbilityStateType::ABILITY_STATE_ENABLE, infos);
183885b47fbSopenharmony_ci    EXPECT_EQ(infos.size(), 1);
184885b47fbSopenharmony_ci
185885b47fbSopenharmony_ci    AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
186885b47fbSopenharmony_ci    accountData_->ClearInstalledAbility();
187885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_002 end";
188885b47fbSopenharmony_ci}
189885b47fbSopenharmony_ci
190885b47fbSopenharmony_ci/**
191885b47fbSopenharmony_ci * @tc.number: AAMS_moduletest_GetAbilityList_003
192885b47fbSopenharmony_ci * @tc.name: GetAbilityList
193885b47fbSopenharmony_ci * @tc.desc: Test function GetAbilityList
194885b47fbSopenharmony_ci * Get Disable Ability list with 2 installed ability accessibility and a connected accessibility ability.
195885b47fbSopenharmony_ci */
196885b47fbSopenharmony_ciHWTEST_F(AAMSServerTest, GetAbilityList_003, TestSize.Level1)
197885b47fbSopenharmony_ci{
198885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_003 start";
199885b47fbSopenharmony_ci    sleep(1);
200885b47fbSopenharmony_ci    AddAccessibleAbilityConnection();
201885b47fbSopenharmony_ci
202885b47fbSopenharmony_ci    AccessibilityAbilityInitParams initParams;
203885b47fbSopenharmony_ci    std::shared_ptr<AccessibilityAbilityInfo> installAbilityInfo =
204885b47fbSopenharmony_ci        std::make_shared<AccessibilityAbilityInfo>(initParams);
205885b47fbSopenharmony_ci    installAbilityInfo->SetAccessibilityAbilityType(AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_ALL);
206885b47fbSopenharmony_ci    installAbilityInfo->SetPackageName("123");
207885b47fbSopenharmony_ci    auto accountData = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
208885b47fbSopenharmony_ci
209885b47fbSopenharmony_ci    // add install ability dummy
210885b47fbSopenharmony_ci    EXPECT_EQ(1, (int)accountData->GetInstalledAbilities().size());
211885b47fbSopenharmony_ci    accountData->AddInstalledAbility(*installAbilityInfo);
212885b47fbSopenharmony_ci    EXPECT_EQ(2, (int)accountData->GetInstalledAbilities().size());
213885b47fbSopenharmony_ci
214885b47fbSopenharmony_ci    // ABILITY_STATE_DISABLE
215885b47fbSopenharmony_ci    int32_t stateType = AbilityStateType::ABILITY_STATE_DISABLE;
216885b47fbSopenharmony_ci    std::vector<OHOS::Accessibility::AccessibilityAbilityInfo> infos;
217885b47fbSopenharmony_ci    Singleton<AccessibleAbilityManagerService>::GetInstance().GetAbilityList(
218885b47fbSopenharmony_ci        AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN, stateType, infos);
219885b47fbSopenharmony_ci    EXPECT_EQ(infos.size(), 1);
220885b47fbSopenharmony_ci
221885b47fbSopenharmony_ci    AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
222885b47fbSopenharmony_ci    accountData_->ClearInstalledAbility();
223885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_003 end";
224885b47fbSopenharmony_ci}
225885b47fbSopenharmony_ci
226885b47fbSopenharmony_ci/**
227885b47fbSopenharmony_ci * @tc.number: AAMS_moduletest_GetAbilityList_004
228885b47fbSopenharmony_ci * @tc.name: GetAbilityList
229885b47fbSopenharmony_ci * @tc.desc: Test function GetAbilityList
230885b47fbSopenharmony_ci * Get Disabled Ability list.
231885b47fbSopenharmony_ci */
232885b47fbSopenharmony_ciHWTEST_F(AAMSServerTest, GetAbilityList_004, TestSize.Level1)
233885b47fbSopenharmony_ci{
234885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_004 start";
235885b47fbSopenharmony_ci    sleep(1);
236885b47fbSopenharmony_ci    AddAccessibleAbilityConnection();
237885b47fbSopenharmony_ci    int32_t stateType = AbilityStateType::ABILITY_STATE_DISABLE;
238885b47fbSopenharmony_ci    std::vector<OHOS::Accessibility::AccessibilityAbilityInfo> infos;
239885b47fbSopenharmony_ci    Singleton<AccessibleAbilityManagerService>::GetInstance().GetAbilityList(
240885b47fbSopenharmony_ci        AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN, stateType, infos);
241885b47fbSopenharmony_ci    EXPECT_EQ(infos.size(), 0);
242885b47fbSopenharmony_ci
243885b47fbSopenharmony_ci    AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
244885b47fbSopenharmony_ci    accountData_->ClearInstalledAbility();
245885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_004 end";
246885b47fbSopenharmony_ci}
247885b47fbSopenharmony_ci
248885b47fbSopenharmony_ci/**
249885b47fbSopenharmony_ci * @tc.number: AAMS_moduletest_GetAbilityList_005
250885b47fbSopenharmony_ci * @tc.name: GetAbilityList
251885b47fbSopenharmony_ci * @tc.desc: Test function GetAbilityList
252885b47fbSopenharmony_ci * Get Installed ability
253885b47fbSopenharmony_ci */
254885b47fbSopenharmony_ciHWTEST_F(AAMSServerTest, GetAbilityList_005, TestSize.Level1)
255885b47fbSopenharmony_ci{
256885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_005 start";
257885b47fbSopenharmony_ci
258885b47fbSopenharmony_ci    AddAccessibleAbilityConnection();
259885b47fbSopenharmony_ci
260885b47fbSopenharmony_ci    std::vector<OHOS::Accessibility::AccessibilityAbilityInfo> infos;
261885b47fbSopenharmony_ci    Singleton<AccessibleAbilityManagerService>::GetInstance().GetAbilityList(
262885b47fbSopenharmony_ci        AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN,
263885b47fbSopenharmony_ci        AbilityStateType::ABILITY_STATE_INSTALLED, infos);
264885b47fbSopenharmony_ci    EXPECT_EQ(infos.size(), 1);
265885b47fbSopenharmony_ci
266885b47fbSopenharmony_ci    AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
267885b47fbSopenharmony_ci    accountData_->ClearInstalledAbility();
268885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_005 end";
269885b47fbSopenharmony_ci}
270885b47fbSopenharmony_ci
271885b47fbSopenharmony_ci/**
272885b47fbSopenharmony_ci * @tc.number: AAMS_moduletest_RegisterElementOperator_001
273885b47fbSopenharmony_ci * @tc.name: RegisterElementOperator
274885b47fbSopenharmony_ci * @tc.desc: Test function RegisterElementOperator
275885b47fbSopenharmony_ci * Register a ElementOperator and check account data and event detail.
276885b47fbSopenharmony_ci */
277885b47fbSopenharmony_ciHWTEST_F(AAMSServerTest, RegisterElementOperator_001, TestSize.Level1)
278885b47fbSopenharmony_ci{
279885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest RegisterElementOperator_001 start";
280885b47fbSopenharmony_ci    AddAccessibleAbilityConnection();
281885b47fbSopenharmony_ci    auto &aams = Singleton<AccessibleAbilityManagerService>::GetInstance();
282885b47fbSopenharmony_ci    auto accountData = aams.GetCurrentAccountData();
283885b47fbSopenharmony_ci    auto map = accountData->GetAsacConnections();
284885b47fbSopenharmony_ci    EXPECT_EQ(int(map.size()), 0);
285885b47fbSopenharmony_ci    EXPECT_EQ(RET_OK, aams.RegisterElementOperator(0, nullptr, true));
286885b47fbSopenharmony_ci    sleep(1);
287885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "RegisterElementOperator OK";
288885b47fbSopenharmony_ci    map = accountData->GetAsacConnections();
289885b47fbSopenharmony_ci    EXPECT_EQ(int(map.size()), 1);
290885b47fbSopenharmony_ci
291885b47fbSopenharmony_ci    aams.DeregisterElementOperator(0);
292885b47fbSopenharmony_ci    sleep(1);
293885b47fbSopenharmony_ci    AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
294885b47fbSopenharmony_ci    accountData_->ClearInstalledAbility();
295885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest RegisterElementOperator_001 end";
296885b47fbSopenharmony_ci}
297885b47fbSopenharmony_ci
298885b47fbSopenharmony_ci/**
299885b47fbSopenharmony_ci * @tc.number: AAMS_moduletest_DeregisterElementOperator_001
300885b47fbSopenharmony_ci * @tc.name: DeregisterElementOperator
301885b47fbSopenharmony_ci * @tc.desc: Test function DeregisterElementOperator
302885b47fbSopenharmony_ci * Deregister a ElementOperator and check account data and event detail.
303885b47fbSopenharmony_ci */
304885b47fbSopenharmony_ciHWTEST_F(AAMSServerTest, DeregisterElementOperator_001, TestSize.Level1)
305885b47fbSopenharmony_ci{
306885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest DeregisterElementOperator_001 start";
307885b47fbSopenharmony_ci    auto &aams = Singleton<AccessibleAbilityManagerService>::GetInstance();
308885b47fbSopenharmony_ci    auto accountData = aams.GetCurrentAccountData();
309885b47fbSopenharmony_ci    auto map = accountData->GetAsacConnections();
310885b47fbSopenharmony_ci    EXPECT_EQ(int(map.size()), 0);
311885b47fbSopenharmony_ci
312885b47fbSopenharmony_ci    AddAccessibleAbilityConnection();
313885b47fbSopenharmony_ci    sleep(1);
314885b47fbSopenharmony_ci    aams.RegisterElementOperator(0, nullptr, true);
315885b47fbSopenharmony_ci    sleep(1);
316885b47fbSopenharmony_ci    map = accountData->GetAsacConnections();
317885b47fbSopenharmony_ci    EXPECT_EQ(int(map.size()), 1);
318885b47fbSopenharmony_ci
319885b47fbSopenharmony_ci    // wrong windowId
320885b47fbSopenharmony_ci    aams.DeregisterElementOperator(1);
321885b47fbSopenharmony_ci    sleep(1);
322885b47fbSopenharmony_ci    map = accountData->GetAsacConnections();
323885b47fbSopenharmony_ci    EXPECT_EQ(int(map.size()), 1);
324885b47fbSopenharmony_ci
325885b47fbSopenharmony_ci    // true windowId
326885b47fbSopenharmony_ci    aams.DeregisterElementOperator(0);
327885b47fbSopenharmony_ci    sleep(1);
328885b47fbSopenharmony_ci    map = accountData->GetAsacConnections();
329885b47fbSopenharmony_ci    EXPECT_EQ(int(map.size()), 0);
330885b47fbSopenharmony_ci
331885b47fbSopenharmony_ci    AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
332885b47fbSopenharmony_ci    accountData_->ClearInstalledAbility();
333885b47fbSopenharmony_ci    GTEST_LOG_(INFO) << "AAMSServerTest DeregisterElementOperator_001 end";
334885b47fbSopenharmony_ci}
335885b47fbSopenharmony_ci} // namespace Accessibility
336885b47fbSopenharmony_ci} // namespace OHOS