• 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 #include <gtest/gtest.h>
16 #include <functional>
17 
18 #include "ans_inner_errors.h"
19 #include "ans_manager_proxy.h"
20 #include "notification_local_live_view_content.h"
21 #include "notification_local_live_view_subscriber.h"
22 #define private public
23 #include "advanced_notification_service.h"
24 #undef private
25 #include "datetime_ex.h"
26 #include "if_system_ability_manager.h"
27 #include "int_wrapper.h"
28 #include "iservice_registry.h"
29 #include "notification_helper.h"
30 #include "notification_json_convert.h"
31 #include "remote_native_token.h"
32 #include "system_ability_definition.h"
33 #include "want_agent_info.h"
34 #include "want_agent_helper.h"
35 #include "want_params.h"
36 #include "accesstoken_kit.h"
37 
38 using namespace testing::ext;
39 using namespace OHOS::Security::AccessToken;
40 namespace OHOS {
41 namespace Notification {
42 extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet);
43 
44 static sptr<ISystemAbilityManager> systemAbilityManager =
45     SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
46 bool g_onConsumedReceived = false;
47 bool g_onCanceledReceived = false;
48 bool g_onWantReceived = false;
49 bool g_onBadgeNumberReceived = false;
50 const int32_t SLEEP_TIME = 1;
51 const uint64_t ACTIVE_NUMS = 2;
52 const int32_t CASE_ONE = 1;
53 const int32_t CASE_TWO = 2;
54 const int32_t CASE_THREE = 3;
55 const int32_t CASE_FOUR = 4;
56 const int32_t CASE_FIVE = 5;
57 const int32_t CASE_SIX = 6;
58 const int32_t CASE_SEVEN = 7;
59 const int32_t CASE_EIGHT = 8;
60 const int32_t CASE_NINE = 9;
61 const int32_t CASE_TEN = 10;
62 const int32_t CASE_ELEVEN = 11;
63 const int32_t CASE_TWELVE = 12;
64 const int32_t CASE_THIRTEEN = 13;
65 const int32_t CASE_FOURTEEN = 14;
66 const int32_t CASE_FIFTEEN = 15;
67 const int32_t CASE_SIXTEEN = 16;
68 const int32_t CASE_SEVENTEEN = 17;
69 const int32_t CASE_EIGHTEEN = 18;
70 const int32_t CASE_NINETEEN = 19;
71 const int32_t CASE_TWENTY = 20;
72 const int32_t CASE_TWENTY_ONE = 21;
73 
74 const int32_t PIXEL_MAP_TEST_WIDTH = 32;
75 const int32_t PIXEL_MAP_TEST_HEIGHT = 32;
76 
77 const int32_t CANCELGROUP_NID = 10101;
78 const int32_t BADGE_NUMBER = 100;
79 
80 ffrt::mutex g_subscribe_mtx;
81 ffrt::mutex g_consumed_mtx;
82 ffrt::mutex g_unsubscribe_mtx;
83 ffrt::mutex g_send_finished_mtx;
84 AAFwk::Want g_want;
85 
86 ffrt::mutex g_system_live_view_subscribe_mtx;
87 ffrt::mutex g_system_live_view_subscribe_response_mtx;
88 std::string g_onResponseReceivedButtonName {"testButton"};
89 int32_t g_onResponseReceivedId = -1;
90 
91 const time_t TIME_OUT_SECONDS_LIMIT = 5;
92 const std::string CLASSIFICATION_ALARM {"alarm"};
93 
94 class TestLocalLiveViewSubscriber : public NotificationLocalLiveViewSubscriber {
OnConnected()95     void OnConnected()
96     {}
97 
OnDisconnected()98     void OnDisconnected()
99     {}
100 
OnResponse(int32_t notificationId,sptr<NotificationButtonOption> buttonOption)101     void OnResponse(int32_t notificationId, sptr<NotificationButtonOption> buttonOption)
102     {
103         GTEST_LOG_(INFO) << "OnResponse notificationId : " << notificationId;
104         g_onResponseReceivedId = notificationId;
105         g_onResponseReceivedButtonName = buttonOption->GetButtonName();
106         g_system_live_view_subscribe_response_mtx.unlock();
107     }
108 
OnDied()109     void OnDied()
110     {}
111 };
112 
113 class TestAnsSubscriber : public NotificationSubscriber {
114 public:
OnConnected()115     void OnConnected() override
116     {
117         g_subscribe_mtx.unlock();
118     }
119 
OnDisconnected()120     void OnDisconnected() override
121     {
122         g_unsubscribe_mtx.unlock();
123     }
124 
OnDied()125     void OnDied() override
126     {}
127 
OnEnabledNotificationChanged(const std::shared_ptr<EnabledNotificationCallbackData> & callbackData)128     void OnEnabledNotificationChanged(
129         const std::shared_ptr<EnabledNotificationCallbackData> &callbackData) override
130     {}
131 
OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> & date)132     void OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> &date) override
133     {}
134 
OnUpdate(const std::shared_ptr<NotificationSortingMap> & sortingMap)135     void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) override
136     {}
137 
OnCanceled(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap,int deleteReason)138     void OnCanceled(const std::shared_ptr<Notification> &request,
139         const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) override
140     {
141         g_onCanceledReceived = true;
142     }
143 
OnConsumed(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap)144     void OnConsumed(const std::shared_ptr<Notification> &request,
145         const std::shared_ptr<NotificationSortingMap> &sortingMap) override
146     {
147         g_onConsumedReceived = true;
148         g_consumed_mtx.unlock();
149         NotificationRequest notificationRequest = request->GetNotificationRequest();
150         GTEST_LOG_(INFO) << "OnConsumed notificationId : " << notificationRequest.GetNotificationId();
151         if (CASE_ONE == notificationRequest.GetNotificationId()) {
152             CheckCaseOneResult(notificationRequest);
153         } else if (CASE_TWO == notificationRequest.GetNotificationId()) {
154             CheckCaseTwoResult(notificationRequest);
155         } else if (CASE_THREE == notificationRequest.GetNotificationId()) {
156             CheckCaseThreeResult(notificationRequest);
157         } else if (CASE_FOUR == notificationRequest.GetNotificationId()) {
158             CheckCaseFourResult(notificationRequest);
159         } else if (CASE_FIVE == notificationRequest.GetNotificationId()) {
160             CheckCaseFiveResult(notificationRequest);
161         } else if (CASE_SIX == notificationRequest.GetNotificationId()) {
162             CheckCaseSixResult(notificationRequest);
163         } else if (CASE_SEVEN == notificationRequest.GetNotificationId()) {
164             CheckCaseSevenResult(notificationRequest);
165         } else if (CASE_EIGHT == notificationRequest.GetNotificationId()) {
166             CheckCaseEightResult(notificationRequest);
167         } else if (CASE_NINE == notificationRequest.GetNotificationId()) {
168             CheckCaseNineResult(notificationRequest);
169         } else if (CASE_TEN == notificationRequest.GetNotificationId()) {
170             EXPECT_EQ(NotificationConstant::SERVICE_REMINDER, notificationRequest.GetSlotType());
171         } else if (CASE_ELEVEN == notificationRequest.GetNotificationId()) {
172             EXPECT_EQ(NotificationConstant::SOCIAL_COMMUNICATION, notificationRequest.GetSlotType());
173         } else if (CASE_TWELVE == notificationRequest.GetNotificationId()) {
174             EXPECT_EQ(NotificationConstant::CUSTOM, notificationRequest.GetSlotType());
175         } else if (CASE_THIRTEEN == notificationRequest.GetNotificationId()) {
176             EXPECT_EQ(NotificationRequest::GroupAlertType::ALL, notificationRequest.GetGroupAlertType());
177             EXPECT_EQ(true, notificationRequest.IsGroupOverview());
178         } else if (CASE_FOURTEEN == notificationRequest.GetNotificationId()) {
179             CheckCaseFourteenResult(notificationRequest);
180         } else if (CASE_FIFTEEN == notificationRequest.GetNotificationId()) {
181             CheckCaseFifteenResult(notificationRequest);
182         } else if (CASE_SIXTEEN == notificationRequest.GetNotificationId()) {
183             CheckCaseSixteenResult(notificationRequest);
184         } else if (CASE_SEVENTEEN == notificationRequest.GetNotificationId()) {
185             CheckCaseSeventeenResult(notificationRequest);
186         } else if (CASE_TWENTY_ONE == notificationRequest.GetNotificationId()) {
187             CheckCaseTwentyOneResult(notificationRequest);
188         } else {
189             GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish::OnConsumed do nothing!!!!!";
190         }
191     }
192 
OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> & badgeData)193     void OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> &badgeData) override
194     {
195         GTEST_LOG_(INFO) << "ANS_Interface_MT::OnBadgeChanged badgeData : " << badgeData->Dump();
196         g_onBadgeNumberReceived = true;
197         EXPECT_EQ(badgeData->GetBadgeNumber(), BADGE_NUMBER);
198     }
199 
OnBadgeEnabledChanged(const sptr<EnabledNotificationCallbackData> & callbackData)200     void OnBadgeEnabledChanged(
201         const sptr<EnabledNotificationCallbackData> &callbackData) override
202     {}
203 
OnBatchCanceled(const std::vector<std::shared_ptr<Notification>> & requestList,const std::shared_ptr<NotificationSortingMap> & sortingMap,int32_t deleteReason)204     void OnBatchCanceled(const std::vector<std::shared_ptr<Notification>>
205         &requestList, const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) override
206     {}
207 
208 private:
CheckCaseOneResult(NotificationRequest notificationRequest)209     void CheckCaseOneResult(NotificationRequest notificationRequest)
210     {
211         std::shared_ptr<NotificationContent> notificationContent = notificationRequest.GetContent();
212         if (notificationContent != nullptr) {
213             EXPECT_EQ(NotificationContent::Type::MEDIA, notificationContent->GetContentType());
214             std::shared_ptr<NotificationMediaContent> notificationMediaContent =
215                 std::static_pointer_cast<NotificationMediaContent>(notificationContent->GetNotificationContent());
216             if (notificationMediaContent != nullptr) {
217                 EXPECT_EQ(nullptr, notificationMediaContent->GetAVToken());
218                 for (auto it : notificationMediaContent->GetShownActions()) {
219                     EXPECT_EQ((uint32_t)0, it);
220                 }
221             }
222         }
223         EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType());
224         for (auto str : notificationRequest.GetNotificationUserInputHistory()) {
225             EXPECT_EQ("style", str);
226         }
227         EXPECT_EQ("bundleName", notificationRequest.GetOwnerBundleName());
228         EXPECT_EQ("bundleName", notificationRequest.GetCreatorBundleName());
229         EXPECT_EQ("ANS_Interface_MT_Publish_00100", notificationRequest.GetLabel());
230 
231         // pixelmap
232         auto littleIcon = notificationRequest.GetLittleIcon();
233         Media::ImageInfo outImageInfo;
234         littleIcon->GetImageInfo(outImageInfo);
235         GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100 :: littleIcon :: width : " << outImageInfo.size.width;
236         GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100 :: littleIcon :: height : " << outImageInfo.size.height;
237 
238         EXPECT_EQ(outImageInfo.size.width, PIXEL_MAP_TEST_WIDTH);
239         EXPECT_EQ(outImageInfo.size.height, PIXEL_MAP_TEST_HEIGHT);
240         EXPECT_EQ(outImageInfo.pixelFormat, Media::PixelFormat::ALPHA_8);
241         EXPECT_EQ(outImageInfo.colorSpace, Media::ColorSpace::SRGB);
242 
243         EXPECT_NE(nullptr, notificationRequest.GetBigIcon());
244         EXPECT_NE(nullptr, notificationRequest.GetLittleIcon());
245         EXPECT_NE(nullptr, notificationRequest.GetOverlayIcon());
246         std::vector<std::shared_ptr<MessageUser>> messageUser = notificationRequest.GetMessageUsers();
247         for (auto user : messageUser) {
248             if (user != nullptr) {
249                 EXPECT_EQ("ANS_Interface_MT_Publish_00100_Message_User", user->GetName());
250                 EXPECT_EQ("key", user->GetKey());
251                 EXPECT_EQ(nullptr, user->GetPixelMap());
252                 EXPECT_EQ(Uri("."), user->GetUri());
253                 EXPECT_EQ(false, user->IsMachine());
254                 EXPECT_EQ(false, user->IsUserImportant());
255             }
256         }
257     }
258 
CheckCaseTwoResult(NotificationRequest notificationRequest)259     void CheckCaseTwoResult(NotificationRequest notificationRequest)
260     {
261         EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType());
262         std::vector<std::shared_ptr<NotificationActionButton>> actionButtons = notificationRequest.GetActionButtons();
263         for (auto actionButton : actionButtons) {
264             std::shared_ptr<NotificationUserInput> userInput = actionButton->GetUserInput();
265             EXPECT_EQ(NotificationConstant::FREE_FORM_INPUT, userInput->GetInputsSource(g_want));
266             EXPECT_EQ(nullptr, userInput->GetInputsFromWant(g_want));
267             std::map<std::string, std::shared_ptr<Uri>> map = userInput->GetMimeInputsFromWant(g_want, "");
268             EXPECT_EQ(unsigned(0), map.size());
269             EXPECT_EQ("inputKey", userInput->GetInputKey());
270             EXPECT_NE(nullptr, userInput->GetAdditionalData());
271             EXPECT_EQ(NotificationConstant::InputEditType::EDIT_DISABLED, userInput->GetEditType());
272             for (auto option : userInput->GetOptions()) {
273                 EXPECT_EQ("", option);
274             }
275             for (auto type : userInput->GetPermitMimeTypes()) {
276                 EXPECT_EQ("mimeType", type);
277             }
278             EXPECT_EQ(false, userInput->IsMimeTypeOnly());
279             EXPECT_EQ("tag", userInput->GetTag());
280             EXPECT_EQ(false, userInput->IsPermitFreeFormInput());
281         }
282     }
283 
CheckCaseThreeResult(NotificationRequest notificationRequest)284     void CheckCaseThreeResult(NotificationRequest notificationRequest)
285     {
286         EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType());
287         std::vector<std::shared_ptr<NotificationActionButton>> actionButtons = notificationRequest.GetActionButtons();
288         for (auto actionButton : actionButtons) {
289             EXPECT_EQ(nullptr, actionButton->GetIcon());
290             EXPECT_EQ("title", actionButton->GetTitle());
291             EXPECT_EQ(nullptr, actionButton->GetWantAgent());
292             EXPECT_NE(nullptr, actionButton->GetAdditionalData());
293             EXPECT_EQ(NotificationConstant::NONE_ACTION_BUTTON, actionButton->GetSemanticActionButton());
294             for (auto userInputs : actionButton->GetMimeTypeOnlyUserInputs()) {
295                 EXPECT_EQ("onlyUserInputKey", userInputs->GetInputKey());
296             }
297             EXPECT_EQ(true, actionButton->IsAutoCreatedReplies());
298             EXPECT_EQ(true, actionButton->IsContextDependent());
299         }
300     }
301 
CheckCaseFourResult(NotificationRequest notificationRequest)302     void CheckCaseFourResult(NotificationRequest notificationRequest)
303     {
304         std::shared_ptr<NotificationContent> notificationContent = notificationRequest.GetContent();
305         if (notificationContent != nullptr) {
306             EXPECT_EQ(NotificationContent::Type::CONVERSATION, notificationContent->GetContentType());
307             std::shared_ptr<NotificationConversationalContent> notificationConversationContent =
308                 std::static_pointer_cast<NotificationConversationalContent>(
309                     notificationContent->GetNotificationContent());
310             if (notificationConversationContent != nullptr) {
311                 EXPECT_EQ("ConversationTitle", notificationConversationContent->GetConversationTitle());
312                 EXPECT_EQ(false, notificationConversationContent->IsConversationGroup());
313                 std::vector<std::shared_ptr<NotificationConversationalMessage>> messagesPtr =
314                     notificationConversationContent->GetAllConversationalMessages();
315                 EXPECT_EQ(unsigned(CASE_TWO), messagesPtr.size());
316                 MessageUser user = notificationConversationContent->GetMessageUser();
317                 EXPECT_EQ("key", user.GetKey());
318                 EXPECT_EQ("Name", user.GetName());
319                 EXPECT_EQ(nullptr, user.GetPixelMap());
320                 EXPECT_EQ(Uri("."), user.GetUri());
321                 EXPECT_EQ(false, user.IsUserImportant());
322                 EXPECT_EQ(false, user.IsMachine());
323             }
324         }
325         EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType());
326     }
327 
CheckCaseFiveResult(NotificationRequest notificationRequest)328     void CheckCaseFiveResult(NotificationRequest notificationRequest)
329     {
330         std::shared_ptr<NotificationContent> notificationContent = notificationRequest.GetContent();
331         if (notificationContent != nullptr) {
332             EXPECT_EQ(NotificationContent::Type::MULTILINE, notificationContent->GetContentType());
333             std::shared_ptr<NotificationMultiLineContent> notificationMultineContent =
334                 std::static_pointer_cast<NotificationMultiLineContent>(notificationContent->GetNotificationContent());
335             if (notificationMultineContent != nullptr) {
336                 EXPECT_EQ("expandedtitle", notificationMultineContent->GetExpandedTitle());
337                 EXPECT_EQ("brieftext", notificationMultineContent->GetBriefText());
338                 for (auto allLine : notificationMultineContent->GetAllLines()) {
339                     EXPECT_EQ("singleLine", allLine);
340                 }
341             }
342         }
343         EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType());
344     }
345 
CheckCaseSixResult(NotificationRequest notificationRequest)346     void CheckCaseSixResult(NotificationRequest notificationRequest)
347     {
348         std::shared_ptr<NotificationContent> notificationContent = notificationRequest.GetContent();
349         if (notificationContent != nullptr) {
350             EXPECT_EQ(NotificationContent::Type::PICTURE, notificationContent->GetContentType());
351             std::shared_ptr<NotificationPictureContent> notificationPictureContent =
352                 std::static_pointer_cast<NotificationPictureContent>(notificationContent->GetNotificationContent());
353             if (notificationPictureContent != nullptr) {
354                 EXPECT_EQ("expendedtitle", notificationPictureContent->GetExpandedTitle());
355                 EXPECT_EQ("brieftext", notificationPictureContent->GetBriefText());
356                 EXPECT_EQ(nullptr, notificationPictureContent->GetBigPicture());
357             }
358         }
359         EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType());
360     }
361 
CheckCaseSevenResult(NotificationRequest notificationRequest)362     void CheckCaseSevenResult(NotificationRequest notificationRequest)
363     {
364         std::shared_ptr<NotificationContent> notificationContent = notificationRequest.GetContent();
365         if (notificationContent != nullptr) {
366             EXPECT_EQ(NotificationContent::Type::LONG_TEXT, notificationContent->GetContentType());
367             std::shared_ptr<NotificationLongTextContent> notificationLongContent =
368                 std::static_pointer_cast<NotificationLongTextContent>(notificationContent->GetNotificationContent());
369             if (notificationLongContent != nullptr) {
370                 EXPECT_EQ("expendedtitle", notificationLongContent->GetExpandedTitle());
371                 EXPECT_EQ("brieftext", notificationLongContent->GetBriefText());
372                 EXPECT_EQ("longtext", notificationLongContent->GetLongText());
373             }
374         }
375         EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType());
376     }
377 
CheckCaseEightResult(NotificationRequest notificationRequest)378     void CheckCaseEightResult(NotificationRequest notificationRequest)
379     {
380         EXPECT_EQ(NotificationConstant::CONTENT_INFORMATION, notificationRequest.GetSlotType());
381         EXPECT_EQ(false, notificationRequest.IsInProgress());
382         EXPECT_EQ(false, notificationRequest.IsUnremovable());
383         EXPECT_EQ(0, notificationRequest.GetBadgeNumber());
384         EXPECT_NE(0, notificationRequest.GetDeliveryTime());
385         EXPECT_EQ(false, notificationRequest.IsShowDeliveryTime());
386         EXPECT_EQ(false, notificationRequest.IsPermitSystemGeneratedContextualActionButtons());
387         EXPECT_EQ(false, notificationRequest.IsAlertOneTime());
388         EXPECT_EQ(0, notificationRequest.GetAutoDeletedTime());
389         EXPECT_EQ("classification", notificationRequest.GetClassification());
390         EXPECT_EQ((uint32_t)0, notificationRequest.GetColor());
391     }
392 
CheckCaseNineResult(NotificationRequest notificationRequest)393     void CheckCaseNineResult(NotificationRequest notificationRequest)
394     {
395         EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType());
396         EXPECT_EQ(false, notificationRequest.IsColorEnabled());
397         EXPECT_EQ(false, notificationRequest.IsCountdownTimer());
398         EXPECT_EQ("groupvalue", notificationRequest.GetGroupName());
399         EXPECT_EQ(true, notificationRequest.IsOnlyLocal());
400         EXPECT_EQ("setting text", notificationRequest.GetSettingsText());
401         EXPECT_EQ(false, notificationRequest.IsShowStopwatch());
402         EXPECT_EQ("sortingkey", notificationRequest.GetSortingKey());
403         EXPECT_EQ("statusbartext", notificationRequest.GetStatusBarText());
404         EXPECT_EQ(false, notificationRequest.IsTapDismissed());
405         auto visibleness = notificationRequest.GetVisibleness();
406         EXPECT_EQ((int)NotificationConstant::VisiblenessType::PUBLIC, (int)visibleness);
407         EXPECT_EQ(NotificationRequest::BadgeStyle::NONE, notificationRequest.GetBadgeIconStyle());
408         EXPECT_EQ("shortcutid", notificationRequest.GetShortcutId());
409         EXPECT_EQ(false, notificationRequest.IsFloatingIcon());
410         EXPECT_EQ(0, notificationRequest.GetProgressMax());
411         EXPECT_EQ(0, notificationRequest.GetProgressValue());
412         EXPECT_EQ(false, notificationRequest.IsProgressIndeterminate());
413         EXPECT_EQ(1, notificationRequest.GetBadgeNumber());
414     }
415 
CheckCaseFourteenResult(const NotificationRequest & notificationRequest) const416     void CheckCaseFourteenResult(const NotificationRequest& notificationRequest) const
417     {
418         std::shared_ptr<NotificationTemplate> notiTemplate = notificationRequest.GetTemplate();
419         if (notiTemplate != nullptr) {
420             EXPECT_EQ("downloadTemplate1", notiTemplate->GetTemplateName());
421             std::shared_ptr<AAFwk::WantParams> param = notiTemplate->GetTemplateData();
422             int value = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(param->GetParam("downloadTemplate1")));
423             EXPECT_EQ(20, value); // 20 test input
424         }
425         EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType());
426     }
427 
CheckCaseFifteenResult(NotificationRequest notificationRequest)428     void CheckCaseFifteenResult(NotificationRequest notificationRequest)
429     {
430         std::shared_ptr<NotificationFlags> notiFlags = notificationRequest.GetFlags();
431         if (notiFlags != nullptr) {
432             EXPECT_EQ(NotificationConstant::FlagStatus::CLOSE, notiFlags->IsSoundEnabled());
433             EXPECT_EQ(NotificationConstant::FlagStatus::CLOSE, notiFlags->IsVibrationEnabled());
434         }
435     }
436 
CheckCaseSixteenResult(NotificationRequest notificationRequest)437     void CheckCaseSixteenResult(NotificationRequest notificationRequest)
438     {
439         std::shared_ptr<NotificationFlags> notiFlags = notificationRequest.GetFlags();
440         if (notiFlags != nullptr) {
441             EXPECT_EQ(NotificationConstant::FlagStatus::CLOSE, notiFlags->IsSoundEnabled());
442             EXPECT_EQ(NotificationConstant::FlagStatus::CLOSE, notiFlags->IsVibrationEnabled());
443         }
444     }
445 
CheckCaseSeventeenResult(NotificationRequest notificationRequest)446     void CheckCaseSeventeenResult(NotificationRequest notificationRequest)
447     {
448         std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> removalWantAgent =
449             notificationRequest.GetRemovalWantAgent();
450         EXPECT_NE(removalWantAgent, nullptr);
451     }
452 
CheckCaseTwentyOneResult(NotificationRequest notificationRequest)453     void CheckCaseTwentyOneResult(NotificationRequest notificationRequest)
454     {
455         std::shared_ptr<NotificationFlags> notiFlags = notificationRequest.GetFlags();
456         if (notiFlags != nullptr) {
457             EXPECT_EQ(NotificationConstant::FlagStatus::CLOSE, notiFlags->IsSoundEnabled());
458             EXPECT_EQ(NotificationConstant::FlagStatus::CLOSE, notiFlags->IsVibrationEnabled());
459         }
460     }
461 };
462 
463 class CompletedCallbackTest : public AbilityRuntime::WantAgent::CompletedCallback {
OnSendFinished(const AAFwk::Want & want,int resultCode,const std::string & resultData,const AAFwk::WantParams & resultExtras)464     void OnSendFinished(
465         const AAFwk::Want &want, int resultCode, const std::string &resultData, const AAFwk::WantParams &resultExtras)
466     {
467         (void)want;
468         (void)resultCode;
469         (void)resultData;
470         (void)resultExtras;
471 
472         g_send_finished_mtx.unlock();
473         g_onWantReceived = true;
474     }
475 };
476 
477 class AnsInnerKitsModulePublishTest : public testing::Test {
478 public:
479     static void SetUpTestCase();
480     static void TearDownTestCase();
481     void SetUp();
482     void TearDown();
483     void WaitOnSubscribeResult();
484     void WaitOnConsumed();
485     void WaitOnUnsubscribeResult();
486     void WaitOnResponse(int32_t notificationId, std::string buttonName);
487     void CheckJsonConverter(const NotificationRequest *request);
488 
489     static sptr<AdvancedNotificationService> service_;
490 };
491 
492 sptr<AdvancedNotificationService> AnsInnerKitsModulePublishTest::service_;
SetUpTestCase()493 void AnsInnerKitsModulePublishTest::SetUpTestCase()
494 {
495     RemoteNativeToken::SetNativeToken("ans_innerkits_module_publish_test");
496     service_ = OHOS::Notification::AdvancedNotificationService::GetInstance();
497     OHOS::ISystemAbilityManager::SAExtraProp saExtraProp;
498     systemAbilityManager->AddSystemAbility(OHOS::ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID, service_, saExtraProp);
499 }
500 
TearDownTestCase()501 void AnsInnerKitsModulePublishTest::TearDownTestCase()
502 {
503     if (service_ != nullptr) {
504         service_->SelfClean();
505     }
506 }
507 
SetUp()508 void AnsInnerKitsModulePublishTest::SetUp()
509 {
510     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
511 }
512 
TearDown()513 void AnsInnerKitsModulePublishTest::TearDown()
514 {
515     g_onConsumedReceived = false;
516     g_subscribe_mtx.unlock();
517     g_consumed_mtx.unlock();
518     g_unsubscribe_mtx.unlock();
519 }
520 
WaitOnSubscribeResult()521 void AnsInnerKitsModulePublishTest::WaitOnSubscribeResult()
522 {
523     struct tm subscribeTime = {0};
524     EXPECT_EQ(OHOS::GetSystemCurrentTime(&subscribeTime), true);
525     struct tm subscribeDoingTime = {0};
526     EXPECT_EQ(OHOS::GetSystemCurrentTime(&subscribeDoingTime), true);
527     int64_t subscribeSeconds = 0;
528     while (!g_subscribe_mtx.try_lock()) {
529         EXPECT_EQ(OHOS::GetSystemCurrentTime(&subscribeDoingTime), true);
530         subscribeSeconds = OHOS::GetSecondsBetween(subscribeTime, subscribeDoingTime);
531         if (subscribeSeconds >= TIME_OUT_SECONDS_LIMIT) {
532             GTEST_LOG_(INFO) << "g_subscribe_mtx.try_lock overtime";
533             break;
534         }
535     }
536 }
537 
WaitOnConsumed()538 void AnsInnerKitsModulePublishTest::WaitOnConsumed()
539 {
540     struct tm publishTime = {0};
541     EXPECT_EQ(OHOS::GetSystemCurrentTime(&publishTime), true);
542     struct tm publishDoingTime = {0};
543     EXPECT_EQ(OHOS::GetSystemCurrentTime(&publishDoingTime), true);
544     int64_t publishSeconds = 0;
545     while (!g_consumed_mtx.try_lock()) {
546         EXPECT_EQ(OHOS::GetSystemCurrentTime(&publishDoingTime), true);
547         publishSeconds = OHOS::GetSecondsBetween(publishTime, publishDoingTime);
548         if (publishSeconds >= TIME_OUT_SECONDS_LIMIT) {
549             GTEST_LOG_(INFO) << "g_consumed_mtx.try_lock overtime";
550             break;
551         }
552     }
553     EXPECT_EQ(g_onConsumedReceived, true);
554 }
555 
WaitOnUnsubscribeResult()556 void AnsInnerKitsModulePublishTest::WaitOnUnsubscribeResult()
557 {
558     struct tm unsubscribeTime = {0};
559     EXPECT_EQ(OHOS::GetSystemCurrentTime(&unsubscribeTime), true);
560     struct tm unsubscribeDoingTime = {0};
561     EXPECT_EQ(OHOS::GetSystemCurrentTime(&unsubscribeDoingTime), true);
562     int64_t unSubscribeseconds = 0;
563     while (!g_unsubscribe_mtx.try_lock()) {
564         EXPECT_EQ(OHOS::GetSystemCurrentTime(&unsubscribeTime), true);
565         unSubscribeseconds = OHOS::GetSecondsBetween(unsubscribeTime, unsubscribeDoingTime);
566         if (unSubscribeseconds >= TIME_OUT_SECONDS_LIMIT) {
567             GTEST_LOG_(INFO) << "Ag_unsubscribe_mtx.try_lock overtime";
568             break;
569         }
570     }
571 }
572 
WaitOnResponse(int32_t notificationId,std::string buttonName)573 void AnsInnerKitsModulePublishTest::WaitOnResponse(int32_t notificationId, std::string buttonName)
574 {
575     struct tm publishTime = {0};
576     EXPECT_EQ(OHOS::GetSystemCurrentTime(&publishTime), true);
577     struct tm publishDoingTime = {0};
578     EXPECT_EQ(OHOS::GetSystemCurrentTime(&publishDoingTime), true);
579     int64_t publishSeconds = 0;
580     while (!g_system_live_view_subscribe_response_mtx.try_lock()) {
581         EXPECT_EQ(OHOS::GetSystemCurrentTime(&publishDoingTime), true);
582         publishSeconds = OHOS::GetSecondsBetween(publishTime, publishDoingTime);
583         if (publishSeconds >= TIME_OUT_SECONDS_LIMIT) {
584             GTEST_LOG_(INFO) << "g_system_live_view_subscribe_response_mtx.try_lock overtime";
585             break;
586         }
587     }
588     EXPECT_EQ(g_onResponseReceivedButtonName, buttonName);
589     EXPECT_EQ(g_onResponseReceivedId, notificationId);
590 }
591 
CheckJsonConverter(const NotificationRequest * request)592 void AnsInnerKitsModulePublishTest::CheckJsonConverter(const NotificationRequest *request)
593 {
594     nlohmann::json jsonObject;
595     auto ret0 = NotificationJsonConverter::ConvertToJson(request, jsonObject);
596     EXPECT_EQ(ret0, true);
597     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_08000::ConvertToJson object dump ==========>" << jsonObject.dump();
598 
599     std::string jsonString;
600     auto ret1 = NotificationJsonConverter::ConvertToJsonString(request, jsonString);
601     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_08000::ConvertToJsonString ret1 ==========>"
602         << (ret1 ? "true" : "false");
603     EXPECT_EQ(ret1, true);
604     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_08000::ConvertToJsonString string ==========>" << jsonString;
605 
606     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_08000::convert Json sleep start ==========>";
607     sleep(SLEEP_TIME);
608     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_08000::convert Json sleep end ==========>";
609 
610     auto pRequest1 = NotificationJsonConverter::ConvertFromJson<NotificationRequest>(jsonObject);
611     EXPECT_NE(pRequest1, nullptr);
612     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_08000::ConvertFromJson jsonObject dump request ==========>"
613         << pRequest1->Dump();
614 
615     auto pRequest2 = NotificationJsonConverter::ConvertFromJsonString<NotificationRequest>(jsonString);
616     EXPECT_NE(pRequest2, nullptr);
617     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_08000::ConvertFromJsonString jsonString dump request ==========>"
618         << pRequest2->Dump();
619 
620     nlohmann::json jsonObject2;
621     auto ret2 = NotificationJsonConverter::ConvertToJson(pRequest1, jsonObject2);
622     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_08000::ConvertToJson ret2 ==========>" << (ret2 ? "true" : "false");
623     EXPECT_EQ(ret2, true);
624     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_08000::FromJson -> ToJson object dump ==========>"
625         << jsonObject2.dump();
626 }
627 
628 /**
629  * @tc.number    : ANS_Interface_MT_Publish_00100
630  * @tc.name      : Publish_00100
631  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a media notification.
632  * @tc.expected  : Add notification slot success, make a subscriber and publish a media notification success.
633  */
634 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_00100, Function | MediumTest | Level1)
635 {
636     NotificationBundleOption bundleOption;
637     bundleOption.SetBundleName("bundleName");
638     bundleOption.SetUid(1);
639     std::string deviceId = "";
640     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
641         bundleOption, deviceId, true), (int)ERR_OK);
642 
643     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100 start ==========>";
644     NotificationSlot slot(NotificationConstant::OTHER);
645     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
646     auto subscriber = std::make_shared<TestAnsSubscriber>();
647     NotificationSubscribeInfo info = NotificationSubscribeInfo();
648     info.AddAppName("bundleName");
649     info.AddAppUserId(SUBSCRIBE_USER_ALL);
650     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100::SubscribeInfo:" << info.Dump();
651     g_subscribe_mtx.lock();
652     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
653     WaitOnSubscribeResult();
654     std::shared_ptr<NotificationMediaContent> mediaContent = std::make_shared<NotificationMediaContent>();
655     EXPECT_NE(mediaContent, nullptr);
656     mediaContent->SetAVToken(nullptr);
657     std::vector<uint32_t> actions;
658     actions.push_back(0);
659     mediaContent->SetShownActions(actions);
660     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100::mediaContent:" << mediaContent->Dump();
661     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(mediaContent);
662     EXPECT_NE(content, nullptr);
663     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100::Content:" << content->Dump();
664     NotificationRequest req;
665     req.SetContent(content);
666     req.SetSlotType(NotificationConstant::OTHER);
667     req.SetNotificationId(CASE_ONE);
668     std::vector<std::string> style;
669     style.push_back("style");
670     req.SetNotificationUserInputHistory(style);
671     req.SetOwnerBundleName("bundleName");
672     req.SetCreatorBundleName("creatorbundlename");
673     req.SetLabel("ANS_Interface_MT_Publish_00100");
674 
675     // pixelmap
676     auto pixelMap = std::make_shared<Media::PixelMap>();
677     EXPECT_NE(pixelMap, nullptr);
678     Media::ImageInfo imageInfo;
679     imageInfo.size.width = PIXEL_MAP_TEST_WIDTH;
680     imageInfo.size.height = PIXEL_MAP_TEST_HEIGHT;
681     imageInfo.pixelFormat = Media::PixelFormat::ALPHA_8;
682     imageInfo.colorSpace = Media::ColorSpace::SRGB;
683     pixelMap->SetImageInfo(imageInfo);
684     int32_t rowDataSize = (PIXEL_MAP_TEST_WIDTH + 3) / 4 * 4;
685     uint32_t bufferSize = rowDataSize * PIXEL_MAP_TEST_HEIGHT;
686     void *buffer = malloc(bufferSize);
687     if (buffer != nullptr) {
688         pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, Media::AllocatorType::HEAP_ALLOC, nullptr);
689     }
690     EXPECT_NE(buffer, nullptr);
691 
692     req.SetBigIcon(pixelMap);
693     req.SetLittleIcon(pixelMap);
694     req.SetOverlayIcon(pixelMap);
695     std::shared_ptr<MessageUser> messageUserPtr = std::make_shared<MessageUser>();
696     EXPECT_NE(messageUserPtr, nullptr);
697     messageUserPtr->SetName("ANS_Interface_MT_Publish_00100_Message_User");
698     messageUserPtr->SetKey("key");
699     messageUserPtr->SetPixelMap(nullptr);
700     messageUserPtr->SetUri(Uri("."));
701     messageUserPtr->SetMachine(false);
702     messageUserPtr->SetUserAsImportant(false);
703     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100::messageUser is::" << messageUserPtr->Dump();
704     req.AddMessageUser(messageUserPtr);
705     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100::messageUser is::" << req.Dump();
706     g_consumed_mtx.lock();
707     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
708     WaitOnConsumed();
709     g_unsubscribe_mtx.lock();
710     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
711     WaitOnUnsubscribeResult();
712 }
713 
714 /**
715  * @tc.number    : ANS_Interface_MT_Publish_00200
716  * @tc.name      : Publish_00200
717  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a local notification with input
718  *                 box.
719  * @tc.expected  : Add notification slot success, make a subscriber and publish a local notification with input box
720  *                 success.
721  */
722 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_00200, Function | MediumTest | Level1)
723 {
724     NotificationBundleOption bundleOption;
725     bundleOption.SetBundleName("bundleName");
726     bundleOption.SetUid(1);
727     std::string deviceId = "";
728     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
729         bundleOption, deviceId, true), (int)ERR_OK);
730 
731     NotificationSlot slot(NotificationConstant::OTHER);
732     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
733     auto subscriber = std::make_shared<TestAnsSubscriber>();
734     NotificationSubscribeInfo info = NotificationSubscribeInfo();
735     info.AddAppName("bundleName");
736     info.AddAppUserId(SUBSCRIBE_USER_ALL);
737     g_subscribe_mtx.lock();
738     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
739     WaitOnSubscribeResult();
740     std::shared_ptr<NotificationMediaContent> mediaContent = std::make_shared<NotificationMediaContent>();
741     EXPECT_NE(mediaContent, nullptr);
742     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(mediaContent);
743     EXPECT_NE(content, nullptr);
744     AbilityRuntime::WantAgent::WantAgentInfo paramsInfo;
745     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
746         AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo);
747     std::shared_ptr<NotificationActionButton> actionButton =
748         NotificationActionButton::Create(nullptr, "title", wantAgent);
749     std::shared_ptr<NotificationUserInput> userInput = NotificationUserInput::Create("inputKey");
750     std::vector<std::shared_ptr<NotificationUserInput>> userInputs;
751     AAFwk::WantParams additional;
752     std::map<std::string, std::shared_ptr<Uri>> results;
753     std::vector<std::string> options;
754     std::set<std::string> permitMimeTypes;
755     std::shared_ptr<AAFwk::WantParams> additionalPtr;
756     userInput->SetInputsSource(g_want, NotificationConstant::FREE_FORM_INPUT);
757     userInput->AddInputsToWant(userInputs, g_want, additional);
758     std::shared_ptr<NotificationUserInput> userInputMine = NotificationUserInput::Create(
759         "Key", "tag", options, false, permitMimeTypes, additionalPtr, NotificationConstant::EDIT_AUTO);
760     userInput->AddMimeInputToWant(*userInputMine, g_want, results);
761     userInput->AddAdditionalData(additional);
762     userInput->SetEditType(NotificationConstant::EDIT_DISABLED);
763     userInput->SetOptions(options);
764     userInput->SetPermitMimeTypes("mimeType", false);
765     userInput->SetTag("tag");
766     userInput->SetPermitFreeFormInput(false);
767     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00200::userInput is::" << userInput->Dump();
768     actionButton->AddNotificationUserInput(userInput);
769     NotificationRequest req;
770     req.SetContent(content);
771     req.SetSlotType(NotificationConstant::OTHER);
772     req.AddActionButton(actionButton);
773     req.SetNotificationId(CASE_TWO);
774     req.SetOwnerBundleName("bundleName");
775     g_consumed_mtx.lock();
776     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
777     WaitOnConsumed();
778     g_unsubscribe_mtx.lock();
779     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
780     WaitOnUnsubscribeResult();
781 }
782 
783 /**
784  * @tc.number    : ANS_Interface_MT_Publish_00300
785  * @tc.name      : Publish_00300
786  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a local notification with
787  *                 ActionButton.
788  * @tc.expected  : Add notification slot success, make a subscriber and publish a local notification with ActionButton
789  *                 success.
790  */
791 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_00300, Function | MediumTest | Level1)
792 {
793     NotificationBundleOption bundleOption;
794     bundleOption.SetBundleName("bundleName");
795     bundleOption.SetUid(1);
796     std::string deviceId = "";
797     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
798         bundleOption, deviceId, true), (int)ERR_OK);
799 
800     NotificationSlot slot(NotificationConstant::OTHER);
801     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
802     auto subscriber = std::make_shared<TestAnsSubscriber>();
803     NotificationSubscribeInfo info = NotificationSubscribeInfo();
804     info.AddAppName("bundleName");
805     info.AddAppUserId(SUBSCRIBE_USER_ALL);
806     g_subscribe_mtx.lock();
807     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
808     WaitOnSubscribeResult();
809     std::shared_ptr<NotificationMediaContent> mediaContent = std::make_shared<NotificationMediaContent>();
810     EXPECT_NE(mediaContent, nullptr);
811     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(mediaContent);
812     EXPECT_NE(content, nullptr);
813     AbilityRuntime::WantAgent::WantAgentInfo paramsInfo;
814     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
815         AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo);
816     if (nullptr == wantAgent) {
817         GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00300::wantAgent is nullptr";
818     }
819     std::shared_ptr<NotificationActionButton> actionButton =
820         NotificationActionButton::Create(nullptr, "title", wantAgent);
821     std::shared_ptr<NotificationUserInput> onlyUserInput = NotificationUserInput::Create("onlyUserInputKey");
822     AAFwk::WantParams additional;
823     actionButton->AddAdditionalData(additional);
824     actionButton->SetSemanticActionButton(NotificationConstant::NONE_ACTION_BUTTON);
825     actionButton->SetAutoCreatedReplies(true);
826     actionButton->AddMimeTypeOnlyUserInput(onlyUserInput);
827     actionButton->SetContextDependent(true);
828     GTEST_LOG_(INFO) << actionButton->Dump();
829     NotificationRequest req;
830     req.SetContent(content);
831     req.SetSlotType(NotificationConstant::OTHER);
832     req.AddActionButton(actionButton);
833     req.SetNotificationId(CASE_THREE);
834     req.SetOwnerBundleName("bundleName");
835     g_consumed_mtx.lock();
836     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
837     WaitOnConsumed();
838     g_unsubscribe_mtx.lock();
839     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
840     WaitOnUnsubscribeResult();
841 }
842 
843 /**
844  * @tc.number    : ANS_Interface_MT_Publish_00400
845  * @tc.name      : Publish_00400
846  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a local conversation
847  * notification.
848  * @tc.expected  : Add notification slot success, make a subscriber and publish a local conversation notification
849  * success.
850  */
851 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_00400, Function | MediumTest | Level1)
852 {
853     NotificationBundleOption bundleOption;
854     bundleOption.SetBundleName("bundleName");
855     bundleOption.SetUid(1);
856     std::string deviceId = "";
857     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
858         bundleOption, deviceId, true), (int)ERR_OK);
859 
860     NotificationSlot slot(NotificationConstant::OTHER);
861     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
862     auto subscriber = std::make_shared<TestAnsSubscriber>();
863     NotificationSubscribeInfo info = NotificationSubscribeInfo();
864     info.AddAppName("bundleName");
865     info.AddAppUserId(SUBSCRIBE_USER_ALL);
866     g_subscribe_mtx.lock();
867     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
868     WaitOnSubscribeResult();
869     MessageUser messageUser, sender;
870     messageUser.SetKey("key");
871     messageUser.SetName("Name");
872     messageUser.SetPixelMap(nullptr);
873     messageUser.SetUri(Uri("."));
874     messageUser.SetUserAsImportant(false);
875     messageUser.SetMachine(false);
876     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00400::messgaeUser is::" << messageUser.Dump();
877     std::shared_ptr<NotificationConversationalContent> conversationContent =
878         std::make_shared<NotificationConversationalContent>(messageUser);
879     EXPECT_NE(conversationContent, nullptr);
880     conversationContent->SetConversationTitle("ConversationTitle");
881     conversationContent->SetConversationGroup(false);
882     conversationContent->AddConversationalMessage("text", 0, sender);
883     std::shared_ptr<NotificationConversationalMessage> messagePtr =
884         std::make_shared<NotificationConversationalMessage>("messageptr", 0, sender);
885     EXPECT_NE(messagePtr, nullptr);
886     conversationContent->AddConversationalMessage(messagePtr);
887     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00400::conversationContent is::" << conversationContent->Dump();
888     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(conversationContent);
889     EXPECT_NE(content, nullptr);
890     NotificationRequest req;
891     req.SetContent(content);
892     req.SetSlotType(NotificationConstant::OTHER);
893     req.SetNotificationId(CASE_FOUR);
894     req.SetOwnerBundleName("bundleName");
895     g_consumed_mtx.lock();
896     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
897     WaitOnConsumed();
898     g_unsubscribe_mtx.lock();
899     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
900     WaitOnUnsubscribeResult();
901 }
902 
903 /**
904  * @tc.number    : ANS_Interface_MT_Publish_00500
905  * @tc.name      : Publish_00500
906  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a local multiline notification.
907  * @tc.expected  : Add notification slot success, make a subscriber and publish a local multiline notification success.
908  */
909 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_00500, Function | MediumTest | Level1)
910 {
911     NotificationBundleOption bundleOption;
912     bundleOption.SetBundleName("bundleName");
913     bundleOption.SetUid(1);
914     std::string deviceId = "";
915     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
916         bundleOption, deviceId, true), (int)ERR_OK);
917 
918     NotificationSlot slot(NotificationConstant::OTHER);
919     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
920     auto subscriber = std::make_shared<TestAnsSubscriber>();
921     NotificationSubscribeInfo info = NotificationSubscribeInfo();
922     info.AddAppName("bundleName");
923     info.AddAppUserId(SUBSCRIBE_USER_ALL);
924     g_subscribe_mtx.lock();
925     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
926     WaitOnSubscribeResult();
927     MessageUser messageUser;
928     std::shared_ptr<NotificationMultiLineContent> multiLineContent = std::make_shared<NotificationMultiLineContent>();
929     EXPECT_NE(multiLineContent, nullptr);
930     multiLineContent->SetExpandedTitle("expandedtitle");
931     multiLineContent->SetBriefText("brieftext");
932     multiLineContent->AddSingleLine("singleLine");
933     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00500::multiLineContent::" << multiLineContent->Dump();
934     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(multiLineContent);
935     EXPECT_NE(content, nullptr);
936     NotificationRequest req;
937     req.SetContent(content);
938     req.SetSlotType(NotificationConstant::OTHER);
939     req.SetNotificationId(CASE_FIVE);
940     req.SetOwnerBundleName("bundleName");
941     g_consumed_mtx.lock();
942     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
943     WaitOnConsumed();
944     g_unsubscribe_mtx.lock();
945     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
946     WaitOnUnsubscribeResult();
947 }
948 
949 /**
950  * @tc.number    : ANS_Interface_MT_Publish_00600
951  * @tc.name      : Publish_00600
952  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a local picture notification.
953  * @tc.expected  : Add notification slot success, make a subscriber and publish a local picture notification success.
954  */
955 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_00600, Function | MediumTest | Level1)
956 {
957     NotificationBundleOption bundleOption;
958     bundleOption.SetBundleName("bundleName");
959     bundleOption.SetUid(1);
960     std::string deviceId = "";
961     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
962         bundleOption, deviceId, true), (int)ERR_OK);
963 
964     NotificationSlot slot(NotificationConstant::OTHER);
965     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
966     auto subscriber = std::make_shared<TestAnsSubscriber>();
967     NotificationSubscribeInfo info = NotificationSubscribeInfo();
968     info.AddAppName("bundleName");
969     info.AddAppUserId(SUBSCRIBE_USER_ALL);
970     g_subscribe_mtx.lock();
971     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
972     WaitOnSubscribeResult();
973     MessageUser messageUser;
974     std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
975     EXPECT_NE(pictureContent, nullptr);
976     pictureContent->SetExpandedTitle("expendedtitle");
977     pictureContent->SetBriefText("brieftext");
978     pictureContent->SetBigPicture(nullptr);
979     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00600::pictureContent is::" << pictureContent->Dump();
980     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(pictureContent);
981     EXPECT_NE(content, nullptr);
982     NotificationRequest req;
983     req.SetContent(content);
984     req.SetSlotType(NotificationConstant::OTHER);
985     req.SetNotificationId(CASE_SIX);
986     req.SetOwnerBundleName("bundleName");
987     g_consumed_mtx.lock();
988     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
989     WaitOnConsumed();
990     g_unsubscribe_mtx.lock();
991     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
992     WaitOnUnsubscribeResult();
993 }
994 
995 /**
996  * @tc.number    : ANS_Interface_MT_Publish_00700
997  * @tc.name      : Publish_00700
998  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a local long text notification.
999  * @tc.expected  : Add notification slot success, make a subscriber and publish a local long text notification success.
1000  */
1001 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_00700, Function | MediumTest | Level1)
1002 {
1003     NotificationBundleOption bundleOption;
1004     bundleOption.SetBundleName("bundleName");
1005     bundleOption.SetUid(1);
1006     std::string deviceId = "";
1007     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1008         bundleOption, deviceId, true), (int)ERR_OK);
1009 
1010     NotificationSlot slot(NotificationConstant::OTHER);
1011     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1012     auto subscriber = std::make_shared<TestAnsSubscriber>();
1013     NotificationSubscribeInfo info = NotificationSubscribeInfo();
1014     info.AddAppName("bundleName");
1015     info.AddAppUserId(SUBSCRIBE_USER_ALL);
1016     g_subscribe_mtx.lock();
1017     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
1018     WaitOnSubscribeResult();
1019     MessageUser messageUser;
1020     std::shared_ptr<NotificationLongTextContent> longTextContent =
1021         std::make_shared<NotificationLongTextContent>("longtext");
1022     EXPECT_NE(longTextContent, nullptr);
1023     longTextContent->SetExpandedTitle("expendedtitle");
1024     longTextContent->SetBriefText("brieftext");
1025     longTextContent->SetLongText("longtext");
1026     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00700::longTextContentis::" << longTextContent->Dump();
1027     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(longTextContent);
1028     EXPECT_NE(content, nullptr);
1029     NotificationRequest req;
1030     req.SetContent(content);
1031     req.SetSlotType(NotificationConstant::OTHER);
1032     req.SetNotificationId(CASE_SEVEN);
1033     req.SetOwnerBundleName("bundleName");
1034     g_consumed_mtx.lock();
1035     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1036     WaitOnConsumed();
1037     g_unsubscribe_mtx.lock();
1038     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
1039     WaitOnUnsubscribeResult();
1040 }
1041 
1042 /**
1043  * @tc.number    : ANS_Interface_MT_Publish_00800
1044  * @tc.name      : Publish_00800
1045  * @tc.desc      : Add notification slot(type is CONTENT_INFORMATION), make a subscriber and publish a local normal
1046  *                 notification.
1047  * @tc.expected  : Add notification slot success, make a subscriber and publish a local normal notification success.
1048  */
1049 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_00800, Function | MediumTest | Level1)
1050 {
1051     NotificationBundleOption bundleOption;
1052     bundleOption.SetBundleName("bundleName");
1053     bundleOption.SetUid(1);
1054     std::string deviceId = "";
1055     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1056         bundleOption, deviceId, true), (int)ERR_OK);
1057 
1058     NotificationSlot slot(NotificationConstant::CONTENT_INFORMATION);
1059     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1060     auto subscriber = std::make_shared<TestAnsSubscriber>();
1061     g_subscribe_mtx.lock();
1062     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber));
1063     WaitOnSubscribeResult();
1064     MessageUser messageUser;
1065     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1066     EXPECT_NE(normalContent, nullptr);
1067     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00800::normalContentis::" << normalContent->Dump();
1068     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1069     EXPECT_NE(content, nullptr);
1070     NotificationRequest req;
1071     req.SetContent(content);
1072     req.SetSlotType(NotificationConstant::CONTENT_INFORMATION);
1073     req.SetNotificationId(CASE_EIGHT);
1074     req.SetInProgress(false);
1075     req.SetUnremovable(false);
1076     req.SetBadgeNumber(0);
1077     req.SetDeliveryTime(0);
1078     req.SetShowDeliveryTime(false);
1079     req.SetPermitSystemGeneratedContextualActionButtons(false);
1080     req.SetAlertOneTime(false);
1081     req.SetAutoDeletedTime(0);
1082     req.SetClassification("classification");
1083     req.SetColor(0);
1084     req.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN);
1085     g_consumed_mtx.lock();
1086     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1087     WaitOnConsumed();
1088     g_unsubscribe_mtx.lock();
1089     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber));
1090     WaitOnUnsubscribeResult();
1091 }
1092 
1093 /**
1094  * @tc.number    : ANS_Interface_MT_Publish_00900
1095  * @tc.name      : Publish_00900
1096  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a local normal
1097  *                 notification.
1098  * @tc.expected  : Add notification slot success, make a subscriber and publish a local normal notification success.
1099  */
1100 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_00900, Function | MediumTest | Level1)
1101 {
1102     NotificationBundleOption bundleOption;
1103     bundleOption.SetBundleName("bundleName");
1104     bundleOption.SetUid(1);
1105     std::string deviceId = "";
1106     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1107         bundleOption, deviceId, true), (int)ERR_OK);
1108 
1109     NotificationSlot slot(NotificationConstant::OTHER);
1110     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1111     auto subscriber = std::make_shared<TestAnsSubscriber>();
1112     g_subscribe_mtx.lock();
1113     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber));
1114     WaitOnSubscribeResult();
1115     MessageUser messageUser;
1116     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1117     EXPECT_NE(normalContent, nullptr);
1118     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1119     EXPECT_NE(content, nullptr);
1120     NotificationRequest req;
1121     req.SetContent(content);
1122     req.SetSlotType(NotificationConstant::OTHER);
1123     req.SetNotificationId(CASE_NINE);
1124     req.SetColorEnabled(false);
1125     req.SetCountdownTimer(false);
1126     req.SetGroupName("groupvalue");
1127     req.SetOnlyLocal(true);
1128     req.SetSettingsText("setting text");
1129     req.SetShowStopwatch(false);
1130     req.SetSortingKey("sortingkey");
1131     req.SetStatusBarText("statusbartext");
1132     req.SetTapDismissed(false);
1133     req.SetVisibleness(NotificationConstant::VisiblenessType::PUBLIC);
1134     req.SetBadgeIconStyle(NotificationRequest::BadgeStyle::NONE);
1135     req.SetShortcutId("shortcutid");
1136     req.SetFloatingIcon(false);
1137     req.SetProgressBar(0, 0, false);
1138     req.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN);
1139     req.SetBadgeNumber(1);
1140     g_consumed_mtx.lock();
1141     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1142     WaitOnConsumed();
1143     g_unsubscribe_mtx.lock();
1144     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber));
1145     WaitOnUnsubscribeResult();
1146 }
1147 
1148 /**
1149  * @tc.number    : ANS_Interface_MT_Publish_01000
1150  * @tc.name      : Publish_01000
1151  * @tc.desc      : Add notification slot(type is SERVICE_REMINDER), make a subscriber and publish a local normal
1152  *                 notification.
1153  * @tc.expected  : Add notification slot success, make a subscriber and publish a local normal notification success.
1154  */
1155 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_01000, Function | MediumTest | Level1)
1156 {
1157     NotificationBundleOption bundleOption;
1158     bundleOption.SetBundleName("bundleName");
1159     bundleOption.SetUid(1);
1160     std::string deviceId = "";
1161     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1162         bundleOption, deviceId, true), (int)ERR_OK);
1163 
1164     NotificationSlot slot(NotificationConstant::SERVICE_REMINDER);
1165     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1166     auto subscriber = std::make_shared<TestAnsSubscriber>();
1167     // Wait OnSubscribeResult
1168     g_subscribe_mtx.lock();
1169     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber));
1170     WaitOnSubscribeResult();
1171     MessageUser messageUser;
1172     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1173     EXPECT_NE(normalContent, nullptr);
1174     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1175     EXPECT_NE(content, nullptr);
1176     NotificationRequest req;
1177     req.SetContent(content);
1178     req.SetSlotType(NotificationConstant::SERVICE_REMINDER);
1179     req.SetNotificationId(CASE_TEN);
1180     g_consumed_mtx.lock();
1181     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1182     WaitOnConsumed();
1183     g_unsubscribe_mtx.lock();
1184     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber));
1185     WaitOnUnsubscribeResult();
1186     sleep(SLEEP_TIME);
1187 }
1188 
1189 /**
1190  * @tc.number    : ANS_Interface_MT_Publish_02000
1191  * @tc.name      : Publish_02000
1192  * @tc.desc      : Add notification slot(type is SOCIAL_COMMUNICATION), make a subscriber and publish a local normal
1193  *                 notification.
1194  * @tc.expected  : Add notification slot success, make a subscriber and publish a local normal notification success.
1195  */
1196 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_02000, Function | MediumTest | Level1)
1197 {
1198     NotificationBundleOption bundleOption;
1199     bundleOption.SetBundleName("bundleName");
1200     bundleOption.SetUid(1);
1201     std::string deviceId = "";
1202     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1203         bundleOption, deviceId, true), (int)ERR_OK);
1204 
1205     NotificationSlot slot(NotificationConstant::SOCIAL_COMMUNICATION);
1206     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1207     auto subscriber = std::make_shared<TestAnsSubscriber>();
1208     g_subscribe_mtx.lock();
1209     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber));
1210     WaitOnSubscribeResult();
1211     MessageUser messageUser;
1212     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1213     EXPECT_NE(normalContent, nullptr);
1214     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1215     EXPECT_NE(content, nullptr);
1216     NotificationRequest req;
1217     req.SetContent(content);
1218     req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION);
1219     req.SetNotificationId(CASE_ELEVEN);
1220     g_consumed_mtx.lock();
1221     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1222     WaitOnConsumed();
1223     g_unsubscribe_mtx.lock();
1224     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber));
1225     WaitOnUnsubscribeResult();
1226 }
1227 
1228 /**
1229  * @tc.number    : ANS_Interface_MT_Publish_03000
1230  * @tc.name      : Publish_03000
1231  * @tc.desc      : Add notification slot(type is CUSTOM), make a subscriber and publish a local normal
1232  *                 notification.
1233  * @tc.expected  : Add notification slot success, make a subscriber and publish a local normal notification success.
1234  */
1235 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_03000, Function | MediumTest | Level1)
1236 {
1237     NotificationBundleOption bundleOption;
1238     bundleOption.SetBundleName("bundleName");
1239     bundleOption.SetUid(1);
1240     std::string deviceId = "";
1241     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1242         bundleOption, deviceId, true), (int)ERR_OK);
1243 
1244     NotificationSlot slot(NotificationConstant::CUSTOM);
1245     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1246     auto subscriber = std::make_shared<TestAnsSubscriber>();
1247     g_subscribe_mtx.lock();
1248     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber));
1249     WaitOnSubscribeResult();
1250     MessageUser messageUser;
1251     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1252     EXPECT_NE(normalContent, nullptr);
1253     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1254     EXPECT_NE(content, nullptr);
1255     NotificationRequest req;
1256     req.SetContent(content);
1257     req.SetSlotType(NotificationConstant::CUSTOM);
1258     req.SetNotificationId(CASE_TWELVE);
1259     GTEST_LOG_(INFO) << "request is ::" << req.Dump();
1260     g_consumed_mtx.lock();
1261     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1262     WaitOnConsumed();
1263     g_unsubscribe_mtx.lock();
1264     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber));
1265     WaitOnUnsubscribeResult();
1266 }
1267 
1268 /**
1269  * @tc.number    : ANS_Interface_MT_Publish_07000
1270  * @tc.name      : Publish_07000
1271  * @tc.desc      : Add notification slot(type is SOCIAL_COMMUNICATION), make a subscriber and publish a local group
1272  *                 notification.
1273  * @tc.expected  : Add notification slot success, make a subscriber and publish a local group notification success.
1274  */
1275 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_07000, Function | MediumTest | Level1)
1276 {
1277     NotificationBundleOption bundleOption;
1278     bundleOption.SetBundleName("bundleName");
1279     bundleOption.SetUid(1);
1280     std::string deviceId = "";
1281     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1282         bundleOption, deviceId, true), (int)ERR_OK);
1283 
1284     NotificationSlot slot(NotificationConstant::SOCIAL_COMMUNICATION);
1285     slot.EnableBypassDnd(true);
1286     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1287     auto subscriber = std::make_shared<TestAnsSubscriber>();
1288     g_subscribe_mtx.lock();
1289     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber));
1290     WaitOnSubscribeResult();
1291     MessageUser messageUser;
1292     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1293     EXPECT_NE(normalContent, nullptr);
1294     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1295     EXPECT_NE(content, nullptr);
1296     NotificationRequest req;
1297     req.SetContent(content);
1298     req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION);
1299     req.SetGroupName("groupnotifcation");
1300     req.SetGroupOverview(true);
1301     req.SetNotificationId(CASE_THIRTEEN);
1302     req.SetGroupAlertType(NotificationRequest::GroupAlertType::ALL);
1303     g_consumed_mtx.lock();
1304     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1305     WaitOnConsumed();
1306     g_unsubscribe_mtx.lock();
1307     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber));
1308     WaitOnUnsubscribeResult();
1309 }
1310 
1311 /**
1312  * @tc.number    : ANS_FW_MT_GetActiveNotifications_00100
1313  * @tc.name      : GetActiveNotifications_00100
1314  * @tc.desc      : Get the active notifications and the number of active notifications of the current application.
1315  * @tc.expected  : Get the active notifications success and the number of active notifications of the current
1316  *                 application is right.
1317  */
1318 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_GetActiveNotifications_00100, Function | MediumTest | Level1)
1319 {
1320     NotificationBundleOption bundleOption;
1321     bundleOption.SetBundleName("bundleName");
1322     bundleOption.SetUid(1);
1323     std::string deviceId = "";
1324     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1325         bundleOption, deviceId, true), (int)ERR_OK);
1326 
1327     std::shared_ptr<NotificationLongTextContent> implContent = std::make_shared<NotificationLongTextContent>();
1328     EXPECT_NE(implContent, nullptr);
1329     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(implContent);
1330     EXPECT_NE(content, nullptr);
1331     EXPECT_EQ((int)ERR_OK, (int)NotificationHelper::CancelAllNotifications());
1332     uint64_t countBefor = 0;
1333     EXPECT_EQ((int)ERR_OK, NotificationHelper::GetActiveNotificationNums(countBefor));
1334     EXPECT_EQ(0, countBefor);
1335     std::string label1 = "Label1";
1336     NotificationRequest req1(0);
1337     req1.SetLabel(label1);
1338     req1.SetContent(content);
1339     req1.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN);
1340     req1.SetCreatorUid(100);
1341 
1342     EXPECT_EQ(0, NotificationHelper::PublishNotification(req1));
1343     std::string label2 = "Label2";
1344     NotificationRequest req2(0);
1345     req2.SetLabel(label2);
1346     req2.SetContent(content);
1347     req2.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN);
1348     req2.SetCreatorUid(100);
1349     EXPECT_EQ(0, NotificationHelper::PublishNotification(req2));
1350     uint64_t countAfter = 0;
1351     EXPECT_EQ((int)ERR_OK, NotificationHelper::GetActiveNotificationNums(countAfter));
1352     EXPECT_EQ(ACTIVE_NUMS, countAfter);
1353     std::vector<sptr<NotificationRequest>> requests;
1354     EXPECT_EQ((int)ERR_OK, NotificationHelper::GetActiveNotifications(requests));
1355     EXPECT_EQ("Label1", requests[0]->GetLabel());
1356     EXPECT_EQ("Label2", requests[1]->GetLabel());
1357     EXPECT_EQ((int)ERR_OK, (int)NotificationHelper::RemoveNotifications(SUBSCRIBE_USER_SYSTEM_BEGIN));
1358     sleep(SLEEP_TIME);
1359     EXPECT_EQ((int)ERR_OK, NotificationHelper::GetActiveNotificationNums(countAfter));
1360     EXPECT_EQ(0, countAfter);
1361 }
1362 
1363 /**
1364  * @tc.number    : ANS_FW_MT_CancelGroup_10100
1365  * @tc.name      : CancelGroup_10100
1366  * @tc.desc      : Cancel the notifications of the same group.
1367  * @tc.expected  : All notifications of the same group have been cancelled.
1368  */
1369 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_CancelGroup_10100, Function | MediumTest | Level1)
1370 {
1371     NotificationBundleOption bundleOption;
1372     bundleOption.SetBundleName("bundleName");
1373     bundleOption.SetUid(1);
1374     std::string deviceId = "";
1375     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1376         bundleOption, deviceId, true), (int)ERR_OK);
1377 
1378     NotificationSubscribeInfo info = NotificationSubscribeInfo();
1379     info.AddAppName("bundleName");
1380     info.AddAppUserId(SUBSCRIBE_USER_ALL);
1381 
1382     auto subscriber = std::make_shared<TestAnsSubscriber>();
1383     g_subscribe_mtx.lock();
1384     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
1385     WaitOnSubscribeResult();
1386 
1387     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1388     EXPECT_NE(normalContent, nullptr);
1389     GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100::normalContentis::" << normalContent->Dump();
1390     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1391     EXPECT_NE(content, nullptr);
1392 
1393     NotificationRequest req;
1394     req.SetContent(content);
1395     req.SetSlotType(NotificationConstant::OTHER);
1396     req.SetNotificationId(CANCELGROUP_NID);
1397     req.SetLabel("CancelGroup_10100");
1398     req.SetGroupName("group10100");
1399 
1400     g_consumed_mtx.lock();
1401     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1402     WaitOnConsumed();
1403     g_onConsumedReceived = false;
1404 
1405     GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100:: call CancelGroup : effective parameters";
1406     EXPECT_EQ(0, NotificationHelper::CancelGroup("group10100"));
1407 
1408     sleep(SLEEP_TIME);
1409     g_onCanceledReceived = false;
1410 
1411     GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100:: call CancelGroup : invalid parameters";
1412     EXPECT_EQ(0, NotificationHelper::CancelGroup("ngroup"));
1413 
1414     sleep(SLEEP_TIME);
1415     g_onCanceledReceived = false;
1416 
1417     req.SetOwnerBundleName("mybundlename");
1418     req.SetCreatorBundleName("mybundlename");
1419     g_consumed_mtx.unlock();
1420     g_consumed_mtx.lock();
1421     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1422     WaitOnConsumed();
1423     g_onConsumedReceived = false;
1424 
1425     NotificationBundleOption bo("bundlename", 0);
1426     GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100:: call RemoveGroupByBundle : effective parameters";
1427     EXPECT_EQ(0, NotificationHelper::RemoveGroupByBundle(bo, "group10100"));
1428 
1429     sleep(SLEEP_TIME);
1430     g_onCanceledReceived = false;
1431 
1432     GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100:: call RemoveGroupByBundle : invalid parameters";
1433     EXPECT_EQ(0, NotificationHelper::RemoveGroupByBundle(bo, "ngroup"));
1434 
1435     sleep(SLEEP_TIME);
1436     g_onCanceledReceived = false;
1437 
1438     g_unsubscribe_mtx.lock();
1439     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
1440     WaitOnUnsubscribeResult();
1441 }
1442 
1443 /**
1444  * @tc.number    : ANS_Interface_MT_Publish_04000
1445  * @tc.name      : Publish_04000
1446  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a template notification.
1447  * @tc.expected  : Add notification slot success, make a subscriber and publish a ltemplate notification success.
1448  */
1449 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_04000, Function | MediumTest | Level1)
1450 {
1451     NotificationBundleOption bundleOption;
1452     bundleOption.SetBundleName("bundleName");
1453     bundleOption.SetUid(1);
1454     std::string deviceId = "";
1455     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1456         bundleOption, deviceId, true), (int)ERR_OK);
1457 
1458     NotificationSlot slot(NotificationConstant::OTHER);
1459     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1460     auto subscriber = std::make_shared<TestAnsSubscriber>();
1461     NotificationSubscribeInfo info = NotificationSubscribeInfo();
1462     info.AddAppName("bundleName");
1463     info.AddAppUserId(SUBSCRIBE_USER_ALL);
1464     g_subscribe_mtx.lock();
1465     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
1466     WaitOnSubscribeResult();
1467 
1468     std::shared_ptr<NotificationTemplate> notiTemplate = std::make_shared<NotificationTemplate>();
1469     EXPECT_NE(notiTemplate, nullptr);
1470     notiTemplate->SetTemplateName("downloadTemplate1");
1471 
1472     AAFwk::WantParams wantParams;
1473     std::string key("downloadTemplate1");
1474     int resultValue = 20;
1475     wantParams.SetParam(key, AAFwk::Integer::Box(resultValue));
1476     wantParams.SetParam("fileName", AAFwk::Integer::Box(resultValue));
1477     wantParams.SetParam("title", AAFwk::Integer::Box(resultValue));
1478     notiTemplate->SetTemplateData(std::make_shared<AAFwk::WantParams>(wantParams));
1479     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_04000::notiTemplate::" << notiTemplate->Dump();
1480     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1481     EXPECT_NE(normalContent, nullptr);
1482     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1483     EXPECT_NE(content, nullptr);
1484     NotificationRequest req;
1485     req.SetContent(content);
1486     req.SetTemplate(notiTemplate);
1487     req.SetSlotType(NotificationConstant::OTHER);
1488     req.SetNotificationId(CASE_FOURTEEN);
1489     g_consumed_mtx.lock();
1490     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1491     WaitOnConsumed();
1492     g_unsubscribe_mtx.lock();
1493     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
1494     WaitOnUnsubscribeResult();
1495 }
1496 
1497 /**
1498  * @tc.number    : ANS_Interface_MT_Publish_08000
1499  * @tc.name      : Publish_08000
1500  * @tc.desc      : .
1501  * @tc.expected  : .
1502  */
1503 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_08000, Function | MediumTest | Level1)
1504 {
1505     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_08000::convert Json start ############==========>";
1506 
1507     NotificationRequest req;
1508     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1509     EXPECT_NE(normalContent, nullptr);
1510     normalContent->SetTitle("normal_title");
1511     normalContent->SetText("normal_text");
1512     normalContent->SetAdditionalText("normal_additional_text");
1513     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00800::normalContent::" << normalContent->Dump();
1514 
1515     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1516     EXPECT_NE(content, nullptr);
1517 
1518     req.SetNotificationId(8000);
1519     req.SetContent(content);
1520     req.SetSlotType(NotificationConstant::CONTENT_INFORMATION);
1521     req.SetClassification(NotificationRequest::CLASSIFICATION_ALARM);
1522     req.SetLabel("label");
1523     req.SetOwnerBundleName("owner");
1524 
1525     auto wAgent1 = std::make_shared<AbilityRuntime::WantAgent::WantAgent>();
1526     req.SetWantAgent(wAgent1);
1527 
1528     auto wAgent2 = std::make_shared<AbilityRuntime::WantAgent::WantAgent>();
1529     std::shared_ptr<Media::PixelMap> dummyIcon;
1530     auto ab1 = NotificationActionButton::Create(dummyIcon, "ab1_title", wAgent2);
1531 
1532     auto spUserInput2 = NotificationUserInput::Create("uikey2");
1533     ab1->AddNotificationUserInput(spUserInput2);
1534     auto spOnlyUserInput1 = NotificationUserInput::Create("uionlykey1");
1535     spOnlyUserInput1->SetPermitFreeFormInput(false);
1536     spOnlyUserInput1->SetPermitMimeTypes("uionly", true);
1537     auto spOnlyUserInput4 = NotificationUserInput::Create("uionlykey4");
1538     spOnlyUserInput4->SetPermitFreeFormInput(false);
1539     spOnlyUserInput4->SetPermitMimeTypes("uionly", true);
1540 
1541     ab1->AddMimeTypeOnlyUserInput(spOnlyUserInput1);
1542     ab1->AddMimeTypeOnlyUserInput(spOnlyUserInput4);
1543 
1544     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> dummyWantAgent;
1545     auto ab2 = NotificationActionButton::Create(dummyIcon, "ab2_title", dummyWantAgent);
1546 
1547     req.AddActionButton(ab1);
1548     req.AddActionButton(ab2);
1549 
1550     std::vector<std::string> history {"uihistory3", "uihistory2", "uihistory1"};
1551     req.SetNotificationUserInputHistory(history);
1552 
1553     auto msgUser1 = std::make_shared<MessageUser>();
1554     msgUser1->SetKey("msgUser1_key");
1555     msgUser1->SetName("msgUser1_name");
1556     auto msgUser2 = std::make_shared<MessageUser>();
1557     msgUser2->SetKey("msgUser2_key");
1558     msgUser2->SetName("msgUser2_name");
1559     req.AddMessageUser(msgUser2);
1560     req.AddMessageUser(msgUser1);
1561 
1562     CheckJsonConverter(&req);
1563 }
1564 
1565 /**
1566  * @tc.number    : ANS_Interface_MT_Publish_05000
1567  * @tc.name      : Publish_05000
1568  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a flags notification.
1569  * @tc.expected  : Add notification slot success, make a subscriber and publish a flags notification success.
1570  */
1571 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_05000, Function | MediumTest | Level1)
1572 {
1573     NotificationBundleOption bundleOption;
1574     bundleOption.SetBundleName("bundleName");
1575     bundleOption.SetUid(1);
1576     std::string deviceId = "";
1577     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1578         bundleOption, deviceId, true), (int)ERR_OK);
1579 
1580     NotificationSlot slot(NotificationConstant::OTHER);
1581     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1582     auto subscriber = std::make_shared<TestAnsSubscriber>();
1583     NotificationSubscribeInfo info = NotificationSubscribeInfo();
1584     info.AddAppName("bundleName");
1585     info.AddAppUserId(SUBSCRIBE_USER_ALL);
1586     g_subscribe_mtx.lock();
1587     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
1588     WaitOnSubscribeResult();
1589 
1590     std::shared_ptr<NotificationFlags> notiFlags = std::make_shared<NotificationFlags>();
1591     EXPECT_NE(notiFlags, nullptr);
1592     notiFlags->SetSoundEnabled(NotificationConstant::FlagStatus::CLOSE);
1593     notiFlags->SetVibrationEnabled(NotificationConstant::FlagStatus::OPEN);
1594     GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_04000::flags::" << notiFlags->Dump();
1595     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1596     EXPECT_NE(normalContent, nullptr);
1597     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1598     EXPECT_NE(content, nullptr);
1599     NotificationRequest req;
1600     req.SetContent(content);
1601     req.SetFlags(notiFlags);
1602     req.SetNotificationId(CASE_FIFTEEN);
1603     g_consumed_mtx.lock();
1604     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1605     WaitOnConsumed();
1606     g_unsubscribe_mtx.lock();
1607     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
1608     WaitOnUnsubscribeResult();
1609 }
1610 
1611 /**
1612  * @tc.number    : ANS_Interface_MT_Publish_06000
1613  * @tc.name      : Publish_06000
1614  * @tc.desc      : Add notification slot(type is OTHER), make a subscriber and publish a flags notification.
1615  * @tc.expected  : Add notification slot success, make a subscriber and publish default flags notification success.
1616  */
1617 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_06000, Function | MediumTest | Level1)
1618 {
1619     NotificationBundleOption bundleOption;
1620     bundleOption.SetBundleName("bundleName");
1621     bundleOption.SetUid(1);
1622     std::string deviceId = "";
1623     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1624         bundleOption, deviceId, true), (int)ERR_OK);
1625 
1626     NotificationSlot slot(NotificationConstant::OTHER);
1627     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1628     auto subscriber = std::make_shared<TestAnsSubscriber>();
1629     NotificationSubscribeInfo info = NotificationSubscribeInfo();
1630     info.AddAppName("bundleName");
1631     info.AddAppUserId(SUBSCRIBE_USER_ALL);
1632     g_subscribe_mtx.lock();
1633     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
1634     WaitOnSubscribeResult();
1635 
1636     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1637     EXPECT_NE(normalContent, nullptr);
1638     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1639     EXPECT_NE(content, nullptr);
1640     NotificationRequest req;
1641     req.SetContent(content);
1642     req.SetSlotType(NotificationConstant::OTHER);
1643     req.SetNotificationId(CASE_TWENTY_ONE);
1644     g_consumed_mtx.lock();
1645     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1646     WaitOnConsumed();
1647     g_unsubscribe_mtx.lock();
1648     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
1649     WaitOnUnsubscribeResult();
1650 }
1651 
1652 /**
1653  * @tc.number    : ANS_Interface_MT_Slot_Enalbe_00100
1654  * @tc.name      : Slot_Enalbe_00100
1655  * @tc.desc      : Add notification slot(type is CONTENT_INFORMATION),
1656  * make a subscriber and publish a flags notification.
1657  * @tc.expected  : Add notification slot success, make a subscriber and publish default flags notification success.
1658  */
1659 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Slot_Enalbe_00100, Function | MediumTest | Level1)
1660 {
1661     NotificationBundleOption bundleOption;
1662     bundleOption.SetBundleName("bundleName");
1663     bundleOption.SetUid(1);
1664     std::string deviceId = "";
1665     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1666         bundleOption, deviceId, true), (int)ERR_OK);
1667 
1668     GTEST_LOG_(INFO) << "ANS_Interface_MT_Slot_Enalbe_00100::start:";
1669     NotificationSlot slot(NotificationConstant::CONTENT_INFORMATION);
1670     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1671 
1672     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1673     EXPECT_NE(normalContent, nullptr);
1674     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1675     EXPECT_NE(content, nullptr);
1676     NotificationRequest req;
1677     req.SetContent(content);
1678     req.SetSlotType(NotificationConstant::CONTENT_INFORMATION);
1679     req.SetNotificationId(CASE_SIXTEEN);
1680     g_consumed_mtx.lock();
1681     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1682 
1683     bool enable = false;
1684     NotificationBundleOption bo("bundleName", 1);
1685     EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(
1686         bo, NotificationConstant::CONTENT_INFORMATION, enable, false));
1687     sleep(SLEEP_TIME);
1688     EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::CONTENT_INFORMATION, enable));
1689     GTEST_LOG_(INFO) << "ANS_Interface_MT_Slot_Enalbe_00100::end:" << enable;
1690     EXPECT_EQ(enable, false);
1691     EXPECT_EQ(ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, NotificationHelper::PublishNotification(req));
1692     EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(
1693         bo, NotificationConstant::CONTENT_INFORMATION, true, false));
1694 }
1695 
1696 /**
1697  * @tc.number    : ANS_Interface_MT_Slot_Enalbe_00200
1698  * @tc.name      : Slot_Enalbe_00200
1699  * @tc.desc      : Add notification slot(type is SERVICE_REMINDER), make a subscriber and publish a flags notification.
1700  * @tc.expected  : Add notification slot success, make a subscriber and publish default flags notification success.
1701  */
1702 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Slot_Enalbe_00200, Function | MediumTest | Level1)
1703 {
1704     NotificationBundleOption bundleOption;
1705     bundleOption.SetBundleName("bundleName");
1706     bundleOption.SetUid(1);
1707     std::string deviceId = "";
1708     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1709         bundleOption, deviceId, true), (int)ERR_OK);
1710 
1711     GTEST_LOG_(INFO) << "ANS_Interface_MT_Slot_Enalbe_00200::start:";
1712     NotificationSlot slot(NotificationConstant::SERVICE_REMINDER);
1713     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1714 
1715     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1716     EXPECT_NE(normalContent, nullptr);
1717     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1718     EXPECT_NE(content, nullptr);
1719     NotificationRequest req;
1720     req.SetContent(content);
1721     req.SetSlotType(NotificationConstant::SERVICE_REMINDER);
1722     req.SetNotificationId(CASE_SIXTEEN);
1723     g_consumed_mtx.lock();
1724     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1725 
1726     bool enable = false;
1727     NotificationBundleOption bo("bundleName", 1);
1728     GTEST_LOG_(INFO) << "ANS_Interface_MT_Slot_Enalbe_00200::end:" << enable;
1729     EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(
1730         bo, NotificationConstant::SERVICE_REMINDER, enable, false));
1731     sleep(SLEEP_TIME);
1732     EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable));
1733     EXPECT_EQ(enable, false);
1734     EXPECT_EQ((uint32_t)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, NotificationHelper::PublishNotification(req));
1735 
1736     enable = true;
1737     EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(
1738         bo, NotificationConstant::SERVICE_REMINDER, enable, false));
1739     sleep(SLEEP_TIME);
1740     EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable));
1741     EXPECT_EQ(enable, true);
1742     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1743 }
1744 
1745 /**
1746  * @tc.number    : ANS_Interface_MT_Publish_09000
1747  * @tc.name      : Publish_09000
1748  * @tc.desc      : Add removalWantAgent, make a subscriber and publish a removalWantAgent notification.
1749  * @tc.expected  : Add removalWantAgent success, make a subscriber and publish removalWantAgent notification success.
1750  */
1751 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_09000, Function | MediumTest | Level1)
1752 {
1753     NotificationBundleOption bundleOption;
1754     bundleOption.SetBundleName("bundleName");
1755     bundleOption.SetUid(1);
1756     std::string deviceId = "";
1757     EXPECT_EQ(NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
1758         bundleOption, deviceId, true), (int)ERR_OK);
1759 
1760     NotificationSlot slot(NotificationConstant::OTHER);
1761     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1762     auto subscriber = std::make_shared<TestAnsSubscriber>();
1763     NotificationSubscribeInfo info = NotificationSubscribeInfo();
1764     info.AddAppName("bundleName");
1765     info.AddAppUserId(SUBSCRIBE_USER_ALL);
1766     g_subscribe_mtx.lock();
1767     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
1768     WaitOnSubscribeResult();
1769 
1770     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1771     EXPECT_NE(normalContent, nullptr);
1772     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1773     EXPECT_NE(content, nullptr);
1774 
1775     auto want = std::make_shared<OHOS::AAFwk::Want>();
1776     EXPECT_NE(want, nullptr);
1777     want->SetAction("usual.event.REMOVAL_WANTAGENT");
1778     AppExecFwk::ElementName element("device", "bundleName", "abilityName");
1779     want->SetElement(element);
1780     std::vector<std::shared_ptr<AAFwk::Want>> wants { want };
1781     std::vector<AbilityRuntime::WantAgent::WantAgentConstant::Flags> flags {
1782         AbilityRuntime::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG };
1783     AbilityRuntime::WantAgent::WantAgentInfo paramsInfo(
1784         10,
1785         AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT,
1786         flags, wants, nullptr
1787     );
1788 
1789     std::shared_ptr<AbilityRuntime::ApplicationContext> context =
1790         std::make_shared<AbilityRuntime::ApplicationContext>();
1791     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent = nullptr;
1792     AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(context, paramsInfo, wantAgent);
1793     EXPECT_NE(wantAgent, nullptr);
1794 
1795     NotificationRequest req;
1796     req.SetContent(content);
1797     req.SetSlotType(NotificationConstant::OTHER);
1798     req.SetNotificationId(CASE_SEVENTEEN);
1799     req.SetRemovalWantAgent(wantAgent);
1800     g_consumed_mtx.lock();
1801     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1802     WaitOnConsumed();
1803     g_unsubscribe_mtx.lock();
1804     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
1805     WaitOnUnsubscribeResult();
1806 }
1807 
1808 /**
1809  * @tc.number    : ANS_Interface_MT_Publish_10001
1810  * @tc.name      : Publish_10001
1811  * @tc.desc      : Add notification slot(type is LIVE_VIEW), make a subscriber, a system live view subscriber
1812  *                 and publish a system live view notification. Then trigger a button.
1813  * @tc.expected  : Add notification slot success, publish notification failed because not subscirbe button callback .
1814  */
1815 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_10001, Function | MediumTest | Level1)
1816 {
1817     NotificationSlot slot(NotificationConstant::LIVE_VIEW);
1818     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1819     auto subscriber = std::make_shared<TestAnsSubscriber>();
1820     g_subscribe_mtx.lock();
1821     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber));
1822     WaitOnSubscribeResult();
1823 
1824     MessageUser messageUser;
1825     std::shared_ptr<NotificationLocalLiveViewContent> liveContent =
1826         std::make_shared<NotificationLocalLiveViewContent>();
1827     EXPECT_NE(liveContent, nullptr);
1828     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(liveContent);
1829     EXPECT_NE(content, nullptr);
1830 
1831     NotificationRequest req;
1832     int32_t notificationId = CASE_EIGHTEEN;
1833     req.SetContent(content);
1834     req.SetSlotType(NotificationConstant::LIVE_VIEW);
1835     req.SetNotificationId(notificationId);
1836 
1837     EXPECT_EQ(ERR_ANS_LOCAL_SUBSCRIBE_CHECK_FAILED, NotificationHelper::PublishNotification(req));
1838 
1839     g_unsubscribe_mtx.lock();
1840     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber));
1841     WaitOnUnsubscribeResult();
1842 }
1843 
1844 /**
1845  * @tc.number    : ANS_Interface_MT_Publish_10002
1846  * @tc.name      : Publish_10002
1847  * @tc.desc      : Add notification slot(type is LIVE_VIEW), make a subscriber, a system live view subscriber
1848  *                 and publish a system live view notification. Then trigger a button.
1849  * @tc.expected  : Add notification slot success, make a subscriber, publish a notification
1850  *                 and trigger a buuton success.
1851  */
1852 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_10002, Function | MediumTest | Level1)
1853 {
1854     NotificationSlot slot(NotificationConstant::LIVE_VIEW);
1855     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
1856     auto subscriber = std::make_shared<TestAnsSubscriber>();
1857     g_subscribe_mtx.lock();
1858     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber));
1859     WaitOnSubscribeResult();
1860 
1861     auto systemLiveViewSubscriber = TestLocalLiveViewSubscriber();
1862     EXPECT_EQ(0, NotificationHelper::SubscribeLocalLiveViewNotification(systemLiveViewSubscriber, true));
1863 
1864     MessageUser messageUser;
1865     std::shared_ptr<NotificationLocalLiveViewContent> liveContent =
1866         std::make_shared<NotificationLocalLiveViewContent>();
1867     EXPECT_NE(liveContent, nullptr);
1868     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(liveContent);
1869     EXPECT_NE(content, nullptr);
1870 
1871     NotificationRequest req;
1872     int32_t notificationId = CASE_TWENTY;
1873     req.SetContent(content);
1874     req.SetSlotType(NotificationConstant::LIVE_VIEW);
1875     req.SetNotificationId(notificationId);
1876 
1877     g_consumed_mtx.lock();
1878     EXPECT_EQ(0, NotificationHelper::PublishNotification(req));
1879     WaitOnConsumed();
1880 
1881     std::string buttonName = "testButton";
1882     NotificationBundleOption bundleOption;
1883     bundleOption.SetBundleName("bundleName");
1884     bundleOption.SetUid(1);
1885     NotificationButtonOption buttonOption;
1886     buttonOption.SetButtonName(buttonName);
1887     g_system_live_view_subscribe_response_mtx.lock();
1888     EXPECT_EQ(0, NotificationHelper::TriggerLocalLiveView(bundleOption, notificationId, buttonOption));
1889     WaitOnResponse(notificationId, buttonName);
1890 
1891     g_unsubscribe_mtx.lock();
1892     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber));
1893     WaitOnUnsubscribeResult();
1894 }
1895 
1896 /**
1897  * @tc.name: ANS_Interface_MT_SetBadgeNumber_00100
1898  * @tc.desc: check SetBadgeNumber interface return value.
1899  * @tc.type: FUNC
1900  * @tc.require: #I6C2X9
1901  */
1902 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_SetBadgeNumber_00100, Function | MediumTest | Level1)
1903 {
1904     EXPECT_EQ(NotificationHelper::SetBadgeNumber(BADGE_NUMBER), (int)ERR_OK);
1905 }
1906 
1907 /**
1908  * @tc.name: ANS_Interface_MT_SetBadgeNumber_00200
1909  * @tc.desc: check SetBadgeNumber interface return value.
1910  * @tc.type: FUNC
1911  * @tc.require: #I6C2X9
1912  */
1913 HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_SetBadgeNumber_00200, Function | MediumTest | Level1)
1914 {
1915     auto subscriber = std::make_shared<TestAnsSubscriber>();
1916     NotificationSubscribeInfo info = NotificationSubscribeInfo();
1917     info.AddAppName("bundleName");
1918     info.AddAppUserId(SUBSCRIBE_USER_ALL);
1919     g_subscribe_mtx.lock();
1920     EXPECT_EQ(0, NotificationHelper::SubscribeNotification(*subscriber, info));
1921     WaitOnSubscribeResult();
1922 
1923     EXPECT_EQ(NotificationHelper::SetBadgeNumber(BADGE_NUMBER), (int)ERR_OK);
1924     sleep(SLEEP_TIME);
1925     EXPECT_EQ(g_onBadgeNumberReceived, true);
1926 
1927     EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(*subscriber, info));
1928     WaitOnUnsubscribeResult();
1929 }
1930 }  // namespace Notification
1931 }  // namespace OHOS
1932