• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 <thread>
37 #include <chrono>
38 
39 using namespace testing::ext;
40 using namespace OHOS::AppExecFwk;
41 using testing::_;
42 using testing::Invoke;
43 using testing::Return;
44 using testing::SetArgReferee;
45 using ::testing::DoAll;
46 
47 namespace {
48     const int32_t SLEEP_TIME = 10000;
49 }
50 
51 namespace OHOS {
52 namespace AAFwk {
53 template<typename F>
WaitUntilTaskCalled(const F & f,const std::shared_ptr<TaskHandlerWrap> & handler,std::atomic<bool> & taskCalled)54 static void WaitUntilTaskCalled(const F& f, const std::shared_ptr<TaskHandlerWrap>& handler,
55     std::atomic<bool>& taskCalled)
56 {
57     const uint32_t maxRetryCount = 1000;
58     const uint32_t sleepTime = 1000;
59     uint32_t count = 0;
60     if (handler->SubmitTask(f)) {
61         while (!taskCalled.load()) {
62             ++count;
63             // if delay more than 1 second, break
64             if (count >= maxRetryCount) {
65                 break;
66             }
67             usleep(sleepTime);
68         }
69     }
70 }
71 
WaitUntilTaskDone(const std::shared_ptr<TaskHandlerWrap> & handler)72 static void WaitUntilTaskDone(const std::shared_ptr<TaskHandlerWrap>& handler)
73 {
74     std::atomic<bool> taskCalled(false);
75     auto f = [&taskCalled]() { taskCalled.store(true); };
76     WaitUntilTaskCalled(f, handler, taskCalled);
77 }
78 
79 class AbilityConnectManagerTest : public testing::Test {
80 public:
81     static void SetUpTestCase(void);
82     static void TearDownTestCase(void);
83     void SetUp();
84     void TearDown();
85 
86     AbilityConnectManager* ConnectManager() const;
87     std::shared_ptr<MockTaskHandlerWrap> TaskHandler() const;
88     std::shared_ptr<EventHandlerWrap> EventHandler() const;
89 
90     AbilityRequest GenerateAbilityRequest(const std::string& deviceName, const std::string& abilityName,
91         const std::string& appName, const std::string& bundleName, const std::string& moduleName);
92 
93     static constexpr int TEST_WAIT_TIME = 1000000;
94 
95     sptr<SessionInfo> MockSessionInfo(int32_t persistentId);
96     std::shared_ptr<AbilityRecord> InitAbilityRecord();
97     std::shared_ptr<MockTaskHandlerWrap> taskHandler_;
98 
99 protected:
100     AbilityRequest abilityRequest_{};
101     AbilityRequest abilityRequest1_{};
102     AbilityRequest abilityRequest2_{};
103     std::shared_ptr<AbilityRecord> serviceRecord_{ nullptr };
104     std::shared_ptr<AbilityRecord> serviceRecord1_{ nullptr };
105     std::shared_ptr<AbilityRecord> serviceRecord2_{ nullptr };
106     OHOS::sptr<Token> serviceToken_{ nullptr };
107     OHOS::sptr<Token> serviceToken1_{ nullptr };
108     OHOS::sptr<Token> serviceToken2_{ nullptr };
109     OHOS::sptr<IAbilityConnection> callbackA_{ nullptr };
110     OHOS::sptr<IAbilityConnection> callbackB_{ nullptr };
111 
112 private:
113     std::shared_ptr<AbilityConnectManager> connectManager_;
114     std::shared_ptr<EventHandlerWrap> eventHandler_;
115 };
116 
GenerateAbilityRequest(const std::string & deviceName,const std::string & abilityName,const std::string & appName,const std::string & bundleName,const std::string & moduleName)117 AbilityRequest AbilityConnectManagerTest::GenerateAbilityRequest(const std::string& deviceName,
118     const std::string& abilityName, const std::string& appName, const std::string& bundleName,
119     const std::string& moduleName)
120 {
121     ElementName element(deviceName, bundleName, abilityName, moduleName);
122     Want want;
123     want.SetElement(element);
124 
125     AbilityInfo abilityInfo;
126     abilityInfo.visible = true;
127     abilityInfo.applicationName = appName;
128     abilityInfo.type = AbilityType::SERVICE;
129     abilityInfo.name = abilityName;
130     abilityInfo.bundleName = bundleName;
131     abilityInfo.moduleName = moduleName;
132     abilityInfo.deviceId = deviceName;
133     ApplicationInfo appinfo;
134     appinfo.name = appName;
135     abilityInfo.applicationInfo = appinfo;
136     AbilityRequest abilityRequest;
137     abilityRequest.want = want;
138     abilityRequest.abilityInfo = abilityInfo;
139     abilityRequest.appInfo = appinfo;
140     abilityInfo.process = bundleName;
141 
142     return abilityRequest;
143 }
144 
MockSessionInfo(int32_t persistentId)145 sptr<SessionInfo> AbilityConnectManagerTest::MockSessionInfo(int32_t persistentId)
146 {
147     sptr<SessionInfo> sessionInfo = new (std::nothrow) SessionInfo();
148     if (!sessionInfo) {
149         TAG_LOGE(AAFwkTag::TEST, "sessionInfo is nullptr");
150         return nullptr;
151     }
152     sessionInfo->persistentId = persistentId;
153     return sessionInfo;
154 }
155 
InitAbilityRecord()156 std::shared_ptr<AbilityRecord> AbilityConnectManagerTest::InitAbilityRecord()
157 {
158     AbilityRequest abilityRequest;
159     abilityRequest.appInfo.bundleName = "com.example.unittest";
160     abilityRequest.abilityInfo.name = "MainAbility";
161     abilityRequest.abilityInfo.type = AbilityType::PAGE;
162     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
163     return abilityRecord;
164 }
165 
SetUpTestCase(void)166 void AbilityConnectManagerTest::SetUpTestCase(void)
167 {}
TearDownTestCase(void)168 void AbilityConnectManagerTest::TearDownTestCase(void)
169 {
170     std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
171 }
172 
SetUp(void)173 void AbilityConnectManagerTest::SetUp(void)
174 {
175     connectManager_ = std::make_unique<AbilityConnectManager>(0);
176     taskHandler_ = MockTaskHandlerWrap::CreateQueueHandler("AbilityConnectManagerTest");
177     eventHandler_ = std::make_shared<EventHandlerWrap>(taskHandler_);
178     // generate ability request
179     std::string deviceName = "device";
180     std::string abilityName = "ServiceAbility";
181     std::string appName = "hiservcie";
182     std::string bundleName = "com.ix.hiservcie";
183     std::string moduleName = "entry";
184     abilityRequest_ = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName, moduleName);
185     serviceRecord_ = AbilityRecord::CreateAbilityRecord(abilityRequest_);
186     serviceToken_ = serviceRecord_->GetToken();
187     std::string deviceName1 = "device";
188     std::string abilityName1 = "musicServiceAbility";
189     std::string appName1 = "musicservcie";
190     std::string bundleName1 = "com.ix.musicservcie";
191     std::string moduleName1 = "entry";
192     abilityRequest1_ = GenerateAbilityRequest(deviceName1, abilityName1, appName1, bundleName1, moduleName1);
193     serviceRecord1_ = AbilityRecord::CreateAbilityRecord(abilityRequest1_);
194     std::string deviceName2 = "device";
195     std::string abilityName2 = "residentServiceAbility";
196     std::string appName2 = "residentservcie";
197     std::string bundleName2 = "com.ix.residentservcie";
198     std::string moduleName2 = "entry";
199     abilityRequest2_ = GenerateAbilityRequest(deviceName2, abilityName2, appName2, bundleName2, moduleName2);
200     serviceRecord2_ = AbilityRecord::CreateAbilityRecord(abilityRequest2_);
201     serviceToken2_ = serviceRecord_->GetToken();
202     serviceToken1_ = serviceRecord_->GetToken();
203     callbackA_ = new AbilityConnectCallback();
204     callbackB_ = new AbilityConnectCallback();
205     // mock bms
206     OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
207         OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
208 }
209 
TearDown(void)210 void AbilityConnectManagerTest::TearDown(void)
211 {
212     // reset the callback count
213     AbilityConnectCallback::onAbilityConnectDoneCount = 0;
214     AbilityConnectCallback::onAbilityDisconnectDoneCount = 0;
215     serviceRecord_ = nullptr;
216 }
217 
ConnectManager() const218 AbilityConnectManager* AbilityConnectManagerTest::ConnectManager() const
219 {
220     return connectManager_.get();
221 }
222 
TaskHandler() const223 std::shared_ptr<MockTaskHandlerWrap> AbilityConnectManagerTest::TaskHandler() const
224 {
225     return taskHandler_;
226 }
227 
EventHandler() const228 std::shared_ptr<EventHandlerWrap> AbilityConnectManagerTest::EventHandler() const
229 {
230     return eventHandler_;
231 }
232 
233 /*
234  * Feature: AbilityConnectManager
235  * Function: StartAbility
236  * SubFunction: NA
237  * FunctionPoints: StartAbility
238  * EnvConditions:NA
239  * CaseDescription: Verify the normal process of startability
240  */
241 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_001, TestSize.Level1)
242 {
243     ConnectManager()->SetTaskHandler(TaskHandler());
244     ConnectManager()->SetEventHandler(EventHandler());
245 
246     auto result = ConnectManager()->StartAbility(abilityRequest_);
247     EXPECT_EQ(OHOS::ERR_OK, result);
248     WaitUntilTaskDone(TaskHandler());
249 
250     auto elementName = abilityRequest_.want.GetElement().GetURI();
251     auto service = ConnectManager()->GetServiceRecordByElementName(elementName);
252     EXPECT_NE(service, nullptr);
253     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 1);
254 
255     service->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
256 
257     auto result1 = ConnectManager()->StartAbility(abilityRequest_);
258     WaitUntilTaskDone(TaskHandler());
259     EXPECT_EQ(OHOS::ERR_OK, result1);
260     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 1);
261 
262     service->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVATING);
263     auto result2 = ConnectManager()->StartAbility(abilityRequest_);
264     WaitUntilTaskDone(TaskHandler());
265     EXPECT_EQ(OHOS::ERR_OK, result2);
266     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 1);
267 }
268 
269 /*
270  * Feature: AbilityConnectManager
271  * Function: TerminateAbility
272  * SubFunction: NA
273  * FunctionPoints: StartAbility and TerminateAbility
274  * EnvConditions:NA
275  * CaseDescription: Verify the following:
276  * 1.token is nullptr, terminate ability failed
277  * 2.token is not nullptr, terminate ability success, and verify the status
278  */
279 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_002, TestSize.Level1)
280 {
281     ConnectManager()->SetTaskHandler(TaskHandler());
282     ConnectManager()->SetEventHandler(EventHandler());
283 
284     auto result = ConnectManager()->StartAbility(abilityRequest_);
285     EXPECT_EQ(OHOS::ERR_OK, result);
286     WaitUntilTaskDone(TaskHandler());
287 
288     OHOS::sptr<OHOS::IRemoteObject> nullToken = nullptr;
289     auto result1 = ConnectManager()->TerminateAbility(nullToken);
290     EXPECT_EQ(OHOS::ERR_INVALID_VALUE, result1);
291 
292     auto elementName = abilityRequest_.want.GetElement().GetURI();
293     auto service = ConnectManager()->GetServiceRecordByElementName(elementName);
294     EXPECT_NE(service, nullptr);
295 
296     auto result2 = ConnectManager()->TerminateAbility(service->GetToken());
297     WaitUntilTaskDone(TaskHandler());
298     EXPECT_EQ(OHOS::ERR_OK, result2);
299     EXPECT_EQ(service->GetAbilityState(), TERMINATING);
300 }
301 
302 /*
303  * Feature: AbilityConnectManager
304  * Function: TerminateAbility
305  * SubFunction: NA
306  * FunctionPoints: StartAbility and TerminateAbility
307  * EnvConditions:NA
308  * CaseDescription: Verify ability is terminating, terminate ability success
309  */
310 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_003, TestSize.Level1)
311 {
312     ConnectManager()->SetTaskHandler(TaskHandler());
313     ConnectManager()->SetEventHandler(EventHandler());
314 
315     auto result = ConnectManager()->StartAbility(abilityRequest_);
316     EXPECT_EQ(OHOS::ERR_OK, result);
317     WaitUntilTaskDone(TaskHandler());
318 
319     auto elementName = abilityRequest_.want.GetElement().GetURI();
320     auto service = ConnectManager()->GetServiceRecordByElementName(elementName);
321     EXPECT_NE(service, nullptr);
322 
323     service->SetTerminatingState();
324     auto result1 = ConnectManager()->TerminateAbility(service->GetToken());
325     WaitUntilTaskDone(TaskHandler());
326     EXPECT_EQ(OHOS::ERR_OK, result1);
327     EXPECT_NE(service->GetAbilityState(), TERMINATING);
328 }
329 
330 /*
331  * Feature: AbilityConnectManager
332  * Function: TerminateAbility
333  * SubFunction: NA
334  * FunctionPoints: StartAbility and TerminateAbility
335  * EnvConditions: NA
336  * CaseDescription: Verify service is connected, terminate ability failed
337  */
338 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_004, TestSize.Level1)
339 {
340     ConnectManager()->SetTaskHandler(TaskHandler());
341     ConnectManager()->SetEventHandler(EventHandler());
342 
343     auto result = ConnectManager()->StartAbility(abilityRequest_);
344     EXPECT_EQ(OHOS::ERR_OK, result);
345     WaitUntilTaskDone(TaskHandler());
346 
347     auto result1 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
348     EXPECT_EQ(0, result1);
349 
350     auto elementName = abilityRequest_.want.GetElement().GetURI();
351     auto service = ConnectManager()->GetServiceRecordByElementName(elementName);
352     EXPECT_NE(service, nullptr);
353 
354     auto result2 = ConnectManager()->TerminateAbility(service->GetToken());
355     WaitUntilTaskDone(TaskHandler());
356     EXPECT_EQ(0, result2);
357     EXPECT_EQ(service->GetAbilityState(), TERMINATING);
358 }
359 
360 /*
361  * Feature: AbilityConnectManager
362  * Function: StopServiceAbility
363  * SubFunction: NA
364  * FunctionPoints: StartAbility and StopServiceAbility
365  * EnvConditions: NA
366  * CaseDescription: Verify the following:
367  * 1.token is nullptr, stop service ability failed
368  * 2.token is not nullptr, stop service ability success, and verify the status
369  */
370 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_005, TestSize.Level1)
371 {
372     ConnectManager()->SetTaskHandler(TaskHandler());
373     ConnectManager()->SetEventHandler(EventHandler());
374 
375     auto result = ConnectManager()->StartAbility(abilityRequest_);
376     EXPECT_EQ(OHOS::ERR_OK, result);
377     WaitUntilTaskDone(TaskHandler());
378 
379     auto elementName = abilityRequest_.want.GetElement().GetURI();
380     auto service = ConnectManager()->GetServiceRecordByElementName(elementName);
381     EXPECT_NE(service, nullptr);
382 
383     AbilityRequest otherRequest;
384     auto result1 = ConnectManager()->StopServiceAbility(otherRequest);
385     WaitUntilTaskDone(TaskHandler());
386     EXPECT_EQ(OHOS::ERR_INVALID_VALUE, result1);
387 
388     auto result2 = ConnectManager()->StopServiceAbility(abilityRequest_);
389     WaitUntilTaskDone(TaskHandler());
390     EXPECT_EQ(OHOS::ERR_OK, result2);
391     EXPECT_EQ(service->GetAbilityState(), TERMINATING);
392 }
393 
394 /*
395  * Feature: AbilityConnectManager
396  * Function: StopServiceAbility
397  * SubFunction: NA
398  * FunctionPoints: StartAbility and StopServiceAbility
399  * EnvConditions:NA
400  * CaseDescription: Verify ability is terminating, stop service ability success
401  */
402 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_006, TestSize.Level1)
403 {
404     ConnectManager()->SetTaskHandler(TaskHandler());
405     ConnectManager()->SetEventHandler(EventHandler());
406 
407     auto result = ConnectManager()->StartAbility(abilityRequest_);
408     EXPECT_EQ(OHOS::ERR_OK, result);
409     WaitUntilTaskDone(TaskHandler());
410 
411     auto elementName = abilityRequest_.want.GetElement().GetURI();
412     auto service = ConnectManager()->GetServiceRecordByElementName(elementName);
413     EXPECT_NE(service, nullptr);
414 
415     service->SetTerminatingState();
416     auto result1 = ConnectManager()->StopServiceAbility(abilityRequest_);
417     WaitUntilTaskDone(TaskHandler());
418     EXPECT_EQ(OHOS::ERR_OK, result1);
419     EXPECT_NE(service->GetAbilityState(), TERMINATING);
420 }
421 
422 /*
423  * Feature: AbilityConnectManager
424  * Function: StopServiceAbility
425  * SubFunction: NA
426  * FunctionPoints: StartAbility and StopServiceAbility
427  * EnvConditions: NA
428  * CaseDescription: Verify service is connected, stop service ability failed
429  */
430 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_007, TestSize.Level1)
431 {
432     ConnectManager()->SetTaskHandler(TaskHandler());
433     ConnectManager()->SetEventHandler(EventHandler());
434 
435     auto result = ConnectManager()->StartAbility(abilityRequest_);
436     EXPECT_EQ(OHOS::ERR_OK, result);
437     WaitUntilTaskDone(TaskHandler());
438 
439     auto result1 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
440     EXPECT_EQ(0, result1);
441 
442     auto elementName = abilityRequest_.want.GetElement().GetURI();
443     auto service = ConnectManager()->GetServiceRecordByElementName(elementName);
444     EXPECT_NE(service, nullptr);
445 
446     auto result2 = ConnectManager()->StopServiceAbility(abilityRequest_);
447     WaitUntilTaskDone(TaskHandler());
448     EXPECT_EQ(0, result2);
449     EXPECT_EQ(service->GetAbilityState(), TERMINATING);
450 }
451 
452 /*
453  * Feature: AbilityConnectManager
454  * Function: ConnectAbilityLocked
455  * SubFunction: NA
456  * FunctionPoints: NA
457  * EnvConditions:NA
458  * CaseDescription: verify the scene of service not loaded and callback not bound.
459  */
460 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_008, TestSize.Level1)
461 {
462     int result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
463     EXPECT_EQ(0, result);
464 
465     auto connectMap = ConnectManager()->connectMap_;
466     auto connectRecordList = connectMap.at(callbackA_->AsObject());
467     EXPECT_EQ(1, static_cast<int>(connectRecordList.size()));
468 
469     auto elementName = abilityRequest_.want.GetElement();
470     auto elementNameUri = elementName.GetURI();
471     auto serviceMap = ConnectManager()->GetServiceMap();
472     auto abilityRecord = serviceMap.at(elementNameUri);
473     connectRecordList = abilityRecord->GetConnectRecordList();
474     EXPECT_EQ(1, static_cast<int>(connectRecordList.size()));
475 }
476 
477 /*
478  * Feature: AbilityConnectManager
479  * Function: ConnectAbilityLocked
480  * SubFunction: NA
481  * FunctionPoints: NA
482  * EnvConditions:NA
483  * CaseDescription: verify the scene of service load ability's timeout.
484  */
485 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_009, TestSize.Level1)
486 {
487     ConnectManager()->SetTaskHandler(TaskHandler());
488     ConnectManager()->SetEventHandler(EventHandler());
489     int result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
490     EXPECT_EQ(0, result);
491 
492     auto connectMap = ConnectManager()->connectMap_;
493     EXPECT_EQ(1, static_cast<int>(connectMap.size()));
494     WaitUntilTaskDone(TaskHandler());
495     usleep(TEST_WAIT_TIME);
496 
497     connectMap = ConnectManager()->connectMap_;
498     EXPECT_EQ(1, static_cast<int>(connectMap.size()));
499 }
500 
501 /*
502  * Feature: AbilityConnectManager
503  * Function: ConnectAbilityLocked
504  * SubFunction: NA
505  * FunctionPoints: NA
506  * EnvConditions:NA
507  * CaseDescription: verify the scene of service loaded and callback not bound.
508  */
509 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_010, TestSize.Level1)
510 {
511     auto result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
512     EXPECT_EQ(0, result);
513 
514     result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackB_, nullptr);
515     EXPECT_EQ(0, result);
516 
517     auto connectMap = ConnectManager()->connectMap_;
518     auto connectRecordList = connectMap.at(callbackA_->AsObject());
519     EXPECT_EQ(1, static_cast<int>(connectRecordList.size()));
520 
521     connectRecordList = connectMap.at(callbackB_->AsObject());
522     EXPECT_EQ(1, static_cast<int>(connectRecordList.size()));
523 
524     auto elementName = abilityRequest_.want.GetElement();
525     std::string elementNameUri = elementName.GetURI();
526     auto serviceMap = ConnectManager()->GetServiceMap();
527     auto abilityRecord = serviceMap.at(elementNameUri);
528     connectRecordList = abilityRecord->GetConnectRecordList();
529     EXPECT_EQ(2, static_cast<int>(connectRecordList.size()));
530 }
531 
532 /*
533  * Feature: AbilityConnectManager
534  * Function: ConnectAbilityLocked
535  * SubFunction: NA
536  * FunctionPoints: NA
537  * EnvConditions:NA
538  * CaseDescription: verify the scene of service connect ability's timeout.
539  */
540 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_011, TestSize.Level1)
541 {
542     ConnectManager()->SetTaskHandler(TaskHandler());
543     ConnectManager()->SetEventHandler(EventHandler());
544 
545     int result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
546     auto elementName = abilityRequest_.want.GetElement();
547     std::string elementNameUri = elementName.GetURI();
548     auto serviceMap = ConnectManager()->GetServiceMap();
549     auto abilityRecord = serviceMap.at(elementNameUri);
550     auto token = abilityRecord->GetToken();
551 
552     auto connectMap = ConnectManager()->connectMap_;
553     EXPECT_EQ(1, static_cast<int>(connectMap.size()));
554 
555     auto scheduler = new AbilityScheduler();
556     ConnectManager()->AttachAbilityThreadLocked(scheduler, token->AsObject());
557     ConnectManager()->AbilityTransitionDone(token->AsObject(), OHOS::AAFwk::AbilityState::INACTIVE);
558 
559     WaitUntilTaskDone(TaskHandler());
560     usleep(TEST_WAIT_TIME);
561     connectMap = ConnectManager()->connectMap_;
562     EXPECT_EQ(0, result);
563     EXPECT_EQ(1, static_cast<int>(connectMap.size()));
564 }
565 
566 /*
567  * Feature: AbilityConnectManager
568  * Function: ConnectAbilityLocked
569  * SubFunction: NA
570  * FunctionPoints: NA
571  * EnvConditions:NA
572  * CaseDescription: verify the scene of service loaded and callback bound.
573  */
574 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_012, TestSize.Level1)
575 {
576     auto result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
577     EXPECT_EQ(0, result);
578 
579     result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
580     EXPECT_EQ(0, result);
581 
582     auto connectMap = ConnectManager()->connectMap_;
583     auto connectRecordList = connectMap.at(callbackA_->AsObject());
584     EXPECT_EQ(1, static_cast<int>(connectRecordList.size()));
585 
586     auto elementName = abilityRequest_.want.GetElement();
587     std::string elementNameUri = elementName.GetURI();
588     auto serviceMap = ConnectManager()->GetServiceMap();
589     auto abilityRecord = serviceMap.at(elementNameUri);
590     connectRecordList = abilityRecord->GetConnectRecordList();
591     EXPECT_EQ(1, static_cast<int>(connectRecordList.size()));
592 }
593 
594 /*
595  * Feature: AbilityConnectManager
596  * Function: ConnectAbilityLocked
597  * SubFunction: NA
598  * FunctionPoints: NA
599  * EnvConditions:NA
600  * CaseDescription: verify the scene of service not loaded and callback bound.
601  */
602 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_013, TestSize.Level1)
603 {
604     int result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
605     EXPECT_EQ(0, result);
606 
607     std::string deviceNameB = "device";
608     std::string abilityNameB = "ServiceAbilityB";
609     std::string appNameB = "hiservcieB";
610     std::string bundleNameB = "com.ix.hiservcieB";
611     std::string moduleNameB = "entry";
612     auto abilityRequestB = GenerateAbilityRequest(deviceNameB, abilityNameB, appNameB, bundleNameB, moduleNameB);
613     result = ConnectManager()->ConnectAbilityLocked(abilityRequestB, callbackA_, nullptr);
614     EXPECT_EQ(0, result);
615 
616     auto connectMap = ConnectManager()->connectMap_;
617     auto connectRecordList = connectMap.at(callbackA_->AsObject());
618     EXPECT_EQ(2, static_cast<int>(connectRecordList.size()));
619 
620     auto elementName = abilityRequest_.want.GetElement();
621     std::string elementNameUri = elementName.GetURI();
622     auto serviceMap = ConnectManager()->GetServiceMap();
623     auto abilityRecord = serviceMap.at(elementNameUri);
624     connectRecordList = abilityRecord->GetConnectRecordList();
625     EXPECT_EQ(1, static_cast<int>(connectRecordList.size()));
626 
627     auto elementNameB = abilityRequest_.want.GetElement();
628     std::string elementNameUriB = elementNameB.GetURI();
629     abilityRecord = serviceMap.at(elementNameUriB);
630     connectRecordList = abilityRecord->GetConnectRecordList();
631     EXPECT_EQ(1, static_cast<int>(connectRecordList.size()));
632 }
633 
634 /*
635  * Feature: AbilityConnectManager
636  * Function: ConnectAbilityLocked
637  * SubFunction: NA
638  * FunctionPoints: NA
639  * EnvConditions:NA
640  * CaseDescription: verify the scene of service loaded and callback bound, but service and callback was not associated.
641  */
642 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_014, TestSize.Level1)
643 {
644     auto result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
645     EXPECT_EQ(0, result);
646 
647     std::string deviceNameB = "device";
648     std::string abilityNameB = "ServiceAbilityB";
649     std::string appNameB = "hiservcieB";
650     std::string bundleNameB = "com.ix.hiservcieB";
651     std::string moduleNameB = "entry";
652     auto abilityRequestB = GenerateAbilityRequest(deviceNameB, abilityNameB, appNameB, bundleNameB, moduleNameB);
653     result = ConnectManager()->ConnectAbilityLocked(abilityRequestB, callbackB_, nullptr);
654     EXPECT_EQ(0, result);
655 
656     ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackB_, nullptr);
657     auto connectMap = ConnectManager()->connectMap_;
658     auto connectRecordList = connectMap.at(callbackB_->AsObject());
659     EXPECT_EQ(2, static_cast<int>(connectRecordList.size()));
660 
661     connectRecordList = connectMap.at(callbackA_->AsObject());
662     EXPECT_EQ(1, static_cast<int>(connectRecordList.size()));
663 
664     auto elementName = abilityRequest_.want.GetElement();
665     std::string elementNameUri = elementName.GetURI();
666     auto serviceMap = ConnectManager()->GetServiceMap();
667     auto abilityRecord = serviceMap.at(elementNameUri);
668     connectRecordList = abilityRecord->GetConnectRecordList();
669     EXPECT_EQ(2, static_cast<int>(connectRecordList.size()));
670 }
671 
672 /*
673  * Feature: AbilityConnectManager
674  * Function: AttachAbilityThreadLocked
675  * SubFunction: NA
676  * FunctionPoints: NA
677  * EnvConditions:NA
678  * CaseDescription: verify the AttachAbilityThreadLocked function when the parameter is null.
679  */
680 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_015, TestSize.Level1)
681 {
682     auto result = ConnectManager()->AttachAbilityThreadLocked(nullptr, nullptr);
683     EXPECT_EQ(OHOS::ERR_INVALID_VALUE, result);
684 }
685 
686 /*
687  * Feature: AbilityConnectManager
688  * Function: ScheduleConnectAbilityDoneLocked
689  * SubFunction: NA
690  * FunctionPoints: NA
691  * EnvConditions:NA
692  * CaseDescription: verify the ScheduleConnectAbilityDoneLocked function when the parameter is null.
693  */
694 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_016, TestSize.Level1)
695 {
696     auto callback = new AbilityConnectCallback();
697     auto result = ConnectManager()->ScheduleConnectAbilityDoneLocked(nullptr, callback);
698     EXPECT_EQ(OHOS::ERR_INVALID_VALUE, result);
699 }
700 
701 /*
702  * Feature: AbilityConnectManager
703  * Function: ScheduleConnectAbilityDoneLocked
704  * SubFunction: NA
705  * FunctionPoints: NA
706  * EnvConditions:NA
707  * CaseDescription: verify the ScheduleConnectAbilityDoneLocked function when the state is CONNECTED.
708  */
709 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_017, TestSize.Level1)
710 {
711     auto callback = new AbilityConnectCallback();
712     ConnectManager()->ConnectAbilityLocked(abilityRequest_, callback, nullptr);
713 
714     auto elementName = abilityRequest_.want.GetElement();
715     std::string elementNameUri = elementName.GetURI();
716     auto serviceMap = ConnectManager()->GetServiceMap();
717     auto abilityRecord = serviceMap.at(elementNameUri);
718     auto token = abilityRecord->GetToken();
719 
720     abilityRecord->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
721     ConnectManager()->ScheduleConnectAbilityDoneLocked(token, callback);
722     auto abilityRecordB = Token::GetAbilityRecordByToken(token);
723     EXPECT_TRUE(abilityRecordB);
724     auto connectRecordList = abilityRecordB->GetConnectRecordList();
725     int size = connectRecordList.size();
726     EXPECT_EQ(1, size);
727     if (size != 0) {
728         auto connState = (*(connectRecordList.begin()))->GetConnectState();
729         EXPECT_EQ(ConnectionState::CONNECTED, connState);
730     }
731 }
732 
733 /*
734  * Feature: AbilityConnectManager
735  * Function: GetActiveUIExtensionList
736  * SubFunction: NA
737  * FunctionPoints: NA
738  * EnvConditions:NA
739  * CaseDescription: verify the GetActiveUIExtensionList function.
740  */
741 HWTEST_F(AbilityConnectManagerTest, GetActiveUIExtensionList_01, TestSize.Level1)
742 {
743     int32_t pid = 1;
744     std::vector<std::string> extensionList;
745     auto result = ConnectManager()->GetActiveUIExtensionList(pid, extensionList);
746     EXPECT_EQ(result, ERR_OK);
747 
748     std::string bundleName = "com.test.demo";
749     result = ConnectManager()->GetActiveUIExtensionList(bundleName, extensionList);
750     EXPECT_EQ(result, ERR_OK);
751 }
752 
753 /*
754  * Feature: AbilityConnectManager
755  * Function: ScheduleConnectAbilityDoneLocked
756  * SubFunction: NA
757  * FunctionPoints: NA
758  * EnvConditions:NA
759  * CaseDescription: verify the input parameters.
760  */
761 HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Connect_001, TestSize.Level1)
762 {
763     // start test
764     // test1 for serviceToken is null but remoteObject is valid
765     OHOS::sptr<OHOS::IRemoteObject> object = new AbilityConnectCallback();
766     int ret = ConnectManager()->ScheduleConnectAbilityDoneLocked(nullptr, object);
767     EXPECT_EQ(OHOS::ERR_INVALID_VALUE, ret);
768 
769     // test2 for both of serviceToken and remoteObject are null
770     ret = ConnectManager()->ScheduleConnectAbilityDoneLocked(nullptr, nullptr);
771     EXPECT_EQ(OHOS::ERR_INVALID_VALUE, ret);
772 }
773 
774 /*
775  * Feature: AbilityConnectManager
776  * Function: ScheduleConnectAbilityDoneLocked
777  * SubFunction: NA
778  * FunctionPoints: NA
779  * EnvConditions:NA
780  * CaseDescription: verify the input serviceToken which corresponding ability record doesn't exist.
781  */
782 HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Connect_002, TestSize.Level1)
783 {
784     // test for serviceToken's abilityRecord is null
785     serviceRecord_ = nullptr;
786     int ret = ConnectManager()->ScheduleConnectAbilityDoneLocked(serviceToken_, nullptr);
787     EXPECT_EQ(OHOS::ERR_INVALID_VALUE, ret);
788 }
789 
790 /*
791  * Feature: AbilityConnectManager
792  * Function: ScheduleConnectAbilityDoneLocked
793  * SubFunction: OnAbilityConnectDone
794  * FunctionPoints: NA
795  * EnvConditions:NA
796  * CaseDescription: verify the input serviceToken which corresponding connection list is empty.
797  */
798 HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Connect_003, TestSize.Level1)
799 {
800     // test for serviceToken's connection list is null
801     // start test
802     auto callback = new AbilityConnectCallback();
803     int ret = ConnectManager()->ScheduleConnectAbilityDoneLocked(serviceToken_, callback);
804     EXPECT_EQ(OHOS::AAFwk::INVALID_CONNECTION_STATE, ret);
805     auto connList = serviceRecord_->GetConnectRecordList();
806     EXPECT_EQ(true, connList.empty());  // the connection list size should be empty
807 }
808 
809 /*
810  * Feature: AbilityConnectManager
811  * Function: ScheduleConnectAbilityDoneLocked
812  * SubFunction: OnAbilityConnectDone
813  * FunctionPoints: NA
814  * EnvConditions:NA
815  * CaseDescription: verify the input serviceToken which corresponding connection list members' state
816  * is not CONNECTING or CONNECTED.
817  */
818 HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Connect_004, TestSize.Level1)
819 {
820     // test for schedule the service connected done but the corresponding connection state is not CONNECTING
821     // generate the first connection record of callbackA_
822     auto newConnRecord1 = ConnectionRecord::CreateConnectionRecord(
823         serviceToken_, serviceRecord_, callbackA_, nullptr);  // newConnRecord1's default state is INIT
824     serviceRecord_->AddConnectRecordToList(newConnRecord1);
825     // generate the second connection record of callbackB_
826     auto newConnRecord2 = ConnectionRecord::CreateConnectionRecord(serviceToken_, serviceRecord_, callbackB_, nullptr);
827     newConnRecord2->SetConnectState(ConnectionState::DISCONNECTING);  // newConnRecord2's state is DISCONNECTING
828     serviceRecord_->AddConnectRecordToList(newConnRecord2);
829     auto connList = serviceRecord_->GetConnectRecordList();
830     EXPECT_EQ(2, static_cast<int>(connList.size()));  // the connection list members should be two
831     // start test
832     auto callback = new AbilityConnectCallback();
833     serviceRecord_->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
834     int ret = ConnectManager()->ScheduleConnectAbilityDoneLocked(serviceToken_, callback);
835     EXPECT_EQ(OHOS::ERR_OK, ret);  // the result should be OK
836     // connection callback should not be called, so check the count
837     EXPECT_EQ(0, AbilityConnectCallback::onAbilityConnectDoneCount);
838     EXPECT_EQ(0, AbilityConnectCallback::onAbilityDisconnectDoneCount);
839 }
840 
841 /*
842  * Feature: AbilityConnectManager
843  * Function: ScheduleConnectAbilityDoneLocked
844  * SubFunction: OnAbilityConnectDone
845  * FunctionPoints: NA
846  * EnvConditions:NA
847  * CaseDescription: verify the scene : 1.serviceToken's corresponding connection list member's state is CONNECTING.
848  * 2.But the connection callback is null.
849  */
850 HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Connect_005, TestSize.Level1)
851 {
852     // test for schedule the service connected done but the corresponding connection state is not CONNECTING
853     // generate the first connection record of null
854     auto newConnRecord1 = ConnectionRecord::CreateConnectionRecord(
855         serviceToken_, serviceRecord_, nullptr, nullptr);  // newConnRecord1's default state is INIT
856     serviceRecord_->AddConnectRecordToList(newConnRecord1);
857     newConnRecord1->SetConnectState(ConnectionState::CONNECTING);  // newConnRecord1's state is CONNECTING
858     auto connList = serviceRecord_->GetConnectRecordList();
859     EXPECT_EQ(1, static_cast<int>(connList.size()));  // the connection list members should be zero
860     // start test
861     auto callback = new AbilityConnectCallback();
862     serviceRecord_->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
863     int ret = ConnectManager()->ScheduleConnectAbilityDoneLocked(serviceToken_, callback);
864     EXPECT_EQ(OHOS::ERR_OK, ret);  // the result should be OK
865     // connection callback should not be called, so check the count
866     EXPECT_EQ(0, AbilityConnectCallback::onAbilityConnectDoneCount);
867 }
868 
869 /*
870  * Feature: AbilityConnectManager
871  * Function: ScheduleConnectAbilityDoneLocked
872  * SubFunction: OnAbilityConnectDone
873  * FunctionPoints: NA
874  * EnvConditions:NA
875  * CaseDescription: verify the scene : 1.serviceToken's corresponding connection list member's state is CONNECTED.
876  * 2.But the connection callback is null.
877  */
878 HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Connect_006, TestSize.Level1)
879 {
880     // test for schedule the service connected done but the corresponding connection state is not CONNECTING
881     // generate the first connection record of null
882     auto newConnRecord1 = ConnectionRecord::CreateConnectionRecord(
883         serviceToken_, serviceRecord_, nullptr, nullptr);  // newConnRecord1's default state is INIT
884     serviceRecord_->AddConnectRecordToList(newConnRecord1);
885     newConnRecord1->SetConnectState(ConnectionState::CONNECTED);  // newConnRecord1's state is CONNECTED
886     auto connList = serviceRecord_->GetConnectRecordList();
887     EXPECT_EQ(1, static_cast<int>(connList.size()));  // the connection list members should be zero
888     // start test
889     auto callback = new AbilityConnectCallback();
890     serviceRecord_->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
891     int ret = ConnectManager()->ScheduleConnectAbilityDoneLocked(serviceToken_, callback);
892     EXPECT_EQ(OHOS::ERR_OK, ret);  // the result should be OK
893     // connection callback should not be called, so check the count
894     EXPECT_EQ(0, AbilityConnectCallback::onAbilityConnectDoneCount);
895 }
896 
897 /*
898  * Feature: AbilityConnectManager
899  * Function: ScheduleConnectAbilityDoneLocked
900  * SubFunction: OnAbilityConnectDone
901  * FunctionPoints: NA
902  * EnvConditions:NA
903  * CaseDescription: verify the scene : 1.serviceToken's corresponding connection list member's state is CONNECTING.
904  * 2.But the connection callback is valid.
905  */
906 HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Connect_007, TestSize.Level1)
907 {
908     // test for schedule the service connected done but the corresponding connection state is not CONNECTING
909     // generate the first connection record of callbackA_
910     auto newConnRecord1 = ConnectionRecord::CreateConnectionRecord(
911         serviceToken_, serviceRecord_, callbackA_, nullptr);  // newConnRecord1's default state is INIT
912     serviceRecord_->AddConnectRecordToList(newConnRecord1);
913     // generate the second connection record of callbackB_
914     auto newConnRecord2 = ConnectionRecord::CreateConnectionRecord(serviceToken_, serviceRecord_, callbackB_, nullptr);
915     newConnRecord2->SetConnectState(ConnectionState::CONNECTING);  // newConnRecord2's state is CONNECTING
916     serviceRecord_->AddConnectRecordToList(newConnRecord2);
917     auto connList = serviceRecord_->GetConnectRecordList();
918     EXPECT_EQ(2, static_cast<int>(connList.size()));  // the connection list members should be two
919     // start test
920     auto callback = new AbilityConnectCallback();
921     serviceRecord_->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
922     int ret = ConnectManager()->ScheduleConnectAbilityDoneLocked(serviceToken_, callback);
923     EXPECT_EQ(OHOS::ERR_OK, ret);  // the result should be OK
924     // connection callback should not be called, so check the count
925     EXPECT_EQ(0, AbilityConnectCallback::onAbilityConnectDoneCount);
926     EXPECT_EQ(0, AbilityConnectCallback::onAbilityDisconnectDoneCount);
927 }
928 
929 /*
930  * Feature: AbilityConnectManager
931  * Function: ScheduleConnectAbilityDoneLocked
932  * SubFunction: OnAbilityConnectDone
933  * FunctionPoints: NA
934  * EnvConditions:NA
935  * CaseDescription: verify the scene : 1.serviceToken's corresponding connection list member's state is CONNECTED.
936  * 2.But the connection callback is valid.
937  */
938 HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Connect_008, TestSize.Level1)
939 {
940     // test for schedule the service connected done but the corresponding connection state is not CONNECTING
941     // generate the first connection record of callbackA_
942     auto newConnRecord1 = ConnectionRecord::CreateConnectionRecord(
943         serviceToken_, serviceRecord_, callbackA_, nullptr);               // newConnRecord1's default state is INIT
944     newConnRecord1->SetConnectState(ConnectionState::CONNECTED);  // newConnRecord1's state is CONNECTED
945     serviceRecord_->AddConnectRecordToList(newConnRecord1);
946     // generate the second connection record of callbackB_
947     auto newConnRecord2 = ConnectionRecord::CreateConnectionRecord(serviceToken_, serviceRecord_, callbackB_, nullptr);
948     newConnRecord2->SetConnectState(ConnectionState::CONNECTING);  // newConnRecord2's state is CONNECTING
949     serviceRecord_->AddConnectRecordToList(newConnRecord2);
950     // generate the third connection record of callbackC
951     auto callbackC = new AbilityConnectCallback();
952     auto newConnRecord3 = ConnectionRecord::CreateConnectionRecord(serviceToken_, serviceRecord_, callbackC, nullptr);
953     newConnRecord3->SetConnectState(ConnectionState::CONNECTING);  // newConnRecord3's state is CONNECTING
954     serviceRecord_->AddConnectRecordToList(newConnRecord3);
955     auto connList = serviceRecord_->GetConnectRecordList();
956     EXPECT_EQ(3, static_cast<int>(connList.size()));  // the connection list members should be three
957     // start test
958     auto callback = new AbilityConnectCallback();
959     serviceRecord_->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
960     int ret = ConnectManager()->ScheduleConnectAbilityDoneLocked(serviceToken_, callback);
961     EXPECT_EQ(OHOS::ERR_OK, ret);  // the result should be OK
962     // connection callback should not be called, so check the count
963     EXPECT_EQ(0, AbilityConnectCallback::onAbilityConnectDoneCount);
964     EXPECT_EQ(0, AbilityConnectCallback::onAbilityDisconnectDoneCount);
965 }
966 
967 /*
968  * Feature: AbilityConnectManager
969  * Function: DisconnectAbilityLocked
970  * SubFunction:
971  * FunctionPoints: DisconnectAbilityLocked and ConnectAbilityLocked
972  * EnvConditions:NA
973  * CaseDescription:Verify the following:
974  * 1. Disconnect ability a nonexistent connect, disconnect failed
975  * 2. If the current connect ability state is not connected, disconnect fails
976  * 3. Verify the success of disconnect ability
977  */
978 HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Disconnect_001, TestSize.Level1)
979 {
980     ConnectManager()->SetTaskHandler(TaskHandler());
981     ConnectManager()->SetEventHandler(EventHandler());
982 
983     auto callback = new AbilityConnectCallback();
984     auto result = ConnectManager()->DisconnectAbilityLocked(callback);
985     EXPECT_EQ(result, OHOS::AAFwk::CONNECTION_NOT_EXIST);
986 
987     auto result1 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
988     EXPECT_EQ(0, result1);
989 
990     auto result2 = ConnectManager()->DisconnectAbilityLocked(callbackA_);
991     EXPECT_EQ(result2, OHOS::AAFwk::INVALID_CONNECTION_STATE);
992 
993     auto list = ConnectManager()->GetConnectRecordListByCallback(callbackA_);
994     EXPECT_EQ(static_cast<int>(list.size()), 1);
995 
996     for (auto& it : list) {
997         it->SetConnectState(ConnectionState::CONNECTED);
998     }
999 
1000     auto result3 = ConnectManager()->DisconnectAbilityLocked(callbackA_);
1001     EXPECT_EQ(result3, OHOS::ERR_OK);
1002 }
1003 
1004 /*
1005  * Feature: AbilityConnectManager
1006  * Function: DisconnectAbilityLocked
1007  * SubFunction:
1008  * FunctionPoints: DisconnectAbilityLocked and ConnectAbilityLocked
1009  * EnvConditions:NA
1010  * CaseDescription: Results after verifying the disconnect ability
1011  */
1012 HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Disconnect_002, TestSize.Level1)
1013 {
1014     ConnectManager()->SetTaskHandler(TaskHandler());
1015     ConnectManager()->SetEventHandler(EventHandler());
1016 
1017     auto result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1018     EXPECT_EQ(0, result);
1019 
1020     auto result1 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackB_, nullptr);
1021     EXPECT_EQ(0, result1);
1022 
1023     auto result2 = ConnectManager()->ConnectAbilityLocked(abilityRequest1_, callbackA_, nullptr);
1024     EXPECT_EQ(0, result2);
1025 
1026     auto result3 = ConnectManager()->ConnectAbilityLocked(abilityRequest1_, callbackB_, nullptr);
1027     EXPECT_EQ(0, result3);
1028 
1029     auto listA = ConnectManager()->GetConnectRecordListByCallback(callbackA_);
1030     EXPECT_EQ(static_cast<int>(listA.size()), 2);
1031 
1032     for (auto& it : listA) {
1033         it->SetConnectState(ConnectionState::CONNECTED);
1034     }
1035 
1036     auto listB = ConnectManager()->GetConnectRecordListByCallback(callbackB_);
1037     EXPECT_EQ(static_cast<int>(listB.size()), 2);
1038 
1039     for (auto& it : listB) {
1040         it->SetConnectState(ConnectionState::CONNECTED);
1041     }
1042 
1043     auto result5 = ConnectManager()->DisconnectAbilityLocked(callbackA_);
1044     WaitUntilTaskDone(TaskHandler());
1045     EXPECT_EQ(result5, OHOS::ERR_OK);
1046     auto serviceMap = ConnectManager()->GetServiceMap();
1047     EXPECT_EQ(static_cast<int>(serviceMap.size()), 2);
1048 
1049     auto connectMap = ConnectManager()->connectMap_;
1050     EXPECT_EQ(static_cast<int>(connectMap.size()), 1);
1051     for (auto& it : connectMap) {
1052         EXPECT_EQ(static_cast<int>(it.second.size()), 2);
1053     }
1054 }
1055 
1056 /*
1057  * Feature: AbilityConnectManager
1058  * Function: AbilityTransitionDone
1059  * SubFunction: NA
1060  * FunctionPoints: AbilityTransitionDone
1061  * EnvConditions:NA
1062  * CaseDescription: Verify the abilitytransitiondone process
1063  */
1064 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_019, TestSize.Level1)
1065 {
1066     OHOS::sptr<OHOS::IRemoteObject> nullToken = nullptr;
1067     auto result = ConnectManager()->AbilityTransitionDone(nullToken, OHOS::AAFwk::AbilityState::INACTIVE);
1068     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
1069 
1070     ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1071     auto elementName = abilityRequest_.want.GetElement();
1072     std::string elementNameUri = elementName.GetURI();
1073     auto serviceMap = ConnectManager()->GetServiceMap();
1074     auto abilityRecord = serviceMap.at(elementNameUri);
1075     auto token = abilityRecord->GetToken();
1076 
1077     auto result1 = ConnectManager()->AbilityTransitionDone(token, OHOS::AAFwk::AbilityState::INACTIVE);
1078     EXPECT_EQ(result1, OHOS::ERR_INVALID_VALUE);
1079 
1080     ConnectManager()->MoveToTerminatingMap(abilityRecord);
1081     auto result2 = ConnectManager()->AbilityTransitionDone(token, OHOS::AAFwk::AbilityState::INITIAL);
1082     EXPECT_EQ(result2, OHOS::ERR_OK);
1083 
1084     auto result3 = ConnectManager()->AbilityTransitionDone(token, OHOS::AAFwk::AbilityState::TERMINATING);
1085     EXPECT_EQ(result3, OHOS::ERR_INVALID_VALUE);
1086 }
1087 
1088 /*
1089  * Feature: AbilityConnectManager
1090  * Function: ScheduleDisconnectAbilityDoneLocked
1091  * SubFunction: NA
1092  * FunctionPoints: ScheduleDisconnectAbilityDoneLocked
1093  * EnvConditions:NA
1094  * CaseDescription: Verify the ScheduleDisconnectAbilityDoneLocked process
1095  */
1096 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_020, TestSize.Level1)
1097 {
1098     ConnectManager()->SetTaskHandler(TaskHandler());
1099     ConnectManager()->SetEventHandler(EventHandler());
1100 
1101     OHOS::sptr<OHOS::IRemoteObject> nullToken = nullptr;
1102     auto result = ConnectManager()->ScheduleDisconnectAbilityDoneLocked(nullToken);
1103     EXPECT_EQ(result, OHOS::AAFwk::CONNECTION_NOT_EXIST);
1104 
1105     std::shared_ptr<AbilityRecord> ability = nullptr;
1106     OHOS::sptr<OHOS::IRemoteObject> token1 = new OHOS::AAFwk::Token(ability);
1107     auto result1 = ConnectManager()->ScheduleDisconnectAbilityDoneLocked(token1);
1108     EXPECT_EQ(result1, OHOS::AAFwk::CONNECTION_NOT_EXIST);
1109 
1110     ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1111     auto elementName = abilityRequest_.want.GetElement();
1112     std::string elementNameUri = elementName.GetURI();
1113     auto serviceMap = ConnectManager()->GetServiceMap();
1114     auto abilityRecord = serviceMap.at(elementNameUri);
1115     auto token = abilityRecord->GetToken();
1116 
1117     auto listA = ConnectManager()->GetConnectRecordListByCallback(callbackA_);
1118     for (auto& it : listA) {
1119         it->SetConnectState(ConnectionState::CONNECTED);
1120     }
1121 
1122     auto result2 = ConnectManager()->DisconnectAbilityLocked(callbackA_);
1123     WaitUntilTaskDone(TaskHandler());
1124     EXPECT_EQ(result2, OHOS::ERR_OK);
1125 
1126     auto result3 = ConnectManager()->ScheduleDisconnectAbilityDoneLocked(token);
1127     EXPECT_EQ(result3, OHOS::AAFwk::INVALID_CONNECTION_STATE);
1128 
1129     abilityRecord->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
1130 
1131     auto result4 = ConnectManager()->ScheduleDisconnectAbilityDoneLocked(token);
1132     EXPECT_EQ(result4, OHOS::ERR_OK);
1133 }
1134 
1135 /*
1136  * Feature: AbilityConnectManager
1137  * Function: ScheduleCommandAbilityDoneLocked
1138  * SubFunction: NA
1139  * FunctionPoints: ScheduleCommandAbilityDoneLocked
1140  * EnvConditions:NA
1141  * CaseDescription: Verify the ScheduleCommandAbilityDoneLocked process
1142  */
1143 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_021, TestSize.Level1)
1144 {
1145     ConnectManager()->SetTaskHandler(TaskHandler());
1146     ConnectManager()->SetEventHandler(EventHandler());
1147 
1148     OHOS::sptr<OHOS::IRemoteObject> nullToken = nullptr;
1149     auto result = ConnectManager()->ScheduleCommandAbilityDoneLocked(nullToken);
1150     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
1151 
1152     std::shared_ptr<AbilityRecord> ability = nullptr;
1153     OHOS::sptr<OHOS::IRemoteObject> token1 = new OHOS::AAFwk::Token(ability);
1154     auto result1 = ConnectManager()->ScheduleCommandAbilityDoneLocked(token1);
1155     EXPECT_EQ(result1, OHOS::ERR_INVALID_VALUE);
1156 
1157     ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1158     auto elementName = abilityRequest_.want.GetElement();
1159     std::string elementNameUri = elementName.GetURI();
1160     auto serviceMap = ConnectManager()->GetServiceMap();
1161     auto abilityRecord = serviceMap.at(elementNameUri);
1162     auto token = abilityRecord->GetToken();
1163 
1164     auto result2 = ConnectManager()->ScheduleCommandAbilityDoneLocked(token);
1165     EXPECT_EQ(result2, OHOS::AAFwk::INVALID_CONNECTION_STATE);
1166 
1167     abilityRecord->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
1168     auto result3 = ConnectManager()->ScheduleCommandAbilityDoneLocked(token);
1169     EXPECT_EQ(result3, OHOS::ERR_OK);
1170 }
1171 
1172 /*
1173  * Feature: AbilityConnectManager
1174  * Function: GetExtensionByTokenFromServiceMap
1175  * SubFunction: NA
1176  * FunctionPoints: GetExtensionByTokenFromServiceMap
1177  * EnvConditions:NA
1178  * CaseDescription: Verify the GetExtensionByTokenFromServiceMap process
1179  */
1180 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_022, TestSize.Level1)
1181 {
1182     ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1183     auto elementName = abilityRequest_.want.GetElement();
1184     std::string elementNameUri = elementName.GetURI();
1185     auto serviceMap = ConnectManager()->GetServiceMap();
1186     auto abilityRecord = serviceMap.at(elementNameUri);
1187     auto token = abilityRecord->GetToken();
1188 
1189     auto ability = ConnectManager()->GetExtensionByTokenFromServiceMap(token);
1190     EXPECT_EQ(abilityRecord, ability);
1191 
1192     OHOS::sptr<OHOS::IRemoteObject> nullToken = nullptr;
1193     auto ability1 = ConnectManager()->GetExtensionByTokenFromServiceMap(nullToken);
1194     EXPECT_EQ(nullptr, ability1);
1195 
1196     auto recordId = abilityRecord->GetAbilityRecordId();
1197     EXPECT_EQ(ConnectManager()->GetExtensionByIdFromServiceMap(recordId), abilityRecord);
1198     EXPECT_EQ(ConnectManager()->GetExtensionByIdFromServiceMap(0), nullptr);
1199 }
1200 
1201 /*
1202  * Feature: AbilityConnectManager
1203  * Function: OnAbilityDied
1204  * SubFunction:
1205  * FunctionPoints: OnAbilityDied
1206  * EnvConditions:NA
1207  * CaseDescription: Verify the OnAbilityDied process
1208  */
1209 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_024, TestSize.Level1)
1210 {
1211     ConnectManager()->SetTaskHandler(TaskHandler());
1212     ConnectManager()->SetEventHandler(EventHandler());
1213 
1214     auto result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1215     EXPECT_EQ(0, result);
1216 
1217     auto result1 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackB_, nullptr);
1218     EXPECT_EQ(0, result1);
1219 
1220     auto result2 = ConnectManager()->ConnectAbilityLocked(abilityRequest1_, callbackA_, nullptr);
1221     EXPECT_EQ(0, result2);
1222 
1223     auto result3 = ConnectManager()->ConnectAbilityLocked(abilityRequest1_, callbackB_, nullptr);
1224     EXPECT_EQ(0, result3);
1225 
1226     auto listA = ConnectManager()->GetConnectRecordListByCallback(callbackA_);
1227     EXPECT_EQ(static_cast<int>(listA.size()), 2);
1228 
1229     for (auto& it : listA) {
1230         it->SetConnectState(ConnectionState::CONNECTED);
1231     }
1232 
1233     auto listB = ConnectManager()->GetConnectRecordListByCallback(callbackB_);
1234     EXPECT_EQ(static_cast<int>(listB.size()), 2);
1235 
1236     for (auto& it : listB) {
1237         it->SetConnectState(ConnectionState::CONNECTED);
1238     }
1239 
1240     auto elementName = abilityRequest_.want.GetElement();
1241     std::string elementNameUri = elementName.GetURI();
1242     auto serviceMap = ConnectManager()->GetServiceMap();
1243     auto abilityRecord = serviceMap.at(elementNameUri);
1244     auto token = abilityRecord->GetToken();
1245 
1246     int userId = 0;
__anon13414c6a0302() 1247     auto task = [abilityRecord, connectManager = ConnectManager(), userId]() {
1248         connectManager->HandleAbilityDiedTask(abilityRecord, userId);
1249     };
1250     EXPECT_CALL(*taskHandler_, SubmitTaskInner(_, _)).WillRepeatedly(DoAll(SetArgReferee<0>(task),
1251         testing::Invoke(taskHandler_.get(), &MockTaskHandlerWrap::MockTaskHandler)));
1252     ConnectManager()->OnAbilityDied(abilityRecord, 0);
1253     auto list = abilityRecord->GetConnectRecordList();
1254     EXPECT_EQ(static_cast<int>(list.size()), 0);
1255 
1256     auto elementName1 = abilityRequest1_.want.GetElement();
1257     std::string elementNameUri1 = elementName1.GetURI();
1258     serviceMap = ConnectManager()->GetServiceMap();
1259     auto abilityRecord1 = serviceMap.at(elementNameUri1);
1260     auto token1 = abilityRecord1->GetToken();
__anon13414c6a0402() 1261     auto task1 = [abilityRecord1, connectManager = ConnectManager(), userId]() {
1262         connectManager->HandleAbilityDiedTask(abilityRecord1, userId);
1263     };
1264     EXPECT_CALL(*taskHandler_, SubmitTaskInner(_, _)).WillRepeatedly(DoAll(SetArgReferee<0>(task1),
1265         testing::Invoke(taskHandler_.get(), &MockTaskHandlerWrap::MockTaskHandler)));
1266     ConnectManager()->OnAbilityDied(abilityRecord1, 0);
1267     auto list1 = abilityRecord1->GetConnectRecordList();
1268     EXPECT_EQ(static_cast<int>(list1.size()), 0);
1269 }
1270 
1271 /*
1272  * Feature: AbilityConnectManager
1273  * Function: DispatchInactive
1274  * SubFunction:
1275  * FunctionPoints: DispatchInactive
1276  * EnvConditions:NA
1277  * CaseDescription: Verify the DispatchInactive process
1278  */
1279 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_025, TestSize.Level1)
1280 {
1281     std::shared_ptr<AbilityRecord> ability = nullptr;
1282     auto result = ConnectManager()->DispatchInactive(ability, OHOS::AAFwk::AbilityState::INACTIVATING);
1283     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
1284 
1285     ConnectManager()->SetTaskHandler(TaskHandler());
1286     ConnectManager()->SetEventHandler(EventHandler());
1287 
1288     auto result3 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1289     EXPECT_EQ(0, result3);
1290 
1291     auto elementName = abilityRequest_.want.GetElement();
1292     std::string elementNameUri = elementName.GetURI();
1293     auto serviceMap = ConnectManager()->GetServiceMap();
1294     auto abilityRecord = serviceMap.at(elementNameUri);
1295     auto token = abilityRecord->GetToken();
1296 
1297     abilityRecord->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
1298     auto result1 = ConnectManager()->DispatchInactive(abilityRecord, OHOS::AAFwk::AbilityState::INACTIVATING);
1299     EXPECT_EQ(result1, OHOS::ERR_INVALID_VALUE);
1300 
1301     abilityRecord->SetAbilityState(OHOS::AAFwk::AbilityState::INACTIVATING);
1302     auto result2 = ConnectManager()->DispatchInactive(abilityRecord, OHOS::AAFwk::AbilityState::INACTIVATING);
1303     EXPECT_EQ(result2, OHOS::ERR_OK);
1304     EXPECT_EQ(abilityRecord->GetAbilityState(), OHOS::AAFwk::AbilityState::INACTIVE);
1305 }
1306 
1307 /*
1308  * Feature: AbilityConnectManager
1309  * Function: DispatchInactive
1310  * SubFunction:
1311  * FunctionPoints: DispatchInactive
1312  * EnvConditions:NA
1313  * CaseDescription: Verify the DispatchInactive process
1314  */
1315 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_026, TestSize.Level1)
1316 {
1317     std::shared_ptr<AbilityRecord> ability = nullptr;
1318     auto result = ConnectManager()->DispatchInactive(ability, OHOS::AAFwk::AbilityState::INACTIVATING);
1319     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
1320 
1321     ConnectManager()->SetTaskHandler(TaskHandler());
1322     ConnectManager()->SetEventHandler(EventHandler());
1323 
1324     auto result3 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1325     EXPECT_EQ(0, result3);
1326 
1327     auto elementName = abilityRequest_.want.GetElement();
1328     std::string elementNameUri = elementName.GetURI();
1329     auto serviceMap = ConnectManager()->GetServiceMap();
1330     auto abilityRecord = serviceMap.at(elementNameUri);
1331     auto token = abilityRecord->GetToken();
1332 
1333     abilityRecord->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE);
1334     auto result1 = ConnectManager()->DispatchInactive(abilityRecord, OHOS::AAFwk::AbilityState::INACTIVATING);
1335     EXPECT_EQ(result1, OHOS::ERR_INVALID_VALUE);
1336 
1337     abilityRecord->SetAbilityState(OHOS::AAFwk::AbilityState::INACTIVATING);
1338     auto result2 = ConnectManager()->DispatchInactive(abilityRecord, OHOS::AAFwk::AbilityState::INACTIVATING);
1339     EXPECT_EQ(result2, OHOS::ERR_OK);
1340     EXPECT_EQ(abilityRecord->GetAbilityState(), OHOS::AAFwk::AbilityState::INACTIVE);
1341 }
1342 
1343 /*
1344  * Feature: AbilityConnectManager
1345  * Function: AddConnectDeathRecipient
1346  * SubFunction:
1347  * FunctionPoints: AddConnectDeathRecipient
1348  * EnvConditions:NA
1349  * CaseDescription: Verify the AddConnectDeathRecipient process
1350  */
1351 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_027, TestSize.Level1)
1352 {
1353     ConnectManager()->SetTaskHandler(TaskHandler());
1354     ConnectManager()->SetEventHandler(EventHandler());
1355 
1356     ConnectManager()->AddConnectDeathRecipient(nullptr);
1357     EXPECT_TRUE(ConnectManager()->recipientMap_.empty());
1358 }
1359 
1360 /*
1361  * Feature: AbilityConnectManager
1362  * Function: RemoveConnectDeathRecipient
1363  * SubFunction:
1364  * FunctionPoints: RemoveConnectDeathRecipient
1365  * EnvConditions:NA
1366  * CaseDescription: Verify the RemoveConnectDeathRecipient process
1367  */
1368 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_028, TestSize.Level1)
1369 {
1370     ConnectManager()->SetTaskHandler(TaskHandler());
1371     ConnectManager()->SetEventHandler(EventHandler());
1372 
1373     ConnectManager()->AddConnectDeathRecipient(nullptr);
1374     EXPECT_TRUE(ConnectManager()->recipientMap_.empty());
1375 
1376     ConnectManager()->RemoveConnectDeathRecipient(nullptr);
1377     EXPECT_TRUE(ConnectManager()->recipientMap_.empty());
1378 }
1379 
1380 /*
1381  * Feature: AbilityConnectManager
1382  * Function: OnCallBackDied
1383  * SubFunction:
1384  * FunctionPoints: OnCallBackDied
1385  * EnvConditions:NA
1386  * CaseDescription: Verify the OnCallBackDied process
1387  */
1388 HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_029, TestSize.Level1)
1389 {
1390     TAG_LOGI(AAFwkTag::TEST, "AbilityConnectManagerTest::AAFWK_Connect_Service_029 called.");
1391     ConnectManager()->SetTaskHandler(TaskHandler());
1392     ConnectManager()->SetEventHandler(EventHandler());
1393 
1394 
1395     auto result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr);
1396     EXPECT_EQ(0, result);
1397 
1398     const sptr<IRemoteObject> remoteObject1 = nullptr;
__anon13414c6a0502() 1399     auto task1 = [remoteObject1, connectManager = ConnectManager()]() {
1400         connectManager->HandleCallBackDiedTask(remoteObject1);
1401     };
1402     EXPECT_CALL(*taskHandler_, SubmitTaskInner(_, _)).WillRepeatedly(DoAll(SetArgReferee<0>(task1),
1403         testing::Invoke(taskHandler_.get(), &MockTaskHandlerWrap::MockTaskHandler)));
1404     ConnectManager()->OnCallBackDied(nullptr);
1405     auto connectMap = ConnectManager()->connectMap_;
1406     auto connectRecordList = connectMap.at(callbackA_->AsObject());
1407     EXPECT_EQ(1, static_cast<int>(connectRecordList.size()));
1408     for (auto& it : connectRecordList) {
1409         EXPECT_NE(it->GetAbilityConnectCallback(), nullptr);
1410     }
1411 
1412 
1413     const sptr<IRemoteObject> remoteObject2 = callbackA_->AsObject();
__anon13414c6a0602() 1414     auto task2 = [remoteObject2, connectManager = ConnectManager()]() {
1415         connectManager->HandleCallBackDiedTask(remoteObject2);
1416     };
1417     EXPECT_CALL(*taskHandler_, SubmitTaskInner(_, _)).WillRepeatedly(DoAll(SetArgReferee<0>(task2),
1418         testing::Invoke(taskHandler_.get(), &MockTaskHandlerWrap::MockTaskHandler)));
1419     ConnectManager()->OnCallBackDied(callbackA_->AsObject());
1420     connectRecordList = connectMap.at(callbackA_->AsObject());
1421     EXPECT_EQ(1, static_cast<int>(connectMap.size()));
1422     for (auto& it : connectRecordList) {
1423         EXPECT_EQ(it->GetAbilityConnectCallback(), nullptr);
1424     }
1425     TAG_LOGI(AAFwkTag::TEST, "AbilityConnectManagerTest::AAFWK_Connect_Service_029 end.");
1426 }
1427 
1428 /*
1429  * Feature: AbilityConnectManager
1430  * Function: StartAbilityLocked
1431  * SubFunction: StartAbilityLocked
1432  * FunctionPoints: NA
1433  * EnvConditions: NA
1434  * CaseDescription: Verify AbilityConnectManager StartAbilityLocked
1435  */
1436 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_StartAbilityLocked_001, TestSize.Level1)
1437 {
1438     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1439     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1440     AbilityRequest abilityRequest;
1441     abilityRequest.abilityInfo.deviceId = "id";
1442     abilityRequest.abilityInfo.bundleName = "bundle";
1443     abilityRequest.abilityInfo.name = "name";
1444     abilityRequest.abilityInfo.moduleName = "module";
1445     std::string stringUri = "id/bundle/module/name";
1446     AppExecFwk::ElementName element(abilityRequest.abilityInfo.deviceId, abilityRequest.abilityInfo.bundleName,
1447         abilityRequest.abilityInfo.name, abilityRequest.abilityInfo.moduleName);
1448     EXPECT_EQ(element.GetURI(), stringUri);
1449     abilityRecord->currentState_ = AbilityState::ACTIVE;
1450     abilityRecord->SetPreAbilityRecord(serviceRecord1_);
1451     connectManager->serviceMap_.emplace(stringUri, abilityRecord);
1452     int res = connectManager->StartAbilityLocked(abilityRequest);
1453     EXPECT_EQ(res, ERR_OK);
1454 }
1455 
1456 /*
1457  * Feature: AbilityConnectManager
1458  * Function: GetOrCreateServiceRecord
1459  * SubFunction: GetOrCreateServiceRecord
1460  * FunctionPoints: NA
1461  * EnvConditions: NA
1462  * CaseDescription: Verify AbilityConnectManager GetOrCreateServiceRecord
1463  */
1464 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_GetOrCreateServiceRecord_001, TestSize.Level1)
1465 {
1466     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1467     ASSERT_NE(connectManager, nullptr);
1468     AbilityRequest abilityRequest;
1469     bool isCreatedByConnect = false;
1470     std::shared_ptr<AbilityRecord> targetService = nullptr;
1471     bool isLoadedAbility = false;
1472     abilityRequest.abilityInfo.name = AbilityConfig::LAUNCHER_ABILITY_NAME;
1473     connectManager->serviceMap_.clear();
1474     connectManager->GetOrCreateServiceRecord(abilityRequest, isCreatedByConnect, targetService, isLoadedAbility);
1475 }
1476 
1477 /*
1478  * Feature: AbilityConnectManager
1479  * Function: ConnectAbilityLocked
1480  * SubFunction: ConnectAbilityLocked
1481  * FunctionPoints: NA
1482  * EnvConditions: NA
1483  * CaseDescription: Verify AbilityConnectManager ConnectAbilityLocked
1484  */
1485 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_ConnectAbilityLocked_001, TestSize.Level1)
1486 {
1487     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1488     ASSERT_NE(connectManager, nullptr);
1489     ConnectManager()->SetTaskHandler(TaskHandler());
1490     ConnectManager()->SetEventHandler(EventHandler());
1491     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1492     AbilityRequest abilityRequest;
1493     sptr<IRemoteObject> callerToken = abilityRecord->GetToken();
1494     OHOS::sptr<IAbilityConnection> connect = new AbilityConnectCallback();
1495     OHOS::sptr<IAbilityConnection> callback1 = new AbilityConnectCallback();
1496     OHOS::sptr<IAbilityConnection> callback2 = new AbilityConnectCallback();
1497     std::shared_ptr<ConnectionRecord> connection1 =
1498         std::make_shared<ConnectionRecord>(callerToken, abilityRecord, callback1, nullptr);
1499     std::shared_ptr<ConnectionRecord> connection2 =
1500         std::make_shared<ConnectionRecord>(callerToken, abilityRecord, callback2, nullptr);
1501     abilityRequest.abilityInfo.deviceId = "id";
1502     abilityRequest.abilityInfo.bundleName = "bundle";
1503     abilityRequest.abilityInfo.name = "name";
1504     abilityRequest.abilityInfo.moduleName = "module";
1505     std::string stringUri = "id/bundle/name/module";
1506     abilityRecord->currentState_ = AbilityState::ACTIVE;
1507     abilityRecord->AddConnectRecordToList(connection1);
1508     connectManager->serviceMap_.emplace(stringUri, abilityRecord);
1509     connectManager->connectMap_.clear();
1510     connectManager->ConnectAbilityLocked(abilityRequest, connect, callerToken);
1511     abilityRecord->AddConnectRecordToList(connection2);
1512     connectManager->ConnectAbilityLocked(abilityRequest, connect, callerToken);
1513     connectManager->SetEventHandler(nullptr);
1514     connectManager->ConnectAbilityLocked(abilityRequest, connect, callerToken);
1515 }
1516 
1517 /*
1518  * Feature: AbilityConnectManager
1519  * Function: AttachAbilityThreadLocked
1520  * SubFunction: AttachAbilityThreadLocked
1521  * FunctionPoints: NA
1522  * EnvConditions: NA
1523  * CaseDescription: Verify AbilityConnectManager AttachAbilityThreadLocked
1524  */
1525 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_AttachAbilityThreadLocked_001, TestSize.Level1)
1526 {
1527     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1528     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1529     sptr<IAbilityScheduler> scheduler = nullptr;
1530     sptr<IRemoteObject> token = abilityRecord->GetToken();
1531     connectManager->serviceMap_.emplace("first", abilityRecord);
1532     connectManager->eventHandler_ = nullptr;
1533     connectManager->taskHandler_ = nullptr;
1534     int res = connectManager->AttachAbilityThreadLocked(scheduler, token);
1535     EXPECT_EQ(res, ERR_OK);
1536 }
1537 
1538 /*
1539  * Feature: AbilityConnectManager
1540  * Function: OnAppStateChanged
1541  * SubFunction: OnAppStateChanged
1542  * FunctionPoints: NA
1543  * EnvConditions: NA
1544  * CaseDescription: Verify AbilityConnectManager OnAppStateChanged
1545  */
1546 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_OnAppStateChanged_001, TestSize.Level1)
1547 {
1548     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1549     ASSERT_NE(connectManager, nullptr);
1550     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1551     AppInfo info;
1552     std::string bundleName = "bundleName";
1553     std::string name = "name";
1554     int32_t uid = 0;
1555     info.processName = bundleName;
1556     abilityRecord->abilityInfo_.applicationInfo.bundleName = bundleName;
1557     abilityRecord->abilityInfo_.applicationInfo.name = name;
1558     abilityRecord->abilityInfo_.uid = uid;
1559     info.appData.push_back({name, uid});
1560     connectManager->serviceMap_.emplace("first", abilityRecord);
1561     connectManager->OnAppStateChanged(info);
1562 }
1563 
1564 /*
1565  * Feature: AbilityConnectManager
1566  * Function: OnAppStateChanged
1567  * SubFunction: OnAppStateChanged
1568  * FunctionPoints: NA
1569  * EnvConditions: NA
1570  * CaseDescription: Verify AbilityConnectManager OnAppStateChanged
1571  */
1572 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_OnAppStateChanged_002, TestSize.Level1)
1573 {
1574     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1575     ASSERT_NE(connectManager, nullptr);
1576     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1577     AppInfo info;
1578     std::string bundleName = "bundleName";
1579     std::string name = "name";
1580     int32_t uid = 0;
1581     info.processName = "";
1582     abilityRecord->abilityInfo_.applicationInfo.bundleName = bundleName;
1583     abilityRecord->abilityInfo_.applicationInfo.name = name;
1584     abilityRecord->abilityInfo_.uid = uid;
1585     info.appData.push_back({name, uid});
1586     connectManager->serviceMap_.emplace("first", abilityRecord);
1587     connectManager->serviceMap_.emplace("first", nullptr);
1588     connectManager->OnAppStateChanged(info);
1589 }
1590 
1591 /*
1592  * Feature: AbilityConnectManager
1593  * Function: AbilityTransitionDone
1594  * SubFunction: AbilityTransitionDone
1595  * FunctionPoints: NA
1596  * EnvConditions: NA
1597  * CaseDescription: Verify AbilityConnectManager AbilityTransitionDone
1598  */
1599 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_AbilityTransitionDone_001, TestSize.Level1)
1600 {
1601     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1602     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1603     sptr<IRemoteObject> token = abilityRecord->GetToken();
1604     int state = AbilityState::INACTIVE;
1605     abilityRecord->abilityInfo_.type = AbilityType::PAGE;
1606     abilityRecord->SetAbilityState(AbilityState::ACTIVE);
1607     connectManager->serviceMap_.emplace("first", abilityRecord);
1608     int res1 = connectManager->AbilityTransitionDone(token, state);
1609     EXPECT_EQ(res1, ERR_INVALID_VALUE);
1610     state = AbilityState::INITIAL;
1611     connectManager->MoveToTerminatingMap(abilityRecord);
1612     int res2 = connectManager->AbilityTransitionDone(token, state);
1613     EXPECT_EQ(res2, ERR_OK);
1614 }
1615 
1616 /*
1617  * Feature: AbilityConnectManager
1618  * Function: ScheduleConnectAbilityDoneLocked
1619  * SubFunction: ScheduleConnectAbilityDoneLocked
1620  * FunctionPoints: NA
1621  * EnvConditions: NA
1622  * CaseDescription: Verify AbilityConnectManager ScheduleConnectAbilityDoneLocked
1623  */
1624 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_ScheduleConnectAbilityDoneLocked_001, TestSize.Level1)
1625 {
1626     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1627     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1628     sptr<IRemoteObject> token = abilityRecord->GetToken();
1629     sptr<IRemoteObject> remoteObject = nullptr;
1630     abilityRecord->abilityInfo_.type = AbilityType::PAGE;
1631     abilityRecord->SetAbilityState(AbilityState::INACTIVE);
1632     connectManager->serviceMap_.emplace("first", abilityRecord);
1633     int res = connectManager->ScheduleConnectAbilityDoneLocked(token, remoteObject);
1634     EXPECT_EQ(res, ERR_OK);
1635 }
1636 
1637 /*
1638  * Feature: AbilityConnectManager
1639  * Function: ScheduleDisconnectAbilityDoneLocked
1640  * SubFunction: ScheduleDisconnectAbilityDoneLocked
1641  * FunctionPoints: NA
1642  * EnvConditions: NA
1643  * CaseDescription: Verify AbilityConnectManager ScheduleDisconnectAbilityDoneLocked
1644  */
1645 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_ScheduleDisconnectAbilityDoneLocked_001, TestSize.Level1)
1646 {
1647     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1648     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1649     OHOS::sptr<IAbilityConnection> callback = new AbilityConnectCallback();
1650     std::shared_ptr<ConnectionRecord> connection =
1651         std::make_shared<ConnectionRecord>(abilityRecord->GetToken(), abilityRecord, callback, nullptr);
1652     sptr<IRemoteObject> token = abilityRecord->GetToken();
1653     connection->SetConnectState(ConnectionState::DISCONNECTING);
1654     abilityRecord->abilityInfo_.type = AbilityType::PAGE;
1655     abilityRecord->SetAbilityState(AbilityState::INACTIVE);
1656     abilityRecord->connRecordList_.push_back(connection);
1657     connectManager->serviceMap_.emplace("first", abilityRecord);
1658     int res = connectManager->ScheduleDisconnectAbilityDoneLocked(token);
1659     EXPECT_EQ(res, INVALID_CONNECTION_STATE);
1660     abilityRecord->AddStartId();
1661     abilityRecord->SetAbilityState(AbilityState::ACTIVE);
1662     connectManager->serviceMap_.emplace("first", abilityRecord);
1663     res = connectManager->ScheduleDisconnectAbilityDoneLocked(token);
1664     EXPECT_EQ(res, ERR_OK);
1665 }
1666 
1667 /*
1668  * Feature: AbilityConnectManager
1669  * Function: ScheduleCommandAbilityDoneLocked
1670  * SubFunction: ScheduleCommandAbilityDoneLocked
1671  * FunctionPoints: NA
1672  * EnvConditions: NA
1673  * CaseDescription: Verify AbilityConnectManager ScheduleCommandAbilityDoneLocked
1674  */
1675 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_ScheduleCommandAbilityDoneLocked_001, TestSize.Level1)
1676 {
1677     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1678     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1679     sptr<IRemoteObject> token = abilityRecord->GetToken();
1680     abilityRecord->abilityInfo_.type = AbilityType::PAGE;
1681     abilityRecord->SetAbilityState(AbilityState::INACTIVE);
1682     abilityRecord->connRecordList_.clear();
1683     connectManager->serviceMap_.emplace("first", abilityRecord);
1684     int res = connectManager->ScheduleCommandAbilityDoneLocked(token);
1685     EXPECT_EQ(res, ERR_OK);
1686 }
1687 
1688 /*
1689  * Feature: AbilityConnectManager
1690  * Function: CompleteCommandAbility
1691  * SubFunction: CompleteCommandAbility
1692  * FunctionPoints: NA
1693  * EnvConditions: NA
1694  * CaseDescription: Verify AbilityConnectManager CompleteCommandAbility
1695  */
1696 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_CompleteCommandAbility_001, TestSize.Level1)
1697 {
1698     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1699     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1700     connectManager->taskHandler_ = nullptr;
1701     connectManager->CompleteCommandAbility(abilityRecord);
1702     EXPECT_TRUE(abilityRecord->IsAbilityState(AbilityState::ACTIVE));
1703 }
1704 
1705 /*
1706  * Feature: AbilityConnectManager
1707  * Function: GetServiceRecordByElementName
1708  * SubFunction: GetServiceRecordByElementName
1709  * FunctionPoints: NA
1710  * EnvConditions: NA
1711  * CaseDescription: Verify AbilityConnectManager GetServiceRecordByElementName
1712  */
1713 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_GetServiceRecordByElementName_001, TestSize.Level1)
1714 {
1715     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1716     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1717     std::string element = "first";
1718     connectManager->serviceMap_.emplace(element, abilityRecord);
1719     auto res = connectManager->GetServiceRecordByElementName(element);
1720     EXPECT_NE(res, nullptr);
1721 }
1722 
1723 /*
1724  * Feature: AbilityConnectManager
1725  * Function: GetExtensionByTokenFromServiceMap
1726  * SubFunction: GetExtensionByTokenFromServiceMap
1727  * FunctionPoints: NA
1728  * EnvConditions: NA
1729  * CaseDescription: Verify AbilityConnectManager GetExtensionByTokenFromServiceMap
1730  */
1731 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_GetExtensionByTokenFromServiceMap_001, TestSize.Level1)
1732 {
1733     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1734     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1735     sptr<IRemoteObject> token = abilityRecord->GetToken();
1736     connectManager->serviceMap_.emplace("first", nullptr);
1737     auto res = connectManager->GetExtensionByTokenFromServiceMap(token);
1738     EXPECT_EQ(res, nullptr);
1739 }
1740 
1741 /*
1742  * Feature: AbilityConnectManager
1743  * Function: GetConnectRecordListByCallback
1744  * SubFunction: GetConnectRecordListByCallback
1745  * FunctionPoints: NA
1746  * EnvConditions: NA
1747  * CaseDescription: Verify AbilityConnectManager GetConnectRecordListByCallback
1748  */
1749 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_GetConnectRecordListByCallback_001, TestSize.Level1)
1750 {
1751     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1752     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1753     sptr<IAbilityConnection> callback = new AbilityConnectCallback();
1754     connectManager->connectMap_.clear();
1755     auto res = connectManager->GetConnectRecordListByCallback(callback);
1756     EXPECT_EQ(res.size(), 0u);
1757 }
1758 
1759 /*
1760  * Feature: AbilityConnectManager
1761  * Function: GetExtensionByIdFromServiceMap
1762  * SubFunction: GetExtensionByIdFromServiceMap
1763  * FunctionPoints: NA
1764  * EnvConditions: NA
1765  * CaseDescription: Verify AbilityConnectManager GetExtensionByIdFromServiceMap
1766  */
1767 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_GetAbilityRecordById_001, TestSize.Level1)
1768 {
1769     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1770     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1771     int64_t abilityRecordId = abilityRecord->GetRecordId();
1772     connectManager->serviceMap_.emplace("first", abilityRecord);
1773     connectManager->serviceMap_.emplace("second", nullptr);
1774     auto res = connectManager->GetExtensionByIdFromServiceMap(abilityRecordId);
1775     EXPECT_NE(res, nullptr);
1776 }
1777 
1778 /*
1779  * Feature: AbilityConnectManager
1780  * Function: LoadAbility
1781  * SubFunction: LoadAbility
1782  * FunctionPoints: NA
1783  * EnvConditions: NA
1784  * CaseDescription: Verify AbilityConnectManager LoadAbility
1785  */
1786 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_LoadAbility_001, TestSize.Level1)
1787 {
1788     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1789     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1790     abilityRecord->isLauncherRoot_ = true;
1791     abilityRecord->isRestarting_ = true;
1792     abilityRecord->isLauncherAbility_ = true;
1793     abilityRecord->restartCount_ = -1;
1794     EXPECT_FALSE(abilityRecord->CanRestartRootLauncher());
1795     connectManager->LoadAbility(abilityRecord);
1796 }
1797 
1798 /*
1799  * Feature: AbilityConnectManager
1800  * Function: LoadAbility
1801  * SubFunction: LoadAbility
1802  * FunctionPoints: NA
1803  * EnvConditions: NA
1804  * CaseDescription: Verify AbilityConnectManager LoadAbility
1805  */
1806 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_LoadAbility_002, TestSize.Level1)
1807 {
1808     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1809     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1810     std::shared_ptr<CallerRecord> caller1 = std::make_shared<CallerRecord>(0, abilityRecord);
1811     std::shared_ptr<CallerRecord> caller2 = std::make_shared<CallerRecord>();
1812     abilityRecord->isLauncherRoot_ = false;
1813     abilityRecord->isCreateByConnect_ = false;
1814     abilityRecord->callerList_.push_back(caller1);
1815     EXPECT_TRUE(abilityRecord->CanRestartRootLauncher());
1816     connectManager->LoadAbility(abilityRecord);
1817     abilityRecord->callerList_.push_back(caller2);
1818     connectManager->LoadAbility(abilityRecord);
1819     abilityRecord->callerList_.push_back(nullptr);
1820     connectManager->LoadAbility(abilityRecord);
1821 }
1822 
1823 /*
1824  * Feature: AbilityConnectManager
1825  * Function: PostTimeOutTask
1826  * SubFunction: PostTimeOutTask
1827  * FunctionPoints: NA
1828  * EnvConditions: NA
1829  * CaseDescription: Verify AbilityConnectManager PostTimeOutTask
1830  */
1831 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_PostTimeOutTask_001, TestSize.Level1)
1832 {
1833     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1834     ASSERT_NE(connectManager, nullptr);
1835     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1836     uint32_t messageId = 2;
1837     connectManager->PostTimeOutTask(abilityRecord, messageId);
1838 }
1839 
1840 /*
1841  * Feature: AbilityConnectManager
1842  * Function: HandleStartTimeoutTask
1843  * SubFunction: HandleStartTimeoutTask
1844  * FunctionPoints: NA
1845  * EnvConditions: NA
1846  * CaseDescription: Verify AbilityConnectManager HandleStartTimeoutTask
1847  */
1848 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_HandleStartTimeoutTask_001, TestSize.Level1)
1849 {
1850     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1851     ASSERT_NE(connectManager, nullptr);
1852     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1853     abilityRecord->abilityInfo_.name = "abilityName";
1854     connectManager->HandleStartTimeoutTask(abilityRecord);
1855 }
1856 
1857 /*
1858  * Feature: AbilityConnectManager
1859  * Function: HandleStartTimeoutTask
1860  * SubFunction: HandleStartTimeoutTask
1861  * FunctionPoints: NA
1862  * EnvConditions: NA
1863  * CaseDescription: Verify AbilityConnectManager HandleStartTimeoutTask
1864  */
1865 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_HandleStartTimeoutTask_002, TestSize.Level1)
1866 {
1867     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1868     ASSERT_NE(connectManager, nullptr);
1869     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1870     abilityRecord->abilityInfo_.name = AbilityConfig::LAUNCHER_ABILITY_NAME;
1871     connectManager->HandleStartTimeoutTask(abilityRecord);
1872 }
1873 
1874 /*
1875  * Feature: AbilityConnectManager
1876  * Function: HandleConnectTimeoutTask
1877  * SubFunction: HandleConnectTimeoutTask
1878  * FunctionPoints: NA
1879  * EnvConditions: NA
1880  * CaseDescription: Verify AbilityConnectManager HandleConnectTimeoutTask
1881  */
1882 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_HandleConnectTimeoutTask_001, TestSize.Level1)
1883 {
1884     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1885     ASSERT_NE(connectManager, nullptr);
1886     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1887     abilityRecord->abilityInfo_.name = AbilityConfig::LAUNCHER_ABILITY_NAME;
1888     connectManager->HandleConnectTimeoutTask(abilityRecord);
1889 }
1890 
1891 /*
1892  * Feature: AbilityConnectManager
1893  * Function: HandleCommandTimeoutTask
1894  * SubFunction: HandleCommandTimeoutTask
1895  * FunctionPoints: NA
1896  * EnvConditions: NA
1897  * CaseDescription: Verify AbilityConnectManager HandleCommandTimeoutTask
1898  */
1899 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_HandleCommandTimeoutTask_001, TestSize.Level1)
1900 {
1901     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1902     ASSERT_NE(connectManager, nullptr);
1903     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1904     abilityRecord->abilityInfo_.name = AbilityConfig::LAUNCHER_ABILITY_NAME;
1905     connectManager->HandleCommandTimeoutTask(abilityRecord);
1906     abilityRecord->abilityInfo_.name = "abilityName";
1907     connectManager->HandleCommandTimeoutTask(abilityRecord);
1908 }
1909 
1910 /*
1911  * Feature: AbilityConnectManager
1912  * Function: HandleTerminateDisconnectTask
1913  * SubFunction: HandleTerminateDisconnectTask
1914  * FunctionPoints: NA
1915  * EnvConditions: NA
1916  * CaseDescription: Verify AbilityConnectManager HandleTerminateDisconnectTask
1917  */
1918 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_HandleTerminateDisconnectTask_001, TestSize.Level1)
1919 {
1920     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1921     ASSERT_NE(connectManager, nullptr);
1922     OHOS::sptr<IAbilityConnection> callback = new AbilityConnectCallback();
1923     std::shared_ptr<ConnectionRecord> connection =
1924         std::make_shared<ConnectionRecord>(nullptr, nullptr, callback, nullptr);
1925     AbilityConnectManager::ConnectListType connectlist;
1926     connectlist.push_back(nullptr);
1927     connectlist.push_back(connection);
1928     connectManager->HandleTerminateDisconnectTask(connectlist);
1929 }
1930 
1931 /*
1932  * Feature: AbilityConnectManager
1933  * Function: DispatchInactive
1934  * SubFunction: DispatchInactive
1935  * FunctionPoints: NA
1936  * EnvConditions: NA
1937  * CaseDescription: Verify AbilityConnectManager DispatchInactive
1938  */
1939 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_DispatchInactive_001, TestSize.Level1)
1940 {
1941     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1942     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1943     int state = 0;
1944     abilityRecord->SetAbilityState(AbilityState::INACTIVATING);
1945     abilityRecord->isCreateByConnect_ = false;
1946     connectManager->SetTaskHandler(TaskHandler());
1947     connectManager->SetEventHandler(EventHandler());
1948     int res = connectManager->DispatchInactive(abilityRecord, state);
1949     EXPECT_EQ(res, ERR_OK);
1950 }
1951 
1952 /*
1953  * Feature: AbilityConnectManager
1954  * Function: DispatchTerminate
1955  * SubFunction: DispatchTerminate
1956  * FunctionPoints: NA
1957  * EnvConditions: NA
1958  * CaseDescription: Verify AbilityConnectManager DispatchTerminate
1959  */
1960 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_DispatchTerminate_001, TestSize.Level1)
1961 {
1962     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1963     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1964     connectManager->SetTaskHandler(TaskHandler());
1965     connectManager->SetEventHandler(EventHandler());
1966     int res = connectManager->DispatchTerminate(abilityRecord);
1967     EXPECT_EQ(res, ERR_OK);
1968 }
1969 
1970 /*
1971  * Feature: AbilityConnectManager
1972  * Function: CommandAbility
1973  * SubFunction: CommandAbility
1974  * FunctionPoints: NA
1975  * EnvConditions: NA
1976  * CaseDescription: Verify AbilityConnectManager CommandAbility
1977  */
1978 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_CommandAbility_001, TestSize.Level1)
1979 {
1980     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1981     ASSERT_NE(connectManager, nullptr);
1982     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
1983     connectManager->SetEventHandler(nullptr);
1984     connectManager->CommandAbility(abilityRecord);
1985 }
1986 
1987 /*
1988  * Feature: AbilityConnectManager
1989  * Function: TerminateDone
1990  * SubFunction: TerminateDone
1991  * FunctionPoints: NA
1992  * EnvConditions: NA
1993  * CaseDescription: Verify AbilityConnectManager TerminateDone
1994  */
1995 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_TerminateDone_001, TestSize.Level1)
1996 {
1997     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
1998     ASSERT_NE(connectManager, nullptr);
1999     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2000     abilityRecord->SetAbilityState(AbilityState::TERMINATING);
2001     connectManager->TerminateDone(abilityRecord);
2002 }
2003 
2004 /*
2005  * Feature: AbilityConnectManager
2006  * Function: IsAbilityConnected
2007  * SubFunction: IsAbilityConnected
2008  * FunctionPoints: NA
2009  * EnvConditions: NA
2010  * CaseDescription: Verify AbilityConnectManager IsAbilityConnected
2011  */
2012 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_IsAbilityConnected_001, TestSize.Level1)
2013 {
2014     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2015     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2016     std::list<std::shared_ptr<ConnectionRecord>> connectRecordList;
2017     OHOS::sptr<IAbilityConnection> callback = new AbilityConnectCallback();
2018     std::shared_ptr<ConnectionRecord> connection =
2019         std::make_shared<ConnectionRecord>(abilityRecord->GetToken(), abilityRecord, callback, nullptr);
2020     connectRecordList.push_back(connection);
2021     bool res1 = connectManager->IsAbilityConnected(nullptr, connectRecordList);
2022     EXPECT_FALSE(res1);
2023     connectRecordList.push_back(nullptr);
2024     bool res2 = connectManager->IsAbilityConnected(abilityRecord, connectRecordList);
2025     EXPECT_TRUE(res2);
2026 }
2027 
2028 /*
2029  * Feature: AbilityConnectManager
2030  * Function: RemoveServiceAbility
2031  * SubFunction: RemoveServiceAbility
2032  * FunctionPoints: NA
2033  * EnvConditions: NA
2034  * CaseDescription: Verify AbilityConnectManager RemoveServiceAbility
2035  */
2036 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_RemoveServiceAbility_001, TestSize.Level1)
2037 {
2038     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2039     ASSERT_NE(connectManager, nullptr);
2040     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2041     AbilityInfo abilityInfo;
2042     abilityRecord->abilityInfo_ = abilityInfo;
2043     connectManager->serviceMap_.clear();
2044     connectManager->RemoveServiceAbility(abilityRecord);
2045 }
2046 
2047 /*
2048  * Feature: AbilityConnectManager
2049  * Function: OnCallBackDied
2050  * SubFunction: OnCallBackDied
2051  * FunctionPoints: NA
2052  * EnvConditions: NA
2053  * CaseDescription: Verify AbilityConnectManager OnCallBackDied
2054  */
2055 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_OnCallBackDied_001, TestSize.Level1)
2056 {
2057     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2058     ASSERT_NE(connectManager, nullptr);
2059     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2060     wptr<IRemoteObject> remote{ abilityRecord->GetToken() };
2061     connectManager->SetEventHandler(nullptr);
2062     connectManager->OnCallBackDied(remote);
2063 }
2064 
2065 /*
2066  * Feature: AbilityConnectManager
2067  * Function: HandleCallBackDiedTask
2068  * SubFunction: HandleCallBackDiedTask
2069  * FunctionPoints: NA
2070  * EnvConditions: NA
2071  * CaseDescription: Verify AbilityConnectManager HandleCallBackDiedTask
2072  */
2073 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_HandleCallBackDiedTask_001, TestSize.Level1)
2074 {
2075     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2076     ASSERT_NE(connectManager, nullptr);
2077     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2078     sptr<IRemoteObject> connect = abilityRecord->GetToken();
2079     connectManager->connectMap_.clear();
2080     connectManager->HandleCallBackDiedTask(connect);
2081 }
2082 
2083 /*
2084  * Feature: AbilityConnectManager
2085  * Function: OnAbilityDied
2086  * SubFunction: OnAbilityDied
2087  * FunctionPoints: NA
2088  * EnvConditions: NA
2089  * CaseDescription: Verify AbilityConnectManager OnAbilityDied
2090  */
2091 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_OnAbilityDied_001, TestSize.Level1)
2092 {
2093     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2094     ASSERT_NE(connectManager, nullptr);
2095     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2096     int32_t currentUserId = 0;
2097     abilityRecord->abilityInfo_.type = AbilityType::PAGE;
2098     connectManager->SetEventHandler(nullptr);
2099     connectManager->OnAbilityDied(abilityRecord, currentUserId);
2100     abilityRecord->abilityInfo_.type = AbilityType::EXTENSION;
2101     connectManager->OnAbilityDied(abilityRecord, currentUserId);
2102 }
2103 
2104 /*
2105  * Feature: AbilityConnectManager
2106  * Function: OnTimeOut
2107  * SubFunction: OnTimeOut
2108  * FunctionPoints: NA
2109  * EnvConditions: NA
2110  * CaseDescription: Verify AbilityConnectManager OnTimeOut
2111  */
2112 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_OnTimeOut_001, TestSize.Level1)
2113 {
2114     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2115     ASSERT_NE(connectManager, nullptr);
2116     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2117     uint32_t msgId = 2;
2118     connectManager->serviceMap_.emplace("first", abilityRecord);
2119     int64_t abilityRecordId = 1;
2120     connectManager->OnTimeOut(msgId, abilityRecordId);
2121     msgId = 0;
2122     connectManager->OnTimeOut(msgId, abilityRecordId);
2123 }
2124 
2125 /*
2126  * Feature: AbilityConnectManager
2127  * Function: HandleInactiveTimeout
2128  * SubFunction: HandleInactiveTimeout
2129  * FunctionPoints: NA
2130  * EnvConditions: NA
2131  * CaseDescription: Verify AbilityConnectManager HandleInactiveTimeout
2132  */
2133 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_HandleInactiveTimeout_001, TestSize.Level1)
2134 {
2135     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2136     ASSERT_NE(connectManager, nullptr);
2137     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2138     abilityRecord->abilityInfo_.name = AbilityConfig::LAUNCHER_ABILITY_NAME;
2139     connectManager->HandleInactiveTimeout(abilityRecord);
2140     abilityRecord->abilityInfo_.name = "abilityName";
2141     connectManager->HandleInactiveTimeout(abilityRecord);
2142 }
2143 
2144 /*
2145  * Feature: AbilityConnectManager
2146  * Function: HandleAbilityDiedTask
2147  * SubFunction: HandleAbilityDiedTask
2148  * FunctionPoints: NA
2149  * EnvConditions: NA
2150  * CaseDescription: Verify AbilityConnectManager HandleAbilityDiedTask
2151  */
2152 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_HandleAbilityDiedTask_001, TestSize.Level1)
2153 {
2154     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2155     ASSERT_NE(connectManager, nullptr);
2156     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2157     int32_t currentUserId = 0;
2158     connectManager->serviceMap_.clear();
2159     connectManager->HandleAbilityDiedTask(abilityRecord, currentUserId);
2160 }
2161 
2162 /*
2163  * Feature: AbilityConnectManager
2164  * Function: RestartAbility
2165  * SubFunction: RestartAbility
2166  * FunctionPoints: NA
2167  * EnvConditions: NA
2168  * CaseDescription: Verify AbilityConnectManager RestartAbility
2169  */
2170 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_RestartAbility_001, TestSize.Level1)
2171 {
2172     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2173     ASSERT_NE(connectManager, nullptr);
2174     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2175     int32_t currentUserId = 0;
2176     connectManager->userId_ = 1;
2177     abilityRecord->abilityInfo_.name = AbilityConfig::LAUNCHER_ABILITY_NAME;
2178     connectManager->RestartAbility(abilityRecord, currentUserId);
2179     connectManager->userId_ = currentUserId;
2180     connectManager->RestartAbility(abilityRecord, currentUserId);
2181 }
2182 
2183 /*
2184  * Feature: AbilityConnectManager
2185  * Function: RestartAbility
2186  * SubFunction: RestartAbility
2187  * FunctionPoints: NA
2188  * EnvConditions: NA
2189  * CaseDescription: Verify AbilityConnectManager RestartAbility
2190  */
2191 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_RestartAbility_002, TestSize.Level1)
2192 {
2193     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2194     ASSERT_NE(connectManager, nullptr);
2195     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2196     int32_t currentUserId = 0;
2197     connectManager->userId_ = currentUserId;
2198     abilityRecord->abilityInfo_.name = "abilityName";
2199     abilityRecord->SetRestartCount(-1);
2200     connectManager->RestartAbility(abilityRecord, currentUserId);
2201 }
2202 
2203 /*
2204  * Feature: AbilityConnectManager
2205  * Function: DumpState
2206  * SubFunction: DumpState
2207  * FunctionPoints: NA
2208  * EnvConditions: NA
2209  * CaseDescription: Verify AbilityConnectManager DumpState
2210  */
2211 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_DumpState_001, TestSize.Level1)
2212 {
2213     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2214     ASSERT_NE(connectManager, nullptr);
2215     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2216     std::vector<std::string> info;
2217     bool isClient = false;
2218     std::string args = "args";
2219     connectManager->serviceMap_.emplace(args, abilityRecord);
2220     connectManager->DumpState(info, isClient, args);
2221     connectManager->serviceMap_.clear();
2222     connectManager->DumpState(info, isClient, args);
2223     args = "";
2224     connectManager->DumpState(info, isClient, args);
2225 }
2226 
2227 /*
2228  * Feature: AbilityConnectManager
2229  * Function: DumpStateByUri
2230  * SubFunction: DumpStateByUri
2231  * FunctionPoints: NA
2232  * EnvConditions: NA
2233  * CaseDescription: Verify AbilityConnectManager DumpStateByUri
2234  */
2235 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_DumpStateByUri_001, TestSize.Level1)
2236 {
2237     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2238     ASSERT_NE(connectManager, nullptr);
2239     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2240     std::vector<std::string> info;
2241     bool isClient = false;
2242     std::string args = "args";
2243     std::vector<std::string> params;
2244     connectManager->serviceMap_.emplace(args, abilityRecord);
2245     connectManager->DumpStateByUri(info, isClient, args, params);
2246     connectManager->serviceMap_.clear();
2247     connectManager->DumpStateByUri(info, isClient, args, params);
2248 }
2249 
2250 /*
2251  * Feature: AbilityConnectManager
2252  * Function: GetExtensionRunningInfos
2253  * SubFunction: GetExtensionRunningInfos
2254  * FunctionPoints: NA
2255  * EnvConditions: NA
2256  * CaseDescription: Verify AbilityConnectManager GetExtensionRunningInfos
2257  */
2258 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_GetExtensionRunningInfos_001, TestSize.Level1)
2259 {
2260     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2261     ASSERT_NE(connectManager, nullptr);
2262     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2263     int upperLimit = 1;
2264     std::vector<ExtensionRunningInfo> info;
2265     int32_t userId = 0;
2266     bool isPerm = false;
2267     ExtensionRunningInfo extensionInfo;
2268     info.push_back(extensionInfo);
2269     connectManager->serviceMap_.emplace("first", abilityRecord);
2270     connectManager->GetExtensionRunningInfos(upperLimit, info, userId, isPerm);
2271 }
2272 
2273 /*
2274  * Feature: AbilityConnectManager
2275  * Function: GetExtensionRunningInfo
2276  * SubFunction: GetExtensionRunningInfo
2277  * FunctionPoints: NA
2278  * EnvConditions: NA
2279  * CaseDescription: Verify AbilityConnectManager GetExtensionRunningInfo
2280  */
2281 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_GetExtensionRunningInfo_001, TestSize.Level1)
2282 {
2283     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2284     ASSERT_NE(connectManager, nullptr);
2285     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2286     OHOS::sptr<IAbilityConnection> callback = new AbilityConnectCallback();
2287     std::shared_ptr<ConnectionRecord> connection =
2288         std::make_shared<ConnectionRecord>(abilityRecord->GetToken(), abilityRecord, callback, nullptr);
2289     int32_t userId = 0;
2290     std::vector<ExtensionRunningInfo> info;
2291     Want want;
2292     AbilityInfo abilityInfo;
2293     ApplicationInfo applicationInfo;
2294     want.SetElementName("device", "bundle", "ability", "module");
2295     abilityRecord->SetWant(want);
2296     abilityRecord->connRecordList_.push_back(nullptr);
2297     abilityRecord->connRecordList_.push_back(connection);
2298     connectManager->GetExtensionRunningInfo(abilityRecord, userId, info);
2299 }
2300 
2301 /*
2302  * Feature: AbilityConnectManager
2303  * Function: IsAbilityNeedKeepAlive
2304  * SubFunction:
2305  * FunctionPoints: IsAbilityNeedKeepAlive
2306  * EnvConditions:NA
2307  * CaseDescription: Verify the IsAbilityNeedKeepAlive need keep alive.
2308  * @tc.require: issueI6588V
2309  */
2310 HWTEST_F(AbilityConnectManagerTest, AAFWK_IsAbilityNeedKeepAlive_001, TestSize.Level1)
2311 {
2312     ConnectManager()->SetTaskHandler(TaskHandler());
2313     ConnectManager()->SetEventHandler(EventHandler());
2314 
2315     serviceRecord2_->SetKeepAliveBundle(true);
2316     // mock bms return
2317     EXPECT_TRUE(ConnectManager()->IsAbilityNeedKeepAlive(serviceRecord2_));
2318 }
2319 
2320 /*
2321  * Feature: AbilityConnectManager
2322  * Function: RestartAbility
2323  * SubFunction:
2324  * FunctionPoints: RestartAbility
2325  * EnvConditions:NA
2326  * CaseDescription: Verify ability not restart the normal ability died.
2327  * @tc.require: issueI6588V
2328  */
2329 HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_001, TestSize.Level1)
2330 {
2331     ConnectManager()->SetTaskHandler(TaskHandler());
2332     ConnectManager()->SetEventHandler(EventHandler());
2333 
2334     int userId = 0;
2335 
2336     auto result = ConnectManager()->StartAbility(abilityRequest_);
2337     EXPECT_EQ(OHOS::ERR_OK, result);
2338 
2339     auto elementName = abilityRequest_.want.GetElement().GetURI();
2340     std::shared_ptr<AbilityRecord> service = ConnectManager()->GetServiceRecordByElementName(elementName);
2341     EXPECT_NE(service, nullptr);
2342     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 1);
2343 
2344     // HandleTerminate
__anon13414c6a0702() 2345     auto task = [service, connectManager = ConnectManager(), userId]() {
2346         connectManager->HandleAbilityDiedTask(service, userId);
2347     };
2348     EXPECT_CALL(*taskHandler_, SubmitTaskInner(_, _)).WillRepeatedly(DoAll(SetArgReferee<0>(task),
2349         testing::Invoke(taskHandler_.get(), &MockTaskHandlerWrap::MockTaskHandler)));
2350     ConnectManager()->OnAbilityDied(service, userId);
2351     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 0);
2352 }
2353 
2354 /*
2355  * Feature: AbilityConnectManager
2356  * Function: RestartAbility
2357  * SubFunction:
2358  * FunctionPoints: RestartAbility
2359  * EnvConditions:NA
2360  * CaseDescription: Verify ability restart when the resident ability died.
2361  * @tc.require: issueI6588V
2362  */
2363 HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_002, TestSize.Level1)
2364 {
2365     ConnectManager()->SetTaskHandler(TaskHandler());
2366     ConnectManager()->SetEventHandler(EventHandler());
2367 
2368     int userId = 0;
2369 
2370     auto result = ConnectManager()->StartAbility(abilityRequest2_);
2371     EXPECT_EQ(OHOS::ERR_OK, result);
2372     WaitUntilTaskDone(TaskHandler());
2373 
2374     auto elementName = abilityRequest2_.want.GetElement().GetURI();
2375     auto service = ConnectManager()->GetServiceRecordByElementName(elementName);
2376     EXPECT_NE(service, nullptr);
2377     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 1);
2378 
2379     // HandleTerminate
2380     ConnectManager()->HandleAbilityDiedTask(service, userId);
2381     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 0);
2382 }
2383 
2384 /*
2385  * Feature: AbilityConnectManager
2386  * Function: RestartAbility
2387  * SubFunction:
2388  * FunctionPoints: RestartAbility
2389  * EnvConditions:NA
2390  * CaseDescription: Verify ability restart when the resident ability died and restart out of max times.
2391  * @tc.require: issueI6588V
2392  */
2393 HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_003, TestSize.Level1)
2394 {
2395     ConnectManager()->SetTaskHandler(TaskHandler());
2396     ConnectManager()->SetEventHandler(EventHandler());
2397 
2398     int userId = 0;
2399 
2400     auto result = ConnectManager()->StartAbility(abilityRequest2_);
2401     EXPECT_EQ(OHOS::ERR_OK, result);
2402     WaitUntilTaskDone(TaskHandler());
2403 
2404     auto elementName = abilityRequest2_.want.GetElement().GetURI();
2405     std::shared_ptr<AbilityRecord> service = ConnectManager()->GetServiceRecordByElementName(elementName);
2406     EXPECT_NE(service, nullptr);
2407     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 1);
2408     // set the over interval time according the config; without init config, the interval time is 0.
2409     // ensure now - restartTime < intervalTime
2410     service->SetRestartTime(AbilityUtil::SystemTimeMillis() + 1000);
2411 
2412     // HandleTerminate
2413     ConnectManager()->HandleAbilityDiedTask(service, userId);
2414     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 0);
2415 }
2416 
2417 /*
2418  * Feature: AbilityConnectManager
2419  * Function: PostRestartResidentTask
2420  * SubFunction:
2421  * FunctionPoints: PostRestartResidentTask
2422  * EnvConditions:NA
2423  * CaseDescription: Verify the PostRestartResidentTask process.
2424  * @tc.require: issueI6588V
2425  */
2426 HWTEST_F(AbilityConnectManagerTest, AAFWK_PostRestartResidentTask_001, TestSize.Level1)
2427 {
2428     ConnectManager()->SetTaskHandler(TaskHandler());
2429     ConnectManager()->SetEventHandler(EventHandler());
2430 
2431     ConnectManager()->PostRestartResidentTask(abilityRequest2_);
2432     WaitUntilTaskDone(TaskHandler());
2433     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 0);
2434 }
2435 
2436 /*
2437  * Feature: AbilityConnectManager
2438  * Function: StartAbility
2439  * SubFunction: NA
2440  * FunctionPoints: StartAbility
2441  * EnvConditions:NA
2442  * CaseDescription: Verify the normal process of startability with session info
2443  */
2444 HWTEST_F(AbilityConnectManagerTest, AAFWK_Start_Service_With_SessionInfo_001, TestSize.Level1)
2445 {
2446     ConnectManager()->SetTaskHandler(TaskHandler());
2447     ConnectManager()->SetEventHandler(EventHandler());
2448 
2449     auto sessionInfo = MockSessionInfo(0);
2450     abilityRequest_.sessionInfo = sessionInfo;
2451     auto result = ConnectManager()->StartAbility(abilityRequest_);
2452     EXPECT_EQ(OHOS::ERR_OK, result);
2453     abilityRequest_.sessionInfo = nullptr;
2454     WaitUntilTaskDone(TaskHandler());
2455 
2456     auto service = ConnectManager()->GetUIExtensionBySessionInfo(sessionInfo);
2457     EXPECT_EQ(static_cast<int>(ConnectManager()->GetServiceMap().size()), 1);
2458 }
2459 
2460 /*
2461  * Feature: AbilityConnectManager
2462  * Function: StartAbilityLocked
2463  * SubFunction: StartAbilityLocked
2464  * FunctionPoints: NA
2465  * EnvConditions: NA
2466  * CaseDescription: Verify AbilityConnectManager StartAbilityLocked with session info
2467  */
2468 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_StartAbilityLocked_With_SessionInfo_001, TestSize.Level1)
2469 {
2470     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2471     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2472     AbilityRequest abilityRequest;
2473     abilityRequest.abilityInfo.deviceId = "id";
2474     abilityRequest.abilityInfo.bundleName = "bundle";
2475     abilityRequest.abilityInfo.name = "name";
2476     abilityRequest.abilityInfo.moduleName = "module";
2477     std::string stringUri = "id/bundle/module/name";
2478     AppExecFwk::ElementName element(abilityRequest.abilityInfo.deviceId, abilityRequest.abilityInfo.bundleName,
2479         abilityRequest.abilityInfo.name, abilityRequest.abilityInfo.moduleName);
2480     EXPECT_EQ(element.GetURI(), stringUri);
2481     abilityRecord->currentState_ = AbilityState::ACTIVE;
2482     abilityRecord->SetPreAbilityRecord(serviceRecord1_);
2483     connectManager->serviceMap_.emplace(stringUri, abilityRecord);
2484     abilityRequest.sessionInfo = MockSessionInfo(0);
2485     int res = connectManager->StartAbilityLocked(abilityRequest);
2486     EXPECT_EQ(res, ERR_OK);
2487 }
2488 
2489 /*
2490  * Feature: MissionListManager
2491  * Function: MoveToBackground
2492  * SubFunction: NA
2493  * FunctionPoints: MissionListManager MoveToBackground
2494  * EnvConditions: NA
2495  * CaseDescription: Verify MoveToBackground
2496  */
2497 HWTEST_F(AbilityConnectManagerTest, MoveToBackground_001, TestSize.Level1)
2498 {
2499     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2500     ASSERT_NE(connectManager, nullptr);
2501     std::shared_ptr<AbilityRecord> abilityRecord;
2502     connectManager->MoveToBackground(abilityRecord);
2503     connectManager.reset();
2504 }
2505 
2506 /*
2507  * Feature: MissionListManager
2508  * Function: MoveToBackground
2509  * SubFunction: NA
2510  * FunctionPoints: MissionListManager MoveToBackground
2511  * EnvConditions: NA
2512  * CaseDescription: Verify MoveToBackground
2513  */
2514 HWTEST_F(AbilityConnectManagerTest, MoveToBackground_002, TestSize.Level1)
2515 {
2516     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2517     ASSERT_NE(connectManager, nullptr);
2518     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2519     abilityRecord->lifeCycleStateInfo_.sceneFlag = 1;
2520     connectManager->MoveToBackground(abilityRecord);
2521     connectManager.reset();
2522 }
2523 
2524 /*
2525  * Feature: MissionListManager
2526  * Function: MoveToBackground
2527  * SubFunction: NA
2528  * FunctionPoints: MissionListManager MoveToBackground
2529  * EnvConditions: NA
2530  * CaseDescription: Verify MoveToBackground
2531  */
2532 HWTEST_F(AbilityConnectManagerTest, MoveToBackground_003, TestSize.Level1)
2533 {
2534     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2535     ASSERT_NE(connectManager, nullptr);
2536     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2537     abilityRecord->lifeCycleStateInfo_.sceneFlag = 2;
2538     abilityRecord->SetClearMissionFlag(true);
2539     connectManager->MoveToBackground(abilityRecord);
2540     connectManager.reset();
2541 }
2542 
2543 
2544 /*
2545  * Feature: MissionListManager
2546  * Function: CompleteBackground
2547  * SubFunction: NA
2548  * FunctionPoints: MissionListManager CompleteBackground
2549  * EnvConditions: NA
2550  * CaseDescription: Verify CompleteBackground
2551  */
2552 HWTEST_F(AbilityConnectManagerTest, CompleteBackground_001, TestSize.Level1)
2553 {
2554     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2555     ASSERT_NE(connectManager, nullptr);
2556     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2557     abilityRecord->currentState_ = AbilityState::FOREGROUND;
2558     connectManager->CompleteBackground(abilityRecord);
2559     connectManager.reset();
2560 }
2561 
2562 /*
2563  * Feature: MissionListManager
2564  * Function: CompleteBackground
2565  * SubFunction: NA
2566  * FunctionPoints: MissionListManager CompleteBackground
2567  * EnvConditions: NA
2568  * CaseDescription: Verify CompleteBackground
2569  */
2570 HWTEST_F(AbilityConnectManagerTest, CompleteBackground_002, TestSize.Level1)
2571 {
2572     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2573     ASSERT_NE(connectManager, nullptr);
2574     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2575     abilityRecord->currentState_ = AbilityState::BACKGROUNDING;
2576     abilityRecord->SetPendingState(AbilityState::FOREGROUND);
2577     abilityRecord->SetSwitchingPause(true);
2578     connectManager->CompleteBackground(abilityRecord);
2579     connectManager.reset();
2580 }
2581 
2582 /*
2583  * Feature: MissionListManager
2584  * Function: CompleteBackground
2585  * SubFunction: NA
2586  * FunctionPoints: MissionListManager CompleteBackground
2587  * EnvConditions: NA
2588  * CaseDescription: Verify CompleteBackground
2589  */
2590 HWTEST_F(AbilityConnectManagerTest, CompleteBackground_003, TestSize.Level1)
2591 {
2592     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2593     ASSERT_NE(connectManager, nullptr);
2594     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2595     abilityRecord->currentState_ = AbilityState::BACKGROUNDING;
2596     abilityRecord->SetPendingState(AbilityState::BACKGROUND);
2597     abilityRecord->SetSwitchingPause(false);
2598     abilityRecord->SetStartedByCall(true);
2599     abilityRecord->SetStartToBackground(true);
2600     abilityRecord->isReady_ = true;
2601     connectManager->CompleteBackground(abilityRecord);
2602     connectManager.reset();
2603 }
2604 
2605 /*
2606  * Feature: MissionListManager
2607  * Function: CompleteBackground
2608  * SubFunction: NA
2609  * FunctionPoints: MissionListManager CompleteBackground
2610  * EnvConditions: NA
2611  * CaseDescription: Verify CompleteBackground
2612  */
2613 HWTEST_F(AbilityConnectManagerTest, CompleteBackground_004, TestSize.Level1)
2614 {
2615     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2616     ASSERT_NE(connectManager, nullptr);
2617     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2618     std::shared_ptr<AbilityRecord> abilityRecord2 = InitAbilityRecord();
2619     abilityRecord->currentState_ = AbilityState::BACKGROUNDING;
2620     abilityRecord->SetPendingState(AbilityState::BACKGROUND);
2621     abilityRecord->SetSwitchingPause(false);
2622     abilityRecord->SetStartedByCall(false);
2623     abilityRecord->SetStartToBackground(true);
2624     abilityRecord->isReady_ = true;
2625     abilityRecord2->currentState_ = AbilityState::BACKGROUND;
2626     connectManager->CompleteBackground(abilityRecord);
2627     connectManager.reset();
2628 }
2629 
2630 /*
2631  * Feature: MissionListManager
2632  * Function: CompleteBackground
2633  * SubFunction: NA
2634  * FunctionPoints: MissionListManager CompleteBackground
2635  * EnvConditions: NA
2636  * CaseDescription: Verify CompleteBackground
2637  */
2638 HWTEST_F(AbilityConnectManagerTest, CompleteBackground_005, TestSize.Level1)
2639 {
2640     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2641     ASSERT_NE(connectManager, nullptr);
2642     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2643     std::shared_ptr<AbilityRecord> abilityRecord2 = InitAbilityRecord();
2644     abilityRecord->currentState_ = AbilityState::BACKGROUNDING;
2645     abilityRecord->SetPendingState(AbilityState::BACKGROUND);
2646     abilityRecord->SetSwitchingPause(false);
2647     abilityRecord->SetStartedByCall(true);
2648     abilityRecord->SetStartToBackground(false);
2649     abilityRecord->isReady_ = true;
2650     abilityRecord2->currentState_ = AbilityState::BACKGROUND;
2651     connectManager->CompleteBackground(abilityRecord);
2652     connectManager.reset();
2653 }
2654 
2655 /*
2656  * Feature: MissionListManager
2657  * Function: CompleteBackground
2658  * SubFunction: NA
2659  * FunctionPoints: MissionListManager CompleteBackground
2660  * EnvConditions: NA
2661  * CaseDescription: Verify CompleteBackground
2662  */
2663 HWTEST_F(AbilityConnectManagerTest, CompleteBackground_006, TestSize.Level1)
2664 {
2665     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2666     ASSERT_NE(connectManager, nullptr);
2667     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2668     std::shared_ptr<AbilityRecord> abilityRecord2 = InitAbilityRecord();
2669     abilityRecord->currentState_ = AbilityState::BACKGROUNDING;
2670     abilityRecord->SetPendingState(AbilityState::BACKGROUND);
2671     abilityRecord->SetSwitchingPause(false);
2672     abilityRecord->SetStartedByCall(true);
2673     abilityRecord->SetStartToBackground(true);
2674     abilityRecord->isReady_ = false;
2675     abilityRecord2->currentState_ = AbilityState::FOREGROUND;
2676     connectManager->CompleteBackground(abilityRecord);
2677     connectManager.reset();
2678 }
2679 
2680 /*
2681  * Feature: MissionListManager
2682  * Function: PrintTimeOutLog
2683  * SubFunction: NA
2684  * FunctionPoints: MissionListManager PrintTimeOutLog
2685  * EnvConditions: NA
2686  * CaseDescription: Verify PrintTimeOutLog
2687  */
2688 HWTEST_F(AbilityConnectManagerTest, PrintTimeOutLog_001, TestSize.Level1)
2689 {
2690     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2691     ASSERT_NE(connectManager, nullptr);
2692     uint32_t msgId = 0;
2693     connectManager->PrintTimeOutLog(nullptr, msgId);
2694     connectManager.reset();
2695 }
2696 
2697 /*
2698  * Feature: MissionListManager
2699  * Function: PrintTimeOutLog
2700  * SubFunction: NA
2701  * FunctionPoints: MissionListManager PrintTimeOutLog
2702  * EnvConditions: NA
2703  * CaseDescription: Verify PrintTimeOutLog
2704  */
2705 HWTEST_F(AbilityConnectManagerTest, PrintTimeOutLog_002, TestSize.Level1)
2706 {
2707     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2708     ASSERT_NE(connectManager, nullptr);
2709     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2710     uint32_t msgId = 0;
2711     connectManager->PrintTimeOutLog(abilityRecord, msgId);
2712     connectManager.reset();
2713 }
2714 
2715 /*
2716  * Feature: MissionListManager
2717  * Function: PrintTimeOutLog
2718  * SubFunction: NA
2719  * FunctionPoints: MissionListManager PrintTimeOutLog
2720  * EnvConditions: NA
2721  * CaseDescription: Verify PrintTimeOutLog
2722  */
2723 HWTEST_F(AbilityConnectManagerTest, PrintTimeOutLog_003, TestSize.Level1)
2724 {
2725     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2726     ASSERT_NE(connectManager, nullptr);
2727     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2728     uint32_t msgId = 1;
2729     connectManager->PrintTimeOutLog(abilityRecord, msgId);
2730     connectManager.reset();
2731 }
2732 
2733 /*
2734  * Feature: MissionListManager
2735  * Function: PrintTimeOutLog
2736  * SubFunction: NA
2737  * FunctionPoints: MissionListManager PrintTimeOutLog
2738  * EnvConditions: NA
2739  * CaseDescription: Verify PrintTimeOutLog
2740  */
2741 HWTEST_F(AbilityConnectManagerTest, PrintTimeOutLog_004, TestSize.Level1)
2742 {
2743     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2744     ASSERT_NE(connectManager, nullptr);
2745     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2746     uint32_t msgId = 2;
2747     connectManager->PrintTimeOutLog(abilityRecord, msgId);
2748     connectManager.reset();
2749 }
2750 
2751 /*
2752  * Feature: MissionListManager
2753  * Function: PrintTimeOutLog
2754  * SubFunction: NA
2755  * FunctionPoints: MissionListManager PrintTimeOutLog
2756  * EnvConditions: NA
2757  * CaseDescription: Verify PrintTimeOutLog
2758  */
2759 HWTEST_F(AbilityConnectManagerTest, PrintTimeOutLog_005, TestSize.Level1)
2760 {
2761     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2762     ASSERT_NE(connectManager, nullptr);
2763     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2764     uint32_t msgId = 4;
2765     connectManager->PrintTimeOutLog(abilityRecord, msgId);
2766     connectManager.reset();
2767 }
2768 
2769 /*
2770  * Feature: MissionListManager
2771  * Function: PrintTimeOutLog
2772  * SubFunction: NA
2773  * FunctionPoints: MissionListManager PrintTimeOutLog
2774  * EnvConditions: NA
2775  * CaseDescription: Verify PrintTimeOutLog
2776  */
2777 HWTEST_F(AbilityConnectManagerTest, PrintTimeOutLog_006, TestSize.Level1)
2778 {
2779     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2780     ASSERT_NE(connectManager, nullptr);
2781     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2782     uint32_t msgId = 5;
2783     connectManager->PrintTimeOutLog(abilityRecord, msgId);
2784     connectManager.reset();
2785 }
2786 
2787 /*
2788  * Feature: MissionListManager
2789  * Function: PrintTimeOutLog
2790  * SubFunction: NA
2791  * FunctionPoints: MissionListManager PrintTimeOutLog
2792  * EnvConditions: NA
2793  * CaseDescription: Verify PrintTimeOutLog
2794  */
2795 HWTEST_F(AbilityConnectManagerTest, PrintTimeOutLog_007, TestSize.Level1)
2796 {
2797     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2798     ASSERT_NE(connectManager, nullptr);
2799     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2800     uint32_t msgId = 6;
2801     connectManager->PrintTimeOutLog(abilityRecord, msgId);
2802     connectManager.reset();
2803 }
2804 
2805 /*
2806  * Feature: MissionListManager
2807  * Function: PrintTimeOutLog
2808  * SubFunction: NA
2809  * FunctionPoints: MissionListManager PrintTimeOutLog
2810  * EnvConditions: NA
2811  * CaseDescription: Verify PrintTimeOutLog
2812  */
2813 HWTEST_F(AbilityConnectManagerTest, PrintTimeOutLog_008, TestSize.Level1)
2814 {
2815     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2816     ASSERT_NE(connectManager, nullptr);
2817     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2818     uint32_t msgId = 3;
2819     connectManager->PrintTimeOutLog(abilityRecord, msgId);
2820     connectManager.reset();
2821 }
2822 
2823 /*
2824  * Feature: AbilityConnectManager
2825  * Function: OnAbilityRequestDone
2826  * SubFunction: NA
2827  * FunctionPoints: AbilityConnectManager OnAbilityRequestDone
2828  * EnvConditions: NA
2829  * CaseDescription: Verify OnAbilityRequestDone
2830  * @tc.require: AR000I8B26
2831  */
2832 HWTEST_F(AbilityConnectManagerTest, OnAbilityRequestDone_001, TestSize.Level1)
2833 {
2834     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2835     std::shared_ptr<AbilityRecord> abilityRecord = serviceRecord_;
2836     sptr<IRemoteObject> token = abilityRecord->GetToken();
2837     abilityRecord->abilityInfo_.extensionAbilityType = ExtensionAbilityType::UI;
2838     abilityRecord->SetAbilityState(AbilityState::INACTIVE);
2839     connectManager->serviceMap_.emplace("first", abilityRecord);
2840     connectManager->OnAbilityRequestDone(token, 2);
2841     EXPECT_EQ(abilityRecord->GetAbilityState(), AbilityState::FOREGROUNDING);
2842     connectManager->serviceMap_.erase("first");
2843     abilityRecord->abilityInfo_.extensionAbilityType = ExtensionAbilityType::UNSPECIFIED;
2844     abilityRecord->SetAbilityState(AbilityState::INITIAL);
2845 }
2846 
2847 /*
2848  * Feature: AbilityConnectManager
2849  * Function: ScheduleCommandAbilityWindowDone
2850  * SubFunction: NA
2851  * FunctionPoints: AbilityConnectManager ScheduleCommandAbilityWindowDone
2852  * EnvConditions: NA
2853  * CaseDescription: Verify ScheduleCommandAbilityWindowDone
2854  * @tc.require: AR000I8B26
2855  */
2856 HWTEST_F(AbilityConnectManagerTest, ScheduleCommandAbilityWindowDone_001, TestSize.Level1)
2857 {
2858     ConnectManager()->SetTaskHandler(TaskHandler());
2859     ConnectManager()->SetEventHandler(EventHandler());
2860     auto sessionInfo = MockSessionInfo(0);
2861 
2862     sptr<IRemoteObject> nullToken = nullptr;
2863     auto result = ConnectManager()->ScheduleCommandAbilityWindowDone(
2864         nullToken, sessionInfo, WIN_CMD_FOREGROUND, ABILITY_CMD_FOREGROUND);
2865     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
2866 
2867     std::shared_ptr<AbilityRecord> ability = nullptr;
2868     OHOS::sptr<OHOS::IRemoteObject> token1 = new OHOS::AAFwk::Token(ability);
2869     auto result1 = ConnectManager()->ScheduleCommandAbilityWindowDone(
2870         token1, sessionInfo, WIN_CMD_FOREGROUND, ABILITY_CMD_FOREGROUND);
2871     EXPECT_EQ(result1, OHOS::ERR_INVALID_VALUE);
2872 
2873     sptr<SessionInfo> nullSession = nullptr;
2874     auto result2 = ConnectManager()->ScheduleCommandAbilityWindowDone(
2875         serviceToken_, nullSession, WIN_CMD_FOREGROUND, ABILITY_CMD_FOREGROUND);
2876     EXPECT_EQ(result2, OHOS::ERR_INVALID_VALUE);
2877 
2878     auto result3 = ConnectManager()->ScheduleCommandAbilityWindowDone(
2879         serviceToken_, sessionInfo, WIN_CMD_FOREGROUND, ABILITY_CMD_FOREGROUND);
2880     EXPECT_EQ(result3, OHOS::ERR_OK);
2881 }
2882 
2883 /*
2884  * Feature: AbilityConnectManager
2885  * Function: ForegroundUIExtensionAbility
2886  * SubFunction: NA
2887  * FunctionPoints: MissionListManager ForegroundUIExtensionAbility
2888  * EnvConditions: NA
2889  * CaseDescription: Verify ForegroundUIExtensionAbility
2890  * @tc.require: AR000I8B26
2891  */
2892 HWTEST_F(AbilityConnectManagerTest, MoveToForeground_001, TestSize.Level1)
2893 {
2894     serviceRecord_->ForegroundUIExtensionAbility();
2895     EXPECT_EQ(serviceRecord_->GetAbilityState(), AbilityState::FOREGROUNDING);
2896     serviceRecord_->SetAbilityState(AbilityState::INITIAL);
2897 }
2898 
2899 /*
2900  * Feature: AbilityConnectManager
2901  * Function: DispatchForeground
2902  * SubFunction:
2903  * FunctionPoints: DispatchForeground
2904  * EnvConditions:NA
2905  * CaseDescription: Verify the DispatchForeground process
2906  * @tc.require: AR000I8B26
2907  */
2908 HWTEST_F(AbilityConnectManagerTest, DispatchForeground_001, TestSize.Level1)
2909 {
2910     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2911     ASSERT_NE(connectManager, nullptr);
2912     std::shared_ptr<AbilityRecord> ability = nullptr;
2913     auto result = connectManager->DispatchForeground(ability);
2914     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
2915 
2916     result = connectManager->DispatchForeground(serviceRecord_);
2917     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
2918 
2919     connectManager->SetTaskHandler(TaskHandler());
2920     connectManager->SetEventHandler(EventHandler());
2921     result = connectManager->DispatchForeground(serviceRecord_);
2922     EXPECT_EQ(result, OHOS::ERR_OK);
2923 }
2924 
2925 /*
2926  * Feature: AbilityConnectManager
2927  * Function: DispatchBackground
2928  * SubFunction:
2929  * FunctionPoints: DispatchBackground
2930  * EnvConditions:NA
2931  * CaseDescription: Verify the DispatchBackground process
2932  * @tc.require: AR000I8B26
2933  */
2934 HWTEST_F(AbilityConnectManagerTest, DispatchBackground_001, TestSize.Level1)
2935 {
2936     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2937     ASSERT_NE(connectManager, nullptr);
2938     std::shared_ptr<AbilityRecord> ability = nullptr;
2939     auto result = connectManager->DispatchBackground(ability);
2940     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
2941 
2942     result = connectManager->DispatchBackground(serviceRecord_);
2943     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
2944 
2945     connectManager->SetTaskHandler(TaskHandler());
2946     connectManager->SetEventHandler(EventHandler());
2947     result = connectManager->DispatchBackground(serviceRecord_);
2948     EXPECT_EQ(result, OHOS::ERR_OK);
2949 }
2950 
2951 /*
2952  * Feature: AbilityConnectManager
2953  * Function: HandleCommandWindowTimeoutTask
2954  * SubFunction: HandleCommandWindowTimeoutTask
2955  * FunctionPoints: NA
2956  * EnvConditions: NA
2957  * CaseDescription: Verify AbilityConnectManager HandleCommandWindowTimeoutTask
2958  * @tc.require: AR000I8B26
2959  */
2960 HWTEST_F(AbilityConnectManagerTest, HandleCommandWindowTimeoutTask_001, TestSize.Level1)
2961 {
2962     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2963     ASSERT_NE(connectManager, nullptr);
2964     connectManager->HandleCommandWindowTimeoutTask(serviceRecord_, MockSessionInfo(0), WIN_CMD_FOREGROUND);
2965 }
2966 
2967 /*
2968  * Feature: AbilityConnectManager
2969  * Function: CommandAbilityWindow
2970  * SubFunction: CommandAbilityWindow
2971  * FunctionPoints: NA
2972  * EnvConditions: NA
2973  * CaseDescription: Verify AbilityConnectManager CommandAbilityWindow
2974  * @tc.require: AR000I8B26
2975  */
2976 HWTEST_F(AbilityConnectManagerTest, CommandAbilityWindow_001, TestSize.Level1)
2977 {
2978     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
2979     ASSERT_NE(connectManager, nullptr);
2980     connectManager->SetTaskHandler(TaskHandler());
2981     connectManager->SetEventHandler(EventHandler());
2982     connectManager->CommandAbilityWindow(serviceRecord_, MockSessionInfo(0), WIN_CMD_FOREGROUND);
2983 }
2984 
2985 /*
2986  * Feature: AbilityConnectManager
2987  * Function: CompleteForeground
2988  * SubFunction: CompleteForeground
2989  * FunctionPoints: NA
2990  * EnvConditions: NA
2991  * CaseDescription: Verify AbilityConnectManager CompleteForeground
2992  * @tc.require: AR000I8B26
2993  */
2994 HWTEST_F(AbilityConnectManagerTest, CompleteForeground_001, TestSize.Level1)
2995 {
2996     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
2997     ASSERT_NE(connectManager, nullptr);
2998     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
2999     abilityRecord->currentState_ = AbilityState::BACKGROUND;
3000     connectManager->CompleteForeground(abilityRecord);
3001     EXPECT_EQ(abilityRecord->GetAbilityState(), AbilityState::BACKGROUND);
3002 
3003     abilityRecord->currentState_ = AbilityState::FOREGROUNDING;
3004     connectManager->CompleteForeground(abilityRecord);
3005     EXPECT_EQ(abilityRecord->GetAbilityState(), AbilityState::FOREGROUND);
3006     connectManager.reset();
3007 }
3008 
3009 /*
3010  * Feature: AbilityConnectManager
3011  * Function: AddUIExtWindowDeathRecipient
3012  * SubFunction: AddUIExtWindowDeathRecipient
3013  * FunctionPoints: NA
3014  * EnvConditions: NA
3015  * CaseDescription: Verify AbilityConnectManager AddUIExtWindowDeathRecipient
3016  * @tc.require: AR000I8B26
3017  */
3018 HWTEST_F(AbilityConnectManagerTest, AddUIExtWindowDeathRecipient_001, TestSize.Level1)
3019 {
3020     ConnectManager()->SetTaskHandler(TaskHandler());
3021     ConnectManager()->SetEventHandler(EventHandler());
3022     ConnectManager()->uiExtRecipientMap_.clear();
3023 
3024     ConnectManager()->AddUIExtWindowDeathRecipient(nullptr);
3025     EXPECT_TRUE(ConnectManager()->uiExtRecipientMap_.empty());
3026 
3027     ConnectManager()->AddUIExtWindowDeathRecipient(callbackA_->AsObject());
3028     EXPECT_EQ(static_cast<int>(ConnectManager()->uiExtRecipientMap_.size()), 1);
3029 
3030     // Add twice, do not add repeatedly
3031     ConnectManager()->AddUIExtWindowDeathRecipient(callbackA_->AsObject());
3032     EXPECT_EQ(static_cast<int>(ConnectManager()->uiExtRecipientMap_.size()), 1);
3033     ConnectManager()->uiExtRecipientMap_.clear();
3034 }
3035 
3036 /*
3037  * Feature: AbilityConnectManager
3038  * Function: RemoveUIExtWindowDeathRecipient
3039  * SubFunction:
3040  * FunctionPoints: RemoveUIExtWindowDeathRecipient
3041  * EnvConditions:NA
3042  * CaseDescription: Verify the RemoveUIExtWindowDeathRecipient process
3043  * @tc.require: AR000I8B26
3044  */
3045 HWTEST_F(AbilityConnectManagerTest, RemoveUIExtWindowDeathRecipient_001, TestSize.Level1)
3046 {
3047     ConnectManager()->SetTaskHandler(TaskHandler());
3048     ConnectManager()->SetEventHandler(EventHandler());
3049     ConnectManager()->uiExtRecipientMap_.clear();
3050 
3051     ConnectManager()->AddUIExtWindowDeathRecipient(callbackA_->AsObject());
3052     EXPECT_EQ(static_cast<int>(ConnectManager()->uiExtRecipientMap_.size()), 1);
3053 
3054     ConnectManager()->RemoveUIExtWindowDeathRecipient(nullptr);
3055     EXPECT_FALSE(ConnectManager()->uiExtRecipientMap_.empty());
3056 
3057     ConnectManager()->RemoveUIExtWindowDeathRecipient(callbackA_->AsObject());
3058     EXPECT_TRUE(ConnectManager()->uiExtRecipientMap_.empty());
3059 }
3060 
3061 /*
3062  * Feature: AbilityConnectManager
3063  * Function: OnUIExtWindowDied
3064  * SubFunction:
3065  * FunctionPoints: OnUIExtWindowDied
3066  * EnvConditions:NA
3067  * CaseDescription: Verify the OnUIExtWindowDied process
3068  * @tc.require: AR000I8B26
3069  */
3070 HWTEST_F(AbilityConnectManagerTest, OnUIExtWindowDied_001, TestSize.Level1)
3071 {
3072     ConnectManager()->SetTaskHandler(TaskHandler());
3073     ConnectManager()->SetEventHandler(EventHandler());
3074     ConnectManager()->uiExtRecipientMap_.clear();
3075     ConnectManager()->uiExtensionMap_.clear();
3076 
3077     ConnectManager()->uiExtensionMap_.emplace(
3078         callbackA_->AsObject(), AbilityConnectManager::UIExtWindowMapValType(serviceRecord_, MockSessionInfo(0)));
3079     ConnectManager()->AddUIExtWindowDeathRecipient(callbackA_->AsObject());
3080     ConnectManager()->OnUIExtWindowDied(nullptr);
3081     EXPECT_EQ(static_cast<int>(ConnectManager()->uiExtRecipientMap_.size()), 1);
3082     EXPECT_EQ(static_cast<int>(ConnectManager()->uiExtensionMap_.size()), 1);
3083 }
3084 
3085 /*
3086  * Feature: AbilityConnectManager
3087  * Function: HandleUIExtWindowDiedTask
3088  * SubFunction: HandleUIExtWindowDiedTask
3089  * FunctionPoints: NA
3090  * EnvConditions: NA
3091  * CaseDescription: Verify AbilityConnectManager HandleUIExtWindowDiedTask
3092  * @tc.require: AR000I8B26
3093  */
3094 HWTEST_F(AbilityConnectManagerTest, HandleUIExtWindowDiedTask_001, TestSize.Level1)
3095 {
3096     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
3097     ASSERT_NE(connectManager, nullptr);
3098     connectManager->uiExtRecipientMap_.clear();
3099     connectManager->uiExtensionMap_.clear();
3100 
3101     connectManager->uiExtensionMap_.emplace(
3102         callbackA_->AsObject(), AbilityConnectManager::UIExtWindowMapValType(serviceRecord_, MockSessionInfo(0)));
3103     connectManager->AddUIExtWindowDeathRecipient(callbackA_->AsObject());
3104     connectManager->HandleUIExtWindowDiedTask(nullptr);
3105     EXPECT_EQ(static_cast<int>(connectManager->uiExtRecipientMap_.size()), 1);
3106     EXPECT_EQ(static_cast<int>(connectManager->uiExtensionMap_.size()), 1);
3107 
3108     connectManager->HandleUIExtWindowDiedTask(callbackA_->AsObject());
3109     EXPECT_TRUE(connectManager->uiExtRecipientMap_.empty());
3110     EXPECT_TRUE(connectManager->uiExtensionMap_.empty());
3111 }
3112 
3113 /*
3114  * Feature: AbilityConnectManager
3115  * Function: IsUIExtensionFocused
3116  * SubFunction: IsUIExtensionFocused
3117  * FunctionPoints: NA
3118  * EnvConditions: NA
3119  * CaseDescription: Verify AbilityConnectManager IsUIExtensionFocused
3120  */
3121 HWTEST_F(AbilityConnectManagerTest, IsUIExtensionFocused_001, TestSize.Level1)
3122 {
3123     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
3124     ASSERT_NE(connectManager, nullptr);
3125     connectManager->uiExtensionMap_.clear();
3126     bool isFocused = connectManager->IsUIExtensionFocused(
3127         serviceRecord_->GetApplicationInfo().accessTokenId, serviceRecord1_->GetToken());
3128     EXPECT_EQ(isFocused, false);
3129     connectManager.reset();
3130 }
3131 
3132 /*
3133  * Feature: AbilityConnectManager
3134  * Function: IsUIExtensionFocused
3135  * SubFunction: IsUIExtensionFocused
3136  * FunctionPoints: NA
3137  * EnvConditions: NA
3138  * CaseDescription: Verify AbilityConnectManager IsUIExtensionFocused
3139  */
3140 HWTEST_F(AbilityConnectManagerTest, IsUIExtensionFocused_002, TestSize.Level1)
3141 {
3142     AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
3143     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
3144     ASSERT_NE(connectManager, nullptr);
3145     connectManager->uiExtensionMap_.clear();
3146 
3147     std::string device = "device";
3148     std::string abilityName = "uiExtensionUserAbility";
3149     std::string appName = "uiExtensionUser";
3150     std::string bundleName = "com.ix.uiExtensionUser";
3151     std::string moduleName = "entry";
3152     auto request = GenerateAbilityRequest(device, abilityName, appName, bundleName, moduleName);
3153     auto uiExtensionUser = AbilityRecord::CreateAbilityRecord(request);
3154     EXPECT_NE(uiExtensionUser, nullptr);
3155 
3156     std::string abilityName1 = "uiExtensionAbility1";
3157     std::string appName1 = "uiExtensionProvider1";
3158     std::string bundleName1 = "com.ix.uiExtensionProvider1";
3159     std::string moduleName1 = "entry";
3160     auto request1 = GenerateAbilityRequest(device, abilityName1, appName1, bundleName1, moduleName1);
3161     auto uiExtension1 = AbilityRecord::CreateAbilityRecord(request1);
3162     EXPECT_NE(uiExtension1, nullptr);
3163     uiExtension1->abilityInfo_.extensionAbilityType = ExtensionAbilityType::SYS_COMMON_UI;
3164     sptr<SessionInfo> sessionInfo1 = new (std::nothrow) SessionInfo();
3165     sessionInfo1->callerToken = uiExtensionUser->GetToken();
3166     uiExtension1->sessionInfo_ = sessionInfo1;
3167     connectManager->uiExtensionMap_.emplace(
3168         callbackA_->AsObject(), AbilityConnectManager::UIExtWindowMapValType(uiExtension1, sessionInfo1));
3169     bool isFocused1 = connectManager->IsUIExtensionFocused(
3170         uiExtension1->GetApplicationInfo().accessTokenId, uiExtensionUser->GetToken());
3171     EXPECT_EQ(isFocused1, true);
3172     std::string abilityName2 = "uiExtensionAbility2";
3173     std::string appName2 = "uiExtensionProvider2";
3174     std::string bundleName2 = "com.ix.uiExtensionProvider2";
3175     std::string moduleName2 = "entry";
3176     auto request2 = GenerateAbilityRequest(device, abilityName2, appName2, bundleName2, moduleName2);
3177     auto uiExtension2 = AbilityRecord::CreateAbilityRecord(request2);
3178     EXPECT_NE(uiExtension2, nullptr);
3179     uiExtension2->abilityInfo_.extensionAbilityType = ExtensionAbilityType::SYS_COMMON_UI;
3180     sptr<SessionInfo> sessionInfo2 = new (std::nothrow) SessionInfo();
3181     sessionInfo2->callerToken = uiExtension1->GetToken();
3182     uiExtension2->sessionInfo_ = sessionInfo2;
3183     connectManager->uiExtensionMap_.emplace(
3184         callbackA_->AsObject(), AbilityConnectManager::UIExtWindowMapValType(uiExtension2, sessionInfo2));
3185     bool isFocused2 = connectManager->IsUIExtensionFocused(
3186         uiExtension2->GetApplicationInfo().accessTokenId, uiExtensionUser->GetToken());
3187     EXPECT_EQ(isFocused2, true);
3188     connectManager.reset();
3189 }
3190 
3191 /*
3192  * Feature: AbilityConnectManager
3193  * Function: GetUIExtensionSourceToken
3194  * SubFunction: GetUIExtensionSourceToken
3195  * FunctionPoints: NA
3196  * EnvConditions: NA
3197  * CaseDescription: Verify AbilityConnectManager GetUIExtensionSourceToken
3198  */
3199 HWTEST_F(AbilityConnectManagerTest, GetUIExtensionSourceToken_001, TestSize.Level1)
3200 {
3201     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(3);
3202     ASSERT_NE(connectManager, nullptr);
3203     connectManager->uiExtensionMap_.clear();
3204     auto sourceToken = connectManager->GetUIExtensionSourceToken(nullptr);
3205     EXPECT_EQ(sourceToken, nullptr);
3206     connectManager.reset();
3207 }
3208 
3209 /*
3210  * Feature: AbilityConnectManager
3211  * Function: PauseExtensions
3212  * SubFunction: PauseExtensions
3213  * FunctionPoints: NA
3214  * EnvConditions: NA
3215  * CaseDescription: Verify AbilityConnectManager PauseExtensions
3216  */
3217 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_PauseExtensions_001, TestSize.Level1)
3218 {
3219     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
3220     ASSERT_NE(connectManager, nullptr);
3221     std::shared_ptr<AbilityRecord> abilityRecord1 = serviceRecord_;
3222     abilityRecord1->abilityInfo_.type = AbilityType::PAGE;
3223     connectManager->serviceMap_.emplace("first", abilityRecord1);
3224     std::shared_ptr<AbilityRecord> abilityRecord2 = AbilityRecord::CreateAbilityRecord(abilityRequest_);
3225     abilityRecord2->abilityInfo_.type = AbilityType::EXTENSION;
3226     abilityRecord2->abilityInfo_.name = AbilityConfig::LAUNCHER_ABILITY_NAME;
3227     abilityRecord2->abilityInfo_.bundleName = AbilityConfig::LAUNCHER_BUNDLE_NAME;
3228     connectManager->serviceMap_.emplace("second", abilityRecord2);
3229     connectManager->PauseExtensions();
3230 }
3231 
3232 /*
3233  * Feature: AbilityConnectManager
3234  * Function: SignRestartAppFlag
3235  * CaseDescription: Verify AbilityConnectManager SignRestartAppFlag
3236  */
3237 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_SignRestartAppFlag_001, TestSize.Level1)
3238 {
3239     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
3240     ASSERT_NE(connectManager, nullptr);
3241 
3242     std::string bundleName = "testBundleName";
3243     std::shared_ptr<AbilityRecord> abilityRecord1 = serviceRecord_;
3244     abilityRecord1->abilityInfo_.bundleName = bundleName;
3245     connectManager->serviceMap_.emplace("first", abilityRecord1);
3246     std::shared_ptr<AbilityRecord> abilityRecord2 = AbilityRecord::CreateAbilityRecord(abilityRequest_);
3247     abilityRecord2->abilityInfo_.bundleName = "errTestBundleName";
3248     connectManager->serviceMap_.emplace("second", abilityRecord2);
3249     int32_t uid = 100;
3250     connectManager->SignRestartAppFlag(uid, "");
3251 }
3252 
3253 /*
3254  * Feature: AbilityConnectManager
3255  * Function: BuildEventInfo
3256  * CaseDescription: Verify AbilityConnectManager BuildEventInfo
3257  */
3258 HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_BuildEventInfo_001, TestSize.Level1)
3259 {
3260     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
3261     ASSERT_NE(connectManager, nullptr);
3262 
3263     connectManager->BuildEventInfo(nullptr);
3264     std::shared_ptr<AbilityRecord> abilityRecord = InitAbilityRecord();
3265     connectManager->BuildEventInfo(abilityRecord);
3266     abilityRecord->SetCreateByConnectMode(true);
3267     connectManager->BuildEventInfo(abilityRecord);
3268 }
3269 
3270 /**
3271  * @tc.name: UpdateUIExtensionInfo_0100
3272  * @tc.desc: Update want params of ui extension.
3273  * @tc.type: FUNC
3274  */
3275 HWTEST_F(AbilityConnectManagerTest, UpdateUIExtensionInfo_0100, TestSize.Level1)
3276 {
3277     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
3278     ASSERT_NE(connectManager, nullptr);
3279 
3280     Want want;
3281     AppExecFwk::AbilityInfo abilityInfo;
3282     abilityInfo.extensionAbilityType = ExtensionAbilityType::SYS_COMMON_UI;
3283     AppExecFwk::ApplicationInfo applicationInfo;
3284     auto abilityRecord = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
3285     abilityRecord->SetUIExtensionAbilityId(1000);
3286     connectManager->UpdateUIExtensionInfo(abilityRecord);
3287     EXPECT_EQ(abilityRecord->GetWant().HasParameter("ability.want.params.uiExtensionAbilityId"), true);
3288     EXPECT_EQ(abilityRecord->GetWant().GetIntParam("ability.want.params.uiExtensionAbilityId", -1), 1000);
3289 }
3290 
3291 /**
3292  * @tc.name: PreloadUIExtensionAbilityLocked_0100
3293  * @tc.desc: preload uiextension ability
3294  * @tc.type: FUNC
3295  */
3296 HWTEST_F(AbilityConnectManagerTest, PreloadUIExtensionAbilityLocked_0100, TestSize.Level1)
3297 {
3298     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
3299     ASSERT_NE(connectManager, nullptr);
3300 
3301     AbilityRequest abilityRequest;
3302     AppExecFwk::ElementName providerElement("0", "com.ohos.uiextensionprovider", "UIExtensionProvider", "entry");
3303     abilityRequest.want.SetElement(providerElement);
3304     abilityRequest.abilityInfo.type = AbilityType::EXTENSION;
3305     std::string hostBundleName = "com.ohos.uiextensionuser";
3306     auto ret = connectManager->PreloadUIExtensionAbilityLocked(abilityRequest, hostBundleName);
3307     EXPECT_NE(ret, ERR_OK);
3308 }
3309 
3310 /**
3311  * @tc.name: UnloadUIExtensionAbility_0100
3312  * @tc.desc: UnloadUIExtensionAbility
3313  * @tc.type: FUNC
3314  */
3315 HWTEST_F(AbilityConnectManagerTest, UnloadUIExtensionAbility_0100, TestSize.Level1)
3316 {
3317     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
3318     ASSERT_NE(connectManager, nullptr);
3319 
3320     AbilityRequest abilityRequest;
3321     AppExecFwk::ElementName providerElement("0", "com.ohos.uiextensionprovider", "UIExtensionProvider", "entry");
3322     abilityRequest.want.SetElement(providerElement);
3323     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
3324     std::string hostBundleName = "com.ohos.uiextensionuser";
3325     auto ret = connectManager->UnloadUIExtensionAbility(abilityRecord, hostBundleName);
3326     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3327 }
3328 
3329 /**
3330  * @tc.name: AbilityWindowConfigTransactionDone_0100
3331  * @tc.desc: AbilityWindowConfigTransactionDone
3332  * @tc.type: FUNC
3333  */
3334 HWTEST_F(AbilityConnectManagerTest, AbilityWindowConfigTransactionDone_0100, TestSize.Level1)
3335 {
3336     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
3337     ASSERT_NE(connectManager, nullptr);
3338 
3339     WindowConfig windowConfig;
3340     auto ret = connectManager->AbilityWindowConfigTransactionDone(serviceToken_, windowConfig);
3341     EXPECT_EQ(ret, ERR_OK);
3342 }
3343 
3344 /**
3345  * @tc.name: UpdateKeepAliveEnableState_0100
3346  * @tc.desc: UpdateKeepAliveEnableState
3347  * @tc.type: FUNC
3348  */
3349 HWTEST_F(AbilityConnectManagerTest, UpdateKeepAliveEnableState_0100, TestSize.Level1)
3350 {
3351     std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
3352     ASSERT_NE(connectManager, nullptr);
3353 
3354     auto ret = connectManager->UpdateKeepAliveEnableState("bundle", "entry", "mainAbility", true);
3355     EXPECT_EQ(ret, ERR_OK);
3356 }
3357 }  // namespace AAFwk
3358 }  // namespace OHOS
3359