• 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 "window_test_utils.h"
19 #include "window_accessibility_controller.h"
20 #include "window_impl.h"
21 #include "wm_common.h"
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 using Utils = WindowTestUtils;
28 class WindowDisplayZoomTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     virtual void SetUp() override;
33     virtual void TearDown() override;
34     Utils::TestWindowInfo windowInfo_;
35 };
36 
SetUpTestCase()37 void WindowDisplayZoomTest::SetUpTestCase()
38 {
39 }
40 
TearDownTestCase()41 void WindowDisplayZoomTest::TearDownTestCase()
42 {
43 }
44 
SetUp()45 void WindowDisplayZoomTest::SetUp()
46 {
47     windowInfo_ = {
48         .name = "zoomWindow",
49         .rect = {0, 0, 300, 100},
50         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
51         .mode = WindowMode::WINDOW_MODE_FLOATING,
52         .needAvoid = false,
53         .parentLimit = false,
54         .showWhenLocked = true,
55         .parentId = INVALID_WINDOW_ID,
56     };
57 }
58 
TearDown()59 void WindowDisplayZoomTest::TearDown()
60 {
61 }
62 
63 namespace {
64 /**
65  * @tc.name: DisplayZoom01
66  * @tc.desc: test interface SetAnchorAndScale
67  * @tc.type: FUNC
68  * @tc.require: issueI5NGWL
69  */
70 HWTEST_F(WindowDisplayZoomTest, DisplayZoom01, Function | MediumTest | Level3)
71 {
72     WindowAccessibilityController::GetInstance().OffWindowZoom();
73     sleep(1);
74 
75     windowInfo_.name = "DisplayZoom01";
76     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
77     Window* ptr = window.GetRefPtr();
78     WindowImpl* implPtr = (WindowImpl*)ptr;
79     ASSERT_EQ(WMError::WM_OK, window->Show());
80     sleep(1);
81     Transform expect;
82     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
83 
84     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
85     sleep(1);
86     Rect rect = window->GetRect();
87     expect.pivotX_ = (0 - rect.posX_) * 1.0 / rect.width_;
88     expect.pivotY_ = (0 - rect.posY_) * 1.0 / rect.height_;
89     expect.scaleX_ = expect.scaleY_ = 2; // scale value
90     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
91 
92     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
93     sleep(1);
94     expect.scaleX_ = expect.scaleY_ = 4; // scale value
95     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
96 
97     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 0.5);
98     sleep(1);
99     expect.scaleX_ = expect.scaleY_ = 2; // scale value
100     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
101 
102     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 0.1);
103     sleep(1);
104     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
105 
106     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, -0.1);
107     sleep(1);
108     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
109 
110     WindowAccessibilityController::GetInstance().OffWindowZoom();
111     window->Destroy();
112 }
113 
114 /**
115  * @tc.name: DisplayZoom02
116  * @tc.desc: test interface SetAnchorOffset
117  * @tc.type: FUNC
118  * @tc.require: issueI5NGWL
119  */
120 HWTEST_F(WindowDisplayZoomTest, DisplayZoom02, Function | MediumTest | Level3)
121 {
122     windowInfo_.name = "DisplayZoom02";
123     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
124     ASSERT_EQ(WMError::WM_OK, window->Show());
125     sleep(1);
126 
127     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
128     sleep(1);
129     WindowAccessibilityController::GetInstance().SetAnchorOffset(-100, -100);
130     sleep(1);
131 
132     Transform expect;
133     Rect rect = window->GetRect();
134     expect.pivotX_ = (0 - rect.posX_) * 1.0 / rect.width_;
135     expect.pivotY_ = (0 - rect.posY_) * 1.0 / rect.height_;
136     expect.scaleX_ = expect.scaleY_ = 2; // scale value
137     expect.translateX_ = expect.translateY_ = -100;  // translate value
138 
139     WindowAccessibilityController::GetInstance().SetAnchorOffset(200, 200);
140     sleep(1);
141     expect.translateX_ = expect.translateY_ = 0;
142     WindowAccessibilityController::GetInstance().OffWindowZoom();
143     window->Destroy();
144 }
145 
146 /**
147  * @tc.name: DisplayZoom03
148  * @tc.desc: test interface OffWindowZoom
149  * @tc.type: FUNC
150  * @tc.require: issueI5NGWL
151  */
152 HWTEST_F(WindowDisplayZoomTest, DisplayZoom03, Function | MediumTest | Level3)
153 {
154     windowInfo_.name = "DisplayZoom03";
155     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
156     Window* ptr = window.GetRefPtr();
157     WindowImpl* implPtr = (WindowImpl*)ptr;
158     ASSERT_EQ(WMError::WM_OK, window->Show());
159     sleep(1);
160 
161     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
162     sleep(1);
163     WindowAccessibilityController::GetInstance().OffWindowZoom();
164     sleep(1);
165 
166     Transform expect;
167     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
168 
169     window->Destroy();
170 }
171 
172 /**
173  * @tc.name: DisplayZoom04
174  * @tc.desc: test add and remove a window after zoom display
175  * @tc.type: FUNC
176  * @tc.require: issueI5NGWL
177  */
178 HWTEST_F(WindowDisplayZoomTest, DisplayZoom04, Function | MediumTest | Level3)
179 {
180     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
181     sleep(1);
182 
183     windowInfo_.name = "DisplayZoom04";
184     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
185     Window* ptr = window.GetRefPtr();
186     WindowImpl* implPtr = (WindowImpl*)ptr;
187     ASSERT_EQ(WMError::WM_OK, window->Show());
188     sleep(1);
189 
190     Transform expect;
191     Rect rect = window->GetRect();
192     expect.pivotX_ = (rect.width_ == 0) ? 0 : (0 - rect.posX_) * 1.0 / rect.width_;
193     expect.pivotY_ = (rect.height_ == 0) ? 0 : (0 - rect.posY_) * 1.0 / rect.height_;
194     expect.scaleX_ = expect.scaleY_ = 2; // scale value
195     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
196 
197     ASSERT_EQ(WMError::WM_OK, window->Hide());;
198     WindowAccessibilityController::GetInstance().OffWindowZoom();
199     sleep(1);
200 
201     ASSERT_EQ(WMError::WM_OK, window->Show());
202     sleep(1);
203     Transform identity;
204     ASSERT_TRUE(identity == implPtr->GetWindowProperty()->GetZoomTransform());
205 
206     window->Destroy();
207 }
208 
209 /**
210  * @tc.name: DisplayZoom05
211  * @tc.desc: test animate and zoom transform
212  * @tc.type: FUNC
213  * @tc.require: issueI5NGWL
214  */
215 HWTEST_F(WindowDisplayZoomTest, DisplayZoom05, Function | MediumTest | Level3)
216 {
217     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
218     sleep(1);
219 
220     windowInfo_.name = "DisplayZoom05";
221     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
222     Window* ptr = window.GetRefPtr();
223     WindowImpl* implPtr = (WindowImpl*)ptr;
224     ASSERT_EQ(WMError::WM_OK, window->Show());
225     sleep(1);
226 
227     Transform animate;
228     animate.translateX_ = -100; // translate x value
229     animate.translateZ_ = 100; // translate z value
230     window->SetTransform(animate);
231     sleep(1);
232 
233     Transform expect;
234     Rect rect = window->GetRect();
235     expect.pivotX_ = (rect.width_ == 0) ? 0 : (0 - rect.posX_) * 1.0 / rect.width_;
236     expect.pivotY_ = (rect.height_ == 0) ? 0 : (0 - rect.posY_) * 1.0 / rect.height_;
237     expect.scaleX_ = expect.scaleY_ = 1.7; // scale value
238     Transform actual = implPtr->GetWindowProperty()->GetZoomTransform();
239 
__anon2af968a00202(float a, float b) 240     auto isExpec = [](float a, float b) -> bool {
241         return abs(a - b) < 0.1;
242     };
243     ASSERT_EQ(true, isExpec(actual.pivotX_, expect.pivotX_));
244     ASSERT_EQ(true, isExpec(actual.pivotY_, expect.pivotY_));
245     ASSERT_EQ(true, isExpec(actual.scaleX_, expect.scaleX_));
246     ASSERT_EQ(true, isExpec(actual.scaleY_, expect.scaleY_));
247 
248     WindowAccessibilityController::GetInstance().OffWindowZoom();
249     window->Destroy();
250 }
251 
252 /**
253  * @tc.name: DisplayZoom06
254  * @tc.desc: test speical window type
255  * @tc.type: FUNC
256  * @tc.require: issueI5NGWL
257  */
258 HWTEST_F(WindowDisplayZoomTest, DisplayZoom06, Function | MediumTest | Level3)
259 {
260     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
261     sleep(1);
262 
263     windowInfo_.name = "DisplayZoom06";
264     windowInfo_.type = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT;
265     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
266     Window* ptr = window.GetRefPtr();
267     WindowImpl* implPtr = (WindowImpl*)ptr;
268     ASSERT_EQ(WMError::WM_OK, window->Show());
269     sleep(1);
270 
271     Transform expect;
272     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
273 
274     WindowAccessibilityController::GetInstance().OffWindowZoom();
275     window->Destroy();
276 }
277 }
278 } // namespace Rosen
279 } // namespace OHOS