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