• 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.Level1)
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     ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect));
105 }
106 
107 /**
108  * @tc.name: CheckOtherWindowCoverComp002
109  * @tc.desc: Test component window is not found in list
110  * @tc.type: FUNC
111  * @tc.require:
112  */
113 HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp002, TestSize.Level1)
114 {
115     WindowManager::GetInstance().result_ = WMError::WM_OK;
116     std::vector<sptr<UnreliableWindowInfo>> list;
117     sptr<UnreliableWindowInfo> compWin = new UnreliableWindowInfo();
118     compWin->windowId_ = 1;
119     compWin->zOrder_ = 1;
120     compWin->floatingScale_ = 1.0;
121     list.emplace_back(compWin);
122     WindowManager::GetInstance().info_ = list;
123 
124     SecCompRect compRect = {
125         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
126         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
127     };
128     ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect));
129 }
130 
131 /**
132  * @tc.name: CheckOtherWindowCoverComp003
133  * @tc.desc: Test component window is not covered
134  * @tc.type: FUNC
135  * @tc.require:
136  */
137 HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp003, TestSize.Level1)
138 {
139     WindowManager::GetInstance().result_ = WMError::WM_OK;
140     std::vector<sptr<UnreliableWindowInfo>> list;
141     sptr<UnreliableWindowInfo> compWin = new UnreliableWindowInfo();
142     compWin->windowId_ = 0;
143     compWin->zOrder_ = 1;
144     compWin->floatingScale_ = 1.0;
145     list.emplace_back(compWin);
146     WindowManager::GetInstance().info_ = list;
147 
148     SecCompRect compRect = {
149         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE,
150         ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE
151     };
152     ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect));
153 }
154