• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <gtest/gtest.h>
17 
18 #define private public
19 #define protected public
20 #include "extension_config_mgr.h"
21 #include "mock/mock_runtime.h"
22 #undef private
23 #undef protected
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace AbilityRuntime {
30 namespace {
31     constexpr int32_t EXTENSION_TYPE_FORM = 0;
32     constexpr int32_t EXTENSION_TYPE_WORK_SCHEDULER = 1;
33     constexpr int32_t EXTENSION_TYPE_INPUTMETHOD = 2;
34     constexpr int32_t EXTENSION_TYPE_SERVICE = 3;
35     constexpr int32_t EXTENSION_TYPE_ACCESSIBILITY = 4;
36     constexpr int32_t EXTENSION_TYPE_DATASHARE = 5;
37     constexpr int32_t EXTENSION_TYPE_STATICSUBSCRIBER = 7;
38     constexpr int32_t EXTENSION_TYPE_WALLPAPER = 8;
39     constexpr int32_t EXTENSION_TYPE_BACKUP = 9;
40     constexpr int32_t EXTENSION_TYPE_WINDOW = 10;
41     constexpr int32_t EXTENSION_TYPE_ENTERPRISE_ADMIN = 11;
42     constexpr int32_t EXTENSION_TYPE_FILE_ACCESS = 12;
43     constexpr int32_t EXTENSION_TYPE_DRIVER = 18;
44     constexpr char BLOCK_LIST_ITEM_SERVICE_EXTENSION[] = "ServiceExtension";
45     constexpr char BLOCK_LIST_ITEM_FORM_EXTENSION[] = "FormExtension";
46     constexpr char BLOCK_LIST_ITEM_FILE_ACCESS_EXTENSION[] = "FileAccessExtension";
47     constexpr char BLOCK_LIST_ITEM_BACKUP_EXTENSION[] = "BackupExtension";
48     constexpr char BLOCK_LIST_ITEM_ENTERPRISE_ADMIN_EXTENSION[] = "EnterpriseAdminExtension";
49     constexpr char BLOCK_LIST_ITEM_WINDOW_EXTENSION_EXTENSION[] = "WindowExtensionExtension";
50     constexpr char BLOCK_LIST_ITEM_WALLPAPER_EXTENSION[] = "WallpaperExtension";
51     constexpr char BLOCK_LIST_ITEM_STATIC_SUBSCRIBER_EXTENSION[] = "StaticSubscriberExtension";
52     constexpr char BLOCK_LIST_ITEM_ACCESSIBILITY_EXTENSION[] = "AccessibilityExtension";
53     constexpr char BLOCK_LIST_ITEM_INPUT_METHOD_EXTENSION_ABILITY[] = "InputMethodExtensionAbility";
54     constexpr char BLOCK_LIST_ITEM_WORK_SCHEDULER_EXTENSION[] = "WorkSchedulerExtension";
55     constexpr char BLOCK_LIST_ITEM_DATA_SHARE_EXTENSION[] = "DataShareExtension";
56     constexpr char BLOCK_LIST_ITEM_DRIVER_EXTENSION[] = "DriverExtension";
57     constexpr char INVAILD_BLOCK_LIST_ITEM[] = "InvaildExtension";
58 }
59 
60 class ExtensionConfigMgrTest : public testing::Test {
61 public:
62     static void SetUpTestCase();
63     static void TearDownTestCase();
64     void SetUp() override;
65     void TearDown() override;
66 };
67 
SetUpTestCase()68 void ExtensionConfigMgrTest::SetUpTestCase()
69 {}
70 
TearDownTestCase()71 void ExtensionConfigMgrTest::TearDownTestCase()
72 {}
73 
SetUp()74 void ExtensionConfigMgrTest::SetUp()
75 {}
76 
TearDown()77 void ExtensionConfigMgrTest::TearDown()
78 {}
79 
80 /**
81  * @tc.name: Init_0100
82  * @tc.desc: Init Test
83  * @tc.type: FUNC
84  * @tc.require: issueI581T3
85  */
86 HWTEST_F(ExtensionConfigMgrTest, Init_0100, TestSize.Level0)
87 {
88     ExtensionConfigMgr mgr;
89     mgr.Init();
90     bool result = false;
91     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_SERVICE_EXTENSION) != mgr.blocklistConfig_.end());
92     EXPECT_TRUE(result);
93     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_FORM_EXTENSION) != mgr.blocklistConfig_.end());
94     EXPECT_TRUE(result);
95     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_FILE_ACCESS_EXTENSION) != mgr.blocklistConfig_.end());
96     EXPECT_TRUE(result);
97     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_BACKUP_EXTENSION) != mgr.blocklistConfig_.end());
98     EXPECT_TRUE(result);
99     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_ENTERPRISE_ADMIN_EXTENSION) != mgr.blocklistConfig_.end());
100     EXPECT_TRUE(result);
101     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_WINDOW_EXTENSION_EXTENSION) != mgr.blocklistConfig_.end());
102     EXPECT_TRUE(result);
103     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_WALLPAPER_EXTENSION) != mgr.blocklistConfig_.end());
104     EXPECT_TRUE(result);
105     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_STATIC_SUBSCRIBER_EXTENSION) != mgr.blocklistConfig_.end());
106     EXPECT_TRUE(result);
107     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_ACCESSIBILITY_EXTENSION) != mgr.blocklistConfig_.end());
108     EXPECT_TRUE(result);
109     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_INPUT_METHOD_EXTENSION_ABILITY) != mgr.blocklistConfig_.end());
110     EXPECT_TRUE(result);
111     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_WORK_SCHEDULER_EXTENSION) != mgr.blocklistConfig_.end());
112     EXPECT_TRUE(result);
113     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_DATA_SHARE_EXTENSION) != mgr.blocklistConfig_.end());
114     EXPECT_TRUE(result);
115 }
116 
117 /**
118  * @tc.name: AddBlockListItem_0100
119  * @tc.desc: AddBlockListItem Test
120  * @tc.type: FUNC
121  * @tc.require: issueI581T3
122  */
123 HWTEST_F(ExtensionConfigMgrTest, AddBlockListItem_0100, TestSize.Level1)
124 {
125     ExtensionConfigMgr mgr;
126     mgr.Init();
127     bool result = false;
128     mgr.AddBlockListItem(BLOCK_LIST_ITEM_FORM_EXTENSION, EXTENSION_TYPE_FORM);
129     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_FORM) != mgr.extensionBlocklist_.end());
130     EXPECT_TRUE(result);
131     mgr.AddBlockListItem(BLOCK_LIST_ITEM_WORK_SCHEDULER_EXTENSION, EXTENSION_TYPE_WORK_SCHEDULER);
132     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_WORK_SCHEDULER) != mgr.extensionBlocklist_.end());
133     EXPECT_TRUE(result);
134     mgr.AddBlockListItem(BLOCK_LIST_ITEM_INPUT_METHOD_EXTENSION_ABILITY, EXTENSION_TYPE_INPUTMETHOD);
135     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_INPUTMETHOD) != mgr.extensionBlocklist_.end());
136     EXPECT_TRUE(result);
137     mgr.AddBlockListItem(BLOCK_LIST_ITEM_SERVICE_EXTENSION, EXTENSION_TYPE_SERVICE);
138     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_SERVICE) != mgr.extensionBlocklist_.end());
139     EXPECT_TRUE(result);
140     mgr.AddBlockListItem(BLOCK_LIST_ITEM_ACCESSIBILITY_EXTENSION, EXTENSION_TYPE_ACCESSIBILITY);
141     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_ACCESSIBILITY) != mgr.extensionBlocklist_.end());
142     EXPECT_TRUE(result);
143     mgr.AddBlockListItem(BLOCK_LIST_ITEM_DATA_SHARE_EXTENSION, EXTENSION_TYPE_DATASHARE);
144     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_DATASHARE) != mgr.extensionBlocklist_.end());
145     EXPECT_TRUE(result);
146     mgr.AddBlockListItem(BLOCK_LIST_ITEM_STATIC_SUBSCRIBER_EXTENSION, EXTENSION_TYPE_STATICSUBSCRIBER);
147     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_STATICSUBSCRIBER) != mgr.extensionBlocklist_.end());
148     EXPECT_TRUE(result);
149     mgr.AddBlockListItem(BLOCK_LIST_ITEM_WALLPAPER_EXTENSION, EXTENSION_TYPE_WALLPAPER);
150     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_WALLPAPER) != mgr.extensionBlocklist_.end());
151     EXPECT_TRUE(result);
152     mgr.AddBlockListItem(BLOCK_LIST_ITEM_BACKUP_EXTENSION, EXTENSION_TYPE_BACKUP);
153     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_BACKUP) != mgr.extensionBlocklist_.end());
154     EXPECT_TRUE(result);
155     mgr.AddBlockListItem(BLOCK_LIST_ITEM_WINDOW_EXTENSION_EXTENSION, EXTENSION_TYPE_WINDOW);
156     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_WINDOW) != mgr.extensionBlocklist_.end());
157     EXPECT_TRUE(result);
158     mgr.AddBlockListItem(BLOCK_LIST_ITEM_ENTERPRISE_ADMIN_EXTENSION, EXTENSION_TYPE_ENTERPRISE_ADMIN);
159     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_ENTERPRISE_ADMIN) != mgr.extensionBlocklist_.end());
160     EXPECT_TRUE(result);
161     mgr.AddBlockListItem(BLOCK_LIST_ITEM_FILE_ACCESS_EXTENSION, EXTENSION_TYPE_FILE_ACCESS);
162     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_FILE_ACCESS) != mgr.extensionBlocklist_.end());
163     EXPECT_TRUE(result);
164 }
165 
166 /**
167  * @tc.name: AddBlockListItem_0200
168  * @tc.desc: AddBlockListItem Test
169  * @tc.type: FUNC
170  * @tc.require: issueI5825N
171  */
172 HWTEST_F(ExtensionConfigMgrTest, AddBlockListItem_0200, TestSize.Level1)
173 {
174     ExtensionConfigMgr mgr;
175     mgr.Init();
176     mgr.AddBlockListItem(INVAILD_BLOCK_LIST_ITEM, EXTENSION_TYPE_FORM);
177     bool result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_FORM) != mgr.extensionBlocklist_.end());
178     EXPECT_FALSE(result);
179 }
180 
181 /**
182  * @tc.name: GenerateExtensionEtsBlocklists_0100
183  * @tc.desc: Generate Extension ets block list Test
184  * @tc.type: FUNC
185  */
186 HWTEST_F(ExtensionConfigMgrTest, GenerateExtensionEtsBlocklists_0100, TestSize.Level1)
187 {
188     ExtensionConfigMgr mgr;
189     std::unordered_set<std::string> set1 = { "111", "222", "333" };
190     mgr.extensionBlocklist_.clear();
191     mgr.extensionEtsBlocklist_.clear();
192     mgr.extensionBlocklist_.emplace(EXTENSION_TYPE_FORM, set1);
193     mgr.extensionType_ = EXTENSION_TYPE_WORK_SCHEDULER;
194     mgr.GenerateExtensionEtsBlocklists();
195     EXPECT_TRUE(mgr.extensionEtsBlocklist_.empty());
196 
197     std::unordered_set<std::string> set2;
198     mgr.extensionBlocklist_.clear();
199     mgr.extensionEtsBlocklist_.clear();
200     mgr.extensionBlocklist_.emplace(EXTENSION_TYPE_FORM, set2);
201     mgr.extensionType_ = EXTENSION_TYPE_FORM;
202     mgr.GenerateExtensionEtsBlocklists();
203     EXPECT_TRUE(mgr.extensionEtsBlocklist_.empty());
204 
205     mgr.extensionBlocklist_.clear();
206     mgr.extensionEtsBlocklist_.clear();
207     mgr.extensionBlocklist_.emplace(EXTENSION_TYPE_FORM, set1);
208     mgr.extensionType_ = EXTENSION_TYPE_FORM;
209     mgr.GenerateExtensionEtsBlocklists();
210     EXPECT_FALSE(mgr.extensionEtsBlocklist_.empty());
211     for (const auto& ele: set1) {
212         EXPECT_TRUE(mgr.extensionEtsBlocklist_.find(ele) != mgr.extensionEtsBlocklist_.end());
213     }
214 }
215 
216 /**
217  * @tc.name: GenerateExtensionEtsBlocklists_ShouldDoNothing_WhenExtensionEtsBlocklistIsNotEmpty
218  * @tc.desc: func should do nothing when extensionEtsBlocklist is not empty.
219  * @tc.type: FUNC
220  */
221 HWTEST_F(ExtensionConfigMgrTest, GenerateExtensionEtsBlocklists_ShouldDoNothing_WhenExtensionEtsBlocklistIsNotEmpty,
222     TestSize.Level1)
223 {
224     ExtensionConfigMgr mgr;
225     mgr.extensionEtsBlocklist_ = { "module1", "module2" };
226     mgr.GenerateExtensionEtsBlocklists();
227 
228     EXPECT_EQ(mgr.extensionEtsBlocklist_.size(), 2);
229     EXPECT_NE(mgr.extensionEtsBlocklist_.find("module1"), mgr.extensionEtsBlocklist_.end());
230     EXPECT_NE(mgr.extensionEtsBlocklist_.find("module2"), mgr.extensionEtsBlocklist_.end());
231 }
232 
233 /**
234  * @tc.name: GetStringAfterRemovePreFix_ShouldRemoveOHOSPrefix_WhenNameStartsWithOHOS
235  * @tc.desc: func should remove prefix when input name startswith @ohos.
236  * @tc.type: FUNC
237  */
238 HWTEST_F(ExtensionConfigMgrTest, GetStringAfterRemovePreFix_ShouldRemoveOHOSPrefix_WhenNameStartsWithOHOS,
239     TestSize.Level1)
240 {
241     ExtensionConfigMgr mgr;
242     std::string input = "@ohos.example";
243     std::string expectOutput = "example";
244     EXPECT_EQ(mgr.GetStringAfterRemovePreFix(input), expectOutput);
245 }
246 
247 /**
248  * @tc.name: GetStringAfterRemovePreFix_ShouldRemoveOtherPrefix_WhenNameStartsWithOther
249  * @tc.desc: func should remove prefix when input name startswith @xxx.
250  * @tc.type: FUNC
251  */
252 HWTEST_F(ExtensionConfigMgrTest, GetStringAfterRemovePreFix_ShouldRemoveOtherPrefix_WhenNameStartsWithOther,
253     TestSize.Level1)
254 {
255     ExtensionConfigMgr mgr;
256     std::string input = "@xxx.example";
257     std::string expectOutput = "example";
258     EXPECT_EQ(mgr.GetStringAfterRemovePreFix(input), expectOutput);
259 
260     input = "@xx.example";
261     expectOutput = "example";
262     EXPECT_EQ(mgr.GetStringAfterRemovePreFix(input), expectOutput);
263 }
264 
265 /**
266  * @tc.name: GetStringAfterRemovePreFix_ShouldNotRemovePrefix_WhenNameDoesNotStartsWithPrefix
267  * @tc.desc: func should not remove prefix when input name does not startswith any prefix.
268  * @tc.type: FUNC
269  */
270 HWTEST_F(ExtensionConfigMgrTest, GetStringAfterRemovePreFix_ShouldNotRemovePrefix_WhenNameDoesNotStartsWithPrefix,
271     TestSize.Level1)
272 {
273     ExtensionConfigMgr mgr;
274     std::string input = "example";
275     std::string expectOutput = "example";
276     EXPECT_EQ(mgr.GetStringAfterRemovePreFix(input), expectOutput);
277 }
278 
279 /**
280  * @tc.name: GetStringAfterRemovePreFix_ShouldHandleEmptyInput_WhenNameIsEmpty
281  * @tc.desc: func should handle empty input when input name is empty.
282  * @tc.type: FUNC
283  */
284 HWTEST_F(ExtensionConfigMgrTest, GetStringAfterRemovePreFix_ShouldHandleEmptyInput_WhenNameIsEmpty, TestSize.Level1)
285 {
286     ExtensionConfigMgr mgr;
287     std::string input = "";
288     std::string expectOutput = "";
289     EXPECT_EQ(mgr.GetStringAfterRemovePreFix(input), expectOutput);
290 }
291 
292 /**
293  * @tc.name: GetStringAfterRemovePreFix_ShouldHandleShortInput_WhenNameIsShorterThanPrefix
294  * @tc.desc: func should handle short input when input name is shorter than prefix.
295  * @tc.type: FUNC
296  */
297 HWTEST_F(ExtensionConfigMgrTest, GetStringAfterRemovePreFix_ShouldHandleShortInput_WhenNameIsShorterThanPrefix,
298     TestSize.Level1)
299 {
300     ExtensionConfigMgr mgr;
301     std::string input = "11";
302     std::string expectOutput = "11";
303     EXPECT_EQ(mgr.GetStringAfterRemovePreFix(input), expectOutput);
304 }
305 
306 /**
307  * @tc.name: GetStringAfterRemovePreFix_0100
308  * @tc.desc: GetStringAfterRemovePreFix Test
309  * @tc.type: FUNC
310  */
311 HWTEST_F(ExtensionConfigMgrTest, GetStringAfterRemovePreFix_0100, TestSize.Level1)
312 {
313     ExtensionConfigMgr mgr;
314     EXPECT_EQ(mgr.GetStringAfterRemovePreFix("@ohos.aaa.bbb"), "aaa.bbb");
315     EXPECT_EQ(mgr.GetStringAfterRemovePreFix("aaaaaa"), "aaaaaa");
316     EXPECT_EQ(mgr.GetStringAfterRemovePreFix("aaa"), "aaa");
317     EXPECT_EQ(mgr.GetStringAfterRemovePreFix("@ohos."), "");
318     EXPECT_EQ(mgr.GetStringAfterRemovePreFix("@xxx."), "");
319     EXPECT_EQ(mgr.GetStringAfterRemovePreFix("@xxx.aaa"), "aaa");
320     EXPECT_EQ(mgr.GetStringAfterRemovePreFix("@xxx"), "@xxx");
321 }
322 
323 /**
324  * @tc.name: CheckEtsModuleLoadable_ShouldReturnTrue_WhenFileNameIsPrefixAndNotInBlocklist
325  * @tc.desc: func should return true when file is prefix and not in blocklist.
326  * @tc.type: FUNC
327  */
328 HWTEST_F(ExtensionConfigMgrTest, CheckEtsModuleLoadable_ShouldReturnTrue_WhenFileNameIsPrefixAndNotInBlocklist,
329     TestSize.Level1)
330 {
331     ExtensionConfigMgr mgr;
332     std::string className = "file.class";
333     std::string fileName = "file";
334     EXPECT_TRUE(mgr.CheckEtsModuleLoadable(className, fileName));
335 }
336 
337 /**
338  * @tc.name: CheckEtsModuleLoadable_ShouldReturnFalse_WhenFileNameIsNotPrefix
339  * @tc.desc: func should return false when file is not prefix.(note: class name should be "std::string(filename) + '.'")
340  * @tc.type: FUNC
341  */
342 HWTEST_F(ExtensionConfigMgrTest, CheckEtsModuleLoadable_ShouldReturnFalse_WhenFileNameIsNotPrefix, TestSize.Level1)
343 {
344     ExtensionConfigMgr mgr;
345     std::string className = "file.class";
346     std::string fileName = "fileName";
347     EXPECT_FALSE(mgr.CheckEtsModuleLoadable(className, fileName));
348     EXPECT_FALSE(mgr.CheckEtsModuleLoadable("bundle.bundleApplication", "bundle.bundleApp"));
349 }
350 
351 /**
352  * @tc.name: CheckEtsModuleLoadable_ShouldReturnFalse_WhenFileNameIsLongerThanClassName
353  * @tc.desc: func should return false when file name is longer than class name.
354  * @tc.type: FUNC
355  */
356 HWTEST_F(ExtensionConfigMgrTest, CheckEtsModuleLoadable_ShouldReturnFalse_WhenFileNameIsLongerThanClassName,
357     TestSize.Level1)
358 {
359     ExtensionConfigMgr mgr;
360     std::string className = "file";
361     std::string fileName = "fileName";
362     EXPECT_FALSE(mgr.CheckEtsModuleLoadable(className, fileName));
363     EXPECT_FALSE(mgr.CheckEtsModuleLoadable("bundle.bundle", "bundle.bundle"));
364 }
365 
366 /**
367  * @tc.name: CheckEtsModuleLoadable_ShouldReturnFalse_WhenFileNameInBlockListAndStartsWithOHOS
368  * @tc.desc: func should return false when file name in blocklist and startswith ohos.
369  * @tc.type: FUNC
370  */
371 HWTEST_F(ExtensionConfigMgrTest, CheckEtsModuleLoadable_ShouldReturnFalse_WhenFileNameInBlockListAndStartsWithOHOS,
372     TestSize.Level1)
373 {
374     ExtensionConfigMgr mgr;
375     mgr.Init();
376     mgr.AddBlockListItem(BLOCK_LIST_ITEM_DRIVER_EXTENSION, EXTENSION_TYPE_DRIVER);
377     mgr.extensionType_ = EXTENSION_TYPE_DRIVER;
378     mgr.GenerateExtensionEtsBlocklists();
379     EXPECT_FALSE(mgr.CheckEtsModuleLoadable("@ohos.abilityAccessCtrl.abilityAccessCtrl", "@ohos.abilityAccessCtrl"));
380 }
381 
382 /**
383  * @tc.name: CheckEtsModuleLoadable_ShouldReturnFalse_WhenFileNameInBlockListAndStartsWithXXX
384  * @tc.desc: func should return false when file name in blocklist and startswith xxx.
385  * @tc.type: FUNC
386  */
387 HWTEST_F(ExtensionConfigMgrTest, CheckEtsModuleLoadable_ShouldReturnFalse_WhenFileNameInBlockListAndStartsWithXXX,
388     TestSize.Level1)
389 {
390     ExtensionConfigMgr mgr;
391     mgr.Init();
392     mgr.AddBlockListItem(BLOCK_LIST_ITEM_DRIVER_EXTENSION, EXTENSION_TYPE_DRIVER);
393     mgr.extensionType_ = EXTENSION_TYPE_DRIVER;
394     mgr.GenerateExtensionEtsBlocklists();
395     EXPECT_FALSE(mgr.CheckEtsModuleLoadable("@xxx.app.ability.appManager", "@xxx.app.ability.appManager"));
396 }
397 
398 /**
399  * @tc.name: CheckEtsModuleLoadable_ShouldReturnFalse_WhenFileNameInBlockListAndNotStartsWithPrefix
400  * @tc.desc: func should return false when file name in blocklist and not startswith prefix.
401  * @tc.type: FUNC
402  */
403 HWTEST_F(ExtensionConfigMgrTest,
404     CheckEtsModuleLoadable_ShouldReturnFalse_WhenFileNameInBlockListAndNotStartsWithPrefix, TestSize.Level1)
405 {
406     ExtensionConfigMgr mgr;
407     mgr.Init();
408     mgr.AddBlockListItem(BLOCK_LIST_ITEM_DRIVER_EXTENSION, EXTENSION_TYPE_DRIVER);
409     mgr.extensionType_ = EXTENSION_TYPE_DRIVER;
410     mgr.GenerateExtensionEtsBlocklists();
411 
412     EXPECT_FALSE(mgr.CheckEtsModuleLoadable("abilityAccessCtrl.XXX", "abilityAccessCtrl"));
413     EXPECT_FALSE(mgr.CheckEtsModuleLoadable("bundle.bundle", "bundle"));
414     EXPECT_FALSE(mgr.CheckEtsModuleLoadable("bundle.bundleManager.bundleManager", "bundle.bundleManager"));
415 }
416 
417 /**
418  * @tc.name: CheckEtsModuleLoadable_ShouldReturnTrue_WhenFileNameNotInBlockListAndStartsWithPrefix
419  * @tc.desc: func should return true when file name not in blocklist and startswith prefix.
420  * @tc.type: FUNC
421  */
422 HWTEST_F(ExtensionConfigMgrTest,
423     CheckEtsModuleLoadable_ShouldReturnTrue_WhenFileNameNotInBlockListAndStartsWithPrefix, TestSize.Level1)
424 {
425     ExtensionConfigMgr mgr;
426     mgr.Init();
427     mgr.AddBlockListItem(BLOCK_LIST_ITEM_DRIVER_EXTENSION, EXTENSION_TYPE_DRIVER);
428     mgr.extensionType_ = EXTENSION_TYPE_DRIVER;
429     mgr.GenerateExtensionEtsBlocklists();
430 
431     EXPECT_TRUE(mgr.CheckEtsModuleLoadable("@xxx.app.app.appManager.appManager", "@xxx.app.app.appManager"));
432     EXPECT_TRUE(mgr.CheckEtsModuleLoadable("@ohos.app.app.appManager.appManager", "@ohos.app.app.appManager"));
433 }
434 
435 /**
436  * @tc.name: UpdateRuntimeModuleChecker_ShouldHandleEtsRuntime_WhenLanguageIsEts
437  * @tc.desc: func should handle ets runtime when language is EtsRuntime.
438  * @tc.type: FUNC
439  */
440 HWTEST_F(ExtensionConfigMgrTest, UpdateRuntimeModuleChecker_ShouldHandleEtsRuntime_WhenLanguageIsEts, TestSize.Level1)
441 {
442     ExtensionConfigMgr mgr;
443     mgr.UpdateRuntimeModuleChecker(nullptr);
444     auto mockRuntimePtr = std::make_unique<MockRuntime>();
445     EXPECT_NE(mockRuntimePtr, nullptr);
446     std::unique_ptr<Runtime> runtime = std::move(mockRuntimePtr);
447     mgr.UpdateRuntimeModuleChecker(runtime);
448     MockRuntime &mockRuntime = static_cast<MockRuntime&>(*runtime);
449     EXPECT_TRUE(mockRuntime.extensionApiCheckerFlag_);
450     EXPECT_TRUE(mockRuntime.loadCheckerFlag_);
451     auto checkFunc = mockRuntime.GetExtensionApiCheckCallback();
452     EXPECT_NE(checkFunc, nullptr);
453     EXPECT_FALSE(checkFunc("111", "222"));
454 }
455 
456 /**
457  * @tc.name: UpdateRuntimeModuleChecker_ShouldHandleNotEtsRuntime_WhenLanguageIsJs
458  * @tc.desc: func should handle not ets runtime when language is JsRuntime.
459  * @tc.type: FUNC
460  */
461 HWTEST_F(ExtensionConfigMgrTest, UpdateRuntimeModuleChecker_ShouldHandleNotEtsRuntime_WhenLanguageIsJs,
462     TestSize.Level1)
463 {
464     ExtensionConfigMgr mgr;
465     auto mockRuntimePtr = std::make_unique<MockRuntime>();
466     EXPECT_NE(mockRuntimePtr, nullptr);
467     mockRuntimePtr->SetLanguage(Runtime::Language::JS);
468     std::unique_ptr<Runtime> runtime = std::move(mockRuntimePtr);
469     mgr.UpdateRuntimeModuleChecker(runtime);
470     MockRuntime &mockRuntime = static_cast<MockRuntime&>(*runtime);
471     EXPECT_TRUE(mockRuntime.loadCheckerFlag_);
472     EXPECT_FALSE(mockRuntime.extensionApiCheckerFlag_);
473 }
474 }  // namespace AbilityRuntime
475 }  // namespace OHOS
476