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