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