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// gtest 17#include <gtest/gtest.h> 18#include "display_manager_proxy.h" 19#include "window_test_utils.h" 20#include "wm_common.h" 21using namespace testing; 22using namespace testing::ext; 23 24namespace OHOS { 25namespace Rosen { 26namespace { 27constexpr uint32_t WAIT_ASYNC_US = 100000; // 100ms 28} 29using Utils = WindowTestUtils; 30class WindowInputTest : public testing::Test { 31public: 32 static void SetUpTestCase(); 33 static void TearDownTestCase(); 34 virtual void SetUp() override; 35 virtual void TearDown() override; 36 Utils::TestWindowInfo fullScreenWindow_; 37}; 38 39void WindowInputTest::SetUpTestCase() 40{ 41 auto display = DisplayManager::GetInstance().GetDisplayById(0); 42 ASSERT_TRUE((display != nullptr)); 43 Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; 44 Utils::InitByDisplayRect(displayRect); 45} 46 47void WindowInputTest::TearDownTestCase() 48{ 49} 50 51void WindowInputTest::SetUp() 52{ 53 fullScreenWindow_ = { 54 .name = "FullWindow", 55 .rect = Utils::customAppRect_, 56 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, 57 .mode = WindowMode::WINDOW_MODE_FULLSCREEN, 58 .needAvoid = false, 59 .parentLimit = false, 60 .parentId = INVALID_WINDOW_ID, 61 }; 62} 63 64void WindowInputTest::TearDown() 65{ 66} 67 68namespace { 69/** 70 * @tc.name: SetTouchHotAreas01 71 * @tc.desc: Normal scenario testing for Window#SetTouchHotAreas 72 * @tc.type: FUNC 73 */ 74HWTEST_F(WindowInputTest, SetTouchHotAreas01, Function | MediumTest | Level3) 75{ 76 fullScreenWindow_.name = "window_hot_areas.1"; 77 const sptr<Window>& window = Utils::CreateTestWindow(fullScreenWindow_); 78 if (window == nullptr) { 79 return; 80 } 81 ASSERT_EQ(WMError::WM_OK, window->Show()); 82 83 std::vector<Rect> requestedTouchHotAreas; 84 window->GetRequestedTouchHotAreas(requestedTouchHotAreas); 85 ASSERT_TRUE(requestedTouchHotAreas.empty()); 86 87 usleep(WAIT_ASYNC_US); 88 Rect windowRect = window->GetRect(); 89 90 std::vector<Rect> rects; 91 uint32_t hotAreasNum = 10; 92 uint32_t hotAreaWidth = windowRect.width_ / hotAreasNum; 93 uint32_t hotAreaHeight = windowRect.height_ / hotAreasNum; 94 for (uint32_t i = 0; i < hotAreasNum; ++i) { 95 rects.emplace_back(Rect{ hotAreaWidth * i, hotAreaHeight * i, hotAreaWidth, hotAreaHeight }); 96 } 97 ASSERT_EQ(WMError::WM_OK, window->SetTouchHotAreas(rects)); 98 window->GetRequestedTouchHotAreas(requestedTouchHotAreas); 99 ASSERT_EQ(rects.size(), requestedTouchHotAreas.size()); 100 for (uint32_t i = 0; i < rects.size(); ++i) { 101 ASSERT_TRUE(rects[i] == requestedTouchHotAreas[i]); 102 } 103 104 rects.clear(); 105 rects.emplace_back(Rect{ 0, 0, hotAreaWidth, hotAreaHeight }); 106 ASSERT_EQ(WMError::WM_OK, window->SetTouchHotAreas(rects)); 107 window->GetRequestedTouchHotAreas(requestedTouchHotAreas); 108 ASSERT_EQ(rects.size(), requestedTouchHotAreas.size()); 109 for (uint32_t i = 0; i < rects.size(); ++i) { 110 ASSERT_TRUE(rects[i] == requestedTouchHotAreas[i]); 111 } 112 113 rects.clear(); 114 ASSERT_EQ(WMError::WM_OK, window->SetTouchHotAreas(rects)); 115 window->GetRequestedTouchHotAreas(requestedTouchHotAreas); 116 ASSERT_TRUE(requestedTouchHotAreas.empty()); 117 118 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 119} 120 121/** 122 * @tc.name: SetTouchHotAreas02 123 * @tc.desc: Abnormal scenario testing for Window#SetTouchHotAreas 124 * @tc.type: FUNC 125 */ 126HWTEST_F(WindowInputTest, SetTouchHotAreas02, Function | MediumTest | Level3) 127{ 128 fullScreenWindow_.name = "window_hot_areas.2"; 129 const sptr<Window>& window = Utils::CreateTestWindow(fullScreenWindow_); 130 if (window == nullptr) { 131 return; 132 } 133 ASSERT_EQ(WMError::WM_OK, window->Show()); 134 135 usleep(WAIT_ASYNC_US); 136 Rect windowRect = window->GetRect(); 137 138 std::vector<Rect> rects; 139 /* maximum hot areas: 10, test exceeding maximum hot areas */ 140 uint32_t hotAreasNum = 11; 141 uint32_t hotAreaWidth = windowRect.width_ / hotAreasNum; 142 uint32_t hotAreaHeight = windowRect.height_ / hotAreasNum; 143 for (uint32_t i = 0; i < hotAreasNum; ++i) { 144 rects.emplace_back(Rect{ hotAreaWidth * i, hotAreaHeight * i, hotAreaWidth, hotAreaHeight }); 145 } 146 ASSERT_EQ(WMError::WM_OK, window->SetTouchHotAreas(rects)); 147 148 rects.clear(); 149 rects.emplace_back(Rect{ -1, 0, windowRect.width_ / 2, windowRect.height_ / 2 }); 150 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects)); 151 152 rects.clear(); 153 rects.emplace_back(Rect{ 0, -1, windowRect.width_ / 2, windowRect.height_ / 2 }); 154 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects)); 155 156 rects.clear(); 157 rects.emplace_back(Rect{ 0, 0, 0, windowRect.height_ / 2 }); 158 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects)); 159 160 rects.clear(); 161 rects.emplace_back(Rect{ 0, 0, windowRect.width_ / 2, 0 }); 162 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects)); 163 164 rects.clear(); 165 rects.emplace_back(Rect{ windowRect.width_, 0, windowRect.width_ / 2, windowRect.height_ / 2 }); 166 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects)); 167 168 rects.clear(); 169 rects.emplace_back(Rect{ 0, windowRect.height_, windowRect.width_ / 2, windowRect.height_ / 2 }); 170 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects)); 171 172 std::vector<Rect> requestedTouchHotAreas; 173 window->GetRequestedTouchHotAreas(requestedTouchHotAreas); 174 ASSERT_FALSE(requestedTouchHotAreas.empty()); 175 176 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 177} 178} // namespace 179} // namespace Rosen 180} // namespace OHOS