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