• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "window_accessibility_controller.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 WindowEffectTest : 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 WindowEffectTest::SetUpTestCase()
38 {
39 }
40 
TearDownTestCase()41 void WindowEffectTest::TearDownTestCase()
42 {
43 }
44 
SetUp()45 void WindowEffectTest::SetUp()
46 {
47     windowInfo_ = {
48             .name = "TestWindow",
49             .rect = {0, 0, 100, 200},
50             .type = WindowType::WINDOW_TYPE_FLOAT,
51             .mode = WindowMode::WINDOW_MODE_FLOATING,
52             .needAvoid = false,
53             .parentLimit = false,
54             .parentId = INVALID_WINDOW_ID,
55     };
56 }
57 
TearDown()58 void WindowEffectTest::TearDown()
59 {
60 }
61 
62 namespace {
63 /**
64  * @tc.name: WindowEffect01
65  * @tc.desc: Set window corner radius
66  * @tc.type: FUNC
67  */
68 HWTEST_F(WindowEffectTest, WindowEffect01, Function | MediumTest | Level3)
69 {
70     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
71     ASSERT_NE(nullptr, window);
72 
73     ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(0.0));
74     ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(16.0));
75     ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(1000.0));
76     ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(-1.0));
77 
78     ASSERT_EQ(WMError::WM_OK, window->Destroy());
79 }
80 
81 /**
82  * @tc.name: WindowEffect02
83  * @tc.desc: Set window shadow radius
84  * @tc.type: FUNC
85  */
86 HWTEST_F(WindowEffectTest, WindowEffect02, Function | MediumTest | Level3)
87 {
88     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
89     ASSERT_NE(nullptr, window);
90 
91     ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(0.0));
92     ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(16.0));
93     ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(1000.0));
94     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowRadius(-1.0));
95 
96     ASSERT_EQ(WMError::WM_OK, window->Destroy());
97 }
98 
99 /**
100  * @tc.name: WindowEffect03
101  * @tc.desc: Set window shadow color
102  * @tc.type: FUNC
103  */
104 HWTEST_F(WindowEffectTest, WindowEffect03, Function | MediumTest | Level3)
105 {
106     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
107     ASSERT_NE(nullptr, window);
108 
109     ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#FF22EE44"));
110     ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#22EE44"));
111     ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#ff22ee44"));
112 
113     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("ff22ee44"));
114     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("22ee44"));
115     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ppEE44"));
116     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#eepp44"));
117     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ffeePP44"));
118     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff22ee4422"));
119     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff"));
120 
121     ASSERT_EQ(WMError::WM_OK, window->Destroy());
122 }
123 
124 /**
125  * @tc.name: WindowEffect04
126  * @tc.desc: Set window shadow offset
127  * @tc.type: FUNC
128  */
129 HWTEST_F(WindowEffectTest, WindowEffect04, Function | MediumTest | Level3)
130 {
131     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
132     ASSERT_NE(nullptr, window);
133 
134     window->SetShadowOffsetX(0.0);
135     window->SetShadowOffsetX(16.0);
136     window->SetShadowOffsetX(1000.0);
137     window->SetShadowOffsetX(-1.0);
138 
139     window->SetShadowOffsetY(0.0);
140     window->SetShadowOffsetY(16.0);
141     window->SetShadowOffsetY(1000.0);
142     window->SetShadowOffsetY(-1.0);
143 
144     ASSERT_EQ(WMError::WM_OK, window->Destroy());
145 }
146 
147 /**
148  * @tc.name: WindowEffect05
149  * @tc.desc: Set window blur radius
150  * @tc.type: FUNC
151  */
152 HWTEST_F(WindowEffectTest, WindowEffect05, Function | MediumTest | Level3)
153 {
154     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
155     ASSERT_NE(nullptr, window);
156 
157     ASSERT_EQ(WMError::WM_OK, window->SetBlur(0.0));
158     ASSERT_EQ(WMError::WM_OK, window->SetBlur(16.0));
159     ASSERT_EQ(WMError::WM_OK, window->SetBlur(1000.0));
160     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBlur(-1.0));
161 
162     ASSERT_EQ(WMError::WM_OK, window->Destroy());
163 }
164 
165 /**
166  * @tc.name: WindowEffect06
167  * @tc.desc: Set window backdrop blur radius
168  * @tc.type: FUNC
169  */
170 HWTEST_F(WindowEffectTest, WindowEffect06, Function | MediumTest | Level3)
171 {
172     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
173     ASSERT_NE(nullptr, window);
174 
175     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(0.0));
176     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(16.0));
177     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(1000.0));
178     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlur(-1.0));
179 
180     ASSERT_EQ(WMError::WM_OK, window->Destroy());
181 }
182 
183 /**
184  * @tc.name: WindowEffect07
185  * @tc.desc: Set window backdrop blur style
186  * @tc.type: FUNC
187  */
188 HWTEST_F(WindowEffectTest, WindowEffect07, Function | MediumTest | Level3)
189 {
190     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
191     ASSERT_NE(nullptr, window);
192 
193     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF));
194     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THIN));
195     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_REGULAR));
196     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THICK));
197 
198     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(-1)));
199     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(5)));
200 
201     ASSERT_EQ(WMError::WM_OK, window->Destroy());
202 }
203 
204 /**
205  * @tc.name: WindowEffect08
206  * @tc.desc: Set window backdrop blur style
207  * @tc.type: FUNC
208  */
209 HWTEST_F(WindowEffectTest, WindowEffect08, Function | MediumTest | Level3)
210 {
211     const sptr<Window> &window = Utils::CreateTestWindow(windowInfo_);
212     ASSERT_NE(nullptr, window);
213     WindowAccessibilityController::GetInstance().OffWindowZoom();
214     sleep(1);
215     WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2);
216     sleep(1);
217     WindowAccessibilityController::GetInstance().SetAnchorOffset(-100, -100);
218 }
219 
220 } // namespace
221 } // namespace Rosen
222 } // namespace OHOS
223