• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <gtest/gtest.h>
17 #include <memory>
18 
19 #define private public
20 #define protected public
21 #include "ability_connect_manager.h"
22 #undef private
23 #undef protected
24 
25 #include "ability_config.h"
26 #include "ability_manager_errors.h"
27 #include "ability_scheduler.h"
28 #include "ability_util.h"
29 #include "bundlemgr/mock_bundle_manager.h"
30 #include "hilog_tag_wrapper.h"
31 #include "mock_ability_connect_callback.h"
32 #include "mock_sa_call.h"
33 #include "mock_task_handler_wrap.h"
34 #include "sa_mgr_client.h"
35 #include "system_ability_definition.h"
36 #include "session/host/include/session.h"
37 #include <thread>
38 #include <chrono>
39 
40 using namespace testing::ext;
41 using namespace OHOS::AppExecFwk;
42 using testing::_;
43 using testing::Invoke;
44 using testing::Return;
45 using testing::SetArgReferee;
46 using ::testing::DoAll;
47 
48 namespace {
49 const std::string PARAM_RESV_CALLER_APP_ID("ohos.aafwk.param.callerAppId");
50 }
51 
52 namespace OHOS {
53 namespace AAFwk {
54 class AbilityConnectManagerFourthTest : public testing::Test {
55 public:
56     static void SetUpTestCase(void);
57     static void TearDownTestCase(void);
58     void SetUp();
59     void TearDown();
60 
61     AbilityConnectManager* ConnectManager() const;
62     std::shared_ptr<MockTaskHandlerWrap> TaskHandler() const;
63     std::shared_ptr<EventHandlerWrap> EventHandler() const;
64 
65     AbilityRequest GenerateAbilityRequest(const std::string& deviceName, const std::string& abilityName,
66         const std::string& appName, const std::string& bundleName, const std::string& moduleName);
67 
68     sptr<SessionInfo> MockSessionInfo(int32_t persistentId);
69     std::shared_ptr<AbilityRecord> InitAbilityRecord();
70     std::shared_ptr<MockTaskHandlerWrap> taskHandler_;
71 protected:
72     AbilityRequest abilityRequest_{};
73     AbilityRequest abilityRequest1_{};
74     AbilityRequest abilityRequest2_{};
75     std::shared_ptr<AbilityRecord> serviceRecord_{ nullptr };
76     std::shared_ptr<AbilityRecord> serviceRecord1_{ nullptr };
77     std::shared_ptr<AbilityRecord> serviceRecord2_{ nullptr };
78     OHOS::sptr<Token> serviceToken_{ nullptr };
79     OHOS::sptr<Token> serviceToken1_{ nullptr };
80     OHOS::sptr<Token> serviceToken2_{ nullptr };
81     OHOS::sptr<IAbilityConnection> callbackA_{ nullptr };
82     OHOS::sptr<IAbilityConnection> callbackB_{ nullptr };
83 
84 private:
85     std::shared_ptr<AbilityConnectManager> connectManager_;
86     std::shared_ptr<EventHandlerWrap> eventHandler_;
87 };
88 
GenerateAbilityRequest(const std::string & deviceName,const std::string & abilityName,const std::string & appName,const std::string & bundleName,const std::string & moduleName)89 AbilityRequest AbilityConnectManagerFourthTest::GenerateAbilityRequest(const std::string& deviceName,
90     const std::string& abilityName, const std::string& appName, const std::string& bundleName,
91     const std::string& moduleName)
92 {
93     ElementName element(deviceName, bundleName, abilityName, moduleName);
94     Want want;
95     want.SetElement(element);
96 
97     AbilityInfo abilityInfo;
98     abilityInfo.visible = true;
99     abilityInfo.applicationName = appName;
100     abilityInfo.type = AbilityType::SERVICE;
101     abilityInfo.name = abilityName;
102     abilityInfo.bundleName = bundleName;
103     abilityInfo.moduleName = moduleName;
104     abilityInfo.deviceId = deviceName;
105     ApplicationInfo appinfo;
106     appinfo.name = appName;
107     abilityInfo.applicationInfo = appinfo;
108     AbilityRequest abilityRequest;
109     abilityRequest.want = want;
110     abilityRequest.abilityInfo = abilityInfo;
111     abilityRequest.appInfo = appinfo;
112     abilityInfo.process = bundleName;
113 
114     return abilityRequest;
115 }
116 
MockSessionInfo(int32_t persistentId)117 sptr<SessionInfo> AbilityConnectManagerFourthTest::MockSessionInfo(int32_t persistentId)
118 {
119     sptr<SessionInfo> sessionInfo = new (std::nothrow) SessionInfo();
120     if (!sessionInfo) {
121         TAG_LOGE(AAFwkTag::TEST, "sessionInfo is nullptr");
122         return nullptr;
123     }
124     sessionInfo->persistentId = persistentId;
125     return sessionInfo;
126 }
127 
InitAbilityRecord()128 std::shared_ptr<AbilityRecord> AbilityConnectManagerFourthTest::InitAbilityRecord()
129 {
130     AbilityRequest abilityRequest;
131     abilityRequest.appInfo.bundleName = "com.example.unittest";
132     abilityRequest.abilityInfo.name = "MainAbility";
133     abilityRequest.abilityInfo.type = AbilityType::PAGE;
134     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
135     return abilityRecord;
136 }
137 
SetUpTestCase(void)138 void AbilityConnectManagerFourthTest::SetUpTestCase(void)
139 {}
140 
TearDownTestCase(void)141 void AbilityConnectManagerFourthTest::TearDownTestCase(void)
142 {}
143 
SetUp(void)144 void AbilityConnectManagerFourthTest::SetUp(void)
145 {
146     connectManager_ = std::make_unique<AbilityConnectManager>(0);
147     taskHandler_ = MockTaskHandlerWrap::CreateQueueHandler("AbilityConnectManagerFourthTest");
148     eventHandler_ = std::make_shared<EventHandlerWrap>(taskHandler_);
149     // generate ability request
150     std::string deviceName = "device";
151     std::string abilityName = "ServiceAbility";
152     std::string appName = "hiservcie";
153     std::string bundleName = "com.ix.hiservcie";
154     std::string moduleName = "entry";
155     abilityRequest_ = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName, moduleName);
156     serviceRecord_ = AbilityRecord::CreateAbilityRecord(abilityRequest_);
157     serviceToken_ = serviceRecord_->GetToken();
158     std::string deviceName1 = "device";
159     std::string abilityName1 = "musicServiceAbility";
160     std::string appName1 = "musicservcie";
161     std::string bundleName1 = "com.ix.musicservcie";
162     std::string moduleName1 = "entry";
163     abilityRequest1_ = GenerateAbilityRequest(deviceName1, abilityName1, appName1, bundleName1, moduleName1);
164     serviceRecord1_ = AbilityRecord::CreateAbilityRecord(abilityRequest1_);
165     std::string deviceName2 = "device";
166     std::string abilityName2 = "residentServiceAbility";
167     std::string appName2 = "residentservcie";
168     std::string bundleName2 = "com.ix.residentservcie";
169     std::string moduleName2 = "entry";
170     abilityRequest2_ = GenerateAbilityRequest(deviceName2, abilityName2, appName2, bundleName2, moduleName2);
171     serviceRecord2_ = AbilityRecord::CreateAbilityRecord(abilityRequest2_);
172     serviceToken2_ = serviceRecord_->GetToken();
173     serviceToken1_ = serviceRecord_->GetToken();
174     callbackA_ = new AbilityConnectCallback();
175     callbackB_ = new AbilityConnectCallback();
176 }
177 
TearDown(void)178 void AbilityConnectManagerFourthTest::TearDown(void)
179 {
180     // reset the callback count
181     AbilityConnectCallback::onAbilityConnectDoneCount = 0;
182     AbilityConnectCallback::onAbilityDisconnectDoneCount = 0;
183     serviceRecord_ = nullptr;
184 }
185 
ConnectManager() const186 AbilityConnectManager* AbilityConnectManagerFourthTest::ConnectManager() const
187 {
188     return connectManager_.get();
189 }
190 
TaskHandler() const191 std::shared_ptr<MockTaskHandlerWrap> AbilityConnectManagerFourthTest::TaskHandler() const
192 {
193     return taskHandler_;
194 }
195 
EventHandler() const196 std::shared_ptr<EventHandlerWrap> AbilityConnectManagerFourthTest::EventHandler() const
197 {
198     return eventHandler_;
199 }
200 
201 /*
202  * Feature: AbilityConnectManager
203  * Function: DispatchForeground
204  */
205 HWTEST_F(AbilityConnectManagerFourthTest, DispatchForeground_001, TestSize.Level1)
206 {
207     TAG_LOGI(AAFwkTag::TEST, "DispatchForeground_001 start");
208     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
209     EXPECT_NE(connectManager, nullptr);
210 
211     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
212     EXPECT_NE(abilityRecord, nullptr);
213     taskHandler_ = MockTaskHandlerWrap::CreateQueueHandler("AbilityConnectManagerFourthTest");
214     connectManager->taskHandler_ = taskHandler_;
215     int result = connectManager->DispatchForeground(abilityRecord);
216 
217     EXPECT_EQ(result, ERR_OK);
218     TAG_LOGI(AAFwkTag::TEST, "DispatchForeground_001 end");
219 }
220 
221 /*
222  * Feature: AbilityConnectManager
223  * Function: NeedExtensionControl
224  */
225 HWTEST_F(AbilityConnectManagerFourthTest, NeedExtensionControl_003, TestSize.Level1)
226 {
227     TAG_LOGI(AAFwkTag::TEST, "NeedExtensionControl_003 start");
228     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
229     EXPECT_NE(connectManager, nullptr);
230 
231     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
232     abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::UI;
233     abilityRecord->customProcessFlag_ = "true";
234     abilityRecord->extensionProcessMode_ = 0;
235     ASSERT_NE(abilityRecord, nullptr);
236 
237     bool result = connectManager->NeedExtensionControl(abilityRecord);
238     EXPECT_FALSE(result);
239     TAG_LOGI(AAFwkTag::TEST, "NeedExtensionControl_003 end");
240 }
241 
242 /*
243  * Feature: AbilityConnectManager
244  * Function: NeedExtensionControl
245  */
246 HWTEST_F(AbilityConnectManagerFourthTest, NeedExtensionControl_004, TestSize.Level1)
247 {
248     TAG_LOGI(AAFwkTag::TEST, "NeedExtensionControl_004 start");
249     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
250     EXPECT_NE(connectManager, nullptr);
251 
252     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
253     abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::UI;
254     abilityRecord->customProcessFlag_ = "true";
255     abilityRecord->extensionProcessMode_ = 1;
256     ASSERT_NE(abilityRecord, nullptr);
257 
258     bool result = connectManager->NeedExtensionControl(abilityRecord);
259     EXPECT_FALSE(result);
260     TAG_LOGI(AAFwkTag::TEST, "NeedExtensionControl_004 end");
261 }
262 
263 /*
264  * Feature: AbilityConnectManager
265  * Function: TerminateRecord
266  */
267 HWTEST_F(AbilityConnectManagerFourthTest, TerminateRecord_001, TestSize.Level1)
268 {
269     TAG_LOGI(AAFwkTag::TEST, "TerminateRecord_001 start");
270     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
271     EXPECT_NE(connectManager, nullptr);
272 
273     AbilityRequest abilityRequest;
274     abilityRequest.appInfo.bundleName = "com.example.unittest";
275     abilityRequest.abilityInfo.name = "MainAbility";
276     abilityRequest.abilityInfo.type = AbilityType::PAGE;
277     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
278     ASSERT_NE(abilityRecord, nullptr);
279     abilityRecord->recordId_ = 1;
280     EXPECT_EQ(connectManager->GetExtensionByIdFromServiceMap(abilityRecord->GetRecordId()), nullptr);
281 
282     connectManager->AddToServiceMap("testKey", abilityRecord);
283     connectManager->TerminateRecord(abilityRecord);
284     EXPECT_NE(connectManager->GetExtensionByIdFromTerminatingMap(abilityRecord->GetRecordId()), nullptr);
285     TAG_LOGI(AAFwkTag::TEST, "TerminateRecord_001 end");
286 }
287 
288 /*
289  * Feature: AbilityConnectManager
290  * Function: GetExtensionByTokenFromTerminatingMap
291  */
292 HWTEST_F(AbilityConnectManagerFourthTest, GetExtensionByTokenFromTerminatingMap_001, TestSize.Level1)
293 {
294     TAG_LOGI(AAFwkTag::TEST, "GetExtensionByTokenFromTerminatingMap_001 start");
295     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
296     EXPECT_NE(connectManager, nullptr);
297 
298     OHOS::sptr<OHOS::IRemoteObject> nullToken = nullptr;
299     auto result = connectManager->GetExtensionByTokenFromTerminatingMap(nullToken);
300     EXPECT_EQ(result, nullptr);
301     connectManager->terminatingExtensionList_.clear();
302     TAG_LOGI(AAFwkTag::TEST, "GetExtensionByTokenFromTerminatingMap_001 end");
303 }
304 
305 /*
306  * Feature: AbilityConnectManager
307  * Function: GetExtensionByTokenFromTerminatingMap
308  */
309 HWTEST_F(AbilityConnectManagerFourthTest, GetExtensionByTokenFromTerminatingMap_002, TestSize.Level1)
310 {
311     TAG_LOGI(AAFwkTag::TEST, "GetExtensionByTokenFromTerminatingMap_002 start");
312     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
313     EXPECT_NE(connectManager, nullptr);
314 
315     AbilityRequest abilityRequest;
316     abilityRequest.appInfo.bundleName = "com.example.unittest";
317     abilityRequest.abilityInfo.name = "MainAbility";
318     abilityRequest.abilityInfo.type = AbilityType::PAGE;
319     abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SHARE;
320     std::shared_ptr<AbilityRecord> validRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
321     OHOS::sptr<OHOS::IRemoteObject> validToken = new OHOS::AAFwk::Token(validRecord);
322     auto result = connectManager->GetExtensionByTokenFromTerminatingMap(validToken);
323     EXPECT_EQ(result, nullptr);
324     connectManager->terminatingExtensionList_.clear();
325     TAG_LOGI(AAFwkTag::TEST, "GetExtensionByTokenFromTerminatingMap_002 end");
326 }
327 
328 /*
329  * Feature: AbilityConnectManager
330  * Function: DispatchInactive
331  */
332 HWTEST_F(AbilityConnectManagerFourthTest, DispatchInactive_001, TestSize.Level1)
333 {
334     TAG_LOGI(AAFwkTag::TEST, "DispatchInactive_001 start");
335     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
336     EXPECT_NE(connectManager, nullptr);
337 
338     const std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
339     abilityRecord->currentState_ = AbilityState::INACTIVATING;
340     abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE;
341     EXPECT_NE(abilityRecord, nullptr);
342     taskHandler_ = MockTaskHandlerWrap::CreateQueueHandler("AbilityConnectManagerFourthTest");
343     std::shared_ptr<EventHandlerWrap> eventHandler1_ = std::make_shared<EventHandlerWrap>(taskHandler_);
344     EXPECT_NE(eventHandler1_, nullptr);
345     connectManager->eventHandler_ = eventHandler1_;
346 
347     connectManager->DispatchInactive(abilityRecord, 0);
348     EXPECT_EQ(abilityRecord->GetAbilityState(), AbilityState::INACTIVE);
349     TAG_LOGI(AAFwkTag::TEST, "DispatchInactive_001 end");
350 }
351 
352 /*
353  * Feature: AbilityConnectManager
354  * Function: DispatchInactive
355  */
356 HWTEST_F(AbilityConnectManagerFourthTest, DispatchInactive_002, TestSize.Level1)
357 {
358     TAG_LOGI(AAFwkTag::TEST, "DispatchInactive_002 start");
359     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
360     EXPECT_NE(connectManager, nullptr);
361 
362     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
363     abilityRecord->currentState_ = AbilityState::INACTIVATING;
364     abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE;
365     EXPECT_NE(abilityRecord, nullptr);
366     abilityRecord->SetCreateByConnectMode(false);
367     auto taskHandler1_ = MockTaskHandlerWrap::CreateQueueHandler("AbilityConnectManagerFourthTest");
368     std::shared_ptr<EventHandlerWrap> eventHandler1_ = std::make_shared<EventHandlerWrap>(taskHandler_);
369     EXPECT_NE(eventHandler1_, nullptr);
370     connectManager->eventHandler_ = eventHandler1_;
371     Want want;
372     want.SetParam("ability.want.params.is_preload_uiextension_ability", false);
373     abilityRecord->SetWant(want);
374     connectManager->uiExtensionAbilityRecordMgr_= nullptr;
375 
376     int result = connectManager->DispatchInactive(abilityRecord, AbilityState::INACTIVATING);
377     EXPECT_EQ(result, ERR_OK);
378     TAG_LOGI(AAFwkTag::TEST, "DispatchInactive_002 end");
379 }
380 
381 /*
382  * Feature: AbilityConnectManager
383  * Function: DispatchInactive
384  */
385 HWTEST_F(AbilityConnectManagerFourthTest, DispatchInactive_003, TestSize.Level1)
386 {
387     TAG_LOGI(AAFwkTag::TEST, "DispatchInactive_003 start");
388     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
389     EXPECT_NE(connectManager, nullptr);
390 
391     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
392     abilityRecord->currentState_ = AbilityState::INACTIVATING;
393     abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE;
394     abilityRecord->SetUIExtensionAbilityId(1);
395     EXPECT_NE(abilityRecord, nullptr);
396     abilityRecord->SetCreateByConnectMode(false);
397     taskHandler_ = MockTaskHandlerWrap::CreateQueueHandler("AbilityConnectManagerFourthTest");
398     std::shared_ptr<EventHandlerWrap> eventHandler1_ = std::make_shared<EventHandlerWrap>(taskHandler_);
399     EXPECT_NE(eventHandler1_, nullptr);
400     connectManager->eventHandler_ = eventHandler1_;
401     Want want;
402     want.SetParam("ability.want.params.is_preload_uiextension_ability", false);
403     abilityRecord->SetWant(want);
404 
405     int result = connectManager->DispatchInactive(abilityRecord, AbilityState::INACTIVATING);
406     EXPECT_EQ(result, ERR_OK);
407     TAG_LOGI(AAFwkTag::TEST, "DispatchInactive_003 end");
408 }
409 
410 /*
411  * Feature: AbilityConnectManager
412  * Function: DispatchInactive
413  */
414 HWTEST_F(AbilityConnectManagerFourthTest, DispatchInactive_004, TestSize.Level1)
415 {
416     TAG_LOGI(AAFwkTag::TEST, "DispatchInactive_004 start");
417     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
418     EXPECT_NE(connectManager, nullptr);
419 
420     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
421     abilityRecord->currentState_ = AbilityState::INACTIVATING;
422     abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE;
423     abilityRecord->SetUIExtensionAbilityId(1);
424 
425     EXPECT_NE(abilityRecord, nullptr);
426     abilityRecord->SetCreateByConnectMode(false);
427     auto taskHandler1_ = MockTaskHandlerWrap::CreateQueueHandler("AbilityConnectManagerFourthTest");
428     std::shared_ptr<EventHandlerWrap> eventHandler1_ = std::make_shared<EventHandlerWrap>(taskHandler1_);
429     EXPECT_NE(eventHandler1_, nullptr);
430     connectManager->eventHandler_ = eventHandler1_;
431     Want want;
432     want.SetParam("ability.want.params.is_preload_uiextension_ability", true);
433     abilityRecord->SetWant(want);
434 
435     int result = connectManager->DispatchInactive(abilityRecord, 0);
436     EXPECT_EQ(result, ERR_INVALID_VALUE);
437     TAG_LOGI(AAFwkTag::TEST, "DispatchInactive_004 end");
438 }
439 
440 /*
441 * Feature: AbilityConnectManager
442 * Function: HandleUIExtensionDied
443 */
444 HWTEST_F(AbilityConnectManagerFourthTest, HandleUIExtensionDied_002, TestSize.Level1)
445 {
446     TAG_LOGI(AAFwkTag::TEST, "HandleUIExtensionDied_002 start");
447     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
448     EXPECT_NE(connectManager, nullptr);
449 
450     sptr<Token> token = serviceToken_;
451     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
452     ASSERT_NE(abilityRecord, nullptr);
453     sptr<IRemoteObject> sessionToken = abilityRecord->GetToken();
454     connectManager->AddUIExtWindowDeathRecipient(sessionToken);
455     connectManager->uiExtensionMap_[sessionToken] = {std::weak_ptr<AbilityRecord>(), nullptr};
456     EXPECT_EQ(connectManager->uiExtensionMap_.size(), 1);
457 
458     connectManager->HandleUIExtensionDied(abilityRecord);
459     EXPECT_EQ(connectManager->uiExtensionMap_.size(), 0);
460     TAG_LOGI(AAFwkTag::TEST, "HandleUIExtensionDied_002 end");
461 }
462 
463 /*
464  * Feature: AbilityConnectManager
465  * Function: HandleUIExtensionDied
466  */
467 HWTEST_F(AbilityConnectManagerFourthTest, HandleUIExtensionDied_003, TestSize.Level1)
468 {
469     TAG_LOGI(AAFwkTag::TEST, "HandleUIExtensionDied_003 start");
470     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
471     EXPECT_NE(connectManager, nullptr);
472 
473     sptr<Token> token = serviceToken_;
474     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
475     ASSERT_NE(abilityRecord, nullptr);
476     sptr<IRemoteObject> sessionToken = abilityRecord->GetToken();
477     connectManager->uiExtensionMap_[sessionToken] = {abilityRecord, nullptr};
478     EXPECT_EQ(connectManager->uiExtensionMap_.size(), 1);
479 
480     connectManager->HandleUIExtensionDied(abilityRecord);
481     EXPECT_EQ(connectManager->uiExtensionMap_.size(), 0);
482     TAG_LOGI(AAFwkTag::TEST, "HandleUIExtensionDied_003 end");
483 }
484 
485 /*
486  * Feature: AbilityConnectManager
487  * Function: HandleUIExtensionDied
488  */
489 HWTEST_F(AbilityConnectManagerFourthTest, HandleUIExtensionDied_004, TestSize.Level1)
490 {
491     TAG_LOGI(AAFwkTag::TEST, "HandleUIExtensionDied_004 start");
492     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
493     EXPECT_NE(connectManager, nullptr);
494 
495     sptr<Token> token = serviceToken_;
496     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
497     ASSERT_NE(abilityRecord, nullptr);
498     std::shared_ptr<AbilityRecord> anotherAbilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest1_);
499     ASSERT_NE(anotherAbilityRecord, nullptr);
500     sptr<IRemoteObject> sessionToken = abilityRecord->GetToken();
501     connectManager->uiExtensionMap_[sessionToken] = {anotherAbilityRecord, nullptr};
502     EXPECT_EQ(connectManager->uiExtensionMap_.size(), 1);
503 
504     connectManager->HandleUIExtensionDied(abilityRecord);
505     EXPECT_EQ(connectManager->uiExtensionMap_.size(), 1);
506     TAG_LOGI(AAFwkTag::TEST, "HandleUIExtensionDied_004 end");
507 }
508 
509 /*
510  * Feature: AbilityConnectManager
511  * Function: GetServiceKey
512  */
513 HWTEST_F(AbilityConnectManagerFourthTest, GetServiceKey_001, TestSize.Level1)
514 {
515     TAG_LOGI(AAFwkTag::TEST, "GetServiceKey_001 start");
516     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
517     ASSERT_NE(connectManager, nullptr);
518 
519     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
520     ASSERT_NE(abilityRecord, nullptr);
521     abilityRecord->uri_ = "com.example.test";
522     abilityRecord->abilityInfo_.bundleName = "com.ohos.formrenderservice";
523     Want want;
524     want.SetParam("com.ohos.formrenderservice", 0);
525     abilityRecord->SetWant(want);
526 
527     std::string serviceKey = connectManager->GetServiceKey(abilityRecord);
528     EXPECT_EQ(serviceKey, "com.example.test0");
529     TAG_LOGI(AAFwkTag::TEST, "GetServiceKey_001 end");
530 }
531 
532 /*
533  * Feature: AbilityConnectManager
534  * Function: GetExtensionRunningInfos
535  */
536 HWTEST_F(AbilityConnectManagerFourthTest, GetExtensionRunningInfos_001, TestSize.Level1)
537 {
538     TAG_LOGI(AAFwkTag::TEST, "GetExtensionRunningInfos_001 start");
539     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
540     EXPECT_NE(connectManager, nullptr);
541 
542     std::vector<ExtensionRunningInfo> info;
543     int upperLimit = 2;
544     int32_t userId = 0;
545     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
546     ASSERT_NE(abilityRecord, nullptr);
547     connectManager->AddToServiceMap("testServiceKey1", abilityRecord);
548     info.emplace_back();
549 
550     connectManager->GetExtensionRunningInfos(upperLimit, info, userId, true);
551     EXPECT_EQ(info.size(), upperLimit);
552     TAG_LOGI(AAFwkTag::TEST, "GetExtensionRunningInfos_001 end");
553 }
554 
555 /*
556  * Feature: AbilityConnectManager
557  * Function: GetExtensionRunningInfos
558  */
559 HWTEST_F(AbilityConnectManagerFourthTest, GetExtensionRunningInfos_002, TestSize.Level1)
560 {
561     TAG_LOGI(AAFwkTag::TEST, "GetExtensionRunningInfos_002 start");
562     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
563     EXPECT_NE(connectManager, nullptr);
564 
565     std::vector<ExtensionRunningInfo> info;
566     int upperLimit = 2;
567     int32_t userId = 0;
568     connectManager->AddToServiceMap("testServiceKey2", nullptr);
569 
570     connectManager->GetExtensionRunningInfos(upperLimit, info, userId, true);
571     EXPECT_EQ(info.size(), 0);
572     TAG_LOGI(AAFwkTag::TEST, "GetExtensionRunningInfos_002 end");
573 }
574 
575 /*
576  * Feature: AbilityConnectManager
577  * Function: GetExtensionRunningInfos
578  */
579 HWTEST_F(AbilityConnectManagerFourthTest, GetExtensionRunningInfos_003, TestSize.Level1)
580 {
581     TAG_LOGI(AAFwkTag::TEST, "GetExtensionRunningInfos_003 start");
582     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
583     EXPECT_NE(connectManager, nullptr);
584 
585     std::vector<ExtensionRunningInfo> info;
586     int upperLimit = 2;
587     int32_t userId = 0;
588     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
589     ASSERT_NE(abilityRecord, nullptr);
590     connectManager->AddToServiceMap("testServiceKey3", abilityRecord);
591 
592     connectManager->GetExtensionRunningInfos(upperLimit, info, userId, true);
593     EXPECT_EQ(info.size(), 1);
594     TAG_LOGI(AAFwkTag::TEST, "GetExtensionRunningInfos_003 end");
595 }
596 
597 /*
598  * Feature: AbilityConnectManager
599  * Function: GetAbilityRunningInfos
600  */
601 HWTEST_F(AbilityConnectManagerFourthTest, GetAbilityRunningInfos_001, TestSize.Level1)
602 {
603     TAG_LOGI(AAFwkTag::TEST, "GetAbilityRunningInfos_001 start");
604     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
605     EXPECT_NE(connectManager, nullptr);
606 
607     std::vector<AbilityRunningInfo> info;
608     connectManager->AddToServiceMap("testServiceKey1", nullptr);
609 
610     connectManager->GetAbilityRunningInfos(info, true);
611     EXPECT_EQ(info.size(), 0);
612     TAG_LOGI(AAFwkTag::TEST, "GetAbilityRunningInfos_001 end");
613 }
614 
615 /*
616  * Feature: AbilityConnectManager
617  * Function: GetAbilityRunningInfos
618  */
619 HWTEST_F(AbilityConnectManagerFourthTest, GetAbilityRunningInfos_002, TestSize.Level1)
620 {
621     TAG_LOGI(AAFwkTag::TEST, "GetAbilityRunningInfos_002 start");
622     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
623     EXPECT_NE(connectManager, nullptr);
624 
625     std::vector<AbilityRunningInfo> info;
626     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
627     ASSERT_NE(abilityRecord, nullptr);
628     connectManager->AddToServiceMap("testServiceKey2", abilityRecord);
629 
630     connectManager->GetAbilityRunningInfos(info, true);
631     EXPECT_GT(info.size(), 0);
632     TAG_LOGI(AAFwkTag::TEST, "GetAbilityRunningInfos_002 end");
633 }
634 
635 /*
636  * Feature: AbilityConnectManager
637  * Function: GetAbilityRunningInfos
638  */
639 HWTEST_F(AbilityConnectManagerFourthTest, GetAbilityRunningInfos_003, TestSize.Level1)
640 {
641     TAG_LOGI(AAFwkTag::TEST, "GetAbilityRunningInfos_003 start");
642     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
643     EXPECT_NE(connectManager, nullptr);
644 
645     std::vector<AbilityRunningInfo> info;
646     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
647     ASSERT_NE(abilityRecord, nullptr);
648     abilityRecord->abilityInfo_.applicationInfo.accessTokenId = IPCSkeleton::GetCallingTokenID();
649     connectManager->AddToServiceMap("testServiceKey3", abilityRecord);
650 
651     connectManager->GetAbilityRunningInfos(info, false);
652     EXPECT_GT(info.size(), 0);
653     TAG_LOGI(AAFwkTag::TEST, "GetAbilityRunningInfos_003 end");
654 }
655 
656 /*
657  * Feature: AbilityConnectManager
658  * Function: IsLauncher
659  */
660 HWTEST_F(AbilityConnectManagerFourthTest, IsLauncher_001, TestSize.Level1)
661 {
662     TAG_LOGI(AAFwkTag::TEST, "IsLauncher_001 start");
663     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
664     EXPECT_NE(connectManager, nullptr);
665 
666     std::shared_ptr<AbilityRecord> nullAbilityRecord = nullptr;
667     bool result = connectManager->IsLauncher(nullAbilityRecord);
668     EXPECT_FALSE(result);
669     TAG_LOGI(AAFwkTag::TEST, "IsLauncher_001 end");
670 }
671 
672 /*
673  * Feature: AbilityConnectManager
674  * Function: IsLauncher
675  */
676 HWTEST_F(AbilityConnectManagerFourthTest, IsLauncher_002, TestSize.Level1)
677 {
678     TAG_LOGI(AAFwkTag::TEST, "IsLauncher_002 start");
679     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
680     EXPECT_NE(connectManager, nullptr);
681 
682     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
683     ASSERT_NE(abilityRecord, nullptr);
684     abilityRecord->abilityInfo_.name = "NotLauncher";
685     abilityRecord->abilityInfo_.bundleName = "com.ohos.launcher";
686 
687     bool result = connectManager->IsLauncher(abilityRecord);
688     EXPECT_FALSE(result);
689     TAG_LOGI(AAFwkTag::TEST, "IsLauncher_002 end");
690 }
691 
692 /*
693  * Feature: AbilityConnectManager
694  * Function: IsLauncher
695  */
696 HWTEST_F(AbilityConnectManagerFourthTest, IsLauncher_003, TestSize.Level1)
697 {
698     TAG_LOGI(AAFwkTag::TEST, "IsLauncher_003 start");
699     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
700     EXPECT_NE(connectManager, nullptr);
701 
702     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
703     ASSERT_NE(abilityRecord, nullptr);
704     abilityRecord->abilityInfo_.name = "com.ohos.launcher.MainAbility";
705     abilityRecord->abilityInfo_.bundleName = "NotLauncherBundle";
706 
707     bool result = connectManager->IsLauncher(abilityRecord);
708     EXPECT_FALSE(result);
709     TAG_LOGI(AAFwkTag::TEST, "IsLauncher_003 end");
710 }
711 
712 /*
713  * Feature: AbilityConnectManager
714  * Function: IsLauncher
715  */
716 HWTEST_F(AbilityConnectManagerFourthTest, IsLauncher_004, TestSize.Level1)
717 {
718     TAG_LOGI(AAFwkTag::TEST, "IsLauncher_004 start");
719     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
720     EXPECT_NE(connectManager, nullptr);
721 
722     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
723     ASSERT_NE(abilityRecord, nullptr);
724     abilityRecord->abilityInfo_.name = "com.ohos.launcher.MainAbility";
725     abilityRecord->abilityInfo_.bundleName = "com.ohos.launcher";
726 
727     bool result = connectManager->IsLauncher(abilityRecord);
728     EXPECT_TRUE(result);
729     TAG_LOGI(AAFwkTag::TEST, "IsLauncher_004 end");
730 }
731 
732 /*
733  * Feature: AbilityConnectManager
734  * Function: IsUIExtensionFocused
735  */
736 HWTEST_F(AbilityConnectManagerFourthTest, IsUIExtensionFocused_001, TestSize.Level1)
737 {
738     TAG_LOGI(AAFwkTag::TEST, "IsUIExtensionFocused_001 start");
739     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
740     EXPECT_NE(connectManager, nullptr);
741 
742     uint32_t uiExtensionTokenId = 1;
743     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
744     ASSERT_NE(abilityRecord, nullptr);
745     sptr<IRemoteObject> focusToken = abilityRecord->GetToken();
746     abilityRecord->abilityInfo_.applicationInfo.accessTokenId = 5;
747     connectManager->uiExtensionMap_.clear();
748     connectManager->uiExtensionMap_.emplace(focusToken, std::make_pair(abilityRecord, nullptr));
749 
750     bool result = connectManager->IsUIExtensionFocused(uiExtensionTokenId, focusToken);
751     EXPECT_FALSE(result);
752     TAG_LOGI(AAFwkTag::TEST, "IsUIExtensionFocused_001 end");
753 }
754 
755 /*
756  * Feature: AbilityConnectManager
757  * Function: IsUIExtensionFocused
758  */
759 HWTEST_F(AbilityConnectManagerFourthTest, IsUIExtensionFocused_002, TestSize.Level1)
760 {
761     TAG_LOGI(AAFwkTag::TEST, "IsUIExtensionFocused_002 start");
762     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
763     EXPECT_NE(connectManager, nullptr);
764 
765     uint32_t uiExtensionTokenId = 1;
766     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
767     ASSERT_NE(abilityRecord, nullptr);
768     sptr<IRemoteObject> focusToken = abilityRecord->GetToken();
769     abilityRecord->abilityInfo_.applicationInfo.accessTokenId = uiExtensionTokenId;
770     sptr<SessionInfo> sessionInfo = new (std::nothrow) SessionInfo();
771     sessionInfo->callerToken = focusToken;
772     connectManager->uiExtensionMap_.clear();
773     connectManager->uiExtensionMap_.emplace(focusToken, std::make_pair(abilityRecord, sessionInfo));
774 
775     bool result = connectManager->IsUIExtensionFocused(uiExtensionTokenId, focusToken);
776     EXPECT_TRUE(result);
777     TAG_LOGI(AAFwkTag::TEST, "IsUIExtensionFocused_002 end");
778 }
779 
780 /*
781  * Feature: AbilityConnectManager
782  * Function: GetUIExtensionSourceToken
783  */
784 HWTEST_F(AbilityConnectManagerFourthTest, GetUIExtensionSourceToken_001, TestSize.Level1)
785 {
786     TAG_LOGI(AAFwkTag::TEST, "GetUIExtensionSourceToken_001 start");
787     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
788     EXPECT_NE(connectManager, nullptr);
789 
790     sptr<IRemoteObject> nulltoken = nullptr;
791     sptr<IRemoteObject> resultToken = connectManager->GetUIExtensionSourceToken(nulltoken);
792     EXPECT_EQ(resultToken, nullptr);
793     TAG_LOGI(AAFwkTag::TEST, "GetUIExtensionSourceToken_001 end");
794 }
795 
796 /*
797  * Feature: AbilityConnectManager
798  * Function: GetUIExtensionSourceToken
799  */
800 HWTEST_F(AbilityConnectManagerFourthTest, GetUIExtensionSourceToken_002, TestSize.Level1)
801 {
802     TAG_LOGI(AAFwkTag::TEST, "GetUIExtensionSourceToken_002 start");
803     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
804     EXPECT_NE(connectManager, nullptr);
805 
806     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
807     ASSERT_NE(abilityRecord, nullptr);
808     sptr<IRemoteObject> token = abilityRecord->GetToken();
809     connectManager->uiExtensionMap_.emplace(token, std::make_pair(abilityRecord, nullptr));
810 
811     sptr<IRemoteObject> resultToken = connectManager->GetUIExtensionSourceToken(token);
812     EXPECT_EQ(resultToken, nullptr);
813     TAG_LOGI(AAFwkTag::TEST, "GetUIExtensionSourceToken_002 end");
814 }
815 
816 /*
817  * Feature: AbilityConnectManager
818  * Function: GetUIExtensionSourceToken
819  */
820 HWTEST_F(AbilityConnectManagerFourthTest, GetUIExtensionSourceToken_003, TestSize.Level1)
821 {
822     TAG_LOGI(AAFwkTag::TEST, "GetUIExtensionSourceToken_002 start");
823     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
824     EXPECT_NE(connectManager, nullptr);
825 
826     sptr<SessionInfo> sessionInfo = new SessionInfo();
827     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
828     ASSERT_NE(abilityRecord, nullptr);
829     sptr<IRemoteObject> token = abilityRecord->GetToken();
830     connectManager->uiExtensionMap_.clear();
831     connectManager->uiExtensionMap_.emplace(token, std::make_pair(abilityRecord, sessionInfo));
832 
833     sptr<IRemoteObject> resultToken = connectManager->GetUIExtensionSourceToken(token);
834     EXPECT_EQ(resultToken, nullptr);
835     TAG_LOGI(AAFwkTag::TEST, "GetUIExtensionSourceToken_002 end");
836 }
837 
838 /*
839  * Feature: AbilityConnectManager
840  * Function: StopServiceAbilityLocked
841  */
842 HWTEST_F(AbilityConnectManagerFourthTest, StopServiceAbilityLocked_001, TestSize.Level1)
843 {
844     TAG_LOGI(AAFwkTag::TEST, "StopServiceAbilityLocked_001 start");
845     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
846     EXPECT_NE(connectManager, nullptr);
847 
848     AbilityRequest abilityRequest;
849     abilityRequest.abilityInfo.deviceId = "deviceId";
850     abilityRequest.abilityInfo.bundleName = "com.ohos.formrenderservice";
851     abilityRequest.abilityInfo.name = "testAbility";
852     abilityRequest.abilityInfo.moduleName = "testModule";
853 
854     int result = connectManager->StopServiceAbilityLocked(abilityRequest);
855     EXPECT_EQ(result, ERR_INVALID_VALUE);
856     TAG_LOGI(AAFwkTag::TEST, "StopServiceAbilityLocked_001 end");
857 }
858 
859 /*
860  * Feature: AbilityConnectManager
861  * Function: StopServiceAbilityLocked
862  */
863 HWTEST_F(AbilityConnectManagerFourthTest, StopServiceAbilityLocked_002, TestSize.Level1)
864 {
865     TAG_LOGI(AAFwkTag::TEST, "StopServiceAbilityLocked_002 start");
866     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
867     EXPECT_NE(connectManager, nullptr);
868 
869     AbilityRequest abilityRequest;
870     abilityRequest.abilityInfo.deviceId = "deviceId";
871     abilityRequest.abilityInfo.bundleName ="testBundle";
872     abilityRequest.abilityInfo.name = "testAbility";
873     abilityRequest.abilityInfo.moduleName = "testModule";
874     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
875     ASSERT_NE(abilityRecord, nullptr);
876     abilityRecord->SetAbilityState(AbilityState::TERMINATING);
877     connectManager->AddToServiceMap("testServiceKey", abilityRecord);
878 
879     int result = connectManager->StopServiceAbilityLocked(abilityRequest);
880     EXPECT_EQ(result, ERR_INVALID_VALUE);
881     TAG_LOGI(AAFwkTag::TEST, "StopServiceAbilityLocked_002 end");
882 }
883 
884 /*
885  * Feature: AbilityConnectManager
886  * Function: StopServiceAbilityLocked
887  */
888 HWTEST_F(AbilityConnectManagerFourthTest, StopServiceAbilityLocked_003, TestSize.Level1)
889 {
890     TAG_LOGI(AAFwkTag::TEST, "StopServiceAbilityLocked_003 start");
891     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
892     EXPECT_NE(connectManager, nullptr);
893 
894     AbilityRequest abilityRequest;
895     abilityRequest.abilityInfo.deviceId = "deviceId";
896     abilityRequest.abilityInfo.bundleName ="testBundle";
897     abilityRequest.abilityInfo.name = "testAbility";
898     abilityRequest.abilityInfo.moduleName = "testModule";
899     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
900     ASSERT_NE(abilityRecord, nullptr);
901     sptr<IRemoteObject> callerToken = abilityRecord->GetToken();
902     OHOS::sptr<IAbilityConnection> callback1 = new AbilityConnectCallback();
903     std::shared_ptr<ConnectionRecord> connectRecord =
904         std::make_shared<ConnectionRecord>(callerToken, abilityRecord, callback1, nullptr);
905     abilityRecord->AddConnectRecordToList(connectRecord);
906     connectManager->AddToServiceMap("testServiceKey", abilityRecord);
907 
908     int result = connectManager->StopServiceAbilityLocked(abilityRequest);
909     EXPECT_EQ(result, ERR_INVALID_VALUE);
910     TAG_LOGI(AAFwkTag::TEST, "StopServiceAbilityLocked_003 end");
911 }
912 
913 /*
914  * Feature: AbilityConnectManager
915  * Function: RemoveServiceFromMapSafe
916  */
917 HWTEST_F(AbilityConnectManagerFourthTest, RemoveServiceFromMapSafe_001, TestSize.Level1)
918 {
919     TAG_LOGI(AAFwkTag::TEST, "RemoveServiceFromMapSafe_001 start");
920     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
921     EXPECT_NE(connectManager, nullptr);
922 
923     std::string existingKey = "existingServiceKey";
924     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
925     ASSERT_NE(abilityRecord, nullptr);
926     connectManager->AddToServiceMap(existingKey, abilityRecord);
927     EXPECT_EQ(connectManager->GetServiceMap().size(), 1);
928 
929     connectManager->RemoveServiceFromMapSafe(existingKey);
930     EXPECT_EQ(connectManager->GetServiceMap().size(), 0);
931     TAG_LOGI(AAFwkTag::TEST, "RemoveServiceFromMapSafe_001 end");
932 }
933 
934 /*
935  * Feature: AbilityConnectManager
936  * Function: QueryPreLoadUIExtensionRecordInner
937  */
938 HWTEST_F(AbilityConnectManagerFourthTest, QueryPreLoadUIExtensionRecordInner_001, TestSize.Level1)
939 {
940     TAG_LOGI(AAFwkTag::TEST, "QueryPreLoadUIExtensionRecordInner_001 start");
941     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
942     EXPECT_NE(connectManager, nullptr);
943 
944     AppExecFwk::ElementName element("deviceId", "bundleName", "abilityName", "moduleName");
945     std::string moduleName = "testModule";
946     std::string hostBundleName = "testHostBundle";
947     int32_t recordNum = 0;
948 
949     int32_t result =
950         connectManager->QueryPreLoadUIExtensionRecordInner(element, moduleName, hostBundleName, recordNum);
951     EXPECT_EQ(result, ERR_OK);
952 
953     connectManager->uiExtensionAbilityRecordMgr_ = nullptr;
954     result =
955         connectManager->QueryPreLoadUIExtensionRecordInner(element, moduleName, hostBundleName, recordNum);
956     EXPECT_EQ(result, ERR_NULL_OBJECT);
957     TAG_LOGI(AAFwkTag::TEST, "QueryPreLoadUIExtensionRecordInner_001 end");
958 }
959 
960 /*
961  * Feature: AbilityConnectManager
962  * Function: QueryPreLoadUIExtensionRecordInner
963  */
964 HWTEST_F(AbilityConnectManagerFourthTest, QueryPreLoadUIExtensionRecordInner_002, TestSize.Level1)
965 {
966     TAG_LOGI(AAFwkTag::TEST, "QueryPreLoadUIExtensionRecordInner_002 start");
967     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
968     EXPECT_NE(connectManager, nullptr);
969 
970     AppExecFwk::ElementName element("deviceId", "bundleName", "abilityName", "moduleName");
971     std::string moduleName = "testModule";
972     std::string hostBundleName = "testHostBundle";
973     int32_t recordNum = 0;
974 
975     connectManager->uiExtensionAbilityRecordMgr_ = nullptr;
976     int result = connectManager->QueryPreLoadUIExtensionRecordInner(element, moduleName, hostBundleName, recordNum);
977     EXPECT_EQ(result, ERR_NULL_OBJECT);
978     TAG_LOGI(AAFwkTag::TEST, "QueryPreLoadUIExtensionRecordInner_002 end");
979 }
980 /*
981  * Feature: AbilityConnectManager
982  * Function: SuspendExtensionAbilityLocked
983  * SubFunction:
984  * FunctionPoints: SuspendExtensionAbilityLocked and ConnectAbilityLocked
985  * EnvConditions:NA
986  * CaseDescription:Verify the following:
987  * 1. Disconnect ability a nonexistent connect, disconnect failed
988  * 2. If the current connect ability state is not connected, disconnect fails
989  * 3. Verify the success of disconnect ability
990  */
991 HWTEST_F(AbilityConnectManagerFourthTest, AAFWK_Kit_SuspendExtensionAbilityLocked_001, TestSize.Level1)
992 {
993     ConnectManager()->SetTaskHandler(TaskHandler());
994     ConnectManager()->SetEventHandler(EventHandler());
995 
996     auto callback = new AbilityConnectCallback();
997     auto result = ConnectManager()->SuspendExtensionAbilityLocked(callback);
998     EXPECT_EQ(result, OHOS::AAFwk::CONNECTION_NOT_EXIST);
999 
1000     auto result1 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1001     EXPECT_EQ(0, result1);
1002 
1003     auto result2 = ConnectManager()->SuspendExtensionAbilityLocked(callbackA_);
1004     EXPECT_EQ(result2, OHOS::AAFwk::INVALID_CONNECTION_STATE);
1005 
1006     auto list = ConnectManager()->GetConnectRecordListByCallback(callbackA_);
1007     EXPECT_EQ(static_cast<int>(list.size()), 1);
1008 
1009     for (auto& it : list) {
1010         it->SetConnectState(ConnectionState::CONNECTED);
1011     }
1012 
1013     auto result3 = ConnectManager()->SuspendExtensionAbilityLocked(callbackA_);
1014     EXPECT_EQ(result3, OHOS::ERR_OK);
1015 }
1016 
1017 /*
1018  * Feature: AbilityConnectManager
1019  * Function: ResumeExtensionAbilityLocked
1020  * SubFunction:
1021  * FunctionPoints: ResumeExtensionAbilityLocked
1022  * EnvConditions:NA
1023  * CaseDescription:Verify the following:
1024  * 1. If the current connect ability state is not connected, disconnect fails
1025  * 2. Verify the success of ResumeExtensionAbilityLocked ability
1026  */
1027 HWTEST_F(AbilityConnectManagerFourthTest, AAFWK_Kit_ResumeExtensionAbilityLocked_001, TestSize.Level1)
1028 {
1029     ConnectManager()->SetTaskHandler(TaskHandler());
1030     ConnectManager()->SetEventHandler(EventHandler());
1031 
1032     auto callback = new AbilityConnectCallback();
1033 
1034     auto result1 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1035     EXPECT_EQ(0, result1);
1036 
1037     auto result2 = ConnectManager()->ResumeExtensionAbilityLocked(callbackA_);
1038     EXPECT_EQ(result2, OHOS::AAFwk::INVALID_CONNECTION_STATE);
1039 
1040     auto list = ConnectManager()->GetConnectRecordListByCallback(callbackA_);
1041     EXPECT_EQ(static_cast<int>(list.size()), 1);
1042 
1043 
1044     for (auto& it : list) {
1045         it->SetConnectState(ConnectionState::CONNECTED);
1046     }
1047 
1048     ConnectManager()->SuspendExtensionAbilityLocked(callbackA_);
1049 
1050     auto result3 = ConnectManager()->ResumeExtensionAbilityLocked(callbackA_);
1051     EXPECT_EQ(result3, OHOS::ERR_OK);
1052 }
1053 
1054 }  // namespace AAFwk
1055 }  // namespace OHOS
1056