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