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