1 /*
2 * Copyright (c) 2023 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 #include <gtest/gtest.h>
17 #include "mock_session.h"
18 #include "mock_uicontent.h"
19 #include "modifier_render_thread/rs_modifiers_draw_thread.h"
20 #include "window_scene_session_impl.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace Rosen {
27
28 class WindowSceneEffectTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp() override;
33 void TearDown() override;
34 };
35
SetUpTestCase()36 void WindowSceneEffectTest::SetUpTestCase() {}
37
TearDownTestCase()38 void WindowSceneEffectTest::TearDownTestCase()
39 {
40 #ifdef RS_ENABLE_VK
41 RSModifiersDrawThread::Destroy();
42 #endif
43 }
44
SetUp()45 void WindowSceneEffectTest::SetUp() {}
46
TearDown()47 void WindowSceneEffectTest::TearDown() {}
48
49 class WindowEffectTestUtils {
50 public:
CreateTestWindow(const std::string & name)51 static sptr<WindowSceneSessionImpl> CreateTestWindow(const std::string& name)
52 {
53 sptr<WindowOption> option = new (std::nothrow) WindowOption();
54 option->SetWindowName(name);
55 option->SetDisplayId(0);
56 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
57 window->property_->SetPersistentId(1);
58 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
59 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
60 window->hostSession_ = session;
61 return window;
62 }
63 };
64
65 namespace {
66 using Utils = WindowEffectTestUtils;
67
68 /**
69 * @tc.name: WindowEffect01
70 * @tc.desc: Set window corner radius
71 * @tc.type: FUNC
72 */
73 HWTEST_F(WindowSceneEffectTest, WindowEffect01, TestSize.Level1)
74 {
75 const sptr<WindowSceneSessionImpl>& window = Utils::CreateTestWindow("CornerRadius");
76 ASSERT_NE(nullptr, window);
77
78 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(0.0));
79 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(16.0));
80 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(1000.0));
81 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(-1.0));
82
83 ASSERT_EQ(WMError::WM_OK, window->Destroy(true));
84 }
85
86 /**
87 * @tc.name: WindowEffect02
88 * @tc.desc: Set window shadow radius
89 * @tc.type: FUNC
90 */
91 HWTEST_F(WindowSceneEffectTest, WindowEffect02, TestSize.Level1)
92 {
93 const sptr<WindowSceneSessionImpl>& window = Utils::CreateTestWindow("shadowRadius");
94 ASSERT_NE(nullptr, window);
95
96 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(0.0));
97 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(16.0));
98 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(1000.0));
99 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowRadius(-1.0));
100
101 ASSERT_EQ(WMError::WM_OK, window->Destroy(true));
102 }
103
104 /**
105 * @tc.name: WindowEffect03
106 * @tc.desc: Set window shadow color
107 * @tc.type: FUNC
108 */
109 HWTEST_F(WindowSceneEffectTest, WindowEffect03, TestSize.Level1)
110 {
111 const sptr<WindowSceneSessionImpl>& window = Utils::CreateTestWindow("WindowEffect03");
112 ASSERT_NE(nullptr, window);
113
114 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#FF22EE44"));
115 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#22EE44"));
116 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#ff22ee44"));
117
118 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("ff22ee44"));
119 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("22ee44"));
120 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ppEE44"));
121 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#eepp44"));
122 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ffeePP44"));
123 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff22ee4422"));
124 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff"));
125
126 ASSERT_EQ(WMError::WM_OK, window->Destroy(true));
127 }
128
129 /**
130 * @tc.name: WindowEffect04
131 * @tc.desc: Set window shadow offset
132 * @tc.type: FUNC
133 */
134 HWTEST_F(WindowSceneEffectTest, WindowEffect04, TestSize.Level1)
135 {
136 const sptr<WindowSceneSessionImpl>& window = Utils::CreateTestWindow("WindowEffect04");
137 ASSERT_NE(nullptr, window);
138
139 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetX(0.0));
140 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetX(16.0));
141 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetX(1000.0));
142 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetX(-1.0));
143
144 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetY(0.0));
145 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetY(16.0));
146 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetY(1000.0));
147 ASSERT_EQ(WMError::WM_OK, window->SetShadowOffsetY(-1.0));
148
149 ASSERT_EQ(WMError::WM_OK, window->Destroy(true));
150 }
151
152 /**
153 * @tc.name: WindowEffect05
154 * @tc.desc: Set window blur radius
155 * @tc.type: FUNC
156 */
157 HWTEST_F(WindowSceneEffectTest, WindowEffect05, TestSize.Level1)
158 {
159 const sptr<WindowSceneSessionImpl>& window = Utils::CreateTestWindow("WindowEffect05");
160 ASSERT_NE(nullptr, window);
161
162 ASSERT_EQ(WMError::WM_OK, window->SetBlur(0.0));
163 ASSERT_EQ(WMError::WM_OK, window->SetBlur(16.0));
164 ASSERT_EQ(WMError::WM_OK, window->SetBlur(1000.0));
165 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBlur(-1.0));
166
167 ASSERT_EQ(WMError::WM_OK, window->Destroy(true));
168 }
169
170 /**
171 * @tc.name: WindowEffect06
172 * @tc.desc: Set window backdrop blur radius
173 * @tc.type: FUNC
174 */
175 HWTEST_F(WindowSceneEffectTest, WindowEffect06, TestSize.Level1)
176 {
177 const sptr<WindowSceneSessionImpl>& window = Utils::CreateTestWindow("WindowEffect06");
178 ASSERT_NE(nullptr, window);
179
180 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(0.0));
181 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(16.0));
182 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(1000.0));
183 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlur(-1.0));
184
185 ASSERT_EQ(WMError::WM_OK, window->Destroy(true));
186 }
187
188 /**
189 * @tc.name: WindowEffect07
190 * @tc.desc: Set window backdrop blur style
191 * @tc.type: FUNC
192 */
193 HWTEST_F(WindowSceneEffectTest, WindowEffect07, TestSize.Level1)
194 {
195 const sptr<WindowSceneSessionImpl>& window = Utils::CreateTestWindow("WindowEffect07");
196 ASSERT_NE(nullptr, window);
197
198 window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF);
199 window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THIN);
200 window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_REGULAR);
201 window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THICK);
202
203 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(-1)));
204 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(5)));
205
206 ASSERT_EQ(WMError::WM_OK, window->Destroy(true));
207 }
208
209 } // namespace
210 } // namespace Rosen
211 } // namespace OHOS
212