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 "display_manager_proxy.h" 19#include "common_test_utils.h" 20#include "window_test_utils.h" 21#include "window_accessibility_controller.h" 22#include "wm_common.h" 23using namespace testing; 24using namespace testing::ext; 25 26namespace OHOS { 27namespace Rosen { 28using Utils = WindowTestUtils; 29class WindowEffectTest : public testing::Test { 30public: 31 static void SetUpTestCase(); 32 static void TearDownTestCase(); 33 virtual void SetUp() override; 34 virtual void TearDown() override; 35 Utils::TestWindowInfo windowInfo_; 36private: 37 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000; 38}; 39 40void WindowEffectTest::SetUpTestCase() 41{ 42} 43 44void WindowEffectTest::TearDownTestCase() 45{ 46} 47 48void WindowEffectTest::SetUp() 49{ 50 CommonTestUtils::GuaranteeFloatWindowPermission("wms_window_effect_test"); 51 windowInfo_ = { 52 .name = "TestWindow", 53 .rect = {0, 0, 100, 200}, 54 .type = WindowType::WINDOW_TYPE_FLOAT, 55 .mode = WindowMode::WINDOW_MODE_FLOATING, 56 .needAvoid = false, 57 .parentLimit = false, 58 .parentId = INVALID_WINDOW_ID, 59 }; 60} 61 62void WindowEffectTest::TearDown() 63{ 64 usleep(WAIT_SYNC_IN_NS); 65} 66 67namespace { 68/** 69 * @tc.name: WindowEffect01 70 * @tc.desc: Set window corner radius 71 * @tc.type: FUNC 72 */ 73HWTEST_F(WindowEffectTest, WindowEffect01, Function | MediumTest | Level3) 74{ 75 const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_); 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()); 84} 85 86/** 87 * @tc.name: WindowEffect02 88 * @tc.desc: Set window shadow radius 89 * @tc.type: FUNC 90 */ 91HWTEST_F(WindowEffectTest, WindowEffect02, Function | MediumTest | Level3) 92{ 93 const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_); 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()); 102} 103 104/** 105 * @tc.name: WindowEffect03 106 * @tc.desc: Set window shadow color 107 * @tc.type: FUNC 108 */ 109HWTEST_F(WindowEffectTest, WindowEffect03, Function | MediumTest | Level3) 110{ 111 const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_); 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()); 127} 128 129/** 130 * @tc.name: WindowEffect04 131 * @tc.desc: Set window shadow offset 132 * @tc.type: FUNC 133 */ 134HWTEST_F(WindowEffectTest, WindowEffect04, Function | MediumTest | Level3) 135{ 136 const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_); 137 ASSERT_NE(nullptr, window); 138 139 window->SetShadowOffsetX(0.0); 140 window->SetShadowOffsetX(16.0); 141 window->SetShadowOffsetX(1000.0); 142 window->SetShadowOffsetX(-1.0); 143 144 window->SetShadowOffsetY(0.0); 145 window->SetShadowOffsetY(16.0); 146 window->SetShadowOffsetY(1000.0); 147 window->SetShadowOffsetY(-1.0); 148 149 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 150} 151 152/** 153 * @tc.name: WindowEffect05 154 * @tc.desc: Set window blur radius 155 * @tc.type: FUNC 156 */ 157HWTEST_F(WindowEffectTest, WindowEffect05, Function | MediumTest | Level3) 158{ 159 const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_); 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()); 168} 169 170/** 171 * @tc.name: WindowEffect06 172 * @tc.desc: Set window backdrop blur radius 173 * @tc.type: FUNC 174 */ 175HWTEST_F(WindowEffectTest, WindowEffect06, Function | MediumTest | Level3) 176{ 177 const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_); 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()); 186} 187 188/** 189 * @tc.name: WindowEffect07 190 * @tc.desc: Set window backdrop blur style 191 * @tc.type: FUNC 192 */ 193HWTEST_F(WindowEffectTest, WindowEffect07, Function | MediumTest | Level3) 194{ 195 const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_); 196 ASSERT_NE(nullptr, window); 197 198 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF)); 199 200 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(-1))); 201 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(5))); 202 WindowAccessibilityController::GetInstance().SetAnchorOffset(-100, -100); 203 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 204} 205 206 207} // namespace 208} // namespace Rosen 209} // namespace OHOS 210