1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <chrono>
17 #include <functional>
18 #include <thread>
19 
20 #include "gtest/gtest.h"
21 
22 #define private public
23 
24 #include "advanced_notification_service.h"
25 #include "ans_const_define.h"
26 #include "ans_inner_errors.h"
27 #include "ans_log_wrapper.h"
28 #include "ans_subscriber_listener.h"
29 #include "ans_ut_constant.h"
30 #include "iremote_object.h"
31 #include "want_agent_info.h"
32 #include "want_agent_helper.h"
33 #include "want_params.h"
34 #include "mock_ipc_skeleton.h"
35 #include "notification_preferences.h"
36 #include "notification_constant.h"
37 #include "notification_record.h"
38 #include "notification_subscriber.h"
39 #include "refbase.h"
40 
41 extern void MockVerifyNativeToken(bool mockRet);
42 extern void MockVerifyShellToken(bool mockRet);
43 extern void MockGetDistributedEnableInApplicationInfo(bool mockRet, uint8_t mockCase = 0);
44 extern void MockGetOsAccountLocalIdFromUid(bool mockRet, uint8_t mockCase = 0);
45 
46 using namespace testing::ext;
47 using namespace OHOS::Media;
48 using namespace OHOS::Security::AccessToken;
49 
50 namespace OHOS {
51 namespace Notification {
52 extern void MockIsVerfyPermisson(bool isVerify);
53 extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet);
54 extern void MockIsSystemApp(bool isSystemApp);
55 extern void MockDistributedNotificationEnabled(bool isEnable);
56 extern void MockIsNonBundleName(bool isNonBundleName);
57 
58 class AnsBranchTest : public testing::Test {
59 public:
60     static void SetUpTestCase();
61     static void TearDownTestCase();
62     void SetUp();
63     void TearDown();
64     static void InitNotificationRecord(std::shared_ptr<NotificationRecord> &record,
65         const NotificationLiveViewContent::LiveViewStatus &status);
66 private:
67     void TestAddSlot(NotificationConstant::SlotType type);
68 
69 private:
70     static sptr<AdvancedNotificationService> advancedNotificationService_;
71 };
72 
73 sptr<AdvancedNotificationService> AnsBranchTest::advancedNotificationService_ = nullptr;
74 
SetUpTestCase()75 void AnsBranchTest::SetUpTestCase() {}
76 
TearDownTestCase()77 void AnsBranchTest::TearDownTestCase() {}
78 
SetUp()79 void AnsBranchTest::SetUp()
80 {
81     GTEST_LOG_(INFO) << "SetUp start";
82 
83     advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService();
84     IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
85     IPCSkeleton::SetCallingUid(SYSTEM_APP_UID);
86     advancedNotificationService_->CancelAll(0);
87     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE);
88     MockIsSystemApp(true);
89     GTEST_LOG_(INFO) << "SetUp end";
90 }
91 
TearDown()92 void AnsBranchTest::TearDown()
93 {
94     IPCSkeleton::SetCallingUid(SYSTEM_APP_UID);
95     advancedNotificationService_ = nullptr;
96     GTEST_LOG_(INFO) << "TearDown";
97 }
98 
SleepForFC()99 inline void SleepForFC()
100 {
101     // For ANS Flow Control
102     std::this_thread::sleep_for(std::chrono::seconds(1));
103 }
104 
105 class TestAnsSubscriber : public NotificationSubscriber {
106 public:
OnDied()107     void OnDied() override
108     {}
OnConnected()109     void OnConnected() override
110     {}
OnDisconnected()111     void OnDisconnected() override
112     {}
OnUpdate(const std::shared_ptr<NotificationSortingMap> & sortingMap)113     void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) override
114     {}
OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> & date)115     void OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> &date) override
116     {}
OnCanceled(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap,int32_t deleteReason)117     void OnCanceled(const std::shared_ptr<Notification> &request,
118         const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) override
119     {}
OnEnabledNotificationChanged(const std::shared_ptr<EnabledNotificationCallbackData> & callbackData)120     void OnEnabledNotificationChanged(
121         const std::shared_ptr<EnabledNotificationCallbackData> &callbackData) override
122     {}
OnConsumed(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap)123     void OnConsumed(const std::shared_ptr<Notification> &request,
124         const std::shared_ptr<NotificationSortingMap> &sortingMap) override
125     {}
OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> & badgeData)126     void OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> &badgeData) override
127     {}
OnBadgeEnabledChanged(const sptr<EnabledNotificationCallbackData> & callbackData)128     void OnBadgeEnabledChanged(const sptr<EnabledNotificationCallbackData> &callbackData) override
129     {}
OnBatchCanceled(const std::vector<std::shared_ptr<Notification>> & requestList,const std::shared_ptr<NotificationSortingMap> & sortingMap,int32_t deleteReason)130     void OnBatchCanceled(const std::vector<std::shared_ptr<Notification>>
131         &requestList, const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) override
132     {}
133 };
134 
TestAddSlot(NotificationConstant::SlotType type)135 void AnsBranchTest::TestAddSlot(NotificationConstant::SlotType type)
136 {
137     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
138     MockIsSystemApp(true);
139     MockIsVerfyPermisson(true);
140     std::vector<sptr<NotificationSlot>> slots;
141     sptr<NotificationSlot> slot = new NotificationSlot(type);
142     slots.push_back(slot);
143     ASSERT_EQ(advancedNotificationService_->AddSlots(slots), (int)ERR_OK);
144 }
145 
146 /**
147  * @tc.number    : AnsBranchTest_222000
148  * @tc.name      : PrepareNotificationRequest_1000
149  * @tc.desc      : Test PrepareNotificationRequest function return ERR_ANS_NON_SYSTEM_APP.
150  * @tc.require   : #I6P8UI
151  */
152 HWTEST_F(AnsBranchTest, AnsBranchTest_222000, Function | SmallTest | Level1)
153 {
154     sptr<NotificationRequest> req = new NotificationRequest();
155     EXPECT_NE(req, nullptr);
156 
157     req->SetIsAgentNotification(true);
158     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
159     MockIsSystemApp(false);
160     MockIsVerfyPermisson(false);
161 
162     ASSERT_EQ(advancedNotificationService_->PrepareNotificationRequest(req), ERR_ANS_NON_SYSTEM_APP);
163 }
164 
165 /**
166  * @tc.number    : AnsBranchTest_223000
167  * @tc.name      : PrepareNotificationRequest_2000
168  * @tc.desc      : Test PrepareNotificationRequest function return ERR_ANS_PERMISSION_DENIED.
169  * @tc.require   : #I6P8UI
170  */
171 HWTEST_F(AnsBranchTest, AnsBranchTest_223000, Function | SmallTest | Level1)
172 {
173     sptr<NotificationRequest> req = new NotificationRequest();
174     EXPECT_NE(req, nullptr);
175 
176     req->SetIsAgentNotification(true);
177     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
178     MockIsVerfyPermisson(false);
179     ASSERT_EQ(advancedNotificationService_->PrepareNotificationRequest(req), ERR_ANS_PERMISSION_DENIED);
180 }
181 
182 /**
183  * @tc.number    : AnsBranchTest_224000
184  * @tc.name      : Publish_1000
185  * @tc.desc      : Test Publish function req is false.
186  * @tc.require   : #I6P8UI
187  */
188 HWTEST_F(AnsBranchTest, AnsBranchTest_224000, Function | SmallTest | Level1)
189 {
190     std::string label = "publish's label";
191     ASSERT_EQ(advancedNotificationService_->Publish(label, nullptr), ERR_ANS_INVALID_PARAM);
192 }
193 
194 /**
195  * @tc.number    : AnsBranchTest_225000
196  * @tc.name      : CancelAsBundle_1000
197  * @tc.desc      : Test CancelAsBundle function return ERR_ANS_NON_SYSTEM_APP.
198  * @tc.require   : #I6P8UI
199  */
200 HWTEST_F(AnsBranchTest, AnsBranchTest_225000, Function | SmallTest | Level1)
201 {
202     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
203     MockIsSystemApp(false);
204 
205     int32_t notificationId = 1;
206     std::string representativeBundle = "RepresentativeBundle";
207     int32_t userId = 1;
208     ASSERT_EQ(advancedNotificationService_->CancelAsBundle(
209         notificationId, representativeBundle, userId), ERR_ANS_NON_SYSTEM_APP);
210 }
211 
212 /**
213  * @tc.number    : AnsBranchTest_226000
214  * @tc.name      : CancelAsBundle_2000
215  * @tc.desc      : Test CancelAsBundle function return ERR_ANS_PERMISSION_DENIED.
216  * @tc.require   : #I6P8UI
217  */
218 HWTEST_F(AnsBranchTest, AnsBranchTest_226000, Function | SmallTest | Level1)
219 {
220     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
221     MockIsVerfyPermisson(false);
222 
223     int32_t notificationId = 1;
224     std::string representativeBundle = "RepresentativeBundle";
225     int32_t userId = 1;
226     ASSERT_EQ(advancedNotificationService_->CancelAsBundle(
227         notificationId, representativeBundle, userId), ERR_ANS_PERMISSION_DENIED);
228 }
229 
230 /**
231  * @tc.number    : AnsBranchTest_227000
232  * @tc.name      : AddSlots_2000
233  * @tc.desc      : Test AddSlots function return ERR_ANS_PERMISSION_DENIED.
234  * @tc.require   : #I6P8UI
235  */
236 HWTEST_F(AnsBranchTest, AnsBranchTest_227000, Function | SmallTest | Level1)
237 {
238     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
239     MockIsVerfyPermisson(false);
240 
241     std::vector<sptr<NotificationSlot>> slots;
242     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::OTHER);
243     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::OTHER);
244     slots.push_back(slot0);
245     slots.push_back(slot1);
246     ASSERT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_PERMISSION_DENIED);
247 }
248 
249 /**
250  * @tc.number    : AnsBranchTest_228000
251  * @tc.name      : Delete_1000
252  * @tc.desc      : Test Delete function return ERR_ANS_PERMISSION_DENIED.
253  * @tc.require   : #I6P8UI
254  */
255 HWTEST_F(AnsBranchTest, AnsBranchTest_228000, Function | SmallTest | Level1)
256 {
257     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
258     MockIsVerfyPermisson(false);
259 
260     const std::string key = "key";
261     ASSERT_EQ(advancedNotificationService_->Delete(
262         key, NotificationConstant::CANCEL_REASON_DELETE), ERR_ANS_PERMISSION_DENIED);
263 }
264 
265 /**
266  * @tc.number    : AnsBranchTest_229000
267  * @tc.name      : DeleteByBundle_1000
268  * @tc.desc      : Test DeleteByBundle function return ERR_ANS_PERMISSION_DENIED.
269  * @tc.require   : #I6P8UI
270  */
271 HWTEST_F(AnsBranchTest, AnsBranchTest_229000, Function | SmallTest | Level1)
272 {
273     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
274     MockIsVerfyPermisson(false);
275 
276     ASSERT_EQ(advancedNotificationService_->DeleteByBundle(
277         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID)), ERR_ANS_PERMISSION_DENIED);
278 }
279 
280 /**
281  * @tc.number    : AnsBranchTest_230000
282  * @tc.name      : DeleteByBundle_2000
283  * @tc.desc      : Test DeleteByBundle function return ERR_ANS_NON_SYSTEM_APP.
284  * @tc.require   : #I6P8UI
285  */
286 HWTEST_F(AnsBranchTest, AnsBranchTest_230000, Function | SmallTest | Level1)
287 {
288     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
289     MockIsSystemApp(false);
290 
291     ASSERT_EQ(advancedNotificationService_->DeleteByBundle(
292         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID)), ERR_ANS_NON_SYSTEM_APP);
293 }
294 
295 /**
296  * @tc.number    : AnsBranchTest_231000
297  * @tc.name      : DeleteAll_1000
298  * @tc.desc      : Test DeleteAll function return ERR_ANS_PERMISSION_DENIED.
299  * @tc.require   : #I6P8UI
300  */
301 HWTEST_F(AnsBranchTest, AnsBranchTest_231000, Function | SmallTest | Level1)
302 {
303     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
304     MockIsVerfyPermisson(false);
305 
306     ASSERT_EQ(advancedNotificationService_->DeleteAll(), ERR_ANS_PERMISSION_DENIED);
307 }
308 
309 /**
310  * @tc.number    : AnsBranchTest_232000
311  * @tc.name      : GetSlotsByBundle_1000
312  * @tc.desc      : Test GetSlotsByBundle function return ERR_ANS_NON_SYSTEM_APP.
313  * @tc.require   : #I6P8UI
314  */
315 HWTEST_F(AnsBranchTest, AnsBranchTest_232000, Function | SmallTest | Level1)
316 {
317     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
318     MockIsSystemApp(false);
319 
320     std::vector<sptr<NotificationSlot>> slots;
321     ASSERT_EQ(advancedNotificationService_->GetSlotsByBundle(
322         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), slots), ERR_ANS_NON_SYSTEM_APP);
323 }
324 
325 /**
326  * @tc.number    : AnsBranchTest_233000
327  * @tc.name      : GetSlotsByBundle_2000
328  * @tc.desc      : Test GetSlotsByBundle function return ERR_ANS_PERMISSION_DENIED.
329  * @tc.require   : #I6P8UI
330  */
331 HWTEST_F(AnsBranchTest, AnsBranchTest_233000, Function | SmallTest | Level1)
332 {
333     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
334     MockIsVerfyPermisson(false);
335 
336     std::vector<sptr<NotificationSlot>> slots;
337     ASSERT_EQ(advancedNotificationService_->GetSlotsByBundle(
338         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), slots), ERR_ANS_PERMISSION_DENIED);
339 }
340 
341 /**
342  * @tc.number    : AnsBranchTest_234000
343  * @tc.name      : UpdateSlots_1000
344  * @tc.desc      : Test UpdateSlots function return ERR_ANS_NON_SYSTEM_APP.
345  * @tc.require   : #I6P8UI
346  */
347 HWTEST_F(AnsBranchTest, AnsBranchTest_234000, Function | SmallTest | Level1)
348 {
349     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
350     MockIsSystemApp(false);
351 
352     std::vector<sptr<NotificationSlot>> slots;
353     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::OTHER);
354     slots.push_back(slot0);
355     ASSERT_EQ(advancedNotificationService_->UpdateSlots(
356         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), slots), ERR_ANS_NON_SYSTEM_APP);
357 }
358 
359 /**
360  * @tc.number    : AnsBranchTest_235000
361  * @tc.name      : UpdateSlots_1000
362  * @tc.desc      : Test UpdateSlots function return ERR_ANS_PERMISSION_DENIED.
363  * @tc.require   : #I6P8UI
364  */
365 HWTEST_F(AnsBranchTest, AnsBranchTest_235000, Function | SmallTest | Level1)
366 {
367     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
368     MockIsVerfyPermisson(false);
369 
370     std::vector<sptr<NotificationSlot>> slots;
371     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::OTHER);
372     slots.push_back(slot0);
373     ASSERT_EQ(advancedNotificationService_->UpdateSlots(
374         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), slots), ERR_ANS_PERMISSION_DENIED);
375 }
376 
377 /**
378  * @tc.number    : AnsBranchTest_236000
379  * @tc.name      : SetShowBadgeEnabledForBundle_1000
380  * @tc.desc      : Test SetShowBadgeEnabledForBundle function return ERR_ANS_PERMISSION_DENIED.
381  * @tc.require   : #I6P8UI
382  */
383 HWTEST_F(AnsBranchTest, AnsBranchTest_236000, Function | SmallTest | Level1)
384 {
385     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
386     MockIsVerfyPermisson(false);
387 
388     ASSERT_EQ(advancedNotificationService_->SetShowBadgeEnabledForBundle(
389         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), true), ERR_ANS_PERMISSION_DENIED);
390 }
391 
392 /**
393  * @tc.number    : AnsBranchTest_237000
394  * @tc.name      : GetShowBadgeEnabledForBundle_1000
395  * @tc.desc      : Test GetShowBadgeEnabledForBundle function return ERR_ANS_NON_SYSTEM_APP.
396  * @tc.require   : #I6P8UI
397  */
398 HWTEST_F(AnsBranchTest, AnsBranchTest_237000, Function | SmallTest | Level1)
399 {
400     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
401     MockIsSystemApp(false);
402 
403     bool allow = false;
404     ASSERT_EQ(advancedNotificationService_->GetShowBadgeEnabledForBundle(
405         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), allow), ERR_ANS_NON_SYSTEM_APP);
406 }
407 
408 /**
409  * @tc.number    : AnsBranchTest_238000
410  * @tc.name      : GetShowBadgeEnabledForBundle_2000
411  * @tc.desc      : Test GetShowBadgeEnabledForBundle function return ERR_ANS_PERMISSION_DENIED.
412  * @tc.require   : #I6P8UI
413  */
414 HWTEST_F(AnsBranchTest, AnsBranchTest_238000, Function | SmallTest | Level1)
415 {
416     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
417     MockIsVerfyPermisson(false);
418 
419     bool allow = false;
420     ASSERT_EQ(advancedNotificationService_->GetShowBadgeEnabledForBundle(
421         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), allow), ERR_ANS_PERMISSION_DENIED);
422 }
423 
424 /**
425  * @tc.number    : AnsBranchTest_239000
426  * @tc.name      : Subscribe_1000
427  * @tc.desc      : Test Subscribe function return ERR_ANS_NON_SYSTEM_APP.
428  * @tc.require   : #I6P8UI
429  */
430 HWTEST_F(AnsBranchTest, AnsBranchTest_239000, Function | SmallTest | Level1)
431 {
432     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
433     MockIsSystemApp(false);
434 
435     auto subscriber = new TestAnsSubscriber();
436     sptr<NotificationSubscribeInfo> info = new NotificationSubscribeInfo();
437     ASSERT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_ANS_NON_SYSTEM_APP);
438 }
439 
440 /**
441  * @tc.number    : AnsBranchTest_240000
442  * @tc.name      : Subscribe_1000
443  * @tc.desc      : Test Subscribe function return ERR_ANS_PERMISSION_DENIED.
444  * @tc.require   : #I6P8UI
445  */
446 HWTEST_F(AnsBranchTest, AnsBranchTest_240000, Function | SmallTest | Level1)
447 {
448     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
449     MockIsVerfyPermisson(false);
450 
451     auto subscriber = new TestAnsSubscriber();
452     sptr<NotificationSubscribeInfo> info = new NotificationSubscribeInfo();
453     ASSERT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_ANS_PERMISSION_DENIED);
454 }
455 
456 /**
457  * @tc.number    : AnsBranchTest_241000
458  * @tc.name      : Unsubscribe_1000
459  * @tc.desc      : Test Unsubscribe function return ERR_ANS_PERMISSION_DENIED.
460  * @tc.require   : #I6P8UI
461  */
462 HWTEST_F(AnsBranchTest, AnsBranchTest_241000, Function | SmallTest | Level1)
463 {
464     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
465     MockIsVerfyPermisson(false);
466 
467     auto subscriber = new TestAnsSubscriber();
468     sptr<NotificationSubscribeInfo> info = new NotificationSubscribeInfo();
469     ASSERT_EQ(advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), info), ERR_ANS_PERMISSION_DENIED);
470 }
471 
472 /**
473  * @tc.number    : AnsBranchTest_242000
474  * @tc.name      : GetAllActiveNotifications_1000
475  * @tc.desc      : Test GetAllActiveNotifications function return ERR_ANS_PERMISSION_DENIED.
476  * @tc.require   : #I6P8UI
477  */
478 HWTEST_F(AnsBranchTest, AnsBranchTest_242000, Function | SmallTest | Level1)
479 {
480     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
481     MockIsVerfyPermisson(false);
482 
483     std::vector<sptr<Notification>> allNotifications;
484     ASSERT_EQ(advancedNotificationService_->GetAllActiveNotifications(allNotifications), ERR_ANS_PERMISSION_DENIED);
485 }
486 
487 /**
488  * @tc.number    : AnsBranchTest_243000
489  * @tc.name      : GetSpecialActiveNotifications_1000
490  * @tc.desc      : Test GetSpecialActiveNotifications function return ERR_ANS_NON_SYSTEM_APP.
491  * @tc.require   : #I6P8UI
492  */
493 HWTEST_F(AnsBranchTest, AnsBranchTest_243000, Function | SmallTest | Level1)
494 {
495     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
496     MockIsSystemApp(false);
497 
498     std::vector<std::string> keys;
499     std::vector<sptr<Notification>> specialActiveNotifications;
500     ASSERT_EQ(advancedNotificationService_->GetSpecialActiveNotifications(
501         keys, specialActiveNotifications), ERR_ANS_NON_SYSTEM_APP);
502 }
503 
504 /**
505  * @tc.number    : AnsBranchTest_244000
506  * @tc.name      : GetSpecialActiveNotifications_2000
507  * @tc.desc      : Test GetSpecialActiveNotifications function return ERR_ANS_PERMISSION_DENIED.
508  * @tc.require   : #I6P8UI
509  */
510 HWTEST_F(AnsBranchTest, AnsBranchTest_244000, Function | SmallTest | Level1)
511 {
512     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
513     MockIsVerfyPermisson(false);
514 
515     std::vector<std::string> keys;
516     std::vector<sptr<Notification>> specialActiveNotifications;
517     ASSERT_EQ(advancedNotificationService_->GetSpecialActiveNotifications(
518         keys, specialActiveNotifications), ERR_ANS_PERMISSION_DENIED);
519 }
520 
521 /**
522  * @tc.number    : AnsBranchTest_245000
523  * @tc.name      : SetNotificationsEnabledForAllBundles_2000
524  * @tc.desc      : Test SetNotificationsEnabledForAllBundles function return ERR_ANS_NON_SYSTEM_APP.
525  * @tc.require   : #I6P8UI
526  */
527 HWTEST_F(AnsBranchTest, AnsBranchTest_245000, Function | SmallTest | Level1)
528 {
529     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
530     MockIsSystemApp(false);
531 
532     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForAllBundles(
533         std::string(), true), ERR_ANS_NON_SYSTEM_APP);
534 }
535 
536 /**
537  * @tc.number    : AnsBranchTest_246000
538  * @tc.name      : SetNotificationsEnabledForAllBundles_1000
539  * @tc.desc      : Test SetNotificationsEnabledForAllBundles function return ERR_ANS_PERMISSION_DENIED.
540  * @tc.require   : #I6P8UI
541  */
542 HWTEST_F(AnsBranchTest, AnsBranchTest_246000, Function | SmallTest | Level1)
543 {
544     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
545     MockIsVerfyPermisson(false);
546 
547     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForAllBundles(
548         std::string(), true), ERR_ANS_PERMISSION_DENIED);
549 }
550 
551 /**
552  * @tc.number    : AnsBranchTest_247000
553  * @tc.name      : SetNotificationsEnabledForSpecialBundle_1000
554  * @tc.desc      : Test SetNotificationsEnabledForSpecialBundle function return ERR_ANS_PERMISSION_DENIED.
555  * @tc.require   : #I6P8UI
556  */
557 HWTEST_F(AnsBranchTest, AnsBranchTest_247000, Function | SmallTest | Level1)
558 {
559     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
560     MockIsVerfyPermisson(false);
561 
562     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
563         std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), false),
564             ERR_ANS_PERMISSION_DENIED);
565 }
566 
567 /**
568  * @tc.number    : AnsBranchTest_248000
569  * @tc.name      : IsAllowedNotify_1000
570  * @tc.desc      : Test IsAllowedNotify function return ERR_ANS_NON_SYSTEM_APP.
571  * @tc.require   : #I6P8UI
572  */
573 HWTEST_F(AnsBranchTest, AnsBranchTest_248000, Function | SmallTest | Level1)
574 {
575     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
576     MockIsSystemApp(false);
577 
578     bool allowed = false;
579     ASSERT_EQ(advancedNotificationService_->IsAllowedNotify(allowed), ERR_ANS_NON_SYSTEM_APP);
580 }
581 
582 /**
583  * @tc.number    : AnsBranchTest_249000
584  * @tc.name      : IsAllowedNotify_2000
585  * @tc.desc      : Test IsAllowedNotify function return ERR_ANS_PERMISSION_DENIED.
586  * @tc.require   : #I6P8UI
587  */
588 HWTEST_F(AnsBranchTest, AnsBranchTest_249000, Function | SmallTest | Level1)
589 {
590     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
591     MockIsVerfyPermisson(false);
592 
593     bool allowed = false;
594     ASSERT_EQ(advancedNotificationService_->IsAllowedNotify(allowed), ERR_ANS_PERMISSION_DENIED);
595 }
596 
597 /**
598  * @tc.number    : AnsBranchTest_250000
599  * @tc.name      : GetAppTargetBundle_1000
600  * @tc.desc      : Test GetAppTargetBundle function return ERR_ANS_NON_SYSTEM_APP.
601  * @tc.require   : #I6P8UI
602  */
603 HWTEST_F(AnsBranchTest, AnsBranchTest_250000, Function | SmallTest | Level1)
604 {
605     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
606     MockIsSystemApp(false);
607 
608     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
609     sptr<NotificationBundleOption> targetBundle(nullptr);
610     bundleOption->SetBundleName("test");
611     ASSERT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, targetBundle), ERR_ANS_NON_SYSTEM_APP);
612 }
613 
614 /**
615  * @tc.number    : AnsBranchTest_251000
616  * @tc.name      : IsSpecialBundleAllowedNotify_1000
617  * @tc.desc      : Test IsSpecialBundleAllowedNotify function return ERR_ANS_NON_SYSTEM_APP.
618  * @tc.require   : #I6P8UI
619  */
620 HWTEST_F(AnsBranchTest, AnsBranchTest_251000, Function | SmallTest | Level1)
621 {
622     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
623     MockIsSystemApp(false);
624 
625     bool allowed = true;
626     ASSERT_EQ(advancedNotificationService_->IsSpecialBundleAllowedNotify(
627         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), allowed), ERR_ANS_NON_SYSTEM_APP);
628 }
629 
630 /**
631  * @tc.number    : AnsBranchTest_252000
632  * @tc.name      : IsSpecialBundleAllowedNotify_2000
633  * @tc.desc      : Test IsSpecialBundleAllowedNotify function return ERR_ANS_PERMISSION_DENIED.
634  * @tc.require   : #I6P8UI
635  */
636 HWTEST_F(AnsBranchTest, AnsBranchTest_252000, Function | SmallTest | Level1)
637 {
638     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
639     MockIsVerfyPermisson(false);
640 
641     bool allowed = true;
642     ASSERT_EQ(advancedNotificationService_->IsSpecialBundleAllowedNotify(
643         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), allowed), ERR_ANS_PERMISSION_DENIED);
644 }
645 
646 /**
647  * @tc.number    : AnsBranchTest_254000
648  * @tc.name      : IsSpecialBundleAllowedNotify_4000
649  * @tc.desc      : Test IsSpecialBundleAllowedNotify function return ERR_ANS_PERMISSION_DENIED.
650  * @tc.require   : #I6P8UI
651  */
652 HWTEST_F(AnsBranchTest, AnsBranchTest_254000, Function | SmallTest | Level1)
653 {
654     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
655     MockIsVerfyPermisson(true);
656 
657     MockIsNonBundleName(true);
658     bool allowed = true;
659     ASSERT_EQ(advancedNotificationService_->IsSpecialBundleAllowedNotify(
660         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), allowed), ERR_ANS_INVALID_BUNDLE);
661 }
662 
663 /**
664  * @tc.number    : AnsBranchTest_255000
665  * @tc.name      : RemoveNotification_1000
666  * @tc.desc      : Test RemoveNotification function return ERR_ANS_PERMISSION_DENIED.
667  * @tc.require   : #I6P8UI
668  */
669 HWTEST_F(AnsBranchTest, AnsBranchTest_255000, Function | SmallTest | Level1)
670 {
671     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
672     MockIsVerfyPermisson(false);
673 
674     int32_t notificationId = 1;
675     std::string label = "testRemove";
676     auto result = advancedNotificationService_->RemoveNotification(
677         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID),
678         notificationId, label, NotificationConstant::CANCEL_REASON_DELETE);
679     ASSERT_EQ(result, ERR_ANS_PERMISSION_DENIED);
680 }
681 
682 /**
683  * @tc.number    : AnsBranchTest_256000
684  * @tc.name      : RemoveAllNotifications_1000
685  * @tc.desc      : Test RemoveAllNotifications function return ERR_ANS_PERMISSION_DENIED.
686  * @tc.require   : #I6P8UI
687  */
688 HWTEST_F(AnsBranchTest, AnsBranchTest_256000, Function | SmallTest | Level1)
689 {
690     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
691     MockIsVerfyPermisson(false);
692 
693     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
694     ASSERT_EQ(advancedNotificationService_->RemoveAllNotifications(bundleOption), ERR_ANS_PERMISSION_DENIED);
695 }
696 
697 /**
698  * @tc.number    : AnsBranchTest_257000
699  * @tc.name      : GetSlotNumAsBundle_1000
700  * @tc.desc      : Test GetSlotNumAsBundle function return ERR_ANS_NON_SYSTEM_APP.
701  * @tc.require   : #I6P8UI
702  */
703 HWTEST_F(AnsBranchTest, AnsBranchTest_257000, Function | SmallTest | Level1)
704 {
705     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
706     MockIsSystemApp(false);
707 
708     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
709     uint64_t num = 1;
710     ASSERT_EQ(advancedNotificationService_->GetSlotNumAsBundle(bundleOption, num), ERR_ANS_NON_SYSTEM_APP);
711 }
712 
713 /**
714  * @tc.number    : AnsBranchTest_258000
715  * @tc.name      : GetSlotNumAsBundle_2000
716  * @tc.desc      : Test GetSlotNumAsBundle function return ERR_ANS_PERMISSION_DENIED.
717  * @tc.require   : #I6P8UI
718  */
719 HWTEST_F(AnsBranchTest, AnsBranchTest_258000, Function | SmallTest | Level1)
720 {
721     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
722     MockIsVerfyPermisson(false);
723 
724     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
725     uint64_t num = 1;
726     ASSERT_EQ(advancedNotificationService_->GetSlotNumAsBundle(bundleOption, num), ERR_ANS_PERMISSION_DENIED);
727 }
728 
729 /**
730  * @tc.number    : AnsBranchTest_259000
731  * @tc.name      : RemoveGroupByBundle_2000
732  * @tc.desc      : Test RemoveGroupByBundle function return ERR_ANS_PERMISSION_DENIED.
733  * @tc.require   : #I6P8UI
734  */
735 HWTEST_F(AnsBranchTest, AnsBranchTest_259000, Function | SmallTest | Level1)
736 {
737     MockVerifyNativeToken(false);
738     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
739     MockIsVerfyPermisson(false);
740 
741     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
742     std::string groupName = "group";
743     ASSERT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), ERR_ANS_PERMISSION_DENIED);
744 }
745 
746 /**
747  * @tc.number    : AnsBranchTest_260000
748  * @tc.name      : SetDoNotDisturbDate_1000
749  * @tc.desc      : Test SetDoNotDisturbDate function return ERR_ANS_NON_SYSTEM_APP.
750  * @tc.require   : #I6P8UI
751  */
752 HWTEST_F(AnsBranchTest, AnsBranchTest_260000, Function | SmallTest | Level1)
753 {
754     MockVerifyNativeToken(false);
755     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
756     MockIsSystemApp(false);
757 
758     sptr<NotificationDoNotDisturbDate> date =
759         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0);
760     ASSERT_EQ(advancedNotificationService_->SetDoNotDisturbDate(date), ERR_ANS_NON_SYSTEM_APP);
761     ASSERT_EQ(advancedNotificationService_->GetDoNotDisturbDate(date), ERR_ANS_NON_SYSTEM_APP);
762 }
763 
764 /**
765  * @tc.number    : AnsBranchTest_261000
766  * @tc.name      : SetDoNotDisturbDate_2000
767  * @tc.desc      : Test SetDoNotDisturbDate function return ERR_ANS_PERMISSION_DENIED.
768  * @tc.require   : #I6P8UI
769  */
770 HWTEST_F(AnsBranchTest, AnsBranchTest_261000, Function | SmallTest | Level1)
771 {
772     MockVerifyNativeToken(false);
773     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
774     MockIsVerfyPermisson(false);
775 
776     sptr<NotificationDoNotDisturbDate> date =
777         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0);
778     ASSERT_EQ(advancedNotificationService_->SetDoNotDisturbDate(date), ERR_ANS_PERMISSION_DENIED);
779     ASSERT_EQ(advancedNotificationService_->GetDoNotDisturbDate(date), ERR_ANS_PERMISSION_DENIED);
780 }
781 
782 /**
783  * @tc.number    : AnsBranchTest_262000
784  * @tc.name      : DoesSupportDoNotDisturbMode_1000
785  * @tc.desc      : Test DoesSupportDoNotDisturbMode function return ERR_ANS_NON_SYSTEM_APP.
786  * @tc.require   : #I6P8UI
787  */
788 HWTEST_F(AnsBranchTest, AnsBranchTest_262000, Function | SmallTest | Level1)
789 {
790     MockIsSystemApp(false);
791     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
792 
793     bool doesSupport = true;
794     ASSERT_EQ(advancedNotificationService_->DoesSupportDoNotDisturbMode(doesSupport), ERR_ANS_NON_SYSTEM_APP);
795 }
796 
797 /**
798  * @tc.number    : AnsBranchTest_263000
799  * @tc.name      : DoesSupportDoNotDisturbMode_2000
800  * @tc.desc      : Test DoesSupportDoNotDisturbMode function return ERR_ANS_PERMISSION_DENIED.
801  * @tc.require   : #I6P8UI
802  */
803 HWTEST_F(AnsBranchTest, AnsBranchTest_263000, Function | SmallTest | Level1)
804 {
805     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
806     MockIsVerfyPermisson(false);
807 
808     bool doesSupport = true;
809     ASSERT_EQ(advancedNotificationService_->DoesSupportDoNotDisturbMode(doesSupport), ERR_ANS_PERMISSION_DENIED);
810 }
811 
812 /**
813  * @tc.number    : AnsBranchTest_264000
814  * @tc.name      : EnableDistributed_1000
815  * @tc.desc      : Test EnableDistributed function return ERR_ANS_NON_SYSTEM_APP.
816  * @tc.require   : #I6P8UI
817  */
818 HWTEST_F(AnsBranchTest, AnsBranchTest_264000, Function | SmallTest | Level1)
819 {
820     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
821     MockIsSystemApp(false);
822 
823     bool enabled = true;
824     sptr<NotificationBundleOption> bundleOption =
825         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
826     ASSERT_EQ(advancedNotificationService_->EnableDistributed(enabled), ERR_ANS_NON_SYSTEM_APP);
827     ASSERT_EQ(advancedNotificationService_->EnableDistributedByBundle(bundleOption, enabled), ERR_ANS_NON_SYSTEM_APP);
828     ASSERT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enabled), ERR_ANS_NON_SYSTEM_APP);
829 }
830 
831 /**
832  * @tc.number    : AnsBranchTest_284000
833  * @tc.name      : EnableDistributed_2000
834  * @tc.desc      : Test EnableDistributed function return ERR_ANS_PERMISSION_DENIED.
835  * @tc.require   : #I6P8UI
836  */
837 HWTEST_F(AnsBranchTest, AnsBranchTest_284000, Function | SmallTest | Level1)
838 {
839     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
840     MockIsVerfyPermisson(false);
841 
842     bool enabled = true;
843     sptr<NotificationBundleOption> bundleOption =
844         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
845     ASSERT_EQ(advancedNotificationService_->EnableDistributed(enabled), ERR_ANS_PERMISSION_DENIED);
846     ASSERT_EQ(advancedNotificationService_->EnableDistributedByBundle(
847         bundleOption, enabled), ERR_ANS_PERMISSION_DENIED);
848     ASSERT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(
849         bundleOption, enabled), ERR_ANS_PERMISSION_DENIED);
850 }
851 
852 /**
853  * @tc.number    : AnsBranchTest_265000
854  * @tc.name      : GetDeviceRemindType_1000
855  * @tc.desc      : Test GetDeviceRemindType function return ERR_ANS_NON_SYSTEM_APP.
856  * @tc.require   : #I6P8UI
857  */
858 HWTEST_F(AnsBranchTest, AnsBranchTest_265000, Function | SmallTest | Level1)
859 {
860     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
861     MockIsSystemApp(false);
862 
863     NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND;
864     ASSERT_EQ(advancedNotificationService_->GetDeviceRemindType(remindType), ERR_ANS_NON_SYSTEM_APP);
865 }
866 
867 /**
868  * @tc.number    : AnsBranchTest_266000
869  * @tc.name      : GetDeviceRemindType_2000
870  * @tc.desc      : Test GetDeviceRemindType function return ERR_ANS_PERMISSION_DENIED.
871  * @tc.require   : #I6P8UI
872  */
873 HWTEST_F(AnsBranchTest, AnsBranchTest_266000, Function | SmallTest | Level1)
874 {
875     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
876     MockIsVerfyPermisson(false);
877 
878     NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND;
879     ASSERT_EQ(advancedNotificationService_->GetDeviceRemindType(remindType), ERR_ANS_PERMISSION_DENIED);
880 }
881 
882 /**
883  * @tc.number    : AnsBranchTest_267000
884  * @tc.name      : IsSpecialUserAllowedNotify_1000
885  * @tc.desc      : Test IsSpecialUserAllowedNotify function return ERR_ANS_PERMISSION_DENIED.
886  * @tc.require   : #I6P8UI
887  */
888 HWTEST_F(AnsBranchTest, AnsBranchTest_267000, Function | SmallTest | Level1)
889 {
890     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
891     MockIsVerfyPermisson(false);
892 
893     int32_t userId = 3;
894     bool allowed = true;
895     bool enable = true;
896     ASSERT_EQ(advancedNotificationService_->IsSpecialUserAllowedNotify(
897         userId, allowed), (int)ERR_ANS_PERMISSION_DENIED);
898     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledByUser(
899         userId, enable), (int)ERR_ANS_PERMISSION_DENIED);
900 }
901 
902 /**
903  * @tc.number    : AnsBranchTest_267100
904  * @tc.name      : IsSpecialUserAllowedNotify_1000
905  * @tc.desc      : Test IsSpecialUserAllowedNotify function return ERR_ANS_NON_SYSTEM_APP.
906  * @tc.require   : #I6P8UI
907  */
908 HWTEST_F(AnsBranchTest, AnsBranchTest_267100, Function | SmallTest | Level1)
909 {
910     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
911     MockIsSystemApp(false);
912 
913     int32_t userId = 3;
914     bool allowed = true;
915     bool enable = true;
916     ASSERT_EQ(advancedNotificationService_->IsSpecialUserAllowedNotify(
917         userId, allowed), (int)ERR_ANS_NON_SYSTEM_APP);
918     ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledByUser(
919         userId, enable), (int)ERR_ANS_NON_SYSTEM_APP);
920 }
921 
922 /**
923  * @tc.number    : AnsBranchTest_268000
924  * @tc.name      : SetDoNotDisturbDate_1000
925  * @tc.desc      : Test SetDoNotDisturbDate function return ERR_ANS_NON_SYSTEM_APP.
926  * @tc.require   : #I6P8UI
927  */
928 HWTEST_F(AnsBranchTest, AnsBranchTest_268000, Function | SmallTest | Level1)
929 {
930     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
931     MockIsSystemApp(false);
932 
933     int32_t userId = 3;
934     sptr<NotificationDoNotDisturbDate> date = nullptr;
935     ASSERT_EQ(advancedNotificationService_->SetDoNotDisturbDate(userId, date), ERR_ANS_NON_SYSTEM_APP);
936     ASSERT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_ANS_NON_SYSTEM_APP);
937 }
938 
939 /**
940  * @tc.number    : AnsBranchTest_269000
941  * @tc.name      : SetDoNotDisturbDate_2000
942  * @tc.desc      : Test SetDoNotDisturbDate function return ERR_ANS_PERMISSION_DENIED.
943  * @tc.require   : #I6P8UI
944  */
945 HWTEST_F(AnsBranchTest, AnsBranchTest_269000, Function | SmallTest | Level1)
946 {
947     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
948     MockIsVerfyPermisson(false);
949 
950     int32_t userId = 3;
951     sptr<NotificationDoNotDisturbDate> date = nullptr;
952     ASSERT_EQ(advancedNotificationService_->SetDoNotDisturbDate(userId, date), ERR_ANS_PERMISSION_DENIED);
953     ASSERT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_ANS_PERMISSION_DENIED);
954 }
955 
956 /**
957  * @tc.number    : AnsBranchTest_270000
958  * @tc.name      : SetEnabledForBundleSlot_1000
959  * @tc.desc      : Test SetEnabledForBundleSlot function return ERR_ANS_PERMISSION_DENIED.
960  * @tc.require   : #I6P8UI
961  */
962 HWTEST_F(AnsBranchTest, AnsBranchTest_270000, Function | SmallTest | Level1)
963 {
964     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
965     MockIsVerfyPermisson(false);
966 
967     bool enabled = false;
968     bool isForceControl = false;
969     auto result = advancedNotificationService_->SetEnabledForBundleSlot(
970         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID),
971             NotificationConstant::SlotType::SOCIAL_COMMUNICATION, enabled, false);
972 
973     ASSERT_EQ(result, ERR_ANS_PERMISSION_DENIED);
974     auto result1 = advancedNotificationService_->GetEnabledForBundleSlot(
975         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID),
976             NotificationConstant::SlotType::SOCIAL_COMMUNICATION, enabled);
977     ASSERT_EQ(result1, ERR_ANS_PERMISSION_DENIED);
978 }
979 
980 /**
981  * @tc.number    : AnsBranchTest_271000
982  * @tc.name      : SetEnabledForBundleSlot_1000
983  * @tc.desc      : Test SetEnabledForBundleSlot function return ERR_ANS_PERMISSION_DENIED.
984  * @tc.require   : #I6P8UI
985  */
986 HWTEST_F(AnsBranchTest, AnsBranchTest_271000, Function | SmallTest | Level1)
987 {
988     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
989     MockVerifyShellToken(false);
990 
991     std::string cmd = "CMD";
992     std::string bundle = "Bundle";
993     int32_t userId = 4;
994     std::vector<std::string> dumpInfo;
995     ASSERT_EQ(advancedNotificationService_->ShellDump(
996         cmd, bundle, userId, 0, dumpInfo), (int)ERR_ANS_PERMISSION_DENIED);
997 }
998 
999 /**
1000  * @tc.number    : AnsBranchTest_272000
1001  * @tc.name      : SetSyncNotificationEnabledWithoutApp_1000
1002  * @tc.desc      : Test SetSyncNotificationEnabledWithoutApp function return ERR_ANS_NON_SYSTEM_APP.
1003  * @tc.require   : #I6P8UI
1004  */
1005 HWTEST_F(AnsBranchTest, AnsBranchTest_272000, Function | SmallTest | Level1)
1006 {
1007     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
1008     MockIsSystemApp(false);
1009 
1010     int32_t userId = 3;
1011     bool enabled = true;
1012     ASSERT_EQ(advancedNotificationService_->SetSyncNotificationEnabledWithoutApp(
1013         userId, enabled), ERR_ANS_NON_SYSTEM_APP);
1014     ASSERT_EQ(advancedNotificationService_->GetSyncNotificationEnabledWithoutApp(
1015         userId, enabled), ERR_ANS_NON_SYSTEM_APP);
1016 }
1017 
1018 /**
1019  * @tc.number    : AnsBranchTest_273000
1020  * @tc.name      : SetSyncNotificationEnabledWithoutApp_2000
1021  * @tc.desc      : Test SetSyncNotificationEnabledWithoutApp function return ERR_ANS_PERMISSION_DENIED.
1022  * @tc.require   : #I6P8UI
1023  */
1024 HWTEST_F(AnsBranchTest, AnsBranchTest_273000, Function | SmallTest | Level1)
1025 {
1026     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
1027     MockIsVerfyPermisson(false);
1028 
1029     int32_t userId = 3;
1030     bool enabled = true;
1031     ASSERT_EQ(advancedNotificationService_->SetSyncNotificationEnabledWithoutApp(
1032         userId, enabled), ERR_ANS_PERMISSION_DENIED);
1033     ASSERT_EQ(advancedNotificationService_->GetSyncNotificationEnabledWithoutApp(
1034         userId, enabled), ERR_ANS_PERMISSION_DENIED);
1035 }
1036 
1037 /**
1038  * @tc.number    : AnsBranchTest_274000
1039  * @tc.name      : EnableDistributedByBundle_3000
1040  * @tc.desc      : Test EnableDistributedByBundle function return ERR_ANS_NON_SYSTEM_APP.
1041  * @tc.require   : #I6P8UI
1042  */
1043 HWTEST_F(AnsBranchTest, AnsBranchTest_274000, Function | SmallTest | Level1)
1044 {
1045     MockGetDistributedEnableInApplicationInfo(false, 2);
1046     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
1047     MockIsSystemApp(false);
1048     bool enabled = true;
1049     sptr<NotificationBundleOption> bundleOption =
1050         new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
1051     ASSERT_EQ(advancedNotificationService_->EnableDistributedByBundle(
1052         bundleOption, enabled), ERR_ANS_NON_SYSTEM_APP);
1053 }
1054 
1055 /**
1056  * @tc.number    : AnsBranchTest_275000
1057  * @tc.name      : EnableDistributedSelf_2000
1058  * @tc.desc      : Test EnableDistributedSelf function return ERR_ANS_PERMISSION_DENIED.
1059  * @tc.require   : #I6P8UI
1060  */
1061 HWTEST_F(AnsBranchTest, AnsBranchTest_275000, Function | SmallTest | Level1)
1062 {
1063     MockDistributedNotificationEnabled(false);
1064     MockIsNonBundleName(false);
1065     bool enabled = true;
1066     ASSERT_EQ(advancedNotificationService_->EnableDistributedSelf(enabled), (int)ERR_ANS_PERMISSION_DENIED);
1067 }
1068 
1069 /**
1070  * @tc.number    : AnsBranchTest_276000
1071  * @tc.name      : IsDistributedEnableByBundle_3000
1072  * @tc.desc      : Test IsDistributedEnableByBundle function return ERR_ANS_PERMISSION_DENIED.
1073  * @tc.require   : #I6P8UI
1074  */
1075 HWTEST_F(AnsBranchTest, AnsBranchTest_276000, Function | SmallTest | Level1)
1076 {
1077     MockIsSystemApp(true);
1078     MockIsVerfyPermisson(true);
1079     MockVerifyNativeToken(true);
1080     MockGetDistributedEnableInApplicationInfo(true, 2);
1081     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(
1082         TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
1083     bool enabled = false;
1084     ASSERT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enabled), ERR_OK);
1085 }
1086 
1087 /**
1088  * @tc.number    : AnsBranchTest_277000
1089  * @tc.name      : DoDistributedPublish_3000
1090  * @tc.desc      : Test DoDistributedPublish function return ERR_ANS_PERMISSION_DENIED.
1091  * @tc.require   : #I6P8UI
1092  */
1093 HWTEST_F(AnsBranchTest, AnsBranchTest_277000, Function | SmallTest | Level1)
1094 {
1095     MockGetDistributedEnableInApplicationInfo(false, 2);
1096     MockGetOsAccountLocalIdFromUid(false, 1);
1097     MockDistributedNotificationEnabled(false);
1098     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(
1099         TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
1100     std::shared_ptr<NotificationRecord> record = nullptr;
1101     ASSERT_EQ(advancedNotificationService_->DoDistributedPublish(bundleOption, record), ERR_OK);
1102 }
1103 
1104 /**
1105  * @tc.number    : AnsBranchTest_278000
1106  * @tc.name      : GetDistributedEnableInApplicationInfo_3000
1107  * @tc.desc      : Test GetDistributedEnableInApplicationInfo function return ERR_ANS_PERMISSION_DENIED.
1108  * @tc.require   : #I6P8UI
1109  */
1110 HWTEST_F(AnsBranchTest, AnsBranchTest_278000, Function | SmallTest | Level1)
1111 {
1112     MockGetOsAccountLocalIdFromUid(false, 3);
1113     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(
1114         TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
1115     bool enabled = false;;
1116     ASSERT_EQ(advancedNotificationService_->GetDistributedEnableInApplicationInfo(
1117         bundleOption, enabled), ERR_ANS_INVALID_PARAM);
1118 }
1119 
InitNotificationRecord(std::shared_ptr<NotificationRecord> & record,const NotificationLiveViewContent::LiveViewStatus & status)1120 void AnsBranchTest::InitNotificationRecord(std::shared_ptr<NotificationRecord> &record,
1121     const NotificationLiveViewContent::LiveViewStatus &status)
1122 {
1123     NotificationRequest notificationRequest;
1124     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
1125     auto liveContent = std::make_shared<NotificationLiveViewContent>();
1126     liveContent->SetLiveViewStatus(status);
1127     auto content = std::make_shared<NotificationContent>(liveContent);
1128     notificationRequest.SetContent(content);
1129 
1130     record->request = sptr<NotificationRequest>::MakeSptr(notificationRequest);
1131     record->notification = new (std::nothrow) Notification(record->request);
1132 }
1133 
1134 /**
1135  * @tc.number    : AnsBranchTest_279000
1136  * @tc.name      : UpdateNotificationTimerInfo_0001
1137  * @tc.desc      : Check set update and finish timer when create notification request
1138  * @tc.require   : issue
1139  */
1140 HWTEST_F(AnsBranchTest, AnsBranchTest_279000, Function | SmallTest | Level1)
1141 {
1142     using Status = NotificationLiveViewContent::LiveViewStatus;
1143     auto record = std::make_shared<NotificationRecord>();
1144     InitNotificationRecord(record, Status::LIVE_VIEW_CREATE);
1145     ASSERT_EQ(record->notification->GetFinishTimer(), NotificationConstant::INVALID_TIMER_ID);
1146     ASSERT_EQ(record->notification->GetUpdateTimer(), NotificationConstant::INVALID_TIMER_ID);
1147     auto result = advancedNotificationService_->UpdateNotificationTimerInfo(record);
1148     ASSERT_EQ(result, ERR_OK);
1149     EXPECT_NE(record->notification->GetFinishTimer(), NotificationConstant::INVALID_TIMER_ID);
1150     EXPECT_NE(record->notification->GetUpdateTimer(), NotificationConstant::INVALID_TIMER_ID);
1151 }
1152 
1153 /**
1154  * @tc.number    : AnsBranchTest_279001
1155  * @tc.name      : UpdateNotificationTimerInfo_0002
1156  * @tc.desc      : Check set update and finish timer when update notification request
1157  * @tc.require   : issue
1158  */
1159 HWTEST_F(AnsBranchTest, AnsBranchTest_279001, Function | SmallTest | Level1)
1160 {
1161     using Status = NotificationLiveViewContent::LiveViewStatus;
1162     auto record = std::make_shared<NotificationRecord>();
1163     InitNotificationRecord(record, Status::LIVE_VIEW_INCREMENTAL_UPDATE);
1164     record->notification->SetUpdateTimer(2);
1165     record->notification->SetFinishTimer(3);
1166     auto result = advancedNotificationService_->UpdateNotificationTimerInfo(record);
1167     ASSERT_EQ(result, ERR_OK);
1168     /* finish timer not change, but update timer changed */
1169     EXPECT_NE(record->notification->GetUpdateTimer(), 2);
1170     ASSERT_EQ(record->notification->GetFinishTimer(), 3);
1171 }
1172 
1173 /**
1174  * @tc.number    : AnsBranchTest_279002
1175  * @tc.name      : UpdateNotificationTimerInfo_0003
1176  * @tc.desc      : Check cancel update and finish timer when end notification request
1177  * @tc.require   : issue
1178  */
1179 HWTEST_F(AnsBranchTest, AnsBranchTest_279002, Function | SmallTest | Level1)
1180 {
1181     using Status = NotificationLiveViewContent::LiveViewStatus;
1182     auto record = std::make_shared<NotificationRecord>();
1183     InitNotificationRecord(record, Status::LIVE_VIEW_END);
1184     record->notification->SetUpdateTimer(2);
1185     record->notification->SetFinishTimer(3);
1186 
1187     auto result = advancedNotificationService_->UpdateNotificationTimerInfo(record);
1188     ASSERT_EQ(result, ERR_OK);
1189     /* finish timer not change, but update timer changed */
1190     ASSERT_EQ(record->notification->GetUpdateTimer(), NotificationConstant::INVALID_TIMER_ID);
1191     ASSERT_EQ(record->notification->GetFinishTimer(), NotificationConstant::INVALID_TIMER_ID);
1192 }
1193 
1194 /**
1195  * @tc.number    : AnsBranchTest_285000
1196  * @tc.name      : IsNeedSilentInDoNotDisturbMode_1000
1197  * @tc.desc      : Test IsNeedSilentInDoNotDisturbMode function return ERR_ANS_NON_SYSTEM_APP.
1198  */
1199 HWTEST_F(AnsBranchTest, AnsBranchTest_285000, Function | SmallTest | Level1)
1200 {
1201     MockIsSystemApp(false);
1202     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
1203 
1204     std::string phoneNumber = "11111111111";
1205     int32_t callerType = 0;
1206     ASSERT_EQ(advancedNotificationService_->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType), -1);
1207 }
1208 
1209 /**
1210  * @tc.number    : AnsBranchTest_286000
1211  * @tc.name      : IsNeedSilentInDoNotDisturbMode_2000
1212  * @tc.desc      : Test IsNeedSilentInDoNotDisturbMode function return ERR_ANS_PERMISSION_DENIED.
1213  */
1214 HWTEST_F(AnsBranchTest, AnsBranchTest_286000, Function | SmallTest | Level1)
1215 {
1216     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
1217     MockIsVerfyPermisson(false);
1218 
1219     std::string phoneNumber = "11111111111";
1220     int32_t callerType = 0;
1221     ASSERT_EQ(advancedNotificationService_->IsNeedSilentInDoNotDisturbMode(
1222         phoneNumber, callerType), ERR_ANS_PERMISSION_DENIED);
1223 }
1224 }  // namespace Notification
1225 }  // namespace OHOS
1226