• 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 #include <gtest/gtest.h>
16 
17 #include "location_button.h"
18 #include "sec_comp_err.h"
19 #include "sec_comp_log.h"
20 #include "service_test_common.h"
21 #include "window_info_helper.h"
22 #include "window_manager.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::Rosen;
27 using namespace OHOS::Security::SecurityComponent;
28 
29 namespace {
30 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
31     LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "WindowInfoHelperTest"};
32 }
33 
34 namespace OHOS {
35 namespace Security {
36 namespace SecurityComponent {
37 class WindowInfoHelperTest : public testing::Test {
38 public:
SetUpTestCase()39     static void SetUpTestCase() {};
40 
TearDownTestCase()41     static void TearDownTestCase() {};
42 
SetUp()43     void SetUp()
44     {
45         SC_LOG_INFO(LABEL, "setup");
46     };
47 
TearDown()48     void TearDown() {};
49 };
50 }  // namespace SecurityComponent
51 }  // namespace Security
52 }  // namespace OHOS
53 
54 /**
55  * @tc.name: CheckOtherWindowCoverComp001
56  * @tc.desc: Test pinter event cross other window
57  * @tc.type: FUNC
58  * @tc.require:
59  */
60 HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp001, TestSize.Level0)
61 {
62     WindowManager::GetInstance().result_ = WMError::WM_OK;
63     std::vector<sptr<UnreliableWindowInfo>> list;
64     sptr<UnreliableWindowInfo> compWin = new UnreliableWindowInfo();
65     compWin->windowId_ = 0;
66     compWin->zOrder_ = 1;
67     compWin->floatingScale_ = 1.0; // window did not scale
68     list.emplace_back(compWin);
69     list.emplace_back(nullptr);
70 
71     sptr<UnreliableWindowInfo> downNotCrossWin = new UnreliableWindowInfo();
72     downNotCrossWin->windowId_ = 1;
73     downNotCrossWin->zOrder_ = 0;
74     downNotCrossWin->floatingScale_ = 0.0;
75     downNotCrossWin->windowRect_ = Rosen::Rect{ 0, 0, 0, 0 };
76     list.emplace_back(downNotCrossWin);
77 
78     sptr<UnreliableWindowInfo> downCrossWin = new UnreliableWindowInfo();
79     downCrossWin->windowId_ = 1;
80     downCrossWin->zOrder_ = 0;
81     downCrossWin->floatingScale_ = 0.9; // window is scaled to 90%
82     downCrossWin->windowRect_ = Rosen::Rect {
83         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
84         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
85     };
86     list.emplace_back(downCrossWin);
87 
88     sptr<UnreliableWindowInfo> upWin = new UnreliableWindowInfo();
89     upWin->windowId_ = 1;
90     upWin->zOrder_ = 2; // layer larger than comp window
91     upWin->floatingScale_ = 1.0; // window did not scale
92     upWin->windowRect_ = Rosen::Rect {
93         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
94         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
95     };
96     list.emplace_back(upWin);
97     WindowManager::GetInstance().info_ = list;
98 
99     SecCompRect compRect = {
100         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
101         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
102     };
103 
104     std::string message;
105     ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message));
106 }
107 
108 /**
109  * @tc.name: CheckOtherWindowCoverComp002
110  * @tc.desc: Test component window is not found in list
111  * @tc.type: FUNC
112  * @tc.require:
113  */
114 HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp002, TestSize.Level0)
115 {
116     WindowManager::GetInstance().result_ = WMError::WM_OK;
117     std::vector<sptr<UnreliableWindowInfo>> list;
118     sptr<UnreliableWindowInfo> compWin = new UnreliableWindowInfo();
119     compWin->windowId_ = 1;
120     compWin->zOrder_ = 1;
121     compWin->floatingScale_ = 1.0;
122     list.emplace_back(compWin);
123     WindowManager::GetInstance().info_ = list;
124 
125     SecCompRect compRect = {
126         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
127         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
128     };
129     std::string message;
130     ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message));
131 }
132 
133 /**
134  * @tc.name: CheckOtherWindowCoverComp003
135  * @tc.desc: Test component window is not covered
136  * @tc.type: FUNC
137  * @tc.require:
138  */
139 HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp003, TestSize.Level0)
140 {
141     WindowManager::GetInstance().result_ = WMError::WM_OK;
142     std::vector<sptr<UnreliableWindowInfo>> list;
143     sptr<UnreliableWindowInfo> compWin = new UnreliableWindowInfo();
144     compWin->windowId_ = 0;
145     compWin->zOrder_ = 1;
146     compWin->floatingScale_ = 1.0;
147     list.emplace_back(compWin);
148     WindowManager::GetInstance().info_ = list;
149 
150     SecCompRect compRect = {
151         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
152         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
153     };
154     std::string message;
155     ASSERT_TRUE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message));
156 }
157 
158 /**
159  * @tc.name: CheckOtherWindowCoverComp004
160  * @tc.desc: Test component window is not covered
161  * @tc.type: FUNC
162  * @tc.require:
163  */
164 HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp004, TestSize.Level0)
165 {
166     WindowManager::GetInstance().result_ = WMError::WM_OK;
167     std::vector<sptr<UnreliableWindowInfo>> list;
168     sptr<UnreliableWindowInfo> compWin = new UnreliableWindowInfo();
169     compWin->windowId_ = 1;
170     compWin->zOrder_ = 1;
171     compWin->floatingScale_ = 1.0;
172     compWin->windowRect_ = Rosen::Rect {
173         0, 0,
174         ServiceTestCommon::TEST_COORDINATE + 2, ServiceTestCommon::TEST_COORDINATE + 2
175     };
176     list.emplace_back(compWin);
177     WindowManager::GetInstance().info_ = list;
178 
179     SecCompRect compRect = {
180         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
181         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
182     };
183     compRect.borderRadius_ = {
184         ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2,
185         ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2
186     };
187     std::string message;
188     ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message));
189 }
190 
191 /**
192  * @tc.name: CheckOtherWindowCoverComp005
193  * @tc.desc: Test component window is not covered
194  * @tc.type: FUNC
195  * @tc.require:
196  */
197 HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp005, TestSize.Level0)
198 {
199     WindowManager::GetInstance().result_ = WMError::WM_OK;
200     std::vector<sptr<UnreliableWindowInfo>> list;
201     sptr<UnreliableWindowInfo> compWin = new UnreliableWindowInfo();
202     compWin->windowId_ = 1;
203     compWin->zOrder_ = 1;
204     compWin->floatingScale_ = 1.0;
205     compWin->windowRect_ = Rosen::Rect {
206         0, (ServiceTestCommon::TEST_COORDINATE * 2) - 2,
207         ServiceTestCommon::TEST_COORDINATE + 2, ServiceTestCommon::TEST_COORDINATE + 2
208     };
209     list.emplace_back(compWin);
210     WindowManager::GetInstance().info_ = list;
211 
212     SecCompRect compRect = {
213         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
214         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
215     };
216     compRect.borderRadius_ = {
217         ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2,
218         ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2
219     };
220     std::string message;
221     ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message));
222 }
223 
224 /**
225  * @tc.name: CheckOtherWindowCoverComp006
226  * @tc.desc: Test component window is not covered
227  * @tc.type: FUNC
228  * @tc.require:
229  */
230 HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp006, TestSize.Level0)
231 {
232     WindowManager::GetInstance().result_ = WMError::WM_OK;
233     std::vector<sptr<UnreliableWindowInfo>> list;
234     sptr<UnreliableWindowInfo> compWin = new UnreliableWindowInfo();
235     compWin->windowId_ = 1;
236     compWin->zOrder_ = 1;
237     compWin->floatingScale_ = 1.0;
238     compWin->windowRect_ = Rosen::Rect {
239         (ServiceTestCommon::TEST_COORDINATE * 2) - 2, 0,
240         ServiceTestCommon::TEST_COORDINATE + 2, ServiceTestCommon::TEST_COORDINATE + 2
241     };
242     list.emplace_back(compWin);
243     WindowManager::GetInstance().info_ = list;
244 
245     SecCompRect compRect = {
246         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
247         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
248     };
249     compRect.borderRadius_ = {
250         ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2,
251         ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2
252     };
253     std::string message;
254     ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message));
255 }
256 
257 /**
258  * @tc.name: CheckOtherWindowCoverComp007
259  * @tc.desc: Test component window is not covered
260  * @tc.type: FUNC
261  * @tc.require:
262  */
263 HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp007, TestSize.Level0)
264 {
265     WindowManager::GetInstance().result_ = WMError::WM_OK;
266     std::vector<sptr<UnreliableWindowInfo>> list;
267     sptr<UnreliableWindowInfo> compWin = new UnreliableWindowInfo();
268     compWin->windowId_ = 1;
269     compWin->zOrder_ = 1;
270     compWin->floatingScale_ = 1.0;
271     compWin->windowRect_ = Rosen::Rect {
272         (ServiceTestCommon::TEST_COORDINATE * 2) - 2, (ServiceTestCommon::TEST_COORDINATE * 2) - 2,
273         ServiceTestCommon::TEST_COORDINATE + 2, ServiceTestCommon::TEST_COORDINATE + 2
274     };
275     list.emplace_back(compWin);
276     WindowManager::GetInstance().info_ = list;
277 
278     SecCompRect compRect = {
279         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
280         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
281     };
282     compRect.borderRadius_ = {
283         ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2,
284         ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2
285     };
286     std::string message;
287     ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message));
288 }
289