• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "sec_comp_info_helper_test.h"
17 
18 #include "accesstoken_kit.h"
19 #include "display.h"
20 #include "display_info.h"
21 #include "display_manager.h"
22 #include "location_button.h"
23 #include "paste_button.h"
24 #include "save_button.h"
25 #include "sec_comp_log.h"
26 #include "sec_comp_err.h"
27 #include "sec_comp_tool.h"
28 #include "service_test_common.h"
29 #include "window_manager.h"
30 
31 using namespace testing::ext;
32 using namespace OHOS;
33 using namespace OHOS::Security::SecurityComponent;
34 
35 namespace {
36 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
37     LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompInfoHelperTest"};
38 static double g_curScreenWidth = 0.0F;
39 static double g_curScreenHeight = 0.0F;
40 static double g_testWidth = 0.0F;
41 static double g_testHeight = 0.0F;
42 
GetScreenSize()43 static bool GetScreenSize()
44 {
45     sptr<OHOS::Rosen::Display> display =
46         OHOS::Rosen::DisplayManager::GetInstance().GetDefaultDisplaySync();
47     if (display == nullptr) {
48         return false;
49     }
50 
51     auto info = display->GetDisplayInfo();
52     if (info == nullptr) {
53         return false;
54     }
55 
56     g_curScreenWidth = static_cast<double>(info->GetWidth());
57     g_curScreenHeight = static_cast<double>(info->GetHeight());
58     return true;
59 }
60 }
61 
SetUpTestCase()62 void SecCompInfoHelperTest::SetUpTestCase()
63 {
64     ASSERT_TRUE(GetScreenSize());
65     g_testWidth = (ServiceTestCommon::ZERO_OFFSET + g_curScreenWidth) / ServiceTestCommon::QUARTER;
66     g_testHeight = (ServiceTestCommon::ZERO_OFFSET + g_curScreenHeight) / ServiceTestCommon::QUARTER;
67 }
68 
TearDownTestCase()69 void SecCompInfoHelperTest::TearDownTestCase()
70 {}
71 
SetUp()72 void SecCompInfoHelperTest::SetUp()
73 {
74     SC_LOG_INFO(LABEL, "setup");
75     Rosen::WindowManager::GetInstance().SetDefaultSecCompScene();
76 }
77 
TearDown()78 void SecCompInfoHelperTest::TearDown()
79 {}
80 
81 /**
82  * @tc.name: ParseComponent001
83  * @tc.desc: Test parse component info success
84  * @tc.type: FUNC
85  * @tc.require: AR000HO9J7
86  */
87 HWTEST_F(SecCompInfoHelperTest, ParseComponent001, TestSize.Level1)
88 {
89     nlohmann::json jsonComponent;
90     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
91     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
92     ASSERT_NE(nullptr, comp);
93     ASSERT_TRUE(comp->GetValid());
94 }
95 
96 /**
97  * @tc.name: ParseComponent002
98  * @tc.desc: Test parse component info with empty json
99  * @tc.type: FUNC
100  * @tc.require: AR000HO9J7
101  */
102 HWTEST_F(SecCompInfoHelperTest, ParseComponent002, TestSize.Level1)
103 {
104     nlohmann::json jsonComponent;
105     ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(UNKNOWN_SC_TYPE, jsonComponent));
106 
107     ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent));
108     ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(PASTE_COMPONENT, jsonComponent));
109     ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(SAVE_COMPONENT, jsonComponent));
110 }
111 
112 /**
113  * @tc.name: ParseComponent003
114  * @tc.desc: Test parse component info with invalid type
115  * @tc.type: FUNC
116  * @tc.require: AR000HO9J7
117  */
118 HWTEST_F(SecCompInfoHelperTest, ParseComponent003, TestSize.Level1)
119 {
120     nlohmann::json jsonComponent;
121     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
122 
123     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
124     ASSERT_TRUE(comp->GetValid());
125 
126     jsonComponent[JsonTagConstants::JSON_SC_TYPE] = UNKNOWN_SC_TYPE;
127     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
128     ASSERT_EQ(nullptr, comp);
129 }
130 
GetDefaultRect(void)131 static SecCompRect GetDefaultRect(void)
132 {
133     SecCompRect rect = {
134         .x_ = g_testWidth,
135         .y_ = g_testHeight,
136         .width_ = g_testWidth,
137         .height_ = g_testHeight
138     };
139     return rect;
140 }
141 
142 /**
143  * @tc.name: ParseComponent004
144  * @tc.desc: Test parse component info with invalid rect
145  * @tc.type: FUNC
146  * @tc.require: AR000HO9J7
147  */
148 HWTEST_F(SecCompInfoHelperTest, ParseComponent004, TestSize.Level1)
149 {
150     SecCompRect rect = GetDefaultRect();
151     SecCompRect windowRect = GetDefaultRect();
152     ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
153 
154     rect.x_ = ServiceTestCommon::TEST_INVALID_DIMENSION;
155     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
156     rect.x_ = g_testWidth;
157 
158     rect.y_ = ServiceTestCommon::TEST_INVALID_DIMENSION;
159     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
160     rect.y_ = g_testHeight;
161 
162     rect.x_ = g_curScreenWidth + 1;
163     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
164     rect.x_ = g_testWidth;
165 
166     rect.y_ = g_curScreenHeight + 1;
167     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
168     rect.y_ = g_testHeight;
169 
170     rect.width_ = g_curScreenWidth;
171     rect.height_ = g_curScreenHeight;
172     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
173     rect.width_ = g_testWidth;
174     rect.height_ = g_testHeight;
175 
176     rect.x_ = g_curScreenWidth - g_testWidth;
177     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
178     rect.x_ = g_testWidth;
179     rect.y_ = g_curScreenHeight - g_testHeight;
180 
181     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
182     rect.y_ = g_testHeight;
183 }
184 
185 /**
186  * @tc.name: ParseComponent005
187  * @tc.desc: Test parse component info with windowRect invalid
188  * @tc.type: FUNC
189  * @tc.require: AR000HO9J7
190  */
191 HWTEST_F(SecCompInfoHelperTest, ParseComponent005, TestSize.Level1)
192 {
193     SecCompRect rect = GetDefaultRect();
194     SecCompRect windowRect = GetDefaultRect();
195     ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
196 
197     windowRect.x_ = g_testWidth + 1;
198     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
199     windowRect.x_ = g_testWidth;
200 
201     windowRect.y_ = g_testHeight + 1;
202     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
203     windowRect.y_ = g_testHeight;
204 
205     windowRect.width_ = g_testWidth - 1;
206     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
207     windowRect.width_ = g_testWidth;
208 
209     windowRect.height_ = g_testHeight - 1;
210     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
211     windowRect.height_ = g_testHeight;
212 
213     windowRect.width_ = ServiceTestCommon::TEST_INVALID_DIMENSION;
214     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
215     windowRect.width_ = g_testWidth;
216 
217     windowRect.height_ = ServiceTestCommon::TEST_INVALID_DIMENSION;
218     ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect));
219     windowRect.height_ = g_testHeight;
220 }
221 
222 /**
223  * @tc.name: ParseComponent006
224  * @tc.desc: Test parse component info with parentEffect active
225  * @tc.type: FUNC
226  * @tc.require: AR000HO9J7
227  */
228 HWTEST_F(SecCompInfoHelperTest, ParseComponent006, TestSize.Level1)
229 {
230     nlohmann::json jsonComponent;
231     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
232 
233     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
234     ASSERT_TRUE(comp->GetValid());
235 
236     jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json {
237         { JsonTagConstants::JSON_PARENT_EFFECT_TAG, true },
238         { JsonTagConstants::JSON_IS_CLIPPED_TAG, false },
239         { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 },
240         { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 },
241         { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 },
242         { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 },
243         { JsonTagConstants::JSON_PARENT_TAG_TAG, "" },
244     };
245     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
246     ASSERT_FALSE(comp->GetValid());
247 }
248 
249 /**
250  * @tc.name: ParseComponent007
251  * @tc.desc: Test parse component info with invalid size
252  * @tc.type: FUNC
253  * @tc.require: AR000HO9J7
254  */
255 HWTEST_F(SecCompInfoHelperTest, ParseComponent007, TestSize.Level1)
256 {
257     nlohmann::json jsonComponent;
258     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
259 
260     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
261     ASSERT_TRUE(comp->GetValid());
262 
263     auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG];
264     sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION;
265     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
266     ASSERT_FALSE(comp->GetValid());
267 
268     sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = ServiceTestCommon::TEST_DIMENSION;
269     sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION;
270     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
271     ASSERT_FALSE(comp->GetValid());
272 
273     sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = ServiceTestCommon::TEST_DIMENSION;
274     sizeJson[JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION;
275     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
276     ASSERT_FALSE(comp->GetValid());
277 }
278 
279 /**
280  * @tc.name: ParseComponent008
281  * @tc.desc: Test parse component info with invalid size
282  * @tc.type: FUNC
283  * @tc.require: AR000HO9J7
284  */
285 HWTEST_F(SecCompInfoHelperTest, ParseComponent008, TestSize.Level1)
286 {
287     nlohmann::json jsonComponent;
288     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
289     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
290     ASSERT_TRUE(comp->GetValid());
291 
292     auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG];
293     auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG];
294     paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION;
295     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
296     ASSERT_FALSE(comp->GetValid());
297 
298     paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = ServiceTestCommon::TEST_DIMENSION;
299     paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION;
300     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
301     ASSERT_FALSE(comp->GetValid());
302 }
303 
304 /**
305  * @tc.name: ParseComponent009
306  * @tc.desc: Test parse component info with invalid size
307  * @tc.type: FUNC
308  * @tc.require: AR000HO9J7
309  */
310 HWTEST_F(SecCompInfoHelperTest, ParseComponent009, TestSize.Level1)
311 {
312     nlohmann::json jsonComponent;
313     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
314     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
315     ASSERT_TRUE(comp->GetValid());
316 
317     auto& sizesJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG];
318     auto& paddingsJson = sizesJson[JsonTagConstants::JSON_PADDING_SIZE_TAG];
319     paddingsJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION;
320     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
321     ASSERT_FALSE(comp->GetValid());
322 
323     paddingsJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = ServiceTestCommon::TEST_DIMENSION;
324     paddingsJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION;
325     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
326     ASSERT_FALSE(comp->GetValid());
327 }
328 
329 /**
330  * @tc.name: ParseComponent010
331  * @tc.desc: Test parse component info with invalid color
332  * @tc.type: FUNC
333  * @tc.require: AR000HO9J7
334  */
335 HWTEST_F(SecCompInfoHelperTest, ParseComponent010, TestSize.Level1)
336 {
337     nlohmann::json jsonComponent;
338     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
339     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
340     ASSERT_TRUE(comp->GetValid());
341 
342     auto& colorJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG];
343     colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_INVALID;
344     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
345     ASSERT_FALSE(comp->GetValid());
346 
347     colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_RED;
348     colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_INVALID;
349     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
350     ASSERT_FALSE(comp->GetValid());
351 }
352 
353 /**
354  * @tc.name: ParseComponent011
355  * @tc.desc: Test parse component info with invalid style
356  * @tc.type: FUNC
357  * @tc.require: AR000HO9J7
358  */
359 HWTEST_F(SecCompInfoHelperTest, ParseComponent011, TestSize.Level1)
360 {
361     nlohmann::json jsonComponent;
362     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
363     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
364     ASSERT_TRUE(comp->GetValid());
365 
366     jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json {
367         { JsonTagConstants::JSON_TEXT_TAG, NO_TEXT },
368         { JsonTagConstants::JSON_ICON_TAG, NO_ICON },
369         { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE },
370     };
371     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
372     ASSERT_FALSE(comp->GetValid());
373 }
374 
375 /**
376  * @tc.name: ParseComponent012
377  * @tc.desc: Test parse component info with invalid style
378  * @tc.type: FUNC
379  * @tc.require: AR000HO9J7
380  */
381 HWTEST_F(SecCompInfoHelperTest, ParseComponent012, TestSize.Level1)
382 {
383     nlohmann::json jsonComponent;
384     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
385     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
386     ASSERT_TRUE(comp->GetValid());
387 
388     auto& colorsJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG];
389     colorsJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_YELLOW;
390     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
391     ASSERT_FALSE(comp->GetValid());
392 
393     colorsJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_RED;
394     colorsJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_YELLOW;
395     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
396     ASSERT_FALSE(comp->GetValid());
397 
398     auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG];
399     styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::NO_BG_TYPE;
400     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
401     ASSERT_FALSE(comp->GetValid());
402 }
403 
404 /**
405  * @tc.name: ParseComponent013
406  * @tc.desc: Test parse component info with invalid style
407  * @tc.type: FUNC
408  * @tc.require: AR000HO9J7
409  */
410 HWTEST_F(SecCompInfoHelperTest, ParseComponent013, TestSize.Level1)
411 {
412     nlohmann::json jsonComponent;
413     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
414     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
415     ASSERT_TRUE(comp->GetValid());
416 
417     auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG];
418     styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::NO_BG_TYPE;
419     auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG];
420     auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG];
421     paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG;
422     paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG;
423     paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG;
424     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
425     ASSERT_FALSE(comp->GetValid());
426 
427     paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG;
428     paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = ServiceTestCommon::TEST_DIMENSION;
429     paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG;
430     paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG;
431     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
432     ASSERT_FALSE(comp->GetValid());
433 }
434 
435 /**
436  * @tc.name: ParseComponent014
437  * @tc.desc: Test parse component info with invalid style
438  * @tc.type: FUNC
439  * @tc.require: AR000HO9J7
440  */
441 HWTEST_F(SecCompInfoHelperTest, ParseComponent014, TestSize.Level1)
442 {
443     nlohmann::json jsonComponent;
444     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
445     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
446     ASSERT_TRUE(comp->GetValid());
447 
448     auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG];
449     styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::NO_BG_TYPE;
450 
451     auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG];
452     auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG];
453     paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG;
454     paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG;
455     paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG;
456     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
457     ASSERT_FALSE(comp->GetValid());
458 
459     paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG;
460     paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG;
461     paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG;
462     paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = ServiceTestCommon::TEST_DIMENSION;
463     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
464     ASSERT_FALSE(comp->GetValid());
465 }
466 
467 
468 /**
469  * @tc.name: ParseComponent015
470  * @tc.desc: Test parse component info with similar color
471  * @tc.type: FUNC
472  * @tc.require: AR000HO9J7
473  */
474 HWTEST_F(SecCompInfoHelperTest, ParseComponent015, TestSize.Level1)
475 {
476     nlohmann::json jsonComponent;
477     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
478     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
479     ASSERT_TRUE(comp->GetValid());
480 
481     jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json {
482         { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION },
483         { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON },
484         { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }
485     };
486     jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json {
487         { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW },
488         { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLACK },
489         { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }
490     };
491     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
492     ASSERT_FALSE(comp->GetValid());
493 }
494 
495 /**
496  * @tc.name: CheckComponentValid001
497  * @tc.desc: Test CheckComponentValid with invalid color
498  * @tc.type: FUNC
499  * @tc.require: AR000HO9J7
500  */
501 HWTEST_F(SecCompInfoHelperTest, CheckComponentValid001, TestSize.Level1)
502 {
503     nlohmann::json jsonComponent;
504     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
505     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
506     ASSERT_TRUE(comp->GetValid());
507     ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp));
508     jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json {
509         { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED },
510         { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLACK },
511         { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_WHITE }
512     };
513     comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
514     ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp));
515 }
516 
517 /**
518  * @tc.name: CheckComponentValid002
519  * @tc.desc: Test CheckComponentValid with invalid text or icon
520  * @tc.type: FUNC
521  * @tc.require: AR000HO9J7
522  */
523 HWTEST_F(SecCompInfoHelperTest, CheckComponentValid002, TestSize.Level1)
524 {
525     nlohmann::json jsonComponent;
526     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
527     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
528     comp->text_ = UNKNOWN_TEXT;
529     ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp));
530 
531     comp->text_ = static_cast<int32_t>(LocationDesc::SELECT_LOCATION);
532     comp->icon_ = UNKNOWN_ICON;
533     ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp));
534 
535     comp->text_ = UNKNOWN_TEXT;
536     ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp));
537 }
538 
539 /**
540  * @tc.name: CheckComponentValid003
541  * @tc.desc: Test CheckComponentValid with invalid type
542  * @tc.type: FUNC
543  * @tc.require: AR000HO9J7
544  */
545 HWTEST_F(SecCompInfoHelperTest, CheckComponentValid003, TestSize.Level1)
546 {
547     nlohmann::json jsonComponent;
548     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
549     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
550     comp->type_ = SecCompType::UNKNOWN_SC_TYPE;
551     ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp));
552 
553     comp->type_ = SecCompType::MAX_SC_TYPE;
554     ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp));
555 }
556 
557 /**
558  * @tc.name: CheckComponentValid004
559  * @tc.desc: Test CheckComponentValid with window scale changed
560  * @tc.type: FUNC
561  * @tc.require:
562  */
563 HWTEST_F(SecCompInfoHelperTest, CheckComponentValid004, TestSize.Level1)
564 {
565     nlohmann::json jsonComponent;
566     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
567     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
568 
569     Rosen::WindowManager::GetInstance().result_ = Rosen::WMError::WM_OK;
570     std::vector<sptr<Rosen::AccessibilityWindowInfo>> list;
571     sptr<Rosen::AccessibilityWindowInfo> compWin = new Rosen::AccessibilityWindowInfo();
572     compWin->wid_ = 0;
573     compWin->layer_ = 1;
574     compWin->scaleVal_ = 0.99; // change window scale to 0.99
575     list.emplace_back(compWin);
576 
577     sptr<Rosen::AccessibilityWindowInfo> otherWin = new Rosen::AccessibilityWindowInfo();
578     otherWin->wid_ = 1;
579     otherWin->layer_ = 0;
580     otherWin->scaleVal_ = 0.0;
581     list.emplace_back(otherWin);
582     Rosen::WindowManager::GetInstance().list_ = list;
583     ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp));
584 }
585 
586 /**
587  * @tc.name: CheckComponentValid005
588  * @tc.desc: Test CheckComponentValid with get GetWindowScale failed
589  * @tc.type: FUNC
590  * @tc.require:
591  */
592 HWTEST_F(SecCompInfoHelperTest, CheckComponentValid005, TestSize.Level1)
593 {
594     nlohmann::json jsonComponent;
595     ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
596     SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent);
597 
598     Rosen::WindowManager::GetInstance().result_ = static_cast<OHOS::Rosen::WMError>(-1);
599     ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp));
600 }
601 
602 /**
603  * @tc.name: DLP-GrantTempPermission001
604  * @tc.desc: Test DLP sandbox app grant save button
605  * @tc.type: FUNC
606  * @tc.require:
607  */
608 HWTEST_F(SecCompInfoHelperTest, GrantTempPermission001, TestSize.Level1)
609 {
610     OHOS::Security::AccessToken::AccessTokenIDInner tokenInner = {
611         .tokenUniqueID = 0x00001,
612         .res = 1,
613         .dlpFlag = 1,
614         .type = OHOS::Security::AccessToken::TOKEN_HAP,
615         .version = 0,
616     };
617     OHOS::Security::AccessToken::AccessTokenID *tokenid =
618         reinterpret_cast<OHOS::Security::AccessToken::AccessTokenID *>(&tokenInner);
619     ASSERT_NE(0, *tokenid);
620 
621     nlohmann::json jsonComponent;
622     ServiceTestCommon::BuildSaveComponentJson(jsonComponent);
623     SecCompBase* comp = SecCompInfoHelper::ParseComponent(SAVE_COMPONENT, jsonComponent);
624     ASSERT_NE(nullptr, comp);
625     std::shared_ptr<SecCompBase> shared_comp(comp);
626 
627     EXPECT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL,
628         SecCompInfoHelper::GrantTempPermission(*tokenid, shared_comp));
629 }
630 
631 /**
632  * @tc.name: IsColorSimilar001
633  * @tc.desc: Test IsColorSimilar
634  * @tc.type: FUNC
635  * @tc.require:
636  */
637 HWTEST_F(SecCompInfoHelperTest, IsColorSimilar001, TestSize.Level1)
638 {
639     SecCompColor color1 = {
640         .argb = {
641             .red = 0xFF,
642             .green = 0xFF,
643             .blue = 0xFF,
644             .alpha = 0xFF,
645         }
646     };
647 
648     SecCompColor color2 = {
649         .argb = {
650             .red = 0xFF,
651             .green = 0xFF,
652             .blue = 0xFF,
653             .alpha = 0xF0, // different alpha
654         }
655     };
656     EXPECT_TRUE(IsColorSimilar(color1, color2));
657 }
658