diff --git a/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp index 335bb9845ef5f030b4e13cab179f744f335fe963..502233992c739d26270096cf0c3cc2a43c5e2015 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp @@ -54,8 +54,10 @@ HWTEST_F(LocationButtonTest, FromJson001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton comp; - - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -68,7 +70,9 @@ HWTEST_F(LocationButtonTest, FromJson002, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -82,13 +86,15 @@ HWTEST_F(LocationButtonTest, FromJson003, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton comp; - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); jsonComponent[JsonTagConstants::JSON_SC_TYPE] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); jsonComponent[JsonTagConstants::JSON_SC_TYPE] = 0; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -101,29 +107,31 @@ HWTEST_F(LocationButtonTest, FromJson004, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; nlohmann::json wrongJson = nlohmann::json::parse("{", nullptr, false); jsonComponent[JsonTagConstants::JSON_RECT] = wrongJson; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& rectJson = jsonComponent[JsonTagConstants::JSON_RECT]; rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_X] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_Y] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_Y] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_WIDTH] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_WIDTH] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_HEIGHT] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -136,29 +144,31 @@ HWTEST_F(LocationButtonTest, FromJson005, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; nlohmann::json wrongJson = nlohmann::json::parse("{", nullptr, false); jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = wrongJson; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& rectJson = jsonComponent[JsonTagConstants::JSON_WINDOW_RECT]; rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_X] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_Y] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_Y] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_WIDTH] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_WIDTH] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_HEIGHT] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -171,20 +181,22 @@ HWTEST_F(LocationButtonTest, FromJson006, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = TestCommon::TEST_SIZE; sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = TestCommon::TEST_SIZE; sizeJson[JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -197,17 +209,19 @@ HWTEST_F(LocationButtonTest, FromJson007, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = TestCommon::TEST_DIMENSION; paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -220,17 +234,19 @@ HWTEST_F(LocationButtonTest, FromJson008, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = TestCommon::TEST_DIMENSION; paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -243,19 +259,21 @@ HWTEST_F(LocationButtonTest, FromJson009, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json { { JsonTagConstants::JSON_BORDER_WIDTH_TAG, WRONG_TYPE }, }; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); TestCommon::BuildLocationComponentInfo(jsonComponent); jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, WRONG_TYPE }, }; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -269,19 +287,21 @@ HWTEST_F(LocationButtonTest, FromJson010, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; - ASSERT_TRUE(button.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_TEXT_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; styleJson[JsonTagConstants::JSON_ICON_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** @@ -295,19 +315,21 @@ HWTEST_F(LocationButtonTest, FromJson011, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; - ASSERT_TRUE(button.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); auto& colorJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG]; colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = TestCommon::TEST_COLOR_RED; colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = TestCommon::TEST_COLOR_BLUE; colorJson[JsonTagConstants::JSON_BG_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** @@ -321,32 +343,34 @@ HWTEST_F(LocationButtonTest, FromJson012, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; + std::string message; + bool isClicked = true; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::MAX_LABEL_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::MAX_ICON_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** @@ -360,8 +384,10 @@ HWTEST_F(LocationButtonTest, ToJsonStr001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; + std::string message; + bool isClicked = true; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); ASSERT_EQ(jsonComponent.dump(), button.ToJsonStr()); } @@ -392,10 +418,12 @@ HWTEST_F(LocationButtonTest, CompareLocationButton001, TestSize.Level1) LocationButton button2; nlohmann::json jsonComponent; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message, isClicked)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -423,8 +451,10 @@ HWTEST_F(LocationButtonTest, CompareLocationButton002, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp1; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + ASSERT_TRUE(comp1.FromJson(jsonComponent, message, isClicked)); LocationButton comp2 = comp1; comp1.type_ = SAVE_COMPONENT; @@ -489,8 +519,10 @@ HWTEST_F(LocationButtonTest, CompareLocationButton003, TestSize.Level1) LocationButton button1; SaveButton button2; nlohmann::json jsonComponent; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, false)); } diff --git a/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp index d79349ddb51e352852008fe32485db266f0a9f43..e3690123c05b63d67c93c0234704c4893bf53806 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp @@ -53,32 +53,34 @@ HWTEST_F(PasteButtonTest, IsParamValid001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); PasteButton button; + std::string message; + bool isClicked = true; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::PASTE; styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::MAX_LABEL_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::PASTE; styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::MAX_ICON_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** @@ -94,9 +96,11 @@ HWTEST_F(PasteButtonTest, ComparePasteButton001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); + std::string message; + bool isClicked = true; - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message, isClicked)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -124,8 +128,10 @@ HWTEST_F(PasteButtonTest, ComparePasteButton002, TestSize.Level1) { nlohmann::json jsonComponent; PasteButton comp1; + std::string message; + bool isClicked = true; TestCommon::BuildPasteComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + ASSERT_TRUE(comp1.FromJson(jsonComponent, message, isClicked)); PasteButton comp2 = comp1; comp1.type_ = SAVE_COMPONENT; @@ -158,8 +164,10 @@ HWTEST_F(PasteButtonTest, ComparePasteButton003, TestSize.Level1) PasteButton button1; SaveButton button2; nlohmann::json jsonComponent; + std::string message; + bool isClicked = true; TestCommon::BuildPasteComponentInfo(jsonComponent); - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true)); } diff --git a/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp index ffe975ece56f5c4c3b171750a78d8a912d0eaede..6133497beb77ec3d4c7e62e0c1b1a48a7e5c3a61 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp @@ -53,36 +53,38 @@ HWTEST_F(SaveButtonTest, IsParamValid001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildSaveComponentInfo(jsonComponent); SaveButton button; + std::string message; + bool isClicked = true; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); auto& stylesJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; stylesJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::DOWNLOAD; stylesJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::LINE_ICON; stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::MAX_LABEL_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::DOWNLOAD; stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::MAX_ICON_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::LINE_ICON; stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::PICTURE_ICON; stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** @@ -97,10 +99,12 @@ HWTEST_F(SaveButtonTest, CompareSaveButton001, TestSize.Level1) SaveButton button2; nlohmann::json jsonComponent; + std::string message; + bool isClicked = true; TestCommon::BuildSaveComponentInfo(jsonComponent); - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message, isClicked)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -129,7 +133,9 @@ HWTEST_F(SaveButtonTest, CompareSaveButton002, TestSize.Level1) nlohmann::json jsonComponent; SaveButton comp1; TestCommon::BuildSaveComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + ASSERT_TRUE(comp1.FromJson(jsonComponent, message, isClicked)); SaveButton comp2 = comp1; comp1.type_ = PASTE_COMPONENT; @@ -162,8 +168,10 @@ HWTEST_F(SaveButtonTest, CompareSaveButton003, TestSize.Level1) SaveButton button1; PasteButton button2; nlohmann::json jsonComponent; + std::string message; + bool isClicked = true; TestCommon::BuildSaveComponentInfo(jsonComponent); - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true)); } diff --git a/frameworks/security_component/src/location_button.cpp b/frameworks/security_component/src/location_button.cpp index b8c4c388ae6de4c1fe470683d0b184fcacd5a8da..d1ca914e50c68e07fc34a409703d5f8069bc81cd 100644 --- a/frameworks/security_component/src/location_button.cpp +++ b/frameworks/security_component/src/location_button.cpp @@ -24,7 +24,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "LocationButton"}; } -bool LocationButton::IsTextIconTypeValid() +bool LocationButton::IsTextIconTypeValid(std::string &message, bool isClicked) { if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= LocationDesc::MAX_LABEL_TYPE) || (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= LocationIcon::MAX_ICON_TYPE)) { diff --git a/frameworks/security_component/src/paste_button.cpp b/frameworks/security_component/src/paste_button.cpp index 23d353b752ff7a06df2663293e9a0f801edfd8a3..ce0c7dd26aa510c438da02406055b166e9c66db8 100644 --- a/frameworks/security_component/src/paste_button.cpp +++ b/frameworks/security_component/src/paste_button.cpp @@ -24,7 +24,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "PasteButton"}; } -bool PasteButton::IsTextIconTypeValid() +bool PasteButton::IsTextIconTypeValid(std::string& message, bool isClicked) { if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= PasteDesc::MAX_LABEL_TYPE) || (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= PasteIcon::MAX_ICON_TYPE)) { diff --git a/frameworks/security_component/src/save_button.cpp b/frameworks/security_component/src/save_button.cpp index 73a5a9dca912c0882b003b5bb6ac94e29ddc14cd..74073360dbd1d2c4dc1afe30d7616e7b247f6d4c 100644 --- a/frameworks/security_component/src/save_button.cpp +++ b/frameworks/security_component/src/save_button.cpp @@ -26,15 +26,17 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SaveButton"}; } -bool SaveButton::IsTextIconTypeValid() +bool SaveButton::IsTextIconTypeValid(std::string &message, bool isClicked) { if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= SaveDesc::MAX_LABEL_TYPE) || (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= SaveIcon::MAX_ICON_TYPE)) { return false; } - if ((static_cast(icon_) == SaveIcon::PICTURE_ICON) && !IsSystemAppCalling()) { + if (isClicked && (static_cast(icon_) == SaveIcon::PICTURE_ICON) && !IsSystemAppCalling()) { SC_LOG_ERROR(LABEL, "Picture icon only for system application."); + message = ", security component icon type = " + std::to_string(icon_) + + ", picture icon only for system application."; return false; } diff --git a/frameworks/security_component/src/sec_comp_base.cpp b/frameworks/security_component/src/sec_comp_base.cpp index 6d00cd26bf6b17a730a26f9657417887aaffe404..6cf600b3d0403f743867d716aeb008744312fa44 100644 --- a/frameworks/security_component/src/sec_comp_base.cpp +++ b/frameworks/security_component/src/sec_comp_base.cpp @@ -302,7 +302,7 @@ bool SecCompBase::ParseCrossAxisState(const nlohmann::json& json, const std::str return true; } -bool SecCompBase::FromJson(const nlohmann::json& jsonSrc) +bool SecCompBase::FromJson(const nlohmann::json& jsonSrc, std::string& message, bool isClicked) { SC_LOG_DEBUG(LABEL, "Button info %{public}s.", jsonSrc.dump().c_str()); if (!ParseType(jsonSrc, JsonTagConstants::JSON_SC_TYPE)) { @@ -329,7 +329,7 @@ bool SecCompBase::FromJson(const nlohmann::json& jsonSrc) if (!ParseParent(jsonSrc, JsonTagConstants::JSON_PARENT_TAG)) { return false; } - if (!ParseStyle(jsonSrc, JsonTagConstants::JSON_STYLE_TAG)) { + if (!ParseStyle(jsonSrc, JsonTagConstants::JSON_STYLE_TAG, message, isClicked)) { return false; } if (!ParseValue(jsonSrc, JsonTagConstants::JSON_WINDOW_ID, windowId_)) { @@ -436,7 +436,7 @@ bool SecCompBase::CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck return (leftValue == rightValue); } -bool SecCompBase::ParseStyle(const nlohmann::json& json, const std::string& tag) +bool SecCompBase::ParseStyle(const nlohmann::json& json, const std::string& tag, std::string& message, bool isClicked) { if ((json.find(tag) == json.end()) || !json.at(tag).is_object()) { SC_LOG_ERROR(LABEL, "json: %{public}s tag invalid.", tag.c_str()); @@ -460,7 +460,7 @@ bool SecCompBase::ParseStyle(const nlohmann::json& json, const std::string& tag) } text_ = jsonStyle.at(JsonTagConstants::JSON_TEXT_TAG).get(); icon_ = jsonStyle.at(JsonTagConstants::JSON_ICON_TAG).get(); - if (!IsTextIconTypeValid()) { + if (!IsTextIconTypeValid(message, isClicked)) { SC_LOG_ERROR(LABEL, "text or icon is invalid."); return false; } diff --git a/interfaces/inner_api/security_component/include/location_button.h b/interfaces/inner_api/security_component/include/location_button.h index 9788b0ca81b4215306ee74772c1abb2bbd5cfb52..a6b700e5cb25a78d91eeba8d81dd05a82c94ef70 100644 --- a/interfaces/inner_api/security_component/include/location_button.h +++ b/interfaces/inner_api/security_component/include/location_button.h @@ -46,7 +46,7 @@ enum class LocationIcon : int32_t { class __attribute__((visibility("default"))) LocationButton : public SecCompBase { public: - virtual bool IsTextIconTypeValid() override; + virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) override; virtual bool IsCorrespondenceType() override; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const override; private: diff --git a/interfaces/inner_api/security_component/include/paste_button.h b/interfaces/inner_api/security_component/include/paste_button.h index 0e43c8f8fd20dfd4f8068102be74e30a4fbcd519..cc3f4ef5a9658e8d25aeebcd6ab8a0a217a7db66 100644 --- a/interfaces/inner_api/security_component/include/paste_button.h +++ b/interfaces/inner_api/security_component/include/paste_button.h @@ -35,7 +35,7 @@ enum class PasteIcon : int32_t { class __attribute__((visibility("default"))) PasteButton : public SecCompBase { public: - virtual bool IsTextIconTypeValid() override; + virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) override; virtual bool IsCorrespondenceType() override; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const override; diff --git a/interfaces/inner_api/security_component/include/save_button.h b/interfaces/inner_api/security_component/include/save_button.h index b547399c382008d0ae9da0909e78f25b13488abf..ef9d03947e6a6514be406ff06dbbb17be4ac0416 100644 --- a/interfaces/inner_api/security_component/include/save_button.h +++ b/interfaces/inner_api/security_component/include/save_button.h @@ -49,7 +49,7 @@ enum class SaveIcon : int32_t { class __attribute__((visibility("default"))) SaveButton : public SecCompBase { public: - virtual bool IsTextIconTypeValid() override; + virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) override; virtual bool IsCorrespondenceType() override; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const override; private: diff --git a/interfaces/inner_api/security_component/include/sec_comp_base.h b/interfaces/inner_api/security_component/include/sec_comp_base.h index 02f77402da8dc9bff59b4d75b12ce79ece8328eb..a22fd70faba02ba0d3459881c762e1a32a167a19 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_base.h +++ b/interfaces/inner_api/security_component/include/sec_comp_base.h @@ -87,7 +87,7 @@ class __attribute__((visibility("default"))) SecCompBase { public: SecCompBase() = default; virtual ~SecCompBase() = default; - bool FromJson(const nlohmann::json& jsonSrc); + bool FromJson(const nlohmann::json& jsonSrc, std::string& message, bool isClicked); void ToJson(nlohmann::json& jsonRes) const; std::string ToJsonStr(void) const; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const; @@ -138,7 +138,7 @@ public: int32_t nodeId_ = 0; CrossAxisState crossAxisState_ = CrossAxisState::STATE_INVALID; protected: - virtual bool IsTextIconTypeValid() = 0; + virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) = 0; virtual bool IsCorrespondenceType() = 0; private: bool ParseDimension(const nlohmann::json& json, const std::string& tag, DimensionT& res); @@ -151,7 +151,7 @@ private: bool ParseSize(const nlohmann::json& json, const std::string& tag); bool ParseParent(const nlohmann::json& json, const std::string& tag); bool ParseRect(const nlohmann::json& json, const std::string& tag, SecCompRect& rect); - bool ParseStyle(const nlohmann::json& json, const std::string& tag); + bool ParseStyle(const nlohmann::json& json, const std::string& tag, std::string& message, bool isClicked); bool ParseType(const nlohmann::json& json, const std::string& tag); bool ParseValue(const nlohmann::json& json, const std::string& tag, int32_t& value); bool ParseDisplayId(const nlohmann::json& json, const std::string& tag); diff --git a/interfaces/inner_api/security_component_common/sec_comp_info_helper.h b/interfaces/inner_api/security_component_common/sec_comp_info_helper.h index 42005c932bf5c3120e733d45488469c0561ab94a..836138963a2e85f76f640530fdf6a6b3fb5ba873 100644 --- a/interfaces/inner_api/security_component_common/sec_comp_info_helper.h +++ b/interfaces/inner_api/security_component_common/sec_comp_info_helper.h @@ -24,10 +24,10 @@ namespace OHOS { namespace Security { namespace SecurityComponent { template -T* ConstructComponent(const nlohmann::json& jsonComponent) +T* ConstructComponent(const nlohmann::json& jsonComponent, std::string& message, bool isClicked) { T *componentPtr = new (std::nothrow)T(); - if ((componentPtr != nullptr) && !componentPtr->FromJson(jsonComponent)) { + if ((componentPtr != nullptr) && !componentPtr->FromJson(jsonComponent, message, isClicked)) { delete componentPtr; return nullptr; } @@ -36,7 +36,8 @@ T* ConstructComponent(const nlohmann::json& jsonComponent) class __attribute__((visibility("default"))) SecCompInfoHelper { public: - static SecCompBase* ParseComponent(SecCompType type, const nlohmann::json& jsonComponent, std::string& message); + static SecCompBase* ParseComponent(SecCompType type, const nlohmann::json& jsonComponent, + std::string& message, bool isClicked = false); static bool CheckComponentValid(SecCompBase* comp, std::string& message); static bool CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, const uint64_t displayId, const CrossAxisState crossAxisState, std::string& message); diff --git a/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp b/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp index 3f7e0c9e835984f872eabea40f90c1ed53a7d5d4..5f369c47bd31ab31036efce0b34c4afd9d5e1824 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp @@ -59,18 +59,18 @@ void SecCompInfoHelper::AdjustSecCompRect(SecCompBase* comp, float scale) } SecCompBase* SecCompInfoHelper::ParseComponent(SecCompType type, const nlohmann::json& jsonComponent, - std::string& message) + std::string& message, bool isClicked) { SecCompBase* comp = nullptr; switch (type) { case LOCATION_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message, isClicked); break; case PASTE_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message, isClicked); break; case SAVE_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message, isClicked); break; default: SC_LOG_ERROR(LABEL, "Parse component type unknown"); diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp index c1fd80e03ea98aaad44028ad0d32df746462978d..ecc4aa3b95dd3a313d3c677bac62179f081d0c15 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp @@ -454,7 +454,7 @@ int32_t SecCompManager::CheckClickSecurityComponentInfo(std::shared_ptrGetType(), jsonComponent, message); + SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), jsonComponent, message, isClicked_); std::shared_ptr reportComponentInfo(report); int32_t uid = IPCSkeleton::GetCallingUid(); OHOS::AppExecFwk::BundleMgrClient bmsClient; @@ -549,12 +549,12 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(SecCompInfo& info, con SC_LOG_ERROR(LABEL, "Can not find target component"); return SC_SERVICE_ERROR_COMPONENT_NOT_EXIST; } - + isClicked_ = true; int32_t res = CheckClickSecurityComponentInfo(sc, info.scId, compJson, caller, message); if (res != SC_OK) { return res; } - SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), compJson, message); + SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), compJson, message, isClicked_); if (report == nullptr) { return SC_SERVICE_ERROR_COMPONENT_INFO_INVALID; } diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.h b/services/security_component_service/sa/sa_main/sec_comp_manager.h index b57b3634d57fc816a8885194a3e3669ac30ed2f4..97c4b7e16b8876c756741ee853830679a7465d38 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.h +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.h @@ -89,6 +89,7 @@ private: int32_t scIdStart_; bool isSaExit_ = false; int32_t superFoldOffsetY_ = 0; + bool isClicked_ = false; std::shared_ptr secRunner_; std::shared_ptr secHandler_;