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 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.Level1) 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.Level1) 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