• 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     Transform expect;
81     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
82 
83     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
84     sleep(1);
85     Rect rect = window->GetRect();
86     expect.pivotX_ = (0 - rect.posX_) * 1.0 / rect.width_;
87     expect.pivotY_ = (0 - rect.posY_) * 1.0 / rect.height_;
88     expect.scaleX_ = expect.scaleY_ = 2;
89     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
90 
91     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
92     sleep(1);
93     expect.scaleX_ = expect.scaleY_ = 4;
94     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
95 
96     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 0.5);
97     sleep(1);
98     expect.scaleX_ = expect.scaleY_ = 2;
99     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
100 
101     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 0.1);
102     sleep(1);
103     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
104 
105     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, -0.1);
106     sleep(1);
107     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
108 
109     WindowAccessibilityController::GetInstance().OffWindowZoom();
110     window->Destroy();
111 }
112 
113 /**
114  * @tc.name: DisplayZoom02
115  * @tc.desc: test interface SetAnchorOffset
116  * @tc.type: FUNC
117  * @tc.require: issueI5NGWL
118  */
119 HWTEST_F(WindowDisplayZoomTest, DisplayZoom02, Function | MediumTest | Level3)
120 {
121     windowInfo_.name = "DisplayZoom02";
122     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
123     ASSERT_EQ(WMError::WM_OK, window->Show());
124 
125     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
126     sleep(1);
127     WindowAccessibilityController::GetInstance().SetAnchorOffset(-100, -100);
128     sleep(1);
129 
130     Transform expect;
131     Rect rect = window->GetRect();
132     expect.pivotX_ = (0 - rect.posX_) * 1.0 / rect.width_;
133     expect.pivotY_ = (0 - rect.posY_) * 1.0 / rect.height_;
134     expect.scaleX_ = expect.scaleY_ = 2;
135     expect.translateX_ = expect.translateY_ = -100;
136 
137     WindowAccessibilityController::GetInstance().SetAnchorOffset(200, 200);
138     sleep(1);
139     expect.translateX_ = expect.translateY_ = 0;
140     WindowAccessibilityController::GetInstance().OffWindowZoom();
141     window->Destroy();
142 }
143 
144 /**
145  * @tc.name: DisplayZoom03
146  * @tc.desc: test interface OffWindowZoom
147  * @tc.type: FUNC
148  * @tc.require: issueI5NGWL
149  */
150 HWTEST_F(WindowDisplayZoomTest, DisplayZoom03, Function | MediumTest | Level3)
151 {
152     windowInfo_.name = "DisplayZoom03";
153     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
154     Window* ptr = window.GetRefPtr();
155     WindowImpl* implPtr = (WindowImpl*)ptr;
156     ASSERT_EQ(WMError::WM_OK, window->Show());
157 
158     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
159     sleep(1);
160     WindowAccessibilityController::GetInstance().OffWindowZoom();
161     sleep(1);
162 
163     Transform expect;
164     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
165 
166     window->Destroy();
167 }
168 
169 /**
170  * @tc.name: DisplayZoom04
171  * @tc.desc: test add and remove a window after zoom display
172  * @tc.type: FUNC
173  * @tc.require: issueI5NGWL
174  */
175 HWTEST_F(WindowDisplayZoomTest, DisplayZoom04, Function | MediumTest | Level3)
176 {
177     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
178     sleep(1);
179 
180     windowInfo_.name = "DisplayZoom04";
181     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
182     Window* ptr = window.GetRefPtr();
183     WindowImpl* implPtr = (WindowImpl*)ptr;
184     ASSERT_EQ(WMError::WM_OK, window->Show());
185 
186     Transform expect;
187     Rect rect = window->GetRect();
188     expect.pivotX_ = (0 - rect.posX_) * 1.0 / rect.width_;
189     expect.pivotY_ = (0 - rect.posY_) * 1.0 / rect.height_;
190     expect.scaleX_ = expect.scaleY_ = 2;
191     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
192 
193     ASSERT_EQ(WMError::WM_OK, window->Hide());;
194     WindowAccessibilityController::GetInstance().OffWindowZoom();
195     sleep(1);
196 
197     ASSERT_EQ(WMError::WM_OK, window->Show());
198     sleep(1);
199     Transform identity;
200     ASSERT_TRUE(identity == implPtr->GetWindowProperty()->GetZoomTransform());
201 
202     window->Destroy();
203 }
204 
205 /**
206  * @tc.name: DisplayZoom05
207  * @tc.desc: test animate and zoom transform
208  * @tc.type: FUNC
209  * @tc.require: issueI5NGWL
210  */
211 HWTEST_F(WindowDisplayZoomTest, DisplayZoom05, Function | MediumTest | Level3)
212 {
213     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
214     sleep(1);
215 
216     windowInfo_.name = "DisplayZoom05";
217     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
218     Window* ptr = window.GetRefPtr();
219     WindowImpl* implPtr = (WindowImpl*)ptr;
220     ASSERT_EQ(WMError::WM_OK, window->Show());
221 
222     Transform animate;
223     animate.translateX_ = -100;
224     animate.translateZ_ = 100;
225     window->SetTransform(animate);
226     sleep(1);
227 
228     Transform expect;
229     Rect rect = window->GetRect();
230     expect.pivotX_ = (0 - rect.posX_) * 1.0 / rect.width_;
231     expect.pivotY_ = (0 - rect.posY_) * 1.0 / rect.height_;
232     expect.scaleX_ = expect.scaleY_ = 1.7;
233     Transform actual = implPtr->GetWindowProperty()->GetZoomTransform();
234 
__anon909897220202(float a, float b) 235     auto isExpec = [](float a, float b) -> bool {
236         return abs(a - b) < 0.1;
237     };
238     ASSERT_EQ(true, isExpec(actual.pivotX_, expect.pivotX_));
239     ASSERT_EQ(true, isExpec(actual.pivotY_, expect.pivotY_));
240     ASSERT_EQ(true, isExpec(actual.scaleX_, expect.scaleX_));
241     ASSERT_EQ(true, isExpec(actual.scaleY_, expect.scaleY_));
242 
243     WindowAccessibilityController::GetInstance().OffWindowZoom();
244     window->Destroy();
245 }
246 
247 /**
248  * @tc.name: DisplayZoom06
249  * @tc.desc: test speical window type
250  * @tc.type: FUNC
251  * @tc.require: issueI5NGWL
252  */
253 HWTEST_F(WindowDisplayZoomTest, DisplayZoom06, Function | MediumTest | Level3)
254 {
255     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
256     sleep(1);
257 
258     windowInfo_.name = "DisplayZoom06";
259     windowInfo_.type = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT;
260     sptr<Window> window = Utils::CreateTestWindow(windowInfo_);
261     Window* ptr = window.GetRefPtr();
262     WindowImpl* implPtr = (WindowImpl*)ptr;
263     ASSERT_EQ(WMError::WM_OK, window->Show());
264     sleep(1);
265 
266     Transform expect;
267     ASSERT_TRUE(expect == implPtr->GetWindowProperty()->GetZoomTransform());
268 
269     WindowAccessibilityController::GetInstance().OffWindowZoom();
270     window->Destroy();
271 }
272 }
273 } // namespace Rosen
274 } // namespace OHOS