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