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("");
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_264000
748 * @tc.name : EnableDistributed_1000
749 * @tc.desc : Test EnableDistributed function return ERR_ANS_NON_SYSTEM_APP.
750 * @tc.require : #I6P8UI
751 */
752 HWTEST_F(AnsBranchTest, AnsBranchTest_264000, Function | SmallTest | Level1)
753 {
754 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
755 MockIsSystemApp(false);
756
757 bool enabled = true;
758 sptr<NotificationBundleOption> bundleOption =
759 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
760 ASSERT_EQ(advancedNotificationService_->EnableDistributed(enabled), ERR_ANS_NON_SYSTEM_APP);
761 ASSERT_EQ(advancedNotificationService_->EnableDistributedByBundle(bundleOption, enabled), ERR_ANS_NON_SYSTEM_APP);
762 ASSERT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enabled), ERR_ANS_NON_SYSTEM_APP);
763 }
764
765 /**
766 * @tc.number : AnsBranchTest_284000
767 * @tc.name : EnableDistributed_2000
768 * @tc.desc : Test EnableDistributed function return ERR_ANS_PERMISSION_DENIED.
769 * @tc.require : #I6P8UI
770 */
771 HWTEST_F(AnsBranchTest, AnsBranchTest_284000, Function | SmallTest | Level1)
772 {
773 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
774 MockIsVerfyPermisson(false);
775
776 bool enabled = true;
777 sptr<NotificationBundleOption> bundleOption =
778 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
779 ASSERT_EQ(advancedNotificationService_->EnableDistributed(enabled), ERR_ANS_PERMISSION_DENIED);
780 ASSERT_EQ(advancedNotificationService_->EnableDistributedByBundle(
781 bundleOption, enabled), ERR_ANS_PERMISSION_DENIED);
782 ASSERT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(
783 bundleOption, enabled), ERR_ANS_PERMISSION_DENIED);
784 }
785
786 /**
787 * @tc.number : AnsBranchTest_265000
788 * @tc.name : GetDeviceRemindType_1000
789 * @tc.desc : Test GetDeviceRemindType function return ERR_ANS_NON_SYSTEM_APP.
790 * @tc.require : #I6P8UI
791 */
792 HWTEST_F(AnsBranchTest, AnsBranchTest_265000, Function | SmallTest | Level1)
793 {
794 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
795 MockIsSystemApp(false);
796
797 NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND;
798 ASSERT_EQ(advancedNotificationService_->GetDeviceRemindType(remindType), ERR_ANS_NON_SYSTEM_APP);
799 }
800
801 /**
802 * @tc.number : AnsBranchTest_266000
803 * @tc.name : GetDeviceRemindType_2000
804 * @tc.desc : Test GetDeviceRemindType function return ERR_ANS_PERMISSION_DENIED.
805 * @tc.require : #I6P8UI
806 */
807 HWTEST_F(AnsBranchTest, AnsBranchTest_266000, Function | SmallTest | Level1)
808 {
809 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
810 MockIsVerfyPermisson(false);
811
812 NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND;
813 ASSERT_EQ(advancedNotificationService_->GetDeviceRemindType(remindType), ERR_ANS_PERMISSION_DENIED);
814 }
815
816 /**
817 * @tc.number : AnsBranchTest_267000
818 * @tc.name : IsSpecialUserAllowedNotify_1000
819 * @tc.desc : Test IsSpecialUserAllowedNotify function return ERR_ANS_PERMISSION_DENIED.
820 * @tc.require : #I6P8UI
821 */
822 HWTEST_F(AnsBranchTest, AnsBranchTest_267000, Function | SmallTest | Level1)
823 {
824 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
825 MockIsVerfyPermisson(false);
826
827 int32_t userId = 3;
828 bool allowed = true;
829 bool enable = true;
830 ASSERT_EQ(advancedNotificationService_->IsSpecialUserAllowedNotify(
831 userId, allowed), (int)ERR_ANS_PERMISSION_DENIED);
832 ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledByUser(
833 userId, enable), (int)ERR_ANS_PERMISSION_DENIED);
834 }
835
836 /**
837 * @tc.number : AnsBranchTest_267100
838 * @tc.name : IsSpecialUserAllowedNotify_1000
839 * @tc.desc : Test IsSpecialUserAllowedNotify function return ERR_ANS_NON_SYSTEM_APP.
840 * @tc.require : #I6P8UI
841 */
842 HWTEST_F(AnsBranchTest, AnsBranchTest_267100, Function | SmallTest | Level1)
843 {
844 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
845 MockIsSystemApp(false);
846
847 int32_t userId = 3;
848 bool allowed = true;
849 bool enable = true;
850 ASSERT_EQ(advancedNotificationService_->IsSpecialUserAllowedNotify(
851 userId, allowed), (int)ERR_ANS_NON_SYSTEM_APP);
852 ASSERT_EQ(advancedNotificationService_->SetNotificationsEnabledByUser(
853 userId, enable), (int)ERR_ANS_NON_SYSTEM_APP);
854 }
855
856 /**
857 * @tc.number : AnsBranchTest_270000
858 * @tc.name : SetEnabledForBundleSlot_1000
859 * @tc.desc : Test SetEnabledForBundleSlot function return ERR_ANS_PERMISSION_DENIED.
860 * @tc.require : #I6P8UI
861 */
862 HWTEST_F(AnsBranchTest, AnsBranchTest_270000, Function | SmallTest | Level1)
863 {
864 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
865 MockIsVerfyPermisson(false);
866
867 bool enabled = false;
868 bool isForceControl = false;
869 auto result = advancedNotificationService_->SetEnabledForBundleSlot(
870 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID),
871 NotificationConstant::SlotType::SOCIAL_COMMUNICATION, enabled, false);
872
873 ASSERT_EQ(result, ERR_ANS_PERMISSION_DENIED);
874 auto result1 = advancedNotificationService_->GetEnabledForBundleSlot(
875 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID),
876 NotificationConstant::SlotType::SOCIAL_COMMUNICATION, enabled);
877 ASSERT_EQ(result1, ERR_ANS_PERMISSION_DENIED);
878 }
879
880 /**
881 * @tc.number : AnsBranchTest_271000
882 * @tc.name : SetEnabledForBundleSlot_1000
883 * @tc.desc : Test SetEnabledForBundleSlot function return ERR_ANS_PERMISSION_DENIED.
884 * @tc.require : #I6P8UI
885 */
886 HWTEST_F(AnsBranchTest, AnsBranchTest_271000, Function | SmallTest | Level1)
887 {
888 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
889 MockVerifyShellToken(false);
890
891 std::string cmd = "CMD";
892 std::string bundle = "Bundle";
893 int32_t userId = 4;
894 std::vector<std::string> dumpInfo;
895 ASSERT_EQ(advancedNotificationService_->ShellDump(
896 cmd, bundle, userId, 0, dumpInfo), (int)ERR_ANS_PERMISSION_DENIED);
897 }
898
899 /**
900 * @tc.number : AnsBranchTest_272000
901 * @tc.name : SetSyncNotificationEnabledWithoutApp_1000
902 * @tc.desc : Test SetSyncNotificationEnabledWithoutApp function return ERR_ANS_NON_SYSTEM_APP.
903 * @tc.require : #I6P8UI
904 */
905 HWTEST_F(AnsBranchTest, AnsBranchTest_272000, Function | SmallTest | Level1)
906 {
907 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
908 MockIsSystemApp(false);
909
910 int32_t userId = 3;
911 bool enabled = true;
912 ASSERT_EQ(advancedNotificationService_->SetSyncNotificationEnabledWithoutApp(
913 userId, enabled), ERR_ANS_NON_SYSTEM_APP);
914 ASSERT_EQ(advancedNotificationService_->GetSyncNotificationEnabledWithoutApp(
915 userId, enabled), ERR_ANS_NON_SYSTEM_APP);
916 }
917
918 /**
919 * @tc.number : AnsBranchTest_273000
920 * @tc.name : SetSyncNotificationEnabledWithoutApp_2000
921 * @tc.desc : Test SetSyncNotificationEnabledWithoutApp function return ERR_ANS_PERMISSION_DENIED.
922 * @tc.require : #I6P8UI
923 */
924 HWTEST_F(AnsBranchTest, AnsBranchTest_273000, Function | SmallTest | Level1)
925 {
926 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
927 MockIsVerfyPermisson(false);
928
929 int32_t userId = 3;
930 bool enabled = true;
931 ASSERT_EQ(advancedNotificationService_->SetSyncNotificationEnabledWithoutApp(
932 userId, enabled), ERR_ANS_PERMISSION_DENIED);
933 ASSERT_EQ(advancedNotificationService_->GetSyncNotificationEnabledWithoutApp(
934 userId, enabled), ERR_ANS_PERMISSION_DENIED);
935 }
936
937 /**
938 * @tc.number : AnsBranchTest_274000
939 * @tc.name : EnableDistributedByBundle_3000
940 * @tc.desc : Test EnableDistributedByBundle function return ERR_ANS_NON_SYSTEM_APP.
941 * @tc.require : #I6P8UI
942 */
943 HWTEST_F(AnsBranchTest, AnsBranchTest_274000, Function | SmallTest | Level1)
944 {
945 MockGetDistributedEnableInApplicationInfo(false, 2);
946 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
947 MockIsSystemApp(false);
948 bool enabled = true;
949 sptr<NotificationBundleOption> bundleOption =
950 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
951 ASSERT_EQ(advancedNotificationService_->EnableDistributedByBundle(
952 bundleOption, enabled), ERR_ANS_NON_SYSTEM_APP);
953 }
954
955 /**
956 * @tc.number : AnsBranchTest_275000
957 * @tc.name : EnableDistributedSelf_2000
958 * @tc.desc : Test EnableDistributedSelf function return ERR_ANS_PERMISSION_DENIED.
959 * @tc.require : #I6P8UI
960 */
961 HWTEST_F(AnsBranchTest, AnsBranchTest_275000, Function | SmallTest | Level1)
962 {
963 MockDistributedNotificationEnabled(false);
964 MockIsNonBundleName(false);
965 bool enabled = true;
966 ASSERT_EQ(advancedNotificationService_->EnableDistributedSelf(enabled), (int)ERR_ANS_PERMISSION_DENIED);
967 }
968
969 /**
970 * @tc.number : AnsBranchTest_276000
971 * @tc.name : IsDistributedEnableByBundle_3000
972 * @tc.desc : Test IsDistributedEnableByBundle function return ERR_ANS_PERMISSION_DENIED.
973 * @tc.require : #I6P8UI
974 */
975 HWTEST_F(AnsBranchTest, AnsBranchTest_276000, Function | SmallTest | Level1)
976 {
977 MockIsSystemApp(true);
978 MockIsVerfyPermisson(true);
979 MockVerifyNativeToken(true);
980 MockGetDistributedEnableInApplicationInfo(true, 2);
981 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(
982 TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
983 bool enabled = false;
984 ASSERT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enabled), ERR_OK);
985 }
986
987 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
988 /**
989 * @tc.number : AnsBranchTest_277000
990 * @tc.name : DoDistributedPublish_3000
991 * @tc.desc : Test DoDistributedPublish function return ERR_ANS_PERMISSION_DENIED.
992 * @tc.require : #I6P8UI
993 */
994 HWTEST_F(AnsBranchTest, AnsBranchTest_277000, Function | SmallTest | Level1)
995 {
996 MockGetDistributedEnableInApplicationInfo(false, 2);
997 MockGetOsAccountLocalIdFromUid(false, 1);
998 MockDistributedNotificationEnabled(false);
999 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(
1000 TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
1001 std::shared_ptr<NotificationRecord> record = nullptr;
1002 ASSERT_EQ(advancedNotificationService_->DoDistributedPublish(bundleOption, record), ERR_OK);
1003 }
1004
1005 /**
1006 * @tc.number : AnsBranchTest_278000
1007 * @tc.name : GetDistributedEnableInApplicationInfo_3000
1008 * @tc.desc : Test GetDistributedEnableInApplicationInfo function return ERR_ANS_PERMISSION_DENIED.
1009 * @tc.require : #I6P8UI
1010 */
1011 HWTEST_F(AnsBranchTest, AnsBranchTest_278000, Function | SmallTest | Level1)
1012 {
1013 MockGetOsAccountLocalIdFromUid(false, 3);
1014 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(
1015 TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
1016 bool enabled = false;;
1017 ASSERT_EQ(advancedNotificationService_->GetDistributedEnableInApplicationInfo(
1018 bundleOption, enabled), ERR_ANS_INVALID_PARAM);
1019 }
1020 #endif
1021
InitNotificationRecord(std::shared_ptr<NotificationRecord> & record,const NotificationLiveViewContent::LiveViewStatus & status)1022 void AnsBranchTest::InitNotificationRecord(std::shared_ptr<NotificationRecord> &record,
1023 const NotificationLiveViewContent::LiveViewStatus &status)
1024 {
1025 NotificationRequest notificationRequest;
1026 notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
1027 auto liveContent = std::make_shared<NotificationLiveViewContent>();
1028 liveContent->SetLiveViewStatus(status);
1029 auto content = std::make_shared<NotificationContent>(liveContent);
1030 notificationRequest.SetContent(content);
1031
1032 record->request = sptr<NotificationRequest>::MakeSptr(notificationRequest);
1033 record->notification = new (std::nothrow) Notification(record->request);
1034 }
1035
1036 /**
1037 * @tc.number : AnsBranchTest_279000
1038 * @tc.name : UpdateNotificationTimerInfo_0001
1039 * @tc.desc : Check set update and finish timer when create notification request
1040 * @tc.require : issue
1041 */
1042 HWTEST_F(AnsBranchTest, AnsBranchTest_279000, Function | SmallTest | Level1)
1043 {
1044 using Status = NotificationLiveViewContent::LiveViewStatus;
1045 auto record = std::make_shared<NotificationRecord>();
1046 InitNotificationRecord(record, Status::LIVE_VIEW_CREATE);
1047 ASSERT_EQ(record->notification->GetFinishTimer(), NotificationConstant::INVALID_TIMER_ID);
1048 ASSERT_EQ(record->notification->GetUpdateTimer(), NotificationConstant::INVALID_TIMER_ID);
1049 auto result = advancedNotificationService_->UpdateNotificationTimerInfo(record);
1050 ASSERT_EQ(result, ERR_OK);
1051 EXPECT_NE(record->notification->GetFinishTimer(), NotificationConstant::INVALID_TIMER_ID);
1052 EXPECT_NE(record->notification->GetUpdateTimer(), NotificationConstant::INVALID_TIMER_ID);
1053 }
1054
1055 /**
1056 * @tc.number : AnsBranchTest_279001
1057 * @tc.name : UpdateNotificationTimerInfo_0002
1058 * @tc.desc : Check set update and finish timer when update notification request
1059 * @tc.require : issue
1060 */
1061 HWTEST_F(AnsBranchTest, AnsBranchTest_279001, Function | SmallTest | Level1)
1062 {
1063 using Status = NotificationLiveViewContent::LiveViewStatus;
1064 auto record = std::make_shared<NotificationRecord>();
1065 InitNotificationRecord(record, Status::LIVE_VIEW_INCREMENTAL_UPDATE);
1066 record->notification->SetUpdateTimer(2);
1067 record->notification->SetFinishTimer(3);
1068 auto result = advancedNotificationService_->UpdateNotificationTimerInfo(record);
1069 ASSERT_EQ(result, ERR_OK);
1070 /* finish timer not change, but update timer changed */
1071 EXPECT_NE(record->notification->GetUpdateTimer(), 2);
1072 ASSERT_EQ(record->notification->GetFinishTimer(), 3);
1073 }
1074
1075 /**
1076 * @tc.number : AnsBranchTest_279002
1077 * @tc.name : UpdateNotificationTimerInfo_0003
1078 * @tc.desc : Check cancel update and finish timer when end notification request
1079 * @tc.require : issue
1080 */
1081 HWTEST_F(AnsBranchTest, AnsBranchTest_279002, Function | SmallTest | Level1)
1082 {
1083 using Status = NotificationLiveViewContent::LiveViewStatus;
1084 auto record = std::make_shared<NotificationRecord>();
1085 InitNotificationRecord(record, Status::LIVE_VIEW_END);
1086 record->notification->SetUpdateTimer(2);
1087 record->notification->SetFinishTimer(3);
1088
1089 auto result = advancedNotificationService_->UpdateNotificationTimerInfo(record);
1090 ASSERT_EQ(result, ERR_OK);
1091 /* finish timer not change, but update timer changed */
1092 ASSERT_EQ(record->notification->GetUpdateTimer(), NotificationConstant::INVALID_TIMER_ID);
1093 ASSERT_EQ(record->notification->GetFinishTimer(), NotificationConstant::INVALID_TIMER_ID);
1094 }
1095 } // namespace Notification
1096 } // namespace OHOS
1097