1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <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 #include "extension_record_factory.h"
25 #include "ability_util.h"
26 #include "hilog_tag_wrapper.h"
27
28 using namespace testing::ext;
29 using namespace OHOS::AppExecFwk;
30
31 namespace {
32 const std::string VASSISTANT_BUNDLE_NAME = "com.huawei.hmos.vassistant";
33 const std::string VASSISTANT_B2 = "com.huawei.hmos.vassistant.test";
34 constexpr size_t LOAD_TIMEOUT = 0;
35 constexpr size_t ACTIVE_TIMEOUT = 1;
36 constexpr size_t INACTIVE_TIMEOUT = 2;
37 constexpr size_t FOREGROUND_TIMEOUT = 5;
38 constexpr size_t BACKGROUND_TIMEOUT = 6;
39 constexpr size_t TERMINATE_TIMEOUT = 4;
40 constexpr size_t CONNECT_TIMEOUT = 10;
41 constexpr size_t INVALID_TIMEOUT = 11;
42 }
43
44 namespace OHOS {
45 namespace AAFwk {
46 class AbilityConnectManagerSecondTest : public testing::Test {
47 public:
48 static void SetUpTestCase(void);
49 static void TearDownTestCase(void);
50 void SetUp();
51 void TearDown();
52 AbilityRequest GenerateAbilityRequest(const std::string& deviceName, const std::string& abilityName,
53 const std::string& appName, const std::string& bundleName, const std::string& moduleName);
54
55 protected:
56 AbilityRequest abilityRequest_{};
57 std::shared_ptr<AbilityRecord> serviceRecord_{ nullptr };
58
59 private:
60 std::shared_ptr<AbilityConnectManager> connectManager_;
61 };
62
GenerateAbilityRequest(const std::string & deviceName,const std::string & abilityName,const std::string & appName,const std::string & bundleName,const std::string & moduleName)63 AbilityRequest AbilityConnectManagerSecondTest::GenerateAbilityRequest(const std::string& deviceName,
64 const std::string& abilityName, const std::string& appName, const std::string& bundleName,
65 const std::string& moduleName)
66 {
67 ElementName element(deviceName, bundleName, abilityName, moduleName);
68 Want want;
69 want.SetElement(element);
70
71 AbilityInfo abilityInfo;
72 abilityInfo.visible = true;
73 abilityInfo.applicationName = appName;
74 abilityInfo.type = AbilityType::SERVICE;
75 abilityInfo.name = abilityName;
76 abilityInfo.bundleName = bundleName;
77 abilityInfo.moduleName = moduleName;
78 abilityInfo.deviceId = deviceName;
79 ApplicationInfo appinfo;
80 appinfo.name = appName;
81 abilityInfo.applicationInfo = appinfo;
82 AbilityRequest abilityRequest;
83 abilityRequest.want = want;
84 abilityRequest.abilityInfo = abilityInfo;
85 abilityRequest.appInfo = appinfo;
86 abilityInfo.process = bundleName;
87
88 return abilityRequest;
89 }
90
SetUpTestCase(void)91 void AbilityConnectManagerSecondTest::SetUpTestCase(void)
92 {}
93
TearDownTestCase(void)94 void AbilityConnectManagerSecondTest::TearDownTestCase(void)
95 {}
96
SetUp(void)97 void AbilityConnectManagerSecondTest::SetUp(void)
98 {
99 connectManager_ = std::make_unique<AbilityConnectManager>(0);
100 std::string deviceName = "device";
101 std::string abilityName = "ServiceAbility";
102 std::string appName = "hiservcie";
103 std::string bundleName = "com.ix.hiservcie";
104 std::string moduleName = "entry";
105 abilityRequest_ = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName, moduleName);
106 serviceRecord_ = AbilityRecord::CreateAbilityRecord(abilityRequest_);
107 }
108
TearDown(void)109 void AbilityConnectManagerSecondTest::TearDown(void)
110 {
111 serviceRecord_ = nullptr;
112 }
113
114 /*
115 * Feature: AbilityConnectManager
116 * Function: PreloadUIExtensionAbilityInner
117 */
118 HWTEST_F(AbilityConnectManagerSecondTest, PreloadUIExtensionAbilityInner_001, TestSize.Level1)
119 {
120 TAG_LOGI(AAFwkTag::TEST, "PreloadUIExtensionAbilityInner_001 start");
121 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
122 EXPECT_NE(connectManager, nullptr);
123 std::string hostBundleName = "hostBundleName";
124 int32_t hostPid = 1;
125
126 auto res = connectManager->PreloadUIExtensionAbilityInner(abilityRequest_, hostBundleName, hostPid);
127 EXPECT_EQ(res, ERR_WRONG_INTERFACE_CALL);
128
129 abilityRequest_.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SHARE;
130 res = connectManager->PreloadUIExtensionAbilityInner(abilityRequest_, hostBundleName, hostPid);
131 EXPECT_EQ(res, ERR_OK);
132
133 abilityRequest_.want.SetParam(Want::CREATE_APP_INSTANCE_KEY, true);
134 res = connectManager->PreloadUIExtensionAbilityInner(abilityRequest_, hostBundleName, hostPid);
135 EXPECT_EQ(res, ERR_INVALID_VALUE);
136
137 abilityRequest_.want.SetParam(Want::CREATE_APP_INSTANCE_KEY, false);
138 abilityRequest_.extensionType = AppExecFwk::ExtensionAbilityType::EMBEDDED_UI;
139 res = connectManager->PreloadUIExtensionAbilityInner(abilityRequest_, hostBundleName, hostPid);
140 EXPECT_EQ(res, ERR_INVALID_VALUE);
141 TAG_LOGI(AAFwkTag::TEST, "PreloadUIExtensionAbilityInner_001 end");
142 }
143
144 /*
145 * Feature: AbilityConnectManager
146 * Function: GetExtensionByIdFromTerminatingMap
147 */
148 HWTEST_F(AbilityConnectManagerSecondTest, GetExtensionByIdFromTerminatingMap_001, TestSize.Level1)
149 {
150 TAG_LOGI(AAFwkTag::TEST, "GetExtensionByIdFromTerminatingMap_001 start");
151 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
152 EXPECT_NE(connectManager, nullptr);
153 int64_t abilityRecordId = 1;
154
155 std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest_);
156 connectManager->terminatingExtensionList_.push_back(nullptr);
157 auto res = connectManager->GetExtensionByIdFromTerminatingMap(abilityRecordId);
158 EXPECT_EQ(res, nullptr);
159
160 connectManager->terminatingExtensionList_.push_back(abilityRecord);
161 res = connectManager->GetExtensionByIdFromTerminatingMap(abilityRecordId);
162 EXPECT_EQ(res, nullptr);
163
164 abilityRecordId = abilityRecord->GetAbilityRecordId();
165 res = connectManager->GetExtensionByIdFromTerminatingMap(abilityRecordId);
166 EXPECT_NE(res, nullptr);
167 TAG_LOGI(AAFwkTag::TEST, "GetExtensionByIdFromTerminatingMap_001 end");
168 }
169
170 /*
171 * Feature: AbilityConnectManager
172 * Function: ReportXiaoYiToRSSIfNeeded
173 */
174 HWTEST_F(AbilityConnectManagerSecondTest, ReportXiaoYiToRSSIfNeeded_001, TestSize.Level1)
175 {
176 TAG_LOGI(AAFwkTag::TEST, "GetExtensionByIdFromTerminatingMap_001 start");
177 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
178 EXPECT_NE(connectManager, nullptr);
179
180 abilityRequest_.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION;
181 auto res = connectManager->ReportXiaoYiToRSSIfNeeded(abilityRequest_.abilityInfo);
182 EXPECT_EQ(res, ERR_OK);
183
184 abilityRequest_.abilityInfo.type = AppExecFwk::AbilityType::UNKNOWN;
185 abilityRequest_.abilityInfo.bundleName = VASSISTANT_BUNDLE_NAME;
186 res = connectManager->ReportXiaoYiToRSSIfNeeded(abilityRequest_.abilityInfo);
187 EXPECT_EQ(res, ERR_OK);
188
189 abilityRequest_.abilityInfo.bundleName = VASSISTANT_B2;
190 res = connectManager->ReportXiaoYiToRSSIfNeeded(abilityRequest_.abilityInfo);
191 EXPECT_EQ(res, ERR_OK);
192
193 abilityRequest_.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION;
194 abilityRequest_.abilityInfo.bundleName = VASSISTANT_BUNDLE_NAME;
195 res = connectManager->ReportXiaoYiToRSSIfNeeded(abilityRequest_.abilityInfo);
196 EXPECT_EQ(res, ERR_OK);
197
198 abilityRequest_.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION;
199 abilityRequest_.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE;
200 abilityRequest_.abilityInfo.bundleName = VASSISTANT_BUNDLE_NAME;
201 res = connectManager->ReportXiaoYiToRSSIfNeeded(abilityRequest_.abilityInfo);
202 EXPECT_EQ(res, ERR_OK);
203
204 TAG_LOGI(AAFwkTag::TEST, "ReportXiaoYiToRSSIfNeeded_001 end");
205 }
206
207 /*
208 * Feature: AbilityConnectManager
209 * Function: UpdateKeepAliveEnableState
210 */
211 HWTEST_F(AbilityConnectManagerSecondTest, UpdateKeepAliveEnableState_001, TestSize.Level1)
212 {
213 TAG_LOGI(AAFwkTag::TEST, "UpdateKeepAliveEnableState_001 start");
214 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
215 EXPECT_NE(connectManager, nullptr);
216 std::string bundleName = "";
217 std::string moduleName = "";
218 std::string mainElement = "";
219 bool updateEnable = false;
220
221 abilityRequest_.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION;
222 auto res = connectManager->UpdateKeepAliveEnableState(bundleName, moduleName, mainElement, updateEnable);
223 EXPECT_EQ(res, ERR_OK);
224
225 std::string key = "testKey";
226 connectManager->serviceMap_.emplace(key, serviceRecord_);
227 res = connectManager->UpdateKeepAliveEnableState(bundleName, moduleName, mainElement, updateEnable);
228 EXPECT_EQ(res, ERR_OK);
229
230 bundleName = serviceRecord_->GetAbilityInfo().bundleName;
231 res = connectManager->UpdateKeepAliveEnableState(bundleName, moduleName, mainElement, updateEnable);
232 EXPECT_EQ(res, ERR_OK);
233
234 mainElement = serviceRecord_->GetAbilityInfo().name;
235 res = connectManager->UpdateKeepAliveEnableState(bundleName, moduleName, mainElement, updateEnable);
236 EXPECT_EQ(res, ERR_OK);
237
238 moduleName = serviceRecord_->GetAbilityInfo().moduleName;
239 res = connectManager->UpdateKeepAliveEnableState(bundleName, moduleName, mainElement, updateEnable);
240 EXPECT_EQ(res, ERR_OK);
241
242 TAG_LOGI(AAFwkTag::TEST, "RUpdateKeepAliveEnableState_001 end");
243 }
244
245 /*
246 * Feature: AbilityConnectManager
247 * Function: HandleCommandTimeoutTask
248 */
249 HWTEST_F(AbilityConnectManagerSecondTest, HandleCommandTimeoutTask_001, TestSize.Level1)
250 {
251 TAG_LOGI(AAFwkTag::TEST, "HandleCommandTimeoutTask_001 start");
252
253 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(100);
254 EXPECT_NE(connectManager, nullptr);
255
256 ASSERT_NE(serviceRecord_, nullptr);
257 serviceRecord_->SetAbilityState(AbilityState::INACTIVE);
258
259 std::string serviceKey = serviceRecord_->GetURI();
260 connectManager->AddToServiceMap(serviceKey, serviceRecord_);
261
262 connectManager->HandleCommandTimeoutTask(serviceRecord_);
263 auto serviceMap = connectManager->GetServiceMap();
264 EXPECT_TRUE(serviceMap.find(serviceKey) == serviceMap.end());
265
266 TAG_LOGI(AAFwkTag::TEST, "HandleCommandTimeoutTask_001 end");
267 }
268
269 /*
270 * Feature: AbilityConnectManager
271 * Function: HandleInactiveTimeout
272 */
273 HWTEST_F(AbilityConnectManagerSecondTest, HandleInactiveTimeout_001, TestSize.Level1)
274 {
275 TAG_LOGI(AAFwkTag::TEST, "HandleInactiveTimeout_001 start");
276
277 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(100);
278 EXPECT_NE(connectManager, nullptr);
279
280 ASSERT_NE(serviceRecord_, nullptr);
281 serviceRecord_->SetAbilityState(AbilityState::INACTIVE);
282
283 std::string serviceKey = serviceRecord_->GetURI();
284 connectManager->AddToServiceMap(serviceKey, serviceRecord_);
285
286 connectManager->HandleInactiveTimeout(serviceRecord_);
287 auto serviceMap = connectManager->GetServiceMap();
288 EXPECT_TRUE(serviceMap.find(serviceKey) == serviceMap.end());
289
290 TAG_LOGI(AAFwkTag::TEST, "HandleInactiveTimeout_001 end");
291 }
292 /*
293 * Feature: AbilityConnectManager
294 * Function: GetTimeoutMsgContent
295 */
296 HWTEST_F(AbilityConnectManagerSecondTest, GetTimeoutMsgContent_001, TestSize.Level1)
297 {
298 TAG_LOGI(AAFwkTag::TEST, "GetTimeoutMsgContent_001 start");
299 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
300 ASSERT_NE(connectManager, nullptr);
301 int typeId = 0;
302 std::string msgStr;
303 std::string expected = "load timeout";
304 uint32_t msgId = LOAD_TIMEOUT;
305 connectManager->GetTimeoutMsgContent(msgId, msgStr, typeId);
306 ASSERT_EQ(msgStr, expected);
307
308 msgStr = "";
309 expected = "active timeout";
310 msgId = ACTIVE_TIMEOUT;
311 connectManager->GetTimeoutMsgContent(msgId, msgStr, typeId);
312 ASSERT_EQ(msgStr, expected);
313
314 msgStr = "";
315 expected = "inactive timeout";
316 msgId = INACTIVE_TIMEOUT;
317 connectManager->GetTimeoutMsgContent(msgId, msgStr, typeId);
318 ASSERT_EQ(msgStr, expected);
319 TAG_LOGI(AAFwkTag::TEST, "GetTimeoutMsgContent_001 end");
320 }
321
322 /*
323 * Feature: AbilityConnectManager
324 * Function: GetTimeoutMsgContent
325 */
326 HWTEST_F(AbilityConnectManagerSecondTest, GetTimeoutMsgContent_002, TestSize.Level1)
327 {
328 TAG_LOGI(AAFwkTag::TEST, "GetTimeoutMsgContent_002 start");
329 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
330 ASSERT_NE(connectManager, nullptr);
331 int typeId = 0;
332 std::string msgStr;
333 std::string expected = "background timeout";
334 uint32_t msgId = BACKGROUND_TIMEOUT;
335 connectManager->GetTimeoutMsgContent(msgId, msgStr, typeId);
336 ASSERT_EQ(msgStr, expected);
337
338 msgStr = "";
339 expected = "terminate timeout";
340 msgId = TERMINATE_TIMEOUT;
341 connectManager->GetTimeoutMsgContent(msgId, msgStr, typeId);
342 ASSERT_EQ(msgStr, expected);
343
344 msgStr = "";
345 expected = "connect timeout";
346 msgId = CONNECT_TIMEOUT;
347 connectManager->GetTimeoutMsgContent(msgId, msgStr, typeId);
348 ASSERT_EQ(msgStr, expected);
349 TAG_LOGI(AAFwkTag::TEST, "GetTimeoutMsgContent_002 end");
350 }
351
352 /*
353 * Feature: AbilityConnectManager
354 * Function: GetTimeoutMsgContent
355 */
356 HWTEST_F(AbilityConnectManagerSecondTest, GetTimeoutMsgContent_003, TestSize.Level1)
357 {
358 TAG_LOGI(AAFwkTag::TEST, "GetTimeoutMsgContent_003 start");
359 TAG_LOGI(AAFwkTag::TEST, "GetTimeoutMsgContent_002 start");
360 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
361 ASSERT_NE(connectManager, nullptr);
362
363 int typeId = 0;
364 std::string msgStr;
365 std::string expected = "foreground timeout";
366 uint32_t msgId = FOREGROUND_TIMEOUT;
367 connectManager->GetTimeoutMsgContent(msgId, msgStr, typeId);
368 ASSERT_EQ(msgStr, expected);
369
370 msgId = INVALID_TIMEOUT;
371 bool result = connectManager->GetTimeoutMsgContent(msgId, msgStr, typeId);
372 EXPECT_FALSE(result);
373 TAG_LOGI(AAFwkTag::TEST, "GetTimeoutMsgContent_003 end");
374 }
375
376 /*
377 * Feature: AbilityConnectManager
378 * Function: GenerateBundleName
379 */
380 HWTEST_F(AbilityConnectManagerSecondTest, GenerateBundleName_001, TestSize.Level1)
381 {
382 TAG_LOGI(AAFwkTag::TEST, "GenerateBundleName_001 start");
383 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
384 ASSERT_NE(connectManager, nullptr);
385
386 AbilityRequest abilityRequest;
387 abilityRequest.abilityInfo.bundleName = "com.example.unittest";
388 abilityRequest.appInfo.multiAppMode.multiAppModeType = AppExecFwk::MultiAppModeType::UNSPECIFIED;
389 abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SHARE;
390 connectManager->GenerateBundleName(abilityRequest);
391 ASSERT_EQ(abilityRequest.abilityInfo.bundleName, "com.example.unittest");
392 TAG_LOGI(AAFwkTag::TEST, "GenerateBundleName_001 end");
393 }
394
395 /*
396 * Feature: AbilityConnectManager
397 * Function: HandleRestartResidentTask
398 */
399 HWTEST_F(AbilityConnectManagerSecondTest, HandleRestartResidentTask_001, TestSize.Level1)
400 {
401 TAG_LOGI(AAFwkTag::TEST, "HandleRestartResidentTask_001 start");
402 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
403 ASSERT_NE(connectManager, nullptr);
404
405 AbilityRequest req;
406 req.want.SetElementName("com.example.bundle", "com.example.module", "MainAbility");
407 AbilityRequest taskReq;
408 taskReq.want.SetElementName("com.example.bundle", "com.example.module", "MainAbility");
409 connectManager->restartResidentTaskList_.push_back(taskReq);
410 ASSERT_EQ(connectManager->restartResidentTaskList_.size(), 1);
411
412 connectManager->HandleRestartResidentTask(req);
413 ASSERT_EQ(connectManager->restartResidentTaskList_.size(), 0);
414 TAG_LOGI(AAFwkTag::TEST, "HandleRestartResidentTask_001 end");
415 }
416
417 /*
418 * Feature: AbilityConnectManager
419 * Function: HandleRestartResidentTask
420 */
421 HWTEST_F(AbilityConnectManagerSecondTest, HandleRestartResidentTask_002, TestSize.Level1)
422 {
423 TAG_LOGI(AAFwkTag::TEST, "HandleRestartResidentTask_002 start");
424 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
425 ASSERT_NE(connectManager, nullptr);
426
427 AbilityRequest req;
428 req.want.SetElementName("com.example.bundle", "com.example.module", "MainAbility");
429 AbilityRequest task;
430 task.want.SetElementName("com.other.bundle", "com.other.module", "OtherAbility");
431 connectManager->restartResidentTaskList_.push_back(task);
432 ASSERT_EQ(connectManager->restartResidentTaskList_.size(), 1);
433
434 connectManager->HandleRestartResidentTask(req);
435 ASSERT_EQ(connectManager->restartResidentTaskList_.size(), 1);
436 TAG_LOGI(AAFwkTag::TEST, "HandleRestartResidentTask_002 end");
437 }
438
439 /*
440 * Feature: AbilityConnectManager
441 * Function: HandleRestartResidentTask
442 */
443 HWTEST_F(AbilityConnectManagerSecondTest, HandleRestartResidentTask_003, TestSize.Level1)
444 {
445 TAG_LOGI(AAFwkTag::TEST, "HandleRestartResidentTask_003 start");
446 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
447 ASSERT_NE(connectManager, nullptr);
448
449 AbilityRequest req;
450 req.want.SetElementName("com.example.bundle", "com.example.module", "MainAbility");
451 ASSERT_TRUE(connectManager->restartResidentTaskList_.empty());
452
453 connectManager->HandleRestartResidentTask(req);
454 ASSERT_TRUE(connectManager->restartResidentTaskList_.empty());
455 TAG_LOGI(AAFwkTag::TEST, "HandleRestartResidentTask_003 end");
456 }
457
458 /*
459 * Feature: AbilityConnectManager
460 * Function: DisconnectRecordForce
461 */
462 HWTEST_F(AbilityConnectManagerSecondTest, DisconnectRecordForce_ConnectRecordIsNotLast_001, TestSize.Level1)
463 {
464 TAG_LOGI(AAFwkTag::TEST, "DisconnectRecordForce_ConnectRecordIsNotLast_001 start");
465 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
466 ASSERT_NE(connectManager, nullptr);
467
468 AbilityRequest req;
469 req.want.SetElementName("com.example.bundle", "com.example.module", "MainAbility");
470
471 auto abilityRecord = AbilityRecord::CreateAbilityRecord(req);
472 EXPECT_TRUE(abilityRecord);
473 EXPECT_TRUE(abilityRecord->IsConnectListEmpty());
474
475 auto token = abilityRecord->GetToken();
476 auto connectionRecord = ConnectionRecord::CreateConnectionRecord(token, abilityRecord, nullptr, connectManager);
477 EXPECT_TRUE(connectionRecord);
478
479 abilityRecord->AddConnectRecordToList(connectionRecord);
480 EXPECT_FALSE(abilityRecord->IsConnectListEmpty());
481
482 auto connectionRecord2 = ConnectionRecord::CreateConnectionRecord(nullptr, nullptr, nullptr, connectManager);
483 EXPECT_TRUE(connectionRecord2);
484 abilityRecord->AddConnectRecordToList(connectionRecord2);
485 abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::UI_SERVICE;
486
487 std::list<std::shared_ptr<ConnectionRecord>> list;
488 connectManager->DisconnectRecordForce(list, connectionRecord);
489 EXPECT_TRUE(connectManager->terminatingExtensionList_.empty());
490
491 TAG_LOGI(AAFwkTag::TEST, "DisconnectRecordForce_ConnectRecordIsNotLast_001 end");
492 }
493
494 /*
495 * Feature: AbilityConnectManager
496 * Function: DisconnectRecordForce
497 */
498 HWTEST_F(AbilityConnectManagerSecondTest, DisconnectRecordForce_ConnectRecordIsLastAndIsUISERVICE_001, TestSize.Level1)
499 {
500 TAG_LOGI(AAFwkTag::TEST, "DisconnectRecordForce_ConnectRecordIsLastAndIsUISERVICE_001 start");
501 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
502 ASSERT_NE(connectManager, nullptr);
503
504 AbilityRequest req;
505 req.want.SetElementName("com.example.bundle", "com.example.module", "MainAbility");
506
507 auto abilityRecord = AbilityRecord::CreateAbilityRecord(req);
508 EXPECT_TRUE(abilityRecord);
509 EXPECT_TRUE(abilityRecord->IsConnectListEmpty());
510
511 auto token = abilityRecord->GetToken();
512 auto connectionRecord = ConnectionRecord::CreateConnectionRecord(token, abilityRecord, nullptr, connectManager);
513 EXPECT_TRUE(connectionRecord);
514
515 abilityRecord->AddConnectRecordToList(connectionRecord);
516 EXPECT_FALSE(abilityRecord->IsConnectListEmpty());
517
518 abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::UI_SERVICE;
519
520 std::list<std::shared_ptr<ConnectionRecord>> list;
521 connectManager->DisconnectRecordForce(list, connectionRecord);
522 EXPECT_TRUE(connectManager->terminatingExtensionList_.empty());
523
524 TAG_LOGI(AAFwkTag::TEST, "DisconnectRecordForce_ConnectRecordIsLastAndIsUISERVICE_001 end");
525 }
526
527 HWTEST_F(AbilityConnectManagerSecondTest, DisconnectRecordForce_ConnectRecordIsLastAndNotUISERVICE_001, TestSize.Level1)
528 {
529 TAG_LOGI(AAFwkTag::TEST, "DisconnectRecordForce_ConnectRecordIsLastAndNotUISERVICE_001 start");
530 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
531 ASSERT_NE(connectManager, nullptr);
532
533 AbilityRequest req;
534 req.want.SetElementName("com.example.bundle", "com.example.module", "MainAbility");
535
536 auto abilityRecord = AbilityRecord::CreateAbilityRecord(req);
537 EXPECT_TRUE(abilityRecord);
538 EXPECT_TRUE(abilityRecord->IsConnectListEmpty());
539
540 auto token = abilityRecord->GetToken();
541 auto connectionRecord = ConnectionRecord::CreateConnectionRecord(token, abilityRecord, nullptr, connectManager);
542 EXPECT_TRUE(connectionRecord);
543
544 abilityRecord->AddConnectRecordToList(connectionRecord);
545 EXPECT_FALSE(abilityRecord->IsConnectListEmpty());
546
547 abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::INPUTMETHOD;
548 abilityRecord->SetCreateByConnectMode(true);
549 abilityRecord->startId_ = 0;
550
551 std::list<std::shared_ptr<ConnectionRecord>> list;
552 connectManager->DisconnectRecordForce(list, connectionRecord);
553 EXPECT_TRUE(abilityRecord->IsConnectListEmpty());
554 EXPECT_TRUE(abilityRecord->IsNeverStarted());
555
556 TAG_LOGI(AAFwkTag::TEST, "DisconnectRecordForce_ConnectRecordIsLastAndNotUISERVICE_001 end");
557 }
558
559 HWTEST_F(AbilityConnectManagerSecondTest, DisconnectRecordForce_StartButNotActiveStatus_001, TestSize.Level1)
560 {
561 TAG_LOGI(AAFwkTag::TEST, "DisconnectRecordForce_StartButNotActiveStatus_001 start");
562 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
563 ASSERT_NE(connectManager, nullptr);
564
565 AbilityRequest req;
566 req.want.SetElementName("com.example.bundle", "com.example.module", "MainAbility");
567
568 auto abilityRecord = AbilityRecord::CreateAbilityRecord(req);
569 EXPECT_TRUE(abilityRecord);
570 EXPECT_TRUE(abilityRecord->IsConnectListEmpty());
571
572 auto token = abilityRecord->GetToken();
573 auto connectionRecord = ConnectionRecord::CreateConnectionRecord(token, abilityRecord, nullptr, connectManager);
574 EXPECT_TRUE(connectionRecord);
575
576 abilityRecord->AddConnectRecordToList(connectionRecord);
577 EXPECT_FALSE(abilityRecord->IsConnectListEmpty());
578
579 abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::INPUTMETHOD;
580 abilityRecord->SetCreateByConnectMode(false);
581 abilityRecord->SetAbilityState(AbilityState::FOREGROUND);
582
583 std::list<std::shared_ptr<ConnectionRecord>> list;
584 abilityRecord->isConnected = true;
585 EXPECT_TRUE(abilityRecord->isConnected);
586 connectManager->DisconnectRecordForce(list, connectionRecord);
587 EXPECT_TRUE(abilityRecord->IsConnectListEmpty());
588 EXPECT_FALSE(abilityRecord->IsNeverStarted());
589 EXPECT_TRUE(connectManager->terminatingExtensionList_.empty());
590 EXPECT_FALSE(abilityRecord->isConnected);
591
592 TAG_LOGI(AAFwkTag::TEST, "DisconnectRecordForce_StartButNotActiveStatus_001 end");
593 }
594
595 HWTEST_F(AbilityConnectManagerSecondTest, DisconnectRecordForce_StartButIsActiveStatus_001, TestSize.Level1)
596 {
597 TAG_LOGI(AAFwkTag::TEST, "DisconnectRecordForce_StartButIsActiveStatus_001 start");
598 std::shared_ptr<AbilityConnectManager> connectManager = std::make_shared<AbilityConnectManager>(0);
599 ASSERT_NE(connectManager, nullptr);
600
601 AbilityRequest req;
602 req.want.SetElementName("com.example.bundle", "com.example.module", "MainAbility");
603
604 auto abilityRecord = AbilityRecord::CreateAbilityRecord(req);
605 EXPECT_TRUE(abilityRecord);
606 EXPECT_TRUE(abilityRecord->IsConnectListEmpty());
607
608 auto token = abilityRecord->GetToken();
609 auto connectionRecord = ConnectionRecord::CreateConnectionRecord(token, abilityRecord, nullptr, connectManager);
610 EXPECT_TRUE(connectionRecord);
611
612 abilityRecord->AddConnectRecordToList(connectionRecord);
613 EXPECT_FALSE(abilityRecord->IsConnectListEmpty());
614
615 abilityRecord->abilityInfo_.extensionAbilityType = AppExecFwk::ExtensionAbilityType::INPUTMETHOD;
616 abilityRecord->SetCreateByConnectMode(false);
617 abilityRecord->SetAbilityState(AbilityState::ACTIVE);
618
619 std::list<std::shared_ptr<ConnectionRecord>> list;
620 abilityRecord->isConnected = true;
621 connectManager->DisconnectRecordForce(list, connectionRecord);
622 EXPECT_TRUE(connectManager->terminatingExtensionList_.empty());
623 EXPECT_FALSE(abilityRecord->isConnected);
624
625 TAG_LOGI(AAFwkTag::TEST, "DisconnectRecordForce_StartButIsActiveStatus_001 end");
626 }
627
628 } // namespace AAFwk
629 } // namespace OHOS
630