• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <chrono>
17 #include <functional>
18 #include <memory>
19 #include <thread>
20 
21 #include "gtest/gtest.h"
22 
23 #define private public
24 #include "advanced_notification_service.h"
25 #include "ans_const_define.h"
26 #include "ans_inner_errors.h"
27 #include "ans_log_wrapper.h"
28 #include "ans_ut_constant.h"
29 #include "iremote_object.h"
30 #include "ipc_skeleton.h"
31 #include "want_agent_info.h"
32 #include "want_agent_helper.h"
33 #include "want_params.h"
34 #include "int_wrapper.h"
35 #include "accesstoken_kit.h"
36 #include "notification_preferences.h"
37 #include "notification_constant.h"
38 #include "notification_record.h"
39 #include "notification_subscriber.h"
40 #include "refbase.h"
41 #include "bundle_manager_helper.h"
42 #include "mock_bundle_mgr.h"
43 
44 using namespace testing::ext;
45 using namespace OHOS::Media;
46 using namespace OHOS::Security::AccessToken;
47 
48 extern void MockQueryForgroundOsAccountId(bool mockRet, uint8_t mockCase);
49 
50 namespace OHOS {
51 namespace Notification {
52 extern void MockIsVerfyPermisson(bool isVerify);
53 extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet);
54 extern void MockIsSystemApp(bool isSystemApp);
55 
56 class AnsUtilsTest : public testing::Test {
57 public:
58     static void SetUpTestCase();
59     static void TearDownTestCase();
60     void SetUp();
61     void TearDown();
62 
63 private:
64     void TestAddNotification(int notificationId, const sptr<NotificationBundleOption> &bundle);
65 
66 private:
67     static sptr<AdvancedNotificationService> advancedNotificationService_;
68 };
69 
70 sptr<AdvancedNotificationService> AnsUtilsTest::advancedNotificationService_ = nullptr;
71 
SetUpTestCase()72 void AnsUtilsTest::SetUpTestCase() {}
73 
TearDownTestCase()74 void AnsUtilsTest::TearDownTestCase() {}
75 
SetUp()76 void AnsUtilsTest::SetUp()
77 {
78     GTEST_LOG_(INFO) << "SetUp start";
79 
80     advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService();
81     NotificationPreferences::GetInstance()->ClearNotificationInRestoreFactorySettings();
82     advancedNotificationService_->CancelAll("");
83     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE);
84     MockIsSystemApp(true);
85     GTEST_LOG_(INFO) << "SetUp end";
86 }
87 
TearDown()88 void AnsUtilsTest::TearDown()
89 {
90     advancedNotificationService_ = nullptr;
91     GTEST_LOG_(INFO) << "TearDown";
92 }
93 
SleepForFC()94 inline void SleepForFC()
95 {
96     // For ANS Flow Control
97     std::this_thread::sleep_for(std::chrono::seconds(1));
98 }
99 
100 class TestAnsSubscriber : public NotificationSubscriber {
101 public:
OnDied()102     void OnDied() override
103     {}
OnConnected()104     void OnConnected() override
105     {}
OnDisconnected()106     void OnDisconnected() override
107     {}
OnUpdate(const std::shared_ptr<NotificationSortingMap> & sortingMap)108     void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) override
109     {}
OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> & date)110     void OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> &date) override
111     {}
OnCanceled(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap,int32_t deleteReason)112     void OnCanceled(const std::shared_ptr<Notification> &request,
113         const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) override
114     {}
OnEnabledNotificationChanged(const std::shared_ptr<EnabledNotificationCallbackData> & callbackData)115     void OnEnabledNotificationChanged(
116         const std::shared_ptr<EnabledNotificationCallbackData> &callbackData) override
117     {}
OnConsumed(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap)118     void OnConsumed(const std::shared_ptr<Notification> &request,
119         const std::shared_ptr<NotificationSortingMap> &sortingMap) override
120     {}
OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> & badgeData)121     void OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> &badgeData) override
122     {}
OnBadgeEnabledChanged(const sptr<EnabledNotificationCallbackData> & callbackData)123     void OnBadgeEnabledChanged(const sptr<EnabledNotificationCallbackData> &callbackData) override
124     {}
OnBatchCanceled(const std::vector<std::shared_ptr<Notification>> & requestList,const std::shared_ptr<NotificationSortingMap> & sortingMap,int32_t deleteReason)125     void OnBatchCanceled(const std::vector<std::shared_ptr<Notification>>
126         &requestList, const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) override
127     {}
128 };
129 
TestAddNotification(int notificationId,const sptr<NotificationBundleOption> & bundle)130 void AnsUtilsTest::TestAddNotification(int notificationId, const sptr<NotificationBundleOption> &bundle)
131 {
132     auto slotType = NotificationConstant::SlotType::LIVE_VIEW;
133     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
134     request->SetSlotType(slotType);
135     request->SetOwnerUserId(1);
136     request->SetCreatorUserId(2);
137     request->SetOwnerBundleName("test");
138     request->SetOwnerUid(0);
139     request->SetNotificationId(notificationId);
140     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
141     auto ret = advancedNotificationService_->AssignToNotificationList(record);
142 }
143 
144 /**
145  * @tc.name: FillRequestByKeys_00001
146  * @tc.desc: Test FillRequestByKeys
147  * @tc.type: FUNC
148  * @tc.require: issue
149  */
150 HWTEST_F(AnsUtilsTest, FillRequestByKeys_00001, Function | SmallTest | Level1)
151 {
152     auto slotType = NotificationConstant::SlotType::LIVE_VIEW;
153     sptr<NotificationRequest> oldRequest = new (std::nothrow) NotificationRequest();
154     oldRequest->SetSlotType(slotType);
155     auto liveContent = std::make_shared<NotificationLiveViewContent>();
156     auto extraInfo = std::make_shared<AAFwk::WantParams>();
157     sptr<AAFwk::IInterface> value = AAFwk::Integer::Box(1);
158     extraInfo->SetParam("key1", value);
159     auto content = std::make_shared<NotificationContent>(liveContent);
160     liveContent->SetExtraInfo(extraInfo);
161     oldRequest->SetContent(content);
162 
163     std::vector<std::string> keys = {"key1"};
164     sptr<NotificationRequest> newRequest;
165     ErrCode ret = advancedNotificationService_->FillRequestByKeys(oldRequest, keys, newRequest);
166     ASSERT_EQ(ret, (int)ERR_OK);
167 }
168 
169 /**
170  * @tc.name: IsAllowedGetNotificationByFilter_00001
171  * @tc.desc: Test IsAllowedGetNotificationByFilter
172  * @tc.type: FUNC
173  * @tc.require: issue
174  */
175 HWTEST_F(AnsUtilsTest, IsAllowedGetNotificationByFilter_00001, Function | SmallTest | Level1)
176 {
177     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
178     auto record = std::make_shared<NotificationRecord>();
179     record->bundleOption = new NotificationBundleOption("test", 1);
180     int ret = advancedNotificationService_->IsAllowedGetNotificationByFilter(record, bundle);
181     ASSERT_EQ(ret, (int)ERR_OK);
182 
183     record->bundleOption->SetBundleName("bundleName");
184     ret = advancedNotificationService_->IsAllowedGetNotificationByFilter(record, bundle);
185     ASSERT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED);
186 
187     record->bundleOption->SetBundleName("test");
188     record->bundleOption->SetUid(2);
189     ret = advancedNotificationService_->IsAllowedGetNotificationByFilter(record, bundle);
190     ASSERT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED);
191 }
192 
193 /**
194  * @tc.name: GetActiveNotificationByFilter_00001
195  * @tc.desc: Test GetActiveNotificationByFilter
196  * @tc.type: FUNC
197  * @tc.require: issue
198  */
199 HWTEST_F(AnsUtilsTest, GetActiveNotificationByFilter_00001, Function | SmallTest | Level1)
200 {
201     AdvancedNotificationService ans;
202     ans.notificationSvrQueue_ = nullptr;
203     std::string label = "testLabel";
204     std::vector<std::string> keys = {"key1"};
205     sptr<NotificationRequest> newRequest;
206     auto bundleOption = new NotificationBundleOption("test", 1);
207     int notificationId = 1;
208     int32_t userId = -1;
209     ASSERT_EQ(ans.GetActiveNotificationByFilter(bundleOption, notificationId, label, userId, keys, newRequest),
210         (int)ERR_ANS_INVALID_PARAM);
211 }
212 
213 /**
214  * @tc.name: GetActiveNotificationByFilter_00002
215  * @tc.desc: Test GetActiveNotificationByFilter
216  * @tc.type: FUNC
217  * @tc.require: issue
218  */
219 HWTEST_F(AnsUtilsTest, GetActiveNotificationByFilter_00002, Function | SmallTest | Level1)
220 {
221     std::string label = "testLabel";
222     std::vector<std::string> keys = {"key1"};
223     sptr<NotificationRequest> newRequest;
224     sptr<NotificationBundleOption> bundle;
225     int notificationId = 1;
226     int32_t userId = -1;
227     ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(
228         bundle, notificationId, label, userId, keys, newRequest),
229         (int)ERR_ANS_INVALID_BUNDLE);
230 }
231 
232 /**
233  * @tc.name: GetActiveNotificationByFilter_00003
234  * @tc.desc: Test GetActiveNotificationByFilter
235  * @tc.type: FUNC
236  * @tc.require: issue
237  */
238 HWTEST_F(AnsUtilsTest, GetActiveNotificationByFilter_00003, Function | SmallTest | Level1)
239 {
240     auto slotType = NotificationConstant::SlotType::LIVE_VIEW;
241     std::string label = "testLabel";
242     int notificationId = 1;
243     int32_t userId = -1;
244 
245     sptr<NotificationRequest> oldRequest = new (std::nothrow) NotificationRequest();
246     oldRequest->SetSlotType(slotType);
247     auto liveContent = std::make_shared<NotificationLiveViewContent>();
248     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_CREATE);
249     auto extraInfo = std::make_shared<AAFwk::WantParams>();
250     sptr<AAFwk::IInterface> value = AAFwk::Integer::Box(1);
251     extraInfo->SetParam("key1", value);
252     liveContent->SetExtraInfo(extraInfo);
253     auto content = std::make_shared<NotificationContent>(liveContent);
254     oldRequest->SetContent(content);
255     oldRequest->SetNotificationId(notificationId);
256 
257     oldRequest->SetLabel(label);
258     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
259     auto record = advancedNotificationService_->MakeNotificationRecord(oldRequest, bundle);
260     advancedNotificationService_->AssignToNotificationList(record);
261 
262 
263     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
264     MockIsSystemApp(true);
265     MockIsVerfyPermisson(false);
266 
267     std::vector<std::string> keys;
268     sptr<NotificationRequest> newRequest;
269     ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(bundle,
270         notificationId, label, userId, keys, newRequest), (int)ERR_ANS_PERMISSION_DENIED);
271 
272     MockIsVerfyPermisson(true);
273     ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(bundle,
274         notificationId, label, userId, keys, newRequest), (int)ERR_OK);
275 
276     keys.emplace_back("test1");
277     ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(bundle,
278         notificationId, label, userId, keys, newRequest), (int)ERR_OK);
279 
280     sptr<NotificationBundleOption> bundle1 = new NotificationBundleOption("test1", 1);
281     ASSERT_EQ(advancedNotificationService_->GetActiveNotificationByFilter(bundle1,
282         notificationId, label, userId, keys, newRequest), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS);
283 }
284 
285 /**
286  * @tc.name: RecentNotificationDump_00001
287  * @tc.desc: Test RecentNotificationDump
288  * @tc.type: FUNC
289  * @tc.require: issue
290  */
291 HWTEST_F(AnsUtilsTest, RecentNotificationDump_00001, Function | SmallTest | Level1)
292 {
293     auto slotType = NotificationConstant::SlotType::LIVE_VIEW;
294     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
295     request->SetSlotType(slotType);
296     request->SetOwnerUserId(1);
297     request->SetCreatorUserId(1);
298     request->SetOwnerBundleName("test");
299     request->SetOwnerUid(0);
300     request->SetNotificationId(1);
301     auto notification = new (std::nothrow) Notification(request);
302 
303     auto recentNotification = std::make_shared<AdvancedNotificationService::RecentNotification>();
304     recentNotification->isActive = true;
305     recentNotification->notification = notification;
306     advancedNotificationService_->recentInfo_->list.emplace_front(recentNotification);
307 
308     std::vector<std::string> dumpInfo;
309     int ret = advancedNotificationService_->RecentNotificationDump("test", 1, 1, dumpInfo);
310     ASSERT_EQ(ret, (int)ERR_OK);
311     ASSERT_EQ(dumpInfo.size(), 1);
312 }
313 
314 /**
315  * @tc.name: RecentNotificationDump_00002
316  * @tc.desc: Test RecentNotificationDump
317  * @tc.type: FUNC
318  * @tc.require: issue
319  */
320 HWTEST_F(AnsUtilsTest, RecentNotificationDump_00002, Function | SmallTest | Level1)
321 {
322     auto slotType = NotificationConstant::SlotType::LIVE_VIEW;
323     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
324     request->SetSlotType(slotType);
325     request->SetOwnerUserId(1);
326     request->SetCreatorUserId(1);
327     request->SetOwnerBundleName("test");
328     request->SetOwnerUid(1);
329     request->SetNotificationId(1);
330     auto notification = new (std::nothrow) Notification(request);
331 
332     auto recentNotification = std::make_shared<AdvancedNotificationService::RecentNotification>();
333     recentNotification->isActive = false;
334     recentNotification->notification = notification;
335     advancedNotificationService_->recentInfo_->list.emplace_front(recentNotification);
336 
337     sptr<NotificationRequest> request1 = new (std::nothrow) NotificationRequest();
338     request1->SetOwnerUserId(2);
339     auto notification1 = new (std::nothrow) Notification(request1);
340     auto recentNotification1 = std::make_shared<AdvancedNotificationService::RecentNotification>();
341     recentNotification1->notification = notification1;
342     advancedNotificationService_->recentInfo_->list.emplace_front(recentNotification1);
343 
344     sptr<NotificationRequest> request2 = new (std::nothrow) NotificationRequest();
345     request2->SetOwnerUserId(1);
346     request2->SetOwnerBundleName("test1");
347     auto notification2 = new (std::nothrow) Notification(request2);
348     auto recentNotification2 = std::make_shared<AdvancedNotificationService::RecentNotification>();
349     recentNotification2->notification = notification2;
350     advancedNotificationService_->recentInfo_->list.emplace_front(recentNotification2);
351 
352     sptr<NotificationRequest> request3 = new (std::nothrow) NotificationRequest();
353     request3->SetReceiverUserId(2);
354     request3->SetOwnerUserId(1);
355     auto notification3 = new (std::nothrow) Notification(request3);
356     auto recentNotification3 = std::make_shared<AdvancedNotificationService::RecentNotification>();
357     recentNotification3->notification = notification3;
358     advancedNotificationService_->recentInfo_->list.emplace_front(recentNotification3);
359 
360     std::vector<std::string> dumpInfo;
361     int ret = advancedNotificationService_->RecentNotificationDump("test", 1, 1, dumpInfo);
362     ASSERT_EQ(ret, (int)ERR_OK);
363     ASSERT_EQ(dumpInfo.size(), 1);
364 }
365 
366 /**
367  * @tc.name: RecentNotificationDump_00003
368  * @tc.desc: Test RecentNotificationDump
369  * @tc.type: FUNC
370  * @tc.require: issue
371  */
372 HWTEST_F(AnsUtilsTest, RecentNotificationDump_00003, Function | SmallTest | Level1)
373 {
374     sptr<Notification> notification = nullptr;
375     auto recentNotification = std::make_shared<AdvancedNotificationService::RecentNotification>();
376     recentNotification->isActive = true;
377     recentNotification->notification = notification;
378     advancedNotificationService_->recentInfo_->list.emplace_front(recentNotification);
379 
380     auto slotType = NotificationConstant::SlotType::LIVE_VIEW;
381     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
382     request->SetSlotType(slotType);
383     request->SetOwnerUserId(1);
384     request->SetCreatorUserId(1);
385     request->SetOwnerBundleName("test");
386     request->SetOwnerUid(0);
387     request->SetNotificationId(1);
388     auto notification1 = new (std::nothrow) Notification(request);
389 
390     auto recentNotification1 = std::make_shared<AdvancedNotificationService::RecentNotification>();
391     recentNotification1->isActive = false;
392     recentNotification1->notification = notification1;
393     advancedNotificationService_->recentInfo_->list.emplace_front(recentNotification1);
394 
395     std::vector<std::string> dumpInfo;
396     int ret = advancedNotificationService_->RecentNotificationDump("test", 1, 1, dumpInfo);
397     ASSERT_EQ(ret, (int)ERR_OK);
398     ASSERT_EQ(dumpInfo.size(), 1);
399 }
400 
401 /**
402  * @tc.name: GetLocalNotificationKeys_00001
403  * @tc.desc: Test GetLocalNotificationKeys
404  * @tc.type: FUNC
405  * @tc.require: issue
406  */
407 HWTEST_F(AnsUtilsTest, GetLocalNotificationKeys_00001, Function | SmallTest | Level1)
408 {
409     int notificationId = 1;
410     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
411     TestAddNotification(notificationId, bundle);
412 
413     notificationId = 2;
414     sptr<NotificationBundleOption> bundle2 = new NotificationBundleOption("test1", 2);
415     TestAddNotification(notificationId, bundle2);
416     ASSERT_EQ(advancedNotificationService_->notificationList_.size(), 2);
417 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
418     auto keys = advancedNotificationService_->GetLocalNotificationKeys(bundle2);
419     ASSERT_EQ(keys.size(), 1);
420 #endif
421 }
422 
423 /**
424  * @tc.name: OnBundleDataCleared_00001
425  * @tc.desc: Test OnBundleDataCleared
426  * @tc.type: FUNC
427  * @tc.require: issue
428  */
429 HWTEST_F(AnsUtilsTest, OnBundleDataCleared_00001, Function | SmallTest | Level1)
430 {
431     int notificationId = 1;
432     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
433     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
434     request->SetNotificationId(notificationId);
435     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
436 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
437     record->deviceId = "deviceId";
438 #endif  // DISTRIBUTED_NOTIFICATION_SUPPORTED
439     advancedNotificationService_->AssignToNotificationList(record);
440     advancedNotificationService_->OnBundleDataCleared(bundle);
441     SleepForFC();
442     ASSERT_EQ(advancedNotificationService_->notificationList_.size(), 0);
443 }
444 
445 /**
446  * @tc.name: OnBundleDataCleared_00002
447  * @tc.desc: Test OnBundleDataCleared
448  * @tc.type: FUNC
449  * @tc.require: issue
450  */
451 HWTEST_F(AnsUtilsTest, OnBundleDataCleared_00002, Function | SmallTest | Level1)
452 {
453     int notificationId = 1;
454     AdvancedNotificationService advancedNotificationService;
455     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
456     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
457     request->SetNotificationId(notificationId);
458     auto record = advancedNotificationService.MakeNotificationRecord(request, bundle);
459     advancedNotificationService.AssignToNotificationList(record);
460     advancedNotificationService.notificationSvrQueue_ = nullptr;
461     advancedNotificationService.OnBundleDataCleared(bundle);
462     ASSERT_EQ(advancedNotificationService.notificationList_.size(), 1);
463 }
464 
465 /**
466  * @tc.name: InitNotificationEnableList_00001
467  * @tc.desc: Test InitNotificationEnableList
468  * @tc.type: FUNC
469  * @tc.require: issue
470  */
471 HWTEST_F(AnsUtilsTest, InitNotificationEnableList_00001, Function | SmallTest | Level1)
472 {
473     MockSetBundleInfoEnabled(true);
474     advancedNotificationService_->InitNotificationEnableList();
475     SleepForFC();
476     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
477     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
478     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
479     ASSERT_EQ(static_cast<int32_t>(state), 3);
480 }
481 
482 /**
483  * @tc.name: GetBundleInfoByNotificationBundleOption_00001
484  * @tc.desc: Test GetBundleInfoByNotificationBundleOption
485  * @tc.type: FUNC
486  * @tc.require: issue
487  */
488 HWTEST_F(AnsUtilsTest, GetBundleInfoByNotificationBundleOption_00001, Function | SmallTest | Level1)
489 {
490     MockSetBundleInfoFailed(true);
491     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
492     AppExecFwk::BundleInfo bundleInfo;
493     bool res = advancedNotificationService_->GetBundleInfoByNotificationBundleOption(bundle, bundleInfo);
494     ASSERT_EQ(res, false);
495     MockSetBundleInfoFailed(false);
496 }
497 
498 /**
499  * @tc.name: OnBundleRemoved_00001
500  * @tc.desc: Test OnBundleRemoved
501  * @tc.type: FUNC
502  * @tc.require: issue
503  */
504 HWTEST_F(AnsUtilsTest, OnBundleRemoved_00001, Function | SmallTest | Level1)
505 {
506     int notificationId = 1;
507     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
508     TestAddNotification(notificationId, bundle);
509     ASSERT_EQ(advancedNotificationService_->notificationList_.size(), 1);
510 
511     advancedNotificationService_->OnBundleRemoved(bundle);
512     SleepForFC();
513     ASSERT_EQ(advancedNotificationService_->notificationList_.size(), 0);
514 }
515 
516 /**
517  * @tc.name: OnBundleRemoved_00002
518  * @tc.desc: Test OnBundleRemoved
519  * @tc.type: FUNC
520  * @tc.require: issue
521  */
522 HWTEST_F(AnsUtilsTest, OnBundleRemoved_00002, Function | SmallTest | Level1)
523 {
524     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
525     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
526     request->SetNotificationId(1);
527     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
528     auto ret = advancedNotificationService_->AssignToNotificationList(record);
529     advancedNotificationService_->notificationSvrQueue_ = nullptr;
530     advancedNotificationService_->OnBundleRemoved(bundle);
531     ASSERT_EQ(advancedNotificationService_->notificationList_.size(), 1);
532 }
533 
534 /**
535  * @tc.name: OnBundleDataAdd_00001
536  * @tc.desc: Test OnBundleDataAdd
537  * @tc.type: FUNC
538  * @tc.require: issue
539  */
540 HWTEST_F(AnsUtilsTest, OnBundleDataAdd_00001, Function | SmallTest | Level1)
541 {
542     int notificationId = 1;
543     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("OnBundleDataAdd_00001", 1);
544     TestAddNotification(notificationId, bundle);
545     MockSetBundleInfoEnabled(false);
546     advancedNotificationService_->OnBundleDataAdd(bundle);
547     SleepForFC();
548     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
549     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
550     ASSERT_EQ(static_cast<int32_t>(state), 2);
551 }
552 
553 /**
554  * @tc.name: OnBundleDataAdd_00002
555  * @tc.desc: Test OnBundleDataAdd
556  * @tc.type: FUNC
557  * @tc.require: issue
558  */
559 HWTEST_F(AnsUtilsTest, OnBundleDataAdd_00002, Function | SmallTest | Level1)
560 {
561     int notificationId = 1;
562     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
563     TestAddNotification(notificationId, bundle);
564     MockSetBundleInfoEnabled(true);
565     advancedNotificationService_->OnBundleDataAdd(bundle);
566     SleepForFC();
567     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
568     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
569     ASSERT_EQ(static_cast<int32_t>(state), 3);
570 }
571 
572 /**
573  * @tc.name: OnBundleDataAdd_00003
574  * @tc.desc: Test OnBundleDataAdd
575  * @tc.type: FUNC
576  * @tc.require: issue
577  */
578 HWTEST_F(AnsUtilsTest, OnBundleDataAdd_00003, Function | SmallTest | Level1)
579 {
580     int notificationId = 1;
581     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
582     TestAddNotification(notificationId, bundle);
583     MockSetBundleInfoFailed(true);
584     advancedNotificationService_->OnBundleDataAdd(bundle);
585     SleepForFC();
586     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
587     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
588     MockSetBundleInfoFailed(false);
589     ASSERT_EQ(static_cast<int32_t>(state), 0);
590 }
591 
592 /**
593  * @tc.name: OnBundleDataUpdate_00001
594  * @tc.desc: Test OnBundleDataUpdate
595  * @tc.type: FUNC
596  * @tc.require: issue
597  */
598 HWTEST_F(AnsUtilsTest, OnBundleDataUpdate_00001, Function | SmallTest | Level1)
599 {
600     int notificationId = 1;
601     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
602     TestAddNotification(notificationId, bundle);
603 
604     NotificationPreferences::GetInstance()->SetHasPoppedDialog(bundle, true);
605     advancedNotificationService_->OnBundleDataUpdate(bundle);
606     EXPECT_NE(advancedNotificationService_, nullptr);
607 }
608 
609 /**
610  * @tc.name: OnBundleDataUpdate_00002
611  * @tc.desc: Test OnBundleDataUpdate
612  * @tc.type: FUNC
613  * @tc.require: issue
614  */
615 HWTEST_F(AnsUtilsTest, OnBundleDataUpdate_00002, Function | SmallTest | Level1)
616 {
617     int notificationId = 1;
618     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
619     TestAddNotification(notificationId, bundle);
620     MockSetBundleInfoEnabled(true);
621     advancedNotificationService_->OnBundleDataUpdate(bundle);
622     SleepForFC();
623     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
624     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
625     ASSERT_EQ(static_cast<int32_t>(state), 3);
626 }
627 
628 /**
629  * @tc.name: OnBundleDataUpdate_00003
630  * @tc.desc: Test OnBundleDataUpdate
631  * @tc.type: FUNC
632  * @tc.require: issue
633  */
634 HWTEST_F(AnsUtilsTest, OnBundleDataUpdate_00003, Function | SmallTest | Level1)
635 {
636     AdvancedNotificationService ans;
637     int notificationId = 1;
638     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
639     TestAddNotification(notificationId, bundle);
640     MockSetBundleInfoFailed(true);
641     advancedNotificationService_->OnBundleDataUpdate(bundle);
642     SleepForFC();
643     MockSetBundleInfoFailed(false);
644     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
645     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
646     ASSERT_EQ(static_cast<int32_t>(state), 0);
647 }
648 
649 /**
650  * @tc.name: GetBundlesOfActiveUser_00001
651  * @tc.desc: Test GetBundlesOfActiveUser
652  * @tc.type: FUNC
653  * @tc.require: issue
654  */
655 HWTEST_F(AnsUtilsTest, GetBundlesOfActiveUser_00001, Function | SmallTest | Level1)
656 {
657     MockSetBundleInfoEnabled(true);
658     auto list = advancedNotificationService_->GetBundlesOfActiveUser();
659     ASSERT_EQ(list.size(), 2);
660 }
661 
662 /**
663  * @tc.name: ResetDistributedEnabled_00001
664  * @tc.desc: Test ResetDistributedEnabled
665  * @tc.type: FUNC
666  * @tc.require: issue
667  */
668 HWTEST_F(AnsUtilsTest, ResetDistributedEnabled_00001, Function | SmallTest | Level1)
669 {
670     AdvancedNotificationService ans;
671     std::string oldKey = "enabledNotificationDistributed-test-88-aaa";
672     NotificationPreferences::GetInstance()->SetKvToDb(oldKey, "1", 0);
673     ans.notificationSvrQueue_ = nullptr;
674     ans.ResetDistributedEnabled();
675     SleepForFC();
676     std::string value;
677     NotificationPreferences::GetInstance()->GetKvFromDb("tableVersion", value, 0);
678     ASSERT_NE(value, "1");
679 }
680 
681 /**
682  * @tc.name: ResetDistributedEnabled_00002
683  * @tc.desc: Test ResetDistributedEnabled
684  * @tc.type: FUNC
685  * @tc.require: issue
686  */
687 HWTEST_F(AnsUtilsTest, ResetDistributedEnabled_00002, Function | SmallTest | Level1)
688 {
689     std::string oldKey = "enabledNotificationDistributed-test-88-aaa";
690     std::string oldKey1 = "enabledNotificationDistributed-test-88";
691     NotificationPreferences::GetInstance()->SetKvToDb(oldKey, "1", 0);
692     NotificationPreferences::GetInstance()->SetKvToDb(oldKey1, "1", 0);
693     advancedNotificationService_->ResetDistributedEnabled();
694     SleepForFC();
695     std::string value;
696     NotificationPreferences::GetInstance()->GetKvFromDb("tableVersion", value, 0);
697     ASSERT_EQ(value, "1");
698 }
699 
700 /**
701  * @tc.name: UpdateCloneBundleInfo_00001
702  * @tc.desc: Test UpdateCloneBundleInfo
703  * @tc.type: FUNC
704  * @tc.require: issue
705  */
706 HWTEST_F(AnsUtilsTest, UpdateCloneBundleInfo_00001, Function | SmallTest | Level1)
707 {
708     NotificationCloneBundleInfo cloneBundleInfo;
709     cloneBundleInfo.SetBundleName("test");
710     cloneBundleInfo.SetUid(1);
711     cloneBundleInfo.SetIsShowBadge(true);
712     cloneBundleInfo.SetEnableNotification(NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON);
713     cloneBundleInfo.SetSlotFlags(63);
714     NotificationCloneBundleInfo::SlotInfo info;
715     info.slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
716     info.enable_ = true;
717     cloneBundleInfo.AddSlotInfo(info);
718     advancedNotificationService_->UpdateCloneBundleInfo(cloneBundleInfo);
719     SleepForFC();
720     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
721     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
722     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
723     ASSERT_EQ(static_cast<int32_t>(state), 1);
724 }
725 
726 /**
727  * @tc.name: UpdateCloneBundleInfo_00002
728  * @tc.desc: Test UpdateCloneBundleInfo
729  * @tc.type: FUNC
730  * @tc.require: issue
731  */
732 HWTEST_F(AnsUtilsTest, UpdateCloneBundleInfo_00002, Function | SmallTest | Level1)
733 {
734     AdvancedNotificationService ans;
735     NotificationCloneBundleInfo cloneBundleInfo;
736     cloneBundleInfo.SetBundleName("UpdateCloneBundleInfo_00002");
737     cloneBundleInfo.SetUid(1);
738     cloneBundleInfo.SetIsShowBadge(true);
739     cloneBundleInfo.SetEnableNotification(NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON);
740     cloneBundleInfo.SetSlotFlags(63);
741     NotificationCloneBundleInfo::SlotInfo info;
742     info.slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
743     info.enable_ = true;
744     cloneBundleInfo.AddSlotInfo(info);
745     ans.notificationSvrQueue_ = nullptr;
746     ans.UpdateCloneBundleInfo(cloneBundleInfo);
747     SleepForFC();
748     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("UpdateCloneBundleInfo_00002", 1);
749     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
750     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
751     ASSERT_EQ(static_cast<int32_t>(state), 0);
752 }
753 
754 /**
755  * @tc.name: ExecBatchCancel_00001
756  * @tc.desc: Test ExecBatchCancel
757  * @tc.type: FUNC
758  * @tc.require: issue
759  */
760 HWTEST_F(AnsUtilsTest, ExecBatchCancel_00001, Function | SmallTest | Level1)
761 {
762     std::vector<sptr<Notification>> notifications;
763     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
764     for (int i = 0; i < 201; i++) {
765         auto slotType = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
766         sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
767         request->SetSlotType(slotType);
768         request->SetOwnerUserId(100);
769         request->SetCreatorUserId(0);
770         request->SetOwnerBundleName("test");
771         request->SetOwnerUid(0);
772         request->SetNotificationId(1000+i);
773         auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
774         auto ret = advancedNotificationService_->AssignToNotificationList(record);
775         sptr<Notification> notification = new Notification(request);
776         notifications.push_back(notification);
777     }
778     int reason = 28;
779     advancedNotificationService_->ExecBatchCancel(notifications, reason);
780     ASSERT_EQ(notifications.size() == 0, true);
781 }
782 
783 /**
784  * @tc.name: OnBootSystemCompleted_00001
785  * @tc.desc: Test OnBootSystemCompleted
786  * @tc.type: FUNC
787  * @tc.require: issue
788  */
789 HWTEST_F(AnsUtilsTest, OnBootSystemCompleted_00001, Function | SmallTest | Level1)
790 {
791     advancedNotificationService_->OnBootSystemCompleted();
792 }
793 
794 /**
795  * @tc.name: OnDistributedKvStoreDeathRecipient_00001
796  * @tc.desc: Test OnDistributedKvStoreDeathRecipient
797  * @tc.type: FUNC
798  * @tc.require: issue
799  */
800 HWTEST_F(AnsUtilsTest, OnDistributedKvStoreDeathRecipient_00001, Function | SmallTest | Level1)
801 {
802     advancedNotificationService_->OnDistributedKvStoreDeathRecipient();
803     AdvancedNotificationService ans;
804     ans.notificationSvrQueue_ = nullptr;
805     ans.OnDistributedKvStoreDeathRecipient();
806 }
807 
808 /**
809  * @tc.name: SetRequestBundleInfo_00001
810  * @tc.desc: Test SetRequestBundleInfo
811  * @tc.type: FUNC
812  * @tc.require: issue
813  */
814 HWTEST_F(AnsUtilsTest, SetRequestBundleInfo_00001, Function | SmallTest | Level1)
815 {
816     sptr<NotificationRequest> request = new NotificationRequest();
817     request->SetCreatorBundleName("test");
818     request->SetOwnerBundleName("test");
819     std::string bundle;
820     ASSERT_EQ(advancedNotificationService_->SetRequestBundleInfo(request, 1111, bundle), (int)ERR_OK);
821 }
822 
823 /**
824  * @tc.name: SendNotificationsOnCanceled_00001
825  * @tc.desc: Test SendNotificationsOnCanceled
826  * @tc.type: FUNC
827  * @tc.require: issue
828  */
829 HWTEST_F(AnsUtilsTest, SendNotificationsOnCanceled_00001, Function | SmallTest | Level1)
830 {
831     std::vector<sptr<Notification>> notifications;
832     sptr<NotificationRequest> request = new NotificationRequest();
833     sptr<Notification> no = new Notification(request);
834     notifications.push_back(no);
835     advancedNotificationService_->SendNotificationsOnCanceled(notifications, nullptr, 1);
836 }
837 
838 /**
839  * @tc.name: OnRecoverLiveView_00001
840  * @tc.desc: Test OnRecoverLiveView
841  * @tc.type: FUNC
842  * @tc.require: issue
843  */
844 HWTEST_F(AnsUtilsTest, OnRecoverLiveView_00001, Function | SmallTest | Level1)
845 {
846     std::vector<std::string> keys;
847     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
848     for (int i = 0; i < 10; i++) {
849         auto slotType = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
850         sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
851         request->SetSlotType(slotType);
852         request->SetOwnerUserId(100);
853         request->SetCreatorUserId(0);
854         request->SetOwnerBundleName("test");
855         request->SetOwnerUid(0);
856         request->SetNotificationId(10000+i);
857         auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
858         auto ret = advancedNotificationService_->AssignToNotificationList(record);
859         sptr<Notification> notification = new Notification(request);
860         keys.push_back(notification->GetKey());
861     }
862     advancedNotificationService_->OnRecoverLiveView(keys);
863 }
864 
865 /**
866  * @tc.name: OnRecoverLiveView_00002
867  * @tc.desc: Test OnRecoverLiveView
868  * @tc.type: FUNC
869  * @tc.require: issue
870  */
871 HWTEST_F(AnsUtilsTest, OnRecoverLiveView_00002, Function | SmallTest | Level1)
872 {
873     std::vector<std::string> keys;
874     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
875     auto slotType = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
876     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
877     request->SetSlotType(slotType);
878     request->SetOwnerUserId(100);
879     request->SetCreatorUserId(0);
880     request->SetOwnerBundleName("test");
881     request->SetOwnerUid(0);
882     request->SetNotificationId(222);
883     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
884     auto ret = advancedNotificationService_->AssignToNotificationList(record);
885     sptr<Notification> notification = new Notification(request);
886     keys.push_back(notification->GetKey());
887     keys.push_back("no");
888     advancedNotificationService_->OnRecoverLiveView(keys);
889 }
890 
891 /**
892  * @tc.name: AllowUseReminder_00001
893  * @tc.desc: Test AllowUseReminder
894  * @tc.type: FUNC
895  * @tc.require: issue
896  */
897 HWTEST_F(AnsUtilsTest, AllowUseReminder_00001, Function | SmallTest | Level1)
898 {
899     std::string str = "test1";
900     bool b = false;
901     advancedNotificationService_->AllowUseReminder(str, b);
902     ASSERT_EQ(advancedNotificationService_->AllowUseReminder(str, b), (int)ERR_OK);
903 }
904 
905 /**
906  * @tc.name: CloseAlert_00001
907  * @tc.desc: Test CloseAlert
908  * @tc.type: FUNC
909  * @tc.require: issue
910  */
911 HWTEST_F(AnsUtilsTest, CloseAlert_00001, Function | SmallTest | Level1)
912 {
913     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
914     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
915     request->SetNotificationId(222);
916     auto flags = std::make_shared<NotificationFlags>();
917     flags->SetBannerEnabled(true);
918     request->SetFlags(flags);
919     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
920     advancedNotificationService_->CloseAlert(record);
921     advancedNotificationService_->AssignToNotificationList(record);
922     ASSERT_EQ(advancedNotificationService_->notificationList_.size(), 1);
923     ASSERT_EQ(advancedNotificationService_->notificationList_.front()->request->GetFlags()->GetReminderFlags(), 0);
924 }
925 
926 /**
927  * @tc.name: OnBundleDataUpdate_00002
928  * @tc.desc: Test OnBundleDataUpdate
929  * @tc.name: IsSupportTemplate_00001
930  * @tc.desc: Test IsSupportTemplate
931  * @tc.type: FUNC
932  * @tc.require: issue
933  */
934 HWTEST_F(AnsUtilsTest, IsSupportTemplate_00001, Function | SmallTest | Level1)
935 {
936     AdvancedNotificationService ans;
937     std::string templateName = "";
938     bool support = false;
939     ASSERT_EQ(ans.IsSupportTemplate(templateName, support), (int)ERR_ANS_INVALID_PARAM);
940 }
941 
942 /**
943  * @tc.name: CheckCommonParams_00001
944  * @tc.desc: Test CheckCommonParams
945  * @tc.name: CheckCommonParams_00001
946  * @tc.desc: Test CheckCommonParams
947  * @tc.type: FUNC
948  * @tc.require: issue
949  */
950 HWTEST_F(AnsUtilsTest, CheckCommonParams_00001, Function | SmallTest | Level1)
951 {
952     AdvancedNotificationService ans;
953     ans.notificationSvrQueue_ = nullptr;
954     ASSERT_EQ(ans.CheckCommonParams(), (int)ERR_ANS_INVALID_PARAM);
955 }
956 
957 /**
958  * @tc.name: CheckCommonParams_00002
959  * @tc.desc: Test CheckCommonParams
960  * @tc.type: FUNC
961  * @tc.require: issue
962  */
963 HWTEST_F(AnsUtilsTest, CheckCommonParams_00002, Function | SmallTest | Level1)
964 {
965     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
966     MockIsSystemApp(false);
967     ASSERT_EQ(advancedNotificationService_->CheckCommonParams(), (int)ERR_ANS_NON_SYSTEM_APP);
968 }
969 
970 /**
971  * @tc.name: DeleteAllByUser_0001
972  * @tc.desc: Test DeleteAllByUser_0001
973  * @tc.type: FUNC
974  * @tc.require: issue
975  */
976 HWTEST_F(AnsUtilsTest, DeleteAllByUser_0001, Function | SmallTest | Level1)
977 {
978     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
979     MockIsSystemApp(false);
980     ASSERT_EQ(advancedNotificationService_->DeleteAllByUser(0), (int)ERR_ANS_NON_SYSTEM_APP);
981 }
982 
983 /**
984  * @tc.name: DeleteAllByUser_0001
985  * @tc.desc: Test DeleteAllByUser_0001
986  * @tc.type: FUNC
987  * @tc.require: issue
988  */
989 HWTEST_F(AnsUtilsTest, DeleteAllByUser_0002, Function | SmallTest | Level1)
990 {
991     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
992     MockIsSystemApp(true);
993     MockIsVerfyPermisson(false);
994     ASSERT_EQ(advancedNotificationService_->DeleteAllByUser(0), (int)ERR_ANS_PERMISSION_DENIED);
995 }
996 
997 /**
998  * @tc.name: DeleteAllByUserInner_0001
999  * @tc.desc: Test OnUserRemoved_0001
1000  * @tc.type: FUNC
1001  * @tc.require: issue
1002  */
1003 HWTEST_F(AnsUtilsTest, DeleteAllByUserInner_0001, Function | SmallTest | Level1)
1004 {
1005     AdvancedNotificationService ans;
1006     ans.notificationSvrQueue_ = nullptr;
1007     ASSERT_EQ(ans.DeleteAllByUserInner(0, 0, true), (int)ERR_ANS_INVALID_PARAM);
1008 }
1009 
1010 /**
1011  * @tc.name: CheckBundleOptionValid_0001
1012  * @tc.desc: Test CheckBundleOptionValid_0001
1013  * @tc.type: FUNC
1014  * @tc.require: issue
1015  */
1016 HWTEST_F(AnsUtilsTest, CheckBundleOptionValid_0001, Function | SmallTest | Level1)
1017 {
1018     sptr<NotificationBundleOption> bundle = nullptr;
1019     ASSERT_EQ(advancedNotificationService_->CheckBundleOptionValid(bundle), (int)ERR_ANS_INVALID_PARAM);
1020 
1021     bundle = new (std::nothrow) NotificationBundleOption("", 1);
1022     ASSERT_EQ(advancedNotificationService_->CheckBundleOptionValid(bundle), (int)ERR_ANS_INVALID_PARAM);
1023 
1024     MockQueryForgroundOsAccountId(false, 0);
1025     bundle = new (std::nothrow) NotificationBundleOption("test", 1);
1026     ASSERT_EQ(advancedNotificationService_->CheckBundleOptionValid(bundle), (int)ERR_ANS_INVALID_BUNDLE);
1027 
1028     MockQueryForgroundOsAccountId(true, 0);
1029     ASSERT_EQ(advancedNotificationService_->CheckBundleOptionValid(bundle), (int)ERR_OK);
1030 
1031     sptr<NotificationBundleOption> bundle1 = new (std::nothrow) NotificationBundleOption("test", 1);
1032     MockQueryForgroundOsAccountId(true, 2);
1033     ASSERT_EQ(advancedNotificationService_->CheckBundleOptionValid(bundle1), (int)ERR_OK);
1034 
1035     sptr<NotificationBundleOption> bundle2 = new (std::nothrow) NotificationBundleOption("test", 0);
1036     ASSERT_EQ(advancedNotificationService_->CheckBundleOptionValid(bundle2), (int)ERR_ANS_INVALID_BUNDLE);
1037 
1038     sptr<NotificationBundleOption> bundle3 = new (std::nothrow) NotificationBundleOption("test", 0);
1039     MockQueryForgroundOsAccountId(true, 0);
1040     ASSERT_EQ(advancedNotificationService_->CheckBundleOptionValid(bundle3), (int)ERR_OK);
1041 }
1042 
1043 /**
1044  * @tc.name: SubmitAsyncTask_0001
1045  * @tc.desc: Test SubmitAsyncTask_0001
1046  * @tc.type: FUNC
1047  * @tc.require: issue
1048  */
1049 HWTEST_F(AnsUtilsTest, SubmitAsyncTask_0001, Function | SmallTest | Level1)
1050 {
1051     ErrCode result = ERR_OK;
__anon05d08e710102() 1052     advancedNotificationService_->SubmitAsyncTask(std::bind([&]() {
1053         result = ERR_ANS_INVALID_PARAM;
1054     }));
1055     SleepForFC();
1056     ASSERT_EQ(result, (int)ERR_ANS_INVALID_PARAM);
1057 }
1058 
1059 /**
1060  * @tc.name: GetCommonTargetRecordList_0001
1061  * @tc.desc: Test GetCommonTargetRecordList_0001
1062  * @tc.type: FUNC
1063  * @tc.require: issue
1064  */
1065 HWTEST_F(AnsUtilsTest, GetCommonTargetRecordList_0001, Function | SmallTest | Level1)
1066 {
1067     auto slotType = NotificationConstant::SlotType::LIVE_VIEW;
1068     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
1069     sptr<NotificationBundleOption> bundleOption = new (std::nothrow) NotificationBundleOption("test", 1);
1070     request->SetSlotType(slotType);
1071     request->SetOwnerUserId(1);
1072     request->SetCreatorUserId(2);
1073     request->SetOwnerBundleName("test");
1074     request->SetOwnerUid(0);
1075     request->SetCreatorUid(1);
1076     request->SetNotificationId(1);
1077 
1078     auto liveContent = std::make_shared<NotificationLiveViewContent>();
1079     liveContent->SetIsOnlyLocalUpdate(true);
1080     auto content = std::make_shared<NotificationContent>(liveContent);
1081     request->SetContent(content);
1082 
1083     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundleOption);
1084     auto ret = advancedNotificationService_->AssignToNotificationList(record);
1085     std::vector<std::shared_ptr<NotificationRecord>> recordList;
1086     advancedNotificationService_->GetCommonTargetRecordList(1, NotificationConstant::SlotType::LIVE_VIEW,
1087         NotificationContent::Type::LIVE_VIEW, recordList);
1088     ASSERT_EQ(recordList.size(), 1);
1089 }
1090 
1091 }  // namespace Notification
1092 }  // namespace OHOS
1093