diff --git a/frameworks/test/moduletest/BUILD.gn b/frameworks/test/moduletest/BUILD.gn index ea024698b979f5c0e0fc2234f87a6de8ad84c544..5f73269a6e8fa9a6c24d60e4c7a1491994c962c6 100644 --- a/frameworks/test/moduletest/BUILD.gn +++ b/frameworks/test/moduletest/BUILD.gn @@ -139,6 +139,7 @@ ohos_moduletest("ans_innerkits_module_publish_test") { configs = [ "//utils/native/base:utils_config" ] deps = [ + "${aafwk_kits_path}/appkit:app_context", "${core_path}:ans_core", "${frameworks_module_ans_path}:ans_innerkits", "${services_path}/ans:libans", diff --git a/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp index cf378536434ba4f6c4a56ba13fe1b92c77210e70..594f9295b6ca8e23a25455a3a3c96b7ac62b53df 100644 --- a/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -56,6 +56,7 @@ const int32_t CASE_THIRTEEN = 13; const int32_t CASE_FOURTEEN = 14; const int32_t CASE_FIFTEEN = 15; const int32_t CASE_SIXTEEN = 16; +const int32_t CASE_SEVENTEEN = 17; const int32_t PIXEL_MAP_TEST_WIDTH = 32; const int32_t PIXEL_MAP_TEST_HEIGHT = 32; @@ -145,6 +146,8 @@ public: CheckCaseFifteenResult(notificationRequest); } else if (CASE_SIXTEEN == notificationRequest.GetNotificationId()) { CheckCaseSixteenResult(notificationRequest); + } else if (CASE_SEVENTEEN == notificationRequest.GetNotificationId()) { + CheckCaseSeventeenResult(notificationRequest); } else { GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish::OnConsumed do nothing!!!!!"; } @@ -395,6 +398,13 @@ private: EXPECT_EQ(NotificationConstant::FlagStatus::NONE, notiFlags->IsVibrationEnabled()); } } + + void CheckCaseSeventeenResult(NotificationRequest notificationRequest) + { + std::shared_ptr removalWantAgent = + notificationRequest.GetRemovalWantAgent(); + EXPECT_NE(removalWantAgent, nullptr); + } }; class CompletedCallbackTest : public AbilityRuntime::WantAgent::CompletedCallback { @@ -1519,5 +1529,61 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Slot_Enalbe_00200, Func EXPECT_EQ(enable, true); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); } + +/** + * @tc.number : ANS_Interface_MT_Publish_09000 + * @tc.name : Publish_09000 + * @tc.desc : Add removalWantAgent, make a subscriber and publish a removalWantAgent notification. + * @tc.expected : Add removalWantAgent success, make a subscriber and publish removalWantAgent notification success. + */ +HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_09000, Function | MediumTest | Level1) +{ + NotificationSlot slot(NotificationConstant::OTHER); + EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot)); + auto subscriber = TestAnsSubscriber(); + NotificationSubscribeInfo info = NotificationSubscribeInfo(); + info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); + g_subscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); + WaitOnSubscribeResult(); + + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + + auto want = std::make_shared(); + EXPECT_NE(want, nullptr); + want->SetAction("usual.event.REMOVAL_WANTAGENT"); + AppExecFwk::ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + std::vector> wants { want }; + std::vector flags { + AbilityRuntime::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG }; + AbilityRuntime::WantAgent::WantAgentInfo paramsInfo( + 10, + AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, + flags, wants, nullptr + ); + + std::shared_ptr context = + std::make_shared(); + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(context, paramsInfo); + EXPECT_NE(wantAgent, nullptr); + + NotificationRequest req; + req.SetContent(content); + req.SetSlotType(NotificationConstant::OTHER); + req.SetNotificationId(CASE_SEVENTEEN); + req.SetRemovalWantAgent(wantAgent); + g_consumed_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); + WaitOnConsumed(); + g_unsubscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(subscriber, info)); + WaitOnUnsubscribeResult(); +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 26342a3f1008a67dd7114b652bb1be293e6cadb5..26c4c0c170d66f67099b8117a6625ec2076ea96c 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -179,6 +179,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00200, HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00300, Function | SmallTest | Level1) { IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); req->SetSlotType(NotificationConstant::SlotType::CUSTOM); @@ -1587,6 +1588,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10900, HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11000, Function | SmallTest | Level1) { IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); req->SetSlotType(NotificationConstant::SlotType::OTHER); diff --git a/services/ans/test/unittest/mock/mock_access_token_helper.cpp b/services/ans/test/unittest/mock/mock_access_token_helper.cpp index ead552ce069b4c7c348897421950de9e884da883..903342e7ad5e74136f7057ba41d901355c770bf8 100644 --- a/services/ans/test/unittest/mock/mock_access_token_helper.cpp +++ b/services/ans/test/unittest/mock/mock_access_token_helper.cpp @@ -15,6 +15,7 @@ #include "access_token_helper.h" #include "ans_ut_constant.h" +#include "ipc_skeleton.h" namespace OHOS { namespace Notification { @@ -31,7 +32,11 @@ bool AccessTokenHelper::VerifyNativeToken(const Security::AccessToken::AccessTok bool AccessTokenHelper::IsSystemHap() { - return true; + Security::AccessToken::AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID(); + if (tokenId == NATIVE_TOKEN) { + return true; + } + return false; } } // namespace Notification } // namespace OHOS \ No newline at end of file