diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index f2b659cc..8bd9f4cd 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -19,6 +19,7 @@ group("systemtest") { testonly = true deps = [ + ":wm_window_effect_test", ":wm_window_focus_test", ":wm_window_gamut_test", ":wm_window_immersive_test", @@ -42,6 +43,17 @@ ohos_systemtest("wm_window_layout_test") { ## SystemTest wm_window_layout_test }}} +## SystemTest wm_window_effect_test {{{ +ohos_systemtest("wm_window_effect_test") { + module_out_path = module_out_path + + sources = [ "window_effect_test.cpp" ] + + deps = [ ":wm_systemtest_common" ] +} + +## SystemTest wm_window_effect_test }}} + ## SystemTest wm_window_multi_ability_test {{{ ohos_systemtest("wm_window_multi_ability_test") { module_out_path = module_out_path diff --git a/wm/test/systemtest/window_effect_test.cpp b/wm/test/systemtest/window_effect_test.cpp new file mode 100644 index 00000000..eb1e0040 --- /dev/null +++ b/wm/test/systemtest/window_effect_test.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// gtest +#include +#include "window_test_utils.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using utils = WindowTestUtils; +class WindowEffectTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + utils::TestWindowInfo fullScreenAppInfo_; +}; + +void WindowEffectTest::SetUpTestCase() +{ +} + +void WindowEffectTest::TearDownTestCase() +{ +} + +void WindowEffectTest::SetUp() +{ + fullScreenAppInfo_ = { + .name = "FullWindow", + .rect = utils::customAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }; +} + +void WindowEffectTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: WindowEffect01 + * @tc.desc: SetWindowBackgroundBlur | GetWindowBackgroundBlur + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(WindowEffectTest, WindowEffect01, Function | MediumTest | Level3) +{ + const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + + ASSERT_EQ(WMError::WM_OK, window->SetWindowBackgroundBlur(WindowBlurLevel::WINDOW_BLUR_LOW)); + ASSERT_EQ(WindowBlurLevel::WINDOW_BLUR_LOW, window->GetWindowBackgroundBlur()); + window->Destroy(); +} + +/** + * @tc.name: WindowEffect02 + * @tc.desc: SetAlpha | GetAlpha + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(WindowEffectTest, WindowEffect02, Function | MediumTest | Level3) +{ + const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + + ASSERT_EQ(WMError::WM_OK, window->SetAlpha(1.0f)); + ASSERT_EQ(1.0f, window->GetAlpha()); + + window->Destroy(); +} +} // namespace +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 9b37f01d..8a3d0737 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -20,6 +20,7 @@ group("unittest") { deps = [ ":avoid_area_controller_test", ":wm_input_transfer_station_test", + ":wm_window_effect_test", ":wm_window_impl_test", ":wm_window_input_channel_test", ":wm_window_option_test", @@ -51,6 +52,17 @@ ohos_unittest("wm_window_impl_test") { ## UnitTest wm_window_impl_test }}} +## UnitTest wm_window_effect_test {{{ +ohos_unittest("wm_window_effect_test") { + module_out_path = module_out_path + + sources = [ "window_effect_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_effect_test }}} + ## UnitTest wm_input_transfer_station_test {{{ ohos_unittest("wm_input_transfer_station_test") { module_out_path = module_out_path diff --git a/wm/test/unittest/mock_window_adapter.h b/wm/test/unittest/mock_window_adapter.h index 117dfea6..3535378f 100644 --- a/wm/test/unittest/mock_window_adapter.h +++ b/wm/test/unittest/mock_window_adapter.h @@ -29,6 +29,8 @@ public: MOCK_METHOD1(RemoveWindow, WMError(uint32_t windowId)); MOCK_METHOD0(ClearWindowAdapter, void()); MOCK_METHOD1(DestroyWindow, WMError(uint32_t windowId)); + MOCK_METHOD2(SetWindowBackgroundBlur, WMError(uint32_t windowId, WindowBlurLevel level)); + MOCK_METHOD2(SetAlpha, WMError(uint32_t windowId, float alpha)); MOCK_METHOD2(SaveAbilityToken, WMError(const sptr& abilityToken, uint32_t windowId)); MOCK_METHOD3(SetSystemBarProperty, WMError(uint32_t windowId, WindowType type, const SystemBarProperty& property)); }; diff --git a/wm/test/unittest/window_effect_test.cpp b/wm/test/unittest/window_effect_test.cpp new file mode 100644 index 00000000..e8dc851b --- /dev/null +++ b/wm/test/unittest/window_effect_test.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "window_effect_test.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +void WindowEffectTest::SetUpTestCase() +{ +} + +void WindowEffectTest::TearDownTestCase() +{ +} + +void WindowEffectTest::SetUp() +{ +} + +void WindowEffectTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: WindowEffect01 + * @tc.desc: windowOption: set window background blur / get window background blur + * @tc.type: FUNC + */ +HWTEST_F(WindowEffectTest, WindowEffect01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowBackgroundBlur(WindowBlurLevel::WINDOW_BLUR_LOW); + ASSERT_EQ(WindowBlurLevel::WINDOW_BLUR_LOW, option->GetWindowBackgroundBlur()); + option->SetWindowBackgroundBlur(WindowBlurLevel::WINDOW_BLUR_MEDIUM); + ASSERT_EQ(WindowBlurLevel::WINDOW_BLUR_MEDIUM, option->GetWindowBackgroundBlur()); + option->SetWindowBackgroundBlur(WindowBlurLevel::WINDOW_BLUR_HIGH); + ASSERT_EQ(WindowBlurLevel::WINDOW_BLUR_HIGH, option->GetWindowBackgroundBlur()); + option->SetWindowBackgroundBlur(WindowBlurLevel::WINDOW_BLUR_OFF); + ASSERT_EQ(WindowBlurLevel::WINDOW_BLUR_OFF, option->GetWindowBackgroundBlur()); +} + +/** + * @tc.name: WindowEffect02 + * @tc.desc: windowOption: set window alpha/ get window alpha + * @tc.type: FUNC + */ +HWTEST_F(WindowEffectTest, WindowEffect02, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetAlpha(0.0f); + ASSERT_EQ(0.0f, option->GetAlpha()); + option->SetAlpha(0.5f); + ASSERT_EQ(0.5f, option->GetAlpha()); + option->SetAlpha(1.0f); + ASSERT_EQ(1.0f, option->GetAlpha()); +} + +/** + * @tc.name: WindowEffect03 + * @tc.desc: WindowImp: Create window with no default option, get and check Property + * @tc.type: FUNC + */ +HWTEST_F(WindowEffectTest, WindowEffect03, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + option->SetWindowBackgroundBlur(WindowBlurLevel::WINDOW_BLUR_LOW); + sptr window = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + + ASSERT_EQ(WindowBlurLevel::WINDOW_BLUR_LOW, window->GetWindowBackgroundBlur()); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: WindowEffect04 + * @tc.desc: Create window with no default option, get and check Property + * @tc.type: FUNC + */ +HWTEST_F(WindowEffectTest, WindowEffect04, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + option->SetAlpha(0.1f); + + sptr window = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + + ASSERT_EQ(0.1f, window->GetAlpha()); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: WindowEffect05 + * @tc.desc: set window effect parameters throw window, and check parameters. + * @tc.type: FUNC + */ +HWTEST_F(WindowEffectTest, WindowEffect05, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + + EXPECT_CALL(m->Mock(), SetWindowBackgroundBlur(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->SetWindowBackgroundBlur(WindowBlurLevel::WINDOW_BLUR_LOW)); + ASSERT_EQ(WindowBlurLevel::WINDOW_BLUR_LOW, window->GetWindowBackgroundBlur()); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + window->Destroy(); +} + +/** + * @tc.name: WindowEffect06 + * @tc.desc: set window effect parameters throw window, and check parameters. + * @tc.type: FUNC + */ +HWTEST_F(WindowEffectTest, WindowEffect06, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + EXPECT_CALL(m->Mock(), SetAlpha(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->SetAlpha(0.1f)); + ASSERT_EQ(0.1f, window->GetAlpha()); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + window->Destroy(); +} + +/** + * @tc.name: WindowEffect07 + * @tc.desc: WindowImp: Create window with default option, get and check Property + * @tc.type: FUNC + */ +HWTEST_F(WindowEffectTest, WindowEffect07, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + sptr window = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + + ASSERT_EQ(WindowBlurLevel::WINDOW_BLUR_OFF, window->GetWindowBackgroundBlur()); + ASSERT_EQ(1.0f, window->GetAlpha()); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/window_effect_test.h b/wm/test/unittest/window_effect_test.h new file mode 100644 index 00000000..b904d9dc --- /dev/null +++ b/wm/test/unittest/window_effect_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_Effect_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_Effect_TEST_H + +#include +#include "mock_window_adapter.h" +#include "singleton_mocker.h" +#include "window_impl.h" + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; +class WindowEffectTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_Effect_TEST_H \ No newline at end of file diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index d04d2fb2..add1786e 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -257,7 +257,6 @@ WMError WindowController::SetWindowBackgroundBlur(uint32_t windowId, WindowBlurL if (srcLevel == dstLevel) { return WMError::WM_OK; } - node->SetWindowBackgroundBlur(dstLevel); FlushWindowInfo(windowId); return WMError::WM_OK;