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