• 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 "errors.h"
17 #include "notification_content.h"
18 #include "notification_record.h"
19 #include "notification_request.h"
20 #include <chrono>
21 #include <functional>
22 #include <memory>
23 #include <thread>
24 
25 #include "gtest/gtest.h"
26 #include <vector>
27 
28 #define private public
29 
30 #include "advanced_notification_service.h"
31 #include "ans_const_define.h"
32 #include "ans_inner_errors.h"
33 #include "ans_log_wrapper.h"
34 #include "ans_notification.h"
35 #include "ans_ut_constant.h"
36 #include "common_event_manager.h"
37 #include "common_event_support.h"
38 #include "iremote_object.h"
39 #include "mock_ipc_skeleton.h"
40 #include "notification_preferences.h"
41 #include "notification_subscriber.h"
42 #include "notification_subscriber_manager.h"
43 #include "mock_push_callback_stub.h"
44 #include "system_event_observer.h"
45 #include "notification_constant.h"
46 #include "want_agent_info.h"
47 #include "want_agent_helper.h"
48 #include "want_params.h"
49 #include "bundle_manager_helper.h"
50 #include "mock_bundle_mgr.h"
51 
52 extern void MockIsOsAccountExists(bool mockRet);
53 
54 using namespace testing::ext;
55 using namespace OHOS::Media;
56 
57 namespace OHOS {
58 namespace Notification {
59 extern void MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum mockRet);
60 extern void MockIsSystemApp(bool isSystemApp);
61 extern void MockIsNonBundleName(bool isNonBundleName);
62 extern void MockIsVerfyPermisson(bool isVerify);
63 
64 class AdvancedNotificationServiceTest : public testing::Test {
65 public:
66     static void SetUpTestCase();
67     static void TearDownTestCase();
68     void SetUp();
69     void TearDown();
70 
71 private:
72     void TestAddSlot(NotificationConstant::SlotType type);
73     void TestAddLiveViewSlot(bool isForceControl);
74     void MockSystemApp();
75 
76 private:
77     static sptr<AdvancedNotificationService> advancedNotificationService_;
78 };
79 
80 sptr<AdvancedNotificationService> AdvancedNotificationServiceTest::advancedNotificationService_ = nullptr;
81 
SetUpTestCase()82 void AdvancedNotificationServiceTest::SetUpTestCase()
83 {
84     MockIsOsAccountExists(true);
85 }
86 
TearDownTestCase()87 void AdvancedNotificationServiceTest::TearDownTestCase() {}
88 
SetUp()89 void AdvancedNotificationServiceTest::SetUp()
90 {
91     GTEST_LOG_(INFO) << "SetUp start";
92 
93     advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService();
94     IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
95     NotificationPreferences::GetInstance()->ClearNotificationInRestoreFactorySettings();
96     IPCSkeleton::SetCallingUid(SYSTEM_APP_UID);
97     advancedNotificationService_->CancelAll("");
98     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE);
99     GTEST_LOG_(INFO) << "SetUp end";
100 }
101 
TearDown()102 void AdvancedNotificationServiceTest::TearDown()
103 {
104     IPCSkeleton::SetCallingUid(SYSTEM_APP_UID);
105     advancedNotificationService_ = nullptr;
106     GTEST_LOG_(INFO) << "TearDown";
107 }
108 
SleepForFC()109 inline void SleepForFC()
110 {
111     // For ANS Flow Control
112     std::this_thread::sleep_for(std::chrono::seconds(1));
113 }
114 
115 class TestAnsSubscriber : public NotificationSubscriber {
116 public:
OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> & date)117     void OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> &date) override
118     {}
OnConnected()119     void OnConnected() override
120     {}
OnDisconnected()121     void OnDisconnected() override
122     {}
OnDied()123     void OnDied() override
124     {}
OnUpdate(const std::shared_ptr<NotificationSortingMap> & sortingMap)125     void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) override
126     {}
OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> & badgeData)127     void OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> &badgeData) override
128     {}
OnBadgeEnabledChanged(const sptr<EnabledNotificationCallbackData> & callbackData)129     void OnBadgeEnabledChanged(
130         const sptr<EnabledNotificationCallbackData> &callbackData) override
131     {}
OnEnabledNotificationChanged(const std::shared_ptr<EnabledNotificationCallbackData> & callbackData)132     void OnEnabledNotificationChanged(
133         const std::shared_ptr<EnabledNotificationCallbackData> &callbackData) override
134     {}
OnCanceled(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap,int32_t deleteReason)135     void OnCanceled(const std::shared_ptr<Notification> &request,
136         const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) override
137     {}
OnConsumed(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap)138     void OnConsumed(const std::shared_ptr<Notification> &request,
139         const std::shared_ptr<NotificationSortingMap> &sortingMap) override
140     {}
OnBatchCanceled(const std::vector<std::shared_ptr<Notification>> & requestList,const std::shared_ptr<NotificationSortingMap> & sortingMap,int32_t deleteReason)141     void OnBatchCanceled(const std::vector<std::shared_ptr<Notification>>
142         &requestList, const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) override
143     {}
144 };
145 
TestAddSlot(NotificationConstant::SlotType type)146 void AdvancedNotificationServiceTest::TestAddSlot(NotificationConstant::SlotType type)
147 {
148     MockSystemApp();
149     std::vector<sptr<NotificationSlot>> slots;
150     sptr<NotificationSlot> slot = new NotificationSlot(type);
151     slots.push_back(slot);
152     ASSERT_EQ(advancedNotificationService_->AddSlots(slots), (int)ERR_OK);
153 }
154 
MockSystemApp()155 void AdvancedNotificationServiceTest::MockSystemApp()
156 {
157     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
158     MockIsSystemApp(true);
159     MockIsVerfyPermisson(true);
160 }
161 
TestAddLiveViewSlot(bool isForceControl)162 void AdvancedNotificationServiceTest::TestAddLiveViewSlot(bool isForceControl)
163 {
164     MockSystemApp();
165     std::vector<sptr<NotificationSlot>> slots;
166     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::LIVE_VIEW);
167     slot->SetForceControl(isForceControl);
168     slots.push_back(slot);
169     ASSERT_EQ(advancedNotificationService_->AddSlots(slots), (int)ERR_OK);
170 }
171 
MakePixelMap(int32_t width,int32_t height)172 inline std::shared_ptr<PixelMap> MakePixelMap(int32_t width, int32_t height)
173 {
174     const int32_t PIXEL_BYTES = 4;
175     std::shared_ptr<PixelMap> pixelMap = std::make_shared<PixelMap>();
176     if (pixelMap == nullptr) {
177         return nullptr;
178     }
179     ImageInfo info;
180     info.size.width = width;
181     info.size.height = height;
182     info.pixelFormat = PixelFormat::ARGB_8888;
183     info.colorSpace = ColorSpace::SRGB;
184     pixelMap->SetImageInfo(info);
185     int32_t rowDataSize = width * PIXEL_BYTES;
186     uint32_t bufferSize = rowDataSize * height;
187     void *buffer = malloc(bufferSize);
188     if (buffer != nullptr) {
189         pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
190     }
191     return pixelMap;
192 }
193 
194 /**
195  * @tc.number    : ANS_Publish_00100
196  * @tc.name      : ANSPublish00100
197  * @tc.desc      : Publish a normal text type notification.
198  */
199 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00100, Function | SmallTest | Level1)
200 {
201     TestAddSlot(NotificationConstant::SlotType::OTHER);
202     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
203     MockIsSystemApp(true);
204 
205     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
206         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
207     sptr<NotificationRequest> req = new NotificationRequest(1);
208     EXPECT_NE(req, nullptr);
209     req->SetSlotType(NotificationConstant::SlotType::OTHER);
210     req->SetLabel("req's label");
211     req->SetCreatorUid(1);
212     std::string label = "publish's label";
213     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
214     EXPECT_NE(normalContent, nullptr);
215     normalContent->SetText("normalContent's text");
216     normalContent->SetTitle("normalContent's title");
217     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
218     EXPECT_NE(content, nullptr);
219     req->SetContent(content);
220     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
221     SleepForFC();
222 }
223 
224 /**
225  * @tc.number    : ANS_Publish_00200
226  * @tc.name      : ANSPublish00200
227  * @tc.desc      : Publish a normal text type notification twice.
228  */
229 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00200, Function | SmallTest | Level1)
230 {
231     TestAddSlot(NotificationConstant::SlotType::OTHER);
232     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
233     MockIsSystemApp(true);
234 
235     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
236         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
237     sptr<NotificationRequest> req = new NotificationRequest(1);
238     EXPECT_NE(req, nullptr);
239     req->SetSlotType(NotificationConstant::SlotType::OTHER);
240     req->SetLabel("req's label");
241     req->SetCreatorUid(1);
242     std::string label = "publish's label";
243     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
244     EXPECT_NE(normalContent, nullptr);
245     normalContent->SetText("normalContent's text");
246     normalContent->SetTitle("normalContent's title");
247     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
248     EXPECT_NE(content, nullptr);
249     req->SetContent(content);
250     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
251     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
252     SleepForFC();
253 }
254 
255 /**
256  * @tc.number    : ANS_Publish_00300
257  * @tc.name      : ANSPublish00300
258  * @tc.desc      : When slotType is CUSTOM and not systemApp, the notification publish fails,
259  * and the notification publish interface returns ERR_ANS_NON_SYSTEM_APP.
260  */
261 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00300, Function | SmallTest | Level1)
262 {
263     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
264     MockIsSystemApp(false);
265     sptr<NotificationRequest> req = new NotificationRequest();
266     EXPECT_NE(req, nullptr);
267     req->SetSlotType(NotificationConstant::SlotType::CUSTOM);
268     req->SetLabel("req's label");
269     req->SetCreatorUid(1);
270     std::string label = "publish's label";
271     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
272     EXPECT_NE(normalContent, nullptr);
273     normalContent->SetText("normalContent's text");
274     normalContent->SetTitle("normalContent's title");
275     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
276     EXPECT_NE(content, nullptr);
277     req->SetContent(content);
278     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_NON_SYSTEM_APP);
279     SleepForFC();
280 }
281 
282 /**
283  * @tc.number    : ANS_Publish_00400
284  * @tc.name      : ANSPublish00400
285  * @tc.desc      : When the obtained bundleName is empty, the notification publish interface returns
286  * ERR_ANS_INVALID_BUNDLE.
287  */
288 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00400, Function | SmallTest | Level1)
289 {
290     MockIsNonBundleName(true);
291     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
292     MockIsSystemApp(true);
293     sptr<NotificationRequest> req = new NotificationRequest();
294     EXPECT_NE(req, nullptr);
295     req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
296     req->SetLabel("req's label");
297     req->SetCreatorUid(1);
298     std::string label = "publish's label";
299     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
300     EXPECT_NE(normalContent, nullptr);
301     normalContent->SetText("normalContent's text");
302     normalContent->SetTitle("normalContent's title");
303     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
304     EXPECT_NE(content, nullptr);
305     req->SetContent(content);
306     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_INVALID_BUNDLE);
307     MockIsNonBundleName(false);
308     SleepForFC();
309 }
310 
311 /**
312  * @tc.number    : ANS_Publish_00500
313  * @tc.name      : ANSPublish00500
314  * @tc.desc      : When the obtained bundleName does not have a corresponding slot in the database,
315  * create the corresponding slot and publish a notification.
316  */
317 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00500, Function | SmallTest | Level1)
318 {
319     TestAddSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
320     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
321     MockIsSystemApp(true);
322 
323     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
324         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
325     sptr<NotificationRequest> req = new NotificationRequest();
326     EXPECT_NE(req, nullptr);
327     req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
328     req->SetLabel("req's label");
329     req->SetCreatorUid(1);
330     std::string label = "publish's label";
331     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
332     EXPECT_NE(normalContent, nullptr);
333     normalContent->SetText("normalContent's text");
334     normalContent->SetTitle("normalContent's title");
335     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
336     EXPECT_NE(content, nullptr);
337     req->SetContent(content);
338     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
339     SleepForFC();
340 }
341 
342 /**
343  * @tc.number    : ANS_Publish_00600
344  * @tc.name      : ANSPublish00600
345  * @tc.desc      : When the obtained bundleName have a corresponding slot in the database,
346  * the test publish interface can successfully publish a notification of normal text type.
347  */
348 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00600, Function | SmallTest | Level1)
349 {
350     TestAddSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
351     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
352     MockIsSystemApp(true);
353 
354     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
355         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
356     sptr<NotificationRequest> req = new NotificationRequest();
357     EXPECT_NE(req, nullptr);
358     req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
359     req->SetLabel("req's label");
360     req->SetCreatorUid(1);
361     std::string label = "publish's label";
362     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
363     EXPECT_NE(normalContent, nullptr);
364     normalContent->SetText("normalContent's text");
365     normalContent->SetTitle("normalContent's title");
366     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
367     EXPECT_NE(content, nullptr);
368     req->SetContent(content);
369     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
370     SleepForFC();
371 }
372 
373 /**
374  * @tc.number    : ANS_Publish_00700
375  * @tc.name      : ANSPublish00700
376  * @tc.desc      : When the obtained bundleName have a corresponding slot in the database,
377  * create the corresponding slot and publish a notification.
378  */
379 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00700, Function | SmallTest | Level1)
380 {
381     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
382     MockIsSystemApp(true);
383 
384     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
385         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
386     sptr<NotificationRequest> req = new NotificationRequest();
387     EXPECT_NE(req, nullptr);
388     req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
389     req->SetLabel("req's label");
390     req->SetCreatorUid(1);
391     std::string label = "publish's label";
392     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
393     EXPECT_NE(normalContent, nullptr);
394     normalContent->SetText("normalContent's text");
395     normalContent->SetTitle("normalContent's title");
396     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
397     EXPECT_NE(content, nullptr);
398     req->SetContent(content);
399     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
400     SleepForFC();
401 }
402 
403 /**
404  * @tc.number    : ANS_Publish_00800
405  * @tc.name      : ANSPublish00800
406  * @tc.desc      : Create a slot of type SOCIAL_COMMUNICATION and successfully publish a notification
407  */
408 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00800, Function | SmallTest | Level1)
409 {
410     TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
411     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
412     MockIsSystemApp(true);
413 
414     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
415         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
416     sptr<NotificationRequest> req = new NotificationRequest();
417     EXPECT_NE(req, nullptr);
418     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
419     req->SetLabel("req's label");
420     req->SetCreatorUid(1);
421     std::string label = "publish's label";
422     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
423     EXPECT_NE(normalContent, nullptr);
424     normalContent->SetText("normalContent's text");
425     normalContent->SetTitle("normalContent's title");
426     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
427     EXPECT_NE(content, nullptr);
428     req->SetContent(content);
429     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
430     SleepForFC();
431 }
432 
433 /**
434  * @tc.number    : ANS_Publish_00900
435  * @tc.name      : ANSPublish00900
436  * @tc.desc      : Create a slot of type SERVICE_REMINDER and successfully publish a notification
437  */
438 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00900, Function | SmallTest | Level1)
439 {
440     TestAddSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
441     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
442     MockIsSystemApp(true);
443 
444     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
445         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
446     sptr<NotificationRequest> req = new NotificationRequest();
447     EXPECT_NE(req, nullptr);
448     req->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER);
449     req->SetLabel("req's label");
450     req->SetCreatorUid(1);
451     std::string label = "publish's label";
452     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
453     EXPECT_NE(normalContent, nullptr);
454     normalContent->SetText("normalContent's text");
455     normalContent->SetTitle("normalContent's title");
456     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
457     EXPECT_NE(content, nullptr);
458     req->SetContent(content);
459     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
460     SleepForFC();
461 }
462 
463 /**
464  * @tc.number    : ANS_Publish_01000
465  * @tc.name      : ANSPublish01000
466  * @tc.desc      : Create a slot of type CONTENT_INFORMATION and successfully publish a notification
467  */
468 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01000, Function | SmallTest | Level1)
469 {
470     TestAddSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
471     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
472     MockIsSystemApp(true);
473 
474     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
475         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
476     sptr<NotificationRequest> req = new NotificationRequest();
477     EXPECT_NE(req, nullptr);
478     req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
479     req->SetLabel("req's label");
480     req->SetCreatorUid(1);
481     std::string label = "publish's label";
482     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
483     EXPECT_NE(normalContent, nullptr);
484     normalContent->SetText("normalContent's text");
485     normalContent->SetTitle("normalContent's title");
486     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
487     EXPECT_NE(content, nullptr);
488     req->SetContent(content);
489     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
490     SleepForFC();
491 }
492 
493 /**
494  * @tc.number    : ANS_Publish_01100
495  * @tc.name      : ANSPublish01100
496  * @tc.desc      : Create a slot of type OTHER and successfully publish a notification
497  */
498 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01100, Function | SmallTest | Level1)
499 {
500     TestAddSlot(NotificationConstant::SlotType::OTHER);
501     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
502     MockIsSystemApp(true);
503 
504     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
505         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
506     sptr<NotificationRequest> req = new NotificationRequest();
507     EXPECT_NE(req, nullptr);
508     req->SetSlotType(NotificationConstant::SlotType::OTHER);
509     req->SetLabel("req's label");
510     req->SetCreatorUid(1);
511     std::string label = "publish's label";
512     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
513     EXPECT_NE(normalContent, nullptr);
514     normalContent->SetText("normalContent's text");
515     normalContent->SetTitle("normalContent's title");
516     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
517     EXPECT_NE(content, nullptr);
518     req->SetContent(content);
519     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
520     SleepForFC();
521 }
522 
523 /**
524  * @tc.number    : ANS_Publish_01200
525  * @tc.name      : ANSPublish01200
526  * @tc.desc      : Create a slot of type CUSTOM and successfully publish a notification
527  */
528 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01200, Function | SmallTest | Level1)
529 {
530     TestAddSlot(NotificationConstant::SlotType::CUSTOM);
531     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
532     MockIsSystemApp(true);
533     sptr<NotificationRequest> req = new NotificationRequest();
534     EXPECT_NE(req, nullptr);
535     req->SetSlotType(NotificationConstant::SlotType::CUSTOM);
536     req->SetLabel("req's label");
537     req->SetCreatorUid(1);
538     std::string label = "publish's label";
539     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
540     EXPECT_NE(normalContent, nullptr);
541     normalContent->SetText("normalContent's text");
542     normalContent->SetTitle("normalContent's title");
543     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
544     EXPECT_NE(content, nullptr);
545     req->SetContent(content);
546     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
547     MockIsSystemApp(false);
548     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_NON_SYSTEM_APP);
549     SleepForFC();
550 }
551 
552 /**
553  * @tc.number    : ANS_Publish_01300
554  * @tc.name      : ANSPublish01300
555  * @tc.desc      : When a bundle is not allowed to publish a notification, the notification publishing interface
556  returns
557  * ERR_ANS_NOT_ALLOWED
558  */
559 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01300, Function | SmallTest | Level1)
560 {
561     TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
562     sptr<NotificationRequest> req = new NotificationRequest();
563     EXPECT_NE(req, nullptr);
564     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
565     req->SetLabel("req's label");
566     req->SetCreatorUid(1);
567     std::string label = "publish's label";
568     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
569     EXPECT_NE(normalContent, nullptr);
570     normalContent->SetText("normalContent's text");
571     normalContent->SetTitle("normalContent's title");
572     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
573     EXPECT_NE(content, nullptr);
574     req->SetContent(content);
575     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
576                   std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), false),
577         (int)ERR_OK);
578     IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
579     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
580     MockIsSystemApp(true);
581     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_NOT_ALLOWED);
582     SleepForFC();
583 }
584 
585 /**
586  * @tc.number    : ANS_Publish_01400
587  * @tc.name      : ANSPublish01400
588  * @tc.desc      : When an non system app wants to publish an notification with local wantAgent, the
589  *  notification publishing interface returns ERR_ANS_NON_SYSTEM_APP;
590  */
591 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01400, Function | SmallTest | Level1)
592 {
593     TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
594     sptr<NotificationRequest> req = new NotificationRequest();
595     EXPECT_NE(req, nullptr);
596     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
597     std::shared_ptr<AbilityRuntime::WantAgent::LocalPendingWant> localPendingWant =
598         std::make_shared<AbilityRuntime::WantAgent::LocalPendingWant>("TestBundleName", want, 0);
599     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
600         std::make_shared<AbilityRuntime::WantAgent::WantAgent>(localPendingWant);
601     req->SetWantAgent(wantAgent);
602     MockIsSystemApp(false);
603     std::string label = "publish's label";
604     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_NON_SYSTEM_APP);
605     SleepForFC();
606 }
607 
608 /**
609  * @tc.number    : AdvancedNotificationServiceTest_04600
610  * @tc.name      : ANS_Publish_0500
611  * @tc.desc      : publish function when NotificationsEnabled is false
612  */
613 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04600, Function | SmallTest | Level1)
614 {
615     sptr<NotificationRequest> req = new NotificationRequest(1);
616     req->SetCreatorUid(1);
617     req->SetSlotType(NotificationConstant::OTHER);
618     TestAddSlot(NotificationConstant::SlotType::OTHER);
619     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
620                   std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), false),
621         (int)ERR_OK);
622     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
623     MockIsSystemApp(true);
624     ASSERT_EQ(advancedNotificationService_->Publish(std::string(), req), (int)ERR_ANS_NOT_ALLOWED);
625 }
626 
627 /**
628  * @tc.number    : AdvancedNotificationServiceTest_04700
629  * @tc.name      : ANS_Cancel_0100
630  * @tc.desc      : public two notification to cancel one of them
631  */
632 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04700, Function | SmallTest | Level1)
633 {
634     TestAddSlot(NotificationConstant::SlotType::OTHER);
635     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
636     MockIsSystemApp(true);
637 
638     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
639         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
640     std::string label = "testLabel";
641     {
642         sptr<NotificationRequest> req = new NotificationRequest(1);
643         req->SetSlotType(NotificationConstant::OTHER);
644         req->SetLabel(label);
645         req->SetCreatorUid(1);
646         ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
647     }
648     {
649         sptr<NotificationRequest> req = new NotificationRequest(2);
650         req->SetSlotType(NotificationConstant::OTHER);
651         req->SetLabel(label);
652         req->SetCreatorUid(1);
653         ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
654     }
655     ASSERT_EQ(advancedNotificationService_->Cancel(1, label, ""), (int)ERR_OK);
656 }
657 
658 /**
659  * @tc.number    : AdvancedNotificationServiceTest_04800
660  * @tc.name      : ANS_Cancel_0200
661  * @tc.desc      : Test Cancel function when notification no exists
662  */
663 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04800, Function | SmallTest | Level1)
664 {
665     int32_t notificationId = 0;
666     std::string label = "testLabel";
667     ASSERT_EQ((int)advancedNotificationService_->Cancel(
668         notificationId, label, ""), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS);
669 }
670 
671 /**
672  * @tc.number    : AdvancedNotificationServiceTest_04900
673  * @tc.name      : ANS_CancelAll_0100
674  * @tc.desc      : Test CancelAll function
675  */
676 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04900, Function | SmallTest | Level1)
677 {
678     TestAddSlot(NotificationConstant::SlotType::OTHER);
679     sptr<NotificationRequest> req = new NotificationRequest(1);
680     req->SetSlotType(NotificationConstant::OTHER);
681     ASSERT_EQ(advancedNotificationService_->CancelAll(""), (int)ERR_OK);
682 }
683 
684 /**
685  * @tc.number    : AdvancedNotificationServiceTest_05000
686  * @tc.name      : ANS_Cancel_0100
687  * @tc.desc      : Test Cancel function when unremovable is true
688  */
689 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05000, Function | SmallTest | Level1)
690 {
691     TestAddSlot(NotificationConstant::SlotType::OTHER);
692     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
693     MockIsSystemApp(true);
694 
695     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
696         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
697     int32_t notificationId = 2;
698     std::string label = "testLabel";
699     sptr<NotificationRequest> req = new NotificationRequest(notificationId);
700     req->SetSlotType(NotificationConstant::OTHER);
701     req->SetLabel(label);
702     req->SetUnremovable(true);
703     req->SetCreatorUid(1);
704     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
705     ASSERT_EQ(advancedNotificationService_->Cancel(notificationId, label, ""), (int)ERR_OK);
706 }
707 
708 
709 /**
710  * @tc.number    : AdvancedNotificationServiceTest_10000
711  * @tc.name      : ANS_Publish_With_PixelMap
712  * @tc.desc      : Publish a notification with pixelMap.
713  */
714 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10000, Function | SmallTest | Level1)
715 {
716     const int BIG_PICTURE_WIDTH = 400;
717     const int BIG_PICTURE_HEIGHT = 300;
718     const int ICON_SIZE = 36;
719 
720     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
721     MockIsSystemApp(true);
722 
723     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
724         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
725     sptr<NotificationRequest> req = new NotificationRequest(1);
726     EXPECT_NE(req, nullptr);
727     req->SetSlotType(NotificationConstant::SlotType::OTHER);
728     req->SetLabel("label");
729     std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
730     EXPECT_NE(pictureContent, nullptr);
731     pictureContent->SetText("notification text");
732     pictureContent->SetTitle("notification title");
733     std::shared_ptr<PixelMap> bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT);
734     EXPECT_NE(bigPicture, nullptr);
735     pictureContent->SetBigPicture(bigPicture);
736     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(pictureContent);
737     EXPECT_NE(content, nullptr);
738     req->SetContent(content);
739     std::shared_ptr<PixelMap> littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
740     req->SetLittleIcon(littleIcon);
741     std::shared_ptr<PixelMap> bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
742     req->SetBigIcon(bigIcon);
743     ASSERT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK);
744 }
745 
746 /**
747  * @tc.number    : AdvancedNotificationServiceTest_10100
748  * @tc.name      : ANS_Publish_With_PixelMap_Oversize_00100
749  * @tc.desc      : Publish a notification with oversize pixelMap.
750  */
751 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10100, Function | SmallTest | Level1)
752 {
753     const int BIG_PICTURE_WIDTH = 1024;
754     const int BIG_PICTURE_HEIGHT = 1024;
755     const int ICON_SIZE = 36;
756 
757     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
758     MockIsSystemApp(true);
759     sptr<NotificationRequest> req = new NotificationRequest(1);
760     EXPECT_NE(req, nullptr);
761     req->SetSlotType(NotificationConstant::SlotType::OTHER);
762     req->SetLabel("label");
763     std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
764     EXPECT_NE(pictureContent, nullptr);
765     pictureContent->SetText("notification text");
766     pictureContent->SetTitle("notification title");
767     std::shared_ptr<PixelMap> bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT);
768     EXPECT_NE(bigPicture, nullptr);
769     pictureContent->SetBigPicture(bigPicture);
770     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(pictureContent);
771     EXPECT_NE(content, nullptr);
772     req->SetContent(content);
773     std::shared_ptr<PixelMap> littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
774     req->SetLittleIcon(littleIcon);
775     std::shared_ptr<PixelMap> bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
776     req->SetBigIcon(bigIcon);
777     ASSERT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_ANS_PICTURE_OVER_SIZE);
778 }
779 
780 /**
781  * @tc.number    : AdvancedNotificationServiceTest_10200
782  * @tc.name      : ANS_Publish_With_PixelMap_Oversize_00200
783  * @tc.desc      : Publish a notification with oversize pixelMap.
784  */
785 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10200, Function | SmallTest | Level1)
786 {
787     const int BIG_PICTURE_WIDTH = 400;
788     const int BIG_PICTURE_HEIGHT = 300;
789     const int ICON_SIZE = 256;
790 
791     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
792     MockIsSystemApp(true);
793     sptr<NotificationRequest> req = new NotificationRequest(1);
794     EXPECT_NE(req, nullptr);
795     req->SetSlotType(NotificationConstant::SlotType::OTHER);
796     req->SetLabel("label");
797     std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
798     EXPECT_NE(pictureContent, nullptr);
799     pictureContent->SetText("notification text");
800     pictureContent->SetTitle("notification title");
801     std::shared_ptr<PixelMap> bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT);
802     EXPECT_NE(bigPicture, nullptr);
803     pictureContent->SetBigPicture(bigPicture);
804     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(pictureContent);
805     EXPECT_NE(content, nullptr);
806     req->SetContent(content);
807     std::shared_ptr<PixelMap> littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
808     req->SetLittleIcon(littleIcon);
809     std::shared_ptr<PixelMap> bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
810     req->SetBigIcon(bigIcon);
811     ASSERT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_ANS_ICON_OVER_SIZE);
812 }
813 
814 /**
815  * @tc.number    : AdvancedNotificationServiceTest_10300
816  * @tc.name      : ANS_Cancel_By_Group_10300
817  * @tc.desc      : Cancel notification by group name.
818  */
819 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10300, Function | SmallTest | Level1)
820 {
821     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
822     MockIsSystemApp(true);
823 
824     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
825         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
826     sptr<NotificationRequest> req = new NotificationRequest(1);
827     ASSERT_NE(req, nullptr);
828     req->SetSlotType(NotificationConstant::SlotType::OTHER);
829     req->SetLabel("label");
830     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
831     ASSERT_NE(normalContent, nullptr);
832     normalContent->SetText("text");
833     normalContent->SetTitle("title");
834     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
835     ASSERT_NE(content, nullptr);
836     req->SetContent(content);
837     std::string groupName = "group";
838     req->SetGroupName(groupName);
839     ASSERT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK);
840     ASSERT_EQ(advancedNotificationService_->CancelGroup(groupName, ""), (int)ERR_OK);
841     SleepForFC();
842 }
843 
844 /**
845  * @tc.number    : AdvancedNotificationServiceTest_10400
846  * @tc.name      : ANS_Remove_By_Group_10400
847  * @tc.desc      : Remove notification by group name.
848  */
849 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10400, Function | SmallTest | Level1)
850 {
851     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
852     MockIsSystemApp(true);
853 
854     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
855         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
856     sptr<NotificationRequest> req = new NotificationRequest(1);
857     ASSERT_NE(req, nullptr);
858     req->SetSlotType(NotificationConstant::SlotType::OTHER);
859     req->SetLabel("label");
860     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
861     ASSERT_NE(normalContent, nullptr);
862     normalContent->SetText("text");
863     normalContent->SetTitle("title");
864     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
865     ASSERT_NE(content, nullptr);
866     req->SetContent(content);
867     std::string groupName = "group";
868     req->SetGroupName(groupName);
869     ASSERT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK);
870 
871     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
872     ASSERT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), (int)ERR_OK);
873     SleepForFC();
874 }
875 
876 
877 /**
878  * @tc.name: AdvancedNotificationServiceTest_12000
879  * @tc.desc: Send enable notification hisysevent and enable notification error hisysevent.
880  * @tc.type: FUNC
881  * @tc.require: I582Y4
882  */
883 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12000, Function | SmallTest | Level1)
884 {
885     // bundleName is empty
886     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
887         std::string(), new NotificationBundleOption(std::string(), -1), true),
888         (int)ERR_ANS_INVALID_PARAM);
889 
890     TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
891     sptr<NotificationRequest> req = new NotificationRequest();
892     EXPECT_NE(req, nullptr);
893     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
894     req->SetLabel("req's label");
895     std::string label = "enable's label";
896     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
897     EXPECT_NE(normalContent, nullptr);
898     normalContent->SetText("normalContent's text");
899     normalContent->SetTitle("normalContent's title");
900     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
901     EXPECT_NE(content, nullptr);
902     req->SetContent(content);
903     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
904         std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), false),
905         (int)ERR_OK);
906 
907     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
908     MockIsSystemApp(true);
909     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_NOT_ALLOWED);
910     SleepForFC();
911 }
912 
913 /**
914  * @tc.name: AdvancedNotificationServiceTest_12100
915  * @tc.desc: Send enable notification slot hisysevent.
916  * @tc.type: FUNC
917  * @tc.require: I582Y4
918  */
919 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12100, Function | SmallTest | Level1)
920 {
921     TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
922     sptr<NotificationRequest> req = new NotificationRequest();
923     EXPECT_NE(req, nullptr);
924     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
925     req->SetLabel("req's label");
926     std::string label = "enable's label";
927     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
928     EXPECT_NE(normalContent, nullptr);
929     normalContent->SetText("normalContent's text");
930     normalContent->SetTitle("normalContent's title");
931     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
932     EXPECT_NE(content, nullptr);
933     req->SetContent(content);
934     auto result = advancedNotificationService_->SetEnabledForBundleSlot(
935         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID),
936         NotificationConstant::SlotType::SOCIAL_COMMUNICATION,
937         false, false);
938     ASSERT_EQ(result, (int)ERR_OK);
939 
940     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
941     MockIsSystemApp(true);
942     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED);
943     SleepForFC();
944 }
945 
946 /**
947  * @tc.name: AdvancedNotificationServiceTest_12200
948  * @tc.desc: Send remove notification hisysevent.
949  * @tc.type: FUNC
950  * @tc.require: I582Y4
951  */
952 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12200, Function | SmallTest | Level1)
953 {
954     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
955         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
956     TestAddSlot(NotificationConstant::SlotType::OTHER);
957     int32_t notificationId = 1;
958     std::string label = "testRemove";
959     sptr<NotificationRequest> req = new NotificationRequest(notificationId);
960     req->SetSlotType(NotificationConstant::OTHER);
961     req->SetLabel(label);
962     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
963     MockIsSystemApp(true);
964     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
965 
966     auto result = advancedNotificationService_->RemoveNotification(
967         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID),
968         notificationId, label, NotificationConstant::CANCEL_REASON_DELETE);
969     ASSERT_EQ(result, (int)ERR_OK);
970 }
971 
972 /**
973  * @tc.name: AdvancedNotificationServiceTest_12300
974  * @tc.desc: SA publish notification, Failed to publish when creatorUid default.
975  * @tc.type: FUNC
976  * @tc.require: I5P1GU
977  */
978 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12300, Function | SmallTest | Level1)
979 {
980     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
981         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, 1), true), (int)ERR_OK);
982     TestAddSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
983     sptr<NotificationRequest> req = new NotificationRequest();
984     EXPECT_NE(req, nullptr);
985     req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
986     req->SetLabel("req's label");
987     std::string label = "publish's label";
988     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
989     EXPECT_NE(normalContent, nullptr);
990     normalContent->SetText("normalContent's text");
991     normalContent->SetTitle("normalContent's title");
992     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
993     EXPECT_NE(content, nullptr);
994     req->SetContent(content);
995 
996     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE);
997     ASSERT_EQ(advancedNotificationService_->Publish(label, req), ERR_ANS_INVALID_UID);
998     SleepForFC();
999 
1000     req->SetCreatorUid(1);
1001     ASSERT_EQ(advancedNotificationService_->Publish(label, req), 0);
1002 }
1003 
1004 /*
1005  * @tc.name: AdvancedNotificationServiceTest_12400
1006  * @tc.desc: DLP App publish notification failed.
1007  * @tc.type: FUNC
1008  * @tc.require: I582TY
1009  */
1010 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12400, Function | SmallTest | Level1)
1011 {
1012     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
1013         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
1014     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
1015     MockIsSystemApp(true);
1016     sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
1017     EXPECT_NE(req, nullptr);
1018     req->SetSlotType(NotificationConstant::SlotType::OTHER);
1019     req->SetLabel("req's label");
1020     std::string label = "publish's label";
1021     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1022     EXPECT_NE(normalContent, nullptr);
1023     normalContent->SetText("normalContent's text");
1024     normalContent->SetTitle("normalContent's title");
1025     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1026     EXPECT_NE(content, nullptr);
1027     req->SetContent(content);
1028     EXPECT_NE(advancedNotificationService_->Publish(label, req), ERR_ANS_DLP_HAP);
1029     SleepForFC();
1030 
1031     ASSERT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK);
1032 }
1033 
1034 /*
1035  * @tc.name: AdvancedNotificationServiceTest_12500
1036  * @tc.desc: When the user removed event is received and the userid is less than or equal to 100,
1037  * the notification cannot be deleted
1038  * @tc.type: FUNC
1039  */
1040 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12500, Function | SmallTest | Level1)
1041 {
1042     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
1043         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
1044     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
1045     MockIsSystemApp(true);
1046     sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
1047     EXPECT_NE(req, nullptr);
1048     req->SetSlotType(NotificationConstant::SlotType::OTHER);
1049     req->SetLabel("req's label");
1050     std::string label = "publish's label";
1051     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1052     EXPECT_NE(normalContent, nullptr);
1053     normalContent->SetText("normalContent's text");
1054     normalContent->SetTitle("normalContent's title");
1055     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1056     EXPECT_NE(content, nullptr);
1057     req->SetContent(content);
1058     req->SetCreatorUserId(DEFAULT_USER_ID);
1059     ASSERT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK);
1060     SleepForFC();
1061 
1062     EventFwk::Want want;
1063     EventFwk::CommonEventData data;
1064     data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED));
1065     data.SetCode(DEFAULT_USER_ID);
1066     advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1067 
1068     ASSERT_EQ(advancedNotificationService_->IsNotificationExists(req->GetBaseKey("")), true);
1069 }
1070 
1071 
1072 /**
1073  * @tc.number    : AdvancedNotificationServiceTest_15500
1074  * @tc.name      : OnReceiveEvent_0100
1075  * @tc.desc      : Test OnReceiveEvent function userid<DEFAULT_USER_ID
1076  * @tc.require   : I5TIQR
1077  */
1078 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15500, Function | SmallTest | Level1)
1079 {
1080     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
1081     MockIsSystemApp(true);
1082 
1083     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
1084         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
1085     sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
1086     EXPECT_NE(req, nullptr);
1087     req->SetSlotType(NotificationConstant::SlotType::OTHER);
1088     req->SetLabel("req's label");
1089     std::string label = "publish's label";
1090     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1091     EXPECT_NE(normalContent, nullptr);
1092     normalContent->SetText("normalContent's text");
1093     normalContent->SetTitle("normalContent's title");
1094     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1095     EXPECT_NE(content, nullptr);
1096     req->SetContent(content);
1097     req->SetCreatorUserId(DEFAULT_USER_ID);
1098     ASSERT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK);
1099     SleepForFC();
1100 
1101     EventFwk::Want want;
1102     EventFwk::CommonEventData data;
1103     data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED));
1104     data.SetCode(50);
1105     advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1106 
1107     ASSERT_EQ(advancedNotificationService_->IsNotificationExists(req->GetBaseKey("")), true);
1108 }
1109 
1110 /**
1111  * @tc.number    : AdvancedNotificationServiceTest_15600
1112  * @tc.name      : OnReceiveEvent_0200
1113  * @tc.desc      : Test OnReceiveEvent function when userid>DEFAULT_USER_ID
1114  * @tc.require   : I5TIQR
1115  */
1116 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15600, Function | SmallTest | Level1)
1117 {
1118     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
1119     MockIsSystemApp(true);
1120 
1121     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
1122         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
1123     sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
1124     EXPECT_NE(req, nullptr);
1125     req->SetSlotType(NotificationConstant::SlotType::OTHER);
1126     req->SetLabel("req's label");
1127     std::string label = "publish's label";
1128     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1129     EXPECT_NE(normalContent, nullptr);
1130     normalContent->SetText("normalContent's text");
1131     normalContent->SetTitle("normalContent's title");
1132     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1133     EXPECT_NE(content, nullptr);
1134     req->SetContent(content);
1135     req->SetCreatorUserId(DEFAULT_USER_ID);
1136     ASSERT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK);
1137     SleepForFC();
1138 
1139     EventFwk::Want want;
1140     EventFwk::CommonEventData data;
1141     data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED));
1142     data.SetCode(200);
1143     advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1144 
1145     ASSERT_EQ(advancedNotificationService_->IsNotificationExists(req->GetBaseKey("")), true);
1146 }
1147 
1148 
1149 /**
1150  * @tc.number    : AdvancedNotificationServiceTest_16100
1151  * @tc.name      : PrepareNotificationInfo_1000
1152  * @tc.desc      : Test PrepareNotificationInfo function.
1153  * @tc.require   : #I60KYN
1154  */
1155 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16100, Function | SmallTest | Level1)
1156 {
1157     GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test start";
1158 
1159     sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
1160     EXPECT_NE(req, nullptr);
1161     req->SetSlotType(NotificationConstant::SlotType::OTHER);
1162     req->SetLabel("req's label");
1163     std::string label = "publish's label";
1164     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1165     EXPECT_NE(normalContent, nullptr);
1166     normalContent->SetText("normalContent's text");
1167     normalContent->SetTitle("normalContent's title");
1168     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1169     EXPECT_NE(content, nullptr);
1170     req->SetContent(content);
1171     req->SetCreatorUserId(DEFAULT_USER_ID);
1172     req->SetIsAgentNotification(true);
1173     advancedNotificationService_->Publish(label, req);
1174     SleepForFC();
1175 
1176     GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test end";
1177 }
1178 
1179 
1180 /**
1181  * @tc.number    : AdvancedNotificationServiceTest_17200
1182  * @tc.name      : ANS_DeleteAll_0100
1183  * @tc.desc      : Test DeleteAll function
1184  * @tc.require   : #I60KYN
1185  */
1186 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17200, Function | SmallTest | Level1)
1187 {
1188     GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start";
1189 
1190     TestAddSlot(NotificationConstant::SlotType::OTHER);
1191     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
1192     MockIsSystemApp(true);
1193 
1194     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
1195         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
1196     sptr<NotificationRequest> req = new NotificationRequest(1);
1197     EXPECT_NE(req, nullptr);
1198     req->SetSlotType(NotificationConstant::SlotType::OTHER);
1199     req->SetLabel("req's label");
1200     std::string label = "publish's label";
1201     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1202     EXPECT_NE(normalContent, nullptr);
1203     normalContent->SetText("normalContent's text");
1204     normalContent->SetTitle("normalContent's title");
1205     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1206     EXPECT_NE(content, nullptr);
1207     req->SetContent(content);
1208     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
1209     SleepForFC();
1210     req->SetCreatorUserId(SUBSCRIBE_USER_INIT);
1211     std::shared_ptr<Notification> notification = std::make_shared<Notification>(req);
1212 
1213     ASSERT_EQ(advancedNotificationService_->DeleteAll(), ERR_OK);
1214 
1215     GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end";
1216 }
1217 
1218 /**
1219  * @tc.number    : AdvancedNotificationServiceTest_04100
1220  * @tc.name      : ANS_GetSpecialActiveNotifications_0100
1221  * @tc.desc      : Test GetSpecialActiveNotifications function
1222  */
1223 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04100, Function | SmallTest | Level1)
1224 {
1225     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
1226         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
1227     TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1228     sptr<NotificationRequest> req = new NotificationRequest();
1229     EXPECT_NE(req, nullptr);
1230     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1231     req->SetLabel("req's label");
1232     req->SetCreatorUid(1);
1233     req->SetAlertOneTime(true);
1234     std::string label = "publish's label";
1235     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1236     EXPECT_NE(normalContent, nullptr);
1237     normalContent->SetText("normalContent's text");
1238     normalContent->SetTitle("normalContent's title");
1239     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1240     EXPECT_NE(content, nullptr);
1241     req->SetContent(content);
1242     ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
1243 
1244     std::vector<sptr<Notification>> allNotifications;
1245     ASSERT_EQ(advancedNotificationService_->GetAllActiveNotifications(allNotifications), (int)ERR_OK);
1246     ASSERT_EQ(allNotifications.size(), (size_t)1);
1247     std::vector<std::string> keys;
1248     for (auto notification : allNotifications) {
1249         keys.push_back(notification->GetKey());
1250     }
1251     std::vector<sptr<Notification>> specialActiveNotifications;
1252     ASSERT_EQ(
1253         advancedNotificationService_->GetSpecialActiveNotifications(keys, specialActiveNotifications), (int)ERR_OK);
1254     ASSERT_EQ(specialActiveNotifications.size(), (size_t)1);
1255     SleepForFC();
1256 }
1257 
1258 /**
1259  * @tc.number    : ANS_Publish_01500
1260  * @tc.name      : ANSPublish01500
1261  * @tc.desc      : publish a continuous task notification
1262  */
1263 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11000, Function | SmallTest | Level1)
1264 {
1265     sptr<NotificationRequest> req = new NotificationRequest();
1266     EXPECT_NE(req, nullptr);
1267     req->SetSlotType(NotificationConstant::SlotType::OTHER);
1268     req->SetLabel("req's label");
1269     ASSERT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_OK);
1270     SleepForFC();
1271 }
1272 
1273 /**
1274  * @tc.number    : ANS_Publish_01600
1275  * @tc.name      : ANSPublish01600
1276  * @tc.desc      : publish a continuous task notification
1277  */
1278 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11100, Function | SmallTest | Level1)
1279 {
1280     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
1281     MockIsSystemApp(true);
1282     sptr<NotificationRequest> req = new NotificationRequest();
1283     EXPECT_NE(req, nullptr);
1284     req->SetSlotType(NotificationConstant::SlotType::OTHER);
1285     req->SetLabel("req's label");
1286     ASSERT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_ANS_NOT_SYSTEM_SERVICE);
1287     SleepForFC();
1288 }
1289 
1290 /**
1291  * @tc.number    : AdvancedNotificationServiceTest_11200
1292  * @tc.name      : ANS_Cancel_0300
1293  * @tc.desc      : public two notification to cancel one of them
1294  */
1295 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11200, Function | SmallTest | Level1)
1296 {
1297     std::string label = "testLabel";
1298     {
1299         sptr<NotificationRequest> req = new NotificationRequest(1);
1300         req->SetSlotType(NotificationConstant::OTHER);
1301         req->SetLabel(label);
1302         ASSERT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_OK);
1303     }
1304     ASSERT_EQ(advancedNotificationService_->CancelContinuousTaskNotification(label, 1), (int)ERR_OK);
1305 }
1306 
1307 /**
1308  * @tc.number    : AdvancedNotificationServiceTest_11300
1309  * @tc.name      : ANS_Cancel_0400
1310  * @tc.desc      : public two notification to cancel one of them
1311  */
1312 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11300, Function | SmallTest | Level1)
1313 {
1314     std::string label = "testLabel";
1315     {
1316         sptr<NotificationRequest> req = new NotificationRequest(1);
1317         req->SetSlotType(NotificationConstant::OTHER);
1318         req->SetLabel(label);
1319         ASSERT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_OK);
1320     }
1321     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
1322     MockIsSystemApp(true);
1323     ASSERT_EQ(
1324         advancedNotificationService_->CancelContinuousTaskNotification(label, 1), (int)ERR_ANS_NOT_SYSTEM_SERVICE);
1325 }
1326 
1327 /**
1328  * @tc.number    : AdvancedNotificationServiceTest_12600
1329  * @tc.name      : ANS_CancelAsBundle_0100
1330  * @tc.desc      : Test CancelAsBundle function when the result is ERR_ANS_NOTIFICATION_NOT_EXISTS
1331  * @tc.require   : issueI5S4VP
1332  */
1333 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12600, Function | SmallTest | Level1)
1334 {
1335     TestAddSlot(NotificationConstant::SlotType::OTHER);
1336     int32_t notificationId = 1;
1337     std::string representativeBundle = "RepresentativeBundle";
1338     int32_t userId = 1;
1339     int result = ERR_ANS_NOTIFICATION_NOT_EXISTS;
1340     ASSERT_EQ(advancedNotificationService_->CancelAsBundle(notificationId, representativeBundle, userId), result);
1341 }
1342 
1343 /**
1344  * @tc.number    : AdvancedNotificationServiceTest_12700
1345  * @tc.name      : ANS_CanPublishAsBundle_0100
1346  * @tc.desc      : Test CanPublishAsBundle function when the result is ERR_INVALID_OPERATION
1347  * @tc.require   : issueI5S4VP
1348  */
1349 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12700, Function | SmallTest | Level1)
1350 {
1351     std::string representativeBundle = "RepresentativeBundle";
1352     bool canPublish = true;
1353     int result = ERR_INVALID_OPERATION;
1354     ASSERT_EQ(advancedNotificationService_->CanPublishAsBundle(representativeBundle, canPublish), result);
1355 }
1356 
1357 /**
1358  * @tc.number    : AdvancedNotificationServiceTest_12800
1359  * @tc.name      : ANS_PublishAsBundle_0100
1360  * @tc.desc      : Test PublishAsBundle function when the result is ERR_INVALID_OPERATION
1361  * @tc.require   : issueI5S4VP
1362  */
1363 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12800, Function | SmallTest | Level1)
1364 {
1365     sptr<NotificationRequest> notification = nullptr;
1366     std::string representativeBundle = "RepresentativeBundle";
1367     int result = ERR_INVALID_OPERATION;
1368     ASSERT_EQ(advancedNotificationService_->PublishAsBundle(notification, representativeBundle), result);
1369 }
1370 
1371 /**
1372  * @tc.number    : AdvancedNotificationServiceTest_21500
1373  * @tc.name      : PublishPreparedNotification_1000
1374  * @tc.desc      : Test PublishPreparedNotification function.
1375  * @tc.require   : issueI62D8C
1376  */
1377 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21500, Function | SmallTest | Level1)
1378 {
1379     GTEST_LOG_(INFO) << "PublishPreparedNotification_1000 test start";
1380 
1381     sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest();
1382     sptr<Notification> notification = new (std::nothrow) Notification(req);
1383     EXPECT_NE(notification, nullptr);
1384     sptr<NotificationBundleOption> bundleOption = nullptr;
1385 
1386     ASSERT_EQ(advancedNotificationService_->PublishPreparedNotification(req, bundleOption), ERR_ANS_INVALID_PARAM);
1387 
1388     GTEST_LOG_(INFO) << "PublishPreparedNotification_1000 test end";
1389 }
1390 
1391 /**
1392  * @tc.number    : AdvancedNotificationServiceTest_19000
1393  * @tc.name      : ANS_Publish_With_PixelMap
1394  * @tc.desc      : Publish a notification with pixelMap.
1395  */
1396 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19000, Function | SmallTest | Level1)
1397 {
1398     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(std::string(),
1399         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), true), (int)ERR_OK);
1400     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
1401     MockIsSystemApp(true);
1402     sptr<NotificationRequest> req = new NotificationRequest(1);
1403     EXPECT_NE(req, nullptr);
1404     req->SetSlotType(NotificationConstant::SlotType::OTHER);
1405     req->SetLabel("label");
1406     std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
1407     EXPECT_NE(pictureContent, nullptr);
1408     pictureContent->SetText("notification text");
1409     pictureContent->SetTitle("notification title");
1410     pictureContent->SetBigPicture(nullptr);
1411     EXPECT_EQ(nullptr, pictureContent->GetBigPicture());
1412     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(pictureContent);
1413     EXPECT_NE(content, nullptr);
1414     req->SetContent(content);
1415 
1416     req->SetLittleIcon(nullptr);
1417     EXPECT_EQ(nullptr, req->GetLittleIcon());
1418     req->SetBigIcon(nullptr);
1419     EXPECT_EQ(nullptr, req->GetBigIcon());
1420     req->SetOverlayIcon(nullptr);
1421     EXPECT_EQ(nullptr, req->GetOverlayIcon());
1422     ASSERT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK);
1423 }
1424 
1425 /**
1426  * @tc.number    : OnReceiveEvent_0200
1427  * @tc.name      : OnReceiveEvent_0200
1428  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED
1429  * @tc.require   : I5TIQR
1430  */
1431 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_0200, Function | SmallTest | Level1)
1432 {
1433     advancedNotificationService_->notificationList_.clear();
1434     int notificationId = 1;
1435     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
1436     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
1437     request->SetNotificationId(notificationId);
1438     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
1439     advancedNotificationService_->AssignToNotificationList(record);
1440 
1441     EventFwk::Want want;
1442     EventFwk::CommonEventData data;
1443     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED)
1444         .SetElementName("test", "")
1445         .SetParam(AppExecFwk::Constants::UID, 1);
1446     data.SetWant(want);
1447     data.SetCode(200);
1448     advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1449     SleepForFC();
1450     ASSERT_EQ(advancedNotificationService_->IsNotificationExists(request->GetBaseKey("")), false);
1451 }
1452 
1453 /**
1454  * @tc.number    : OnReceiveEvent_0300
1455  * @tc.name      : OnReceiveEvent_0300
1456  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED
1457  * @tc.require   : I5TIQR
1458  */
1459 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_0300, Function | SmallTest | Level1)
1460 {
1461     advancedNotificationService_->notificationList_.clear();
1462     int notificationId = 1;
1463     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
1464     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
1465     request->SetNotificationId(notificationId);
1466     request->SetReceiverUserId(SUBSCRIBE_USER_INIT);
1467     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
1468     advancedNotificationService_->AssignToNotificationList(record);
1469 
1470     EventFwk::Want want;
1471     EventFwk::CommonEventData data;
1472     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED);
1473     data.SetWant(want);
1474     data.SetCode(SUBSCRIBE_USER_INIT);
1475     advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1476     ASSERT_EQ(advancedNotificationService_->IsNotificationExists(request->GetBaseKey("")), true);
1477 }
1478 
1479 /**
1480  * @tc.number    : OnReceiveEvent_0400
1481  * @tc.name      : OnReceiveEvent_0400
1482  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED
1483  * @tc.require   : I5TIQR
1484  */
1485 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_0400, Function | SmallTest | Level1)
1486 {
1487     advancedNotificationService_->notificationList_.clear();
1488     sptr<NotificationRequest> request = new NotificationRequest(1);
1489     request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
1490     std::shared_ptr<NotificationLiveViewContent> liveViewContent = std::make_shared<NotificationLiveViewContent>();
1491     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(liveViewContent);
1492     liveViewContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_END);
1493     request->SetContent(content);
1494     request->SetCreatorUid(1);
1495     request->SetCreatorUserId(0);
1496     request->SetLabel("test1");
1497 
1498     std::string bundleName = "test";
1499     int32_t uid = 0;
1500     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(bundleName, uid);
1501     AdvancedNotificationService::NotificationRequestDb requestDbObj =
1502         { .request = request, .bundleOption = bundleOption };
1503     auto result = advancedNotificationService_->SetNotificationRequestToDb(requestDbObj);
1504     ASSERT_EQ(result, ERR_OK);
1505 
1506     EventFwk::Want want;
1507     EventFwk::CommonEventData data;
1508     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
1509     data.SetWant(want);
1510     data.SetCode(0);
1511     advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1512     SleepForFC();
1513     ASSERT_EQ(advancedNotificationService_->notificationList_.size(), 0);
1514 }
1515 
1516 /**
1517  * @tc.number    : OnReceiveEvent_0500
1518  * @tc.name      : OnReceiveEvent_0500
1519  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED
1520  * @tc.require   : I5TIQR
1521  */
1522 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_0500, Function | SmallTest | Level1)
1523 {
1524     int notificationId = 1;
1525     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
1526     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
1527     request->SetNotificationId(notificationId);
1528     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
1529 
1530     advancedNotificationService_->AssignToNotificationList(record);
1531 
1532     EventFwk::Want want;
1533     EventFwk::CommonEventData data;
1534     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED)
1535         .SetElementName("test", "")
1536         .SetParam("ohos.aafwk.param.targetUid", 1);
1537     data.SetWant(want);
1538     data.SetCode(0);
1539     advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1540 
1541     SleepForFC();
1542     ASSERT_EQ(advancedNotificationService_->notificationList_.size(), 0);
1543 }
1544 
1545 /**
1546  * @tc.number    : OnReceiveEvent_0600
1547  * @tc.name      : OnReceiveEvent_0600
1548  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED
1549  * @tc.require   : I5TIQR
1550  */
1551 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_0600, Function | SmallTest | Level1)
1552 {
1553     MockSetBundleInfoEnabled(true);
1554     EventFwk::Want want;
1555     EventFwk::CommonEventData data;
1556     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED)
1557         .SetElementName("test", "")
1558         .SetParam("uid", 1);
1559     data.SetWant(want);
1560     data.SetCode(0);
1561     advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1562 
1563     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
1564     SleepForFC();
1565     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
1566     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
1567     ASSERT_EQ(static_cast<int32_t>(state), 3);
1568 }
1569 
1570 /**
1571  * @tc.number    : OnReceiveEvent_0700
1572  * @tc.name      : OnReceiveEvent_0700
1573  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED
1574  * @tc.require   : I5TIQR
1575  */
1576 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_0700, Function | SmallTest | Level1)
1577 {
1578     MockSetBundleInfoEnabled(true);
1579     EventFwk::Want want;
1580     EventFwk::CommonEventData data;
1581     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED)
1582         .SetElementName("test", "")
1583         .SetParam("uid", 1);
1584     data.SetWant(want);
1585     data.SetCode(0);
1586     advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1587 
1588     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
1589     SleepForFC();
1590     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
1591     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
1592     ASSERT_EQ(static_cast<int32_t>(state), 3);
1593 }
1594 
1595 /**
1596  * @tc.number    : OnReceiveEvent_0800
1597  * @tc.name      : OnReceiveEvent_0800
1598  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED
1599  * @tc.require   : I5TIQR
1600  */
1601 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_0800, Function | SmallTest | Level1)
1602 {
1603     MockSetBundleInfoEnabled(true);
1604     EventFwk::Want want;
1605     EventFwk::CommonEventData data;
1606     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
1607     data.SetWant(want);
1608     data.SetCode(0);
1609     advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1610 
1611     SleepForFC();
1612     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
1613     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
1614     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
1615     ASSERT_EQ(static_cast<int32_t>(state), 3);
1616 }
1617 
1618 /**
1619  * @tc.number    : OnReceiveEvent_0900
1620  * @tc.name      : OnReceiveEvent_0900
1621  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED
1622  * @tc.require   : I5TIQR
1623  */
1624 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_0900, Function | SmallTest | Level1)
1625 {
1626     AdvancedNotificationService advancedNotificationService;
1627     MockSetBundleInfoEnabled(true);
1628     EventFwk::Want want;
1629     EventFwk::CommonEventData data;
1630     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
1631     data.SetWant(want);
1632     data.SetCode(0);
1633     advancedNotificationService.systemEventObserver_->callbacks_.onBootSystemCompleted = nullptr;
1634     advancedNotificationService.systemEventObserver_->OnReceiveEvent(data);
1635 
1636     SleepForFC();
1637     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
1638     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
1639     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
1640     ASSERT_EQ(static_cast<int32_t>(state), 0);
1641 }
1642 
1643 /**
1644  * @tc.number    : OnReceiveEvent_1000
1645  * @tc.name      : OnReceiveEvent_1000
1646  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED
1647  * @tc.require   : I5TIQR
1648  */
1649 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_1000, Function | SmallTest | Level1)
1650 {
1651     AdvancedNotificationService advancedNotificationService;
1652     MockSetBundleInfoEnabled(true);
1653     EventFwk::Want want;
1654     EventFwk::CommonEventData data;
1655     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED)
1656         .SetElementName("test", "")
1657         .SetParam("uid", 1);
1658     data.SetWant(want);
1659     data.SetCode(0);
1660     advancedNotificationService.systemEventObserver_->callbacks_.onBundleAdd = nullptr;
1661     advancedNotificationService.systemEventObserver_->OnReceiveEvent(data);
1662 
1663     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
1664     SleepForFC();
1665     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
1666     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
1667     ASSERT_EQ(static_cast<int32_t>(state), 0);
1668 }
1669 
1670 /**
1671  * @tc.number    : OnReceiveEvent_1100
1672  * @tc.name      : OnReceiveEvent_1100
1673  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_PACKAGE_CHANGED
1674  * @tc.require   : I5TIQR
1675  */
1676 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_1100, Function | SmallTest | Level1)
1677 {
1678     AdvancedNotificationService advancedNotificationService;
1679     MockSetBundleInfoEnabled(true);
1680     EventFwk::Want want;
1681     EventFwk::CommonEventData data;
1682     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED)
1683         .SetElementName("test", "")
1684         .SetParam("uid", 1);
1685     data.SetWant(want);
1686     data.SetCode(0);
1687     advancedNotificationService.systemEventObserver_->callbacks_.onBundleUpdate = nullptr;
1688     advancedNotificationService.systemEventObserver_->OnReceiveEvent(data);
1689 
1690     sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1);
1691     SleepForFC();
1692     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
1693     NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, state);
1694     ASSERT_EQ(static_cast<int32_t>(state), 0);
1695 }
1696 
1697 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1698 /**
1699  * @tc.number    : OnReceiveEvent_1200
1700  * @tc.name      : OnReceiveEvent_1200
1701  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_SCREEN
1702  * @tc.require   : I5TIQR
1703  */
1704 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_1200, Function | SmallTest | Level1)
1705 {
1706     AdvancedNotificationService advancedNotificationService;
1707     MockSetBundleInfoEnabled(true);
1708     EventFwk::Want want;
1709     EventFwk::CommonEventData data;
1710     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON);
1711     data.SetWant(want);
1712     data.SetCode(0);
1713     advancedNotificationService.systemEventObserver_->OnReceiveEvent(data);
1714     ASSERT_EQ(advancedNotificationService.localScreenOn_, true);
1715 }
1716 
1717 /**
1718  * @tc.number    : OnReceiveEvent_1300
1719  * @tc.name      : OnReceiveEvent_1300
1720  * @tc.desc      : Test OnReceiveEvent COMMON_EVENT_SCREEN
1721  * @tc.require   : I5TIQR
1722  */
1723 HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_1300, Function | SmallTest | Level1)
1724 {
1725     AdvancedNotificationService advancedNotificationService;
1726     MockSetBundleInfoEnabled(true);
1727     EventFwk::Want want;
1728     EventFwk::CommonEventData data;
1729     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
1730     data.SetWant(want);
1731     data.SetCode(0);
1732     advancedNotificationService.systemEventObserver_->OnReceiveEvent(data);
1733     ASSERT_EQ(advancedNotificationService.localScreenOn_, false);
1734 }
1735 #endif
1736 
1737 /**
1738  * @tc.number    : CheckNotificationRequest_0100
1739  * @tc.name      : CheckNotificationRequest_0100
1740  * @tc.desc      : Test CheckNotificationRequest method when request is null
1741  * @tc.require   : I5TIQR
1742  */
HWTEST_F(AdvancedNotificationServiceTest,CheckNotificationRequest_0100,Level1)1743 HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0100, Level1)
1744 {
1745     AdvancedNotificationService advancedNotificationService;
1746 
1747     ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(nullptr), ERR_ANS_INVALID_PARAM);
1748 }
1749 
1750 /**
1751  * @tc.number    : CheckNotificationRequest_0200
1752  * @tc.name      : CheckNotificationRequest_0200
1753  * @tc.desc      : Test CheckNotificationRequest method when request has no wantAgent
1754  * @tc.require   : I5TIQR
1755  */
HWTEST_F(AdvancedNotificationServiceTest,CheckNotificationRequest_0200,Level1)1756 HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0200, Level1)
1757 {
1758     AdvancedNotificationService advancedNotificationService;
1759     auto request = new NotificationRequest();
1760 
1761     ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(request), ERR_OK);
1762 }
1763 
1764 /**
1765  * @tc.number    : CheckNotificationRequest_0300
1766  * @tc.name      : CheckNotificationRequest_0300
1767  * @tc.desc      : Test CheckNotificationRequest method when request has no wantAgent
1768  * @tc.require   : I5TIQR
1769  */
HWTEST_F(AdvancedNotificationServiceTest,CheckNotificationRequest_0300,Level1)1770 HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0300, Level1)
1771 {
1772     AdvancedNotificationService advancedNotificationService;
1773     auto request = new NotificationRequest();
1774     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
1775     std::shared_ptr<AbilityRuntime::WantAgent::LocalPendingWant> localPendingWant =
1776         std::make_shared<AbilityRuntime::WantAgent::LocalPendingWant>("TestBundleName", want, 0);
1777     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
1778         std::make_shared<AbilityRuntime::WantAgent::WantAgent>(localPendingWant);
1779     request->SetWantAgent(wantAgent);
1780     MockSystemApp();
1781 
1782     ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(request), ERR_OK);
1783 }
1784 
1785 /**
1786  * @tc.number    : CheckNotificationRequest_0300
1787  * @tc.name      : CheckNotificationRequest_0300
1788  * @tc.desc      : Test CheckNotificationRequest method when request has no wantAgent
1789  * @tc.require   : I5TIQR
1790  */
HWTEST_F(AdvancedNotificationServiceTest,CheckNotificationRequest_0400,Level1)1791 HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0400, Level1)
1792 {
1793     AdvancedNotificationService advancedNotificationService;
1794     auto request = new NotificationRequest();
1795     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
1796     std::shared_ptr<AbilityRuntime::WantAgent::LocalPendingWant> localPendingWant =
1797         std::make_shared<AbilityRuntime::WantAgent::LocalPendingWant>("TestBundleName", want, 0);
1798     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
1799         std::make_shared<AbilityRuntime::WantAgent::WantAgent>(localPendingWant);
1800     request->SetRemovalWantAgent(wantAgent);
1801     MockSystemApp();
1802 
1803     ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(request), ERR_OK);
1804 }
1805 
1806 /**
1807  * @tc.number    : CheckNotificationRequest_0300
1808  * @tc.name      : CheckNotificationRequest_0300
1809  * @tc.desc      : Test CheckNotificationRequest method when request has no wantAgent
1810  * @tc.require   : I5TIQR
1811  */
HWTEST_F(AdvancedNotificationServiceTest,CheckNotificationRequest_0500,Level1)1812 HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0500, Level1)
1813 {
1814     AdvancedNotificationService advancedNotificationService;
1815     auto request = new NotificationRequest();
1816     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
1817     std::shared_ptr<AbilityRuntime::WantAgent::LocalPendingWant> localPendingWant =
1818         std::make_shared<AbilityRuntime::WantAgent::LocalPendingWant>("TestBundleName", want, 0);
1819     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
1820         std::make_shared<AbilityRuntime::WantAgent::WantAgent>(localPendingWant);
1821     request->SetRemovalWantAgent(wantAgent);
1822     MockIsSystemApp(false);
1823 
1824     ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(request), ERR_OK);
1825 }
1826 
1827 /**
1828  * @tc.number    : CheckNotificationRequest_0600
1829  * @tc.name      : CheckNotificationRequest_0600
1830  * @tc.desc      : Test CheckNotificationRequest method when request has linesWantAgent
1831  * @tc.require   : I5TIQR
1832  */
HWTEST_F(AdvancedNotificationServiceTest,CheckNotificationRequest_0600,Level1)1833 HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0600, Level1)
1834 {
1835     AdvancedNotificationService advancedNotificationService;
1836     auto request = new NotificationRequest();
1837     const std::shared_ptr<NotificationMultiLineContent> multiLineContent =
1838         std::make_shared<NotificationMultiLineContent>();
1839     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
1840     std::shared_ptr<AbilityRuntime::WantAgent::LocalPendingWant> localPendingWant =
1841         std::make_shared<AbilityRuntime::WantAgent::LocalPendingWant>("TestBundleName", want, 0);
1842     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
1843         std::make_shared<AbilityRuntime::WantAgent::WantAgent>(localPendingWant);
1844     std::vector<std::shared_ptr<AbilityRuntime::WantAgent::WantAgent>> lineWantAgents;
1845     lineWantAgents.emplace_back(wantAgent);
1846     lineWantAgents.emplace_back(wantAgent);
1847     lineWantAgents.emplace_back(wantAgent);
1848     multiLineContent->AddSingleLine("test1");
1849     multiLineContent->AddSingleLine("test2");
1850     multiLineContent->AddSingleLine("test3");
1851     multiLineContent->SetLineWantAgents(lineWantAgents);
1852     const std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(multiLineContent);
1853     request->SetContent(content);
1854     MockSystemApp();
1855 
1856     ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(request), ERR_OK);
1857 }
1858 
1859 /**
1860  * @tc.number    : CheckNotificationRequestLineWantAgents_0100
1861  * @tc.name      : CheckNotificationRequestLineWantAgents_0100
1862  * @tc.desc      : Test CheckNotificationRequestLineWantAgents method when request has local wantAgent
1863  * @tc.require   : I5TIQR
1864  */
HWTEST_F(AdvancedNotificationServiceTest,CheckNotificationRequestLineWantAgents_0100,Level1)1865 HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequestLineWantAgents_0100, Level1)
1866 {
1867     AdvancedNotificationService advancedNotificationService;
1868     const std::shared_ptr<NotificationMultiLineContent> multiLineContent =
1869         std::make_shared<NotificationMultiLineContent>();
1870     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
1871     std::shared_ptr<AbilityRuntime::WantAgent::LocalPendingWant> localPendingWant =
1872         std::make_shared<AbilityRuntime::WantAgent::LocalPendingWant>("TestBundleName", want, 0);
1873     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
1874         std::make_shared<AbilityRuntime::WantAgent::WantAgent>(localPendingWant);
1875     std::vector<std::shared_ptr<AbilityRuntime::WantAgent::WantAgent>> lineWantAgents;
1876     lineWantAgents.emplace_back(wantAgent);
1877     lineWantAgents.emplace_back(wantAgent);
1878     lineWantAgents.emplace_back(wantAgent);
1879     multiLineContent->AddSingleLine("test1");
1880     multiLineContent->AddSingleLine("test2");
1881     multiLineContent->AddSingleLine("test3");
1882     multiLineContent->SetLineWantAgents(lineWantAgents);
1883     const std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(multiLineContent);
1884     MockIsSystemApp(false);
1885 
1886     ASSERT_EQ(advancedNotificationService.CheckNotificationRequestLineWantAgents(content, true, true), ERR_OK);
1887 }
1888 }  // namespace Notification
1889 }  // namespace OHOS
1890