• 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 #undef private
22 #undef protected
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace AbilityRuntime {
29 namespace {
30     constexpr int32_t EXTENSION_TYPE_FORM = 0;
31     constexpr int32_t EXTENSION_TYPE_WORK_SCHEDULER = 1;
32     constexpr int32_t EXTENSION_TYPE_INPUTMETHOD = 2;
33     constexpr int32_t EXTENSION_TYPE_SERVICE = 3;
34     constexpr int32_t EXTENSION_TYPE_ACCESSIBILITY = 4;
35     constexpr int32_t EXTENSION_TYPE_DATASHARE = 5;
36     constexpr int32_t EXTENSION_TYPE_STATICSUBSCRIBER = 7;
37     constexpr int32_t EXTENSION_TYPE_WALLPAPER = 8;
38     constexpr int32_t EXTENSION_TYPE_BACKUP = 9;
39     constexpr int32_t EXTENSION_TYPE_WINDOW = 10;
40     constexpr int32_t EXTENSION_TYPE_ENTERPRISE_ADMIN = 11;
41     constexpr int32_t EXTENSION_TYPE_FILE_ACCESS = 12;
42     constexpr char BLOCK_LIST_ITEM_SERVICE_EXTENSION[] = "ServiceExtension";
43     constexpr char BLOCK_LIST_ITEM_FORM_EXTENSION[] = "FormExtension";
44     constexpr char BLOCK_LIST_ITEM_FILE_ACCESS_EXTENSION[] = "FileAccessExtension";
45     constexpr char BLOCK_LIST_ITEM_BACKUP_EXTENSION[] = "BackupExtension";
46     constexpr char BLOCK_LIST_ITEM_ENTERPRISE_ADMIN_EXTENSION[] = "EnterpriseAdminExtension";
47     constexpr char BLOCK_LIST_ITEM_WINDOW_EXTENSION_EXTENSION[] = "WindowExtensionExtension";
48     constexpr char BLOCK_LIST_ITEM_WALLPAPER_EXTENSION[] = "WallpaperExtension";
49     constexpr char BLOCK_LIST_ITEM_STATIC_SUBSCRIBER_EXTENSION[] = "StaticSubscriberExtension";
50     constexpr char BLOCK_LIST_ITEM_ACCESSIBILITY_EXTENSION[] = "AccessibilityExtension";
51     constexpr char BLOCK_LIST_ITEM_INPUT_METHOD_EXTENSION_ABILITY[] = "InputMethodExtensionAbility";
52     constexpr char BLOCK_LIST_ITEM_WORK_SCHEDULER_EXTENSION[] = "WorkSchedulerExtension";
53     constexpr char BLOCK_LIST_ITEM_DATA_SHARE_EXTENSION[] = "DataShareExtension";
54     constexpr char INVAILD_BLOCK_LIST_ITEM[] = "InvaildExtension";
55 }
56 
57 class ExtensionConfigMgrTest : public testing::Test {
58 public:
59     static void SetUpTestCase();
60     static void TearDownTestCase();
61     void SetUp() override;
62     void TearDown() override;
63 };
64 
SetUpTestCase()65 void ExtensionConfigMgrTest::SetUpTestCase()
66 {}
67 
TearDownTestCase()68 void ExtensionConfigMgrTest::TearDownTestCase()
69 {}
70 
SetUp()71 void ExtensionConfigMgrTest::SetUp()
72 {}
73 
TearDown()74 void ExtensionConfigMgrTest::TearDown()
75 {}
76 
77 /**
78  * @tc.name: Init_0100
79  * @tc.desc: Init Test
80  * @tc.type: FUNC
81  * @tc.require: issueI581T3
82  */
83 HWTEST_F(ExtensionConfigMgrTest, Init_0100, TestSize.Level0)
84 {
85     ExtensionConfigMgr mgr;
86     mgr.Init();
87     bool result = false;
88     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_SERVICE_EXTENSION) != mgr.blocklistConfig_.end());
89     EXPECT_TRUE(result);
90     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_FORM_EXTENSION) != mgr.blocklistConfig_.end());
91     EXPECT_TRUE(result);
92     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_FILE_ACCESS_EXTENSION) != mgr.blocklistConfig_.end());
93     EXPECT_TRUE(result);
94     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_BACKUP_EXTENSION) != mgr.blocklistConfig_.end());
95     EXPECT_TRUE(result);
96     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_ENTERPRISE_ADMIN_EXTENSION) != mgr.blocklistConfig_.end());
97     EXPECT_TRUE(result);
98     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_WINDOW_EXTENSION_EXTENSION) != mgr.blocklistConfig_.end());
99     EXPECT_TRUE(result);
100     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_WALLPAPER_EXTENSION) != mgr.blocklistConfig_.end());
101     EXPECT_TRUE(result);
102     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_STATIC_SUBSCRIBER_EXTENSION) != mgr.blocklistConfig_.end());
103     EXPECT_TRUE(result);
104     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_ACCESSIBILITY_EXTENSION) != mgr.blocklistConfig_.end());
105     EXPECT_TRUE(result);
106     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_INPUT_METHOD_EXTENSION_ABILITY) != mgr.blocklistConfig_.end());
107     EXPECT_TRUE(result);
108     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_WORK_SCHEDULER_EXTENSION) != mgr.blocklistConfig_.end());
109     EXPECT_TRUE(result);
110     result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_DATA_SHARE_EXTENSION) != mgr.blocklistConfig_.end());
111     EXPECT_TRUE(result);
112 }
113 
114 /**
115  * @tc.name: AddBlockListItem_0100
116  * @tc.desc: AddBlockListItem Test
117  * @tc.type: FUNC
118  * @tc.require: issueI581T3
119  */
120 HWTEST_F(ExtensionConfigMgrTest, AddBlockListItem_0100, TestSize.Level0)
121 {
122     ExtensionConfigMgr mgr;
123     mgr.Init();
124     bool result = false;
125     mgr.AddBlockListItem(BLOCK_LIST_ITEM_FORM_EXTENSION, EXTENSION_TYPE_FORM);
126     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_FORM) != mgr.extensionBlocklist_.end());
127     EXPECT_TRUE(result);
128     mgr.AddBlockListItem(BLOCK_LIST_ITEM_WORK_SCHEDULER_EXTENSION, EXTENSION_TYPE_WORK_SCHEDULER);
129     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_WORK_SCHEDULER) != mgr.extensionBlocklist_.end());
130     EXPECT_TRUE(result);
131     mgr.AddBlockListItem(BLOCK_LIST_ITEM_INPUT_METHOD_EXTENSION_ABILITY, EXTENSION_TYPE_INPUTMETHOD);
132     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_INPUTMETHOD) != mgr.extensionBlocklist_.end());
133     EXPECT_TRUE(result);
134     mgr.AddBlockListItem(BLOCK_LIST_ITEM_SERVICE_EXTENSION, EXTENSION_TYPE_SERVICE);
135     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_SERVICE) != mgr.extensionBlocklist_.end());
136     EXPECT_TRUE(result);
137     mgr.AddBlockListItem(BLOCK_LIST_ITEM_ACCESSIBILITY_EXTENSION, EXTENSION_TYPE_ACCESSIBILITY);
138     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_ACCESSIBILITY) != mgr.extensionBlocklist_.end());
139     EXPECT_TRUE(result);
140     mgr.AddBlockListItem(BLOCK_LIST_ITEM_DATA_SHARE_EXTENSION, EXTENSION_TYPE_DATASHARE);
141     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_DATASHARE) != mgr.extensionBlocklist_.end());
142     EXPECT_TRUE(result);
143     mgr.AddBlockListItem(BLOCK_LIST_ITEM_STATIC_SUBSCRIBER_EXTENSION, EXTENSION_TYPE_STATICSUBSCRIBER);
144     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_STATICSUBSCRIBER) != mgr.extensionBlocklist_.end());
145     EXPECT_TRUE(result);
146     mgr.AddBlockListItem(BLOCK_LIST_ITEM_WALLPAPER_EXTENSION, EXTENSION_TYPE_WALLPAPER);
147     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_WALLPAPER) != mgr.extensionBlocklist_.end());
148     EXPECT_TRUE(result);
149     mgr.AddBlockListItem(BLOCK_LIST_ITEM_BACKUP_EXTENSION, EXTENSION_TYPE_BACKUP);
150     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_BACKUP) != mgr.extensionBlocklist_.end());
151     EXPECT_TRUE(result);
152     mgr.AddBlockListItem(BLOCK_LIST_ITEM_WINDOW_EXTENSION_EXTENSION, EXTENSION_TYPE_WINDOW);
153     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_WINDOW) != mgr.extensionBlocklist_.end());
154     EXPECT_TRUE(result);
155     mgr.AddBlockListItem(BLOCK_LIST_ITEM_ENTERPRISE_ADMIN_EXTENSION, EXTENSION_TYPE_ENTERPRISE_ADMIN);
156     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_ENTERPRISE_ADMIN) != mgr.extensionBlocklist_.end());
157     EXPECT_TRUE(result);
158     mgr.AddBlockListItem(BLOCK_LIST_ITEM_FILE_ACCESS_EXTENSION, EXTENSION_TYPE_FILE_ACCESS);
159     result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_FILE_ACCESS) != mgr.extensionBlocklist_.end());
160     EXPECT_TRUE(result);
161 }
162 
163 /**
164  * @tc.name: AddBlockListItem_0200
165  * @tc.desc: AddBlockListItem Test
166  * @tc.type: FUNC
167  * @tc.require: issueI5825N
168  */
169 HWTEST_F(ExtensionConfigMgrTest, AddBlockListItem_0200, TestSize.Level0)
170 {
171     ExtensionConfigMgr mgr;
172     mgr.Init();
173     mgr.AddBlockListItem(INVAILD_BLOCK_LIST_ITEM, EXTENSION_TYPE_FORM);
174     bool result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_FORM) != mgr.extensionBlocklist_.end());
175     EXPECT_FALSE(result);
176 }
177 }  // namespace AbilityRuntime
178 }  // namespace OHOS
179